123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Exception;
- use think\Model;
- class UserSchool extends Model
- {
- public function add(){
- $data = [
- 'id' => input('id/d',0),
- 'user_id' => input('uid/d',0),
- 'start' => input('start','','trim'),
- 'end' => input('end','','trim'),
- 'xueli' => input('xueli','','trim'),
- 'school' => input('school','','trim'),
- 'county' => input('county','','trim'),
- 'degree' => input('degree','','trim'),
- 'professional' => input('professional','','trim'),
- 'type' => input('type/d',1),
- 'xueli_sn' => input('xueliSn','','trim'),
- 'degree_sn' => input('degreeSn','','trim'),
- ];
- $result = validate('UserSchool')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('UserSchool')->getError());
- }
- $id = $data['id'];
- unset($data['id']);
- if($id > 0){
- $data['update_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- }else{
- $data['create_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data);
- }
- if(!$ret){
- HelpHander::error('操作失败');
- }
- return true;
- }
- public function info($id){
- $info = $this->where('id',$id)->find();
- if(!$info){
- HelpHander::error('数据不存在');
- }
- $data = $info->toArray();
- return $data;
- }
- public function lists($page,$size,$uid){
- $lists = Db::name('user_school')
- ->where('user_id',$uid)
- ->page($page,$size)
- ->order('id desc')
- ->select();
- $total = Db::name('user_school')->where('user_id',$uid)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists:[]
- ];
- return $data;
- }
- public function del($id){
- $ret = $this->where('id',$id)->delete();
- if(!$ret){
- HelpHander::error('删除失败');
- }
- return true;
- }
- }
|