UserSchool.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Exception;
  6. use think\Model;
  7. class UserSchool extends Model
  8. {
  9. public function add(){
  10. $data = [
  11. 'id' => input('id/d',0),
  12. 'user_id' => input('uid/d',0),
  13. 'start' => input('start','','trim'),
  14. 'end' => input('end','','trim'),
  15. 'xueli' => input('xueli','','trim'),
  16. 'school' => input('school','','trim'),
  17. 'county' => input('county','','trim'),
  18. 'degree' => input('degree','','trim'),
  19. 'professional' => input('professional','','trim'),
  20. 'type' => input('type/d',1),
  21. 'xueli_sn' => input('xueliSn','','trim'),
  22. 'degree_sn' => input('degreeSn','','trim'),
  23. ];
  24. $result = validate('UserSchool')->check($data,[],'');
  25. if(true !== $result){
  26. HelpHander::error(validate('UserSchool')->getError());
  27. }
  28. $id = $data['id'];
  29. unset($data['id']);
  30. if($id > 0){
  31. $data['update_time'] = date('Y-m-d H:i:s');
  32. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  33. }else{
  34. $data['create_time'] = date('Y-m-d H:i:s');
  35. $ret = $this->allowField(true)->save($data);
  36. }
  37. if(!$ret){
  38. HelpHander::error('操作失败');
  39. }
  40. return true;
  41. }
  42. public function info($id){
  43. $info = $this->where('id',$id)->find();
  44. if(!$info){
  45. HelpHander::error('数据不存在');
  46. }
  47. $data = $info->toArray();
  48. return $data;
  49. }
  50. public function lists($page,$size,$uid){
  51. $lists = Db::name('user_school')
  52. ->where('user_id',$uid)
  53. ->page($page,$size)
  54. ->order('id desc')
  55. ->select();
  56. $total = Db::name('user_school')->where('user_id',$uid)->count();
  57. $data = [
  58. 'total' => $total,
  59. 'list' => $lists?$lists:[]
  60. ];
  61. return $data;
  62. }
  63. public function del($id){
  64. $ret = $this->where('id',$id)->delete();
  65. if(!$ret){
  66. HelpHander::error('删除失败');
  67. }
  68. return true;
  69. }
  70. }