Membervrorder.php 10 KB

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