123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- <?php
- namespace app\model;
- use think\Model;
- class CustomerVisitLog extends Model
- {
- /**
- * 关联用户
- */
- public function user()
- {
- return $this->belongsTo(User::class, 'user_id');
- }
- /**
- * 关联员工
- */
- public function employee()
- {
- return $this->belongsTo(Employee::class, 'employee_id');
- }
- /**
- * 图片处理
- */
- public function getImgAttr($value)
- {
- if (empty($value)) return [];
- $ali_oss_bindurl = config('app.ali_oss_bindurl');
- $value = explode(',', $value);
- if (!is_array($value))
- $value = [$value];
- foreach ($value as &$it) {
- $it = 'https://' . $ali_oss_bindurl . '/' . $it;
- }
- return $value;
- }
- /**
- * 图片处理
- */
- public function getImg1Attr($value)
- {
- if (empty($value)) return [];
- $ali_oss_bindurl = config('app.ali_oss_bindurl');
- $value = explode(',', $value);
- if (!is_array($value))
- $value = [$value];
- foreach ($value as &$it) {
- $it = 'https://' . $ali_oss_bindurl . '/' . $it;
- }
- return $value;
- }
- public function activity()
- {
- return $this->hasOne(Activity::class, 'id', 'aid');
- }
- public function activitys()
- {
- return $this->belongsTo(Activity::class, 'aid', 'id');
- }
- /** 统一状态 */
- public static $states = [
- ['n' => 1, 'chaos' => [1, '回访', '待确认', '预约回访', '1'], 'state' => '回访'],
- ['n' => 2, 'chaos' => [2, '交定', '定金', '已交定', '收定', '2'], 'state' => '已交定'],
- ['n' => 3, 'chaos' => [3, '签单', '已签单', '3'], 'state' => '已签单'],
- ['n' => 4, 'chaos' => [4, '预约到店', '4'], 'state' => '预约到店'],
- ['n' => 5, 'chaos' => [5, '预约量房', '5'], 'state' => '预约量房'],
- ['n' => 6, 'chaos' => [6, '预约活动', '6'], 'state' => '预约活动'],
- ['n' => 7, 'chaos' => [7, '已到访', '已到店', '确定到店', '确认到店', '7'], 'state' => '已到店'],
- ['n' => 8, 'chaos' => [8, '已量房', '确定量房', '确认量房', '8'], 'state' => '已量房'],
- ['n' => 9, 'chaos' => [9, '到场', '已到场', '确定到场', '确认到场', '9'], 'state' => '已到场'],
- ['n' => 10, 'chaos' => [10, '未到访', 10], 'state' => '未到访'],
- ['n' => 11, 'chaos' => [11, '无效', '11'], 'state' => '无效'],
- ['n' => 12, 'chaos' => [12, '未到店', '12'], 'state' => '未到店'],
- ['n' => 13, 'chaos' => [13, '未量房', '13'], 'state' => '未量房'],
- ['n' => 14, 'chaos' => [14, '未到场', '14'], 'state' => '未到场'],
- ['n' => 15, 'chaos' => [15, '已卖卡', '15', '无忧'], 'state' => '无忧']
- ];
- public function getStateAttr($value)
- {
- if (is_numeric($value)) $value = intval($value);
- foreach (static::$states as $s) {
- if ($value === $s['n'] || in_array($value, $s['chaos'], true)) return $s['state'];
- }
- return '';
- }
- public function setStateAttr($value)
- {
- if (is_numeric($value)) $value = intval($value);
- foreach (static::$states as $s) {
- if ($value === $s['n'] || in_array($value, $s['chaos'], true)) return $s['n'];
- }
- return 1;
- }
- /**
- * 变更跟踪记录中的查询条件
- */
- public static function changeState($state, $type = 'state')
- {
- if (is_array($state) && count($state) == 3) {
- if ($state[0] !== 'state') return $state;
- if ($state[1] == '=') $state[1] = 'in';
- foreach (static::$states as $s) {
- if (in_array($state[2], $s['chaos'], true)) $state[2] = $s['chaos'];
- }
- return $state;
- } else {
- foreach (static::$states as $s) {
- if (in_array($state, $s['chaos'], true)) return $s[$type];
- }
- return $type == 'chaos' ? [] : '';
- }
- }
- public function customer()
- {
- return $this->belongsTo(Customer::class);
- }
- /**
- * 交定凭证
- */
- public function getDeliveryImgAttr($value)
- {
- if (empty($value)) return [];
- $ali_oss_bindurl = config('app.ali_oss_bindurl');
- $value = explode(',', $value);
- if (!is_array($value))
- $value = [$value];
- foreach ($value as &$it) {
- $it = 'https://' . $ali_oss_bindurl . '/' . $it;
- }
- return $value;
- }
- /**
- * 签单凭证
- */
- public function getSignImgAttr($value)
- {
- if (empty($value)) return [];
- $ali_oss_bindurl = config('app.ali_oss_bindurl');
- $value = explode(',', $value);
- if (!is_array($value))
- $value = [$value];
- foreach ($value as &$it) {
- $it = 'https://' . $ali_oss_bindurl . '/' . $it;
- }
- return $value;
- }
- /**
- * 记录扩展字段修改的图片处理
- */
- public function getSavePortraitFieldAttr($value)
- {
- if (empty($value)) return $value;
- $saveall = json_decode($value, true);
- foreach ($saveall as $key => $val) {
- if ($val['type'] == 6) {
- $arr = explode(',', $val['value']);
- $domain = config('app.ali_oss_bindurl');
- $fields = '';
- foreach ($arr as $item) {
- $fields .= 'https://' . $domain . '/' . $item . ',';
- }
- $saveall[$key]['value'] = trim($fields, ',');
- $saveall[$key]['valname'] = trim($fields, ',');
- }
- }
- return json_encode($saveall);
- }
- /**
- * 下次回访时间处理
- */
- public function getNextContactDateAttr($value,$data)
- {
- $cusdata = Customer::with(['org'])->where('id',$data['customer_id'])->find();
- if(empty($cusdata['org'])) return $value;
- $orgids = explode('-',rtrim($cusdata['org']['path'],'-'));
- $root_id = $orgids[0];
- $is_set = Setting::where([['root_id','=',$root_id],['name','=','nextVisitTimeIsOk']])->value('content');
- if(!$is_set){
- $value = $value ? $value : '暂未设置下次回访时间';
- }
- return $value;
- }
- }
|