'正常', 1=>'已售', 2=>'已下架', 3=>'禁止下单', ]; protected $append=[ 'saled', ]; protected $autoWriteTimestamp='int'; protected $hidden=[ 'filter_exists_0','filter_num_0','filter_num_1','filter_num_2','filter_num_3','filter_num_4','filter_num_5','filter_num_6','filter_num_7', 'filter_num_8','filter_num_9','filter_middle_3a','filter_middle_4a','filter_middle_5a','filter_middle_6a','filter_middle_7a','filter_middle_8a', 'filter_middle_abc','filter_middle_abcd','filter_middle_abcde','filter_middle_abcdef','filter_middle_3ab','filter_middle_4ab','filter_middle_5ab', 'filter_no_pos_2','filter_no_pos_3','filter_no_pos_4','filter_no_pos_5','filter_no_pos_6','filter_no_pos_7','filter_no_pos_8','filter_no_pos_9', 'filter_no_pos_10','filter_no_pos_11','filter_tail_3a','filter_tail_4a','filter_tail_5a','filter_tail_6a','filter_tail_7a','filter_tail_8a', 'filter_tail_abc','filter_tail_abcd','filter_tail_abcde','filter_tail_abcdef','filter_tail_3ab','filter_tail_4ab','filter_tail_5ab', 'filter_exists_2','filter_exists_3','filter_exists_4','filter_exists_5','filter_exists_6','filter_exists_7','filter_exists_8','filter_exists_9', ]; public function info(){ return $this->hasOne(MobileInfo::class); } public function orders(){ return $this->hasMany(MobileOrder::class); } public function proxy(){ return $this->belongsTo(Admin::class,'proxy_id'); } public function getSaledAttr($a,$b){ $s=$b['status']??0; return $s===1?1:0; } public static function init() { self::beforeWrite(function (self $mobile){ if(empty($mobile['amount_base'])){ $mobile['amount_base']=0; } if(empty($mobile['amount_charge'])){ $mobile['amount_charge']=0; } if(!isset($mobile['is_activity'])){ $mobile['is_activity']=0; } if(!$mobile['is_activity']) { $mobile['amount'] = $mobile['amount_base'] + $mobile['amount_charge']; }else{ $mobile['amount'] = $mobile['amount_kill'] + $mobile['amount_charge']; } if(isset($mobile['top_time']) && $mobile['top_time']==1){ $mobile['top_time']=time(); }else{ $mobile['top_time']=null; } if(isset($mobile['rec_time']) && $mobile['rec_time']==1){ $mobile['rec_time']=time(); }else{ $mobile['rec_time']=null; } if(isset($mobile->getChangedData()['is_activity']) && $mobile->getChangedData()['is_activity']==1){ self::where('id','>',0)->update(['activity_time'=>null]); $mobile['activity_time']=time(); } foreach (MobileComputer::setMobile($mobile['no'])->filter() as $key=>$value){ $mobile[$key]=$value; } }); self::afterInsert(function (self $mobile){ /*if(!$mobile->info()->find()){ $mobile->info()->save([]); }*/ }); self::beforeInsert(function (self $mobile){ $mobile['sort']=mt_rand(0,99999999); if(empty($mobile['province_id'])){ $mobile['province_id']=Area::getIdByName($mobile['province']); } if(empty($mobile['city_id'])){ $mobile['city_id']=Area::getIdByName($mobile['city']); } if(!empty($mobile['province_id'])){ $mobile['province']=Area::where('id',$mobile['province_id'])->value('name'); } if(!empty($mobile['city_id'])){ $mobile['city']=Area::where('id',$mobile['city_id'])->value('name'); } }); } public static function show(){ $model=new self(); $model->with(['info']); $model->where('status','<>',2); return $model; } /** *@param self $mobile */ public static function whenOrderPayed($mobile){ if($mobile){ $mobile['status']=1; $mobile->save(); } } public function shouldBuy(){ if($this['status']!=0){ throw_user('该靓号已售或不存在'); } } }