$sn])->find()) { return self::createUserSn($prefix, $length); } return $sn; } public function workerRegister() { return $this->hasOne(MasterWorkerRegister::class, 'worker_id', 'id'); } public function workerInfo() { return $this->hasOne(MasterWorkerInfo::class, 'worker_id', 'id'); } public function getRetentionMoneyStatusTextAttr($value,$data):string{ $default = Cache::get('RETENTION_MONEY_STATUS'); if (!$default) { $status = DictData::whereIn('type_value', 'retention_money_status')->column('name','value'); Cache::set('RETENTION_MONEY_STATUS', json_encode($status,true),5); } else { $status = json_decode($default,true); } return $status[$data['retention_money_status']] ?? ''; } public function getRetentionPayStatusTextAttr($value,$data):string{ $default = Cache::get('RETENTION_PAY_STATUS'); if (!$default) { $status = DictData::whereIn('type_value', 'retention_pay_status')->column('name','value'); Cache::set('RETENTION_PAY_STATUS', json_encode($status,true),5); } else { $status = json_decode($default,true); } return $status[$data['retention_pay_status']] ?? ''; } /** * @param $type [inc=新增,dec=减少] * @param $worker_id * @return bool * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public static function setWorktotal($type,$worker_id) { $worker = MasterWorker::where('id',$worker_id)->findOrEmpty(); if($type == 'inc'){ $worker->inc('work_total',1); }else{ $work_total = $worker->work_total == 0?0:1; $worker->dec('work_total',$work_total); } $worker->save(); return true; } public function getTimePeriodAttr($value) { return explode(',',$value); } public function getAvatarAttr($value) { return trim($value) ? FileService::getFileUrl($value) : ''; } public function getRealAvatarAttr($value) { return trim($value) ? FileService::getFileUrl($value) : ''; } public function workerAgree() { return $this->hasOne(MasterWorkerAgree::class, 'worker_id', 'id'); } public function bankAccount() { return $this->hasOne(BankAccount::class, 'worker_id', 'id'); } public function getLabelsAttr($value) { return $value?array_map(function($item){ return (int)$item; },explode(',',$value)):[]; } }