NotifyController.class.php 7.0 KB

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