| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- // +----------------------------------------------------------------------
- // | 商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2017~2021 https://www.thinkphp.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
- // +----------------------------------------------------------------------
- // | Author: thinkphp <admin@yiovo.com>
- // +----------------------------------------------------------------------
- declare (strict_types=1);
- namespace app\common\model;
- use app\api\validate\user\EducationExp;
- use cores\BaseModel;
- use think\model\relation\HasOne;
- /**
- * 学生教育经历模型类
- * Class StudentEduexp
- * @package app\common\model
- */
- class StudentEduexp extends BaseModel
- {
- protected $globalScope = [''];
- // 定义表名
- protected $name = 'student_eduexp';
- // 定义主键
- protected $pk = 'id';
- /**
- * 获取凭证图片
- * @param string $value
- * @return string
- */
- public function getCertifyImgAttr(string $value): string
- {
- return $value? getPreview($value) :'';
- }
- /**
- * 获取用户最近的教育经历
- * @param $userId
- * @return StudentEduexp|array|mixed|\think\Model|null
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public static function getInfoByUser($userId)
- {
- if($userId<=0){
- return false;
- }
- return self::where(['user_id'=> $userId])->order('id desc')->find();
- }
- /**
- * @param $params
- * @return bool
- * @throws \cores\exception\BaseException
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function setData($params)
- {
- $validate = new EducationExp();
- if(!$validate->check($params)){
- throwError($validate->getError());
- }
- $userInfo = \app\api\service\User::getCurrentLoginUser(true);
- $userId = isset($userInfo['user_id'])? intval($userInfo['user_id']) : 0;
- $info = self::getInfoByUser($userId);
- $certifyImg = isset($params['certify_img'])? $params['certify_img'] : '';
- if($info && $info['status'] == 2 && $checkModify = self::checkModify($params, $info) && empty($certifyImg)){
- throwError('您已修改过信息,请先上传凭证');
- }
- $data = [
- 'user_id'=> $userId,
- 'education'=> isset($params['education'])? $params['education'] : '',
- 'school_name'=> isset($params['school_name'])? $params['school_name'] : '',
- 'speciality'=> isset($params['speciality'])? $params['speciality'] : '',
- 'grade'=> isset($params['grade'])? $params['grade'] : '',
- 'status'=> 1,
- ];
- if($certifyImg){
- $data['certify_img'] = $certifyImg;
- }
- if($info){
- return $info->save($data);
- }else{
- return self::save($data);
- }
- }
- /**
- * 验证是否修改过内容
- * @param $params
- * @param $info
- * @return bool
- */
- public static function checkModify($params, $info)
- {
- foreach ($params as $k => $v){
- if($k != 'certify_img' && isset($info[$k]) && $info[$k] != $v){
- return true;
- }
- }
- return false;
- }
- }
|