You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
345 lines
9.2 KiB
345 lines
9.2 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\model\customer_resources;
|
|
|
|
use app\model\dict\Dict;
|
|
use app\model\order_table\OrderTable;
|
|
use app\model\resource_sharing\ResourceSharing;
|
|
use app\model\six_speed\SixSpeed;
|
|
use core\base\BaseModel;
|
|
use think\db\Query;
|
|
use think\model\concern\SoftDelete;
|
|
use think\model\relation\HasMany;
|
|
use think\model\relation\HasOne;
|
|
|
|
use app\model\personnel\Personnel;
|
|
|
|
use app\model\campus\Campus;
|
|
use app\model\member\Member;
|
|
|
|
/**
|
|
* 客户资源模型
|
|
* Class CustomerResources
|
|
* @package app\model\customer_resources
|
|
*/
|
|
class CustomerResources extends BaseModel
|
|
{
|
|
|
|
use SoftDelete;
|
|
|
|
/**
|
|
* 数据表主键
|
|
* @var string
|
|
*/
|
|
protected $pk = 'id';
|
|
|
|
/**
|
|
* 模型名称
|
|
* @var string
|
|
*/
|
|
protected $name = 'customer_resources';
|
|
|
|
/**
|
|
* 定义软删除标记字段.
|
|
* @var string
|
|
*/
|
|
protected $deleteTime = 'deleted_at';
|
|
|
|
/**
|
|
* 定义软删除字段的默认值.
|
|
* @var int
|
|
*/
|
|
protected $defaultSoftDelete = 0;
|
|
|
|
protected $json = [ 'member_label' ];
|
|
|
|
protected $jsonAssoc = true;
|
|
|
|
//定义一个常量数组-字段中文映射
|
|
const FieldZh = [
|
|
'id' => '编号',
|
|
'create_year_month' => '创建年月',
|
|
'create_date' => '创建日期',
|
|
'source_channel' => '来源渠道',
|
|
'source' => '来源',
|
|
'consultant' => '顾问',
|
|
'name' => '姓名',
|
|
'age' => '年龄',
|
|
'gender' => '性别',
|
|
'phone_number' => '联系电话',
|
|
'demand' => '需求',
|
|
'purchasing_power' => '购买力',
|
|
'cognitive_idea' => '认知理念',
|
|
'optional_class_time' => '可选上课时间',
|
|
'distance' => '距离',
|
|
'decision_maker' => '决策人',
|
|
'initial_intent' => '客户初步意向度',
|
|
'campus' => '所属校区',
|
|
'trial_class_count' => '体验课次数',
|
|
'created_at' => '创建时间',
|
|
'updated_at' => '更新时间',
|
|
'deleted_at' => '逻辑删除时间',
|
|
'status' => '客户状态',
|
|
];
|
|
|
|
public function orderTable()
|
|
{
|
|
return $this->hasMany(OrderTable::class, 'resource_id', 'id');
|
|
}
|
|
/**
|
|
* 搜索器:客户资源姓名
|
|
* @param $value
|
|
* @param $data
|
|
*/
|
|
public function searchNameAttr($query, $value, $data)
|
|
{
|
|
if ($value) {
|
|
$query->where("name", $value);
|
|
}
|
|
}
|
|
|
|
public function searchMemberLabelAttr(Query $query, $value, $data)
|
|
{
|
|
if ($value) {
|
|
$query->whereLike('member_label', '%"' . $value . '"%');
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 搜索器:客户资源联系电话
|
|
* @param $value
|
|
* @param $data
|
|
*/
|
|
public function searchPhoneNumberAttr($query, $value, $data)
|
|
{
|
|
if ($value) {
|
|
$query->where("phone_number", $value);
|
|
}
|
|
}
|
|
|
|
|
|
public function member(){
|
|
return $this->hasOne(Member::class, 'member_id', 'member_id');
|
|
}
|
|
|
|
|
|
|
|
//获取顾问名字
|
|
public function personnel(){
|
|
return $this->hasOne(Personnel::class, 'id', 'consultant')->joinType('left')->withField('name,id')->bind(['consultant_name'=>'name']);
|
|
}
|
|
|
|
public function campus(){
|
|
return $this->hasOne(Campus::class, 'id', 'campus')->joinType('left')->withField('campus_name,id')->bind(['campus_name'=>'campus_name']);
|
|
}
|
|
|
|
public function resourceSharing()
|
|
{
|
|
return $this->hasOne(ResourceSharing::class, 'resource_id', 'resource_id')->joinType('left')
|
|
->withField('id as sharin_id,shared_by');
|
|
|
|
}
|
|
|
|
//一对一关联six_speed模型
|
|
public function sixSpeed()
|
|
{
|
|
return $this->hasOne(SixSpeed::class, 'resource_id', 'id');
|
|
}
|
|
|
|
//一对多关联"资源共享表"
|
|
public function resourceSharingHasMany()
|
|
{
|
|
return $this->hasMany(ResourceSharing::class, 'resource_id', 'id');
|
|
}
|
|
|
|
//一对一关联"用户账号登陆表"
|
|
public function memberHasOne()
|
|
{
|
|
return $this->hasOne(Member::class, 'member_id', 'member_id');
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
* 获取客户初步意向度类型名称
|
|
* @param $value
|
|
* @param $data
|
|
* @return array|mixed|string
|
|
*/
|
|
public function getInitialIntentNameAttr($value, $data)
|
|
{
|
|
$key = 'preliminarycustomerintention';
|
|
$val = (String)$data['initial_intent'];
|
|
if ((!empty($val) || isset($val)) && $val !== '') {
|
|
$dict = Dict::where('key',$key)->find();
|
|
$dictionary = $dict['dictionary'] ?? [];
|
|
// 查找匹配的 name
|
|
$res = '';
|
|
foreach ($dictionary as $item) {
|
|
if ($item['value'] == $val) {
|
|
$res = $item['name'];
|
|
break;
|
|
}
|
|
}
|
|
return $res;
|
|
} else {
|
|
return '';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取来源渠道类型名称
|
|
* @param $value
|
|
* @param $data
|
|
* @return array|mixed|string
|
|
*/
|
|
public function getSourceChannelNameAttr($value, $data)
|
|
{
|
|
$key = 'SourceChannel';
|
|
$val = (String)$data['source_channel'];
|
|
if ((!empty($val) || isset($val)) && $val !== '') {
|
|
$dict = Dict::where('key',$key)->find();
|
|
$dictionary = $dict['dictionary'] ?? [];
|
|
// 查找匹配的 name
|
|
$res = '';
|
|
$arr = [
|
|
"name" => "线下",
|
|
"value" => "0",
|
|
"sort" => 0,
|
|
"memo" => "",
|
|
];
|
|
array_unshift($dictionary, $arr);
|
|
foreach ($dictionary as $item) {
|
|
if ($item['value'] == $val) {
|
|
$res = $item['name'];
|
|
break;
|
|
}
|
|
}
|
|
return $res;
|
|
} else {
|
|
return '';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取来源类型名称
|
|
* @param $value
|
|
* @param $data
|
|
* @return array|mixed|string
|
|
*/
|
|
public function getSourceNameAttr($value, $data)
|
|
{
|
|
$key = 'source';
|
|
$val = (String)$data['source'];
|
|
if ((!empty($val) || isset($val)) && $val !== '') {
|
|
$dict = Dict::where('key',$key)->find();
|
|
$dictionary = $dict['dictionary'] ?? [];
|
|
// 查找匹配的 name
|
|
$res = '';
|
|
foreach ($dictionary as $item) {
|
|
if ($item['value'] == $val) {
|
|
$res = $item['name'];
|
|
break;
|
|
}
|
|
}
|
|
return $res;
|
|
} else {
|
|
return '';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取性别类型名称
|
|
* @param $value
|
|
* @param $data
|
|
* @return array|mixed|string
|
|
*/
|
|
public function getGenderNameAttr($value, $data)
|
|
{
|
|
$key = 'zy_sex';
|
|
$val = (String)$data['gender'];
|
|
if ((!empty($val) || isset($val)) && $val !== '') {
|
|
$dict = Dict::where('key',$key)->find();
|
|
$dictionary = $dict['dictionary'] ?? [];
|
|
// 查找匹配的 name
|
|
$res = '';
|
|
foreach ($dictionary as $item) {
|
|
if ($item['value'] == $val) {
|
|
$res = $item['name'];
|
|
break;
|
|
}
|
|
}
|
|
return $res;
|
|
} else {
|
|
return '';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取购买力类型名称
|
|
* @param $value
|
|
* @param $data
|
|
* @return array|mixed|string
|
|
*/
|
|
public function getPurchasingPowerNameAttr($value, $data)
|
|
{
|
|
$key = 'customer_purchasing_power';
|
|
$val = (String)$data['purchasing_power'];
|
|
if ((!empty($val) || isset($val)) && $val !== '') {
|
|
$dict = Dict::where('key',$key)->find();
|
|
$dictionary = $dict['dictionary'] ?? [];
|
|
// 查找匹配的 name
|
|
$res = '';
|
|
foreach ($dictionary as $item) {
|
|
if ($item['value'] == $val) {
|
|
$res = $item['name'];
|
|
break;
|
|
}
|
|
}
|
|
return $res;
|
|
} else {
|
|
return '';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取客户状态类型名称
|
|
* @param $value
|
|
* @param $data
|
|
* @return array|mixed|string
|
|
*/
|
|
public function getStatusNameAttr($value, $data)
|
|
{
|
|
$key = 'kh_status';
|
|
$val = (String)$data['status'];
|
|
if ((!empty($val) || isset($val)) && $val !== '') {
|
|
$dict = Dict::where('key',$key)->find();
|
|
$dictionary = $dict['dictionary'] ?? [];
|
|
// 查找匹配的 name
|
|
$res = '';
|
|
foreach ($dictionary as $item) {
|
|
if ($item['value'] == $val) {
|
|
$res = $item['name'];
|
|
break;
|
|
}
|
|
}
|
|
return $res;
|
|
} else {
|
|
return '';
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|