diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index 1ab74ef5..a4adc669 100644 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -55,8 +55,21 @@ class Auth extends BaseController { public function dotest() { - //SmsService::create()->send($data['phone'], 'VERIFICATION_CODE', ['code' => $sms_code, 'time' => $sms_time]); - return app('json')->success(); + $postUrl = 'http://logistics.lihaink.cn/api/lstSet'; + $curlPost = [ + 'order_id' => '297', + 'order_sn' => 'wxo1691646210943621611', + ]; + $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); + $logisticsInfo = json_decode($data, true); + curl_close($ch); + return app('json')->success($logisticsInfo); } public function test() diff --git a/app/listener/paySuccessOrder.php b/app/listener/paySuccessOrder.php index 1355dcfa..9382de32 100644 --- a/app/listener/paySuccessOrder.php +++ b/app/listener/paySuccessOrder.php @@ -9,6 +9,8 @@ use app\common\model\system\merchant\Merchant; use app\common\repositories\store\order\StoreOrderRepository; use app\common\repositories\system\merchant\FinancialRecordRepository; use app\common\repositories\system\merchant\MerchantRepository; +use app\common\model\user\User; +use crmeb\services\SmsService; use crmeb\utils\DingTalk; use think\facade\Db; use think\facade\Log; @@ -137,20 +139,24 @@ class paySuccessOrder Log::error('订单分润出错', ['code' => $e->getCode(), 'message' => $e->getMessage(), 'trace' => $e->getTraceAsString()]); DingTalk::exception($e, '订单分润出错'); } - //发起物流信息 - $this->sendLogistics($this->event['order']['order_id'], $this->event['order']['order_sn']); + //发起物流信息返回快递员手机 + $logisticsPhone = $this->sendLogistics($this->event['order']['order_id'], $this->event['order']['order_sn']); //生成用户的收货码、发生短信包含收货码 - $this->generateLogisticsCode($orderId); + $this->generateLogisticsCode($this->event['order']['uid'], $this->event['order']['order_id'], $this->event['order']['order_sn'], $logisticsPhone); } //用户收货码 - public function generateLogisticsCode($orderId) { + public function generateLogisticsCode($uid, $orderId, $orderSn, $logisticsPhone) { $code = random_int(1000, 9999); $res = app()->make(StoreOrderRepository::class)->update($orderId, [ 'logistics_code' => $code ]); if ($res) { //发生短信 + $phone = User::where('uid', $uid)->value('phone'); + if ($phone) { + SmsService::create()->send($phone, 'TAKEGOOD_CODE', ['number' => substr($orderSn, -6), 'number2' => $code, 'phone' => $logisticsPhone]); + } } } @@ -170,7 +176,10 @@ class paySuccessOrder curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost); $data = curl_exec($ch); curl_close($ch); + $logisticsInfo = json_decode($data, true); + $phone = $logisticsInfo['data']['phone'] ?? ''; Log::record("发送物流信息 orderId: {$orderId}, orderSn: {$orderSn}"); + return $phone; } public function calculate($type, $field)