ThirthdeliveryController.class.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. * 第三方配送回调地址
  11. * @author cy 2020.08.06
  12. *
  13. */
  14. namespace Home\Controller;
  15. class ThirthdeliveryController extends CommonController {
  16. protected function _initialize()
  17. {
  18. parent::_initialize();
  19. }
  20. public function notify(){
  21. $return_json_data = file_get_contents("php://input");
  22. $json_data = json_decode($return_json_data,true);
  23. //达达平台回调接口
  24. if(isset($json_data['client_id']) && isset($json_data['order_id']) && isset($json_data['order_status']) && isset($json_data['signature'])){
  25. //error_log($return_json_data.'///',3,'logs/error_imdada_'.date('Ymd').'.log');
  26. $other_data = array();
  27. $other_data['data_type'] = 'imdada';
  28. $other_data['order_status'] = $json_data['order_status'];
  29. if($json_data['order_status'] == 2){//待取货
  30. $other_data['dm_id'] = $json_data['dm_id'];
  31. $other_data['dm_name'] = $json_data['dm_name'];
  32. $other_data['dm_mobile'] = $json_data['dm_mobile'];
  33. $other_data['third_id'] = $json_data['client_id'];
  34. D('Seller/Order')->do_localtown_thirth_delivery_return($json_data['order_id'],0,$other_data);
  35. }else if($json_data['order_status'] == 3){//配送中
  36. $other_data['dm_id'] = $json_data['dm_id'];
  37. $other_data['dm_name'] = $json_data['dm_name'];
  38. $other_data['dm_mobile'] = $json_data['dm_mobile'];
  39. $other_data['third_id'] = $json_data['client_id'];
  40. D('Seller/Order')->do_localtown_thirth_delivery_return($json_data['order_id'],0,$other_data);
  41. }else if($json_data['order_status'] == 4){//已完成
  42. D('Seller/Order')->do_localtown_thirth_delivery_return($json_data['order_id'],6,$other_data);
  43. }else if($json_data['order_status'] == 5){//已取消
  44. //订单取消原因
  45. $other_data['cancel_reason'] = $json_data['cancel_reason'];
  46. //订单取消原因来源
  47. $other_data['cancel_from'] = $json_data['cancel_from'];
  48. D('Seller/Order')->do_localtown_thirth_delivery_return($json_data['order_id'],0,$other_data);
  49. }else if($json_data['order_status'] == 9){//妥投异常之物品返回中
  50. //订单取消原因
  51. $other_data['cancel_reason'] = "妥投异常-物品返回中";
  52. //订单取消原因来源
  53. $other_data['cancel_from'] = $json_data['cancel_from'];
  54. D('Seller/Order')->do_localtown_thirth_delivery_return($json_data['order_id'],0,$other_data);
  55. }else if($json_data['order_status'] == 10){//妥投异常之物品返回完成
  56. //订单取消原因
  57. $other_data['cancel_reason'] = "妥投异常-物品返回完成";
  58. //订单取消原因来源
  59. $other_data['cancel_from'] = $json_data['cancel_from'];
  60. D('Seller/Order')->do_localtown_thirth_delivery_return($json_data['order_id'],0,$other_data);
  61. }else if($json_data['order_status'] == 1000){//创建达达运单失败
  62. //订单取消原因
  63. $other_data['cancel_reason'] = $json_data['cancel_reason'];
  64. //订单取消原因来源
  65. $other_data['cancel_from'] = $json_data['cancel_from'];
  66. D('Seller/Order')->do_localtown_thirth_delivery_return($json_data['order_id'],0,$other_data);
  67. }
  68. echo 'notify';
  69. }else if(isset($_GET['sign']) && isset($json_data['sf_order_id']) && isset($json_data['shop_order_id']) && isset($json_data['url_index']) && isset($json_data['push_time'])){
  70. //顺丰同城回调接口
  71. $sign = $_GET['sign'];
  72. //error_log($sign.'==='.$return_json_data.'///',3,'logs/error_sf_'.date('Ymd').'.log');
  73. $dev_id = D('Home/Front')->get_config_by_name('localtown_sf_dev_id');
  74. $dev_key = D('Home/Front')->get_config_by_name('localtown_sf_dev_key');
  75. if ($sign && $sign == base64_encode(MD5("{$return_json_data}&{$dev_id}&{$dev_key}"))) {
  76. $other_data = array();
  77. $url_index = $json_data['url_index'];
  78. $other_data['data_type'] = 'sf';
  79. if($url_index == 'sf_cancel'){//取消订单
  80. //订单取消原因
  81. $other_data['cancel_reason'] = $json_data['cancel_reason'];
  82. //状态描述
  83. $other_data['status_desc'] = $json_data['status_desc'];
  84. //操作人
  85. $other_data['operator_name'] = $json_data['operator_name'];
  86. //操作状态 2:订单取消
  87. $other_data['order_status'] = $json_data['order_status'];
  88. D('Seller/Order')->do_localtown_thirth_delivery_return($json_data['shop_order_id'],0,$other_data);
  89. }else if($url_index == 'rider_status'){//配送状态更改回调
  90. //配送员姓名
  91. $other_data['operator_name'] = $json_data['operator_name'];
  92. //配送员电话
  93. $other_data['operator_phone'] = $json_data['operator_phone'];
  94. //操作状态 10-配送员确认;12:配送员到店;15:配送员配送中
  95. $other_data['order_status'] = $json_data['order_status'];
  96. //备注信息
  97. $other_data['status_desc'] = $json_data['status_desc'];
  98. D('Seller/Order')->do_localtown_thirth_delivery_return($json_data['shop_order_id'],0,$other_data);
  99. }else if($url_index == 'rider_exception'){//订单异常回调
  100. //异常ID
  101. $other_data['ex_id'] = $json_data['ex_id'];
  102. //异常详情
  103. $other_data['ex_content'] = $json_data['ex_content'];
  104. //异常状态 0:订单异常
  105. $other_data['order_status'] = $json_data['order_status'];
  106. D('Seller/Order')->do_localtown_thirth_delivery_return($json_data['shop_order_id'],0,$other_data);
  107. }else if($url_index == 'order_complete'){//订单完成
  108. //操作状态 17-配送员点击完成
  109. $other_data['order_status'] = $json_data['order_status'];
  110. D('Seller/Order')->do_localtown_thirth_delivery_return($json_data['shop_order_id'],6,$other_data);
  111. }
  112. $result_array = array();
  113. $result_array['error_code'] = 0;
  114. $result_array['error_msg'] = "success";
  115. echo json_encode($result_array);
  116. }
  117. }else if(isset($json_data['messageType']) && isset($json_data['messageBody'])){
  118. //达达消息通知:骑士取消订单通知
  119. $messageBody = json_decode($json_data['messageBody'],true);
  120. $other_data = array();
  121. $other_data['data_type'] = 'imdada';
  122. $other_data['order_status'] = 5;
  123. //订单取消原因
  124. $other_data['cancel_reason'] = $messageBody['cancelReason'];
  125. //订单取消原因来源 11:达达骑手取消订单
  126. $other_data['cancel_from'] = 11;
  127. D('Seller/Order')->do_localtown_thirth_delivery_return($messageBody['orderId'],0,$other_data);
  128. $result_array = array();
  129. $result_array['status'] = "ok";
  130. echo json_encode($result_array);
  131. }else if(isset($json_data['app_id']) && isset($json_data['data']) && isset($json_data['salt']) && isset($json_data['signature'])){
  132. //蜂鸟即配 订单状态变更回调
  133. $app_id = D('Home/Front')->get_config_by_name('localtown_ele_app_id');
  134. $secret_key = D('Home/Front')->get_config_by_name('localtown_ele_secret_key');
  135. // 获取签名
  136. $sig = $this->eleGenerateSign($app_id, $json_data['salt'], $secret_key);
  137. if($sig == $json_data['signature']){
  138. $data = urldecode($json_data['data']);
  139. //商户自己的订单号
  140. $partner_order_code = $data['partner_order_code'];
  141. //状态码
  142. $order_status = $data['order_status'];
  143. $order_sn = $this->getOrderSnByThirdOrderId($partner_order_code);
  144. if(!empty($order_sn)){
  145. $other_data = [];
  146. $other_data['data_type'] = 'ele';
  147. if($order_status == 1){//系统已接单
  148. $other_data['desc'] = '已接单';
  149. $other_data['order_status'] = 2;
  150. D('Seller/Order')->do_localtown_thirth_delivery_return($order_sn,0,$other_data);
  151. }else if($order_status == 20){//已分配骑手
  152. //配送员姓名
  153. $other_data['operator_name'] = $data['carrier_driver_name'];
  154. //配送员电话
  155. $other_data['operator_phone'] = $data['carrier_driver_phone'];
  156. $other_data['desc'] = "已分配骑手:".$other_data['operator_name'];
  157. $other_data['order_status'] = 3;
  158. D('Seller/Order')->do_localtown_thirth_delivery_return($order_sn,0,$other_data);
  159. }else if($order_status == 80){//骑手已到店
  160. //配送员姓名
  161. $other_data['operator_name'] = $data['carrier_driver_name'];
  162. //配送员电话
  163. $other_data['operator_phone'] = $data['carrier_driver_phone'];
  164. $other_data['desc'] = "骑手".$other_data['operator_name']."已到店";
  165. $other_data['order_status'] = 3;
  166. D('Seller/Order')->do_localtown_thirth_delivery_return($order_sn,0,$other_data);
  167. }else if($order_status == 2){//配送中
  168. //配送员姓名
  169. $other_data['operator_name'] = $data['carrier_driver_name'];
  170. //配送员电话
  171. $other_data['operator_phone'] = $data['carrier_driver_phone'];
  172. $other_data['desc'] = "骑手".$other_data['operator_name']."配送中";
  173. $other_data['order_status'] = 3;
  174. D('Seller/Order')->do_localtown_thirth_delivery_return($order_sn,0,$other_data);
  175. }else if($order_status == 3){//已送达
  176. //配送员姓名
  177. $other_data['operator_name'] = $data['carrier_driver_name'];
  178. //配送员电话
  179. $other_data['operator_phone'] = $data['carrier_driver_phone'];
  180. $other_data['desc'] = "骑手".$data['carrier_driver_name']."已送达";
  181. $other_data['order_status'] = 4;
  182. D('Seller/Order')->do_localtown_thirth_delivery_return($order_sn,6,$other_data);
  183. }else if($order_status == 5){//异常
  184. $other_data['error_code'] = $data['error_code'];
  185. $other_data['desc'] = $data['detail_description'];
  186. $other_data['order_status'] = 100;
  187. D('Seller/Order')->do_localtown_thirth_delivery_return($order_sn,0,$other_data);
  188. }
  189. }
  190. }
  191. }
  192. }
  193. /**
  194. * @author cy 2021-02-03
  195. * @desc 通过第三方商户订单号获取狮子鱼订单号
  196. * @param $third_order_id
  197. * @return string
  198. */
  199. public function getOrderSnByThirdOrderId($third_order_id){
  200. $orders = M('lionfish_comshop_orderdistribution_order')->field('order_id')->where( array('third_order_id' => $third_order_id) )->find();
  201. if(!empty($orders)){
  202. $order_info = M('lionfish_comshop_order')->field('order_num_alias')->where( array('order_id' => $orders['order_id']) )->find();
  203. if(!empty($order_info)){
  204. return $order_info['order_num_alias'];
  205. }else{
  206. return '';
  207. }
  208. }else{
  209. return '';
  210. }
  211. }
  212. /**
  213. * @author cy 2021-02-03
  214. * @desc 蜂鸟即配签名
  215. * @param $appId
  216. * @param $salt
  217. * @param $secretKey
  218. * @return string
  219. */
  220. public function eleGenerateSign($appId, $salt, $secretKey) {
  221. $seed = 'app_id=' . $appId . '&salt=' . $salt . '&secret_key=' . $secretKey;
  222. return md5(urlencode($seed));
  223. }
  224. }