hasOne(Personnel::class, 'id', 'staff_id')->joinType('left')->withField('name,id')->bind(['staff_id_name'=>'name']); } public function customerResources(){ return $this->hasOne(CustomerResources::class, 'id', 'resource_id')->joinType('left')->withField('name,id')->bind(['resource_id_name'=>'name']); } /** * 获取需求购买力类型名称 * @param $value * @param $data * @return array|mixed|string */ public function getPurchasePowerNameAttr($value, $data) { $key = 'customer_purchasing_power'; $val = (String)$data['purchase_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 getConceptAwarenessNameAttr($value, $data) { $key = 'customer_purchasing_power'; $val = (String)$data['concept_awareness']; 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 ''; } } }