NotifyController.class.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 NotifyController extends CommonController {
  16. protected function _initialize()
  17. {
  18. parent::_initialize();
  19. }
  20. public function orderNotify()
  21. {
  22. $json_data = file_get_contents("php://input");
  23. //log
  24. $oh = [];
  25. $oh['type'] = 'make';
  26. $oh['log'] = $json_data;
  27. M('log')->add( $oh );
  28. $data = json_decode( $json_data, true );
  29. if( !empty($data) && $data['return_code'] == 'success' )
  30. {
  31. $token = strtolower( $data['token'] );
  32. $order_no = $data['order_no'];
  33. $time = $data['time'];
  34. $status = $data['status'];
  35. $rider_name = $data['rider_name'];
  36. $rider_mobile = $data['rider_mobile'];
  37. $orderdistribution_order = M('lionfish_comshop_orderdistribution_order')->where( array('third_order_id' => $order_no ) )->find();
  38. $oh = [];
  39. $oh['type'] = 'step1';
  40. $oh['log'] = !empty($orderdistribution_order) ? 1 : 0;
  41. M('log')->add( $oh );
  42. if( !empty($orderdistribution_order) )
  43. {
  44. $appid = D('Home/Front')->get_config_by_name('wepro_appid' );
  45. $localtown_mk_token = D('Home/Front')->get_config_by_name('localtown_mk_token' );
  46. $new_token = strtolower( md5( $appid . $localtown_mk_token ) );
  47. $order_id = $orderdistribution_order['order_id'];
  48. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
  49. $order_num_alias = $order_info['order_num_alias'];
  50. if( $token == $new_token )
  51. {
  52. //校验正常开始处理逻辑
  53. switch( $status )
  54. {
  55. case 'accepted': //抢单了:
  56. //码科平台回调接口
  57. $other_data = array();
  58. $other_data['data_type'] = 'make';
  59. $other_data['order_status'] = 2;
  60. $other_data['dm_id'] = '';
  61. $other_data['dm_name'] = $rider_name;
  62. $other_data['dm_mobile'] = $rider_mobile;
  63. $other_data['third_id'] = '';
  64. //$order_sn, $order_status_id, $other_data
  65. D('Seller/Order')->do_localtown_thirth_delivery_return( $order_num_alias,0,$other_data);
  66. break;
  67. case 'wait_to_shop':
  68. //确认前往:+ 前往的日志
  69. $oh = array();
  70. $oh['order_id']= $order_id;
  71. $oh['order_status_id']= 4;
  72. $oh['comment']='配送员'.$rider_name.', 手机 '.$rider_mobile.':确认前往';
  73. $oh['date_added']=time();
  74. $oh['notify']=1;
  75. M('lionfish_comshop_order_history')->add( $oh );
  76. break;
  77. case 'payed':
  78. //取消订单:+ 前往的日志
  79. $oh = array();
  80. $oh['order_id']= $order_id;
  81. $oh['order_status_id']= 4;
  82. $oh['comment']='配送员'.$rider_name.', 手机 '.$rider_mobile.':取消订单';
  83. $oh['date_added']=time();
  84. $oh['notify']=1;
  85. M('lionfish_comshop_order_history')->add( $oh );
  86. break;
  87. case 'geted':
  88. //确认取件 //码科平台回调接口
  89. $oh = array();
  90. $oh['order_id']= $order_id;
  91. $oh['order_status_id']= 4;
  92. $oh['comment']='配送员'.$rider_name.', 手机 '.$rider_mobile.':确认取件';
  93. $oh['date_added']=time();
  94. $oh['notify']=1;
  95. M('lionfish_comshop_order_history')->add( $oh );
  96. $other_data = array();
  97. $other_data['data_type'] = 'make';
  98. $other_data['order_status'] = 3;
  99. $other_data['dm_id'] = '';
  100. $other_data['dm_name'] = $rider_name;
  101. $other_data['dm_mobile'] = $rider_mobile;
  102. $other_data['third_id'] = '';
  103. D('Seller/Order')->do_localtown_thirth_delivery_return( $order_num_alias,0, $other_data );
  104. break;
  105. case 'gotoed':
  106. //确认完成
  107. $oh = array();
  108. $oh['order_id']= $order_id;
  109. $oh['order_status_id']= 4;
  110. $oh['comment']='配送员'.$rider_name.', 手机 '.$rider_mobile.':确认送达';
  111. $oh['date_added']=time();
  112. $oh['notify']=1;
  113. M('lionfish_comshop_order_history')->add( $oh );
  114. $other_data = array();
  115. $other_data['data_type'] = 'make';
  116. $other_data['order_status'] = 4;
  117. D('Seller/Order')->do_localtown_thirth_delivery_return( $order_num_alias,6,$other_data);
  118. break;
  119. }
  120. }
  121. }
  122. }
  123. echo 'success';
  124. //Token加密为模块appid+token md5
  125. //抢单了:
  126. //{"token":"507e9dfa06df88b7655cb2671abe3ccb","order_no":"A20210118440401921","return_code":"success",
  127. //"time":1610959924,"status":"accepted","rider_name":"\u5c0f\u72ee","rider_mobile":"15159513836"}
  128. //确认前往:
  129. //{"token":"507e9dfa06df88b7655cb2671abe3ccb","order_no":"A20210118440401921","return_code":"success",
  130. //"time":1610959983,"status":"wait_to_shop","rider_name":"\u5c0f\u72ee","rider_mobile":"15159513836"}
  131. //确认取件
  132. //{"token":"507e9dfa06df88b7655cb2671abe3ccb","order_no":"A20210118440401921","return_code":"success",
  133. //"time":1610960013,"status":"geted","rider_name":"\u5c0f\u72ee","rider_mobile":"15159513836"}
  134. //确认完成
  135. //{"token":"507e9dfa06df88b7655cb2671abe3ccb","order_no":"A20210118440401921","return_code":"success",
  136. //"time":1610960073,"status":"gotoed","rider_name":"\u5c0f\u72ee","rider_mobile":"15159513836"}
  137. /**
  138. *
  139. * {"token":"24ea86c9748d8a476a7e0519f5ce32c7","order_no":"A20200424875992271",
  140. * "return_code":"success","time":1587698827,"status":"gotoed",
  141. * "rider_name":"\u6881\u534e\u6587","rider_mobile":"18178110414"}
  142. *
  143. */
  144. }
  145. }