ExpressClass.php 8.2 KB

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