'编号', 'purchase_power' => '需求购买力', 'concept_awareness' => '认知理念', 'preferred_class_time' => '可选上课时间', 'distance' => '距离', 'communication' => '沟通备注', 'promised_visit_time' => '承诺到访时间', 'actual_visit_time' => '实际到访时间', 'call_intent' => '电话后的意向程度', 'first_visit_status' => '一访情况', 'second_visit_status' => '二访情况', 'is_closed' => '是否关单', 'staff_id' => '人员ID', 'resource_id' => '资源ID', 'created_at' => '创建时间', 'updated_at' => '更新时间', 'deleted_at' => '逻辑删除时间' ]; public function personnel(){ return $this->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 !== '') { $dictionary = $this->getDictionaryData($key); // 查找匹配的 name $res = ''; foreach ($dictionary as $item) { if ($item['value'] == $val) { $res = $item['name']; break; } } return $res; } else { return ''; } } /** * 获取字典数据的辅助方法 * @param string $key * @return array */ private function getDictionaryData($key) { $dict = \think\facade\Db::table('school_sys_dict')->where('key', $key)->find(); $dictionary = []; if ($dict && !empty($dict['dictionary'])) { // 数据库中的字段是双层JSON编码,需要两次解码 $jsonString = json_decode($dict['dictionary'], true); if (is_string($jsonString)) { $dictionary = json_decode($jsonString, true) ?: []; } else { $dictionary = $jsonString ?: []; } } return $dictionary; } /** * 获取认知理念类型名称 * @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 !== '') { $dictionary = $this->getDictionaryData($key); // 查找匹配的 name $res = ''; foreach ($dictionary as $item) { if ($item['value'] == $val) { $res = $item['name']; break; } } return $res; } else { return ''; } } }