349 lines
13 KiB
PHP
349 lines
13 KiB
PHP
<?php
|
|
defined('WXAPP_APP') OR exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Created by Vim
|
|
* User: lcc
|
|
* Date: 2021/10/09
|
|
* Time: 10:08
|
|
*/
|
|
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
|
|
|
|
class Clues extends Wxapp
|
|
{
|
|
|
|
function __construct($inputs, $app_key)
|
|
{
|
|
parent::__construct($inputs, $app_key);
|
|
|
|
$this->login_white = array();//登录白名单
|
|
$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');
|
|
if ($id) {
|
|
return $this->detail($id);
|
|
} else {
|
|
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');
|
|
$intro_biz_id = intval($this->input_param('intro_biz_id'));
|
|
$intro_uid = intval($this->input_param('intro_uid'));
|
|
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(['mobile' => $mobile]);
|
|
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_platform' => 'wxapp',
|
|
'en_time' => date('Y-m-d H:i:s'),
|
|
'c_time' => time()
|
|
];
|
|
//转介绍
|
|
$re_biz = [];
|
|
if ($intro_biz_id || $intro_uid) {
|
|
$cf_id = 32;
|
|
$this->load->model("biz/biz_model", 'mdBiz');
|
|
$re_biz = $this->mdBiz->get(['id' => $intro_biz_id, 'status' => 1]);
|
|
if (!$re_biz) {
|
|
throw new Exception('无此门店', ERR_PARAMS_ERROR);
|
|
}
|
|
$add_data['city_id'] = $re_biz['city_id'];//城市id
|
|
$add_data['county_id'] = $re_biz['county_id'];//区id
|
|
$add_data['status'] = 1;//已分配
|
|
$add_data['status2'] = 1;//强意向
|
|
}
|
|
$add_data['cf_id'] = $cf_id;
|
|
$id = $this->receiver_clues_model->add($add_data);
|
|
if (is_numeric($id)) {
|
|
$this->load->library('receiver/clues_entity');
|
|
$this->load->library('receiver/customers_entity');
|
|
$this->load->model('receiver/receiver_customers_model', 'mdCustomers');
|
|
if ($remark) { //添加日志
|
|
$this->clues_entity->add_log($id, $this->session['uid'], $this->session['nickname'], $remark);
|
|
}
|
|
//转介绍
|
|
if (($intro_biz_id || $intro_uid) && $re_biz) {
|
|
$clues_row = $add_data;
|
|
$add_data = [
|
|
'rid' => $id,
|
|
'name' => $clues_row['name'],
|
|
'mobile' => $clues_row['mobile'],
|
|
'biz_id' => $re_biz['id'],
|
|
'city_id' => $re_biz['city_id'],
|
|
'county_id' => $re_biz['county_id'],
|
|
'brand_id' => $clues_row['brand_id'],
|
|
's_id' => 0,
|
|
'if_driver' => 0,
|
|
'cf_title' => '自有资源',
|
|
'cf_id' => $clues_row['cf_id'],
|
|
'p_time' => date('Y-m-d H:i:s'),
|
|
'c_time' => $clues_row['c_time'],
|
|
'level' => 'H',
|
|
'admin_id' => $intro_uid,
|
|
];
|
|
$customers_id = $this->mdCustomers->add($add_data);
|
|
if ($customers_id) {
|
|
$content = "指定给【{$re_biz['biz_name']}】商家";
|
|
if ($intro_uid) {
|
|
$this->load->model('app/licheb/app_licheb_users_model', 'mdUsers');
|
|
$re_u = $this->mdUsers->get(['id' => $intro_uid]);
|
|
$re_u && $content = "指定给【{$re_biz['biz_name']}_{$re_u['uname']}】人";
|
|
}
|
|
if ($remark) {
|
|
$this->customers_entity->add_log($customers_id, $this->session['uid'], $this->session['nickname'], $remark);
|
|
}
|
|
$this->customers_entity->add_log($customers_id, $this->session['uid'], $this->session['nickname'], '转介绍');
|
|
$this->clues_entity->add_log($id, $this->session['uid'], $this->session['nickname'], $content);
|
|
}
|
|
}
|
|
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']),
|
|
];
|
|
}
|
|
}
|
|
|
|
$data = [
|
|
'list' => $list,
|
|
'total' => $count,
|
|
'all_total' => $total
|
|
];
|
|
return $data;
|
|
}
|
|
|
|
private function detail($id)
|
|
{
|
|
$row = $this->receiver_clues_model->get(['id' => $id]);
|
|
if (!$row) {
|
|
throw new Exception('数据不存在', ERR_PARAMS_ERROR);
|
|
}
|
|
$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 {
|
|
$cfrom = '自带客';
|
|
}
|
|
$mobile = mobile_asterisk($row['mobile']);
|
|
//获取日志
|
|
$logs = [];
|
|
$where = [
|
|
'clue_id' => $row['id'],
|
|
'type!=' => 2
|
|
];
|
|
$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'])
|
|
];
|
|
}
|
|
}
|
|
//获取账单记录
|
|
$mlogs = [];
|
|
$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;
|
|
}
|
|
|
|
protected function get_lists()
|
|
{
|
|
$uid = $this->session['uid'];
|
|
$page = $this->input_param('page');
|
|
$size = $this->input_param('size');
|
|
!$type && $type = 0;
|
|
!$page && $page = 1;
|
|
!$size && $size = 20;
|
|
|
|
$list = [];
|
|
|
|
$where = [
|
|
'app_id' => $this->app_id,
|
|
"recommend_id" => $uid
|
|
];
|
|
$count = $this->receiver_clues_model->count($where); //总数
|
|
|
|
if ($count) {
|
|
$rows = $this->receiver_clues_model->select($where, 'id desc', $page, $size, 'id,name,mobile,c_time');
|
|
foreach ($rows as $key => $val) {
|
|
$list[] = [
|
|
'id' => $val['id'],
|
|
'name' => $val['name'],
|
|
'mobile' => mobile_asterisk($val['mobile']),
|
|
'c_time' => date('Y-m-d H:i:s', $val['c_time']),
|
|
];
|
|
}
|
|
}
|
|
|
|
$data = [
|
|
'list' => $list,
|
|
'total' => $count,
|
|
];
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* Notes:转介绍指定店/人
|
|
* Created on: 2021/11/22 16:09
|
|
* Created by: dengbw
|
|
* @return array
|
|
*/
|
|
protected function get_intro()
|
|
{
|
|
$province_id = 350;
|
|
$intro_city_id = intval($this->input_param('intro_city_id'));
|
|
$intro_biz_id = intval($this->input_param('intro_biz_id'));
|
|
if ($intro_city_id && $intro_biz_id) {
|
|
$this->load->model('app/licheb/app_licheb_users_model', 'mdUsers');
|
|
$where = ['status' => 1, 'group_id<>' => 4, 'biz_id' => $intro_biz_id];
|
|
$res = $this->mdUsers->select($where, 'id desc', 0, 0, 'id,uname as name');
|
|
} else if ($intro_city_id) {
|
|
$this->load->model("biz/biz_model", 'mdBiz');
|
|
$where = ['status' => 1, 'province_id' => $province_id, 'city_id' => $intro_city_id];
|
|
$res = $this->mdBiz->select($where, 'id desc', 0, 0, 'id,biz_name as name');
|
|
} else {
|
|
$this->load->model("area_model", 'mdArea');
|
|
$where = ['province_id' => $province_id];
|
|
$res = $this->mdArea->select($where, '', 0, 0, 'distinct(city_id) as id,city_name as name');
|
|
}
|
|
$data['list'] = $res ? $res : [];
|
|
return $data;
|
|
}
|
|
}
|