Storeorder.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. use think\facade\Db;
  6. /**
  7. * 到店付款订单
  8. */
  9. class Storeorder extends AdminControl
  10. {
  11. const EXPORT_SIZE = 1000;
  12. public function initialize()
  13. {
  14. parent::initialize();
  15. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/vrorder.lang.php');
  16. }
  17. public function index()
  18. {
  19. $order_model = model('StoreOrder');
  20. $condition = [];
  21. $order_sn = input('param.order_sn');
  22. if ($order_sn) {
  23. $condition[] = ['order_sn', '=', $order_sn];
  24. }
  25. $store_name = input('param.store_name');
  26. if ($store_name) {
  27. $store_ids = Db::name('store')->where('store_name', 'like', "%{$store_name}%")->column('store_id');
  28. if (empty($store_ids)) {
  29. $condition[] = ['id', '=', 0];
  30. } else {
  31. $condition[] = ['store_id', 'in', $store_ids];
  32. }
  33. }
  34. $order_state = input('param.order_state');
  35. if (in_array($order_state, ['0', '10', '40'])) {
  36. $condition[] = ['order_state', '=', $order_state];
  37. }
  38. $payment_code = input('param.payment_code');
  39. if ($payment_code) {
  40. $condition[] = ['payment_code', '=', $payment_code];
  41. }
  42. $buyer_name = input('param.buyer_name');
  43. if ($buyer_name) {
  44. $condition[] = ['buyer_name', '=', $buyer_name];
  45. }
  46. $is_refund = input('param.is_refund');
  47. if ($is_refund) {
  48. $condition[] = ['is_refund', '=', $is_refund];
  49. }
  50. $query_start_time = input('param.query_start_time');
  51. $query_end_time = input('param.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[] = ['add_time', '>=', $start_unixtime];
  58. }
  59. if ($end_unixtime) {
  60. $condition[] = ['add_time', '<=', $end_unixtime];
  61. }
  62. $order_list = $order_model->getOrderList($condition, 10, '*', 'id desc', 0, ['store']);
  63. View::assign('show_page', $order_model->page_info->render());
  64. foreach ($order_list as $order_id => $order_info) {
  65. if ($order_info['order_state'] == ORDER_STATE_NEW) {
  66. $order_info['pay_amount'] = $order_info['order_amount'] - $order_info['deduction_amount'];
  67. }
  68. }
  69. //显示支付接口列表(搜索)
  70. View::assign('order_list', $order_list);
  71. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  72. $this->setAdminCurItem('add');
  73. return View::fetch('index');
  74. }
  75. /**
  76. * 平台订单状态操作
  77. *
  78. */
  79. public function change_state()
  80. {
  81. $state_type = input('param.state_type');
  82. if ($state_type == 'cancel') {
  83. $order_id = intval(input('param.id'));
  84. if ($order_id <= 0) {
  85. $this->error(lang('miss_order_number'));
  86. }
  87. $order_model = model('StoreOrder');
  88. $order_model->where('id', $order_id)->update(['order_state' => 0]);
  89. }
  90. ds_json_encode(10000, '操作成功');
  91. }
  92. /**
  93. * 查看订单
  94. *
  95. */
  96. public function show_order()
  97. {
  98. $order_id = intval(input('param.id'));
  99. if ($order_id <= 0) {
  100. $this->error(lang('miss_order_number'));
  101. }
  102. $order_model = model('StoreOrder');
  103. $order_info = $order_model->getOrderInfo(['id' => $order_id], ['store', 'member']);
  104. $order_info['deduction_amount'] = number_format($order_info['deduction_amount'], 2);
  105. View::assign('order_info', $order_info);
  106. return View::fetch('show_order');
  107. }
  108. /**
  109. * 导出
  110. *
  111. */
  112. public function export_step1()
  113. {
  114. $order_model = model('StoreOrder');
  115. $condition = [];
  116. $order_sn = input('param.order_sn');
  117. if ($order_sn) {
  118. $condition[] = ['order_sn', '=', $order_sn];
  119. }
  120. $store_name = input('param.store_name');
  121. if ($store_name) {
  122. $store_ids = Db::name('store')->where('store_name', 'like', "%{$store_name}%")->column('store_id');
  123. if (empty($store_ids)) {
  124. $condition[] = ['id', '=', 0];
  125. } else {
  126. $condition[] = ['store_id', 'in', $store_ids];
  127. }
  128. }
  129. $order_state = input('param.order_state');
  130. if (in_array($order_state, ['0', '10', '40'])) {
  131. $condition[] = ['order_state', '=', $order_state];
  132. }
  133. $payment_code = input('param.payment_code');
  134. if ($payment_code) {
  135. $condition[] = ['payment_code', '=', $payment_code];
  136. }
  137. $buyer_name = input('param.buyer_name');
  138. if ($buyer_name) {
  139. $condition[] = ['buyer_name', '=', $buyer_name];
  140. }
  141. $is_refund = input('param.is_refund');
  142. if ($is_refund) {
  143. $condition[] = ['is_refund', '=', $is_refund];
  144. }
  145. $query_start_time = input('param.query_start_time');
  146. $query_end_time = input('param.query_end_time');
  147. $if_start_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_time);
  148. $if_end_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_time);
  149. $start_unixtime = $if_start_time ? strtotime($query_start_time) : null;
  150. $end_unixtime = $if_end_time ? strtotime($query_end_time) : null;
  151. if ($start_unixtime) {
  152. $condition[] = ['add_time', '>=', $start_unixtime];
  153. }
  154. if ($end_unixtime) {
  155. $condition[] = ['add_time', '<=', $end_unixtime];
  156. }
  157. if (!is_numeric(input('param.page'))) {
  158. $count = $order_model->getOrderCount($condition);
  159. $export_list = [];
  160. if ($count > self::EXPORT_SIZE) { //显示下载链接
  161. $page = ceil($count / self::EXPORT_SIZE);
  162. for ($i = 1; $i <= $page; $i++) {
  163. $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
  164. $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
  165. $export_list[$i] = $limit1 . ' ~ ' . $limit2;
  166. }
  167. View::assign('export_list', $export_list);
  168. return View::fetch('/public/excel');
  169. } else { //如果数量小,直接下载
  170. $data = $order_model->getOrderList($condition, 0, '*', 'id desc', 0, ['store', 'member']);
  171. $this->createExcel($data);
  172. }
  173. } else { //下载
  174. $limit2 = self::EXPORT_SIZE;
  175. $data = $order_model->getOrderList($condition, $limit2, '*', 'id desc', 0, ['store', 'member']);
  176. $this->createExcel($data);
  177. }
  178. }
  179. /**
  180. * 生成excel
  181. *
  182. * @param array $data
  183. */
  184. private function createExcel($data = [])
  185. {
  186. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/export.lang.php');
  187. $excel_obj = new \excel\Excel();
  188. $excel_data = [];
  189. //设置样式
  190. $excel_obj->setStyle(['id' => 's_title', 'Font' => ['FontName' => '宋体', 'Size' => '12', 'Bold' => '1']]);
  191. //header
  192. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_no')];
  193. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_store')];
  194. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_buyer')];
  195. $excel_data[0][] = ['styleid' => 's_title', 'data' => '买家电话'];
  196. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_xtimd')];
  197. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_count')];
  198. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_paytype')];
  199. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_state')];
  200. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_storeid')];
  201. $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_buyerid')];
  202. $excel_data[0][] = ['styleid' => 's_title', 'data' => '订单完成时间'];
  203. //data
  204. foreach ((array)$data as $k => $v) {
  205. $tmp = [];
  206. $tmp[] = ['data' => 'DS' . $v['order_sn']];
  207. $tmp[] = ['data' => $v['extend_store']['store_name']];
  208. $tmp[] = ['data' => $v['extend_member']['member_nickname']];
  209. $tmp[] = ['data' => $v['extend_member']['member_mobile']];
  210. $tmp[] = ['data' => $v['add_time']];
  211. $tmp[] = ['format' => 'Number', 'data' => ds_price_format($v['order_amount'])];
  212. $tmp[] = ['data' => get_order_payment_name($v['payment_code'])];
  213. $state_desc = $v['state_desc'];
  214. if ($v['is_refund'] == 1) {
  215. $state_desc .= "(已退款)";
  216. }
  217. $tmp[] = ['data' => $state_desc];
  218. $tmp[] = ['data' => $v['store_id']];
  219. $tmp[] = ['data' => $v['buyer_id']];
  220. $tmp[] = ['data' => $v['finished_time']];
  221. $excel_data[] = $tmp;
  222. }
  223. $excel_data = $excel_obj->charset($excel_data, CHARSET);
  224. $excel_obj->addArray($excel_data);
  225. $excel_obj->addWorksheet($excel_obj->charset('到店付款订单', CHARSET));
  226. $excel_obj->generateXML($excel_obj->charset('到店付款订单', CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP));
  227. }
  228. }