hasOne(Staff::class, 'id', 'create_staff_id')->field('id,img,name,post'); } //已读 public function read(){ return $this->hasMany(DailyRead::class, 'daily_id', 'id')->field('daily_id,createtime'); } /** * @desc 备注 * @update_date 2021/6/9 更新时间 * @author zhangwei */ public static function createDaily($params) { //自定义字段 $other = []; foreach ($params as $name => $val) { if (strstr( $name,'other_') !== false) { if(is_array($val)){ $other[$name] = implode(',',$val); }else{ $other[$name] = $val; } unset($params[$name]); } } $params['other']=json_encode($other); $model = new self; // 调用当前模型对应的User验证器类进行数据验证 $result = $model->allowField(true)->save($params); if (false === $result) { // 验证失败 输出错误信息 throw new Exception($model->getError()); } $lastId=$model->getLastInsID(); if (isset($params['reminds_id'])) {//发送通知 $staff_ids = explode(',', $params['reminds_id']); foreach ($staff_ids as $staff_id) { //发送通知 Message::addMessage(Message::DAILY_TYPE, $lastId, $staff_id, $params['create_staff_id']); } } return $lastId; } /** * 修改 * @param $params * @return string * @throws Exception */ public static function updateDaily($params) { //自定义字段 $other = []; foreach ($params as $name => $val) { if (strstr( $name,'other_') !== false) { if(is_array($val)){ $other[$name] = implode(',',$val); }else{ $other[$name] = $val; } unset($params[$name]); } } $params['other']=json_encode($other); if(isset($params['reminds_id'])){ unset($params['reminds_id']); } $model = new self; // 调用当前模型对应的User验证器类进行数据验证 $result = $model->allowField(true)->save($params,['id'=>$params['id']]); if (false === $result) { // 验证失败 输出错误信息 throw new Exception($model->getError()); } $lastId=$model->getLastInsID(); $where['create_staff_id'] = $params['create_staff_id']; $where['type'] = $params['type']; DailyDraft::where($where)->update(array('deletetime'=>time())); return $lastId; } public static function getTypeName($types) { switch($types){ case '日报': $typeinfo ='daily'; break; case '周报': $typeinfo ='weekly'; break; case '月报': $typeinfo ='monthly'; break; case '季报': $typeinfo ='quarterly'; break; case '年报': $typeinfo ='yearly'; break; default: $typeinfo ='daily'; break; } return $typeinfo; } }