增加添加线索接口
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
defined('WXAPP_APP') or exit('No direct script access allowed');
|
||||
|
||||
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
|
||||
|
||||
class OpenApi 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', 'clues_model');
|
||||
$this->load->model('receiver/receiver_customers_model', 'customers_model');
|
||||
$this->load->model("biz/biz_model");
|
||||
$this->load->library('receiver/clues_entity');
|
||||
$this->load->library('receiver/customers_entity');
|
||||
}
|
||||
|
||||
//新增线索
|
||||
public function post_clues()
|
||||
{
|
||||
$name = $this->input_param('name');
|
||||
$mobile = $this->input_param('mobile');
|
||||
$out_id = $this->input_param('out_id');
|
||||
$cf_platform = $this->input_param('cf_platform');
|
||||
$en_time = $this->input_param('en_time');
|
||||
$biz_id = $this->input_param('biz_id');
|
||||
$to_customers = $this->input_param('to_customers');
|
||||
if (!$name || !$mobile) {
|
||||
throw new Exception('参数错误', API_CODE_FAIL);
|
||||
}
|
||||
if ($out_id && $cf_platform && $this->clues_model->get(['out_id' => $out_id, 'cf_platform' => $cf_platform])) {
|
||||
throw new Exception('数据已存在', API_CODE_FAIL);
|
||||
}
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'mobile' => $mobile,
|
||||
'out_id' => $out_id,
|
||||
'cf_id' => 2,
|
||||
'cf2_id' => 19,
|
||||
'cf_platform' => $cf_platform,
|
||||
'c_time' => time(),
|
||||
'en_time' => $en_time ?: date('Y-m-d H:i:s'),
|
||||
];
|
||||
if ($to_customers) {
|
||||
$data['biz_id'] = $biz_id;
|
||||
}
|
||||
$ret = $this->clues_model->add($data);
|
||||
if (is_numeric($ret)) {
|
||||
$this->clues_entity->add_log($ret, '', '', '新增线索', 3);
|
||||
}
|
||||
if ($to_customers) { // 分配到客户池
|
||||
$this->customers($ret);
|
||||
}
|
||||
throw new Exception('保存成功', API_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
//分配到客户表
|
||||
public function customers($clue_id)
|
||||
{
|
||||
$re = $this->clues_model->get(array('id' => $clue_id));
|
||||
if (!$re || empty($re)) {
|
||||
return $this->show_json(SYS_CODE_FAIL, '线索不存在!');
|
||||
}
|
||||
$this->load->helper("order");
|
||||
$biz = $this->biz_model->get(array('id' => $re['biz_id']));
|
||||
$add = array(
|
||||
'rid' => $re['id'],
|
||||
'cid' => create_customer_no($biz['county_id']),
|
||||
'name' => $re['name'],
|
||||
'province_id' => $re['province_id'],
|
||||
'city_id' => $re['city_id'],
|
||||
'county_id' => $re['county_id'],
|
||||
'mobile' => $re['mobile'],
|
||||
'biz_id' => $re['biz_id'],
|
||||
'level' => 'H',
|
||||
'cf_title' => '数字营销中台',
|
||||
'of_id' => $re['cf_id'],
|
||||
'of2_id' => $re['cf2_id'],
|
||||
'p_time' => $re['p_time'],
|
||||
'cont_time' => $re['cont_time'],
|
||||
'c_time' => $re['c_time'],
|
||||
);
|
||||
|
||||
$customers_id = $this->customers_model->add($add);
|
||||
if ($customers_id) {
|
||||
$this->clues_entity->add_log($re['id'], '', '', '转交门店跟进', 3);
|
||||
$this->clues_model->update(['status' => 1, 'status2' => 2], ['id' => $re['id']]);
|
||||
|
||||
//同步线索日志到客户日志
|
||||
$this->customers_entity->syn_clues($customers_id, $re['id']);
|
||||
|
||||
//短信通知店长
|
||||
// $this->load->model('app/licheb/app_licheb_users_model');
|
||||
// $where = array('biz_id' => $re['biz_id'], 'status' => 1, 'group_id' => 2);
|
||||
// $res_u = $this->app_licheb_users_model->get($where);
|
||||
// $res_u['mobile'] = 18350451617;
|
||||
// if ($re['biz_id'] != 1) {
|
||||
// b2m_send_sms($res_u['mobile'], '【理车宝】您好,门店新增了1个客户线索。请及时到小程序"理车宝-待分配客户”分配给销售顾问跟进。祝您生活愉快!');
|
||||
// }
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user