field('store_id,store_name') ->where('p_id', $store_id) ->whereOr('store_id', $store_id) ->select(); View::assign('store_arr', $store_arr); $store_ids = $store_arr->column('store_id'); $store_column = []; foreach ($store_arr as $store) { $store_column[$store['store_id']] = $store['store_name']; } //店铺搜索条件 $store_id_input = input('param.store_id', 0); if (!empty($store_id_input)) { if (in_array($store_id_input, $store_ids)) { $store_ids = [$store_id_input]; } else { $store_ids = [0]; } } View::assign('store_id_input', $store_id_input); $model = model('StoreOrder'); $condition = []; $condition[] = ['store_id', 'in', $store_ids]; $order_sn = input('get.order_sn'); if ($order_sn != '') { $condition[] = ['order_sn', '=', $order_sn]; } $buyer_name = input('get.buyer_name'); if ($buyer_name != '') { $condition[] = ['buyer_name', '=', $buyer_name]; } $allow_state_array = ['state_new', 'state_success', 'state_cancel']; $state_type = input('param.state_type'); if (in_array($state_type, $allow_state_array)) { $condition[] = ['order_state', '=', str_replace($allow_state_array, [ORDER_STATE_NEW, ORDER_STATE_SUCCESS, ORDER_STATE_CANCEL], $state_type)]; $condition[] = ['is_refund', '=', 2]; } else { $state_type = 'store_order'; } $query_start_date = input('get.query_start_date'); $query_end_date = input('get.query_end_date'); if ($query_start_date) { $condition[] = ['add_time', '>=', strtotime($query_start_date)]; } if ($query_end_date) { $condition[] = ['add_time', '<=', strtotime($query_end_date)]; } $is_refund = input('param.is_refund'); if ($is_refund == 1) { $state_type = 'order_refund'; $condition[] = ['is_refund', '=', 1]; } $order_list = $model->getOrderList($condition, 20, '*', 'id desc', 0, ['member']); View::assign('show_page', $model->page_info->render()); foreach ($order_list as $key => $order) { //店铺名称 $order_list[$key]['store_name'] = $store_column[$order['store_id']]; } View::assign('order_list', $order_list); /* 设置卖家当前菜单 */ $this->setSellerCurMenu('sellerstoreorder'); /* 设置卖家当前栏目 */ $this->setSellerCurItem($state_type); return View::fetch($this->template_dir . 'index'); } /** * 订单详情 * */ 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); View::assign('order_info', $order_info); $this->setSellerCurMenu('sellerstoreorder'); $this->setSellerCurItem('store_order'); return View::fetch($this->template_dir . 'show_order'); } /** * 订单状态操作 * */ public function change_state() { $model = model('StoreOrder'); $condition = []; $condition[] = ['id', '=', intval(input('param.id'))]; $condition[] = ['store_id', '=', session('store_id')]; $state_type = input('param.state_type'); if ($state_type == 'order_cancel') { $model->where($condition)->update(['order_state' => 0]); } ds_json_encode(10000, '操作成功'); } /** * 栏目菜单 */ function getSellerItemList() { $menu_array = [ [ 'name' => 'store_order', 'text' => lang('ds_member_path_all_order'), 'url' => (string)url('Sellerstoreorder/index'), ], [ 'name' => 'state_new', 'text' => lang('ds_member_path_wait_pay'), 'url' => (string)url('Sellerstoreorder/index', ['state_type' => 'state_new']), ], [ 'name' => 'state_success', 'text' => lang('ds_member_path_finished'), 'url' => (string)url('Sellerstoreorder/index', ['state_type' => 'state_success']), ], [ 'name' => 'state_cancel', 'text' => lang('ds_member_path_canceled'), 'url' => (string)url('Sellerstoreorder/index', ['state_type' => 'state_cancel']), ], [ 'name' => 'order_refund', 'text' => lang('已退款'), 'url' => (string)url('Sellerstoreorder/index', ['is_refund' => '1']), ], ]; return $menu_array; } public function export() { //上级店铺id $store_id = session('store_id'); $store_arr = Db::name('store')->field('store_id,store_name') ->where('p_id', $store_id) ->whereOr('store_id', $store_id) ->select(); $store_ids = $store_arr->column('store_id'); $store_column = []; foreach ($store_arr as $store) { $store_column[$store['store_id']] = $store['store_name']; } //店铺搜索条件 $store_id_input = input('param.store_id', 0); if (!empty($store_id_input)) { if (in_array($store_id_input, $store_ids)) { $store_ids = [$store_id_input]; } else { $store_ids = [0]; } } $model = model('StoreOrder'); $condition = []; $condition[] = ['store_id', 'in', $store_ids]; $ids = input('get.ids'); if (!empty($ids)) { $condition[] = ['id', 'in', explode(',', $ids)]; } $order_sn = input('get.order_sn'); if ($order_sn != '') { $condition[] = ['order_sn', '=', $order_sn]; } $buyer_name = input('get.buyer_name'); if ($buyer_name != '') { $condition[] = ['buyer_name', '=', $buyer_name]; } $allow_state_array = ['state_new', 'state_success', 'state_cancel']; $state_type = input('param.state_type'); if (in_array($state_type, $allow_state_array)) { $condition[] = ['order_state', '=', str_replace($allow_state_array, [ORDER_STATE_NEW, ORDER_STATE_SUCCESS, ORDER_STATE_CANCEL], $state_type)]; $condition[] = ['is_refund', '=', 2]; } $query_start_date = input('get.query_start_date'); $query_end_date = input('get.query_end_date'); if ($query_start_date) { $condition[] = ['add_time', '>=', strtotime($query_start_date)]; } if ($query_end_date) { $condition[] = ['add_time', '<=', strtotime($query_end_date)]; } $is_refund = input('param.is_refund'); if ($is_refund == 1) { $condition[] = ['is_refund', '=', 1]; } $order_list = $model->getOrderList($condition, 0, '*', 'id desc', 0, ['member']); foreach ($order_list as $key => $order) { //店铺名称 $order_list[$key]['store_name'] = $store_column[$order['store_id']]; } $this->createExcel($order_list); } /** * 生成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')]; //data foreach ((array)$data as $k => $v) { $tmp = []; $tmp[] = ['data' => $v['order_sn']]; $tmp[] = ['data' => $v['store_name']]; $tmp[] = ['data' => $v['buyer_name']]; $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'])]; $tmp[] = ['data' => get_order_state($v)]; $tmp[] = ['data' => $v['store_id']]; $tmp[] = ['data' => $v['buyer_id']]; $excel_data[] = $tmp; } $excel_data = $excel_obj->charset($excel_data, CHARSET); $excel_obj->addArray($excel_data); $excel_obj->addWorksheet($excel_obj->charset(lang('exp_od_order'), CHARSET)); $excel_obj->generateXML($excel_obj->charset(lang('exp_od_order'), CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP)); } }