Vrorder.php 13 KB

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