订单发货优化
This commit is contained in:
@@ -651,14 +651,14 @@ class OrderService
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单发货
|
||||
* 订单发货(只生成发货单并更新状态,发货通知在后台「订单发货管理」编辑并确认发货时发送)
|
||||
* @param $id
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function orderShip($id)
|
||||
{
|
||||
$order = Db::transaction(function () use ($id) {
|
||||
Db::transaction(function () use ($id) {
|
||||
//加锁读取,防止并发重复发货、重复分配激活码
|
||||
$order = OrderService::where(['id' => $id])->lock(true)->find();
|
||||
if (!$order) {
|
||||
@@ -677,11 +677,27 @@ class OrderService
|
||||
if (!$saveRes) {
|
||||
exception('更新发货状态失败');
|
||||
}
|
||||
|
||||
return $order;
|
||||
});
|
||||
}
|
||||
|
||||
//发送订单发货通知(事务提交后发送,失败只记日志,不影响发货结果)
|
||||
/**
|
||||
* 发送软件订单发货通知(订阅消息 + 站内消息),失败只记日志
|
||||
* @param string $orderNo 订单号
|
||||
* @return bool 是否发送成功
|
||||
* @throws \Exception 订单不存在或不是已发货的软件订单
|
||||
*/
|
||||
public static function sendShipNotice($orderNo): bool
|
||||
{
|
||||
$order = self::getOne(['order_no' => $orderNo], ['orderGoods']);
|
||||
if (!$order) {
|
||||
exception('订单不存在');
|
||||
}
|
||||
if ($order->order_type != self::ORDER_TYPE_SOFTWARE) {
|
||||
exception('仅软件订单支持发送发货通知');
|
||||
}
|
||||
if ($order->order_status != self::ORDER_STATUS_SHIPPED) {
|
||||
exception('订单未发货,不能发送发货通知');
|
||||
}
|
||||
try {
|
||||
$msgData = [
|
||||
'page' => SubscribeMessageService::PAGE_ORDER_DETAIL,
|
||||
@@ -696,10 +712,13 @@ class OrderService
|
||||
(new EasyWeChatService())->sendMsg($order->user_id, SubscribeMessageService::MSG_TEMP_ORDER_SHIPPED, $msgData);
|
||||
} catch (\Exception $e) {
|
||||
Log::error(__CLASS__ . ' 订单发货通知发送失败:' . json_encode([
|
||||
'order_id' => $id,
|
||||
'order_no' => $orderNo,
|
||||
'error' => $e->getMessage(),
|
||||
], JSON_UNESCAPED_UNICODE));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user