diff --git a/app/common/dao/store/consumption/CommissionDao.php b/app/common/dao/store/consumption/CommissionDao.php index abc21656..79e49781 100644 --- a/app/common/dao/store/consumption/CommissionDao.php +++ b/app/common/dao/store/consumption/CommissionDao.php @@ -133,7 +133,7 @@ class CommissionDao * 请求发送给供应商平台后异步回调 * @param $order * @param $promotionCode - * @param int $type 类型:1=>推广人,2=>镇合伙人 + * @param int $type 类型:1=>小组,2=>村合伙人,3=>镇合伙人,4=>配送员 * @return void */ public function sendCommission($order, $promotionCode, $type = 1) @@ -141,15 +141,17 @@ class CommissionDao $curl = new Curl(); $timestamp = time(); $json = ['timestamp' => $timestamp, 'data' => ['order_id' => $order['order_id'], 'order_sn' => $order['order_no'], 'order_money' => bcmul($order['pay_price'], 100), 'promotion_code' => $promotionCode]]; - if ($type == 2) { + if ($type == 3) { $json['street_code'] = $promotionCode; + } elseif ($type == 4) { + $json['courier_phone'] = $promotionCode; } else { $json['promotion_code'] = $promotionCode; } $aes = new \AES(); $iv = $aes->buildIv($timestamp); $encrypt = $aes->encrypt($json, $iv); - $api = $type == 1 ? 'user_first_order_share_profit' : 'user_order_share_profit'; + $api = in_array($type, [1, 2]) ? 'user_first_order_share_profit' : 'user_order_share_profit'; $url = env('task.worker_host_url') . '/api/shop_call/' . $api; $curl->post($url, ['timestamp' => $timestamp, 'data' => $encrypt]); } diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index f04d4be5..7db41939 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -274,6 +274,7 @@ class StoreOrderRepository extends BaseRepository // 订单的类型 0 发货 1 自提 if ($order->order_type == 1 && $order->status != 10) { $order->verify_code = $this->verifyCode(); + $order->logistics_code = random_int(1000, 9999); } $order->save(); $orderStatus[] = [ @@ -507,7 +508,10 @@ class StoreOrderRepository extends BaseRepository $finance = (new CommissionDao())->firstOrderCommission($order, $finance, $financeSn . ($i++)); $addressCode = explode(',', $order['user_address_code']); // "惠农供销,谱写数字新篇章"活动首单分润,镇合伙人 - (new CommissionDao())->sendCommission($order, $addressCode[3], 2); + (new CommissionDao())->sendCommission($order, $addressCode[3], 3); + if ($order['order_type'] && !empty($order['logistics_phone'])) { + (new CommissionDao())->sendCommission($order, $order['logistics_phone'], 4); + } } } //分销判断 diff --git a/app/controller/merchant/store/order/StoreOrderBehalf.php b/app/controller/merchant/store/order/StoreOrderBehalf.php index 8fab7efa..cd72929f 100644 --- a/app/controller/merchant/store/order/StoreOrderBehalf.php +++ b/app/controller/merchant/store/order/StoreOrderBehalf.php @@ -15,9 +15,12 @@ namespace app\controller\merchant\store\order; +use app\common\model\store\order\StoreOrder; +use app\common\model\store\order\StoreOrderOther; use crmeb\basic\BaseController; use app\common\repositories\store\order\StoreOrderRepository; +use crmeb\services\SmsService; use think\facade\Db; use think\App; use app\common\dao\store\order\StoreOrderDao; @@ -134,14 +137,16 @@ class StoreOrderBehalf extends BaseController $mer_id = $this->request->merId(); $status = $this->request->param('status'); $id = $this->request->param('id'); - $uid = Db::name('merchant')->where('mer_id', $mer_id)->value('uid'); - $res = Db::name('store_order_other')->where('uid', $uid)->where('order_id', $id)->update(['status' => $status]); + $merchant = Db::name('merchant')->where('mer_id', $mer_id)->field('uid,mer_name')->find(); + $orderOther = StoreOrderOther::where('uid', $merchant['uid'])->where('order_id', $id)->find(); + $orderOther->status = $status; + $res = $orderOther->save(); // $find = Db::name('store_order_other')->where('uid', $uid)->where('order_id', $id)->find(); // $find_two = Db::name('store_order')->where('order_sn', $find['order_sn'])->find(); if($res){ - if($status==3){ - - + $order = StoreOrder::where('order_sn', $orderOther['order_sn'])->field('user_phone,order_type,logistics_code')->find()->toArray(); + if($status==3 && $order['order_type'] == 1){ + SmsService::create()->send($order['user_phone'], 'RECEIVE_NOTICE', ['code' => $order['logistics_code'], 'name' => $merchant['mer_name']]); } return app('json')->success('设置成功'); }else{ diff --git a/crmeb/jobs/SendGoodsCodeJob.php b/crmeb/jobs/SendGoodsCodeJob.php index 380ba129..3dfe5253 100644 --- a/crmeb/jobs/SendGoodsCodeJob.php +++ b/crmeb/jobs/SendGoodsCodeJob.php @@ -15,6 +15,7 @@ namespace crmeb\jobs; use app\common\repositories\store\order\StoreOrderRepository; use crmeb\interfaces\JobInterface; +use crmeb\utils\Curl; use think\facade\Log; use think\facade\Db; use think\queue\Job; @@ -31,8 +32,9 @@ class SendGoodsCodeJob implements JobInterface Log::info("sendGoodsCodeJob ============= handle监听order_id " . $this->event['order_id']); try { if ($this->event['activity_type'] == 0 || in_array($this->event['source'], [0,2,103])) { + $logisticsPhone = ''; //发起物流信息返回快递员手机 - if($this->event['activity_type'] !=98){ + if($this->event['activity_type'] !=98 && $this->event['order_type'] != 1){ $logisticsPhone = $this->sendLogistics($this->event['order_id'], $this->event['order_sn']); } //生成用户的收货码 @@ -57,28 +59,14 @@ class SendGoodsCodeJob implements JobInterface //发送物流 public function sendLogistics($orderId, $orderSn) { + $curl = new Curl(); $postUrl = env('LOGISTICS_HOST_URL') . '/api/lstSet'; - Log::info("物流HOST: {$postUrl}"); - Log::info("发送物流信息 orderId: {$orderId}, orderSn: {$orderSn}"); - $curlPost = [ - 'order_id' => $orderId, - 'order_sn' => $orderSn, - ]; - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $postUrl); - curl_setopt($ch, CURLOPT_HEADER, 0); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost); - $data = curl_exec($ch); - curl_close($ch); - $phone = ''; + $data = $curl->post($postUrl, ['order_id' => $orderId, 'order_sn' => $orderSn]); if (!empty($data) && is_string($data)) { $logisticsInfo = json_decode($data, true); $phone = $logisticsInfo['data']['phone'] ?? ''; - Log::info("物流联系信息" . json_encode($logisticsInfo)); } - return $phone; + return $phone ?? ''; } public function failed($data)