Memberorder.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\Lang;
  4. use think\facade\View;
  5. use think\facade\Db;
  6. /**
  7. *
  8. *
  9. * ----------------------------------------------------------------------------
  10. *
  11. * 控制器
  12. */
  13. class Memberorder extends BaseMember
  14. {
  15. public function initialize()
  16. {
  17. parent::initialize();
  18. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberorder.lang.php');
  19. }
  20. public function index()
  21. {
  22. $order_model = model('order');
  23. //搜索
  24. $condition = array();
  25. $condition[] = array('buyer_id', '=', session('member_id'));
  26. $order_sn = input('param.order_sn');
  27. if ($order_sn != '') {
  28. $condition[] = array('order_sn', 'like', '%' . $order_sn . '%');
  29. }
  30. $query_start_date = input('param.query_start_date');
  31. $query_end_date = input('param.query_end_date');
  32. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_date);
  33. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_date);
  34. $start_unixtime = $if_start_date ? strtotime($query_start_date) : null;
  35. $end_unixtime = $if_end_date ? strtotime($query_end_date) : null;
  36. if ($start_unixtime) {
  37. $condition[] = array('add_time', '>=', $start_unixtime);
  38. }
  39. if ($end_unixtime) {
  40. $end_unixtime = $end_unixtime + 86399;
  41. $condition[] = array('add_time', '<=', $end_unixtime);
  42. }
  43. $state_type = input('param.state_type');
  44. if ($state_type != '') {
  45. $condition[] = array('order_state', '=', str_replace(
  46. array('state_new', 'state_pay', 'state_send', 'state_success', 'state_noeval', 'state_cancel'),
  47. array(ORDER_STATE_NEW, ORDER_STATE_PAY, ORDER_STATE_SEND, ORDER_STATE_SUCCESS, ORDER_STATE_SUCCESS, ORDER_STATE_CANCEL),
  48. $state_type
  49. ));
  50. }
  51. if ($state_type == 'state_noeval') {
  52. $condition[] = array('evaluation_state', '=', 0);
  53. $condition[] = array('refund_state', '=', 0);
  54. $condition[] = array('order_state', '=', ORDER_STATE_SUCCESS);
  55. }
  56. //回收站
  57. $recycle = input('param.recycle');
  58. if ($recycle) {
  59. $condition[] = array('delete_state', '=', 1);
  60. } else {
  61. $condition[] = array('delete_state', '=', 0);
  62. }
  63. $order_list = $order_model->getOrderList($condition, 5, '*', 'order_id desc', '', array('order_common', 'order_goods', 'ppintuanorder', 'store'));
  64. View::assign('show_page', $order_model->page_info->render());
  65. $refundreturn_model = model('refundreturn');
  66. $order_list = $refundreturn_model->getGoodsRefundList($order_list);
  67. //订单列表以支付单pay_sn分组显示
  68. $order_group_list = array();
  69. $order_pay_sn_array = array();
  70. foreach ($order_list as $order_id => $order) {
  71. //显示取消订单
  72. $order['if_cancel'] = $order_model->getOrderOperateState('buyer_cancel', $order);
  73. //显示退款取消订单
  74. $order['if_refund_cancel'] = $order_model->getOrderOperateState('refund_cancel', $order);
  75. //显示投诉
  76. $order['if_complain'] = $order_model->getOrderOperateState('complain', $order);
  77. //显示收货
  78. $order['if_receive'] = $order_model->getOrderOperateState('receive', $order);
  79. //显示锁定中
  80. $order['if_lock'] = $order_model->getOrderOperateState('lock', $order);
  81. //显示物流跟踪
  82. $order['if_deliver'] = $order_model->getOrderOperateState('deliver', $order);
  83. //显示评价
  84. $order['if_evaluation'] = $order_model->getOrderOperateState('evaluation', $order);
  85. //显示删除订单(放入回收站)
  86. $order['if_delete'] = $order_model->getOrderOperateState('delete', $order);
  87. //显示永久删除
  88. $order['if_drop'] = $order_model->getOrderOperateState('drop', $order);
  89. //显示还原订单
  90. $order['if_restore'] = $order_model->getOrderOperateState('restore', $order);
  91. foreach ($order['extend_order_goods'] as $value) {
  92. $value['goods_type_cn'] = get_order_goodstype($value['goods_type']);
  93. $value['goods_url'] = (string) url('Goods/index', ['goods_id' => $value['goods_id']]);
  94. if ($value['goods_type'] == 5) {
  95. $order['zengpin_list'][] = $value;
  96. } else {
  97. $order['goods_list'][] = $value;
  98. }
  99. }
  100. if (empty($order['zengpin_list'])) {
  101. $order['goods_count'] = count($order['goods_list']);
  102. } else {
  103. $order['goods_count'] = count($order['goods_list']) + 1;
  104. }
  105. $order_group_list[$order['pay_sn']]['order_list'][] = $order;
  106. //如果有在线支付且未付款的订单则显示合并付款链接
  107. if ($order['order_state'] == ORDER_STATE_NEW || $order['order_state'] == ORDER_STATE_DEPOSIT || $order['order_state'] == ORDER_STATE_REST) {
  108. if (!isset($order_group_list[$order['pay_sn']]['pay_amount'])) {
  109. $order_group_list[$order['pay_sn']]['pay_amount'] = 0;
  110. }
  111. $order_group_list[$order['pay_sn']]['pay_amount'] += ($order['order_state'] == ORDER_STATE_DEPOSIT ? $order['presell_deposit_amount'] : ($order['order_amount'] - $order['presell_deposit_amount'] + $order['presell_rcb_amount'] + $order['presell_pd_amount'])) - $order['pd_amount'] - $order['rcb_amount'];
  112. }
  113. $order_group_list[$order['pay_sn']]['add_time'] = $order['add_time'];
  114. //记录一下pay_sn,后面需要查询支付单表
  115. $order_pay_sn_array[] = $order['pay_sn'];
  116. }
  117. //取得这些订单下的支付单列表
  118. $condition = array();
  119. $condition[] = array('pay_sn', 'in', array_unique($order_pay_sn_array));
  120. $order_pay_list = $order_model->getOrderpayList($condition, '*', '', 'pay_sn');
  121. foreach ($order_group_list as $pay_sn => $pay_info) {
  122. $order_group_list[$pay_sn]['pay_info'] = isset($order_pay_list[$pay_sn]) ? $order_pay_list[$pay_sn] : '';
  123. }
  124. View::assign('order_group_list', $order_group_list);
  125. View::assign('order_pay_list', $order_pay_list);
  126. /* 设置买家当前菜单 */
  127. $this->setMemberCurMenu('member_order');
  128. /* 设置买家当前栏目 */
  129. if ($recycle) {
  130. $this->setMemberCurItem('member_order_recycle');
  131. } else {
  132. $this->setMemberCurItem('member_order');
  133. }
  134. return View::fetch($this->template_dir . 'index');
  135. }
  136. /**
  137. * 物流跟踪
  138. */
  139. public function search_deliver()
  140. {
  141. $order_id = intval(input('param.order_id'));
  142. if ($order_id <= 0) {
  143. $this->error(lang('param_error'), '');
  144. }
  145. $order_model = model('order');
  146. $condition[] = array('order_id', '=', $order_id);
  147. $condition[] = array('buyer_id', '=', session('member_id'));
  148. $order_info = $order_model->getOrderInfo($condition, array('order_common', 'order_goods'));
  149. if (empty($order_info) || !in_array($order_info['order_state'], array(ORDER_STATE_SEND, ORDER_STATE_SUCCESS))) {
  150. $this->error(lang('no_information_found'));
  151. }
  152. View::assign('order_info', $order_info);
  153. //卖家信息
  154. $store_model = model('store');
  155. $store_info = $store_model->getStoreInfoByID($order_info['store_id']);
  156. View::assign('store_info', $store_info);
  157. //卖家发货信息
  158. $daddress_info = model('daddress')->getAddressInfo(array('daddress_id' => $order_info['extend_order_common']['daddress_id']));
  159. View::assign('daddress_info', $daddress_info);
  160. //取得配送公司代码
  161. $express = rkcache('express', true);
  162. View::assign('express_code', isset($express[$order_info['extend_order_common']['shipping_express_id']]) ? $express[$order_info['extend_order_common']['shipping_express_id']]['express_code'] : '');
  163. View::assign('express_name', isset($express[$order_info['extend_order_common']['shipping_express_id']]) ? $express[$order_info['extend_order_common']['shipping_express_id']]['express_name'] : '');
  164. View::assign('express_url', isset($express[$order_info['extend_order_common']['shipping_express_id']]) ? $express[$order_info['extend_order_common']['shipping_express_id']]['express_url'] : '');
  165. View::assign('shipping_code', $order_info['shipping_code']);
  166. View::assign('left_show', 'order_view');
  167. /* 设置买家当前菜单 */
  168. $this->setMemberCurMenu('member_order');
  169. /* 设置买家当前栏目 */
  170. $this->setMemberCurItem('search_deliver');
  171. return View::fetch($this->template_dir . 'search_deliver');
  172. }
  173. /**
  174. * 从第三方取快递信息
  175. *
  176. */
  177. public function get_express()
  178. {
  179. $result = model('express')->queryExpress(input('param.express_code'), input('param.shipping_code'), input('param.phone'));
  180. if ($result['Success'] != true) {
  181. exit(json_encode(false));
  182. }
  183. $content['Traces'] = array_reverse($result['Traces']);
  184. $output = array();
  185. if (is_array($content['Traces'])) {
  186. foreach ($content['Traces'] as $k => $v) {
  187. if ($v['AcceptTime'] == '')
  188. continue;
  189. $output[] = $v['AcceptTime'] . '&nbsp;&nbsp;' . $v['AcceptStation'];
  190. }
  191. }
  192. if (empty($output))
  193. exit(json_encode(false));
  194. echo json_encode($output);
  195. }
  196. /**
  197. * 订单详细
  198. *
  199. */
  200. public function show_order()
  201. {
  202. $order_id = intval(input('param.order_id'));
  203. if ($order_id <= 0) {
  204. $this->error(lang('member_order_none_exist'));
  205. }
  206. $order_model = model('order');
  207. $condition = array();
  208. $condition[] = array('order_id', '=', $order_id);
  209. $condition[] = array('buyer_id', '=', session('member_id'));
  210. $order_info = $order_model->getOrderInfo($condition, array('order_goods', 'order_common', 'store'));
  211. if (empty($order_info) || $order_info['delete_state'] == ORDER_DEL_STATE_DROP) {
  212. $this->error(lang('member_order_none_exist'));
  213. }
  214. $refundreturn_model = model('refundreturn');
  215. $order_list = array();
  216. $order_list[$order_id] = $order_info;
  217. $order_list = $refundreturn_model->getGoodsRefundList($order_list, 1); //订单商品的退款退货显示
  218. $order_info = $order_list[$order_id];
  219. $refund_all = isset($order_info['refund_list'][0]) ? $order_info['refund_list'][0] : '';
  220. if (!empty($refund_all) && $refund_all['seller_state'] < 3) { //订单全部退款商家审核状态:1为待审核,2为同意,3为不同意
  221. View::assign('refund_all', $refund_all);
  222. }
  223. //显示锁定中
  224. $order_info['if_lock'] = $order_model->getOrderOperateState('lock', $order_info);
  225. //显示取消订单
  226. $order_info['if_cancel'] = $order_model->getOrderOperateState('buyer_cancel', $order_info);
  227. //显示退款取消订单
  228. $order_info['if_refund_cancel'] = $order_model->getOrderOperateState('refund_cancel', $order_info);
  229. //显示投诉
  230. $order_info['if_complain'] = $order_model->getOrderOperateState('complain', $order_info);
  231. //显示收货
  232. $order_info['if_receive'] = $order_model->getOrderOperateState('receive', $order_info);
  233. //显示物流跟踪
  234. $order_info['if_deliver'] = $order_model->getOrderOperateState('deliver', $order_info);
  235. //显示评价
  236. $order_info['if_evaluation'] = $order_model->getOrderOperateState('evaluation', $order_info);
  237. //显示系统自动取消订单日期
  238. if ($order_info['order_state'] == ORDER_STATE_NEW || $order_info['order_state'] == ORDER_STATE_DEPOSIT) {
  239. $order_info['order_cancel_day'] = $order_info['add_time'] + config('ds_config.order_auto_cancel_day') * 24 * 3600;
  240. } else if ($order_info['order_state'] == ORDER_STATE_REST) {
  241. $order_info['order_cancel_day'] = $order_info['presell_end_time'] + 72 * 3600;
  242. }
  243. //显示快递信息
  244. if ($order_info['shipping_code'] != '') {
  245. $express = rkcache('express', true);
  246. if (isset($express[$order_info['extend_order_common']['shipping_express_id']])) {
  247. $order_info['express_info']['express_code'] = $express[$order_info['extend_order_common']['shipping_express_id']]['express_code'];
  248. $order_info['express_info']['express_name'] = $express[$order_info['extend_order_common']['shipping_express_id']]['express_name'];
  249. $order_info['express_info']['express_url'] = $express[$order_info['extend_order_common']['shipping_express_id']]['express_url'];
  250. } else {
  251. $order_info['express_info']['express_code'] = '';
  252. $order_info['express_info']['express_name'] = '';
  253. $order_info['express_info']['express_url'] = '';
  254. }
  255. }
  256. //显示系统自动收获时间
  257. if ($order_info['order_state'] == ORDER_STATE_SEND) {
  258. $order_info['order_confirm_day'] = $order_info['delay_time'] + config('ds_config.order_auto_receive_day') * 24 * 3600;
  259. }
  260. //如果订单已取消,取得取消原因、时间,操作人
  261. if ($order_info['order_state'] == ORDER_STATE_CANCEL) {
  262. $order_info['close_info'] = $order_model->getOrderlogInfo(array('order_id' => $order_info['order_id']), 'log_id desc');
  263. }
  264. $order_info['chain_order_type'] = 0;
  265. //如果是待自提则获取提货码
  266. $chain_order_model = model('chain_order');
  267. $chain_order_info = $chain_order_model->getChainOrderInfo(array(array('order_id', '=', $order_info['order_id'])));
  268. if ($chain_order_info) {
  269. $order_info['chain_order_type'] = $chain_order_info['chain_order_type'];
  270. $order_info['chain_order_pickup_code'] = $chain_order_info['chain_order_pickup_code'];
  271. $chain_model = model('chain');
  272. $chain_info = $chain_model->getChainInfo(array(array('chain_id', '=', $chain_order_info['chain_id'])));
  273. if ($chain_info) {
  274. $order_info['chain_addressname'] = $chain_info['chain_addressname'];
  275. $order_info['chain_address'] = $chain_info['chain_address'];
  276. $phone_list = array();
  277. if ($chain_info['chain_mobile']) {
  278. $phone_list[] = $chain_info['chain_mobile'];
  279. }
  280. if ($chain_info['chain_telephony']) {
  281. $phone_list[] = $chain_info['chain_telephony'];
  282. }
  283. $order_info['chain_phone'] = implode(',', $phone_list);
  284. }
  285. }
  286. foreach ($order_info['extend_order_goods'] as $value) {
  287. $value['image_240_url'] = goods_cthumb($value['goods_image'], 240, $value['store_id']);
  288. $value['goods_type_cn'] = get_order_goodstype($value['goods_type']);
  289. $value['goods_url'] = (string) url('Goods/index', ['goods_id' => $value['goods_id']]);
  290. if ($value['goods_type'] == 5) {
  291. $order_info['zengpin_list'][] = $value;
  292. } else {
  293. $order_info['goods_list'][] = $value;
  294. }
  295. }
  296. if (empty($order_info['zengpin_list'])) {
  297. $order_info['goods_count'] = count($order_info['goods_list']);
  298. } else {
  299. $order_info['goods_count'] = count($order_info['goods_list']) + 1;
  300. }
  301. View::assign('order_info', $order_info);
  302. //卖家发货信息
  303. if (!empty($order_info['extend_order_common']['daddress_id'])) {
  304. $daddress_info = model('daddress')->getAddressInfo(array('daddress_id' => $order_info['extend_order_common']['daddress_id']));
  305. View::assign('daddress_info', $daddress_info);
  306. }
  307. /* 设置买家当前菜单 */
  308. $this->setMemberCurMenu('member_order');
  309. /* 设置买家当前栏目 */
  310. $this->setMemberCurItem('my_album');
  311. return View::fetch($this->template_dir . 'show_order');
  312. }
  313. /**
  314. * 买家订单状态操作
  315. *
  316. */
  317. public function change_state()
  318. {
  319. $state_type = input('param.state_type');
  320. $order_id = intval(input('param.order_id'));
  321. $order_model = model('order');
  322. $condition = array();
  323. $condition[] = array('order_id', '=', $order_id);
  324. $condition[] = array('buyer_id', '=', session('member_id'));
  325. $order_info = $order_model->getOrderInfo($condition);
  326. if ($state_type == 'order_cancel') {
  327. $result = $this->_order_cancel($order_info, input('post.'));
  328. } else if ($state_type == 'order_receive') {
  329. $result = $this->_order_receive($order_info, input('post.'));
  330. } else if (in_array($state_type, array('order_delete', 'order_drop', 'order_restore'))) {
  331. $result = $this->_order_recycle($order_info, input('get.'));
  332. } else {
  333. exit();
  334. }
  335. if (!$result['code']) {
  336. ds_json_encode(10001, $result['msg']);
  337. } else {
  338. ds_json_encode(10000, $result['msg']);
  339. }
  340. }
  341. /**
  342. * 取消订单
  343. */
  344. private function _order_cancel($order_info, $post)
  345. {
  346. if (!request()->isPost()) {
  347. View::assign('order_info', $order_info);
  348. echo View::fetch($this->template_dir . 'cancel');
  349. exit();
  350. } else {
  351. $order_model = model('order');
  352. $logic_order = model('order', 'logic');
  353. $if_allow = $order_model->getOrderOperateState('buyer_cancel', $order_info);
  354. if (!$if_allow) {
  355. return ds_callback(false, lang('have_right_operate'));
  356. }
  357. $msg = $post['state_info1'] != '' ? $post['state_info1'] : $post['state_info'];
  358. try {
  359. Db::startTrans();
  360. $logic_order->changeOrderStateCancel($order_info, 'buyer', session('member_name'), $msg);
  361. } catch (\Exception $e) {
  362. Db::rollback();
  363. return ds_callback(false, $e->getMessage());
  364. }
  365. Db::commit();
  366. return ds_callback(true, lang('ds_common_op_succ'));
  367. }
  368. }
  369. /**
  370. * 收货
  371. */
  372. private function _order_receive($order_info, $post)
  373. {
  374. if (!request()->isPost()) {
  375. View::assign('order_info', $order_info);
  376. echo View::fetch($this->template_dir . 'receive');
  377. exit();
  378. } else {
  379. $order_model = model('order');
  380. $logic_order = model('order', 'logic');
  381. $if_allow = $order_model->getOrderOperateState('receive', $order_info);
  382. if (!$if_allow) {
  383. return ds_callback(false, lang('have_right_operate'));
  384. }
  385. return $logic_order->changeOrderStateReceive($order_info, 'buyer', session('member_name'));
  386. }
  387. }
  388. /**
  389. * 回收站
  390. */
  391. private function _order_recycle($order_info, $get)
  392. {
  393. $order_model = model('order');
  394. $logic_order = model('order', 'logic');
  395. $state_type = str_replace(array('order_delete', 'order_drop', 'order_restore'), array('delete', 'drop', 'restore'), input('param.state_type'));
  396. $if_allow = $order_model->getOrderOperateState($state_type, $order_info);
  397. if (!$if_allow) {
  398. return ds_callback(false, lang('have_right_operate'));
  399. }
  400. return $logic_order->changeOrderStateRecycle($order_info, 'buyer', $state_type);
  401. }
  402. /**
  403. * 栏目菜单
  404. */
  405. function getMemberItemList()
  406. {
  407. $item_list = array(
  408. array(
  409. 'name' => 'member_order',
  410. 'text' => lang('ds_member_path_order_list'),
  411. 'url' => (string) url('Memberorder/index'),
  412. ),
  413. array(
  414. 'name' => 'member_order_recycle',
  415. 'text' => lang('recycle_bin'),
  416. 'url' => (string) url('Memberorder/index', ['recycle' => '1']),
  417. ),
  418. );
  419. return $item_list;
  420. }
  421. }