更新物流订单细节

This commit is contained in:
yaooo 2023-08-12 12:04:03 +08:00
parent 5837d30284
commit f0931c5bf2
5 changed files with 65 additions and 42 deletions

View File

@ -271,7 +271,9 @@ class StoreOrderRepository extends BaseRepository
$flag = false;
}
}
//发起物流信息处理
event('order.sendGoodsCode', $order);
// 商户流水账单数据
$finance[] = [
'order_id' => $order->order_id,

View File

@ -66,6 +66,7 @@ return [
'pay_success_meal' => [\crmeb\listens\pay\MealSuccessListen::class],
// 'community_address'=>[\app\listener\CommunityAddress::class],
'order.paySuccessOrder'=>[\app\listener\paySuccessOrder::class],
'order.sendGoodsCode'=>[\app\listener\SendGoodsCode::class],
'product.create'=>[\app\listener\ProductCreate::class],
'product.delivery'=>[\app\listener\DeliveryGoods::class],
'product.sell'=>[\app\listener\CloudProduct::class], //商品上下架

View File

@ -17,7 +17,7 @@ class DeliveryGoods
public function handle($event)
{
$this->event = $event;
Log::info("============= handle监听order_id " . $this->event['order']['order_id']);
Log::info("delivery ============= handle监听order_id " . $this->event['order']['order_id']);
$this->event = $event;
//发生短信包含收货码
$this->sendLogisticsCode($this->event['order']['uid'], $this->event['order']['order_id'], $this->event['order']['order_sn']);

View File

@ -0,0 +1,60 @@
<?php
declare (strict_types=1);
namespace app\listener;
use app\common\repositories\store\order\StoreOrderRepository;
use crmeb\utils\DingTalk;
use think\facade\Db;
use think\facade\Log;
class SendGoodsCode
{
public $event;
public function handle($event)
{
$this->event = $event;
Log::info("sendGoodsCode ============= handle监听order_id " . $this->event['order_id']);
//发起物流信息返回快递员手机
$logisticsPhone = $this->sendLogistics($this->event['order_id'], $this->event['order_sn']);
//生成用户的收货码
$this->generateLogisticsCode($this->event['uid'], $this->event['order_id'], $this->event['order_sn'], $logisticsPhone);
}
//用户收货码
public function generateLogisticsCode($uid, $orderId, $orderSn, $logisticsPhone) {
$code = random_int(1000, 9999);
app()->make(StoreOrderRepository::class)->update($orderId, [
'logistics_code' => $code,
'logistics_phone' => $logisticsPhone
]);
}
//发送物流
public function sendLogistics($orderId, $orderSn)
{
Log::info("发送物流信息 orderId: {$orderId}, orderSn: {$orderSn}");
$postUrl = env('LOGISTICS_LOGIS_URL');
$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 = '';
if (!empty($data) && is_string($data)) {
$logisticsInfo = json_decode($data, true);
$phone = $logisticsInfo['data']['phone'];
Log::info("物流联系信息" . json_encode($logisticsInfo));
}
return $phone;
}
}

View File

@ -29,11 +29,6 @@ class paySuccessOrder
$this->event = $event;
$this->finance = [];
$this->index = 1;
//发起物流信息返回快递员手机
$logisticsPhone = $this->sendLogistics($this->event['order']['order_id'], $this->event['order']['order_sn']);
//生成用户的收货码
$this->generateLogisticsCode($this->event['order']['uid'], $this->event['order']['order_id'], $this->event['order']['order_sn'], $logisticsPhone);
Db::startTrans();
try {
$financialRecordRepository = app()->make(FinancialRecordRepository::class);
@ -144,41 +139,6 @@ class paySuccessOrder
}
}
//用户收货码
public function generateLogisticsCode($uid, $orderId, $orderSn, $logisticsPhone) {
$code = random_int(1000, 9999);
app()->make(StoreOrderRepository::class)->update($orderId, [
'logistics_code' => $code,
'logistics_phone' => $logisticsPhone
]);
}
//发送物流
public function sendLogistics($orderId, $orderSn)
{
Log::info("发送物流信息 orderId: {$orderId}, orderSn: {$orderSn}");
$postUrl = env('LOGISTICS_LOGIS_URL');
$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 = '';
if (!empty($data) && is_string($data)) {
$logisticsInfo = json_decode($data, true);
$phone = $logisticsInfo['data']['phone'];
Log::info("物流联系信息" . json_encode($logisticsInfo));
}
return $phone;
}
public function calculate($type, $field)
{
$merId = Db::name('merchant')->where('type_id', $type)