Memberorder.php 21 KB

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