mirror of
https://github.com/crmeb/CRMEB.git
synced 2025-12-14 20:42:49 +00:00
定时任务修复
This commit is contained in:
parent
9246bdd00c
commit
4a8c077752
@ -22,6 +22,7 @@ use think\facade\Route as Url;
|
||||
use think\facade\Db;
|
||||
use app\admin\model\user\User;
|
||||
use app\admin\model\user\UserBill;
|
||||
|
||||
/**
|
||||
* 订单管理Model
|
||||
* Class StoreOrder
|
||||
@ -44,7 +45,8 @@ class StoreOrder extends BaseModel
|
||||
|
||||
use ModelTrait;
|
||||
|
||||
public static function orderCount(){
|
||||
public static function orderCount()
|
||||
{
|
||||
$data['wz'] = self::statusByWhere(0, new self())->where(['is_system_del' => 0])->count();
|
||||
$data['wf'] = self::statusByWhere(1, new self())->where(['is_system_del' => 0, 'shipping_type' => 1])->count();
|
||||
$data['ds'] = self::statusByWhere(2, new self())->where(['is_system_del' => 0, 'shipping_type' => 1])->count();
|
||||
@ -61,7 +63,8 @@ class StoreOrder extends BaseModel
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function OrderList($where){
|
||||
public static function OrderList($where)
|
||||
{
|
||||
$model = self::getOrderWhere($where, self::alias('a')->join('user r', 'r.uid=a.uid', 'LEFT'), 'a.', 'r')->field('a.*,r.nickname,r.phone,r.spread_uid');
|
||||
if ($where['order'] != '') {
|
||||
$model = $model->order(self::setOrder($where['order']));
|
||||
@ -217,12 +220,14 @@ HTML;
|
||||
$count = self::getOrderWhere($where, self::alias('a')->join('user r', 'r.uid=a.uid', 'LEFT'), 'a.', 'r')->count();
|
||||
return compact('count', 'data');
|
||||
}
|
||||
|
||||
/*
|
||||
* 保存并下载excel
|
||||
* $list array
|
||||
* return
|
||||
*/
|
||||
public static function SaveExcel($list){
|
||||
public static function SaveExcel($list)
|
||||
{
|
||||
$export = [];
|
||||
foreach ($list as $index => $item) {
|
||||
$_info = Db::name('store_order_cart_info')->where('oid', $item['id'])->column('cart_info');
|
||||
@ -270,7 +275,8 @@ HTML;
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function systemPage($where,$userid=false){
|
||||
public static function systemPage($where, $userid = false)
|
||||
{
|
||||
$model = self::getOrderWhere($where, self::alias('a')->join('user r', 'r.uid=a.uid', 'LEFT'), 'a.', 'r')->field('a.*,r.nickname');
|
||||
if ($where['order']) {
|
||||
$model = $model->order('a.' . $where['order']);
|
||||
@ -411,7 +417,8 @@ HTML;
|
||||
* @param $id
|
||||
* @return $this
|
||||
*/
|
||||
public static function updateOffline($id){
|
||||
public static function updateOffline($id)
|
||||
{
|
||||
$count = self::where('id', $id)->count();
|
||||
if (!$count) return self::setErrorInfo('订单不存在');
|
||||
$count = self::where('id', $id)->where('paid', 0)->count();
|
||||
@ -445,16 +452,10 @@ HTML;
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function refundRoutineTemplate($oid){
|
||||
public static function refundRoutineTemplate($oid)
|
||||
{
|
||||
$order = self::where('id', $oid)->find();
|
||||
$data['keyword1'] = $order['order_id'];
|
||||
$data['keyword2'] = date('Y-m-d H:i:s',time());
|
||||
$data['keyword3'] = $order['pay_price'];
|
||||
if($order['pay_type'] == 'yue') $data['keyword4'] = '余额支付';
|
||||
else if($order['pay_type'] == 'weixin') $data['keyword4'] = '微信支付';
|
||||
else if($order['pay_type'] == 'offline') $data['keyword4'] = '线下支付';
|
||||
$data['keyword5'] = '已成功退款';
|
||||
return RoutineTemplate::sendOut('ORDER_REFUND_SUCCESS',$order['uid'],$data);
|
||||
return RoutineTemplate::sendOrderRefundSuccess($order);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -463,7 +464,8 @@ HTML;
|
||||
* @param $model
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getOrderWhere($where,$model,$aler='',$join=''){
|
||||
public static function getOrderWhere($where, $model, $aler = '', $join = '')
|
||||
{
|
||||
// $model = $model->where('combination_id',0);
|
||||
$model = $model->where('is_system_del', 0);
|
||||
if (isset($where['status']) && $where['status'] != '') {
|
||||
@ -520,7 +522,11 @@ HTML;
|
||||
}
|
||||
if (isset($where['data']) && $where['data'] !== '') {
|
||||
switch ($where['data']) {
|
||||
case 'today':case 'week':case 'month':case 'year':case 'yesterday':
|
||||
case 'today':
|
||||
case 'week':
|
||||
case 'month':
|
||||
case 'year':
|
||||
case 'yesterday':
|
||||
$model = $model->whereTime($aler . 'add_time', $where['data']);
|
||||
break;
|
||||
case 'quarter':
|
||||
@ -546,7 +552,9 @@ HTML;
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
public static function getBadge($where){
|
||||
|
||||
public static function getBadge($where)
|
||||
{
|
||||
$price = self::getOrderPrice($where);
|
||||
return [
|
||||
[
|
||||
@ -628,12 +636,14 @@ HTML;
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理订单金额
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function getOrderPrice($where){
|
||||
public static function getOrderPrice($where)
|
||||
{
|
||||
$where['is_del'] = 0;//删除订单不统计
|
||||
$model = new self;
|
||||
$price = array();
|
||||
@ -693,7 +703,8 @@ HTML;
|
||||
return $price;
|
||||
}
|
||||
|
||||
public static function systemPagePink($where){
|
||||
public static function systemPagePink($where)
|
||||
{
|
||||
$model = new self;
|
||||
$model = self::getOrderWherePink($where, $model);
|
||||
$model = $model->order('id desc');
|
||||
@ -754,7 +765,8 @@ HTML;
|
||||
* @param $model
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getOrderWherePink($where,$model){
|
||||
public static function getOrderWherePink($where, $model)
|
||||
{
|
||||
$model = $model->where('combination_id', '>', 0);
|
||||
if ($where['status'] != '') $model = $model::statusByWhere($where['status']);
|
||||
// if($where['is_del'] != '' && $where['is_del'] != -1) $model = $model->where('is_del',$where['is_del']);
|
||||
@ -774,7 +786,8 @@ HTML;
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function getOrderPricePink($where){
|
||||
public static function getOrderPricePink($where)
|
||||
{
|
||||
$model = new self;
|
||||
$price = array();
|
||||
$price['pay_price'] = 0;//支付金额
|
||||
@ -815,7 +828,8 @@ HTML;
|
||||
* @param int $day
|
||||
* @return $this|StoreOrder
|
||||
*/
|
||||
public static function isMainYesterdayCount($preDay = 0,$day = 0){
|
||||
public static function isMainYesterdayCount($preDay = 0, $day = 0)
|
||||
{
|
||||
$model = new self();
|
||||
$model = $model->where('add_time', '>', $preDay);
|
||||
$model = $model->where('add_time', '<', $day);
|
||||
@ -827,7 +841,8 @@ HTML;
|
||||
* @param int $uid
|
||||
* @return int|string
|
||||
*/
|
||||
public static function getUserCountPay($uid = 0){
|
||||
public static function getUserCountPay($uid = 0)
|
||||
{
|
||||
if (!$uid) return 0;
|
||||
return self::where('uid', $uid)->where('paid', 1)->count();
|
||||
}
|
||||
@ -837,7 +852,8 @@ HTML;
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public static function getOneorderList($where){
|
||||
public static function getOneorderList($where)
|
||||
{
|
||||
return self::where('uid', $where['uid'])
|
||||
->order('add_time desc')
|
||||
->page((int)$where['page'], (int)$where['limit'])
|
||||
@ -845,13 +861,17 @@ HTML;
|
||||
])->select()
|
||||
->toArray();
|
||||
}
|
||||
/*
|
||||
|
||||
/**
|
||||
* 设置订单统计图搜索
|
||||
* $where array 条件
|
||||
* return object
|
||||
* @param array $where 条件
|
||||
* @param null $status
|
||||
* @param null $time
|
||||
* @return array
|
||||
*/
|
||||
public static function setEchatWhere($where,$status=null,$time=null){
|
||||
$model=self::statusByWhere($where['status']);
|
||||
public static function setEchatWhere($where, $status = null, $time = null)
|
||||
{
|
||||
$model = self::statusByWhere($where['status'])->where('is_system_del',0);
|
||||
if ($status !== null) $where['type'] = $status;
|
||||
if ($time === true) $where['data'] = '';
|
||||
switch ($where['type']) {
|
||||
@ -874,13 +894,15 @@ HTML;
|
||||
}
|
||||
return self::getModelTime($where, $model);
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取订单数据统计图
|
||||
* $where array
|
||||
* $limit int
|
||||
* return array
|
||||
*/
|
||||
public static function getEchartsOrder($where,$limit=20){
|
||||
public static function getEchartsOrder($where, $limit = 20)
|
||||
{
|
||||
$orderlist = self::setEchatWhere($where)->field(
|
||||
'FROM_UNIXTIME(add_time,"%Y-%m-%d") as _add_time,sum(total_num) total_num,count(*) count,sum(total_price) total_price,sum(refund_price) refund_price,group_concat(cart_id SEPARATOR "|") cart_ids'
|
||||
)->group('_add_time')->order('_add_time asc')->select();
|
||||
@ -939,7 +961,8 @@ HTML;
|
||||
return compact('zoom', 'xdata', 'seriesdata', 'badge', 'legend', 'bing_data', 'bing_xdata');
|
||||
}
|
||||
|
||||
public static function getOrderBadge($where){
|
||||
public static function getOrderBadge($where)
|
||||
{
|
||||
return [
|
||||
[
|
||||
'name' => '拼团订单数量',
|
||||
@ -1014,20 +1037,20 @@ HTML;
|
||||
[
|
||||
'name' => '在线支付金额',
|
||||
'field' => '元',
|
||||
'count'=>self::setEchatWhere($where)->where('pay_type','weixin')->sum('pay_price'),
|
||||
'count' => self::setEchatWhere($where)->where(['paid'=>1,'refund_status'=>0])->where('pay_type', 'weixin')->sum('pay_price'),
|
||||
'content' => '在线支付总金额',
|
||||
'background_color' => 'layui-bg-cyan',
|
||||
'sum'=>self::setEchatWhere($where,null,true)->where('pay_type','weixin')->sum('pay_price'),
|
||||
'sum' => self::setEchatWhere($where, null, true)->where(['paid'=>1,'refund_status'=>0])->where('pay_type', 'weixin')->sum('pay_price'),
|
||||
'class' => 'fa fa-weixin',
|
||||
'col' => 2
|
||||
],
|
||||
[
|
||||
'name' => '余额支付金额',
|
||||
'field' => '元',
|
||||
'count'=>self::setEchatWhere($where)->where('pay_type','yue')->sum('pay_price'),
|
||||
'count' => self::setEchatWhere($where)->where('pay_type', 'yue')->where(['paid'=>1,'refund_status'=>0])->sum('pay_price'),
|
||||
'content' => '余额支付总金额',
|
||||
'background_color' => 'layui-bg-cyan',
|
||||
'sum'=>self::setEchatWhere($where,null,true)->where('pay_type','yue')->sum('pay_price'),
|
||||
'sum' => self::setEchatWhere($where, null, true)->where(['paid'=>1,'refund_status'=>0])->where('pay_type', 'yue')->sum('pay_price'),
|
||||
'class' => 'fa fa-balance-scale',
|
||||
'col' => 2
|
||||
],
|
||||
@ -1044,10 +1067,10 @@ HTML;
|
||||
[
|
||||
'name' => '交易额',
|
||||
'field' => '元',
|
||||
'count'=>self::setEchatWhere($where)->sum('pay_price'),
|
||||
'count' => self::setEchatWhere($where)->where(['paid'=>1,'refund_status'=>0])->sum('pay_price'),
|
||||
'content' => '总交易额',
|
||||
'background_color' => 'layui-bg-cyan',
|
||||
'sum'=>self::setEchatWhere($where,null,true)->sum('pay_price'),
|
||||
'sum' => self::setEchatWhere($where, null, true)->where(['paid'=>1,'refund_status'=>0])->sum('pay_price'),
|
||||
'class' => 'fa fa-jpy',
|
||||
'col' => 2
|
||||
],
|
||||
@ -1136,12 +1159,7 @@ HTML;
|
||||
}
|
||||
|
||||
if ($order['is_channel'] == 1) {//小程序
|
||||
RoutineTemplate::sendOut('OREDER_TAKEVER',$order['uid'],[
|
||||
'keyword1'=>$order['order_id'],
|
||||
'keyword2'=>$title,
|
||||
'keyword3'=>$order['pay_price'],
|
||||
'keyword4'=>date('Y-m-d H:i:s',time()),
|
||||
]);
|
||||
RoutineTemplate::sendOrderTakeOver($order, $title);
|
||||
} else {
|
||||
$openid = WechatUser::where('uid', $order['uid'])->value('openid');
|
||||
WechatTemplateService::sendTemplate($openid, WechatTemplateService::ORDER_TAKE_SUCCESS, [
|
||||
@ -1155,7 +1173,7 @@ HTML;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* 不退款发送模板消息
|
||||
* @param int $id 订单id
|
||||
* @param array $data 退款详情
|
||||
@ -1172,12 +1190,7 @@ HTML;
|
||||
$title .= $store_name . ',';
|
||||
}
|
||||
if ($order->is_channel == 1) {
|
||||
RoutineTemplate::sendOut('ORDER_REFUND_FILE',$order->uid,[
|
||||
'keyword1'=>$order->order_id,
|
||||
'keyword2'=>$title,
|
||||
'keyword3'=>$order->pay_price,
|
||||
'keyword4'=>$data,
|
||||
]);
|
||||
RoutineTemplate::sendOrderRefundFail($order, $title);
|
||||
} else {
|
||||
WechatTemplateService::sendTemplate(WechatUser::where('uid', $order->uid)->value('openid'), WechatTemplateService::ORDER_REFUND_STATUS, [
|
||||
'first' => '很抱歉您的订单退款失败,失败原因:' . $data,
|
||||
@ -1194,16 +1207,19 @@ HTML;
|
||||
* @param int $uid
|
||||
* @return int|string
|
||||
*/
|
||||
public static function getOrderCount($uid = 0){
|
||||
public static function getOrderCount($uid = 0)
|
||||
{
|
||||
if (!$uid) return 0;
|
||||
return self::where('uid', $uid)->where('paid', 1)->where('refund_status', 0)->where('status', 2)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取已支付的订单
|
||||
* @param int $is_promoter
|
||||
* @return int|string
|
||||
*/
|
||||
public static function getOrderPayCount($is_promoter = 0){
|
||||
public static function getOrderPayCount($is_promoter = 0)
|
||||
{
|
||||
return self::where('o.paid', 1)->alias('o')->join('User u', 'u.uid=o.uid')->where('u.is_promoter', $is_promoter)->count();
|
||||
}
|
||||
|
||||
@ -1212,7 +1228,8 @@ HTML;
|
||||
* @param int $is_promoter
|
||||
* @return int|string
|
||||
*/
|
||||
public static function getOrderPayMonthCount($is_promoter = 0){
|
||||
public static function getOrderPayMonthCount($is_promoter = 0)
|
||||
{
|
||||
return self::where('o.paid', 1)->alias('o')->whereTime('o.pay_time', 'last month')->join('User u', 'u.uid=o.uid')->where('u.is_promoter', $is_promoter)->count();
|
||||
}
|
||||
|
||||
@ -1220,21 +1237,24 @@ HTML;
|
||||
* @param $order
|
||||
* @return bool
|
||||
*/
|
||||
public static function gainUserIntegral($order)
|
||||
public static function gainUserIntegral($order, bool $open = true)
|
||||
{
|
||||
if ($order['gain_integral'] > 0) {
|
||||
$userInfo = User::get($order['uid']);
|
||||
BaseModel::beginTrans();
|
||||
$res1 = false != User::where('uid',$userInfo['uid'])->update(['integral'=>bcadd($userInfo['integral'],$order['gain_integral'],2)]);
|
||||
$open && BaseModel::beginTrans();
|
||||
$integral = bcadd($userInfo['integral'], $order['gain_integral'], 2);
|
||||
$res1 = false != User::where('uid', $userInfo['uid'])->update(['integral' => $integral]);
|
||||
$res2 = false != UserBill::income('购买商品赠送积分', $order['uid'], 'integral', 'gain', $order['gain_integral'], $order['id'], bcadd($userInfo['integral'], $order['gain_integral'], 2), '购买商品赠送' . floatval($order['gain_integral']) . '积分');
|
||||
$res = $res1 && $res2;
|
||||
BaseModel::checkTrans($res);
|
||||
$open && BaseModel::checkTrans($res);
|
||||
RoutineTemplate::sendUserIntegral($order['uid'], $order, $order['gain_integral'], $integral);
|
||||
return $res;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function integralBack($id){
|
||||
public static function integralBack($id)
|
||||
{
|
||||
$order = self::get($id)->toArray();
|
||||
if (!(float)bcsub($order['use_integral'], 0, 2) && !$order['back_integral']) return true;
|
||||
if ($order['back_integral'] && !(int)$order['use_integral']) return true;
|
||||
|
||||
@ -151,3 +151,30 @@ if (!function_exists('sysData')) {
|
||||
return app('sysGroupData')->getData($name);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('sys_config')) {
|
||||
/**
|
||||
* 获取系统单个配置
|
||||
* @param string $name
|
||||
* @return string | null
|
||||
*/
|
||||
function sys_config(string $name)
|
||||
{
|
||||
if (empty($name))
|
||||
return null;
|
||||
|
||||
return app('sysConfig')->get($name);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('sys_data')) {
|
||||
/**
|
||||
* 获取系统单个配置
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
function sys_data($name)
|
||||
{
|
||||
return app('sysGroupData')->getData($name);
|
||||
}
|
||||
}
|
||||
@ -76,8 +76,8 @@ class StoreOrder extends BaseModel
|
||||
*/
|
||||
public static function getOrderPriceGroup($cartInfo)
|
||||
{
|
||||
$storePostage = floatval(sysConfig('store_postage')) ?: 0;//邮费基础价
|
||||
$storeFreePostage = floatval(sysConfig('store_free_postage')) ?: 0;//满额包邮
|
||||
$storePostage = floatval(sys_config('store_postage')) ?: 0;//邮费基础价
|
||||
$storeFreePostage = floatval(sys_config('store_free_postage')) ?: 0;//满额包邮
|
||||
$totalPrice = self::getOrderSumPrice($cartInfo, 'truePrice');//获取订单总金额
|
||||
$costPrice = self::getOrderSumPrice($cartInfo, 'costPrice');//获取订单成本价
|
||||
$vipPrice = self::getOrderSumPrice($cartInfo, 'vip_truePrice');//获取订单会员优惠金额
|
||||
@ -118,8 +118,8 @@ class StoreOrder extends BaseModel
|
||||
*/
|
||||
public static function getCombinationOrderPriceGroup($cartInfo)
|
||||
{
|
||||
$storePostage = floatval(sysConfig('store_postage')) ?: 0;
|
||||
$storeFreePostage = floatval(sysConfig('store_free_postage')) ?: 0;
|
||||
$storePostage = floatval(sys_config('store_postage')) ?: 0;
|
||||
$storeFreePostage = floatval(sys_config('store_free_postage')) ?: 0;
|
||||
$totalPrice = self::getCombinationOrderTotalPrice($cartInfo);
|
||||
$costPrice = self::getCombinationOrderTotalPrice($cartInfo);
|
||||
if (!$storeFreePostage) {
|
||||
@ -221,7 +221,7 @@ class StoreOrder extends BaseModel
|
||||
self::beginTrans();
|
||||
try {
|
||||
$shipping_type = (int)$shipping_type;
|
||||
$offlinePayStatus = (int)sysConfig('offline_pay_status') ?? (int)2;
|
||||
$offlinePayStatus = (int)sys_config('offline_pay_status') ?? (int)2;
|
||||
if ($offlinePayStatus == 2) unset(self::$payType['offline']);
|
||||
if (!array_key_exists($payType, self::$payType)) return self::setErrorInfo('选择支付方式有误!', true);
|
||||
if (self::be(['unique' => $key, 'uid' => $uid])) return self::setErrorInfo('请勿重复提交订单', true);
|
||||
@ -286,7 +286,7 @@ class StoreOrder extends BaseModel
|
||||
if (!$res1) return self::setErrorInfo('使用优惠劵失败!', true);
|
||||
|
||||
//$shipping_type = 1 快递发货 $shipping_type = 2 门店自提
|
||||
$store_self_mention = sysConfig('store_self_mention') ?? 0;
|
||||
$store_self_mention = sys_config('store_self_mention') ?? 0;
|
||||
if (!$store_self_mention) $shipping_type = 1;
|
||||
if ($shipping_type === 1) {
|
||||
//是否包邮
|
||||
@ -536,7 +536,8 @@ class StoreOrder extends BaseModel
|
||||
}
|
||||
if ($title) $title = substr($title, 0, strlen($title) - 1);
|
||||
unset($item);
|
||||
}catch (\Exception $e){}
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
return $title;
|
||||
}
|
||||
|
||||
@ -544,7 +545,8 @@ class StoreOrder extends BaseModel
|
||||
* 获取门店自提唯一核销码
|
||||
* @return bool|string
|
||||
*/
|
||||
public static function getStoreCode(){
|
||||
public static function getStoreCode()
|
||||
{
|
||||
list($msec, $sec) = explode(' ', microtime());
|
||||
$num = bcadd(time(), mt_rand(10, 999999), 0) . '' . substr($msec, 2, 3);//生成随机数
|
||||
if (strlen($num) < 12)
|
||||
@ -576,7 +578,7 @@ class StoreOrder extends BaseModel
|
||||
if ($orderInfo['pay_price'] <= 0) exception('该支付无需支付!');
|
||||
$openid = WechatUser::getOpenId($orderInfo['uid']);
|
||||
$bodyContent = self::getProductTitle($orderInfo['cart_id']);
|
||||
$site_name = sysConfig('site_name');
|
||||
$site_name = sys_config('site_name');
|
||||
if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
|
||||
return MiniProgramService::jsPay($openid, $orderInfo['order_id'], $orderInfo['pay_price'], 'productr', self::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30));
|
||||
}
|
||||
@ -601,7 +603,7 @@ class StoreOrder extends BaseModel
|
||||
if ($orderInfo['pay_price'] <= 0) exception('该支付无需支付!');
|
||||
$openid = WechatUser::uidToOpenid($orderInfo['uid'], 'openid');
|
||||
$bodyContent = self::getProductTitle($orderInfo['cart_id']);
|
||||
$site_name = sysConfig('site_name');
|
||||
$site_name = sys_config('site_name');
|
||||
if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
|
||||
return WechatService::jsPay($openid, $orderInfo['order_id'], $orderInfo['pay_price'], 'product', self::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30));
|
||||
}
|
||||
@ -625,7 +627,7 @@ class StoreOrder extends BaseModel
|
||||
if ($orderInfo['paid']) exception('支付已支付!');
|
||||
if ($orderInfo['pay_price'] <= 0) exception('该支付无需支付!');
|
||||
$bodyContent = self::getProductTitle($orderInfo['cart_id']);
|
||||
$site_name = sysConfig('site_name');
|
||||
$site_name = sys_config('site_name');
|
||||
if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
|
||||
return WechatService::paymentPrepare(null, $orderInfo['order_id'], $orderInfo['pay_price'], 'product', self::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30), '', 'MWEB');
|
||||
}
|
||||
@ -716,13 +718,7 @@ class StoreOrder extends BaseModel
|
||||
return self::setErrorInfo('申请退款失败!');
|
||||
else {
|
||||
try {
|
||||
$adminIds = sysConfig('site_store_admin_uids');
|
||||
if (!empty($adminIds)) {
|
||||
if (!($adminList = array_unique(array_filter(explode(',', trim($adminIds)))))) {
|
||||
return self::setErrorInfo('申请退款成功,');
|
||||
}
|
||||
//小程序 发送模板消息
|
||||
RoutineTemplate::sendOrderRefundStatus($order, $refundReasonWap, $adminList);
|
||||
if (in_array($order['is_channel'], [0, 2])) {
|
||||
//公众号发送模板消息
|
||||
WechatTemplateService::sendAdminNoticeTemplate([
|
||||
'first' => "亲,您有一个新订单 \n订单号:{$order['order_id']}",
|
||||
@ -732,8 +728,13 @@ class StoreOrder extends BaseModel
|
||||
'remark' => '请及时处理'
|
||||
]);
|
||||
}
|
||||
if (in_array($order['is_channel'], [1, 2])) {
|
||||
//小程序 发送模板消息
|
||||
RoutineTemplate::sendOrderRefundStatus($order, $refundReasonWap);
|
||||
}
|
||||
ChannelService::instance()->send('NEW_REFUND_ORDER', ['order_id' => $order['order_id']]);
|
||||
}catch (\Exception $e){}
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
event('ShortMssageSend', [$order['order_id'], 'AdminRefund']);
|
||||
return true;
|
||||
}
|
||||
@ -808,28 +809,10 @@ class StoreOrder extends BaseModel
|
||||
public static function orderPostageAfter($postageData, $oid)
|
||||
{
|
||||
$order = self::where('id', $oid)->find();
|
||||
$url = '/pages/order_details/index?order_id=' . $order['order_id'];
|
||||
$group = [
|
||||
'first' => '亲,您的订单已发货,请注意查收',
|
||||
'remark' => '点击查看订单详情'
|
||||
];
|
||||
if ($postageData['delivery_type'] == 'send') {//送货
|
||||
$goodsName = StoreOrderCartInfo::getProductNameList($order['id']);
|
||||
$group = array_merge($group, [
|
||||
'keyword1' => $goodsName,
|
||||
'keyword2' => $order['pay_type'] == 'offline' ? '线下支付' : date('Y/m/d H:i', $order['pay_time']),
|
||||
'keyword3' => $order['user_address'],
|
||||
'keyword4' => $postageData['delivery_name'],
|
||||
'keyword5' => $postageData['delivery_id']
|
||||
]);
|
||||
RoutineTemplate::sendOut('ORDER_DELIVER_SUCCESS', $order['uid'], $group, $url);
|
||||
RoutineTemplate::sendOrderPostage($order);
|
||||
} else if ($postageData['delivery_type'] == 'express') {//发货
|
||||
$group = array_merge($group, [
|
||||
'keyword1' => $order['order_id'],
|
||||
'keyword2' => $postageData['delivery_name'],
|
||||
'keyword3' => $postageData['delivery_id']
|
||||
]);
|
||||
RoutineTemplate::sendOut('ORDER_POSTAGE_SUCCESS', $order['uid'], $group, $url);
|
||||
RoutineTemplate::sendOrderPostage($order, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -840,12 +823,7 @@ class StoreOrder extends BaseModel
|
||||
{
|
||||
$title = self::getProductTitle($order['cart_id']);
|
||||
if ($order['is_channel'] == 1) {//小程序
|
||||
RoutineTemplate::sendOut('OREDER_TAKEVER', $order['uid'], [
|
||||
'keyword1' => $order['order_id'],
|
||||
'keyword2' => $title,
|
||||
'keyword3' => $order['pay_price'],
|
||||
'keyword4' => date('Y-m-d H:i:s', time()),
|
||||
]);
|
||||
RoutineTemplate::sendOrderTakeOver($order, $title);
|
||||
} else {
|
||||
$openid = WechatUser::where('uid', $order['uid'])->value('openid');
|
||||
\crmeb\services\WechatTemplateService::sendTemplate($openid, \crmeb\services\WechatTemplateService::ORDER_TAKE_SUCCESS, [
|
||||
@ -1018,7 +996,11 @@ class StoreOrder extends BaseModel
|
||||
} else {//TODO 发货
|
||||
$status['_type'] = 2;
|
||||
$status['_title'] = '待收货';
|
||||
$status['_msg'] = date('m月d日H时i分', StoreOrderStatus::getTime($order['id'], 'delivery_goods')) . '服务商已发货';
|
||||
if($order['delivery_type'] == 'fictitious')
|
||||
$_time = StoreOrderStatus::getTime($order['id'], 'delivery_fictitious');
|
||||
else
|
||||
$_time = StoreOrderStatus::getTime($order['id'], 'delivery_goods');
|
||||
$status['_msg'] = date('m月d日H时i分', $_time) . '服务商已发货';
|
||||
$status['_class'] = 'state-ysh';
|
||||
}
|
||||
} else if ($order['status'] == 2) {
|
||||
@ -1050,7 +1032,7 @@ class StoreOrder extends BaseModel
|
||||
}
|
||||
}
|
||||
}
|
||||
$order['offlinePayStatus'] = (int)sysConfig('offline_pay_status') ?? (int)2;
|
||||
$order['offlinePayStatus'] = (int)sys_config('offline_pay_status') ?? (int)2;
|
||||
return $order;
|
||||
}
|
||||
|
||||
@ -1565,7 +1547,7 @@ class StoreOrder extends BaseModel
|
||||
public static function startTakeOrder()
|
||||
{
|
||||
//7天前时间戳
|
||||
$systemDeliveryTime = sysConfig('system_delivery_time') ?? 0;
|
||||
$systemDeliveryTime = sys_config('system_delivery_time') ?? 0;
|
||||
//0为取消自动收货功能
|
||||
if ($systemDeliveryTime == 0) return true;
|
||||
$sevenDay = strtotime(date('Y-m-d H:i:s', strtotime('-' . $systemDeliveryTime . ' day')));
|
||||
@ -1589,7 +1571,7 @@ class StoreOrder extends BaseModel
|
||||
else continue;
|
||||
if (!self::edit($data, $item, 'id')) continue;
|
||||
try {
|
||||
OrderRepository::storeProductOrderTakeDeliveryAdmin($order, $item);
|
||||
OrderRepository::storeProductOrderTakeDeliveryTimer($order);
|
||||
$res = $res && true;
|
||||
} catch (\Exception $e) {
|
||||
$res = $res && false;
|
||||
@ -1640,7 +1622,8 @@ class StoreOrder extends BaseModel
|
||||
* @param $where
|
||||
* @return mixed
|
||||
*/
|
||||
public static function orderList($where){
|
||||
public static function orderList($where)
|
||||
{
|
||||
$model = self::getOrderWhere($where, self::alias('a')->join('user r', 'r.uid=a.uid', 'LEFT'), 'a.', 'r')->field('a.id,a.order_id,a.add_time,a.status,a.total_num,a.total_price,a.total_postage,a.pay_price,a.pay_postage,a.paid,a.refund_status,a.remark,a.pay_type');
|
||||
if ($where['order'] != '') {
|
||||
$model = $model->order(self::setOrder($where['order']));
|
||||
@ -1879,7 +1862,8 @@ class StoreOrder extends BaseModel
|
||||
* @param string $join
|
||||
* @return StoreOrder|null
|
||||
*/
|
||||
public static function getOrderWhere($where, $model, $aler = '', $join = ''){
|
||||
public static function getOrderWhere($where, $model, $aler = '', $join = '')
|
||||
{
|
||||
if (isset($where['status']) && $where['status'] != '') $model = self::statusWhere($where['status'], $model, $aler);
|
||||
if (isset($where['is_del']) && $where['is_del'] != '' && $where['is_del'] != -1) $model = $model->where($aler . 'is_del', $where['is_del']);
|
||||
if (isset($where['combination_id'])) {
|
||||
@ -2043,7 +2027,8 @@ class StoreOrder extends BaseModel
|
||||
* @param $id
|
||||
* @return $this
|
||||
*/
|
||||
public static function updateOffline($id){
|
||||
public static function updateOffline($id)
|
||||
{
|
||||
$count = self::where('id', $id)->count();
|
||||
if (!$count) return self::setErrorInfo('订单不存在');
|
||||
$count = self::where('id', $id)->where('paid', 0)->count();
|
||||
|
||||
@ -114,7 +114,7 @@ class User extends BaseModel
|
||||
'last_ip' => request()->ip(),
|
||||
];
|
||||
//TODO 获取后台分销类型
|
||||
$storeBrokerageStatus = sysConfig('store_brokerage_statu');
|
||||
$storeBrokerageStatus = sys_config('store_brokerage_statu');
|
||||
$storeBrokerageStatus = $storeBrokerageStatus ? $storeBrokerageStatus : 1;
|
||||
if (isset($wechatUser['code']) && $wechatUser['code'] && $wechatUser['code'] != $uid && $uid != self::where('uid', $wechatUser['code'])->value('spread_uid')) {
|
||||
if ($storeBrokerageStatus == 1) {
|
||||
@ -155,7 +155,7 @@ class User extends BaseModel
|
||||
if ($spread == $uid) return true;
|
||||
if ($uid == self::where('uid', $spread)->value('spread_uid')) return true;
|
||||
//TODO 获取后台分销类型
|
||||
$storeBrokerageStatus = sysConfig('store_brokerage_statu');
|
||||
$storeBrokerageStatus = sys_config('store_brokerage_statu');
|
||||
$storeBrokerageStatus = $storeBrokerageStatus ? $storeBrokerageStatus : 1;
|
||||
if ($storeBrokerageStatus == 1) {
|
||||
$spreadCount = self::where('uid', $spread)->count();
|
||||
@ -183,7 +183,7 @@ class User extends BaseModel
|
||||
self::beginTrans();
|
||||
$res1 = true;
|
||||
if ($spread_uid) $res1 = self::where('uid', $spread_uid)->inc('spread_count', 1)->update();
|
||||
// $storeBrokerageStatu = sysConfig('store_brokerage_statu') ? : 1;//获取后台分销类型
|
||||
// $storeBrokerageStatu = sys_config('store_brokerage_statu') ? : 1;//获取后台分销类型
|
||||
$res2 = self::create([
|
||||
'account' => 'rt' . $routineUser['uid'] . time(),
|
||||
'pwd' => md5(123456),
|
||||
@ -242,7 +242,7 @@ class User extends BaseModel
|
||||
public static function isUserSpread($uid = 0)
|
||||
{
|
||||
if (!$uid) return false;
|
||||
$status = (int)sysConfig('store_brokerage_statu');
|
||||
$status = (int)sys_config('store_brokerage_statu');
|
||||
$isPromoter = true;
|
||||
if ($status == 1) $isPromoter = self::where('uid', $uid)->value('is_promoter');
|
||||
if ($isPromoter) return true;
|
||||
@ -259,7 +259,7 @@ class User extends BaseModel
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function backOrderBrokerage($orderInfo)
|
||||
public static function backOrderBrokerage($orderInfo,bool $open = true)
|
||||
{
|
||||
//TODO 如果时营销产品不返佣金
|
||||
if (isset($orderInfo['combination_id']) && $orderInfo['combination_id']) return true;
|
||||
@ -272,14 +272,14 @@ class User extends BaseModel
|
||||
//TODO 当前用户不存在 没有上级 或者 当用用户上级时自己 直接返回
|
||||
if (!$userInfo || !$userInfo['spread_uid'] || $userInfo['spread_uid'] == $orderInfo['uid']) return true;
|
||||
//TODO 获取后台分销类型 1 指定分销 2 人人分销
|
||||
$storeBrokerageStatus = sysConfig('store_brokerage_statu');
|
||||
$storeBrokerageStatus = sys_config('store_brokerage_statu');
|
||||
$storeBrokerageStatus = $storeBrokerageStatus ? $storeBrokerageStatus : 1;
|
||||
//TODO 指定分销 判断 上级是否时推广员 如果不是推广员直接跳转二级返佣
|
||||
if ($storeBrokerageStatus == 1) {
|
||||
if (!User::be(['uid' => $userInfo['spread_uid'], 'is_promoter' => 1])) return self::backOrderBrokerageTwo($orderInfo);
|
||||
if (!User::be(['uid' => $userInfo['spread_uid'], 'is_promoter' => 1])) return self::backOrderBrokerageTwo($orderInfo,$open);
|
||||
}
|
||||
//TODO 获取后台一级返佣比例
|
||||
$storeBrokerageRatio = sysConfig('store_brokerage_ratio');
|
||||
$storeBrokerageRatio = sys_config('store_brokerage_ratio');
|
||||
//TODO 一级返佣比例 小于等于零时直接返回 不返佣
|
||||
if ($storeBrokerageRatio <= 0) return true;
|
||||
//TODO 计算获取一级返佣比例
|
||||
@ -299,14 +299,14 @@ class User extends BaseModel
|
||||
//TODO 上级推广员返佣之后的金额
|
||||
$balance = bcadd($spreadUserInfo['brokerage_price'], $brokeragePrice, 2);
|
||||
$mark = $userInfo['nickname'] . '成功消费' . floatval($orderInfo['pay_price']) . '元,奖励推广佣金' . floatval($brokeragePrice);
|
||||
self::beginTrans();
|
||||
$open && self::beginTrans();
|
||||
//TODO 添加推广记录
|
||||
$res1 = UserBill::income('获得推广佣金', $userInfo['spread_uid'], 'now_money', 'brokerage', $brokeragePrice, $orderInfo['id'], $balance, $mark);
|
||||
//TODO 添加用户余额
|
||||
$res2 = self::bcInc($userInfo['spread_uid'], 'brokerage_price', $brokeragePrice, 'uid');
|
||||
//TODO 一级返佣成功 跳转二级返佣
|
||||
$res = $res1 && $res2 && self::backOrderBrokerageTwo($orderInfo);
|
||||
self::checkTrans($res);
|
||||
$res = $res1 && $res2 && self::backOrderBrokerageTwo($orderInfo,$open);
|
||||
$open && self::checkTrans($res);
|
||||
// if($res) return self::backOrderBrokerageTwo($orderInfo);
|
||||
return $res;
|
||||
}
|
||||
@ -320,7 +320,7 @@ class User extends BaseModel
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function backOrderBrokerageTwo($orderInfo)
|
||||
public static function backOrderBrokerageTwo($orderInfo,bool $open = true)
|
||||
{
|
||||
//TODO 获取购买商品的用户
|
||||
$userInfo = User::getUserInfo($orderInfo['uid']);
|
||||
@ -329,14 +329,14 @@ class User extends BaseModel
|
||||
//TODO 上推广人不存在 或者 上推广人没有上级 或者 当用用户上上级时自己 直接返回
|
||||
if (!$userInfoTwo || !$userInfoTwo['spread_uid'] || $userInfoTwo['spread_uid'] == $orderInfo['uid']) return true;
|
||||
//TODO 获取后台分销类型 1 指定分销 2 人人分销
|
||||
$storeBrokerageStatus = sysConfig('store_brokerage_statu');
|
||||
$storeBrokerageStatus = sys_config('store_brokerage_statu');
|
||||
$storeBrokerageStatus = $storeBrokerageStatus ? $storeBrokerageStatus : 1;
|
||||
//TODO 指定分销 判断 上上级是否时推广员 如果不是推广员直接返回
|
||||
if ($storeBrokerageStatus == 1) {
|
||||
if (!User::be(['uid' => $userInfoTwo['spread_uid'], 'is_promoter' => 1])) return true;
|
||||
}
|
||||
//TODO 获取二级返佣比例
|
||||
$storeBrokerageTwo = sysConfig('store_brokerage_two');
|
||||
$storeBrokerageTwo = sys_config('store_brokerage_two');
|
||||
//TODO 二级返佣比例小于等于0 直接返回
|
||||
if ($storeBrokerageTwo <= 0) return true;
|
||||
//TODO 计算获取二级返佣比例
|
||||
@ -356,13 +356,13 @@ class User extends BaseModel
|
||||
//TODO 获取上上级推广员返佣之后余额
|
||||
$balance = bcadd($spreadUserInfoTwo['brokerage_price'], $brokeragePrice, 2);
|
||||
$mark = '二级推广人' . $userInfo['nickname'] . '成功消费' . floatval($orderInfo['pay_price']) . '元,奖励推广佣金' . floatval($brokeragePrice);
|
||||
self::beginTrans();
|
||||
$open && self::beginTrans();
|
||||
//TODO 添加返佣记录
|
||||
$res1 = UserBill::income('获得推广佣金', $userInfoTwo['spread_uid'], 'now_money', 'brokerage', $brokeragePrice, $orderInfo['id'], $balance, $mark);
|
||||
//TODO 添加用户余额
|
||||
$res2 = self::bcInc($userInfoTwo['spread_uid'], 'brokerage_price', $brokeragePrice, 'uid');
|
||||
$res = $res1 && $res2;
|
||||
self::checkTrans($res);
|
||||
$open && self::checkTrans($res);
|
||||
return $res;
|
||||
}
|
||||
|
||||
@ -505,7 +505,7 @@ class User extends BaseModel
|
||||
// 自己不能绑定自己为上级
|
||||
if ($uid == $spreadUid) return false;
|
||||
//TODO 获取后台分销类型
|
||||
$storeBrokerageStatus = sysConfig('store_brokerage_statu');
|
||||
$storeBrokerageStatus = sys_config('store_brokerage_statu');
|
||||
$storeBrokerageStatus = $storeBrokerageStatus ? $storeBrokerageStatus : 1;
|
||||
if ($storeBrokerageStatus == 1) {
|
||||
$spreadCount = self::where('uid', $spreadUid)->count();
|
||||
@ -561,7 +561,7 @@ class User extends BaseModel
|
||||
$data['last_time'] = time();
|
||||
$data['last_ip'] = app('request')->ip();
|
||||
$data['nickname'] = substr(md5($account . time()), 0, 12);
|
||||
$data['avatar'] = $data['headimgurl'] = sysConfig('h5_avatar');
|
||||
$data['avatar'] = $data['headimgurl'] = sys_config('h5_avatar');
|
||||
$data['city'] = '';
|
||||
$data['language'] = '';
|
||||
$data['province'] = '';
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace crmeb\repositories;
|
||||
|
||||
use app\models\store\StoreOrder;
|
||||
@ -48,6 +49,20 @@ class OrderRepository
|
||||
if (!($res1 && $res2)) exception('收货失败!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改状态 为已收货 定时任务使用
|
||||
* @param $order
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function storeProductOrderTakeDeliveryTimer($order)
|
||||
{
|
||||
|
||||
$res1 = AdminStoreOrder::gainUserIntegral($order, false);
|
||||
$res2 = User::backOrderBrokerage($order, false);
|
||||
AdminStoreOrder::orderTakeAfter($order);
|
||||
if (!($res1 && $res2)) exception('收货失败!');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改状态为 已退款 admin模块
|
||||
@ -58,7 +73,8 @@ class OrderRepository
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function storeProductOrderRefundY($data,$oid){
|
||||
public static function storeProductOrderRefundY($data, $oid)
|
||||
{
|
||||
$order = AdminStoreOrder::where('id', $oid)->find();
|
||||
if ($order['is_channel'] == 1)
|
||||
return AdminStoreOrder::refundRoutineTemplate($oid); //TODO 小程序余额退款模板消息
|
||||
@ -84,12 +100,7 @@ class OrderRepository
|
||||
* @param $product $product 商品信息
|
||||
* @param $back_integral $back_integral 退多少积分
|
||||
*/
|
||||
public static function storeOrderIntegralBack($product,$back_integral){
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function computedOrder()
|
||||
public static function storeOrderIntegralBack($product, $back_integral)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user