Memberorder.php 21 KB

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