Files
spacestation/api/controllers/wxapp/licheb/OpenApi.php
T
xiaoyu bc78828cc0 score
2025-05-11 22:44:14 +08:00

183 lines
7.0 KiB
PHP

<?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->model('receiver/order/receiver_orders_model', 'orders_model');
$this->load->model('area_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');
$remark = $this->input_param('remark');
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, 1, 'admin', $remark ?: '新增线索', 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'], 1, 'admin', '转交门店跟进', 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;
}
}
public function post_status()
{
$status_map = [
0 => ['title' => '待确认', 'list' => [0 => '清洗中', 1 => '已派发']],
1 => ['title' => '已成交'],
2 => ['title' => '无效']
];
$out_ids = $this->input_param('out_ids');
$cf_platform = $this->input_param('cf_platform');
if (!$out_ids) {
throw new Exception('参数错误', API_CODE_FAIL);
}
$out_id_array = explode(',', $out_ids);
$lists = [];
if ($out_id_array) {
$ids = implode(',', $out_id_array);
$where = [
"out_id in ({$ids})" => null,
'cf_platform' => $cf_platform,
];
$rows = $this->clues_model->select($where, '', 1, 2000, 'id,out_id,name,status,status2');
foreach ($rows as $item) {
$status2 = $status = 0;
$customersRow = $this->customers_model->get(['rid' => $item['id']]);
if ($customersRow) {
$status2 = 1;
}
if ($this->orders_model->get(['clue_id' => $item['id']])) {
$status = 2;
}
if ($item['status'] == 3) {
$status = 3;
}
$lists[$item['out_id']] = [
'id' => $item['id'],
'out_id' => $item['out_id'],
'status' => $status,
'status2' => $status2,
'status_cn' => $status_map[$status]['title'],
'status2_cn' => $status_map[$status]['list'][$status2] ? $status_map[$status]['list'][$status2] : ''
];
}
}
return ['list' => $lists];
}
public function get_biz()
{
$biz_id = $this->input_param('biz_id');
if (!$biz_id) {
throw new Exception('参数错误', API_CODE_FAIL);
}
$row = $this->biz_model->get(['id' => $biz_id]);
$address = $row['address'] ? $row['address'] : '';
if ($row['county_id']) {
$areas = $this->area_model->get(['county_id' => $row['county_id']]);
$address = $areas['province_name'] . $areas['city_name'] . $areas['county_name'] . $address;
}
$data = [
'id' => $row['id'] ? $row['id'] : '',
'biz_name' => $row['biz_name'] ? $row['biz_name'] : '',
'address' => $address,
'lat' => $row['lat'] ? $row['lat'] : '',
'lng' => $row['lng'] ? $row['lng'] : '',
];
return $data;
}
}