From 6cd89f8b32034465fd34e6899ee5127f62acdf98 Mon Sep 17 00:00:00 2001 From: qianhy Date: Thu, 22 Dec 2022 09:22:50 +0800 Subject: [PATCH] customer add export, orders adjust_fee fixbug --- admin/controllers/receiver/Customer.php | 182 ++++++++++++------ admin/controllers/receiver/orderv2/Orders.php | 22 +-- admin/views/receiver/customer/lists.php | 22 ++- 3 files changed, 150 insertions(+), 76 deletions(-) diff --git a/admin/controllers/receiver/Customer.php b/admin/controllers/receiver/Customer.php index 527050b8..cac1e7db 100644 --- a/admin/controllers/receiver/Customer.php +++ b/admin/controllers/receiver/Customer.php @@ -41,7 +41,71 @@ class Customer extends HD_Controller { $status_arr = $this->customers_model->get_status(); unset($status_arr['-1']); + $params = $this->input->get(); + $page = $params['page'] = $params['page'] ? intval($params['page']) : 1; + $size = $params['size'] = $params['size'] ? intval($params['size']) : 20; + $where = $this->get_where($params); + $count = $this->customers_model->count($where); + $lists = []; + $offlineSources = $this->customers_model->offlineSources(); + $wxqyAry = $this->customers_model->wxqyAry(); + if ($count) { + $fileds = 'id,name,mobile,cf_title,cont_time,admin_id,status,biz_id,level,of_id,of2_id,wxqy'; + $rows = $this->customers_model->select($where, 'id desc', $page, $size, $fileds); + //获取销售员 + $admin_id_arr = array_unique(array_column($rows, 'admin_id')); + $admin_id_arr && $admin_rows = $this->app_licheb_users_model->get_map_by_ids($admin_id_arr, 'id,uname'); + //获取门店 + $biz_id_arr = array_unique(array_column($rows, 'biz_id')); + $biz_id_arr && $biz_rows = $this->biz_model->get_map_by_ids($biz_id_arr, 'id,biz_name'); + foreach ($rows as $key => $val) { + if (SUPER_ADMIN == $this->role || $this->role == 35) { + $mobile_sub = $val['mobile']; + } else { + $mobile_sub = $val['mobile'] ? substr_replace($val['mobile'], '*****', 0, 5) : ''; + } + $of_title = ''; + if ($val['of_id']) { + $of_ary = $offlineSources[$val['of_id']]; + $of_title = $of_ary['name']; + $val['of2_id'] && $of_title .= '-' . $of_ary['list'][$val['of2_id']]; + } + $lists[] = array( + 'id' => $val['id'], + 'name' => $val['name'], + 'mobile' => $val['mobile'], + 'mobile_sub' => $mobile_sub, + 'level' => $val['level'], + 'of_title' => $of_title, + 'of2_id' => $val['of2_id'], + 'status_name' => $status_arr[$val['status']], + 'wxqy_name' => $wxqyAry[$val['wxqy']], + 'admin_name' => isset($admin_rows[$val['admin_id']]) ? $admin_rows[$val['admin_id']][0]['uname'] : '', + 'biz_name' => isset($biz_rows[$val['biz_id']]) ? $biz_rows[$val['biz_id']][0]['biz_name'] : '', + 'cont_time' => $val['cont_time'] != '0000-00-00 00:00:00' ? $val['cont_time'] : '', + ); + } + } + //渠道经理 + $qdjl_lists = $this->app_licheb_users_model->select(array('group_id' => 4, 'status' => 1, 'biz_id<>' => '0'), 'id desc', 0, 0, 'id,uname as name'); + $show_info['levelAry'] = $this->customers_model->get_sdata('level'); + $show_info['offlineSourcesAry'] = $offlineSources; + $show_info['wxqyAry'] = $wxqyAry; + $this->data['show_info'] = $show_info; + $this->data['lists'] = $lists; + $this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count); + $this->data['searchTpAry'] = $this->searchTpAry; + $this->data['searchTimeAry'] = $this->searchTimeAry; + $this->data['params'] = $params; + $this->data['status_arr'] = $status_arr; + $this->data['qdjl_lists'] = $qdjl_lists; + $this->data['export_button'] = $this->uid == 1 ? 1 : 0; + $this->data['_title'] = '客户列表'; + return $this->show_view('receiver/customer/lists', true); + } + + private function get_where(&$params){ !$params['biz_id'] && $params['biz_id'] = ''; !$params['cf_title'] && $params['cf_title'] = ''; !$params['qdjl_id'] && $params['qdjl_id'] = ''; @@ -49,8 +113,6 @@ class Customer extends HD_Controller !$params['of_id'] && $params['of_id'] = ''; !$params['of2_id'] && $params['of2_id'] = ''; !$params['biz_type'] && $params['biz_type'] = ''; - $page = $params['page'] = $params['page'] ? intval($params['page']) : 1; - $size = $params['size'] = $params['size'] ? intval($params['size']) : 20; $where = array('status>=0' => null); if ($_SESSION['admin_info']['biz_id']) { $biz_ids = implode(',', $_SESSION['admin_info']['biz_id']); @@ -148,62 +210,7 @@ class Customer extends HD_Controller } } } - $count = $this->customers_model->count($where); - $lists = []; - $offlineSources = $this->customers_model->offlineSources(); - $wxqyAry = $this->customers_model->wxqyAry(); - if ($count) { - $fileds = 'id,name,mobile,cf_title,cont_time,admin_id,status,biz_id,level,of_id,of2_id,wxqy'; - $rows = $this->customers_model->select($where, 'id desc', $page, $size, $fileds); - //获取销售员 - $admin_id_arr = array_unique(array_column($rows, 'admin_id')); - $admin_id_arr && $admin_rows = $this->app_licheb_users_model->get_map_by_ids($admin_id_arr, 'id,uname'); - //获取门店 - $biz_id_arr = array_unique(array_column($rows, 'biz_id')); - $biz_id_arr && $biz_rows = $this->biz_model->get_map_by_ids($biz_id_arr, 'id,biz_name'); - foreach ($rows as $key => $val) { - if (SUPER_ADMIN == $this->role || $this->role == 35) { - $mobile_sub = $val['mobile']; - } else { - $mobile_sub = $val['mobile'] ? substr_replace($val['mobile'], '*****', 0, 5) : ''; - } - $of_title = ''; - if ($val['of_id']) { - $of_ary = $offlineSources[$val['of_id']]; - $of_title = $of_ary['name']; - $val['of2_id'] && $of_title .= '-' . $of_ary['list'][$val['of2_id']]; - } - $lists[] = array( - 'id' => $val['id'], - 'name' => $val['name'], - 'mobile' => $val['mobile'], - 'mobile_sub' => $mobile_sub, - 'level' => $val['level'], - 'of_title' => $of_title, - 'of2_id' => $val['of2_id'], - 'status_name' => $status_arr[$val['status']], - 'wxqy_name' => $wxqyAry[$val['wxqy']], - 'admin_name' => isset($admin_rows[$val['admin_id']]) ? $admin_rows[$val['admin_id']][0]['uname'] : '', - 'biz_name' => isset($biz_rows[$val['biz_id']]) ? $biz_rows[$val['biz_id']][0]['biz_name'] : '', - 'cont_time' => $val['cont_time'] != '0000-00-00 00:00:00' ? $val['cont_time'] : '', - ); - } - } - //渠道经理 - $qdjl_lists = $this->app_licheb_users_model->select(array('group_id' => 4, 'status' => 1, 'biz_id<>' => '0'), 'id desc', 0, 0, 'id,uname as name'); - $show_info['levelAry'] = $this->customers_model->get_sdata('level'); - $show_info['offlineSourcesAry'] = $offlineSources; - $show_info['wxqyAry'] = $wxqyAry; - $this->data['show_info'] = $show_info; - $this->data['lists'] = $lists; - $this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count); - $this->data['searchTpAry'] = $this->searchTpAry; - $this->data['searchTimeAry'] = $this->searchTimeAry; - $this->data['params'] = $params; - $this->data['status_arr'] = $status_arr; - $this->data['qdjl_lists'] = $qdjl_lists; - $this->data['_title'] = '客户列表'; - return $this->show_view('receiver/customer/lists', true); + return $where; } public function get() @@ -507,7 +514,64 @@ class Customer extends HD_Controller public function export() { - // TODO: Implement export() method. + if ($this->uid != 1){ + return $this->show_json(SYS_CODE_FAIL, '无权限导出'); + } + + $params = $this->input->get(); + $where = $this->get_where($params); + $where["cs_biz_id >= 0"] = null; + $page = 1; + $size = 10000; + + $count = $this->customers_model->count($where); + $data = []; + $offlineSources = $this->customers_model->offlineSources(); + $status_arr = $this->customers_model->get_status(); + unset($status_arr['-1']); + if ($count) { + $fileds = "id, name, mobile, level, status, FROM_UNIXTIME(c_time) as c_time, if(dt_time>0, dt_time,'') as dt_time, if(order_time>0, order_time,'') as order_time, if(cont_time>0, cont_time,'') as cont_time, cf_title, cf_id, of_id, of2_id, (SELECT biz_name FROM `lc_biz` where id = `lc_receiver_customers`.biz_id) as biz_name, (SELECT uname FROM `lc_app_licheb_users` where id = `lc_receiver_customers`.admin_id) as admin_name, biz_id, admin_id"; + $rows = $this->customers_model->select($where, 'id desc', $page, $size, $fileds); + foreach ($rows as $key => $val) { + $of_title = ''; + if ($val['of_id']) { + $of_ary = $offlineSources[$val['of_id']]; + $of_title = $of_ary['name']; + $val['of2_id'] && $of_title .= '-' . $of_ary['list'][$val['of2_id']]; + } + $data[] = array( + 'id' => 'ID', + 'name' => $val['name'], + 'mobile' => $val['mobile'], + 'level' => $val['level'], + 'status_name' => $status_arr[$val['status']], + 'c_time' => $val['c_time'], + 'dt_time' => $val['dt_time'], + 'order_time' => $val['order_time'], + 'cont_time' => $val['cont_time'], + 'of_title' => $of_title, + 'biz_name' => $val['biz_name'], + 'admin_name' => $val['admin_name'], + ); + } + } + $indexs = [ + 'name' => '客户姓名', + 'mobile' => '手机', + 'level' => '客户等级', + 'status_name' => '客户类型', + 'c_time' => '建档时间', + "dt_time" => "到店时间", + "order_time" => "下单时间", + "cont_time" => "最后联系时间", + "of_title" => "来源", + "biz_name" => "归属门店", + "admin_name" => "归属顾问", + ]; + $fileName = '客户列表'; + array_unshift($data, $indexs); + $this->load->library('excel'); + $this->excel->out_csv($data, $indexs, $fileName . "_" . date('YmdHis')); } //改派 diff --git a/admin/controllers/receiver/orderv2/Orders.php b/admin/controllers/receiver/orderv2/Orders.php index db3a7805..53be92bd 100644 --- a/admin/controllers/receiver/orderv2/Orders.php +++ b/admin/controllers/receiver/orderv2/Orders.php @@ -1302,33 +1302,23 @@ class Orders extends HD_Controller ]; $sum = $this->app_liche_orders_model->sum('total_price', $where); //已收金额 $total_price = $sum['total_price']; - /*$need_price = $this->orders_v2_entity->recevable_price($id); //应收金额 - if ($total_price >= $need_price) { - //- 已收总额 >= 应收总额:如“已配车”,调整为“待开票” - $bill_status = $this->receiver_order_status_model->get(['o_id'=>$id,'pid_status'=>3,'status'=>1]); //是否已开票 - $bill_status && $this->receiver_order_status_model->delete(['o_id'=>$id,'pid_status'=>3,'status'=>1]); - } - else{ - //- 已收总额 < 应收总额:如“待开票”,调整为“已配车” - $bill_status = $this->receiver_order_status_model->get(['o_id'=>$id,'pid_status'=>3,'status'=>0]); //是否待开票 - $bill_status && $this->receiver_order_status_model->delete(['o_id'=>$id,'pid_status'=>3,'status'=>0]); - }*/ - - //是否已付款 - if ($total_price > 0){ + $need_price = $this->orders_v2_entity->recevable_price($id); //应收金额 + if ($total_price >= $need_price){ $this->orders_status_entity->set_status($id,0,2); } else{ $fee_status = $this->receiver_order_status_model->get(['o_id'=>$id,'pid_status'=>0,'status'=>2]); //是否已付款 $fee_status && $this->receiver_order_status_model->delete(['o_id'=>$id,'pid_status'=>0,'status'=>2]); + //$bill_status = $this->receiver_order_status_model->get(['o_id'=>$id,'pid_status'=>3,'status'=>1]); //是否已开票 + //$bill_status && $this->receiver_order_status_model->delete(['o_id'=>$id,'pid_status'=>3,'status'=>1]); } //是否已配车 - $car_status = $this->receiver_order_status_model->get(['o_id'=>$id,'pid_status'=>2,'status'=>1]); + /*$car_status = $this->receiver_order_status_model->get(['o_id'=>$id,'pid_status'=>2,'status'=>1]); if (!$car_status){ $row = $this->receiver_orders_v2_model->get(['id'=>$id]); $row && $row['item_id'] && $this->orders_status_entity->set_status($id,2,1); - } + }*/ } public function edit_price(){ diff --git a/admin/views/receiver/customer/lists.php b/admin/views/receiver/customer/lists.php index 900ceeb6..06e7c06c 100644 --- a/admin/views/receiver/customer/lists.php +++ b/admin/views/receiver/customer/lists.php @@ -149,6 +149,9 @@
+
+ +
@@ -283,6 +286,7 @@ show_info: {levelAry: [], offlineSourcesAry: [], wxqyAry: []}, of2Ary: [], bizTypeAry: [], + export_button: 0, }, mounted: function () { var vm = this; @@ -291,6 +295,7 @@ vm.lists = ; vm.qdjl_lists = ; vm.show_info = ; + vm.export_button = ; vm.init_citys(); vm.initBizType(); }, @@ -378,7 +383,22 @@ $('#show-' + id).hide(); }); $("#times_checkbox").prop("checked", false); - } + }, + export_out: function () { + var that = this; + if (that.export_button == 0){ + layer.msg('无权限导出'); + return false; + } + let count = ; + if (count == 0) { + layer.msg('没有数据可导出'); + return false; + } + let href = $.menu.parseUri(window.location.href); + href = href.replace("customer?", "customer/export?"); + window.location.href = href; + }, }, watch: { 'params.of_id': function (nv, ov) {