|
|
@@ -2,7 +2,10 @@
|
|
|
namespace bizHd\express\classes;
|
|
|
|
|
|
use bizHd\base\classes\BaseClass;
|
|
|
+use bizHd\order\classes\OrderClass;
|
|
|
+use common\components\delivery\services\DispatchService;
|
|
|
use common\components\noticeUtil;
|
|
|
+use common\components\util;
|
|
|
use mikemadisonweb\rabbitmq\components\ConsumerInterface;
|
|
|
use Yii;
|
|
|
|
|
|
@@ -41,13 +44,104 @@ class HdDeliveryOrderClass extends BaseClass
|
|
|
//消费者消费下单指令逻辑
|
|
|
public static function beginCreateOrder($data)
|
|
|
{
|
|
|
- //花店,进行下单流程处理
|
|
|
- $dataStr = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
|
- noticeUtil::push('已消费hd -- ' . $dataStr);
|
|
|
- $orderId = $data['orderId']; // xhGhsOrder.id
|
|
|
- //$params = $data['allParams'];
|
|
|
- //Yii::info('params == ' . json_encode($params, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
|
|
- return ConsumerInterface::MSG_REJECT;
|
|
|
+ try{
|
|
|
+ //花店,进行下单流程处理
|
|
|
+ $dataStr = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
|
+ //noticeUtil::push('已消费hd -- ' . $dataStr);
|
|
|
+
|
|
|
+ $orderId = $data['orderId']; // xhOrder.id
|
|
|
+ $params = $data['allParams'];
|
|
|
+ $platform = $params['en_name'];// 平台英文名,$post['platform'] 是中文
|
|
|
+ $errMsg = '';
|
|
|
+ if (empty($platform)) {
|
|
|
+ Yii::error('platform为空');
|
|
|
+ $errMsg = 'platform参数为空';
|
|
|
+ }
|
|
|
+ $pickupTime = $data['pickupTime'];
|
|
|
+
|
|
|
+ $shopId = $data['shopId'];
|
|
|
+ $mainId = $data['mainId'];
|
|
|
+ $params['mainId'] = $mainId;
|
|
|
+ $params['ip'] = $data['ip'];
|
|
|
+ $params['weight'] = $data['weight'];
|
|
|
+ $params['remark'] = $data['remark'] ?? '';
|
|
|
+ $params['total_price_fen'] = $data['price'];
|
|
|
+ $params['pickupTime'] = $pickupTime['value'];
|
|
|
+
|
|
|
+ $Order = OrderClass::getById($orderId, true);
|
|
|
+ if (empty($Order)) {
|
|
|
+ $errMsg = "没有找到订单 hd-orderId={$orderId}";
|
|
|
+ }
|
|
|
+ if ($Order->mainId != $mainId) {
|
|
|
+ $errMsg = "hd-orderId={$orderId} 不是 mainId={$mainId} 的订单";
|
|
|
+ }
|
|
|
+ if (!in_array($Order['sendStatus'], [-4, -2, -1])) {
|
|
|
+ $errMsg = "订单 hd-orderId={$orderId} 已经发过跑腿";
|
|
|
+ }
|
|
|
+
|
|
|
+ if($errMsg != ''){
|
|
|
+ Yii::error($errMsg);
|
|
|
+ noticeUtil::push($errMsg);
|
|
|
+ return ConsumerInterface::MSG_REJECT;
|
|
|
+ }
|
|
|
+
|
|
|
+ $ds = new DispatchService($mainId, $platform);
|
|
|
+ $ret = $ds->createOrder($Order, 'xhOrder', $shopId, $params);
|
|
|
+
|
|
|
+ if (isset($ret['code']) && $ret['code'] == 0) {
|
|
|
+ $hdo = HdDeliveryOrderClass::getByCondition(['mainId' => $mainId, 'orderId' => $ret['data']['orderId']]);
|
|
|
+ if (empty($hdo)) {
|
|
|
+ $data = [
|
|
|
+ 'mainId' => $mainId,
|
|
|
+ 'shopId' => $shopId,
|
|
|
+ 'deliveryId' => $ret['platform'],
|
|
|
+ 'hdOrderId' => $orderId,
|
|
|
+ 'orderId' => $ret['data']['orderId'],
|
|
|
+ 'distance' => $ret['data']['distance'],
|
|
|
+ 'fee' => $ret['data']['fee'],
|
|
|
+ 'orderStatus' => 0
|
|
|
+ ];
|
|
|
+
|
|
|
+ // createdAt 中保存了滴滴跑腿订单的后半截数据
|
|
|
+ if($platform == 'didi'){
|
|
|
+ $data['createdAt'] = date('Y-m-d H:i:s', $ret['data']['timeStamp']);
|
|
|
+ }
|
|
|
+
|
|
|
+ HdDeliveryOrderClass::add($data);
|
|
|
+ } else {
|
|
|
+ Yii::info('重复创建订单');
|
|
|
+ noticeUtil::push('重复创建订单:' . json_encode($hdo, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
|
|
+ }
|
|
|
+ //更新订单
|
|
|
+ $Order->sendDistance = $ret['data']['distance'];
|
|
|
+ $Order->sendStatus = 0;
|
|
|
+ $Order->deliveryId = $platform;
|
|
|
+ $Order->sendType = 2;// 2指跑腿
|
|
|
+ $Order->status = 3;// 3配送中
|
|
|
+ $save = $Order->save();
|
|
|
+ if ($save) {
|
|
|
+ noticeUtil::push("hd-orderId={$orderId}, 创建跑腿成功--" . json_encode($Order->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
|
|
+ } else {
|
|
|
+ noticeUtil::push("hd-orderId={$orderId}, 创建跑腿失败--" . json_encode($Order->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
|
|
+ }
|
|
|
+
|
|
|
+ return ConsumerInterface::MSG_ACK;
|
|
|
+ } else {
|
|
|
+ if (isset($ret['msg'])) {
|
|
|
+ Yii::error("hd-orderId={$orderId}, 创建跑腿失败:" . $ret['msg']);
|
|
|
+ noticeUtil::push("hd-orderId={$orderId}, 创建跑腿失败:" . $ret['msg']);
|
|
|
+ return ConsumerInterface::MSG_REJECT;
|
|
|
+ }
|
|
|
+
|
|
|
+ Yii::error("ghs-orderId={$orderId}, 创建跑腿失败");
|
|
|
+ noticeUtil::push("ghs-orderId={$orderId}, 创建跑腿失败");
|
|
|
+ return ConsumerInterface::MSG_REJECT;
|
|
|
+ }
|
|
|
+ }catch(\Exception $e){
|
|
|
+ Yii::error("hd-orderId={$orderId} 创建跑腿失败:" . $e->getMessage());
|
|
|
+ noticeUtil::push("hd-orderId={$orderId} 创建跑腿失败:" . $e->getMessage());
|
|
|
+ return ConsumerInterface::MSG_REJECT;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|