Sellervrorder.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  13. * 网站地址: https://www.valimart.net/
  14. * ----------------------------------------------------------------------------
  15. *
  16. * ============================================================================
  17. * 控制器
  18. */
  19. class Sellervrorder extends BaseSeller {
  20. public function initialize() {
  21. parent::initialize();
  22. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellervrorder.lang.php');
  23. }
  24. /**
  25. * 虚拟订单列表
  26. *
  27. */
  28. public function index() {
  29. $vrorder_model = model('vrorder');
  30. $condition = array();
  31. $condition[] = array('store_id', '=', session('store_id'));
  32. $order_sn = input('get.order_sn');
  33. if ($order_sn != '') {
  34. $condition[] = array('order_sn', '=', $order_sn);
  35. }
  36. $buyer_name = input('get.buyer_name');
  37. if ($buyer_name != '') {
  38. $condition[] = array('buyer_name', '=', $buyer_name);
  39. }
  40. $allow_state_array = array('state_new', 'state_pay', 'state_success', 'state_cancel');
  41. $state_type = input('param.state_type');
  42. if (in_array($state_type, $allow_state_array)) {
  43. $condition[] = array('order_state', '=', str_replace($allow_state_array, array(ORDER_STATE_NEW, ORDER_STATE_PAY, ORDER_STATE_SUCCESS, ORDER_STATE_CANCEL), $state_type));
  44. } else {
  45. $state_type = 'store_order';
  46. }
  47. $query_start_date = input('get.query_start_date');
  48. $query_end_date = input('get.query_end_date');
  49. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_date);
  50. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_date);
  51. $start_unixtime = $if_start_date ? strtotime($query_end_date) : null;
  52. $end_unixtime = $if_end_date ? (strtotime($query_start_date)+86399) : null;
  53. if ($start_unixtime) {
  54. $condition[] = array('add_time', '>=', $start_unixtime);
  55. }
  56. if ($end_unixtime) {
  57. $condition[] = array('add_time', '<=', $end_unixtime);
  58. }
  59. $skip_off = input('get.skip_off');
  60. if ($skip_off == 1) {
  61. $condition[] = array('order_state', '<>', ORDER_STATE_CANCEL);
  62. }
  63. $order_list = $vrorder_model->getVrorderList($condition, 20, '*', 'order_id desc');
  64. View::assign('show_page', $vrorder_model->page_info->render());
  65. foreach ($order_list as $key => $order) {
  66. //显示取消订单
  67. $order_list[$key]['if_cancel'] = $vrorder_model->getVrorderOperateState('buyer_cancel', $order);
  68. //追加返回买家信息
  69. $order_list[$key]['extend_member'] = model('member')->getMemberInfoByID($order['buyer_id']);
  70. }
  71. View::assign('order_list', $order_list);
  72. /* 设置卖家当前菜单 */
  73. $this->setSellerCurMenu('sellervrorder');
  74. /* 设置卖家当前栏目 */
  75. $this->setSellerCurItem($state_type);
  76. return View::fetch($this->template_dir . 'index');
  77. }
  78. /**
  79. * 卖家订单详情
  80. *
  81. */
  82. public function show_order() {
  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. $vrorder_model = model('vrorder');
  120. $condition = array();
  121. $condition[] = array('order_id','=',intval(input('param.order_id')));
  122. $condition[] = array('store_id','=',session('store_id'));
  123. $order_info = $vrorder_model->getVrorderInfo($condition);
  124. $state_type = input('param.state_type');
  125. if ($state_type == 'order_cancel') {
  126. $result = $this->_order_cancel($order_info, input('post.'));
  127. }
  128. if (!isset($result['code'])) {
  129. ds_json_encode(10001, lang('error'));
  130. } else {
  131. ds_json_encode(10000, $result['msg']);
  132. }
  133. }
  134. /**
  135. * 取消订单
  136. * @param arrty $order_info
  137. * @param arrty $post
  138. * @throws Exception
  139. */
  140. private function _order_cancel($order_info, $post) {
  141. if (!request()->isPost()) {
  142. View::assign('order_id', $order_info['order_id']);
  143. View::assign('order_info', $order_info);
  144. echo View::fetch($this->template_dir . 'cancel');
  145. exit();
  146. } else {
  147. $vrorder_model = model('vrorder');
  148. $logic_vrorder = model('vrorder', 'logic');
  149. $if_allow = $vrorder_model->getVrorderOperateState('store_cancel', $order_info);
  150. if (!$if_allow) {
  151. return ds_callback(false, lang('have_right_operate'));
  152. }
  153. $msg = $post['state_info1'] != '' ? $post['state_info1'] : $post['state_info'];
  154. return $logic_vrorder->changeOrderStateCancel($order_info, 'seller', $msg);
  155. }
  156. }
  157. public function exchange() {
  158. $data = $this->_exchange();
  159. exit(json_encode($data));
  160. }
  161. /**
  162. * 兑换码消费
  163. */
  164. private function _exchange() {
  165. if (input('param.submit_exchange') == 'ok') {
  166. if (!preg_match('/^[a-zA-Z0-9]{15,18}$/', input('get.vr_code'))) {
  167. return array('error' => lang('exchange_code_format_error'));
  168. }
  169. $vrorder_model = model('vrorder');
  170. $vr_code_info = $vrorder_model->getVrordercodeInfo(array('vr_code' => input('get.vr_code')));
  171. if (empty($vr_code_info) || $vr_code_info['store_id'] != session('store_id')) {
  172. return array('error' => lang('exchange_code_not_exist'));
  173. }
  174. if ($vr_code_info['vr_state'] == '1') {
  175. return array('error' => lang('exchange_code_been_used'));
  176. }
  177. if ($vr_code_info['vr_indate'] < TIMESTAMP) {
  178. return array('error' => lang('exchange_code_expired') . date('Y-m-d H:i:s', $vr_code_info['vr_indate']));
  179. }
  180. if ($vr_code_info['refund_lock'] > 0) {//退款锁定状态:0为正常,1为锁定(待审核),2为同意
  181. return array('error' => lang('exchange_code_been_applied_refund'));
  182. }
  183. //更新兑换码状态
  184. $update = array();
  185. $update['vr_state'] = 1;
  186. $update['vr_usetime'] = TIMESTAMP;
  187. $update = $vrorder_model->editVrorderCode($update, array('vr_code' => input('get.vr_code')));
  188. //如果全部兑换完成,更新订单状态
  189. model('vrorder', 'logic')->changeOrderStateSuccess($vr_code_info['order_id']);
  190. if ($update) {
  191. //取得返回信息
  192. $order_info = $vrorder_model->getVrorderInfo(array('order_id' => $vr_code_info['order_id']));
  193. if ($order_info['use_state'] == '0') {
  194. $vrorder_model->editVrorder(array('use_state' => 1), array('order_id' => $vr_code_info['order_id']));
  195. }
  196. $order_info['img_240'] = goods_thumb($order_info, 240);
  197. $order_info['goods_url'] = (string) url('Goods/index', ['goods_id' => $order_info['goods_id']]);
  198. $order_info['order_url'] = (string) url('Sellervrorder/show_order', ['order_id' => $order_info['order_id']]);
  199. return array('error' => '', 'data' => $order_info);
  200. }
  201. } else {
  202. $state_type = input('state_type');
  203. ;
  204. /* 设置卖家当前菜单 */
  205. $this->setSellerCurMenu('sellervrorder');
  206. /* 设置卖家当前栏目 */
  207. $this->setSellerCurItem($state_type);
  208. echo View::fetch($this->template_dir . 'exchange');
  209. exit;
  210. }
  211. }
  212. /**
  213. * 栏目菜单
  214. */
  215. function getSellerItemList() {
  216. $menu_array = array(
  217. array(
  218. 'name' => 'store_order',
  219. 'text' => lang('ds_member_path_all_order'),
  220. 'url' => (string) url('Sellervrorder/index'),
  221. ),
  222. array(
  223. 'name' => 'state_new',
  224. 'text' => lang('ds_member_path_wait_pay'),
  225. 'url' => (string) url('Sellervrorder/index', ['state_type' => 'state_new']),
  226. ),
  227. array(
  228. 'name' => 'state_pay',
  229. 'text' => lang('payment_been'),
  230. 'url' => (string) url('Sellervrorder/index', ['state_type' => 'state_pay']),
  231. ),
  232. array(
  233. 'name' => 'state_success',
  234. 'text' => lang('ds_member_path_finished'),
  235. 'url' => (string) url('Sellervrorder/index', ['state_type' => 'state_success']),
  236. ),
  237. array(
  238. 'name' => 'state_cancel',
  239. 'text' => lang('ds_member_path_canceled'),
  240. 'url' => (string) url('Sellervrorder/index', ['state_type' => 'state_cancel']),
  241. ),
  242. );
  243. if (request()->action() === 'exchange') {
  244. $menu_array[] = array(
  245. 'name' => 'exchange',
  246. 'text' => lang('exchange_code'),
  247. 'url' => (string) url('Sellervrorder/exchange'),
  248. );
  249. }
  250. return $menu_array;
  251. }
  252. }