ExpressClass.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <?php
  2. namespace bizGhs\express\classes;
  3. use bizGhs\order\classes\OrderClass;
  4. use bizHd\base\classes\BaseClass;
  5. use bizHd\purchase\classes\PurchaseClass;
  6. use bizHd\wx\classes\WxOpenClass;
  7. use common\components\dict;
  8. use common\components\expressUtil;
  9. use common\components\util;
  10. use Yii;
  11. class ExpressClass extends BaseClass
  12. {
  13. public static $baseFile = '\bizGhs\express\models\DeliveryOrder';
  14. public static function testUpdate($params, $order)
  15. {
  16. $merchant = WxOpenClass::getGhsWxInfo();
  17. $ptStyle = dict::getDict('ptStyle', 'ghs');
  18. $deliveryId = $params['deliveryId'];
  19. $wayBillId = $params['wayBillId'];
  20. $orderSn = $params['orderSn'];
  21. $bizId = $params['bizId'];
  22. $actionType = $params['actionType'];
  23. $actionTime = $params['actionTime'];
  24. $actionMsg = $params['actionMsg'];
  25. $data = [
  26. 'delivery_id' => $deliveryId,
  27. 'waybill_id' => $wayBillId,
  28. 'order_id' => $orderSn,
  29. 'biz_id' => $bizId,
  30. 'action_time' => $actionTime,
  31. 'action_type' => $actionType,
  32. 'action_msg' => $actionMsg,
  33. ];
  34. $ret = expressUtil::testUpdateOrder($merchant, $data, $ptStyle);
  35. print_r($ret);
  36. }
  37. public static function cancel($params, $order)
  38. {
  39. $cgId = $order->purchaseId;
  40. $cg = PurchaseClass::getById($cgId, true);
  41. if (empty($cg)) {
  42. util::fail('订单信息缺失');
  43. }
  44. $merchant = WxOpenClass::getGhsWxInfo();
  45. $ptStyle = dict::getDict('ptStyle', 'ghs');
  46. $deliveryId = $params['deliveryId'];
  47. $wayBillId = $order->fhWlNo ?? '';
  48. $orderSn = $order->orderSn;
  49. $data = [
  50. 'deliveryId' => $deliveryId,
  51. 'waybill_id' => $wayBillId,
  52. 'order_id' => $orderSn
  53. ];
  54. $ret = expressUtil::cancelOrder($merchant, $data, $ptStyle);
  55. if ($ret['errcode'] == 0) {
  56. $order->fhWlStatus = 2;
  57. $order->save();
  58. $cg->fhWlStatus = 2;
  59. $cg->save();
  60. util::complete('取消成功');
  61. } else {
  62. $code = $ret['errcode'] ?? '';
  63. $msg = $ret['errmsg'] ?? '';
  64. util::fail('取消失败,原因:' . $code . ' / ' . $msg);
  65. }
  66. }
  67. //新增运单 ssh 20250703
  68. public static function addWayBill($params, $order)
  69. {
  70. $cgId = $order->purchaseId;
  71. $cg = PurchaseClass::getById($cgId, true);
  72. if (empty($cg)) {
  73. util::fail('订单信息缺失');
  74. }
  75. $merchant = WxOpenClass::getGhsWxInfo();
  76. $ptStyle = dict::getDict('ptStyle', 'ghs');
  77. $orderSn = $params['orderSn'];
  78. //$openId = $params['openId'];
  79. $deliveryId = $params['deliveryId'];
  80. $bizId = $params['bizId'];
  81. $customRemark = $params['customRemark'];
  82. $senderName = $params['senderName'];
  83. $senderMobile = $params['senderMobile'];
  84. $senderProvince = $params['senderProvince'];
  85. $senderCity = $params['senderCity'];
  86. $senderAddress = $params['senderAddress'];
  87. $receiverName = $params['receiverName'];
  88. $receiverMobile = $params['receiverMobile'];
  89. $receiverProvince = $params['receiverProvince'];
  90. $receiverCity = $params['receiverCity'];
  91. $receiverAddress = $params['receiverAddress'];
  92. $receiverFloor = $params['receiverFloor'];
  93. $goodsCount = $params['goodsCount'];
  94. $goodsName = $params['goodsName'];
  95. $weight = $params['weight'];
  96. $height = $params['height'];
  97. $length = $params['length'];
  98. $width = $params['width'];
  99. $packageNum = $params['packageNum'];
  100. $serviceType = $params['serviceType'];
  101. $serviceName = $params['serviceName'];
  102. $shopImgUrl = $params['shopImgUrl'];
  103. $wxAppId = $params['wxAppId'];
  104. $data = [
  105. // 订单信息
  106. 'order_id' => $orderSn, // 商家订单ID,需唯一
  107. //'openid' => $openId, // 用户openid
  108. 'delivery_id' => $deliveryId, // 快递公司ID
  109. 'biz_id' => $bizId, // 快递公司客户编码或月结账号
  110. 'custom_remark' => $customRemark, // 备注
  111. //0表示已事先约定取件时间;否则请传预期揽件时间戳,需大于当前时间
  112. 'expect_time' => 0,
  113. //订单来源,0为小程序订单,2为App或H5订单,填2则不发送物流服务通知
  114. 'add_source' => 2,
  115. 'wx_appid' => $wxAppId,
  116. // 发件人信息
  117. 'sender' => [
  118. 'name' => $senderName, // 发件人姓名
  119. 'mobile' => $senderMobile, // 发件人手机号
  120. 'province' => $senderProvince, // 发件人省份
  121. 'city' => $senderCity, // 发件人城市
  122. 'address' => $senderAddress, // 发件人详细地址
  123. ],
  124. // 收件人信息
  125. 'receiver' => [
  126. 'name' => $receiverName, // 收件人姓名
  127. 'mobile' => $receiverMobile, // 收件人手机号
  128. 'province' => $receiverProvince, // 收件人省份
  129. 'city' => $receiverCity, // 收件人城市
  130. 'address' => $receiverAddress . $receiverFloor, // 收件人详细地址
  131. ],
  132. // 商品信息
  133. 'shop' => [
  134. 'goods_name' => $goodsName, // 商品名称
  135. 'goods_count' => $goodsCount, // 商品数量
  136. 'img_url' => $shopImgUrl,
  137. ],
  138. // 货物信息
  139. 'cargo' => [
  140. 'count' => $packageNum, // 货物数量
  141. 'weight' => $weight, // 货物总重量,单位kg
  142. 'space_x' => $length, // 货物长度,单位cm
  143. 'space_y' => $width, // 货物宽度,单位cm
  144. 'space_z' => $height, // 货物高度,单位cm
  145. 'detail_list' => [
  146. [
  147. 'name' => '鲜花花材', // 货物名称
  148. 'count' => $packageNum, // 货物数量
  149. ],
  150. ],
  151. ],
  152. // 保价信息
  153. 'insured' => [
  154. 'use_insured' => 0, // 是否保价,0-否,1-是
  155. ],
  156. // 服务类型
  157. 'service' => [
  158. 'service_type' => $serviceType, // 服务类型,0-标准快递
  159. 'service_name' => $serviceName, // 服务名称
  160. ],
  161. ];
  162. Yii::info('req:' . json_encode($data));
  163. $ret = expressUtil::addOrder($merchant, $data, $ptStyle);
  164. if ($ret['errcode'] == 0) {
  165. $wayBillId = $ret['waybill_id'] ?? 0;
  166. $wayBillName = '顺丰速运';
  167. $order->fhWlSn = $deliveryId;
  168. $order->fhWl = $wayBillName;
  169. $order->fhWlNo = $wayBillId;
  170. $order->fhWlStatus = 1;//已经叫物流
  171. $order->save();
  172. $cg->fhWlSn = $deliveryId;
  173. $cg->fhWl = $wayBillName;
  174. $cg->fhWlNo = $wayBillId;
  175. $cg->fhWlStatus = 1;//已经叫物流
  176. $cg->save();
  177. $staffId = $params['staffId'];
  178. $staffName = $params['staffName'];
  179. $params = [
  180. 'fhType' => 0,
  181. 'fhWl' => '',
  182. 'fhWlNo' => '',
  183. 'staffId' => $staffId,
  184. 'staffName' => $staffName,
  185. ];
  186. OrderClass::orderSend($order, $params);
  187. $order->fhType = 1;
  188. $order->save();
  189. $cg->fhType = 1;
  190. $cg->save();
  191. } else {
  192. $code = $ret['errcode'] ?? '';
  193. $msg = $ret['errmsg'] ?? '';
  194. util::fail('提交失败,原因:' . $code . ' / ' . $msg);
  195. }
  196. }
  197. }