330 lines
16 KiB
PHP
330 lines
16 KiB
PHP
<?php
|
|
|
|
/**
|
|
* 订单管理列表
|
|
*/
|
|
class OrdersList
|
|
{
|
|
private $ci;
|
|
private $searchTpAry = array('name' => '客户姓名', 'mobile' => '客户手机号', 'sid' => '订单号');
|
|
private $paywayAry = array(0 => '按揭', 1 => '全款');
|
|
private $overAry = array(0 => '7天内', 1 => '14天内', 2 => '30天内', 3 => '大于30天');
|
|
|
|
public function __construct()
|
|
{
|
|
$this->ci = &get_instance();
|
|
$this->ci->load->model('receiver/order/receiver_orders_model', 'mdOrders');
|
|
$this->ci->load->model('receiver/order/receiver_order_datas_model');
|
|
$this->ci->load->model('app/licheb/app_licheb_users_model', 'mdLichebUsers');
|
|
$this->ci->load->model('app/licheb/app_licheb_channel_biz_model');
|
|
$this->ci->load->model('receiver/receiver_customers_model', 'mdCustomers');
|
|
$this->ci->load->model('receiver/receiver_clues_cfrom_model', 'mdCluesCfrom');
|
|
$this->ci->load->model('auto/auto_series_model');
|
|
$this->ci->load->model('auto/auto_brand_model');
|
|
$this->ci->load->model('auto/auto_cars_model');
|
|
$this->ci->load->model('area_model');
|
|
$this->ci->load->model("biz/biz_model");
|
|
|
|
}
|
|
|
|
public function lists($status_pid, $params = array())
|
|
{
|
|
!$params['qdjl_id'] && $params['qdjl_id'] = '';
|
|
!$params['of_id'] && $params['of_id'] = '';
|
|
!$params['of2_id'] && $params['of2_id'] = '';
|
|
!strlen($params['payway']) && $params['payway'] = '';
|
|
!strlen($params['over_id']) && $params['over_id'] = '';
|
|
$fieldAry = $this->get_fields($status_pid, 0);
|
|
$show_info['offlineSourcesAry'] = $this->ci->mdCustomers->offlineSources_search();
|
|
$show_info['paywayAry'] = $this->paywayAry;//付款方式
|
|
//渠道经理
|
|
$show_info['qdjl_lists'] = $this->ci->mdLichebUsers->select(array('group_id' => 4, 'status' => 1, 'biz_id<>' => '0')
|
|
, 'id desc', 0, 0, 'id,uname as name');
|
|
$result = $this->orders($params);
|
|
$result['show_info'] = $show_info;
|
|
$result['fieldAry'] = $fieldAry;
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Notes:全部订单
|
|
* Created on: 2021/9/18 15:13
|
|
* Created by: dengbw
|
|
* @param array $params
|
|
* @return array
|
|
*/
|
|
private function orders($params = array())
|
|
{
|
|
$page = $params['page'] = $params['page'] ? intval($params['page']) : 1;
|
|
$size = $params['size'] = $params['size'] ? intval($params['size']) : 20;
|
|
$order_status_cn = $this->ci->mdOrders->get_status();
|
|
$view_type = 'orders';
|
|
$where = [
|
|
"status>=" => 0,
|
|
];
|
|
$_title = '全部订单';
|
|
$view = 'receiver/order/lists';
|
|
$params['status_pid'] == 1 && $where["payway"] = 0;
|
|
if ($params['of_id'] || $params['of2_id']) {
|
|
$where_c = 'status>=0';
|
|
$params['of_id'] && $where_c .= ' and of_id = ' . $params['of_id'];
|
|
$params['of2_id'] && $where_c .= ' and of2_id = ' . $params['of2_id'];
|
|
$where["customer_id in (select id from lc_receiver_customers where " . $where_c . ')'] = null;
|
|
}
|
|
if (strlen($params['payway'])) {
|
|
$where["payway"] = $params['payway'];
|
|
}
|
|
if ($params['qdjl_id']) {//渠道经理
|
|
$where["biz_id in(select biz_id from lc_app_licheb_channel_biz where uid={$params['qdjl_id']})"] = null;
|
|
}
|
|
if ($params['title']) {
|
|
$where["{$params['search_tp']} like '%{$params['title']}%'"] = null;
|
|
}
|
|
//创建时间
|
|
if ($params['c_time']) {
|
|
$c_time = explode(' ~ ', $params['c_time']);
|
|
if ($c_time[0]) {
|
|
$where["c_time >="] = strtotime($c_time[0] . ' 00:00:00');
|
|
}
|
|
if ($c_time[1]) {
|
|
$where["c_time <="] = strtotime($c_time[1] . ' 23:59:59');
|
|
}
|
|
}
|
|
//下定时间
|
|
if ($params['order_time']) {
|
|
$order_time = explode(' ~ ', $params['order_time']);
|
|
if ($order_time[0]) {
|
|
$where["order_time >="] = $order_time[0] . ' 00:00:00';
|
|
}
|
|
if ($order_time[1]) {
|
|
$where["order_time <="] = $order_time[1] . ' 23:59:59';
|
|
}
|
|
}
|
|
//开票时间
|
|
if ($params['bill_time']) {
|
|
$bill_time = explode(' ~ ', $params['bill_time']);
|
|
if ($bill_time[0]) {
|
|
$where["bill_time >="] = $bill_time[0] . ' 00:00:00';
|
|
}
|
|
if ($bill_time[1]) {
|
|
$where["bill_time <="] = $bill_time[1] . ' 23:59:59';
|
|
}
|
|
}
|
|
//是否开票
|
|
if ($params['isbill'] == 1) {
|
|
$where["bill_time <>"] = '0000-00-00 00:00:00';
|
|
}
|
|
if ($params['isbill'] == 2) {
|
|
$where["bill_time"] = '0000-00-00 00:00:00';
|
|
}
|
|
|
|
//交付时间
|
|
if ($params['ck_time']) {
|
|
$ck_time = explode(' ~ ', $params['ck_time']);
|
|
if ($ck_time[0]) {
|
|
$where["ck_time >="] = $ck_time[0] . ' 00:00:00';
|
|
}
|
|
if ($ck_time[1]) {
|
|
$where["ck_time <="] = $ck_time[1] . ' 23:59:59';
|
|
}
|
|
}
|
|
!$params['brand_id'] && $params['brand_id'] = 0;
|
|
!$params['series_id'] && $params['series_id'] = 0;
|
|
!$params['car_id'] && $params['car_id'] = 0;
|
|
$params['brand_id'] && $where['brand_id'] = $params['brand_id'];
|
|
$params['series_id'] && $where['series_id'] = $params['series_id'];
|
|
$params['car_id'] && $where['car_id'] = $params['car_id'];
|
|
//销售员筛选
|
|
if ($params['admin_id']) {
|
|
$where["sale_id"] = $params['admin_id'];
|
|
} else {
|
|
if ($params['biz_id_admin']) {//指定店铺所有销售员
|
|
$where["biz_id"] = $params['biz_id_admin'];
|
|
} else {
|
|
//指定城市的所有门店
|
|
$where_biz = array();
|
|
if ($params['county_id_admin']) {
|
|
$where_biz['county_id'] = $params['county_id_admin'];
|
|
} else if ($params['city_id_admin']) {
|
|
$where_biz['city_id'] = $params['city_id_admin'];
|
|
} else if ($params['province_id_admin']) {
|
|
$where_biz['province_id'] = $params['province_id_admin'];
|
|
}
|
|
if ($where_biz) {
|
|
$where_biz['status>-1'] = null;
|
|
$rows_biz = $this->ci->biz_model->select($where_biz, 'id desc', 0, 0, 'id');
|
|
if ($rows_biz) {
|
|
$str_ids = implode(',', array_column($rows_biz, 'id'));
|
|
$where["biz_id in({$str_ids})"] = null;
|
|
} else {
|
|
$where["biz_id"] = -1;
|
|
}
|
|
}
|
|
}
|
|
!$params['province_id_admin'] && $params['province_id_admin'] = '';
|
|
!$params['city_id_admin'] && $params['city_id_admin'] = '';
|
|
!$params['county_id_admin'] && $params['county_id_admin'] = '';
|
|
!$params['biz_id_admin'] && $params['biz_id_admin'] = '';
|
|
$params['admin_id'] = '';
|
|
}
|
|
|
|
if (strlen($params['status'])) {
|
|
$where['status'] = $params['status'];
|
|
}
|
|
$orderby = "c_time desc";
|
|
$count = $this->ci->mdOrders->count($where);
|
|
$rows = $this->ci->mdOrders->select($where, $orderby, $page, $size);
|
|
$lists = [];
|
|
if ($count) {
|
|
//客户来源
|
|
$str_rids = implode(',', array_unique(array_column($rows, 'customer_id')));
|
|
!$str_rids && $str_rids = 0;
|
|
$customers = $this->ci->mdCustomers->map('id', 'of_id,of2_id', array("id in({$str_rids})" => null));
|
|
$offlineSources = $this->ci->mdCustomers->offlineSources();
|
|
//门店
|
|
$str_biz_ids = implode(',', array_unique(array_column($rows, 'biz_id')));
|
|
!$str_biz_ids && $str_biz_ids = 0;
|
|
$bizs_rows = $this->ci->biz_model->select(array("id in({$str_biz_ids})" => null), '', '', '', 'id,biz_name,city_id,county_id,type');
|
|
$bizs = [];
|
|
if ($bizs_rows) { //获取城市
|
|
$ids = array_unique(array_column($bizs_rows, 'county_id'));
|
|
$city_rows = $this->ci->area_model->get_map_by_county_ids($ids, 'id,city_name,city_id', 'city_id');
|
|
foreach ($bizs_rows as $val) {
|
|
$val['city_name'] = $city_rows[$val['city_id']] ? $city_rows[$val['city_id']][0]['city_name'] : '';
|
|
$bizs[$val['id']] = $val;
|
|
}
|
|
}
|
|
|
|
//品牌车型
|
|
$brand_arr = array_unique(array_column($rows, 'brand_id'));
|
|
$brands = $this->ci->auto_brand_model->get_map_by_ids($brand_arr, 'id,name');
|
|
//车系车型
|
|
$series_arr = array_unique(array_column($rows, 'series_id'));
|
|
$series = $this->ci->auto_series_model->get_map_by_ids($series_arr, 'id,name');
|
|
//车系车型
|
|
$car_arr = array_unique(array_column($rows, 'car_id'));
|
|
$cars = $this->ci->auto_cars_model->get_map_by_ids($car_arr, 'id,name');
|
|
|
|
$admin_ids = array_unique(array_column($rows, 'admin_id'));
|
|
$admin_ids_str = implode(',', $admin_ids);
|
|
$admins = [];
|
|
if ($admin_ids_str) {
|
|
$where = ["id in ($admin_ids_str)" => null];
|
|
$admins = $this->ci->mdLichebUsers->map('id', 'uname', $where, 'id desc', 0, 0, 'id,uname'); //顾问
|
|
}
|
|
foreach ($rows as $key => $val) {
|
|
$info_json = json_decode($val['info_json'], true);
|
|
$fields = array();
|
|
$brand_name = isset($brands[$val['brand_id']]) ? $brands[$val['brand_id']][0]['name'] : '';
|
|
$series_name = isset($series[$val['series_id']]) ? $series[$val['series_id']][0]['name'] : '';
|
|
$car_name = isset($cars[$val['car_id']]) ? $cars[$val['car_id']][0]['name'] : '';
|
|
$money_json = json_decode($val['money_json'], true);
|
|
$fields['o_id'] = $val['id'];
|
|
$name = $val['name'];
|
|
$mobile = $val['mobile'];
|
|
$open_url = '/receiver/orders/get?id=';
|
|
$fields['name'] = $size > 1000 ? $name
|
|
: '<a href="javascript:;" data-open="' . $open_url . $val['id'] . '">' . $name . '<br>' . $mobile . '<br>' . $val['card_id'] . '</a>';
|
|
$fields['id_card'] = $val['card_id'];
|
|
$fields['mobile'] = $size > 1000 ? '="' . $mobile . '"' : $mobile;
|
|
$fields['car_name'] = "{$brand_name}-{$series_name}-{$car_name}";
|
|
$fields['payway_name'] = $this->paywayAry[$val['payway']];
|
|
$fields['payway'] = $fields['payway_name'];
|
|
$fields['brand_name'] = $brand_name;
|
|
$fields['series_name'] = $series_name;
|
|
$fields['c_name'] = $car_name;
|
|
$fields['color'] = $val['color'];
|
|
$fields['in_color'] = $val['in_color'];
|
|
$status_name = $order_status_cn[$val['status']];
|
|
$fields['status_name'] = $status_name;
|
|
$fields['biz_name'] = $bizs[$val['biz_id']] ? $bizs[$val['biz_id']]['biz_name'] . '<br>' . $admins[$val['admin_id']] : '';
|
|
$size > 1000 && $fields['biz_name'] = $bizs[$val['biz_id']] ? $bizs[$val['biz_id']]['biz_name'] : '';
|
|
$fields['c_time'] = date('Y-m-d H:i:s', $val['c_time']);
|
|
$of_title = '-';
|
|
$of_title_1 = $of_title_2 = '';
|
|
$of_id = $customers[$val['customer_id']]['of_id'];
|
|
if ($of_id) {
|
|
$of_ary = $offlineSources[$of_id];
|
|
$of_title = $of_ary['name'];
|
|
$of_ary['name'] && $of_title_1 = $of_ary['name'];
|
|
$of2_id = $customers[$val['customer_id']]['of2_id'];
|
|
$of2_id && $of_title .= '-' . $of_ary['list'][$of2_id];
|
|
$of2_id && $of_ary['list'][$of2_id] && $of_title_2 = $of_ary['list'][$of2_id];
|
|
}
|
|
|
|
$fields['of_title'] = $of_title;
|
|
$fields['of_title_1'] = $of_title_1;
|
|
$fields['of_title_2'] = $of_title_2;
|
|
$fields['order_time'] = $val['order_time'] != '0000-00-00 00:00:00' ? $val['order_time'] : '';
|
|
$fields['bill_time'] = $val['bill_time'] != '0000-00-00 00:00:00' ? $val['bill_time'] : '';
|
|
$fields['over_time'] = $val['over_time'] != '0000-00-00 00:00:00' ? date('Y-m-d', strtotime($val['over_time'])) : '';
|
|
$fields['refund_time'] = $val['refund_time'] != '0000-00-00 00:00:00' ? date('Y-m-d', strtotime($val['refund_time'])) : '';
|
|
$fields['ck_time'] = $val['ck_time'];
|
|
|
|
$odata = $this->ci->receiver_order_datas_model->get(['o_id' => $val['id']]);
|
|
$fields['contract'] = $odata['contract_img'] ? '有' : '无';
|
|
|
|
if ($size > 1000) {
|
|
$user_info = '';
|
|
if (!$user_info) {
|
|
$sale = $this->ci->mdLichebUsers->get(['id' => $val['sale_id']], 'uname');
|
|
$fields['admin_name'] = $sale['uname'];
|
|
}
|
|
}
|
|
$lists[] = $fields;
|
|
}
|
|
}
|
|
$pager = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count);
|
|
$_title = $size > 1000 ? $_title : $_title . '列表';
|
|
$view_type != 'orders' && $status_arr = [];
|
|
return array('lists' => $lists, 'pager' => $pager, 'params' => $params, 'status_arr' => $status_arr
|
|
, 'searchTpAry' => $this->searchTpAry, 'view' => $view, 'view_type' => $view_type, '_title' => $_title);
|
|
}
|
|
|
|
/**
|
|
* Notes:获取字段
|
|
* Created on: 2021/10/29 15:38
|
|
* Created by: dengbw
|
|
* @param $status_pid
|
|
* @param int $export
|
|
* @return array
|
|
*/
|
|
public function get_fields($status_pid, $export = 0)
|
|
{
|
|
$fields1 = $fields2 = [];
|
|
if ($export) {
|
|
$fields1['name'] = ['title' => '客户姓名'];
|
|
$fields1['mobile'] = ['title' => '客户电话'];
|
|
$fields1['id_card'] = ['title' => '证件号码'];
|
|
$fields1['brand_name'] = ['title' => '品牌'];
|
|
$fields1['series_name'] = ['title' => '车系'];
|
|
$fields1['c_name'] = ['title' => '车型'];
|
|
$fields1['color'] = ['title' => '车身颜色'];
|
|
$fields1['in_color'] = ['title' => '内饰颜色'];
|
|
$fields1['city_name'] = ['title' => '城市'];
|
|
$fields1['biz_name'] = ['title' => '门店'];
|
|
$fields1['admin_name'] = ['title' => '销售人员'];
|
|
$fields1['of_title_1'] = ['title' => '来源1'];
|
|
$fields1['of_title_2'] = ['title' => '来源2'];
|
|
} else {
|
|
$fields1['name'] = ['title' => '客户', 'width' => '14%'];
|
|
}
|
|
$fields2 = [
|
|
'car_name' => ['title' => '车辆', 'width' => '27%'], 'biz_name' => ['title' => '门店', 'width' => '12%'],
|
|
'payway' => ['title' => '付款方式', 'width' => '9%'], 'of_title' => ['title' => '客户来源', 'width' => '10%'],
|
|
'status_name' => ['title' => '状态', 'width' => '9%'], 'order_time' => ['title' => '下定时间', 'width' => '9%']
|
|
];
|
|
$fields = array_merge($fields1, $fields2);
|
|
if ($export) {
|
|
unset($fields['price'], $fields['c_time'], $fields['car_name'], $fields['of_title']);
|
|
!$fields['c_time'] && $fields['c_time'] = ['title' => '订单时间'];
|
|
!$fields['order_time'] && $fields['order_time'] = ['title' => '下定时间'];
|
|
!$fields['bill_time'] && $fields['bill_time'] = ['title' => '开票时间'];
|
|
!$fields['contract'] && $fields['contract'] = ['title' => '购车合同'];
|
|
}
|
|
return $fields;
|
|
}
|
|
}
|
|
|
|
?>
|