PickOfflinePayNotify.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace addons\CloudStock\common\logic\order;
  3. use addons\CloudStock\common\models\CloudStockAgentOrder;
  4. use addons\CloudStock\common\events\order\FillOrderPickEvent;
  5. use addons\CloudStock\common\enums\CloudStockEnum;
  6. use addons\CloudStock\common\models\CloudStockAgentOrderDetails;
  7. use common\enums\RabbitMqEnum;
  8. use common\enums\StatusEnum;
  9. use common\helpers\ArrayHelper;
  10. class PickOfflinePayNotify
  11. {
  12. /**
  13. * @name:
  14. * @msg: 云库存支付回调
  15. * @param array $trade_info qimall_payment_trade_order 表数据
  16. * @return bool
  17. */
  18. public function notify($trade_info)
  19. {
  20. $t = \Yii::$app->db->beginTransaction();
  21. try {
  22. if (empty($trade_info)) throw new \Exception('传递进来的流水数据为空');
  23. $agent_order = CloudStockAgentOrder::find()
  24. ->where(['trade_id' => $trade_info['trade_id'], 'order_no' => $trade_info['order_no']])
  25. ->andWhere(['=','send_status',CloudStockEnum::PICK_ORDER_STATUS3])
  26. ->one();
  27. if (empty($agent_order)) throw new \Exception('云库存自提订单不存在或者已经支付。trade_info => ' . json_encode(ArrayHelper::toArray($trade_info), JSON_UNESCAPED_UNICODE));
  28. $agent_order->send_status = CloudStockEnum::PICK_ORDER_STATUS0;
  29. $res = $agent_order->save();
  30. if (false === $res) throw new \Exception($agent_order->getErrorMessage());
  31. $t->commit();
  32. // 发起自提事件
  33. $event = new FillOrderPickEvent($agent_order->mall_id);
  34. $data = ['id' => $agent_order->id];
  35. \Yii::$app->services->events->dispatch($event, $data, $event->listeners);
  36. $goodsIds = CloudStockAgentOrderDetails::find()
  37. ->where(['mall_id' => $agent_order->mall_id, 'status' => StatusEnum::ENABLED, 'order_id' => $agent_order->id])
  38. ->select('goods_id')
  39. ->column();
  40. $sync_params = [
  41. 'mall_id' => $agent_order->mall_id,
  42. 'user_id' => $agent_order['user_id'],
  43. 'goods_id' => $goodsIds
  44. ];
  45. \Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_TASK, RabbitMqEnum::TASK_QUEUE, $sync_params, CloudStockAgentOrder::class, 'handleSync');
  46. return true;
  47. } catch (\Exception $e) {
  48. $t->rollBack();
  49. $msg = '云库存自提订单支付回调处理失败:' . $e->getMessage() . ', file: ' . $e->getFile() . ', line: ' . $e->getLine();
  50. \Yii::error($msg);\Yii::getLogger()->flush(true);
  51. return false;
  52. }
  53. }
  54. }