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)); } }