123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- <?php
- namespace app\model;
- use think\Model;
- use toolkits\Aec;
- class CustomerDropPool extends Model
- {
- /**
- * 关联员工
- */
- public function employee()
- {
- return $this->belongsTo(Employee::class, 'employee_id');
- }
- /**
- * 销售部门关联
- */
- public function employeeOrg()
- {
- return $this->hasOneThrough(Org::class, Employee::class, 'id', 'id', 'employee_id', 'org_id');
- }
- /**
- * 关联部门
- */
- public function org()
- {
- return $this->belongsTo(Org::class, 'org_id')->bind(['org_name' => 'name']);
- }
- /**
- * 关联公海
- */
- public function pool()
- {
- return $this->belongsTo(Pool::class, 'org_id')->bind(['pool_name' => 'name']);
- }
- /**
- * 来源
- */
- public function source()
- {
- return $this->belongsTo(CustomerSource::class, 'source_id');
- }
- /**
- * 设计师
- */
- public function designer()
- {
- return $this->belongsTo(Employee::class, 'designer_id');
- }
- /**
- * 设计师部门
- */
- public function designerOrg()
- {
- return $this->hasOneThrough(Org::class, Employee::class, 'id', 'id', 'employee_id', 'org_id');
- }
- /**
- * 建档机制
- * 1,拿到手机号的才能建档
- * 2,档案中有该手机号也不能建档
- */
- public static function onBeforeInsert($customer)
- {
- // 没有手机号不能建档
- if (empty($customer->phone)) return false;
- // 手机号已经存在无法建档
- $condition = [
- 'employee_id' => $customer->employee_id,
- 'phone' => $customer->phone
- ];
- $had = self::where($condition)->find();
- if ($had) return false;
- return true;
- }
- /**
- * 手机号解密
- */
- public function getPhoneAttr($value)
- {
- if (preg_match('/^1[\d]{10}$/', $value)) return $value;
- $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
- $value = $aec->decrypt($value);
- return $value;
- }
- /**
- * 手机号解密
- */
- public function getPhone1Attr($value)
- {
- if (preg_match('/^1[\d]{10}$/', $value)) return $value;
- $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
- $value = $aec->decrypt($value);
- return $value;
- }
-
- /**
- * 手机号解密
- */
- public function getPhone2Attr($value)
- {
- if (preg_match('/^1[\d]{10}$/', $value)) return $value;
- $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
- $value = $aec->decrypt($value);
- return $value;
- }
- /**
- * 手机号加密
- */
- public function setPhoneAttr($value)
- {
- $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
- $value = $aec->encrypt($value);
- return $value;
- }
- //protected $json = ['ext'];
- // private $extAttr = [
- // 'ext1' => '年龄',
- // 'ext2' => '是否首次装修',
- // 'ext3' => '消费能力',
- // 'ext4' => '预计装修时间',
- // 'ext5' => '爱好',
- // 'ext6' => '微信',
- // 'ext7' => '客户空闲时间段',
- // 'ext8' => '家庭结构',
- // 'ext9' => '家庭成员意见',
- // 'ext10' => '户型',
- // 'ext11' => '决策人',
- // 'ext12' => '喜欢色调',
- // 'ext13' => '房屋结构',
- // 'ext14' => '装修方式',
- // 'ext15' => '客户需求',
- // 'ext16' => '客户痛点',
- // 'ext17' => '重视环保',
- // 'ext18' => '重视设计',
- // 'ext19' => '关注的工艺',
- // 'ext20' => '特别在意的空间设计',
- // 'ext21' => '汽车价格',
- // 'ext22' => '房屋价格',
- // 'ext23' => '买小区的原因',
- // 'ext24' => '周边配置',
- // 'ext25' => '设计师服务满意度',
- // 'ext26' => '方案满意度',
- // 'ext27' => '报价满意度',
- // 'ext28' => '意向程度',
- // 'ext29' => '是否到店',
- // 'ext30' => '预计到店使时间',
- // 'ext31' => '是否交定',
- // 'ext32' => '客户其他需求',
- // 'ext33' => '当前所在区域',
- // 'ext34' => '加微类型',
- // 'ext35' => '建群情况',
- // 'ext36' => '直播情况',
- // 'ext37' => '直播人员',
- // 'ext38' => '房屋用途',
- // 'ext39' => '房屋位置',
- // 'ext40' => '其他房屋信息备注',
- // 'ext41' => '谈单时长'
- // ];
- /**
- * 客户扩展属性
- */
- // public function getExtAttr($ext)
- // {
- // $data = [];
- // foreach ($this->extAttr as $k => $v) {
- // $data[$v] = isset($ext->$k) ? $ext->$k : '';
- // }
- // return $data;
- // }
- // public function setExtAttr($ext)
- // {
- // $data = [];
- // foreach ($this->extAttr as $key => $val) {
- // $data[$key] = isset($ext[$val]) ? $ext[$val] : '';
- // }
- // return $data;
- // }
- /**
- * 收定金额转换单位
- */
- public function getDepositMoneyAttr($value)
- {
- if (empty($value)) return $value;
- $length = strlen($value);
- if ($length < 5) return $value . '元';
- if ($length > 4) {
- $num = $value / 10000;
- $value = round($num, 2) . '万元';
- return $value;
- }
- }
- /**
- * 签单金额转换单位
- */
- public function getSignedMoneyAttr($value)
- {
- if (empty($value)) return $value;
- $length = strlen($value);
- if ($length < 5) return $value . '元';
- if ($length > 4) {
- $num = $value / 10000;
- $value = round($num, 2) . '万元';
- return $value;
- }
- }
- /**
- * 获取预约次数
- * @return \think\model\relation\HasMany
- */
- public function visitLog()
- {
- return $this->hasMany('CustomerVisitLog', 'customer_id', 'id');
- }
- /**
- * 参加活动次数 确认到场次数
- * @return \think\model\relation\HasMany
- */
- public function activityFrequency()
- {
- return $this->hasMany('CustomerVisitLog', 'customer_id', 'id');
- }
- /**
- * 关联活动
- */
- public function activity()
- {
- return $this->belongsTo(Activity::class, 'aid');
- }
- /**
- * 关联员工
- */
- public function User()
- {
- return $this->belongsTo(User::class, 'uid');
- }
- /**
- * 关联经济人客户记录
- */
- public function agentLog()
- {
- return $this->hasMany(AgentCustomerLog::class, 'customer_id', 'id');
- }
- public function getStateAttr($value)
- {
- $states = Customer::$states;
- if (is_numeric($value)) $value = intval($value);
- foreach ($states as $s) {
- if ($value === $s['n'] || in_array($value, $s['chaos'], true)) return $s['state'];
- }
- return '';
- }
- public function setStateAttr($value)
- {
- $states = Customer::$states;
- if (is_numeric($value)) $value = intval($value);
- foreach ($states as $s) {
- if ($value === $s['n'] || in_array($value, $s['chaos'], true)) return $s['n'];
- }
- return 0;
- }
- }
|