123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- <?php
- namespace app\admin\controller;
- use think\facade\View;
- use think\facade\Lang;
- use think\facade\Db;
- /**
- * 到店付款订单
- */
- class Storeorder extends AdminControl
- {
- const EXPORT_SIZE = 1000;
- public function initialize()
- {
- parent::initialize();
- Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/vrorder.lang.php');
- }
- public function index()
- {
- $order_model = model('StoreOrder');
- $condition = [];
- $order_sn = input('param.order_sn');
- if ($order_sn) {
- $condition[] = ['order_sn', '=', $order_sn];
- }
- $store_name = input('param.store_name');
- if ($store_name) {
- $store_ids = Db::name('store')->where('store_name', 'like', "%{$store_name}%")->column('store_id');
- if (empty($store_ids)) {
- $condition[] = ['id', '=', 0];
- } else {
- $condition[] = ['store_id', 'in', $store_ids];
- }
- }
- $order_state = input('param.order_state');
- if (in_array($order_state, ['0', '10', '40'])) {
- $condition[] = ['order_state', '=', $order_state];
- }
- $payment_code = input('param.payment_code');
- if ($payment_code) {
- $condition[] = ['payment_code', '=', $payment_code];
- }
- $buyer_name = input('param.buyer_name');
- if ($buyer_name) {
- $condition[] = ['buyer_name', '=', $buyer_name];
- }
- $is_refund = input('param.is_refund');
- if ($is_refund) {
- $condition[] = ['is_refund', '=', $is_refund];
- }
- $query_start_time = input('param.query_start_time');
- $query_end_time = input('param.query_end_time');
- $if_start_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_time);
- $if_end_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_time);
- $start_unixtime = $if_start_time ? strtotime($query_start_time) : null;
- $end_unixtime = $if_end_time ? strtotime($query_end_time) : null;
- if ($start_unixtime) {
- $condition[] = ['add_time', '>=', $start_unixtime];
- }
- if ($end_unixtime) {
- $condition[] = ['add_time', '<=', $end_unixtime];
- }
- $order_list = $order_model->getOrderList($condition, 10, '*', 'id desc', 0, ['store']);
- View::assign('show_page', $order_model->page_info->render());
- foreach ($order_list as $order_id => $order_info) {
- if ($order_info['order_state'] == ORDER_STATE_NEW) {
- $order_info['pay_amount'] = $order_info['order_amount'] - $order_info['deduction_amount'];
- }
- }
- //显示支付接口列表(搜索)
- View::assign('order_list', $order_list);
- View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
- $this->setAdminCurItem('add');
- return View::fetch('index');
- }
- /**
- * 平台订单状态操作
- *
- */
- public function change_state()
- {
- $state_type = input('param.state_type');
- if ($state_type == 'cancel') {
- $order_id = intval(input('param.id'));
- if ($order_id <= 0) {
- $this->error(lang('miss_order_number'));
- }
- $order_model = model('StoreOrder');
- $order_model->where('id', $order_id)->update(['order_state' => 0]);
- }
- ds_json_encode(10000, '操作成功');
- }
- /**
- * 查看订单
- *
- */
- public function show_order()
- {
- $order_id = intval(input('param.id'));
- if ($order_id <= 0) {
- $this->error(lang('miss_order_number'));
- }
- $order_model = model('StoreOrder');
- $order_info = $order_model->getOrderInfo(['id' => $order_id], ['store', 'member']);
- $order_info['deduction_amount'] = number_format($order_info['deduction_amount'], 2);
- View::assign('order_info', $order_info);
- return View::fetch('show_order');
- }
- /**
- * 导出
- *
- */
- public function export_step1()
- {
- $order_model = model('StoreOrder');
- $condition = [];
- $order_sn = input('param.order_sn');
- if ($order_sn) {
- $condition[] = ['order_sn', '=', $order_sn];
- }
- $store_name = input('param.store_name');
- if ($store_name) {
- $store_ids = Db::name('store')->where('store_name', 'like', "%{$store_name}%")->column('store_id');
- if (empty($store_ids)) {
- $condition[] = ['id', '=', 0];
- } else {
- $condition[] = ['store_id', 'in', $store_ids];
- }
- }
- $order_state = input('param.order_state');
- if (in_array($order_state, ['0', '10', '40'])) {
- $condition[] = ['order_state', '=', $order_state];
- }
- $payment_code = input('param.payment_code');
- if ($payment_code) {
- $condition[] = ['payment_code', '=', $payment_code];
- }
- $buyer_name = input('param.buyer_name');
- if ($buyer_name) {
- $condition[] = ['buyer_name', '=', $buyer_name];
- }
- $is_refund = input('param.is_refund');
- if ($is_refund) {
- $condition[] = ['is_refund', '=', $is_refund];
- }
- $query_start_time = input('param.query_start_time');
- $query_end_time = input('param.query_end_time');
- $if_start_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_time);
- $if_end_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_time);
- $start_unixtime = $if_start_time ? strtotime($query_start_time) : null;
- $end_unixtime = $if_end_time ? strtotime($query_end_time) : null;
- if ($start_unixtime) {
- $condition[] = ['add_time', '>=', $start_unixtime];
- }
- if ($end_unixtime) {
- $condition[] = ['add_time', '<=', $end_unixtime];
- }
- if (!is_numeric(input('param.page'))) {
- $count = $order_model->getOrderCount($condition);
- $export_list = [];
- if ($count > self::EXPORT_SIZE) { //显示下载链接
- $page = ceil($count / self::EXPORT_SIZE);
- for ($i = 1; $i <= $page; $i++) {
- $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
- $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
- $export_list[$i] = $limit1 . ' ~ ' . $limit2;
- }
- View::assign('export_list', $export_list);
- return View::fetch('/public/excel');
- } else { //如果数量小,直接下载
- $data = $order_model->getOrderList($condition, 0, '*', 'id desc', 0, ['store', 'member']);
- $this->createExcel($data);
- }
- } else { //下载
- $limit2 = self::EXPORT_SIZE;
- $data = $order_model->getOrderList($condition, $limit2, '*', 'id desc', 0, ['store', 'member']);
- $this->createExcel($data);
- }
- }
- /**
- * 生成excel
- *
- * @param array $data
- */
- private function createExcel($data = [])
- {
- Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/export.lang.php');
- $excel_obj = new \excel\Excel();
- $excel_data = [];
- //设置样式
- $excel_obj->setStyle(['id' => 's_title', 'Font' => ['FontName' => '宋体', 'Size' => '12', 'Bold' => '1']]);
- //header
- $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_no')];
- $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_store')];
- $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_buyer')];
- $excel_data[0][] = ['styleid' => 's_title', 'data' => '买家电话'];
- $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_xtimd')];
- $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_count')];
- $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_paytype')];
- $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_state')];
- $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_storeid')];
- $excel_data[0][] = ['styleid' => 's_title', 'data' => lang('exp_od_buyerid')];
- $excel_data[0][] = ['styleid' => 's_title', 'data' => '订单完成时间'];
- //data
- foreach ((array)$data as $k => $v) {
- $tmp = [];
- $tmp[] = ['data' => 'DS' . $v['order_sn']];
- $tmp[] = ['data' => $v['extend_store']['store_name']];
- $tmp[] = ['data' => $v['extend_member']['member_nickname']];
- $tmp[] = ['data' => $v['extend_member']['member_mobile']];
- $tmp[] = ['data' => $v['add_time']];
- $tmp[] = ['format' => 'Number', 'data' => ds_price_format($v['order_amount'])];
- $tmp[] = ['data' => get_order_payment_name($v['payment_code'])];
- $state_desc = $v['state_desc'];
- if ($v['is_refund'] == 1) {
- $state_desc .= "(已退款)";
- }
- $tmp[] = ['data' => $state_desc];
- $tmp[] = ['data' => $v['store_id']];
- $tmp[] = ['data' => $v['buyer_id']];
- $tmp[] = ['data' => $v['finished_time']];
- $excel_data[] = $tmp;
- }
- $excel_data = $excel_obj->charset($excel_data, CHARSET);
- $excel_obj->addArray($excel_data);
- $excel_obj->addWorksheet($excel_obj->charset('到店付款订单', CHARSET));
- $excel_obj->generateXML($excel_obj->charset('到店付款订单', CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP));
- }
- }
|