Files
liche/home/controllers/h5/Lichene.php
T
2022-03-25 22:43:47 +08:00

87 lines
3.4 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Lichene extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
/**
* Notes:客户画像
* https://liche-dev.xiaoyu.com/h5/lichene
* https://www.liche.cn/h5/lichene
* Created on: 2022/3/25 11:19
* Created by: dengbw
*/
public function index()
{
$this->load->library('wx_qyapi', ['app' => 'lichene']);
$sign_package = $this->wx_qyapi->getSignPackage();
echo json_encode($sign_package, JSON_UNESCAPED_UNICODE);
$data = ['_title' => '客户画像', 'sign_package' => $sign_package];
$this->load->view('/h5/lichene/index', $data);
}
public function get_user()
{
$this->load->model('receiver/receiver_customers_model', 'mdCustomers');
$this->load->model('receiver/receiver_customer_tag_model', 'mdCustomerTag');
$this->load->model('receiver/receiver_customer_tagdata_model', 'mdCustomerTagdata');
$id = 0;
$tagList = $res_td = $sources = [];
//标签
$res = $this->mdCustomerTag->select(['status' => 1, 'pid' => 0], 'sort desc,id desc', 0, 0, 'id,name,type');
if ($res) {
$id && $res_td = $this->mdCustomerTagdata->select(['c_id' => $id], 'id desc', 0, 0, 't_id');//查找用户选择
$tag_data = $res_td ? array_unique(array_column($res_td, 't_id')) : '';
foreach ($res as $key => $val) {
$list = [];
$value = '';
$res2 = $this->mdCustomerTag->select(['status' => 1, 'pid' => $val['id']], 'sort desc,id desc', 0, 0, 'id,name');
foreach ($res2 as $key2 => $val2) {
//检查是否选中标签
$setValue = ['id' => $val2['id'], 'name' => $val2['name']];
if ($val['type'] == 'checkbox') {
$setValue['checked'] = $tag_data && in_array($val2['id'], $tag_data) ? true : false;
} else {
$checked = false;
if ($tag_data && in_array($val2['id'], $tag_data)) {
!$value && $checked = true;
$value = $val2['id'];
}
$setValue['checked'] = $checked;
}
$list[] = $setValue;
}
$tagList[] = ['id' => $val['id'], 'name' => $val['name'], 'type' => $val['type'], 'list' => $list];
}
}
//线索来源
$status = 0;
$offline_sources = $this->mdCustomers->offlineSources();
if (strlen($status) && $status == 0) {//未见客户
unset($offline_sources[1]);
}
foreach ($offline_sources as $key => $val) {
$list = [];
foreach ($val['list'] as $key2 => $val2) {
$list[] = ['id' => $key2, 'name' => $val2];
}
$sources[] = ['id' => $key, 'name' => $val['name'], 'list' => $list];
}
$data['tagList'] = $tagList;
$data['sources'] = $sources;
$this->show_json(200, '获取用户信息成功', $data);
}
private function show_json($code, $msg, $info = [])
{
$data['code'] = $code;
$data['msg'] = $msg;
$data['data'] = $info;
die(json_encode($data, JSON_UNESCAPED_UNICODE));
}
}