Vrorder.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 控制器
  11. */
  12. class Vrorder extends AdminControl
  13. {
  14. /**
  15. * 每次导出订单数量
  16. * @var int
  17. */
  18. const EXPORT_SIZE = 1000;
  19. public function initialize()
  20. {
  21. parent::initialize();
  22. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/vrorder.lang.php');
  23. }
  24. public function index()
  25. {
  26. $vrorder_model = model('vrorder');
  27. $condition = array();
  28. $order_sn = input('get.order_sn');
  29. if ($order_sn) {
  30. $condition[] = array('order_sn', '=', $order_sn);
  31. }
  32. $store_name = input('get.store_name');
  33. if ($store_name) {
  34. $condition[] = array('store_name', '=', $store_name);
  35. }
  36. $order_state = input('get.order_state');
  37. if (!empty($order_state)) {
  38. $condition[] = array('order_state', '=', intval($order_state));
  39. }
  40. $payment_code = input('get.payment_code');
  41. if ($payment_code) {
  42. $condition[] = array('payment_code', '=', $payment_code);
  43. }
  44. $buyer_name = input('get.buyer_name');
  45. if ($buyer_name) {
  46. $condition[] = array('buyer_name', '=', $buyer_name);
  47. }
  48. $query_start_time = input('get.query_start_time');
  49. $query_end_time = input('get.query_end_time');
  50. $if_start_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_time);
  51. $if_end_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_time);
  52. $start_unixtime = $if_start_time ? strtotime($query_start_time) : null;
  53. $end_unixtime = $if_end_time ? strtotime($query_end_time) : null;
  54. if ($start_unixtime) {
  55. $condition[] = array('add_time', '>=', $start_unixtime);
  56. }
  57. if ($end_unixtime) {
  58. $end_unixtime = $end_unixtime + 86399;
  59. $condition[] = array('add_time', '<=', $end_unixtime);
  60. }
  61. $order_list = $vrorder_model->getVrorderList($condition, 30);
  62. foreach ($order_list as $k => $order_info) {
  63. //显示取消订单
  64. $order_list[$k]['if_cancel'] = $vrorder_model->getVrorderOperateState('system_cancel', $order_info);
  65. //显示收到货款
  66. $order_list[$k]['if_system_receive_pay'] = $vrorder_model->getVrorderOperateState('system_receive_pay', $order_info);
  67. }
  68. //显示支付接口列表(搜索)
  69. $payment_list = model('payment')->getPaymentOpenList();
  70. View::assign('payment_list', $payment_list);
  71. View::assign('order_list', $order_list);
  72. View::assign('show_page', $vrorder_model->page_info->render());
  73. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  74. $this->setAdminCurItem('index');
  75. return View::fetch('vr_order_index');
  76. }
  77. /**
  78. * 平台订单状态操作
  79. *
  80. */
  81. public function change_state()
  82. {
  83. $vrorder_model = model('vrorder');
  84. $condition = array();
  85. $condition[] = array('order_id', '=', intval(input('param.order_id')));
  86. $order_info = $vrorder_model->getVrorderInfo($condition);
  87. $state_type = input('param.state_type');
  88. if ($state_type == 'cancel') {
  89. $result = $this->_order_cancel($order_info);
  90. if (isset($result['code'])) {
  91. ds_json_encode('10000', $result['msg']);
  92. }
  93. } elseif ($state_type == 'receive_pay') {
  94. $result = $this->_order_receive_pay($order_info, input('post.'));
  95. if (isset($result['code'])) {
  96. dsLayerOpenSuccess($result['msg']);
  97. }
  98. }
  99. $this->error('操作出错', 'index');
  100. }
  101. /**
  102. * 系统取消订单
  103. * @param unknown $order_info
  104. */
  105. private function _order_cancel($order_info)
  106. {
  107. $vrorder_model = model('vrorder');
  108. $logic_vrorder = model('vrorder', 'logic');
  109. $if_allow = $vrorder_model->getVrorderOperateState('system_cancel', $order_info);
  110. if (!$if_allow) {
  111. return ds_callback(false, lang('no_right_operate'));
  112. }
  113. $this->log('关闭了虚拟订单,' . lang('ds_order_sn') . ':' . $order_info['order_sn'], 1);
  114. return $logic_vrorder->changeOrderStateCancel($order_info, 'store', lang('admin_cancel_vrorder'));
  115. }
  116. /**
  117. * 系统收到货款
  118. * @param unknown $order_info
  119. * @throws Exception
  120. */
  121. private function _order_receive_pay($order_info, $post)
  122. {
  123. $vrorder_model = model('vrorder');
  124. $logic_vrorder = model('vrorder', 'logic');
  125. $if_allow = $vrorder_model->getVrorderOperateState('system_receive_pay', $order_info);
  126. if (!$if_allow) {
  127. return ds_callback(false, lang('no_right_operate'));
  128. }
  129. if (!request()->post()) {
  130. View::assign('order_info', $order_info);
  131. //显示支付接口
  132. $payment_list = model('payment')->getPaymentOpenList();
  133. //去掉预存款和货到付款
  134. foreach ($payment_list as $key => $value) {
  135. if ($value['payment_code'] == 'predeposit' || $value['payment_code'] == 'offline') {
  136. unset($payment_list[$key]);
  137. }
  138. }
  139. View::assign('payment_list', $payment_list);
  140. $this->setAdminCurItem('submit');
  141. echo View::fetch('receive_pay');
  142. exit();
  143. } else {
  144. $this->log('将虚拟订单改为已收款状态,' . lang('ds_order_sn') . ':' . $order_info['order_sn'], 1);
  145. return $logic_vrorder->changeOrderStatePay($order_info, 'system', $post);
  146. }
  147. }
  148. /**
  149. * 查看订单
  150. *
  151. */
  152. public function show_order()
  153. {
  154. $order_id = intval(input('param.order_id'));
  155. if ($order_id <= 0) {
  156. $this->error(lang('miss_order_number'));
  157. }
  158. $vrorder_model = model('vrorder');
  159. $order_info = $vrorder_model->getVrorderInfo(array('order_id' => $order_id));
  160. if (empty($order_info)) {
  161. $this->error(lang('order_not_exist'));
  162. }
  163. //取兑换码列表
  164. $vr_code_list = $vrorder_model->getShowVrordercodeList(array('order_id' => $order_info['order_id']));
  165. $order_info['extend_vr_order_code'] = $vr_code_list;
  166. //显示取消订单
  167. $order_info['if_cancel'] = $vrorder_model->getVrorderOperateState('buyer_cancel', $order_info);
  168. //显示订单进行步骤
  169. $order_info['step_list'] = $vrorder_model->getVrorderStep($order_info);
  170. //显示系统自动取消订单日期
  171. if ($order_info['order_state'] == ORDER_STATE_NEW) {
  172. $order_info['order_cancel_day'] = $order_info['add_time'] + config('ds_config.order_auto_cancel_day') * 24 * 3600;
  173. }
  174. View::assign('order_info', $order_info);
  175. return View::fetch('view');
  176. }
  177. /**
  178. * 导出
  179. *
  180. */
  181. public function export_step1()
  182. {
  183. $vrorder_model = model('vrorder');
  184. $condition = array();
  185. if (input('param.order_sn')) {
  186. $condition[] = array('order_sn', '=', input('param.order_sn'));
  187. }
  188. if (input('param.store_name')) {
  189. $condition[] = array('store_name', '=', input('param.store_name'));
  190. }
  191. $order_state = input('param.order_state');
  192. if (in_array($order_state, array('0', '10', '20', '30', '40'))) {
  193. $condition[] = array('order_state', '=', $order_state);
  194. }
  195. if (input('param.payment_code')) {
  196. $condition[] = array('payment_code', '=', input('param.payment_code'));
  197. }
  198. if (input('param.buyer_name')) {
  199. $condition[] = array('buyer_name', '=', input('param.buyer_name'));
  200. }
  201. $if_start_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', input('param.query_start_time'));
  202. $if_end_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', input('param.query_end_time'));
  203. $start_unixtime = $if_start_time ? strtotime(input('param.query_start_time')) : null;
  204. $end_unixtime = $if_end_time ? strtotime(input('param.query_end_time')) : null;
  205. if ($start_unixtime) {
  206. $condition[] = array('add_time', '>=', $start_unixtime);
  207. }
  208. if ($end_unixtime) {
  209. $end_unixtime = $end_unixtime + 86399;
  210. $condition[] = array('add_time', '<=', $end_unixtime);
  211. }
  212. if (!is_numeric(input('param.page'))) {
  213. $count = $vrorder_model->getVrorderCount($condition);
  214. $export_list = array();
  215. if ($count > self::EXPORT_SIZE) { //显示下载链接
  216. $page = ceil($count / self::EXPORT_SIZE);
  217. for ($i = 1; $i <= $page; $i++) {
  218. $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
  219. $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
  220. $export_list[$i] = $limit1 . ' ~ ' . $limit2;
  221. }
  222. View::assign('export_list', $export_list);
  223. return View::fetch('/public/excel');
  224. } else { //如果数量小,直接下载
  225. $data = $vrorder_model->getVrorderList($condition, '', '*', 'order_id desc', self::EXPORT_SIZE);
  226. $this->createExcel($data);
  227. }
  228. } else { //下载
  229. $limit1 = (input('param.page') - 1) * self::EXPORT_SIZE;
  230. $limit2 = self::EXPORT_SIZE;
  231. $data = $vrorder_model->getVrorderList($condition, $limit2, '*', 'order_id desc');
  232. $this->createExcel($data);
  233. }
  234. }
  235. /**
  236. * 生成excel
  237. *
  238. * @param array $data
  239. */
  240. private function createExcel($data = array())
  241. {
  242. $excel_obj = new \excel\Excel();
  243. $excel_data = array();
  244. //设置样式
  245. $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
  246. //header
  247. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_od_no'));
  248. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_od_store'));
  249. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_od_buyer'));
  250. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_od_xtimd'));
  251. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_od_count'));
  252. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_od_paytype'));
  253. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_od_state'));
  254. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_od_storeid'));
  255. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_od_buyerid'));
  256. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_od_mobile'));
  257. //data
  258. foreach ((array) $data as $k => $v) {
  259. $tmp = array();
  260. $tmp[] = array('data' => 'DS' . $v['order_sn']);
  261. $tmp[] = array('data' => $v['store_name']);
  262. $tmp[] = array('data' => $v['buyer_name']);
  263. $tmp[] = array('data' => date('Y-m-d H:i:s', $v['add_time']));
  264. $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['order_amount']));
  265. $tmp[] = array('data' => get_order_payment_name($v['payment_code']));
  266. $tmp[] = array('data' => $v['state_desc']);
  267. $tmp[] = array('data' => $v['store_id']);
  268. $tmp[] = array('data' => $v['buyer_id']);
  269. $tmp[] = array('data' => $v['buyer_phone']);
  270. $excel_data[] = $tmp;
  271. }
  272. $excel_data = $excel_obj->charset($excel_data, CHARSET);
  273. $excel_obj->addArray($excel_data);
  274. $excel_obj->addWorksheet($excel_obj->charset(lang('exp_od_order'), CHARSET));
  275. $excel_obj->generateXML($excel_obj->charset(lang('exp_od_order'), CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP));
  276. }
  277. protected function getAdminItemList()
  278. {
  279. $menu_array = array(
  280. array(
  281. 'name' => 'index', 'text' => lang('ds_manage'), 'url' => (string)url('Vrorder/index')
  282. )
  283. );
  284. if (request()->action() == 'change_state') {
  285. $menu_array[] = array(
  286. 'name' => 'submit', 'text' => lang('confirm_receive_pay'), 'url' => ''
  287. );
  288. }
  289. if (request()->action() == 'show_order') {
  290. $menu_array[] = array(
  291. 'name' => 'show_order', 'text' => lang('order_detail'), 'url' => ''
  292. );
  293. }
  294. return $menu_array;
  295. }
  296. }