diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index 5304c50..c825be5 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -51,6 +51,7 @@ use Exception; use FormBuilder\Factory\Elm; use FormBuilder\Form; use http\Exception\InvalidArgumentException; +use crmeb\jobs\OrderPartnerJob; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; @@ -81,6 +82,7 @@ class StoreOrderRepository extends BaseRepository const TYPE_SN_USER_RECHARGE = 'wxu'; const TYPE_SN_REFUND = 'rwx'; + /** * StoreOrderRepository constructor. * @param StoreOrderDao $dao @@ -530,14 +532,14 @@ class StoreOrderRepository extends BaseRepository public function userOrderNumber(int $uid) { $noPay = app()->make(StoreGroupOrderRepository::class)->orderNumber($uid); - $noPostage = $this->dao->search(['uid' => $uid, 'status' => 0, 'paid' => 1,'is_user' => 1])->where('StoreOrder.is_del', 0)->count(); - $all = $this->dao->search(['uid' => $uid, 'status' => -2,'is_user' => 1])->where('StoreOrder.is_del', 0)->count(); + $noPostage = $this->dao->search(['uid' => $uid, 'status' => 0, 'paid' => 1, 'is_user' => 1])->where('StoreOrder.is_del', 0)->count(); + $all = $this->dao->search(['uid' => $uid, 'status' => -2, 'is_user' => 1])->where('StoreOrder.is_del', 0)->count(); $noDeliver = $this->dao->search(['uid' => $uid, 'status' => 1, 'paid' => 1])->where('StoreOrder.is_del', 0)->count(); - $noComment = $this->dao->search(['uid' => $uid, 'status' => 2, 'paid' => 1,'is_user' => 1])->where('StoreOrder.is_del', 0)->count(); - $done = $this->dao->search(['uid' => $uid, 'status' => 3, 'paid' => 1,'is_user' => 1])->where('StoreOrder.is_del', 0)->count(); + $noComment = $this->dao->search(['uid' => $uid, 'status' => 2, 'paid' => 1, 'is_user' => 1])->where('StoreOrder.is_del', 0)->count(); + $done = $this->dao->search(['uid' => $uid, 'status' => 3, 'paid' => 1, 'is_user' => 1])->where('StoreOrder.is_del', 0)->count(); $refund = app()->make(StoreRefundOrderRepository::class)->getWhereCount(['uid' => $uid, 'status' => [0, 1, 2]]); //$orderPrice = $this->dao->search(['uid' => $uid, 'paid' => 1])->sum('pay_price'); - $orderCount = $this->dao->search(['uid' => $uid, 'paid' => 1,'is_user' => 1])->count(); + $orderCount = $this->dao->search(['uid' => $uid, 'paid' => 1, 'is_user' => 1])->count(); return compact('noComment', 'done', 'refund', 'noDeliver', 'noPay', 'noPostage', 'orderCount', 'all'); } @@ -717,7 +719,7 @@ class StoreOrderRepository extends BaseRepository if ($order['status'] != 1 || $order['order_type']) throw new ValidateException('订单状态有误'); $func = 'createUserLog'; - if (!$user){ + if (!$user) { $func = 'createSysLog'; $user = $order->user; } @@ -737,12 +739,14 @@ class StoreOrderRepository extends BaseRepository 'change_message' => '已收货', 'change_type' => $storeOrderStatusRepository::ORDER_STATUS_TAKE, ]; - Db::transaction(function () use ($order, $user,$storeOrderStatusRepository,$orderStatus,$func) { + Db::transaction(function () use ($order, $user, $storeOrderStatusRepository, $orderStatus, $func) { $this->takeAfter($order, $user); $order->save(); $storeOrderStatusRepository->{$func}($orderStatus); }); event('order.take', compact('order')); + //推送到贡献值结算队列 + Queue::push(OrderPartnerJob::class, compact('order')); } @@ -959,7 +963,7 @@ class StoreOrderRepository extends BaseRepository 'change_type' => $storeOrderStatusRepository::ORDER_STATUS_CHANGE, ]; - Db::transaction(function () use ($id, $data, $orderGroup, $order, $_group,$storeOrderStatusRepository,$orderStatus,$service_id) { + Db::transaction(function () use ($id, $data, $orderGroup, $order, $_group, $storeOrderStatusRepository, $orderStatus, $service_id) { $orderGroup->total_price = $_group['total_price']; $orderGroup->pay_price = $_group['pay_price']; $orderGroup->pay_postage = $_group['pay_postage']; @@ -970,7 +974,7 @@ class StoreOrderRepository extends BaseRepository $this->changOrderProduct($id, $data); if ($service_id) { - $storeOrderStatusRepository->createServiceLog($service_id,$orderStatus); + $storeOrderStatusRepository->createServiceLog($service_id, $orderStatus); } else { $storeOrderStatusRepository->createAdminLog($orderStatus); } @@ -1109,7 +1113,7 @@ class StoreOrderRepository extends BaseRepository 'mer_id' => $merId ]; - if (!$ret || $ret['status'] != 1 || $ret['mer_id'] != $merId || $ret['is_del'] != 0 || $ret['paid'] != 1 || $ret['delivery_type'] != 0 ) { + if (!$ret || $ret['status'] != 1 || $ret['mer_id'] != $merId || $ret['is_del'] != 0 || $ret['paid'] != 1 || $ret['delivery_type'] != 0) { $imp['status'] = 0; $imp['mark'] = '订单信息不存在或状态错误'; } else { @@ -1127,7 +1131,7 @@ class StoreOrderRepository extends BaseRepository $imp['delivery_id'] = $ret['delivery_id']; $imp['delivery_name'] = $ret['delivery_name']; } else { - $this->delivery($item, $merId,[ + $this->delivery($item, $merId, [ 'delivery_id' => $params['delivery_id'], 'delivery_type' => $params['delivery_type'], 'delivery_name' => $params['delivery_name'], @@ -1185,7 +1189,7 @@ class StoreOrderRepository extends BaseRepository 'to_name' => $data['to_name'], ]; Db::transaction(function () use ($merId, $id, $delivery, $make, $dump, $service_id) { - $this->delivery($id, $merId, $delivery,$service_id); + $this->delivery($id, $merId, $delivery, $service_id); $arr = [ 'type' => 'mer_dump', 'num' => -1, @@ -1197,22 +1201,22 @@ class StoreOrderRepository extends BaseRepository return $delivery; } - public function runDelivery($id, $merId, $data, $split, $method,$service_id = 0) + public function runDelivery($id, $merId, $data, $split, $method, $service_id = 0) { - return Db::transaction(function () use ($id, $merId, $data, $split, $method,$service_id) { + return Db::transaction(function () use ($id, $merId, $data, $split, $method, $service_id) { if ($split['is_split'] && !empty($split['split'])) { foreach ($split['split'] as $v) { $splitData[$v['id']] = $v['num']; } $order = $this->dao->get($id); - $newOrder = app()->make(StoreOrderSplitRepository::class)->splitOrder($order, $splitData,$service_id); - if ($newOrder){ + $newOrder = app()->make(StoreOrderSplitRepository::class)->splitOrder($order, $splitData, $service_id); + if ($newOrder) { $id = $newOrder->order_id; } else { throw new ValidateException('商品不能全部拆单'); } } - return $this->{$method}($id, $merId, $data,$service_id); + return $this->{$method}($id, $merId, $data, $service_id); }); } @@ -1273,17 +1277,17 @@ class StoreOrderRepository extends BaseRepository 'change_type' => $change_type, ]; if ($service_id) { - $statusRepository->createServiceLog($service_id,$orderStatus); + $statusRepository->createServiceLog($service_id, $orderStatus); } else { $statusRepository->createAdminLog($orderStatus); } //虚拟发货后用户直接确认收获 - if($data['status'] == 2){ + if ($data['status'] == 2) { $user = app()->make(UserRepository::class)->get($order['uid']); //订单记录 - $this->takeAfter($order,$user); + $this->takeAfter($order, $user); $orderStatus = [ 'order_id' => $order->order_id, 'order_sn' => $order->order_sn, @@ -1317,7 +1321,7 @@ class StoreOrderRepository extends BaseRepository $make->create($id, $merId, $data, $order); //订单记录 $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class); - $this->dao->update($id, ['delivery_type' => 5, 'status' => 1,'remark' => $data['remark']]); + $this->dao->update($id, ['delivery_type' => 5, 'status' => 1, 'remark' => $data['remark']]); $orderStatus = [ 'order_id' => $id, @@ -1327,7 +1331,7 @@ class StoreOrderRepository extends BaseRepository 'change_type' => $storeOrderStatusRepository::ORDER_DELIVERY_SELF, ]; if ($service_id) { - $storeOrderStatusRepository->createServiceLog($service_id,$orderStatus); + $storeOrderStatusRepository->createServiceLog($service_id, $orderStatus); } else { $storeOrderStatusRepository->createAdminLog($orderStatus); } @@ -1344,20 +1348,20 @@ class StoreOrderRepository extends BaseRepository $whre['is_system_del'] = 0; } $res = $this->dao->getWhere($where, '*', [ - 'orderProduct', - 'user' => function ($query) { - $query->field('uid,real_name,nickname,is_svip,svip_endtime,phone'); - }, - 'refundOrder' => function ($query) { - $query->field('order_id,extension_one,extension_two,refund_price,integral')->where('status', 3); - }, - 'finalOrder', - 'TopSpread' => function ($query) { - $query->field('uid,nickname,avatar'); - }, - 'spread' => function ($query) { - $query->field('uid,nickname,avatar'); - }, + 'orderProduct', + 'user' => function ($query) { + $query->field('uid,real_name,nickname,is_svip,svip_endtime,phone'); + }, + 'refundOrder' => function ($query) { + $query->field('order_id,extension_one,extension_two,refund_price,integral')->where('status', 3); + }, + 'finalOrder', + 'TopSpread' => function ($query) { + $query->field('uid,nickname,avatar'); + }, + 'spread' => function ($query) { + $query->field('uid,nickname,avatar'); + }, ] ); if (!$res) throw new ValidateException('数据不存在'); @@ -1473,17 +1477,17 @@ class StoreOrderRepository extends BaseRepository ]); $count = $query->count(); $list = $query->page($page, $limit)->select()->append(['refund_extension_one', 'refund_extension_two']) - ->each(function($item){ + ->each(function ($item) { // 1:退款中 2:部分退款 3 = 全退 $refunding = 0; if ($item['orderProduct']) { - $is_refund = array_column($item['orderProduct']->toArray(),'is_refund'); + $is_refund = array_column($item['orderProduct']->toArray(), 'is_refund'); $is_refund = array_unique($is_refund); - if (in_array(1,$is_refund)) { + if (in_array(1, $is_refund)) { $refunding = 1; - } else if (in_array(2,$is_refund)) { + } else if (in_array(2, $is_refund)) { $refunding = 2; - } else if (in_array(3,$is_refund)) { + } else if (in_array(3, $is_refund)) { $refunding = 3; } } @@ -1659,7 +1663,7 @@ class StoreOrderRepository extends BaseRepository unset($order['takeOrderList']); } - return compact( 'count','list'); + return compact('count', 'list'); } public function userList($uid, $page, $limit) @@ -1779,17 +1783,17 @@ class StoreOrderRepository extends BaseRepository } $data = [ - 'order_sn' => $order['order_sn'], + 'order_sn' => $order['order_sn'], 'order_type' => $order['order_type'], - 'pay_time' => $order['pay_time'], - 'real_name' => $order['real_name'], + 'pay_time' => $order['pay_time'], + 'real_name' => $order['real_name'], 'user_phone' => $order['user_phone'], 'user_address' => $order['user_address'], - 'total_price' => $order['total_price'], + 'total_price' => $order['total_price'], 'coupon_price' => $order['coupon_price'], - 'pay_price' => $order['pay_price'], + 'pay_price' => $order['pay_price'], 'total_postage' => $order['total_postage'], - 'pay_postage' => $order['pay_postage'], + 'pay_postage' => $order['pay_postage'], 'mark' => $order['mark'], ]; @@ -1810,7 +1814,7 @@ class StoreOrderRepository extends BaseRepository public function verifyOrder(int $id, int $merId, array $data, $serviceId = 0) { - $order = $this->dao->getWhere(['order_id' => $id, 'mer_id' => $merId,'verify_code' => $data['verify_code'],'order_type' => 1],'*',['orderProduct']); + $order = $this->dao->getWhere(['order_id' => $id, 'mer_id' => $merId, 'verify_code' => $data['verify_code'], 'order_type' => 1], '*', ['orderProduct']); if (!$order) throw new ValidateException('订单不存在'); if (!$order->paid) throw new ValidateException('订单未支付'); if ($order['status']) throw new ValidateException('订单已全部核销,请勿重复操作'); @@ -1825,7 +1829,7 @@ class StoreOrderRepository extends BaseRepository event('order.verify.before', compact('order')); //订单记录 $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class); - Db::transaction(function () use ($order,$storeOrderStatusRepository,$serviceId) { + Db::transaction(function () use ($order, $storeOrderStatusRepository, $serviceId) { $this->takeAfter($order, $order->user); $order->save(); $orderStatus = [ @@ -1835,8 +1839,8 @@ class StoreOrderRepository extends BaseRepository 'change_message' => '订单已核销', 'change_type' => $storeOrderStatusRepository::ORDER_STATUS_TAKE, ]; - if ($serviceId){ - $storeOrderStatusRepository->createServiceLog($serviceId,$orderStatus); + if ($serviceId) { + $storeOrderStatusRepository->createServiceLog($serviceId, $orderStatus); } else { $storeOrderStatusRepository->createAdminLog($orderStatus); } @@ -2079,7 +2083,7 @@ class StoreOrderRepository extends BaseRepository 'change_type' => $storeOrderStatusRepository::ORDER_STATUS_DELETE, ]; $productRepository = app()->make(ProductRepository::class); - Db::transaction(function () use ($info, $order, $orderStatus, $storeOrderStatusRepository,$productRepository) { + Db::transaction(function () use ($info, $order, $orderStatus, $storeOrderStatusRepository, $productRepository) { $order->is_del = 1; $order->save(); $storeOrderStatusRepository->createUserLog($orderStatus); @@ -2263,17 +2267,17 @@ class StoreOrderRepository extends BaseRepository * @author Qinii * @day 2023/2/22 */ - public function childrenList($id,$merId) + public function childrenList($id, $merId) { $data = $this->dao->get($id); - $query = $this->dao->getSearch([])->with(['orderProduct'])->where('order_id','<>',$id); - if ($merId) $query->where('mer_id',$merId); + $query = $this->dao->getSearch([])->with(['orderProduct'])->where('order_id', '<>', $id); + if ($merId) $query->where('mer_id', $merId); if ($data['main_id']) { - $query->where(function($query) use($data,$id){ - $query->where('main_id',$data['main_id'])->whereOr('order_id',$data['main_id']); + $query->where(function ($query) use ($data, $id) { + $query->where('main_id', $data['main_id'])->whereOr('order_id', $data['main_id']); }); } else { - $query->where('main_id',$id); + $query->where('main_id', $id); } return $query->select(); } diff --git a/crmeb/jobs/OrderPartnerJob.php b/crmeb/jobs/OrderPartnerJob.php new file mode 100644 index 0000000..89df5f6 --- /dev/null +++ b/crmeb/jobs/OrderPartnerJob.php @@ -0,0 +1,42 @@ + +// +---------------------------------------------------------------------- + + +namespace crmeb\jobs; + +use crmeb\interfaces\JobInterface; +use think\facade\Log; +use think\queue\Job; +use crmeb\services\ExcelService; + +class OrderPartnerJob implements JobInterface +{ + + public function fire($job, $data) + { + try{ + //查询商品类型 -报单区 100% 其他 66.7% + //查询合作人角色是否包含此商品品牌 + //查询合作人橘色是否包含此商品行业 + //查询所属区域角色 + //查询通用角色 + }catch (\Exception $e){ + Log::info('订单角色贡献值处理失败; error : ' . $e->getMessage()); + } + $job->delete(); + } + + public function failed($data) + { + // TODO: Implement failed() method. + } +}