更新订单物流短信处理

This commit is contained in:
yaooo 2023-08-10 15:30:28 +08:00
parent c1e0454775
commit 278c038e31
2 changed files with 28 additions and 6 deletions

View File

@ -55,8 +55,21 @@ class Auth extends BaseController
{ {
public function dotest() public function dotest()
{ {
//SmsService::create()->send($data['phone'], 'VERIFICATION_CODE', ['code' => $sms_code, 'time' => $sms_time]); $postUrl = 'http://logistics.lihaink.cn/api/lstSet';
return app('json')->success(); $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() public function test()

View File

@ -9,6 +9,8 @@ use app\common\model\system\merchant\Merchant;
use app\common\repositories\store\order\StoreOrderRepository; use app\common\repositories\store\order\StoreOrderRepository;
use app\common\repositories\system\merchant\FinancialRecordRepository; use app\common\repositories\system\merchant\FinancialRecordRepository;
use app\common\repositories\system\merchant\MerchantRepository; use app\common\repositories\system\merchant\MerchantRepository;
use app\common\model\user\User;
use crmeb\services\SmsService;
use crmeb\utils\DingTalk; use crmeb\utils\DingTalk;
use think\facade\Db; use think\facade\Db;
use think\facade\Log; use think\facade\Log;
@ -137,20 +139,24 @@ class paySuccessOrder
Log::error('订单分润出错', ['code' => $e->getCode(), 'message' => $e->getMessage(), 'trace' => $e->getTraceAsString()]); Log::error('订单分润出错', ['code' => $e->getCode(), 'message' => $e->getMessage(), 'trace' => $e->getTraceAsString()]);
DingTalk::exception($e, '订单分润出错'); 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); $code = random_int(1000, 9999);
$res = app()->make(StoreOrderRepository::class)->update($orderId, [ $res = app()->make(StoreOrderRepository::class)->update($orderId, [
'logistics_code' => $code 'logistics_code' => $code
]); ]);
if ($res) { 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); curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
$data = curl_exec($ch); $data = curl_exec($ch);
curl_close($ch); curl_close($ch);
$logisticsInfo = json_decode($data, true);
$phone = $logisticsInfo['data']['phone'] ?? '';
Log::record("发送物流信息 orderId: {$orderId}, orderSn: {$orderSn}"); Log::record("发送物流信息 orderId: {$orderId}, orderSn: {$orderSn}");
return $phone;
} }
public function calculate($type, $field) public function calculate($type, $field)