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; } }