Vrorder.php 13 KB

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