Sellervrorder.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. <?php
  2. /*
  3. * 虚拟订单
  4. */
  5. namespace app\home\controller;
  6. use think\facade\Db;
  7. use think\facade\View;
  8. use think\facade\Lang;
  9. /**
  10. * ============================================================================
  11. * DSMall多用户商城
  12. * ============================================================================
  13. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  14. * 网站地址: http://www.csdeshang.com
  15. * ----------------------------------------------------------------------------
  16. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  17. * 不允许对程序代码以任何形式任何目的的再发布。
  18. * ============================================================================
  19. * 控制器
  20. */
  21. class Sellervrorder extends BaseSeller
  22. {
  23. public function initialize()
  24. {
  25. parent::initialize();
  26. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellervrorder.lang.php');
  27. }
  28. /**
  29. * 虚拟订单列表
  30. *
  31. */
  32. public function index()
  33. {
  34. //上级店铺id
  35. $store_id = session('store_id');
  36. $store_arr = Db::name('store')->field('store_id,store_name')
  37. ->where('p_id', $store_id)
  38. ->whereOr('store_id', $store_id)
  39. ->select();
  40. View::assign('store_arr', $store_arr);
  41. $store_ids = $store_arr->column('store_id');
  42. $store_column = [];
  43. foreach ($store_arr as $store) {
  44. $store_column[$store['store_id']] = $store['store_name'];
  45. }
  46. //店铺搜索条件
  47. $store_id_input = input('param.store_id', 0);
  48. if (!empty($store_id_input)) {
  49. if (in_array($store_id_input, $store_ids)) {
  50. $store_ids = [$store_id_input];
  51. } else {
  52. $store_ids = [0];
  53. }
  54. }
  55. View::assign('store_id_input', $store_id_input);
  56. $vrorder_model = model('vrorder');
  57. $condition = [];
  58. $condition[] = ['store_id', 'in', $store_ids];
  59. $order_sn = input('get.order_sn');
  60. if ($order_sn != '') {
  61. $condition[] = ['order_sn', '=', $order_sn];
  62. }
  63. $buyer_name = input('get.buyer_name');
  64. if ($buyer_name != '') {
  65. $condition[] = ['buyer_name', '=', $buyer_name];
  66. }
  67. $allow_state_array = ['state_new', 'state_pay', 'state_success', 'state_cancel'];
  68. $state_type = input('param.state_type');
  69. if (in_array($state_type, $allow_state_array)) {
  70. $condition[] = ['order_state', '=', str_replace($allow_state_array, [ORDER_STATE_NEW, ORDER_STATE_PAY, ORDER_STATE_SUCCESS, ORDER_STATE_CANCEL], $state_type)];
  71. } else {
  72. $state_type = 'store_order';
  73. }
  74. $query_start_date = input('get.query_start_date');
  75. $query_end_date = input('get.query_end_date');
  76. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_date);
  77. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_date);
  78. $start_unixtime = $if_start_date ? strtotime($query_start_date) : null;
  79. $end_unixtime = $if_end_date ? (strtotime($query_end_date) + 86399) : null;
  80. if ($start_unixtime) {
  81. $condition[] = ['add_time', '>=', $start_unixtime];
  82. }
  83. if ($end_unixtime) {
  84. $condition[] = ['add_time', '<=', $end_unixtime];
  85. }
  86. $skip_off = input('get.skip_off');
  87. if ($skip_off == 1) {
  88. $condition[] = ['order_state', '<>', ORDER_STATE_CANCEL];
  89. }
  90. $order_list = $vrorder_model->getVrorderList($condition, 20, '*', 'order_id desc');
  91. View::assign('show_page', $vrorder_model->page_info->render());
  92. foreach ($order_list as $key => $order) {
  93. //显示取消订单
  94. $order_list[$key]['if_cancel'] = $vrorder_model->getVrorderOperateState('buyer_cancel', $order);
  95. //追加返回买家信息
  96. $order_list[$key]['extend_member'] = model('member')->getMemberInfoByID($order['buyer_id']);
  97. //店铺名称
  98. $order_list[$key]['store_name'] = $store_column[$order['store_id']];
  99. }
  100. View::assign('order_list', $order_list);
  101. /* 设置卖家当前菜单 */
  102. $this->setSellerCurMenu('sellervrorder');
  103. /* 设置卖家当前栏目 */
  104. $this->setSellerCurItem($state_type);
  105. return View::fetch($this->template_dir . 'index');
  106. }
  107. /**
  108. * 卖家订单详情
  109. *
  110. */
  111. public function show_order()
  112. {
  113. $order_id = intval(input('param.order_id'));
  114. if ($order_id <= 0) {
  115. $this->error(lang('param_error'));
  116. }
  117. $vrorder_model = model('vrorder');
  118. $condition = [];
  119. $condition[] = ['order_id', '=', $order_id];
  120. $condition[] = ['store_id', '=', session('store_id')];
  121. $order_info = $vrorder_model->getVrorderInfo($condition);
  122. if (empty($order_info)) {
  123. $this->error(lang('store_order_none_exist'));
  124. }
  125. //取兑换码列表
  126. $vr_code_list = $vrorder_model->getShowVrordercodeList(['order_id' => $order_info['order_id']]);
  127. $order_info['extend_vr_order_code'] = $vr_code_list;
  128. //显示取消订单
  129. $order_info['if_cancel'] = $vrorder_model->getVrorderOperateState('buyer_cancel', $order_info);
  130. //显示订单进行步骤
  131. $order_info['step_list'] = $vrorder_model->getVrorderStep($order_info);
  132. //显示系统自动取消订单日期
  133. if ($order_info['order_state'] == ORDER_STATE_NEW) {
  134. $order_info['order_cancel_day'] = $order_info['add_time'] + config('ds_config.order_auto_cancel_day') * 24 * 3600;
  135. }
  136. View::assign('order_info', $order_info);
  137. $this->setSellerCurMenu('sellervrorder');
  138. $this->setSellerCurItem('store_order');
  139. return View::fetch($this->template_dir . 'show_order');
  140. }
  141. /**
  142. * 卖家订单状态操作
  143. *
  144. */
  145. public function change_state()
  146. {
  147. $vrorder_model = model('vrorder');
  148. $condition = [];
  149. $condition[] = ['order_id', '=', intval(input('param.order_id'))];
  150. $condition[] = ['store_id', '=', session('store_id')];
  151. $order_info = $vrorder_model->getVrorderInfo($condition);
  152. $state_type = input('param.state_type');
  153. if ($state_type == 'order_cancel') {
  154. $result = $this->_order_cancel($order_info, input('post.'));
  155. }
  156. if (!isset($result['code'])) {
  157. ds_json_encode(10001, lang('error'));
  158. } else {
  159. ds_json_encode(10000, $result['msg']);
  160. }
  161. }
  162. /**
  163. * 取消订单
  164. * @param arrty $order_info
  165. * @param arrty $post
  166. * @throws Exception
  167. */
  168. private function _order_cancel($order_info, $post)
  169. {
  170. if (!request()->isPost()) {
  171. View::assign('order_id', $order_info['order_id']);
  172. View::assign('order_info', $order_info);
  173. echo View::fetch($this->template_dir . 'cancel');
  174. exit();
  175. } else {
  176. $vrorder_model = model('vrorder');
  177. $logic_vrorder = model('vrorder', 'logic');
  178. $if_allow = $vrorder_model->getVrorderOperateState('store_cancel', $order_info);
  179. if (!$if_allow) {
  180. return ds_callback(false, lang('have_right_operate'));
  181. }
  182. $msg = $post['state_info1'] != '' ? $post['state_info1'] : $post['state_info'];
  183. return $logic_vrorder->changeOrderStateCancel($order_info, 'seller', $msg);
  184. }
  185. }
  186. public function exchange()
  187. {
  188. $data = $this->_exchange();
  189. exit(json_encode($data));
  190. }
  191. /**
  192. * 兑换码消费
  193. */
  194. private function _exchange()
  195. {
  196. if (input('param.submit_exchange') == 'ok') {
  197. if (!preg_match('/^[a-zA-Z0-9]{15,18}$/', input('get.vr_code'))) {
  198. return ['error' => lang('exchange_code_format_error')];
  199. }
  200. $vrorder_model = model('vrorder');
  201. $vr_code_info = $vrorder_model->getVrordercodeInfo(['vr_code' => input('get.vr_code')]);
  202. if (empty($vr_code_info) || $vr_code_info['store_id'] != session('store_id')) {
  203. return ['error' => lang('exchange_code_not_exist')];
  204. }
  205. if ($vr_code_info['vr_state'] == '1') {
  206. return ['error' => lang('exchange_code_been_used')];
  207. }
  208. if ($vr_code_info['vr_indate'] < TIMESTAMP) {
  209. return ['error' => lang('exchange_code_expired') . date('Y-m-d H:i:s', $vr_code_info['vr_indate'])];
  210. }
  211. if ($vr_code_info['refund_lock'] > 0) {//退款锁定状态:0为正常,1为锁定(待审核),2为同意
  212. return ['error' => lang('exchange_code_been_applied_refund')];
  213. }
  214. //更新兑换码状态
  215. $update = [];
  216. $update['vr_state'] = 1;
  217. $update['vr_usetime'] = TIMESTAMP;
  218. $update = $vrorder_model->editVrorderCode($update, ['vr_code' => input('get.vr_code')]);
  219. //如果全部兑换完成,更新订单状态
  220. model('vrorder', 'logic')->changeOrderStateSuccess($vr_code_info['order_id']);
  221. if ($update) {
  222. //取得返回信息
  223. $order_info = $vrorder_model->getVrorderInfo(['order_id' => $vr_code_info['order_id']]);
  224. if ($order_info['use_state'] == '0') {
  225. $vrorder_model->editVrorder(['use_state' => 1], ['order_id' => $vr_code_info['order_id']]);
  226. }
  227. $order_info['img_240'] = goods_thumb($order_info, 240);
  228. $order_info['goods_url'] = (string)url('Goods/index', ['goods_id' => $order_info['goods_id']]);
  229. $order_info['order_url'] = (string)url('Sellervrorder/show_order', ['order_id' => $order_info['order_id']]);
  230. return ['error' => '', 'data' => $order_info];
  231. }
  232. } else {
  233. $state_type = input('state_type');;
  234. /* 设置卖家当前菜单 */
  235. $this->setSellerCurMenu('sellervrorder');
  236. /* 设置卖家当前栏目 */
  237. $this->setSellerCurItem($state_type);
  238. echo View::fetch($this->template_dir . 'exchange');
  239. exit;
  240. }
  241. }
  242. /**
  243. * 栏目菜单
  244. */
  245. function getSellerItemList()
  246. {
  247. $menu_array = [
  248. [
  249. 'name' => 'store_order',
  250. 'text' => lang('ds_member_path_all_order'),
  251. 'url' => (string)url('Sellervrorder/index'),
  252. ],
  253. [
  254. 'name' => 'state_new',
  255. 'text' => lang('ds_member_path_wait_pay'),
  256. 'url' => (string)url('Sellervrorder/index', ['state_type' => 'state_new']),
  257. ],
  258. [
  259. 'name' => 'state_pay',
  260. 'text' => lang('payment_been'),
  261. 'url' => (string)url('Sellervrorder/index', ['state_type' => 'state_pay']),
  262. ],
  263. [
  264. 'name' => 'state_success',
  265. 'text' => lang('ds_member_path_finished'),
  266. 'url' => (string)url('Sellervrorder/index', ['state_type' => 'state_success']),
  267. ],
  268. [
  269. 'name' => 'state_cancel',
  270. 'text' => lang('ds_member_path_canceled'),
  271. 'url' => (string)url('Sellervrorder/index', ['state_type' => 'state_cancel']),
  272. ],
  273. ];
  274. if (request()->action() === 'exchange') {
  275. $menu_array[] = [
  276. 'name' => 'exchange',
  277. 'text' => lang('exchange_code'),
  278. 'url' => (string)url('Sellervrorder/exchange'),
  279. ];
  280. }
  281. return $menu_array;
  282. }
  283. public function export()
  284. {
  285. //上级店铺id
  286. $store_id = session('store_id');
  287. $store_arr = Db::name('store')->field('store_id,store_name')
  288. ->where('p_id', $store_id)
  289. ->whereOr('store_id', $store_id)
  290. ->select();
  291. $store_ids = $store_arr->column('store_id');
  292. $store_column = [];
  293. foreach ($store_arr as $store) {
  294. $store_column[$store['store_id']] = $store['store_name'];
  295. }
  296. //店铺搜索条件
  297. $store_id_input = input('param.store_id', 0);
  298. if (!empty($store_id_input)) {
  299. if (in_array($store_id_input, $store_ids)) {
  300. $store_ids = [$store_id_input];
  301. } else {
  302. $store_ids = [0];
  303. }
  304. }
  305. $vrorder_model = model('vrorder');
  306. $condition = [];
  307. $condition[] = ['store_id', 'in', $store_ids];
  308. $ids = input('get.ids');
  309. if (!empty($ids)) {
  310. $condition[] = ['order_id', 'in', explode(',', $ids)];
  311. }
  312. $order_sn = input('get.order_sn');
  313. if ($order_sn != '') {
  314. $condition[] = ['order_sn', '=', $order_sn];
  315. }
  316. $buyer_name = input('get.buyer_name');
  317. if ($buyer_name != '') {
  318. $condition[] = ['buyer_name', '=', $buyer_name];
  319. }
  320. $allow_state_array = ['state_new', 'state_pay', 'state_success', 'state_cancel'];
  321. $state_type = input('param.state_type');
  322. if (in_array($state_type, $allow_state_array)) {
  323. $condition[] = ['order_state', '=', str_replace($allow_state_array, [ORDER_STATE_NEW, ORDER_STATE_PAY, ORDER_STATE_SUCCESS, ORDER_STATE_CANCEL], $state_type)];
  324. }
  325. $query_start_date = input('get.query_start_date');
  326. $query_end_date = input('get.query_end_date');
  327. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_date);
  328. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_date);
  329. $start_unixtime = $if_start_date ? strtotime($query_start_date) : null;
  330. $end_unixtime = $if_end_date ? (strtotime($query_end_date) + 86399) : null;
  331. if ($start_unixtime) {
  332. $condition[] = ['add_time', '>=', $start_unixtime];
  333. }
  334. if ($end_unixtime) {
  335. $condition[] = ['add_time', '<=', $end_unixtime];
  336. }
  337. $skip_off = input('get.skip_off');
  338. if ($skip_off == 1) {
  339. $condition[] = ['order_state', '<>', ORDER_STATE_CANCEL];
  340. }
  341. $order_list = $vrorder_model->getVrorderList($condition, 0, '*', 'order_id desc');
  342. foreach ($order_list as $key => $order) {
  343. //显示取消订单
  344. $order_list[$key]['if_cancel'] = $vrorder_model->getVrorderOperateState('buyer_cancel', $order);
  345. //追加返回买家信息
  346. $order_list[$key]['extend_member'] = model('member')->getMemberInfoByID($order['buyer_id']);
  347. //店铺名称
  348. $order_list[$key]['store_name'] = $store_column[$order['store_id']];
  349. }
  350. $this->createExcel($order_list);
  351. }
  352. /**
  353. * 生成excel
  354. *
  355. * @param array $data
  356. */
  357. private function createExcel($data = [])
  358. {
  359. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/export.lang.php');
  360. $excel_obj = new \excel\Excel();
  361. $excel_data = [];
  362. //设置样式
  363. $excel_obj->setStyle(['id' => 's_title', 'Font' => ['FontName' => '宋体', 'Size' => '12', 'Bold' => '1']]);
  364. //header
  365. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_no')];
  366. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_store')];
  367. $excel_data[0][] = ['styleid' => 's_title', 'data' => '商品名称'];
  368. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_buyer')];
  369. $excel_data[0][] = ['styleid' => 's_title', 'data' => '手机号'];
  370. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_xtimd')];
  371. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_count')];
  372. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_paytype')];
  373. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_state')];
  374. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_storeid')];
  375. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_buyerid')];
  376. //data
  377. foreach ((array)$data as $k => $v) {
  378. $tmp = [];
  379. $tmp[] = ['data' => $v['order_sn']];
  380. $tmp[] = ['data' => $v['store_name']];
  381. $goods_name = $v['goods_name'] . '*' . $v['goods_num'];
  382. $tmp[] = ['data' => $goods_name];
  383. $tmp[] = ['data' => $v['buyer_name']];
  384. $tmp[] = ['data' => $v['buyer_phone']];
  385. $tmp[] = ['data' => date('Y-m-d H:i:s', $v['add_time'])];
  386. $tmp[] = ['format' => 'Number', 'data' => ds_price_format($v['order_amount'])];
  387. $tmp[] = ['data' => get_order_payment_name($v['payment_code'])];
  388. $tmp[] = ['data' => get_order_state($v)];
  389. $tmp[] = ['data' => $v['store_id']];
  390. $tmp[] = ['data' => $v['buyer_id']];
  391. $excel_data[] = $tmp;
  392. }
  393. $excel_data = $excel_obj->charset($excel_data, CHARSET);
  394. $excel_obj->addArray($excel_data);
  395. $excel_obj->addWorksheet($excel_obj->charset(lang('exp_od_order'), CHARSET));
  396. $excel_obj->generateXML($excel_obj->charset(lang('exp_od_order'), CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP));
  397. }
  398. }