From 52a6d2880dec85e244710a847e0f79530b28e186 Mon Sep 17 00:00:00 2001 From: lccsw <1127794702@qq.com> Date: Tue, 12 Oct 2021 10:10:31 +0800 Subject: [PATCH] add-api-create_clues --- admin/controllers/receiver/Customer.php | 32 -- api/controllers/wxapp/distribution/Home.php | 1 + api/controllers/wxapp/liche/Aptinfo.php | 2 +- api/controllers/wxapp/liche/Clues.php | 402 +++++++++--------- api/controllers/wxapp/liche/Statistics.php | 13 + api/controllers/wxapp/licheb/Cusorder.php | 1 + .../models/receiver/Receiver_clues_model.php | 30 ++ sql/receiver/order.sql | 1 + 8 files changed, 237 insertions(+), 245 deletions(-) diff --git a/admin/controllers/receiver/Customer.php b/admin/controllers/receiver/Customer.php index 1b16531f..1e971a35 100644 --- a/admin/controllers/receiver/Customer.php +++ b/admin/controllers/receiver/Customer.php @@ -426,37 +426,5 @@ class Customer extends HD_Controller return $id; } - //更新晓致电话数据 - public function get_update_xz() - { - $page = $this->input->get('page'); - $size = $this->input->get('size'); - $lk = $this->input->get('lk'); - !$page && $page = 1; - !$size && $size = 10; - $where = [ - 'cf_title' => 'customer', - 'cf_platform' => 'api', - 'status' => 1 - ]; - if ($lk) { - $rows = $this->receiver_xz_model->select($where, 'id desc', $page, $size, 'id,biz_id'); - print_r($rows); - exit; - } - $total = $this->receiver_xz_model->count($where); - $rows = $this->receiver_xz_model->select($where, 'id desc', $page, $size, 'id,cf_id'); - if ($rows) { - foreach ($rows as $key => $val) { - $row = $this->customers_model->get(['id' => $val['cf_id']], 'biz_id'); - if ($row) { - $this->receiver_xz_model->update(['biz_id' => $row['biz_id']], ['id' => $val['id']]); - } - } - echo "total:{$total},剩余:" . ($total - $page * $size); - } else { - echo "finish"; - } - } } diff --git a/api/controllers/wxapp/distribution/Home.php b/api/controllers/wxapp/distribution/Home.php index c818df0c..2687e16d 100644 --- a/api/controllers/wxapp/distribution/Home.php +++ b/api/controllers/wxapp/distribution/Home.php @@ -66,6 +66,7 @@ class Home extends Wxapp !$this->session['up_uid'] && $this->session['dealer'] && $menulist[] = ['title' => '我的团队', 'url' => '/pages/distribute/team/index', 'img' => $img_url . '/distribute/icon-tuandui.png']; } $this->session['manage'] && $menulist[] = ['title' => '分销管理', 'url' => '/pages/distribute/apply/index', 'img' => $img_url . '/distribute/icon-shenqing.png']; + $menulist[] = ['title' => '报备线索', 'url' => '/pages/distribute/clue/index', 'img' => $img_url . '/distribute/icon-sucai.png']; $menulist[] = ['title' => '联系小狸', 'url' => '', 'img' => $img_url . '/distribute/icon-kefu.png']; $data = array( "title" => '分销', diff --git a/api/controllers/wxapp/liche/Aptinfo.php b/api/controllers/wxapp/liche/Aptinfo.php index c476c010..54495c82 100644 --- a/api/controllers/wxapp/liche/Aptinfo.php +++ b/api/controllers/wxapp/liche/Aptinfo.php @@ -131,8 +131,8 @@ class Aptinfo extends Wxapp{ $cms_json = json_decode($cms_row['jsondata'],true); $cms_json['cfrom_id'] && $cf_id = $cms_json['cfrom_id']; $brand_row = $this->auto_brand_model->get(['id'=>$cms_row['target_id']]); + $recommend_id && $cf_id = 8; } - //$row = $this->clues_model->get(['cf_id'=>$cf_id,'cf_uid'=>$uid,'app_id'=>$this->app_id,'status'=>0]); $row = $this->clues_model->get(['mobile'=>$this->session['mobile'],'app_id'=>$this->app_id]); if($row){ $update = [ diff --git a/api/controllers/wxapp/liche/Clues.php b/api/controllers/wxapp/liche/Clues.php index 08cad53d..7e2d05dd 100644 --- a/api/controllers/wxapp/liche/Clues.php +++ b/api/controllers/wxapp/liche/Clues.php @@ -17,236 +17,214 @@ class Clues extends Wxapp{ $this->check_status = array();//用户状态校验 $this->check_mobile = array();//需要手机号 $this->check_headimg =array();//授权微信信息 + $this->load->model('receiver/receiver_clues_model'); + $this->load->model('receiver/receiver_clue_oplogs_model'); + $this->load->model('receiver/order/receiver_orders_model'); + $this->load->model('auto/auto_brand_model'); } protected function get(){ $id = $this->input_param('id'); - $type = $this->input_param('type'); - !strlen($type) && $type = 0; - - $row = $this->orders_model->get(['id'=>$id,'mobile'=>$this->session['mobile']]); - $type_arr = $this->contracts_model->get_types(); - if(!$row || !$type_arr[$type]){ - throw new Exception('参数错误', API_CODE_INVILD_PARAM); - } - $contract = $this->contracts_model->get(['type'=>$type,'o_id'=>$id]); - - $this->load->library('receiver/orders_entity'); - $this->load->library('pdf'); - - list($h5_url,$title) = $this->orders_entity->get_contract_h5($id,$type,1); - list($pdf2img_url,$title) = $this->orders_entity->get_contract_h5($id,$type); - if(!$contract){ - $add_data = [ - 'o_id' => $id, - 'type' => $type, - 'c_time' => time() - ]; - $con_id = $this->contracts_model->add($add_data); - if(!$con_id){ - throw new Exception('创建合同失败', API_CODE_INVILD_PARAM); - } - $cid = create_contract_no(350200,$con_id,$type); - $this->contracts_model->update(['cid'=>$cid],['id'=>$con_id]); - //html转pdf - $save_path = 'data/contracts/'.date('Ymd'); - $filename = $cid.'.pdf'; - $c_res = $this->pdf->html2pdf($pdf2img_url,FCPATH.$save_path,$filename); - $update = [ - 'file' => $save_path.'/'.$filename, - 'cid' => $cid - ]; - $this->contracts_model->update($update,['id'=>$con_id]); + if($id){ + return $this->detail($id); }else{ - if(!$contract['status'] && date('Ymd')!=date('Ymd',$contract['c_time'])){ //更新合同文件日期 - //html转pdf - @unlink(FCPATH.$contract['file']); - $save_path = 'data/contracts/'.date('Ymd'); - $filename = $contract['cid'].'.pdf'; - $c_res = $this->pdf->html2pdf($h5_url,FCPATH.$save_path,$filename); - $update = [ - 'file' => $save_path.'/'.$filename, - 'c_time' => time() + return $this->lists(); + } + } + + protected function post(){ + $cf_id = 8; + $name = $this->input_param('name'); + $mobile = $this->input_param('mobile'); + $brand_id = $this->input_param('brand_id'); + $remark = $this->input_param('remark'); + if(!$mobile||!$name||!$brand_id){ + throw new Exception('参数错误', ERR_PARAMS_ERROR); + } + if(!mobile_valid($mobile)){ + throw new Exception('手机号格式错误', ERR_PARAMS_ERROR); + } + $row = $this->receiver_clues_model->get(['app_id'=>$this->app_id,'mobile'=>$mobile,'cf_uid'=>$this->session['uid']]); + if($row){ + throw new Exception('该手机号已报备', ERR_PARAMS_ERROR); + } + + $add_data = [ + 'app_id' => $this->app_id, + 'name' => $name, + 'mobile' => $mobile, + 'brand_id' => $brand_id, + 'recommend_id' => $this->session['uid'], + 'cf_uid' => $this->session['uid'], + 'cf_id' => $cf_id, + 'cf_platform' => 'wxapp', + 'en_time' => date('Y-m-d H:i:s'), + 'c_time' => time() + ]; + $res = $this->receiver_clues_model->add($add_data); + if(is_numeric($res)){ + if($remark){ //添加日志 + $this->load->library('receiver/clues_entity'); + $this->clues_entity->add_log($res,$this->session['uid'],$this->session['nickname'],$remark); + } + throw new Exception('保存成功', API_CODE_SUCCESS); + }else{ + throw new Exception('保存失败', ERR_PARAMS_ERROR); + } + } + + protected function get_tabs(){ + $uid = $this->session['uid']; + $recommend_id = [$uid]; + $l_user = $this->app_user_model->select(['up_uid'=>$uid],'','','','id'); //下一级用户 + if($l_user){ + $l_user_ids = array_column($l_user,'id'); + $recommend_id = array_merge($l_user_ids,$recommend_id); + } + $recommend_id_str = implode(',',$recommend_id); + $where = [ + 'app_id' => $this->app_id, + "recommend_id in ($recommend_id_str)" => null, + 'status' => 0 + ]; + $count = $this->receiver_clues_model->count($where); + $lists = [ + ['key' =>0 ,'name' => '全部','nums' => 0], + ['key' =>1 ,'name' => '待确认','nums' => $count], + ['key' =>2 ,'name' => '有效','nums' => 0], + ['key' =>3 ,'name' => '无效','nums' => 0], + ]; + return $lists; + } + + private function lists(){ + $uid = $this->session['uid']; + $page = $this->input_param('page'); + $size = $this->input_param('size'); + $type = $this->input_param('type'); + !$type && $type = 0; + !$page && $page = 1; + !$size && $size = 20; + + $list = []; + + $recommend_id = [$uid]; + $l_user = $this->app_user_model->select(['up_uid'=>$uid],'','','','id'); //下一级用户 + if($l_user){ + $l_user_ids = array_column($l_user,'id'); + $recommend_id = array_merge($l_user_ids,$recommend_id); + } + $recommend_id_str = implode(',',$recommend_id); + $where = [ + 'app_id' => $this->app_id, + "recommend_id in ($recommend_id_str)" => null + ]; + $total = $this->receiver_clues_model->count($where); //总数 + + if($type==1){ //待确认 + $where["lc_receiver_orders.id is null"] = null; + $where["lc_receiver_clues.status !="] =3; + }elseif($type==2){ //有效 + $where['lc_receiver_orders.id >'] = 0; + }elseif($type==3){ + $where['lc_receiver_clues.status'] = 3; + } + $count = $this->receiver_clues_model->selectClues($where,'','','',1); + if($count){ + $rows = $this->receiver_clues_model->selectClues($where,'id desc',$page,$size); + foreach($rows as $key=>$val){ + if($val['cf_uid']==$uid){ + $cfrom = '自带客'; + }else{ + $user = $this->app_user_model->get(['id'=>$val['recommend_id']],'nickname'); + $cfrom = "团队带客({$user['nickname']})"; + } + if($val['status']==3){ //无效 + $status_cor = "#666"; + $status_cn = '无效'; + }elseif($val['o_id']){ //有效 + $status_cor = "#f9394d"; + $status_cn = '有效'; + }else{ //待确认 + $status_cor = "#f9394d"; + $status_cn = '待确认'; + } + $list[] = [ + 'id' => $val['id'], + 'name' => $val['name'], + 'mobile' => mobile_asterisk($val['mobile']), + 'status' => [ + 'color' => $status_cor, + 'text' => $status_cn + ], + 'cfrom' => $cfrom, + 'c_time' => date('Y-m-d H:i:s',$val['c_time']), ]; - $this->contracts_model->update($update,['id'=>$contract['id']]); } } - + $data = [ - 'title' => $title, - 'url' => $h5_url, - 'img' => 'https://qs.haodian.cn/wechat_app/liche/mine/he-demo-2.jpg', + 'list' => $list, + 'total' => $count, + 'all_total' => $total ]; return $data; } - protected function post(){ - $uid = $this->session['uid']; - $id = $this->input_param('id'); - $type = $this->input_param('type'); - $img = $this->input_param('img'); - - $row = $this->contracts_model->get(['type'=>$type,'o_id'=>$id]); - $order = $this->orders_model->get(['id'=>$id],'biz_id,ifentrust,pack_id,info_json'); - if(!$row['file'] || !$img){ - throw new Exception('参数错误', API_CODE_INVILD_PARAM); - } - $jsondata = json_decode($order['info_json'],true); - - if($row['status']==1){ - throw new Exception('已签名', API_CODE_INVILD_PARAM); + private function detail($id){ + $row = $this->receiver_clues_model->get(['id'=>$id]); + if(!$row){ + throw new Exception('数据不存在', ERR_PARAMS_ERROR); } - //获取公司印章 - if($type==1){ - $company = $this->sys_company_model->get(["title like '%服务%'"=>null,'status'=>1],'img_seal,id'); + $order = $this->receiver_orders_model->get(['clue_id'=>$row['id'],'status>='=>0]); + if($row['status']==3){ //无效 + $status_cn = '无效'; + }elseif($order){ //有效 + $status_cn = '有效'; + }else{ //待确认 + $status_cn = '待确认'; + } + $brand = $this->auto_brand_model->get(['id'=>$row['brand_id']],'name'); + if($row['recommend_id']!=$this->session['uid']){ + $user = $this->app_user_model->get(['id'=>$row['recommend_id']],'nickname'); + $cfrom = "团队带客({$user['nickname']})"; }else{ - $biz = $this->biz_model->get(['id'=>$order['biz_id']],'company_id'); - $company = $this->sys_company_model->get(['id'=>$biz['company_id']],'img_seal,id'); + $cfrom = '自带客'; } - $img_seal = $company['img_seal'] ? build_qiniu_image_url($company['img_seal']) : ''; - if(!$img_seal){ - throw new Exception('公司公章未上传', API_CODE_FAIL); - } - //pdf转图片 - $pdf_url = http_host_com('api').'/'.$row['file']; - $this->load->library('pdf'); - $pdf = new Pdf(); //正式 - $imgs = $pdf->pdf2img($pdf_url); - if(!$imgs){ - throw new Exception('签名失败,图片转换失败', API_CODE_INVILD_PARAM); - } - - $redis = load_cache('redis'); - $cache_key = "CONTRACT_{$id}_{$uid}_{$type}"; - if($redis->get($cache_key)){ - throw new Exception('请求太频繁,请刷新查看结果', API_CODE_INVILD_PARAM); - } - $redis->save($cache_key,1,60*1); - - $this->load->library('receiver/sign_entity'); - $sign_entity = new Sign_entity(['comp_img'=>$img_seal]); - switch($type){ - case 0: //整车 - $sign_img = array_pop($imgs); - $height = $order['ifentrust'] ? 480 : 380; - $jsondata['c_cardid'] && $height += 30; - $res = $sign_entity->merge($sign_img,$img,1070,$height,230); - if(!$res){ - throw new Exception('签名失败', API_CODE_INVILD_PARAM); - } - $imgs[] = http_host_com('api').'/'.$res; - $imgs = $this->up_qiniu($imgs,$res); - $update = [ - 'imgs' => json_encode($imgs,JSON_UNESCAPED_UNICODE), - 'sign_time' => date('Y-m-d H:i:s'), - 'status' => 1 + $mobile = mobile_asterisk($row['mobile']); + //获取日志 + $logs = []; + $where = [ + 'clue_id' => $row['id'] + ]; + $log_rows = $this->receiver_clue_oplogs_model->select($where,'id desc',1,20,'id,log,c_time'); + if($log_rows){ + foreach($log_rows as $key=>$val){ + $logs[] = [ + 'id' => $val['id'], + 'log' => $val['log'], + 'c_time' => date('Y-m-d H:i:s',$val['c_time']) ]; - $result = $this->contracts_model->update($update,['id'=>$row['id']]); - if($result){ - $redis->delete($cache_key); - throw new Exception('签名成功', API_CODE_SUCCESS); - }else{ - throw new Exception('签名失败', API_CODE_INVILD_PARAM); - } - break; - case 1: //协议 - $sign_img = array_pop($imgs); - $package = $this->package_model->get(['id'=>$order['pack_id']],'srv_ids'); - $srv_count = $package ? count(explode(',',$package['srv_ids'])) : 0; - $height = $order['ifentrust'] ? 1400 : 1280; - $jsondata['c_cardid'] && $height += 30; - $height += $srv_count*52; - $res = $sign_entity->merge($sign_img,$img,1050,$height,300); - if(!$res){ - throw new Exception('签名失败', API_CODE_INVILD_PARAM); - } - $imgs[] = http_host_com('api').'/'.$res; - $imgs = $this->up_qiniu($imgs,$res); - $update = [ - 'imgs' => json_encode($imgs,JSON_UNESCAPED_UNICODE), - 'sign_time' => date('Y-m-d H:i:s'), - 'status' => 1 - ]; - $result = $this->contracts_model->update($update,['id'=>$row['id']]); - if($result){ - $this->load->library('receiver/orders_entity'); - $this->orders_entity->sign_after_v2($id,$this->session); - $redis->delete($cache_key); - throw new Exception('签名成功', API_CODE_SUCCESS); - }else{ - throw new Exception('签名失败', API_CODE_INVILD_PARAM); - } - break; - case 2: //确认信息 - $sign_img = array_pop($imgs); - $height = $order['ifentrust'] ? 600 : 480; - $jsondata['c_cardid'] && $height += 30; - $res = $sign_entity->merge($sign_img,$img,1050,$height,300); - if(!$res){ - throw new Exception('签名失败', API_CODE_INVILD_PARAM); - } - $imgs[] = http_host_com('api').'/'.$res; - $imgs = $this->up_qiniu($imgs,$res); - $update = [ - 'imgs' => json_encode($imgs,JSON_UNESCAPED_UNICODE), - 'sign_time' => date('Y-m-d H:i:s'), - 'status' => 1 - ]; - $result = $this->contracts_model->update($update,['id'=>$row['id']]); - if($result){ - $this->ckcars_model->update(['status'=>2],['o_id'=>$id]); - //生成支付订单 - $this->load->library('receiver/orders_entity'); - $this->orders_entity->check_finish_v2($id,$this->session); - $redis->delete($cache_key); - throw new Exception('签名成功', API_CODE_SUCCESS); - }else{ - throw new Exception('签名失败', API_CODE_INVILD_PARAM); - } - break; - case 3: //车辆交接 - $sign_img = array_pop($imgs); - $height = $order['ifentrust'] ? 1470 : 1350; - $res = $sign_entity->merge($sign_img,$img,1050,$height,350); - if(!$res){ - throw new Exception('签名失败', API_CODE_INVILD_PARAM); - } - $imgs[] = http_host_com('api').'/'.$res; - $imgs = $this->up_qiniu($imgs,$res); - $update = [ - 'imgs' => json_encode($imgs,JSON_UNESCAPED_UNICODE), - 'sign_time' => date('Y-m-d H:i:s'), - 'status' => 1 - ]; - $result = $this->contracts_model->update($update,['id'=>$row['id']]); - if($result){ - $this->deliverys_model->update(['status'=>1],['o_id'=>$id]); - $redis->delete($cache_key); - throw new Exception('签名成功', API_CODE_SUCCESS); - }else{ - throw new Exception('签名失败', API_CODE_INVILD_PARAM); - } - break; - default: - $redis->delete($cache_key); - throw new Exception('未知签名类型', API_CODE_INVILD_PARAM); - } - } - - //图片上传七牛 - private function up_qiniu($imgs,$file){ - $this->load->library('qiniu'); - //上传七牛并保存 - foreach($imgs as $key=>$val){ - $file_name = md5($val).'.jpg'; - $result = $this->qiniu->fetch($val,$file_name); - if($result){ - $imgs[$key] = $result['file']; - if (strpos($val, $file) !== false) { - @unlink(FCPATH.$file); - } } } - return $imgs; + //获取账单记录 + $mlogs = []; + //$mlogs[] = [ + // 'id' => 1, + // 'title' => '报备佣金', + // 'money' => '+500元', + // 'status' => '有效', + // 'c_time' => date('Y-m-d H:i:s') + //]; + $data = [ + 'title' => "{$row['name']}·{$mobile}", + 'brand' => $brand['name'], + 'cfrom' => $cfrom, + 'status' => $status_cn, + 'c_time' => date('Y-m-d H:i:s',$row['c_time']), + 'logs' => $logs, + 'mlogs' => $mlogs + ]; + return $data; } } diff --git a/api/controllers/wxapp/liche/Statistics.php b/api/controllers/wxapp/liche/Statistics.php index 6c4b9ed6..6cc927d9 100644 --- a/api/controllers/wxapp/liche/Statistics.php +++ b/api/controllers/wxapp/liche/Statistics.php @@ -30,9 +30,15 @@ class Statistics extends Wxapp{ 'lc_receiver_orders.status' => 6 ]; $done = $this->clues_model->count_order($where); + $where = [ + 'lc_receiver_clues.recommend_id' => $uid, + 'lc_receiver_orders.status>' => 0 + ]; + $ispay = $this->clues_model->count_order($where); $data = [ ['name'=>'浏览','value'=>intval($brower['browse_num'])], ['name'=>'报名','value'=>$clues], + ['name'=>'下定','value'=>$ispay], ['name'=>'成交','value'=>$done] ]; return $data; @@ -61,10 +67,17 @@ class Statistics extends Wxapp{ 'lc_receiver_orders.status' => 6 ]; $done = $this->clues_model->count_order($where); + $where = [ + 'lc_receiver_clues.recommend_id' => $uid, + 'lc_receiver_clues.brand_id' => $val['id'], + 'lc_receiver_orders.status>' => 0 + ]; + $ispay = $this->clues_model->count_order($where); $commision = 0; $list[] = [ 'title' => $val['name'], 'enroll' => $enroll, + 'ispay' => $ispay, 'done' => $done, 'commision' => number_format($done*500,2) ]; diff --git a/api/controllers/wxapp/licheb/Cusorder.php b/api/controllers/wxapp/licheb/Cusorder.php index 1b4a2600..7980c48a 100644 --- a/api/controllers/wxapp/licheb/Cusorder.php +++ b/api/controllers/wxapp/licheb/Cusorder.php @@ -185,6 +185,7 @@ class Cusorder extends Wxapp{ } $data['money_json'] = json_encode($money_json,JSON_UNESCAPED_UNICODE); + $row['rid'] && $data['clue_id'] = $row['rid']; $o_id = $this->orders_model->add($data); if($o_id){ $sign_data = [ diff --git a/common/models/receiver/Receiver_clues_model.php b/common/models/receiver/Receiver_clues_model.php index 1b7253af..f1b97ef6 100644 --- a/common/models/receiver/Receiver_clues_model.php +++ b/common/models/receiver/Receiver_clues_model.php @@ -71,4 +71,34 @@ class Receiver_clues_model extends HD_Model $this->db->limit($limit, $offset); return $this->db->get()->result_array(); } + + public function selectClues($where = array(), $order = '', $page = 0, $page_size = 20, $count = 0){ + $this->db->from('lc_receiver_clues'); + $this->db->join('lc_receiver_orders', 'lc_receiver_orders.clue_id = lc_receiver_clues.id and lc_receiver_orders.status>=0', 'left'); + + if ($where) { + $this->db->where($where); + } + + if ($count) { + $this->db->distinct()->select('lc_receiver_clues.*'); + return $this->db->count_all_results(); + }else{ + $this->db->select('lc_receiver_clues.*,lc_receiver_orders.id as o_id'); + $this->db->group_by('lc_receiver_clues.id'); + } + + if ($order) { + $this->db->order_by($order); + } + if ($page) { + $offset = ($page - 1) * $page_size; + $limit = $page_size; + } else { + $offset = null; + $limit = null; + } + $this->db->limit($limit, $offset); + return $this->db->get()->result_array(); + } } diff --git a/sql/receiver/order.sql b/sql/receiver/order.sql index 625ec3a4..6984fa38 100644 --- a/sql/receiver/order.sql +++ b/sql/receiver/order.sql @@ -162,6 +162,7 @@ drop table if exists lc_receiver_orders; create table lc_receiver_orders ( id int(10) unsigned not null auto_increment comment '自增id', rid int(10) not null default '0' comment '客户池id', + clue_id int(10) not null default '0' comment '线索id', sid varchar(32) not null comment '订单号', name varchar(32) not null comment '客户姓名', mobile varchar(11) not null comment '客户手机号码',