Membervrorder.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. use think\facade\Db;
  6. /**
  7. *
  8. *
  9. * ----------------------------------------------------------------------------
  10. *
  11. * 控制器
  12. */
  13. class Membervrorder extends BaseMember
  14. {
  15. public function initialize()
  16. {
  17. parent::initialize(); // TODO: Change the autogenerated stub
  18. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/memberorder.lang.php');
  19. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerorder.lang.php');
  20. }
  21. /**
  22. * 买家我的订单
  23. *
  24. */
  25. public function index()
  26. {
  27. $vrorder_model = model('vrorder');
  28. //搜索
  29. $condition = array();
  30. $condition[] = array('buyer_id', '=', session('member_id'));
  31. if (input('param.order_sn') != '') {
  32. $condition[] = array('order_sn', '=', input('param.order_sn'));
  33. }
  34. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', input('param.query_start_date'));
  35. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', input('param.query_end_date'));
  36. $start_unixtime = $if_start_date ? strtotime(input('param.query_start_date')) : null;
  37. $end_unixtime = $if_end_date ? strtotime(input('param.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. if (input('param.state_type') != '') {
  46. $order_state = str_replace(
  47. array(
  48. 'state_new', 'state_pay', 'state_success', 'state_cancel'
  49. ),
  50. array(
  51. ORDER_STATE_NEW, ORDER_STATE_PAY, ORDER_STATE_SUCCESS, ORDER_STATE_CANCEL
  52. ),
  53. input('param.state_type')
  54. );
  55. $condition[] = array('order_state', '=', $order_state);
  56. }
  57. $order_list = $vrorder_model->getVrorderList($condition, 20, '*', 'order_id desc');
  58. //没有使用的兑换码列表
  59. $order_list = $vrorder_model->getCodeRefundList($order_list);
  60. foreach ($order_list as $key => $order) {
  61. //显示取消订单
  62. $order_list[$key]['if_cancel'] = $vrorder_model->getVrorderOperateState('buyer_cancel', $order);
  63. //显示支付
  64. $order_list[$key]['if_pay'] = $vrorder_model->getVrorderOperateState('payment', $order);
  65. //显示删除订单(放入回收站)
  66. $order_list[$key]['if_delete'] = $vrorder_model->getVrorderOperateState('delete', $order);
  67. //显示永久删除
  68. $order_list[$key]['if_drop'] = $vrorder_model->getVrorderOperateState('drop', $order);
  69. //显示还原订单
  70. $order_list[$key]['if_restore'] = $vrorder_model->getVrorderOperateState('restore', $order);
  71. //显示退款
  72. $order_list[$key]['if_refund'] = $vrorder_model->getVrorderOperateState('refund', $order);
  73. //显示评价
  74. $order_list[$key]['if_evaluation'] = $vrorder_model->getVrorderOperateState('evaluation', $order);
  75. //显示商家信息(QQ,WW)
  76. $order_list[$key]['extend_store'] = model('store')->getStoreInfoByID($order['store_id']);
  77. }
  78. View::assign('order_list', $order_list);
  79. View::assign('show_page', $vrorder_model->page_info->render());
  80. $this->setMemberCurMenu('member_vr_order');
  81. $this->setMemberCurItem(input('param.recycle') ? 'member_order_recycle' : 'member_order');
  82. return View::fetch($this->template_dir . 'index');
  83. }
  84. /**
  85. * 订单详细
  86. *
  87. */
  88. public function show_order()
  89. {
  90. $order_id = intval(input('param.order_id'));
  91. if ($order_id <= 0) {
  92. $this->error(lang('member_order_none_exist'));
  93. }
  94. $vrorder_model = model('vrorder');
  95. $condition = array();
  96. $condition[] = array('order_id', '=', $order_id);
  97. $condition[] = array('buyer_id', '=', session('member_id'));
  98. $order_info = $vrorder_model->getVrorderInfo($condition);
  99. if (empty($order_info) || $order_info['delete_state'] == ORDER_DEL_STATE_DROP) {
  100. $this->error(lang('member_order_none_exist'));
  101. }
  102. $order_list = array();
  103. $order_list[$order_id] = $order_info;
  104. $order_list = $vrorder_model->getCodeRefundList($order_list); //没有使用的兑换码列表
  105. $order_info = $order_list[$order_id];
  106. $store_info = model('store')->getStoreInfo(array('store_id' => $order_info['store_id']));
  107. //取兑换码列表
  108. $vr_code_list = $vrorder_model->getShowVrordercodeList(array('order_id' => $order_info['order_id']));
  109. $order_info['extend_vr_order_code'] = $vr_code_list;
  110. //显示取消订单
  111. $order_info['if_cancel'] = $vrorder_model->getVrorderOperateState('buyer_cancel', $order_info);
  112. //显示订单进行步骤
  113. $order_info['step_list'] = $vrorder_model->getVrorderStep($order_info);
  114. //显示退款
  115. $order_info['if_refund'] = $vrorder_model->getVrorderOperateState('refund', $order_info);
  116. //显示评价
  117. $order_info['if_evaluation'] = $vrorder_model->getVrorderOperateState('evaluation', $order_info);
  118. //显示系统自动取消订单日期
  119. if ($order_info['order_state'] == ORDER_STATE_NEW) {
  120. $order_info['order_cancel_day'] = $order_info['add_time'] + config('ds_config.order_auto_cancel_day') * 24 * 3600;
  121. }
  122. if ($order_info['virtual_type'] == 1) {
  123. $order_info['virtual_content'] = explode('\r\n', $order_info['virtual_content']);
  124. }
  125. View::assign('order_info', $order_info);
  126. View::assign('store_info', $store_info);
  127. $this->setMemberCurMenu('member_vr_order');
  128. $this->setMemberCurItem('show_order');
  129. return View::fetch($this->template_dir . 'show_order');
  130. }
  131. /**
  132. * 买家订单状态操作
  133. *
  134. */
  135. public function change_state()
  136. {
  137. $vrorder_model = model('vrorder');
  138. $condition = array();
  139. $condition[] = array('order_id', '=', intval(input('param.order_id')));
  140. $condition[] = array('buyer_id', '=', session('member_id'));
  141. $order_info = $vrorder_model->getVrorderInfo($condition);
  142. if (input('param.state_type') == 'order_cancel') {
  143. $result = $this->_order_cancel($order_info, input('post.'));
  144. }
  145. if (!isset($result['code'])) {
  146. ds_json_encode(10001, lang('no_permission_operation'));
  147. } else {
  148. ds_json_encode(10000, $result['msg']);
  149. }
  150. }
  151. /**
  152. * 取消订单
  153. */
  154. private function _order_cancel($order_info, $post)
  155. {
  156. if (!request()->isPost()) {
  157. View::assign('order_info', $order_info);
  158. echo View::fetch($this->template_dir . 'cancel');
  159. exit();
  160. } else {
  161. $vrorder_model = model('vrorder');
  162. $logic_vrorder = model('vrorder', 'logic');
  163. $if_allow = $vrorder_model->getVrorderOperateState('buyer_cancel', $order_info);
  164. if (!$if_allow) {
  165. return callback(false, lang('have_right_operate'));
  166. }
  167. $msg = $post['state_info1'] != '' ? $post['state_info1'] : $post['state_info'];
  168. return $logic_vrorder->changeOrderStateCancel($order_info, 'buyer', $msg);
  169. }
  170. }
  171. /**
  172. * 发送兑换码到手机
  173. */
  174. public function resend()
  175. {
  176. if (!request()->isPost()) {
  177. return View::fetch($this->template_dir . 'resend');
  178. exit();
  179. }
  180. if (!preg_match('/^[\d]{11}$/', input('post.buyer_phone'))) {
  181. ds_json_encode(10001, lang('please_fill_phone_number_correctly'));
  182. }
  183. $order_id = intval(input('post.order_id'));
  184. if ($order_id <= 0) {
  185. ds_json_encode(10001, lang('member_change_parameter_error'));
  186. }
  187. $vrorder_model = model('vrorder');
  188. $condition = array();
  189. $condition[] = array('order_id', '=', $order_id);
  190. $condition[] = array('buyer_id', '=', session('member_id'));
  191. $order_info = $vrorder_model->getVrorderInfo($condition);
  192. if (empty($order_info) && $order_info['order_state'] != ORDER_STATE_PAY) {
  193. ds_json_encode(10001, lang('error_order_information'));
  194. }
  195. if ($order_info['vr_send_times'] >= 5) {
  196. ds_json_encode(10001, lang('you_send_too_many_times'));
  197. }
  198. //发送兑换码到手机
  199. $param = array(
  200. 'order_id' => $order_id, 'buyer_id' => session('member_id'), 'buyer_phone' => $order_info['buyer_phone']
  201. );
  202. $vrorder_model->sendVrCode($param);
  203. $vrorder_model->editVrorder(array('vr_send_times' => Db::raw('vr_send_times+1')), array('order_id' => $order_id));
  204. ds_json_encode(10000, lang('send_success'));
  205. }
  206. /**
  207. * 用户中心右边,小导航
  208. *
  209. * @param string $menu_type 导航类型
  210. * @param string $menu_key 当前导航的menu_key
  211. * @return
  212. */
  213. protected function getMemberItemList()
  214. {
  215. $menu_array = array(
  216. array(
  217. 'name' => 'member_order', 'text' => lang('ds_member_path_order_list'),
  218. 'url' => (string)url('Membervrorder/index')
  219. ),
  220. );
  221. if (request()->action() == 'show_order') {
  222. $menu_array[] = array(
  223. 'name' => 'show_order', 'text' => lang('member_show_order_desc'),
  224. 'url' => 'javascript:void(0)'
  225. );
  226. }
  227. return $menu_array;
  228. }
  229. }