hasOne(UserAuth::class, 'user_id'); } /** * @notes 搜索器-用户信息 * @param $query * @param $value * @param $data * @author 段誉 * @date 2022/9/22 16:12 */ public function searchKeywordAttr($query, $value, $data) { if ($value) { $query->where('sn|nickname|mobile', 'like', '%' . $value . '%'); } } /** * @notes 搜索器-注册来源 * @param $query * @param $value * @param $data * @author 段誉 * @date 2022/9/22 16:13 */ public function searchChannelAttr($query, $value, $data) { if ($value) { $query->where('channel', '=', $value); } } /** * @notes 搜索器-注册时间 * @param $query * @param $value * @param $data * @author 段誉 * @date 2022/9/22 16:13 */ public function searchCreateTimeStartAttr($query, $value, $data) { if ($value) { $query->where('create_time', '>=', strtotime($value)); } } /** * @notes 搜索器-注册时间 * @param $query * @param $value * @param $data * @author 段誉 * @date 2022/9/22 16:13 */ public function searchCreateTimeEndAttr($query, $value, $data) { if ($value) { $query->where('create_time', '<=', strtotime($value)); } } /** * @notes 头像获取器 - 用于头像地址拼接域名 * @param $value * @return string * @author Tab * @date 2021/7/17 14:28 */ public function getAvatarAttr($value) { return trim($value) ? FileService::getFileUrl($value) : ''; } /** * @notes 获取器-性别描述 * @param $value * @param $data * @return string|string[] * @author 段誉 * @date 2022/9/7 15:15 */ // public function getSexAttr($value, $data) // { // return UserEnum::getSexDesc($value); // } /** * @notes 登录时间 * @param $value * @return string * @author 段誉 * @date 2022/9/23 18:15 */ public function getLoginTimeAttr($value) { return $value ? date('Y-m-d H:i:s', $value) : ''; } /** * @notes 生成用户编码 * @param string $prefix * @param int $length * @return string * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author 段誉 * @date 2022/9/16 10:33 */ public static function createUserSn($prefix = '', $length = 8) { $rand_str = ''; for ($i = 0; $i < $length; $i++) { $rand_str .= mt_rand(0, 9); } $sn = $prefix . $rand_str; if (User::where(['sn' => $sn])->find()) { return self::createUserSn($prefix, $length); } return $sn; } public function admin() { return $this->hasOne(Admin::class, 'id', 'admin_id')->field('id,name,company_id,avatar'); } public function company() { return $this->hasOne(Company::class, 'id', 'company_id')->field(['id','company_name','admin_id','company_type','responsible_area', 'area_manager']); } public function getProvinceNameAttr($value) { return Db::name('geo_province')->where(['province_code' => $this->province])->value('province_name'); } public function getCityNameAttr($value) { return Db::name('geo_city')->where(['city_code' => $this->city])->value('city_name'); } public function getAreaNameAttr($value) { return Db::name('geo_area')->where(['area_code' => $this->area])->value('area_name'); } public function getStreetNameAttr($value) { return Db::name('geo_street')->where(['street_code' => $this->street])->value('street_name'); } public function getVillageNameAttr($value) { return Db::name('geo_village')->where(['village_code' => $this->village])->value('village_name'); } public function getBrigadeNameAttr($value) { return Db::name('geo_brigade')->where('id' ,$this->brigade)->value('brigade_name'); } public function getContractAttr(){ $find= Contract::where('type',2)->where('party_b',$this->id)->field('id,party_a,party_b,check_status')->find(); if($find){ return $find->toArray(); }else{ return []; } } // 查询镇合伙人服务部长 public function searchServiceManager($companyId) { return User::where(['company_id' => $companyId, 'group_id'=> 14])->find(); } // 查询镇合伙人负责人 public function searchMaster($companyId) { return User::where(['company_id' => $companyId, 'group_id'=> 15])->find(); } // 查询镇合伙人市场部长 public function searchMarketingManager($companyId) { return User::where(['company_id' => $companyId, 'group_id'=> 16])->find(); } // 查询村联络员 public function searchLiaisonMan($companyId) { return User::where(['company_id' => $companyId, 'group_id'=> 17])->find(); } }