ExpressClass.php 8.2 KB

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