620 lines
32 KiB
PHP
620 lines
32 KiB
PHP
<?php
|
|
|
|
/**
|
|
* 订单管理列表
|
|
*/
|
|
class Ordersv2List
|
|
{
|
|
private $ci;
|
|
private $searchTpAry = array('owner_name' => '车主姓名', 'owner_mobile' => '车主手机号', 'name' => '客户姓名', 'mobile' => '客户手机号', 'sid' => '订单号');
|
|
private $paywayAry = array(0 => '贷款', 1 => '全款');
|
|
private $overAry = array(0 => '7天内', 1 => '14天内', 2=> '30天内', 3=> '大于30天');
|
|
private $t1 = 'lc_receiver_orders_v2';
|
|
private $t2 = 'lc_receiver_order_status';
|
|
|
|
public function __construct()
|
|
{
|
|
$this->ci = &get_instance();
|
|
$this->ci->load->model('receiver/order/receiver_orders_v2_model', 'mdOrders');
|
|
$this->ci->load->model('receiver/order/receiver_order_status_model');
|
|
$this->ci->load->model('receiver/order/receiver_order_agents_model', 'order_agents_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("biz/biz_model");
|
|
$this->ci->load->model('auto/auto_series_model');
|
|
$this->ci->load->model('auto/auto_brand_model');
|
|
$this->ci->load->model('auto/auto_attr_model');
|
|
$this->ci->load->model('items/items_model', 'mdItems');
|
|
$this->ci->load->model('area_model');
|
|
$this->ci->load->model('sys/sys_finance_model');
|
|
|
|
$this->ci->load->library('receiver/orders_v2_entity');
|
|
$this->ci->load->library('receiver/orders_status_entity');
|
|
}
|
|
|
|
public function lists($status_pid, $params = array())
|
|
{
|
|
// $result = $show_info = array();
|
|
!$params['qdjl_id'] && $params['qdjl_id'] = '';
|
|
!$params['of_id'] && $params['of_id'] = '';
|
|
!$params['of2_id'] && $params['of2_id'] = '';
|
|
!strlen($params['payway']) && $params['payway'] = '';
|
|
!$params['biz_type'] && $params['biz_type'] = '';
|
|
!strlen($params['over_id']) && $params['over_id'] = '';
|
|
!strlen($params['is_bill']) && $params['is_bill'] = '';
|
|
$fieldAry = $this->get_fields($status_pid);
|
|
$show_info['offlineSourcesAry'] = $this->ci->mdCustomers->offlineSources();//客户来源
|
|
$show_info['paywayAry'] = $this->paywayAry;//付款方式
|
|
$show_info['overAry'] = $this->overAry;
|
|
$show_info['bizTypeAry'] = $this->ci->biz_model->type_ary();//门店类型
|
|
//渠道经理
|
|
$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');
|
|
if($params['status_pid']==12){ //意向金订单
|
|
$result = $this->inten_orders($params);
|
|
}else{
|
|
$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;
|
|
$status_arr = $this->ci->receiver_order_status_model->statusAry();
|
|
$order_status_cn = $this->ci->mdOrders->get_status();
|
|
$view_type = 'orders';
|
|
$where = [
|
|
"{$this->t1}.status>=" => 0,
|
|
];
|
|
$_title = '全部订单';
|
|
$view = 'receiver/orderv2/lists';
|
|
$params['status_pid'] == 1 && $where["{$this->t1}.payway"] = 0;
|
|
if (is_product()) {
|
|
$where["{$this->t1}.biz_id<>"] = 1;
|
|
}
|
|
if ($_SESSION['admin_info']['biz_id']) {
|
|
$biz_ids = implode(',', $_SESSION['admin_info']['biz_id']);
|
|
$where["{$this->t1}.biz_id in ($biz_ids)"] = null;
|
|
}
|
|
if ($params['biz_type']) {
|
|
$where["{$this->t1}.biz_id in (select id from lc_biz where type = " . $params['biz_type'] . ')'] = null;
|
|
}
|
|
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["{$this->t1}.customer_id in (select id from lc_receiver_customers where " . $where_c . ')'] = null;
|
|
}
|
|
if (strlen($params['payway'])) {
|
|
$where["{$this->t1}.payway"] = $params['payway'];
|
|
}
|
|
if ($params['qdjl_id']) {//渠道经理
|
|
$where["{$this->t1}.biz_id in(select biz_id from lc_app_licheb_channel_biz where uid={$params['qdjl_id']})"] = null;
|
|
}
|
|
if ($params['title']) {
|
|
$where["{$this->t1}.{$params['search_tp']} like '%{$params['title']}%'"] = null;
|
|
}
|
|
//创建时间
|
|
if ($params['c_time']) {
|
|
$c_time = explode(' ~ ', $params['c_time']);
|
|
if ($c_time[0]) {
|
|
$where["{$this->t1}.c_time >="] = strtotime($c_time[0] . ' 00:00:00');
|
|
}
|
|
if ($c_time[1]) {
|
|
$where["{$this->t1}.c_time <="] = strtotime($c_time[1] . ' 23:59:59');
|
|
}
|
|
}
|
|
//下定时间
|
|
if ($params['order_time']) {
|
|
$order_time = explode(' ~ ', $params['order_time']);
|
|
if ($order_time[0]) {
|
|
$where["{$this->t1}.order_time >="] = $order_time[0] . ' 00:00:00';
|
|
}
|
|
if ($order_time[1]) {
|
|
$where["{$this->t1}.order_time <="] = $order_time[1] . ' 23:59:59';
|
|
}
|
|
}
|
|
//开票时间
|
|
if ($params['bill_time']) {
|
|
$bill_time = explode(' ~ ', $params['bill_time']);
|
|
if ($bill_time[0]) {
|
|
$where["{$this->t1}.bill_time >="] = $bill_time[0] . ' 00:00:00';
|
|
}
|
|
if ($bill_time[1]) {
|
|
$where["{$this->t1}.bill_time <="] = $bill_time[1] . ' 23:59:59';
|
|
}
|
|
}
|
|
if(strlen($params['is_bill'])){
|
|
if($params['is_bill']){
|
|
$where["{$this->t1}.bill_time <> '0000-00-00 00:00:00'"] = null;
|
|
}else{
|
|
$where["{$this->t1}.bill_time"] = '0000-00-00 00:00:00';
|
|
}
|
|
}
|
|
//交付时长
|
|
if(strlen($params['over_id'])){
|
|
if($params['over_id']==3){
|
|
$where["{$this->t1}.over_time>"] = date('Y-m-d',time()+30*24*60*60);
|
|
}else{
|
|
if($params['over_id']==1) {
|
|
$e_day = 14;
|
|
}elseif($params['over_id']==2){
|
|
$e_day = 30;
|
|
}else{
|
|
$e_day = 7;
|
|
}
|
|
$where["{$this->t1}.over_time<="] = date('Y-m-d',time()+$e_day*24*60*60);
|
|
}
|
|
}
|
|
if ($params['brand_id']) {//品牌
|
|
$where["{$this->t1}.brand_id"] = $params['brand_id'];
|
|
} else {
|
|
if (is_product()) {
|
|
$where["{$this->t1}.brand_id<>"] = 3;//狸车品牌不显示
|
|
}
|
|
$params['brand_id'] = '';
|
|
}
|
|
if ($params['s_id']) {//车系
|
|
$where["{$this->t1}.s_id"] = $params['s_id'];
|
|
} else {
|
|
$params['s_id'] = '';
|
|
}
|
|
if ($params['v_id']) {//车型
|
|
$where["{$this->t1}.v_id"] = $params['v_id'];
|
|
} else {
|
|
$params['v_id'] = '';
|
|
}
|
|
if ($params['cor_id']) {//车身颜色
|
|
$where["{$this->t1}.cor_id"] = $params['cor_id'];
|
|
} else {
|
|
$params['cor_id'] = '';
|
|
}
|
|
//销售员筛选
|
|
if ($params['admin_id']) {
|
|
$where["{$this->t1}.sale_id"] = $params['admin_id'];
|
|
} else {
|
|
if ($params['biz_id_admin']) {//指定店铺所有销售员
|
|
$where["{$this->t1}.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'];
|
|
}
|
|
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["{$this->t1}.biz_id in({$str_ids})"] = null;
|
|
} else {
|
|
$where["{$this->t1}.biz_id"] = -1;
|
|
}
|
|
}
|
|
}
|
|
!$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 ($params['vin']) {
|
|
$where = ["{$this->t1}.status>=" => 0];
|
|
$where["{$this->t1}.item_id in(select id from lc_items where vin like '%{$params['vin']}%')"] = null;
|
|
}
|
|
$fileds = "{$this->t1}.id,{$this->t1}.name,{$this->t1}.mobile,{$this->t1}.brand_id,{$this->t1}.s_id,{$this->t1}.v_id,
|
|
{$this->t1}.cor_id,{$this->t1}.incor_id,{$this->t1}.money_json,{$this->t1}.payway,{$this->t1}.status,{$this->t1}.c_time,
|
|
{$this->t1}.biz_id,{$this->t1}.bill_time,{$this->t1}.customer_id,{$this->t1}.owner_name,{$this->t1}.owner_mobile,{$this->t1}.main_type,{$this->t1}.info_json,
|
|
{$this->t1}.order_time,{$this->t1}.bill_time,{$this->t1}.item_id,{$this->t1}.over_time,{$this->t1}.sale_id,{$this->t1}.finance_id,{$this->t1}.refund_time";
|
|
if(strlen($params['status_pid'])){
|
|
$where["{$this->t1}.brand_id>"] = 0;
|
|
}
|
|
if (strlen($params['status_pid']) && $params['status_pid'] != 21) { //付款-已下定
|
|
$where["{$this->t1}.status <> 2"] = null;
|
|
}
|
|
if ($params['status_pid'] == 4) { //交付需要开票后才显示
|
|
$where["{$this->t1}.id in (select o_id from lc_receiver_order_status where pid_status=3 and status=1)"] = null;
|
|
}
|
|
if (strlen($params['status_pid']) && $params['status_pid'] && !in_array($params['status_pid'],[21,5,3])) {
|
|
$where["{$this->t1}.id>="] = Orders_v2_entity::V2_START_ID;
|
|
}
|
|
if (strlen($params['status_pid']) && !$params['status_pid']) { //付款列表 下定时间排序
|
|
$orderby = "{$this->t1}.order_time desc";
|
|
} elseif ($params['status_pid'] == 3) { // 开票列表 开票时间排序
|
|
$orderby = "{$this->t1}.bill_time desc";
|
|
}elseif($params['status_pid'] == 21){ //退款时间排序
|
|
$orderby = "{$this->t1}.refund_time desc";
|
|
} else {
|
|
$orderby = "{$this->t1}.c_time desc";
|
|
}
|
|
if (strlen($params['status_pid']) && $params['status'] && $params['status_pid']!=21 &&$params['status']<21) {
|
|
$where["{$this->t2}.pid_status"] = $params['status_pid'];
|
|
$up_key = $params['status'] + 1;
|
|
$where["{$this->t2}.status in ({$params['status']},{$up_key})"] = null;
|
|
$having = "total = 1";
|
|
if ($params['status_pid'] == 0 && $params['status'] == 1) {
|
|
$having = "total >= 1";
|
|
}
|
|
$count = $this->ci->mdOrders->selectOrders($where, '', '', '', 1, '', $having);
|
|
$rows = $this->ci->mdOrders->selectOrders($where, $orderby, $page, $size, '', $fileds, $having);
|
|
} else {
|
|
if (strlen($params['status']) && $params['status']<21) {
|
|
$where["id not in (select o_id from lc_receiver_order_status where pid_status={$params['status_pid']} and status=1)"] = null;
|
|
}
|
|
if ($params['status_pid'] == 3) { //开票
|
|
if (strlen($params['status'])) { //待开票
|
|
$where['id in (select o_id from lc_receiver_order_status where pid_status=0 and status=2)'] = null;
|
|
} else { //全部
|
|
$where['id in (select o_id from lc_receiver_order_status where (pid_status=0 and status=2) or (pid_status=3 and status=1))'] = null;
|
|
}
|
|
}
|
|
$params['status_pid'] == 21 && $where['status'] = 2; //退款
|
|
if($params['status']==21){ //特殊需求
|
|
$where["id in (select o_id from lc_receiver_order_status where pid_status=0 and status=1)"] = null; //已付定金
|
|
$where["id not in (select o_id from lc_receiver_order_status where pid_status=0 and status=2)"] = null; //尾款未支付
|
|
}
|
|
$count = $this->ci->mdOrders->count($where);
|
|
$rows = $this->ci->mdOrders->select($where, $orderby, $page, $size, $fileds);
|
|
}
|
|
$lists = [];
|
|
if ($count) {
|
|
//商品vin
|
|
$str_item_ids = implode(',', array_unique(array_column($rows, 'item_id')));
|
|
!$str_item_ids && $str_item_ids = 0;
|
|
$items = $this->ci->mdItems->map('id', 'vin', array("id in({$str_item_ids})" => null));
|
|
//客户来源
|
|
$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, 's_id'));
|
|
$series = $this->ci->auto_series_model->get_map_by_ids($series_arr, 'id,name');
|
|
//获取属性
|
|
$v_arr = array_unique(array_column($rows, 'v_id'));
|
|
$cor_arr = array_unique(array_column($rows, 'cor_id'));
|
|
$incor_arr = array_unique(array_column($rows, 'incor_id'));
|
|
$attr_arr = array_merge($v_arr, $cor_arr, $incor_arr);
|
|
$attr = $this->ci->auto_attr_model->get_map_by_ids($attr_arr, 'id,title');
|
|
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['s_id']]) ? $series[$val['s_id']][0]['name'] : '';
|
|
$v_name = isset($attr[$val['v_id']]) ? $attr[$val['v_id']][0]['title'] : '';
|
|
$cor_name = isset($attr[$val['cor_id']]) ? $attr[$val['cor_id']][0]['title'] : '';
|
|
$money_json = json_decode($val['money_json'],true);
|
|
$fields['o_id'] = $val['id'];
|
|
if (Orders_v2_entity::V2_START_ID < $val['id']) {
|
|
if ($val['main_type']) {
|
|
$name = $info_json['c_company'];
|
|
$mobile = $val['mobile'];
|
|
} else {
|
|
$name = $val['owner_name'];
|
|
$mobile = $val['owner_mobile'];
|
|
}
|
|
$open_url = '/receiver/orderv2/orders/get?id=';
|
|
$fields['name'] = $size > 1000 ? $name
|
|
: '<a href="javascript:;" data-open="' . $open_url . $val['id'] . '">' . $name . '<br>' . $mobile . '</a>';
|
|
} else {
|
|
$open_url = '/receiver/orders/get?id=';
|
|
$mobile = $val['mobile'];
|
|
$o_tp = '(旧订单)';
|
|
$fields['name'] = $size > 1000 ? $val['name']
|
|
: '<a href="javascript:;" data-open="' . $open_url . $val['id'] . '">' . $val['name'] . $o_tp . '<br>' . $val['mobile'] . '</a>';
|
|
}
|
|
$fields['id_card'] = $info_json['c_owner_cardid'] ? '="'.$info_json['c_owner_cardid'].'"' : '';
|
|
$fields['mobile'] = $size > 1000 ? '="'.$mobile.'"' : $mobile;
|
|
$fields['car_name'] = "{$brand_name}-{$series_name}-{$v_name}-{$cor_name}";
|
|
$fields['price_car'] = number_format($this->ci->orders_v2_entity->total_price($val['id'],$val['money_json']),2);
|
|
$fields['payway_name'] = $this->paywayAry[$val['payway']];
|
|
$fields['price'] = $fields['payway_name']."<br>".$fields['price_car'];
|
|
$fields['incor_name'] = isset($attr[$val['incor_id']]) ? $attr[$val['incor_id']][0]['title'] : '';
|
|
|
|
if($val['status']==2 || $val['id']<= Orders_v2_entity::V2_START_ID){
|
|
$status_name = $order_status_cn[$val['status']];
|
|
}else{
|
|
$params['status_pid'] == 6 && $params['status_pid']='';
|
|
$status_name = $this->ci->orders_status_entity->last_status_cn($val['id'], $params['status_pid']);
|
|
!$status_name && $status_name = '未下定';
|
|
}
|
|
$fields['status_name'] = $status_name;
|
|
$fields['biz_name'] = $bizs[$val['biz_id']] ? $bizs[$val['biz_id']]['biz_name'] : '';
|
|
$fields['city_name'] = $bizs[$val['biz_id']] ? $bizs[$val['biz_id']]['city_name'] : '';
|
|
$fields['biz_type'] = $bizs[$val['biz_id']] ? $this->ci->biz_model->type_ary($bizs[$val['biz_id']]['type']) : '';
|
|
$fields['c_time'] = date('Y-m-d H:i:s', $val['c_time']);
|
|
$of_title = '-';
|
|
$of_id = $customers[$val['customer_id']]['of_id'];
|
|
if ($of_id) {
|
|
$of_ary = $offlineSources[$of_id];
|
|
$of_title = $of_ary['name'];
|
|
$of2_id = $customers[$val['customer_id']]['of2_id'];
|
|
$of2_id && $of_title .= '-' . $of_ary['list'][$of2_id];
|
|
}
|
|
$fields['of_title'] = $of_title;
|
|
$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['vin'] = $items[$val['item_id']] ? $items[$val['item_id']] : '';
|
|
$fields['vin'] && $fields['car_name'] = $fields['car_name']."<br>".$fields['vin'];
|
|
|
|
if($size>1000){
|
|
$user_info = '';
|
|
if($bizs[$val['biz_id']]['type']==3){ //代理店显示渠道经理的姓名
|
|
$channel_users = $this->ci->app_licheb_channel_biz_model->select(['biz_id'=>$val['biz_id']],'','','','uid');
|
|
$user_ids = array_column($channel_users,'uid');
|
|
$user_ids_str = implode(',',$user_ids);
|
|
if($user_ids_str && $user_ids){
|
|
$where = [
|
|
'group_id' => 4,
|
|
'status' => 1,
|
|
"id in ($user_ids_str)" => null
|
|
];
|
|
$users = $this->ci->mdLichebUsers->select($where,'id desc',1,10,'uname,biz_id'); //渠道经理
|
|
$users && $user_info = implode(' ',array_column($users,'uname'));
|
|
}
|
|
$fields['admin_name'] = $user_info;
|
|
}
|
|
if(!$user_info){
|
|
$sale = $this->ci->mdLichebUsers->get(['id'=>$val['sale_id']],'uname');
|
|
$fields['admin_name'] = $sale['uname'];
|
|
}
|
|
$fields['address'] = $info_json['c_address'];
|
|
}
|
|
if(!$val['payway']){ //分期
|
|
$finance_row = $this->ci->sys_finance_model->get(['id' => $val['finance_id']], 'id,title');
|
|
$is_sure = $this->ci->receiver_order_status_model->count(['o_id'=>$val['id'],'pid_status'=>1,'status'=>2]);
|
|
$fields['pro_loan'] = $finance_row['title'];
|
|
$fields['price_loan'] = $money_json['price_loan'];
|
|
$fields['is_sure'] = $is_sure ? '是':'否';
|
|
}
|
|
$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:意向金订单
|
|
* @param array $params
|
|
* @return array
|
|
*/
|
|
private function inten_orders($params = array())
|
|
{
|
|
$page = $params['page'] = $params['page'] ? intval($params['page']) : 1;
|
|
$size = $params['size'] = $params['size'] ? intval($params['size']) : 20;
|
|
$status_arr = $this->ci->receiver_order_status_model->statusAry();
|
|
$view_type = 'orders';
|
|
$where = [
|
|
"status" => 0,
|
|
"id>=" => 10000,
|
|
"brand_id" => 0
|
|
];
|
|
$_title = '全部订单';
|
|
$view = 'receiver/orderv2/lists';
|
|
$params['status_pid'] == 1 && $where["payway"] = 0;
|
|
if (is_product()) {
|
|
$where["biz_id<>"] = 1;
|
|
}
|
|
if ($_SESSION['admin_info']['biz_id']) {
|
|
$biz_ids = implode(',', $_SESSION['admin_info']['biz_id']);
|
|
$where["biz_id in ($biz_ids)"] = null;
|
|
}
|
|
if ($params['biz_type']) {
|
|
$where["biz_id in (select id from lc_biz where type = " . $params['biz_type'] . ')'] = null;
|
|
}
|
|
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 ($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['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'];
|
|
}
|
|
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['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'] = '';
|
|
}
|
|
$where["id in(select o_id from lc_app_liche_orders where type=4 and status=1 and o_id>=10000)"] = null;
|
|
|
|
$fileds = "id,name,mobile,brand_id,s_id,v_id,
|
|
cor_id,incor_id,money_json,payway,status,c_time,
|
|
biz_id,bill_time,customer_id,owner_name,owner_mobile,main_type,info_json,
|
|
order_time,bill_time,item_id,over_time";
|
|
|
|
$count = $this->ci->mdOrders->count($where);
|
|
$rows = $this->ci->mdOrders->select($where, 'c_time desc', $page, $size, $fileds);
|
|
$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 = $this->ci->biz_model->map('id', 'biz_name', array("id in({$str_biz_ids})" => null));
|
|
foreach ($rows as $key => $val) {
|
|
$info_json = json_decode($val['info_json'], true);
|
|
$fields = array();
|
|
$fields['o_id'] = $val['id'];
|
|
if ($val['main_type']) {
|
|
$name = $info_json['c_company'];
|
|
$mobile = $val['mobile'];
|
|
} else {
|
|
$name = $val['owner_name'];
|
|
$mobile = $val['owner_mobile'];
|
|
}
|
|
$open_url = '/receiver/orderv2/orders/get?id=';
|
|
$fields['name'] = $size > 1000 ? $name
|
|
: '<a href="javascript:;" data-open="' . $open_url . $val['id'] . '">' . $name . '<br>' . $mobile . '</a>';
|
|
$fields['mobile'] = $mobile;
|
|
$fields['biz_name'] = $bizs[$val['biz_id']];
|
|
$fields['c_time'] = date('Y-m-d H:i:s', $val['c_time']);
|
|
$of_title = '-';
|
|
$of_id = $customers[$val['customer_id']]['of_id'];
|
|
if ($of_id) {
|
|
$of_ary = $offlineSources[$of_id];
|
|
$of_title = $of_ary['name'];
|
|
$of2_id = $customers[$val['customer_id']]['of2_id'];
|
|
$of2_id && $of_title .= '-' . $of_ary['list'][$of2_id];
|
|
}
|
|
$fields['of_title'] = $of_title;
|
|
$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' => '客户电话'];
|
|
} else {
|
|
$fields1['name'] = ['title' => '客户', 'width' => '14%'];
|
|
}
|
|
if (!strlen($status_pid)) {
|
|
$fields2 = [
|
|
'car_name' => ['title' => '车辆', 'width' => '27%'], 'biz_name' => ['title' => '门店', 'width' => '12%'],
|
|
'price' => ['title' => '最终售价', 'width' => '9%'],
|
|
// 'payway_name' => ['title' => '付款方式', 'width' => '8%'],
|
|
'of_title' => ['title' => '客户来源', 'width' => '10%'], 'status_name' => ['title' => '状态', 'width' => '9%'],
|
|
'c_time' => ['title' => '订单时间', 'width' => '9%'
|
|
]
|
|
];
|
|
} elseif ($status_pid == 3) {
|
|
$fields2 = [
|
|
'car_name' => ['title' => '车辆', 'width' => '27%'], 'biz_name' => ['title' => '门店', 'width' => '12%'],
|
|
'price' => ['title' => '最终售价', 'width' => '9%'],
|
|
// 'payway_name' => ['title' => '付款方式', 'width' => '8%'],
|
|
'of_title' => ['title' => '客户来源', 'width' => '10%'], 'status_name' => ['title' => '状态', 'width' => '9%'],
|
|
'bill_time' => ['title' => '开票时间', 'width' => '9%']
|
|
];
|
|
} else {
|
|
$fields2 = [
|
|
'car_name' => ['title' => '车辆', 'width' => '27%'], 'biz_name' => ['title' => '门店', 'width' => '12%'],
|
|
'price' => ['title' => '最终售价', 'width' => '9%'],
|
|
// 'payway_name' => ['title' => '付款方式', 'width' => '8%'],
|
|
'of_title' => ['title' => '客户来源', 'width' => '10%'], 'status_name' => ['title' => '状态', 'width' => '9%'],
|
|
'order_time' => ['title' => '下定时间', 'width' => '9%'],'over_time' => ['title' => '交付截止', 'width' => '9%']
|
|
];
|
|
if($status_pid==21){
|
|
unset($fields2['over_time']);
|
|
$fields2['refund_time'] = ['title' => '退款时间', 'width' => '9%'];
|
|
}
|
|
}
|
|
$fields = array_merge($fields1, $fields2);
|
|
if ($export) {
|
|
unset($fields['price'],$fields['c_time']);
|
|
$fields['payway_name'] = ['title'=>'付款方式'];
|
|
$fields['pro_loan'] = ['title'=>'金融机构'];
|
|
$fields['price_loan'] = ['title'=>'贷款金额'];
|
|
$fields['is_sure'] = ['title'=>'确认到款(是/否)'];
|
|
$fields['price_car'] = ['title'=>'最终售价'];
|
|
$fields['city_name'] = ['title'=>'城市'];
|
|
$fields['biz_type'] = ['title'=>'门店类型'];
|
|
$fields['vin'] = ['title' => 'vin码'];
|
|
$fields['over_time'] = ['title' => '止交付时间'];
|
|
$fields['order_time'] = ['title' => '下定时间'];
|
|
$fields['bill_time'] = ['title' => '开票时间'];
|
|
$fields['id_card'] = ['title' => '身份证'];
|
|
$fields['admin_name'] = ['title' => '销售人员'];
|
|
$fields['address'] = ['title' => '联系人地址'];
|
|
}
|
|
return $fields;
|
|
}
|
|
}
|
|
|
|
?>
|