ExpressClass.php 8.2 KB

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