Sellervrorder.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <?php
  2. /*
  3. * 虚拟订单
  4. */
  5. namespace app\home\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. /**
  9. *
  10. *
  11. * ----------------------------------------------------------------------------
  12. *
  13. * 控制器
  14. */
  15. class Sellervrorder extends BaseSeller
  16. {
  17. public function initialize()
  18. {
  19. parent::initialize();
  20. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellervrorder.lang.php');
  21. }
  22. /**
  23. * 虚拟订单列表
  24. *
  25. */
  26. public function index()
  27. {
  28. $vrorder_model = model('vrorder');
  29. $condition = array();
  30. $condition[] = array('store_id', '=', session('store_id'));
  31. $order_sn = input('get.order_sn');
  32. if ($order_sn != '') {
  33. $condition[] = array('order_sn', '=', $order_sn);
  34. }
  35. $buyer_name = input('get.buyer_name');
  36. if ($buyer_name != '') {
  37. $condition[] = array('buyer_name', '=', $buyer_name);
  38. }
  39. $allow_state_array = array('state_new', 'state_pay', 'state_success', 'state_cancel');
  40. $state_type = input('param.state_type');
  41. if (in_array($state_type, $allow_state_array)) {
  42. $condition[] = array('order_state', '=', str_replace($allow_state_array, array(ORDER_STATE_NEW, ORDER_STATE_PAY, ORDER_STATE_SUCCESS, ORDER_STATE_CANCEL), $state_type));
  43. } else {
  44. $state_type = 'store_order';
  45. }
  46. $query_start_date = input('get.query_start_date');
  47. $query_end_date = input('get.query_end_date');
  48. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_date);
  49. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_date);
  50. $start_unixtime = $if_start_date ? strtotime($query_end_date) : null;
  51. $end_unixtime = $if_end_date ? (strtotime($query_start_date) + 86399) : null;
  52. if ($start_unixtime) {
  53. $condition[] = array('add_time', '>=', $start_unixtime);
  54. }
  55. if ($end_unixtime) {
  56. $condition[] = array('add_time', '<=', $end_unixtime);
  57. }
  58. $skip_off = input('get.skip_off');
  59. if ($skip_off == 1) {
  60. $condition[] = array('order_state', '<>', ORDER_STATE_CANCEL);
  61. }
  62. $order_list = $vrorder_model->getVrorderList($condition, 20, '*', 'order_id desc');
  63. View::assign('show_page', $vrorder_model->page_info->render());
  64. foreach ($order_list as $key => $order) {
  65. //显示取消订单
  66. $order_list[$key]['if_cancel'] = $vrorder_model->getVrorderOperateState('buyer_cancel', $order);
  67. //追加返回买家信息
  68. $order_list[$key]['extend_member'] = model('member')->getMemberInfoByID($order['buyer_id']);
  69. }
  70. View::assign('order_list', $order_list);
  71. /* 设置卖家当前菜单 */
  72. $this->setSellerCurMenu('sellervrorder');
  73. /* 设置卖家当前栏目 */
  74. $this->setSellerCurItem($state_type);
  75. return View::fetch($this->template_dir . 'index');
  76. }
  77. /**
  78. * 卖家订单详情
  79. *
  80. */
  81. public function show_order()
  82. {
  83. $order_id = intval(input('param.order_id'));
  84. if ($order_id <= 0) {
  85. $this->error(lang('param_error'));
  86. }
  87. $vrorder_model = model('vrorder');
  88. $condition = array();
  89. $condition[] = array('order_id', '=', $order_id);
  90. $condition[] = array('store_id', '=', session('store_id'));
  91. $order_info = $vrorder_model->getVrorderInfo($condition);
  92. if (empty($order_info)) {
  93. $this->error(lang('store_order_none_exist'));
  94. }
  95. //取兑换码列表
  96. $vr_code_list = $vrorder_model->getShowVrordercodeList(array('order_id' => $order_info['order_id']));
  97. $order_info['extend_vr_order_code'] = $vr_code_list;
  98. //显示取消订单
  99. $order_info['if_cancel'] = $vrorder_model->getVrorderOperateState('buyer_cancel', $order_info);
  100. //显示订单进行步骤
  101. $order_info['step_list'] = $vrorder_model->getVrorderStep($order_info);
  102. //显示系统自动取消订单日期
  103. if ($order_info['order_state'] == ORDER_STATE_NEW) {
  104. $order_info['order_cancel_day'] = $order_info['add_time'] + config('ds_config.order_auto_cancel_day') * 24 * 3600;
  105. }
  106. if ($order_info['virtual_type'] == 1) {
  107. $order_info['virtual_content'] = explode('\r\n', $order_info['virtual_content']);
  108. }
  109. View::assign('order_info', $order_info);
  110. $this->setSellerCurMenu('sellervrorder');
  111. $this->setSellerCurItem('store_order');
  112. return View::fetch($this->template_dir . 'show_order');
  113. }
  114. /**
  115. * 卖家订单状态操作
  116. *
  117. */
  118. public function change_state()
  119. {
  120. $vrorder_model = model('vrorder');
  121. $condition = array();
  122. $condition[] = array('order_id', '=', intval(input('param.order_id')));
  123. $condition[] = array('store_id', '=', session('store_id'));
  124. $order_info = $vrorder_model->getVrorderInfo($condition);
  125. $state_type = input('param.state_type');
  126. if ($state_type == 'order_cancel') {
  127. $result = $this->_order_cancel($order_info, input('post.'));
  128. }
  129. if (!isset($result['code'])) {
  130. ds_json_encode(10001, lang('error'));
  131. } else {
  132. ds_json_encode(10000, $result['msg']);
  133. }
  134. }
  135. /**
  136. * 取消订单
  137. * @param arrty $order_info
  138. * @param arrty $post
  139. * @throws Exception
  140. */
  141. private function _order_cancel($order_info, $post)
  142. {
  143. if (!request()->isPost()) {
  144. View::assign('order_id', $order_info['order_id']);
  145. View::assign('order_info', $order_info);
  146. echo View::fetch($this->template_dir . 'cancel');
  147. exit();
  148. } else {
  149. $vrorder_model = model('vrorder');
  150. $logic_vrorder = model('vrorder', 'logic');
  151. $if_allow = $vrorder_model->getVrorderOperateState('store_cancel', $order_info);
  152. if (!$if_allow) {
  153. return ds_callback(false, lang('have_right_operate'));
  154. }
  155. $msg = $post['state_info1'] != '' ? $post['state_info1'] : $post['state_info'];
  156. return $logic_vrorder->changeOrderStateCancel($order_info, 'seller', $msg);
  157. }
  158. }
  159. public function exchange()
  160. {
  161. $data = $this->_exchange();
  162. exit(json_encode($data));
  163. }
  164. /**
  165. * 兑换码消费
  166. */
  167. private function _exchange()
  168. {
  169. if (input('param.submit_exchange') == 'ok') {
  170. if (!preg_match('/^[a-zA-Z0-9]{15,18}$/', input('get.vr_code'))) {
  171. return array('error' => lang('exchange_code_format_error'));
  172. }
  173. $vrorder_model = model('vrorder');
  174. $vr_code_info = $vrorder_model->getVrordercodeInfo(array('vr_code' => input('get.vr_code')));
  175. if (empty($vr_code_info) || $vr_code_info['store_id'] != session('store_id')) {
  176. return array('error' => lang('exchange_code_not_exist'));
  177. }
  178. if ($vr_code_info['vr_state'] == '1') {
  179. return array('error' => lang('exchange_code_been_used'));
  180. }
  181. if ($vr_code_info['vr_indate'] < TIMESTAMP) {
  182. return array('error' => lang('exchange_code_expired') . date('Y-m-d H:i:s', $vr_code_info['vr_indate']));
  183. }
  184. if ($vr_code_info['refund_lock'] > 0) { //退款锁定状态:0为正常,1为锁定(待审核),2为同意
  185. return array('error' => lang('exchange_code_been_applied_refund'));
  186. }
  187. //更新兑换码状态
  188. $update = array();
  189. $update['vr_state'] = 1;
  190. $update['vr_usetime'] = TIMESTAMP;
  191. $update = $vrorder_model->editVrorderCode($update, array('vr_code' => input('get.vr_code')));
  192. //如果全部兑换完成,更新订单状态
  193. model('vrorder', 'logic')->changeOrderStateSuccess($vr_code_info['order_id']);
  194. if ($update) {
  195. //取得返回信息
  196. $order_info = $vrorder_model->getVrorderInfo(array('order_id' => $vr_code_info['order_id']));
  197. if ($order_info['use_state'] == '0') {
  198. $vrorder_model->editVrorder(array('use_state' => 1), array('order_id' => $vr_code_info['order_id']));
  199. }
  200. $order_info['img_240'] = goods_thumb($order_info, 240);
  201. $order_info['goods_url'] = (string) url('Goods/index', ['goods_id' => $order_info['goods_id']]);
  202. $order_info['order_url'] = (string) url('Sellervrorder/show_order', ['order_id' => $order_info['order_id']]);
  203. return array('error' => '', 'data' => $order_info);
  204. }
  205. } else {
  206. $state_type = input('state_type');;
  207. /* 设置卖家当前菜单 */
  208. $this->setSellerCurMenu('sellervrorder');
  209. /* 设置卖家当前栏目 */
  210. $this->setSellerCurItem($state_type);
  211. echo View::fetch($this->template_dir . 'exchange');
  212. exit;
  213. }
  214. }
  215. /**
  216. * 栏目菜单
  217. */
  218. function getSellerItemList()
  219. {
  220. $menu_array = array(
  221. array(
  222. 'name' => 'store_order',
  223. 'text' => lang('ds_member_path_all_order'),
  224. 'url' => (string) url('Sellervrorder/index'),
  225. ),
  226. array(
  227. 'name' => 'state_new',
  228. 'text' => lang('ds_member_path_wait_pay'),
  229. 'url' => (string) url('Sellervrorder/index', ['state_type' => 'state_new']),
  230. ),
  231. array(
  232. 'name' => 'state_pay',
  233. 'text' => lang('payment_been'),
  234. 'url' => (string) url('Sellervrorder/index', ['state_type' => 'state_pay']),
  235. ),
  236. array(
  237. 'name' => 'state_success',
  238. 'text' => lang('ds_member_path_finished'),
  239. 'url' => (string) url('Sellervrorder/index', ['state_type' => 'state_success']),
  240. ),
  241. array(
  242. 'name' => 'state_cancel',
  243. 'text' => lang('ds_member_path_canceled'),
  244. 'url' => (string) url('Sellervrorder/index', ['state_type' => 'state_cancel']),
  245. ),
  246. );
  247. if (request()->action() === 'exchange') {
  248. $menu_array[] = array(
  249. 'name' => 'exchange',
  250. 'text' => lang('exchange_code'),
  251. 'url' => (string) url('Sellervrorder/exchange'),
  252. );
  253. }
  254. return $menu_array;
  255. }
  256. }