where("name", $value); } } /** * 搜索器:客户资源联系电话 * @param $value * @param $data */ public function searchPhoneNumberAttr($query, $value, $data) { if ($value) { $query->where("phone_number", $value); } } //获取顾问名字 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'); } /** * 获取客户初步意向度类型名称 * @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 ''; } } }