From 3997c4292610a128c47e4f34e51e15cbe7ffd6d8 Mon Sep 17 00:00:00 2001 From: lin fan Date: Thu, 21 Nov 2024 11:16:45 +0800 Subject: [PATCH] 1 --- admin/controllers/autohome/Customer.php | 423 +++++++++++++++ admin/controllers/receiver/Clues.php | 3 - admin/views/autohome/lists.php | 492 ++++++++++++++++++ admin/views/receiver/customer/lists.php | 10 +- api/controllers/wxapp/app/City.php | 4 +- api/controllers/wxapp/licheb/Statistics.php | 8 +- .../autohome/Autohome_customer_model.php | 14 + www/admin/temp/ahclues.xlsx | Bin 0 -> 9642 bytes 8 files changed, 941 insertions(+), 13 deletions(-) create mode 100644 admin/controllers/autohome/Customer.php create mode 100644 admin/views/autohome/lists.php create mode 100644 common/models/autohome/Autohome_customer_model.php create mode 100644 www/admin/temp/ahclues.xlsx diff --git a/admin/controllers/autohome/Customer.php b/admin/controllers/autohome/Customer.php new file mode 100644 index 00000000..8f05fb4e --- /dev/null +++ b/admin/controllers/autohome/Customer.php @@ -0,0 +1,423 @@ + '空间站', 2 => '车卖场']; + private $cfrom2 = [11 => '厦门', 12 => '海口', 13 => '长沙', 14 => '佛山', 15 => '贵阳']; + private $channel = [1 => '抖音直播', 2 => '其他']; + private $push_status = ['0' => '未上传', '-1' => '上传失败']; + private $dis_status = [0 => '未分发', 2 => '分发失败']; + + private $pushAppKey = '0d14a33984239fd744fa47719de5f916'; + private $keySupplyBusinessId = '67'; + private $keyOutsidePvareaidId = '303556333'; + private $keyExt5 = '10477'; + + public function __construct() + { + parent::__construct(); + + $this->load->model('autohome/autohome_customer_model'); + $this->load->model("area_model"); + $this->load->model("biz/biz_model"); + $this->load->model("auto/auto_brand_model"); + $this->load->model("auto/auto_series_model"); + + $this->load->helper('order'); + $this->load->library('mycurl'); + } + + public function index() + { + $params = $this->input->get(); + list($lists, $count) = $this->lists(); + + $this->data['province_id'] = intval($params['province_id']); + $this->data['city_id'] = intval($params['city_id']); + $this->data['provinces'] = $this->province_ary(); + $this->data['lists'] = $lists; + $this->data['params'] = $params; + $this->data['cfromAry'] = $this->cfrom; + $this->data['channelAry'] = $this->channel; + $this->data['export_button'] = SUPER_ADMIN == $this->role ? 1 : 0; + $this->data['_title'] = '线索列表'; + + return $this->show_view('autohome/lists', true); + } + + public function lists($push = false) + { + $params = $this->input->get(); + $where = []; + $page = $params['page'] = $params['page'] ? intval($params['page']) : 1; + $size = $params['size'] = $params['size'] ? intval($params['size']) : 20; + + if (strlen($params['push_id'])) { + switch ($params['push_id']){ + case '0': + $where["push_id"] = 0; + break; + case '-1': + $where["push_id"] = -1; + break; + default: + $where["push_id not in ('0', '-1')"] = null; + } + } + + if ($params['mobile']) { + $where["{$params['mobile']} like '{$params['mobile']}'"] = null; + } + //创建时间 + if ($params['c_time']) { + $c_time = explode(' ~ ', $params['c_time']); + if ($c_time[0]) { + $where["c_time >="] = $c_time[0] . ' 00:00:00'; + } + if ($c_time[1]) { + $where["c_time <="] = $c_time[1] . ' 23:59:59'; + } + } + //上传时间 + if ($params['p_time']) { + $p_time = explode(' ~ ', $params['p_time']); + if ($p_time[0]) { + $where["p_time >="] = $p_time[0] . ' 00:00:00'; + } + if ($p_time[1]) { + $where["p_time <="] = $p_time[1] . ' 23:59:59'; + } + } + + $province_id = intval($params['province_id']); + $city_id = intval($params['city_id']); + $province_id && $where['province_id'] = $province_id; + $city_id && $where['city_id'] = $city_id; + + $params['cfrom_id'] && $where['cfrom'] = $params['cfrom_id']; + $params['cfrom_id2'] && $where['cfrom2'] = $params['cfrom_id2']; + $params['brand_id'] && $where['brand_id'] = $params['brand_id']; + $params['series_id'] && $where['series_id'] = $params['series_id']; + + $count = $this->autohome_customer_model->count($where); + $lists = []; + if ($count) { + $rows = $this->autohome_customer_model->select($where, '', $page, $size); + $city_id_arr = array_filter(array_unique(array_column($rows, 'city_id'))); + if ($city_id_arr) { + $str_ids = implode(',', $city_id_arr); + $map_area_city = $this->area_model->map('city_id', '', ["city_id in ({$str_ids})" => null], '', 0, $size, 'city_id,province_name,city_name'); + } + + $brands = $this->auto_brand_model->get_map_by_ids(array_column($rows, 'brand_id')); + $series = $this->auto_series_model->get_map_by_ids(array_column($rows, 'series_id')); + $map_biz = $this->biz_model->map('biz_name', 'id', ['status' => 1, 'province_id' => 350000], '', 0, 0, 'id,biz_name'); + + foreach ($rows as $val){ + $area = $map_area_city[$val['city_id']][0]; + $val['area_title'] = "{$area['province_name']}-{$area['city_name']}"; + $val['car_title'] = $brands[$val['brand_id']][0]['name']." ".$series[$val['series_id']][0]['name']; + + if($val['cfrom'] == 1){ + $cf2 = $this->cfrom2[$val['cfrom2']]; + }else{ + $cf2 = $map_biz[$val['cfrom2']]; + } + $val['cf_title'] = $this->cfrom[$val['cfrom']]." ".$cf2; + $val['channel'] = $this->channel[$val['channel']]; + $val['push_status'] = $this->push_status[$val['push_id']] ? $this->push_status[$val['push_id']] : '上传成功'; + $val['dis_status'] = $this->dis_status[$val['dis_status']]; + } + $lists[] = $val; + } + + $this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count); + return [$lists, $count]; + } + + public function get() + { + $id = intval($this->input->get('id')); + $info = ['province_id' => 0]; + if ($id) { + $info = $this->item_model->get(['id' => $id]); + $info['src_img'] = build_qiniu_image_url($info['img']); + } + $this->data['provinces'] = $this->province_ary(); + $this->data['info'] = $info; + $this->data['_title'] = $id ? '编辑' : '新增'; + return $this->show_view('/receiver/items/edit', true); + } + + public function add() + { + $info = $this->input->post(); + $data = [ + 'title' => $info['title'], + 's_time' => $info['s_time'], + 'e_time' => $info['e_time'], + 'img' => $info['img'], + 'province_id' => $info['province_id'], + 'descrip' => $info['descrip'], + ]; + $res = $this->item_model->add($data); + if (!$res) { + return $this->show_json(SYS_CODE_FAIL, '保存失败'); + } + return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); + } + + //编辑单条数据 + public function edit() + { + $info = $this->input->post(); + $row = $this->item_model->get(['id' => $info['id']]); + if (!$row) return $this->show_json(SYS_CODE_FAIL, '数据不存在'); + $up_data = [ + 'title' => $info['title'], + 's_time' => $info['s_time'], + 'e_time' => $info['e_time'], + 'img' => $info['img'], + 'province_id' => $info['province_id'], + 'descrip' => $info['descrip'], + ]; + $res = $this->item_model->update($up_data, ['id' => $info['id']]); + if (!$res) { + return $this->show_json(SYS_CODE_FAIL, '保存失败'); + } + return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); + } + + public function del() + { + + } + + public function batch() + { + + } + + function add_excel() + { + require_once COMMPATH . '/third_party/PHPExcel/IOFactory.php'; + $res = $this->upload(); + if (!$res['code']) { + return $this->show_json(0, $res['message']); + } + $file = $res['path']; + if ($res['file_ext'] == '.xls') { + $reader = \PHPExcel_IOFactory::createReader('Excel5'); // 读取 excel 文档 + } elseif ($res['file_ext'] == '.xlsx') { + $reader = \PHPExcel_IOFactory::createReader('Excel2007'); // 读取 excel 文档 + } else { + return $this->show_json(SYS_CODE_FAIL, '文件无法识别'); + } + $PHPExcel = $reader->load($file); // 文档名称 + $objWorksheet = $PHPExcel->getActiveSheet(); + $rowCnt = $objWorksheet->getHighestRow(); //获取总行数 + if ($rowCnt > 800) { + @unlink($file); + return $this->show_json(0, '数据大于800请拆分多个表格导入'); + } + $data = array(); + for ($_row = 2; $_row <= $rowCnt; $_row++) { //读取内容 + $data[] = array( + 'name' => $objWorksheet->getCell('A' . $_row)->getValue(), + 'mobile' => $objWorksheet->getCell('B' . $_row)->getValue(), + 'cfrom1' => $objWorksheet->getCell('C' . $_row)->getValue(), + 'cfrom2' => $objWorksheet->getCell('D' . $_row)->getValue(), + 'channel' => $objWorksheet->getCell('E' . $_row)->getValue(), + 'province_name' => $objWorksheet->getCell('F' . $_row)->getValue(), + 'city_name' => $objWorksheet->getCell('G' . $_row)->getValue(), + 'brand_id' => $objWorksheet->getCell('H' . $_row)->getValue(), + 'series_id' => $objWorksheet->getCell('I' . $_row)->getValue(), + ); + } + $done = $this->add_batch($data); + @unlink($file); + $this->data['load_num'] = count($data); + $this->data['done'] = $done; + return $this->show_json(SYS_CODE_SUCCESS, "成功导入{$done}条"); + } + + public function add_batch($lists=array()) + { + $done = 0; + $adds = $map_province = $map_city = $map_county = $map_biz = []; + $cfrom_f = array_flip($this->cfrom); + $cfrom2_f = array_flip($this->cfrom2); + $map_biz = $this->biz_model->map('biz_name', 'id', ['status' => 1, 'province_id' => 350000], '', 0, 0, 'id,biz_name'); + $province_strings = implode("','", array_unique(array_column($lists, 'province_name'))); + if ($province_strings) $where = ["province_name in ('{$province_strings}')" => null]; + $province_strings && $map_province = $this->area_model->map('province_name', 'province_id', $where, '', 0, 0, 'DISTINCT(province_id),province_name'); + $city_strings = implode("','", array_unique(array_column($lists, 'city_name'))); + if ($city_strings) $where = ["city_name in ('{$city_strings}')" => null]; + $city_strings && $map_city = $this->area_model->map('city_name', 'city_id', $where, '', 0, 0, 'DISTINCT(city_id),city_name'); + $fails = array(); + + foreach ($lists as $k => $v) { + if (!$v['name']) { + $fails[] = array('data' => $v, 'msg' => 'name is null'); + continue; + } + if (!mobile_valid($v['mobile'])) { + $fails[] = array('data' => $v, 'msg' => 'mobile valid fail'); + continue; + } + if ($this->autohome_customer_model->count(['mobile' => $v['mobile']])) { + $fails[] = array('data' => $v, 'msg' => 'mobile duplicate'); + continue; + } + + $cf_id = $cfrom_f[$v['cfrom1']]; + if($cf_id == 1){ + $cf2_id = $cfrom2_f[$v['cfrom2']]; + }else{ + $cf2_id = $map_biz[$v['cfrom2']]; + } + + $temp = array( + 'name' => $v['name'], + 'mobile' => $v['mobile'], + 'cfrom' => $cf_id ? $cf_id : 0, + 'cfrom2' => $cf2_id ? $cf2_id : 0, + 'channel' => $v['channel'] ? $v['channel'] : '', + 'brand_id' => $v['brand_id'] ? $v['brand_id'] : '', + 'series_id' => $v['series_id'] ? $v['series_id'] : '', + 'province_id' => $map_province[$v['province_name']] ? $map_province[$v['province_name']] : 0, + 'city_id' => $map_city[$v['city_name']] ? $map_city[$v['city_name']] : 0, + 'c_time' => date('Y-m-d H:i:s'), + ); + $adds[] = $temp; + $done++; + } + $fails && debug_log('[warning]# fails=' . json_encode($fails), __FUNCTION__, $this->log_dir); + if ($adds) { + $ret = $this->autohome_customer_model->add_batch($adds); + if (!$ret) { + debug_log("[error] add_batch fail; " . $this->autohome_customer_model->db->last_query(), __FUNCTION__, $this->log_dir); + $done = 0; + } + } + + return $done; + } + + private function upload() + { + $config['upload_path'] = $_SERVER['DOCUMENT_ROOT'] . '/temp/'; + $config['allowed_types'] = 'xls|xlsx'; + $config['max_size'] = 5120; + $config['file_name'] = 'receiver_clues' . time() . rand(1, 99999); + $this->load->library('upload', $config); + if (!$this->upload->do_upload('file')) { + return array('code' => SYS_CODE_FAIL, 'message' => $this->upload->display_errors('', '')); + } else { + $data = $this->upload->data(); + return array('code' => SYS_CODE_SUCCESS, 'path' => $data['full_path'], 'file_ext' => $data['file_ext']); + } + } + + public function export() + { + + } + + function json_map_cfrom() + { + $pid = $this->input->post('pid'); + $map_biz = $this->biz_model->map('biz_name', 'id', ['status' => 1, 'province_id' => 350000, 'type' => 0], '', 0, 0, 'id,biz_name'); + + if($pid == 1){ + $this->data = $this->cfrom2; + }else{ + $this->data = array_flip($map_biz); + } + + return $this->show_json(SYS_CODE_SUCCESS); + } + + public function push_search(){ + $url = 'https://autoapi.autohome.com.cn/ggxt/xsyw/api/clues/push'; + list($lists, $count) = $this->lists(1); + $succ = $fail = $undo = 0; + + if($lists){ + foreach ($lists as $v){ + if($v['push_id']){ + $undo++; + continue; + } + + $flowOrderNo = addslashes(json_encode(array('flowOrderNo' => create_customer_no()))); + + $push_data = array( + 'pushAppKey' => $this->pushAppKey, + 'keySupplyBusinessId' => $this->keySupplyBusinessId, + 'keyOutsidePvareaidId' => $this->keyOutsidePvareaidId, + 'keyExt5' => $this->keyExt5, + 'keyExt12' => $flowOrderNo, + 'splitCode' => '123', + 'keyPrivateFlag' => '0', + 'keyTypeId' => '2', + 'keyOrderTime' => $v['c_time'], + 'keyOrderCityId' => $v['city_id'] ? $v['city_id'] : '110100', + 'keyName' => '客户'.$v['id'], + 'keyPhone' => $v['mobile'], + 'keyPurposeBrandId' => $v['brand_id'] ? $v['brand_id'] : null, + 'keyPurposeFactoryId' => null, + 'keyCarAudiId' => $v['series_id'] ? $v['series_id'] : null, + 'keyCarTypeId' => null, + 'keyCardCityId' => $v['city_id'] ? $v['city_id'] : '110100', + ); + + $res = $this->mycurl->httpPost($url, $push_data, 'is_json'); + + if($res){ + $res = json_decode($res, true); + if(!$res['status']){ + $up = array( + 'push_json' => json_encode($push_data), + 'push_id' => $res['result']['pushId'], + 'p_time' => date('Y-m-d H:i:s'), + ); + $succ++; + }else{ + $push_data['res'] = $res; + $up = array( + 'push_json' => json_encode($push_data), + 'push_id' => -1, + 'p_time' => date('Y-m-d H:i:s'), + ); + $fail++; + } + + $this->autohome_customer_model->update($up, array('id' => $v['id'])); + } + } + + $this->data['succ'] = $succ; + $this->data['fail'] = $fail; + $this->data['undo'] = $undo; + return $this->show_json(SYS_CODE_SUCCESS); + } + } + + public function get_dis_status(){ + $url = 'https://autoapi.autohome.com.cn/pj-clues-handler/api/queryCluesInfo'; + + $push_data = array( + 'appKey' => $this->pushAppKey, + 'keySupplyBusinessId' => $this->keySupplyBusinessId, + 'pushIds' => '1725586964500443136', + ); + + $res = $this->mycurl->httpPost($url, $push_data, 'is_json'); + if($res){ + print_r($res); + } + } +} \ No newline at end of file diff --git a/admin/controllers/receiver/Clues.php b/admin/controllers/receiver/Clues.php index bba2ef0f..942044f9 100644 --- a/admin/controllers/receiver/Clues.php +++ b/admin/controllers/receiver/Clues.php @@ -782,9 +782,6 @@ class Clues extends HD_Controller ]; $city_id && $where['city_id'] = $city_id; $county_id && $where['county_id'] = $county_id; - $typeAry = $this->biz_model->type_ary(); - $type_ids = implode(',', array_keys($typeAry)); - $type_ids && $where["type in ($type_ids)"] = null; $bizList = $this->biz_model->select($where, '', '', '', 'id,biz_name'); $this->data['bizList'] = $bizList; return $this->show_json(SYS_CODE_SUCCESS, '操作成功'); diff --git a/admin/views/autohome/lists.php b/admin/views/autohome/lists.php new file mode 100644 index 00000000..3395e9e5 --- /dev/null +++ b/admin/views/autohome/lists.php @@ -0,0 +1,492 @@ + +
+
+
+ +
+
+ + +
+
共有条数据
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
客户所属地区品牌车型线索来源线索渠道上传状态分发状态上传时间

+
+
+
+
+
+ +
+
+ + + + diff --git a/admin/views/receiver/customer/lists.php b/admin/views/receiver/customer/lists.php index 26c4c6a1..ed5478e6 100644 --- a/admin/views/receiver/customer/lists.php +++ b/admin/views/receiver/customer/lists.php @@ -33,7 +33,15 @@
- +