'编号', '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' => '客户状态', 'member_label' => '资源标签' ]; 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 ''; } } /** * 获取决策人类型名称 * @param $value * @param $data * @return array|mixed|string */ public function getDecisionMakerNameAttr($value, $data) { $key = 'decision_maker'; $val = (String)$data['decision_maker'] ?? ''; if ((!empty($val) || isset($val)) && $val !== '') { $dict = Dict::where('key',$key)->find(); $dictionary = $dict['dictionary'] ?? []; // 查找匹配的 name $res = $val; foreach ($dictionary as $item) { if ($item['value'] == $val) { $res = $item['name']; break; } } return $res; } else { return $val; } } }