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