ChainOrder.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <?php
  2. /*
  3. * 门店管理中心
  4. */
  5. namespace app\api\controller;
  6. use think\facade\Lang;
  7. class ChainOrder extends MobileChain {
  8. public function initialize() {
  9. parent::initialize();
  10. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/chain.lang.php');
  11. }
  12. /**
  13. * @api {POST} api/ChainOrder/get_order_list 订单列表
  14. * @apiVersion 1.0.0
  15. * @apiGroup ChainOrder
  16. *
  17. * @apiHeader {String} X-DS-KEY 门店授权token
  18. *
  19. * @apiParam {String} state_type 订单类型(state_default未到站state_arrive已到站state_pickup已取货)
  20. * @apiParam {String} search_name 关键词
  21. * @apiParam {String} hidden_success 是否隐藏已提货订单
  22. *
  23. * @apiSuccess {String} code 返回码,10000为成功
  24. * @apiSuccess {String} message 返回消息
  25. * @apiSuccess {Object} result 返回数据
  26. */
  27. public function get_order_list() {
  28. $chain_order_model = model('chain_order');
  29. $condition = array();
  30. $condition[] = array('chain_order_state', 'not in', [ORDER_STATE_CANCEL, ORDER_STATE_NEW]);
  31. $condition[] = array('chain_id', '=', $this->chain_info['chain_id']);
  32. $search_name = input('get.search_name');
  33. if ($search_name != '') {
  34. $condition[] = array('order_sn|shipping_code', 'like', '%' . $search_name . '%');
  35. View::assign('search_name', $search_name);
  36. }
  37. $allow_state_array = array('state_default', 'state_arrive', 'state_pickup');
  38. $state_type = input('post.state_type');
  39. if (in_array($state_type, $allow_state_array)) {
  40. $condition[] = array('chain_order_state', '=', str_replace($allow_state_array, array(ORDER_STATE_SEND, ORDER_STATE_PICKUP, ORDER_STATE_SUCCESS), $state_type));
  41. }
  42. $order_model = model('order');
  43. $chain_order_list = $chain_order_model->getChainOrderList($condition, '*', 10);
  44. foreach ($chain_order_list as $key => $val) {
  45. $chain_order_list[$key]['state_desc'] = get_order_state(array('order_state' => $val['chain_order_state']));
  46. $condition = array();
  47. $condition[] = array('order_id', '=', $val['order_id']);
  48. $extend_order_goods = $order_model->getOrdergoodsList($condition);
  49. foreach ($extend_order_goods as $k => $v) {
  50. $extend_order_goods[$k]['image_240_url'] = goods_cthumb($v['goods_image'], 240, $v['store_id']);
  51. }
  52. $chain_order_list[$key]['goods_list'] = $extend_order_goods;
  53. }
  54. $mobile_page = $chain_order_model->page_info;
  55. $chain_order_list = array_values($chain_order_list);
  56. $result = array_merge(array('chain_order_list' => $chain_order_list), mobile_page($mobile_page));
  57. ds_json_encode(10000, '', $result);
  58. }
  59. /**
  60. * @api {POST} api/ChainOrder/order_info 订单详情
  61. * @apiVersion 1.0.0
  62. * @apiGroup ChainOrder
  63. *
  64. * @apiHeader {String} X-DS-KEY 卖家授权token
  65. *
  66. * @apiParam {String} chain_order_id 订单id
  67. *
  68. * @apiSuccess {String} code 返回码,10000为成功
  69. * @apiSuccess {String} message 返回消息
  70. * @apiSuccess {Object} result 返回数据
  71. * @apiSuccess {Object} result.order_info 订单信息
  72. * @apiSuccess {Int} result.order_info.if_cancel 是否可取消 true是false否
  73. * @apiSuccess {Int} result.order_info.if_modify_price 是否可修改运费 true是false否
  74. * @apiSuccess {Int} result.order_info.if_spay_price 是否可修改商品价格 true是false否
  75. * @apiSuccess {Int} result.order_info.if_send 是否可发货 true是false否
  76. * @apiSuccess {Int} result.order_info.if_lock 是否被锁定 true是false否
  77. * @apiSuccess {Int} result.order_info.if_deliver 是否显示物流跟踪 true是false否
  78. * @apiSuccess {Object} result.order_info.extend_order_common 订单其他信息 (返回字段参考ordercommon表)
  79. * @apiSuccess {Object} result.order_info.extend_order_goods 订单商品信息 (返回字段参考ordergoods表)
  80. * @apiSuccess {Object} result.order_info.extend_order_goods.image_240_url 商品图片完整路径
  81. * @apiSuccess {Object} result.order_info.extend_order_goods.goods_type_cn 商品类型名称
  82. * @apiSuccess {Object} result.order_info.extend_order_goods.goods_url 商品PC链接
  83. * @apiSuccess {Object} result.order_info.extend_member 用户信息 (返回字段参考member表)
  84. * @apiSuccess {String} result.order_info.invoice 发票信息
  85. * @apiSuccess {String} result.order_info.reciver_phone 收货人手机号
  86. * @apiSuccess {String} result.order_info.reciver_name 收货人姓名
  87. * @apiSuccess {String} result.order_info.reciver_addr 收货地址
  88. * @apiSuccess {String} result.order_info.order_cancel_day 自动取消订单日期
  89. * @apiSuccess {Object} result.order_info.express_info 物流信息
  90. * @apiSuccess {String} result.order_info.express_info.express_code 物流公司代码
  91. * @apiSuccess {String} result.order_info.express_info.express_name 物流公司名称
  92. * @apiSuccess {String} result.order_info.express_info.express_url 物流公司官网
  93. * @apiSuccess {object} result.order_info.zengpin_list 赠品列表 (返回字段参考ordergoods表)
  94. * @apiSuccess {object} result.order_info.goods_list 订单商品列表 (返回字段参考ordergoods表)
  95. * @apiSuccess {object} result.order_info.goods_count 商品数量
  96. * @apiSuccess {object[]} result.order_info.extend_log.order_log_list 订单操作日志列表 (返回字段参考orderlog表)
  97. * @apiSuccess {object} result.order_info.daddress_info 发货信息 (返回字段参考daddress表)
  98. * @apiSuccess {object} result.order_info.real_pay_amount 实际支付金额
  99. */
  100. public function order_info() {
  101. $chain_order_id = intval(input('param.chain_order_id'));
  102. if (!$chain_order_id) {
  103. ds_json_encode(10001, lang('param_error'));
  104. }
  105. $chain_order_model = model('chain_order');
  106. $order_model = model('order');
  107. $condition = array();
  108. $condition[] = array('chain_order_id', '=', $chain_order_id);
  109. $condition[] = array('chain_id', '=', $this->chain_info['chain_id']);
  110. $order_info = $chain_order_model->getChainOrderInfo($condition);
  111. if (empty($order_info)) {
  112. ds_json_encode(10001, lang('store_order_none_existr'));
  113. }
  114. $order_info['state_desc'] = get_order_state(array('order_state' => $order_info['chain_order_state']));
  115. $condition = array();
  116. $condition[] = array('order_id', '=', $order_info['order_id']);
  117. $extend_order_goods = $order_model->getOrdergoodsList($condition);
  118. foreach ($extend_order_goods as $k => $v) {
  119. $extend_order_goods[$k]['image_240_url'] = goods_cthumb($v['goods_image'], 240, $v['store_id']);
  120. }
  121. $order_info['goods_list'] = $extend_order_goods;
  122. ds_json_encode(10000, '', array('chain_order_info' => $order_info));
  123. }
  124. /**
  125. * @api {POST} api/ChainOrder/search_deliver 物流跟踪
  126. * @apiVersion 1.0.0
  127. * @apiGroup ChainOrder
  128. *
  129. * @apiHeader {String} X-DS-KEY 门店授权token
  130. *
  131. * @apiParam {String} chain_order_id 订单id
  132. *
  133. * @apiSuccess {String} code 返回码,10000为成功
  134. * @apiSuccess {String} message 返回消息
  135. * @apiSuccess {Object} result 返回数据
  136. * @apiSuccess {String} result.express_name 物流公司名称
  137. * @apiSuccess {String} result.shipping_code 物流单号
  138. * @apiSuccess {Object[]} result.deliver_info 物流数据
  139. * @apiSuccess {String} result.deliver_info.context 内容
  140. * @apiSuccess {String} result.deliver_info.time 时间
  141. */
  142. public function search_deliver() {
  143. $chain_order_id = intval(input('post.chain_order_id'));
  144. if ($chain_order_id <= 0) {
  145. ds_json_encode(10001, lang('param_error'));
  146. }
  147. $chain_order_model = model('chain_order');
  148. $chain_order_info = $chain_order_model->getChainOrderInfo(array('chain_order_id' => $chain_order_id, 'chain_id' => $this->chain_info['chain_id']));
  149. if (empty($chain_order_info)) {
  150. ds_json_encode(10001, lang('order_not_exist'));
  151. }
  152. $express = rkcache('express', true);
  153. $express_code = $chain_order_info['express_code'];
  154. $express_name = $chain_order_info['express_name'];
  155. $deliver_info = $this->_get_express($express_code, $chain_order_info['shipping_code'], $chain_order_info['reciver_mobphone']);
  156. ds_json_encode(10000, '', array('express_name' => $express_name, 'shipping_code' => $chain_order_info['shipping_code'], 'deliver_info' => $deliver_info));
  157. }
  158. /**
  159. * 从第三方取快递信息
  160. *
  161. */
  162. public function _get_express($express_code, $shipping_code, $phone) {
  163. $result = model('express')->queryExpress($express_code, $shipping_code, $phone);
  164. if ($result['Success'] != true) {
  165. ds_json_encode(10001, lang('deliver_search_fail'));
  166. }
  167. $content['Traces'] = array_reverse($result['Traces']);
  168. $output = array();
  169. if (is_array($content['Traces'])) {
  170. foreach ($content['Traces'] as $k => $v) {
  171. if ($v['AcceptTime'] == '')
  172. continue;
  173. //$output[] = $v['time'] . '&nbsp;&nbsp;' . $v['context'];
  174. $output[$k]['AcceptTime'] = $v['AcceptTime'];
  175. $output[$k]['AcceptStation'] = $v['AcceptStation'];
  176. }
  177. }
  178. if (empty($output))
  179. ds_json_encode(10001, lang('deliver_not_exist'));
  180. return $output;
  181. }
  182. /**
  183. * @api {POST} api/ChainOrder/arrive_point 订单到站
  184. * @apiVersion 1.0.0
  185. * @apiGroup ChainOrder
  186. *
  187. * @apiHeader {String} X-DS-KEY 门店授权token
  188. *
  189. * @apiParam {String} chain_chain_order_id 订单ID
  190. *
  191. * @apiSuccess {String} code 返回码,10000为成功
  192. * @apiSuccess {String} message 返回消息
  193. * @apiSuccess {Object} result 返回数据
  194. */
  195. public function arrive_point() {
  196. $chain_order_id = intval(input('param.chain_order_id'));
  197. if ($chain_order_id <= 0) {
  198. ds_json_encode(10001, lang('param_error'));
  199. }
  200. $chain_order_model = model('chain_order');
  201. $condition = array();
  202. $condition[] = array('chain_order_id', '=', $chain_order_id);
  203. $condition[] = array('chain_id', '=', $this->chain_info['chain_id']);
  204. $chain_order_info = $chain_order_model->getChainOrderInfo($condition);
  205. if (!$chain_order_info) {
  206. ds_json_encode(10001, lang('order_not_exist'));
  207. }
  208. $pickup_code = $this->createPickupCode();
  209. // 更新提货订单表数据
  210. $update = array();
  211. $update['chain_order_pickup_code'] = $pickup_code;
  212. $chain_order_model->editChainOrderArrive($update, array('chain_order_id' => $chain_order_id, 'chain_id' => $this->chain_info['chain_id']));
  213. //更改订单状态
  214. $order_model = model('order');
  215. $order_model->editOrder(array('order_state' => ORDER_STATE_PICKUP), array(
  216. 'order_id' => $chain_order_info['order_id'],
  217. 'order_state' => ORDER_STATE_SEND
  218. ));
  219. // 发送短信提醒
  220. model('cron')->addCron(array('cron_exetime'=>TIMESTAMP,'cron_type'=>'sendPickupcode','cron_value'=>serialize(array('pickup_code' => $pickup_code, 'order_id' => $chain_order_info['order_id']))));
  221. ds_json_encode(10000, lang('ds_common_op_succ'));
  222. }
  223. /**
  224. * @api {POST} api/ChainOrder/pickup_parcel 订单取货
  225. * @apiVersion 1.0.0
  226. * @apiGroup ChainOrder
  227. *
  228. * @apiHeader {String} X-DS-KEY 门店授权token
  229. *
  230. * @apiParam {String} chain_order_id 订单ID
  231. * @apiParam {String} pickup_code 取货码
  232. *
  233. * @apiSuccess {String} code 返回码,10000为成功
  234. * @apiSuccess {String} message 返回消息
  235. * @apiSuccess {Object} result 返回数据
  236. */
  237. public function pickup_parcel() {
  238. if (!request()->isPost()) {
  239. } else {
  240. $chain_order_id = intval(input('post.chain_order_id'));
  241. $pickup_code = intval(input('post.pickup_code'));
  242. if ($chain_order_id <= 0 || $pickup_code <= 0) {
  243. ds_json_encode(10001, lang('param_error'));
  244. }
  245. $chain_order_model = model('chain_order');
  246. $chain_order_info = $chain_order_model->getChainOrderInfo(array('chain_order_id' => $chain_order_id, 'chain_id' => $this->chain_info['chain_id'], 'chain_order_lock_state' => 0, 'chain_order_pickup_code' => $pickup_code));
  247. if (empty($chain_order_info)) {
  248. ds_json_encode(10001, lang('pickup_code_error'));
  249. }
  250. $result = $chain_order_model->editChainOrderPickup(array(), array('chain_order_id' => $chain_order_id, 'chain_id' => $this->chain_info['chain_id'], 'chain_order_lock_state' => 0, 'chain_order_pickup_code' => $pickup_code));
  251. if ($result) {
  252. // 更新订单状态
  253. $order_info = model('order')->getOrderInfo(array('order_id' => $chain_order_info['order_id']));
  254. model('order', 'logic')->changeOrderStateReceive($order_info, 'buyer', lang('chain'), lang('chain_receive_goods'));
  255. ds_json_encode(10000, lang('ds_common_op_succ'));
  256. } else {
  257. ds_json_encode(10001, lang('ds_common_op_fail'));
  258. }
  259. }
  260. }
  261. /**
  262. * 生成提货码
  263. */
  264. private function createPickupCode() {
  265. return rand(1, 9) . rand(0, 9) . rand(0, 9) . rand(0, 9);
  266. }
  267. }