123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- <?php
- namespace App\Models;
- use App\Models\Jobfair\JobfairPutJob;
- use App\Search\Traits\CompanySearchable;
- use Illuminate\Database\Eloquent\SoftDeletes;
- use Illuminate\Foundation\Auth\User;
- class Organization extends User
- {
- use SoftDeletes, CompanySearchable;
- protected $table = 'organization';
- protected $guarded=[''];
- static function getTableName()
- {
- $organization = new Organization();
- return $organization->getTable();
- }
- public function orders()
- {
- return $this->hasMany(Order::class, 'uid', 'id');
- }
- public function service()
- {
- return $this->hasMany(Service::class, 'uid', 'id');
- }
- public function imgs()
- {
- return $this->hasMany(CompanyImg::class, 'company_id');
- }
- public function membersSetmeal()
- {
- return $this->hasOne(MembersSetmeal::class, 'uid');
- }
- public function membersPoints()
- {
- return $this->hasOne(MembersPoint::class, 'uid');
- }
- public static function companyAudit($id, $data)
- {
- return Company::whereIn('id', $id)->update($data);
- }
- public function promotion()
- {
- return $this->belongsTo(Promotion::class, 'id');
- }
- public function getTagAttribute($value)
- {
- return explode(',', $value);
- }
- public function setTagAttribute($value)
- {
- $this->attributes['tag'] = implode(',', $value);
- }
- public function resumes()
- {
- return $this->belongsToMany(Resume::class, 'company_favorites', 'company_id', 'resume_id')->withTimestamps();
- }
- public function subsites()
- {
- return $this->belongsTo(Subsite::class, 'subsite_id');
- }
- public function companyConsultant()
- {
- return $this->hasOne(CompanyConsultant::class,'company_id','id');
- }
- public function toSearchableArray()
- {
- $arr=$this->load(['membersSetmeal'])->toArray();
- $arr['district'] = string_to_array('.', $arr['district']);
- $arr['district_cn'] = string_to_array('/', $arr['district_cn']);
- $arr['trade_cn'] = get_category($arr['trade']);
- foreach ($arr['tag'] as $key => $val) {
- $arr['tag'][$key] = (int)$val;
- }
- foreach ($arr['tag'] as $key => $val) {
- $arr['tag_cn'][$key] =get_category($val);
- }
- $arr['scale_cn'] = get_category($arr['scale']);
- $arr['nature_cn'] = get_category($arr['nature']);
- $arr['location'] = [
- 'lat'=>is_numeric($arr['map_y'])?$arr['map_y']:0,
- 'lon'=>is_numeric($arr['map_y'])?$arr['map_y']:0
- ];
- $arr['subsite_ids'] = [$arr['subsite_id']];
- $audit_num = $this->job()->where(['valid'=>1,'audit'=>1,'display'=>1])->count();
- $wait_audit_num = $this->job()->where(['valid'=>1,'audit'=>2,'display'=>1])->count();
- $arr['job_audit_num'] = $audit_num;
- $arr['job_wait_num'] = $wait_audit_num;
- $arr['job_sum_num'] = (int)$wait_audit_num + (int)($audit_num);
- $new_refresh_job = $this->job()->where(['audit'=>1,'valid'=>1,'display'=>1])->orderBy('refresh_time', 'desc')->first();
- if ($new_refresh_job) {
- $arr['job_new_refresh'] = $new_refresh_job->refresh_time;
- } else {
- $arr['job_new_refresh'] = null;
- }
- unset($arr['password']);
- unset($arr['remember_token']);
- unset($arr['map_x']);
- unset($arr['map_y']);
- unset($arr['map_zoom']);
- unset($arr['map_open']);
- return $arr;
- }
- }
|