UserPunishment.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 UserPunishment 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',null,'trim'),
  14. 'type' => input('type','','trim'),
  15. 'company' => input('company','','trim'),
  16. 'remark' => input('remark','','trim'),
  17. 'reason' => input('reason','','trim'),
  18. ];
  19. $result = validate('UserPunishment')->check($data,[],'');
  20. if(true !== $result){
  21. HelpHander::error(validate('UserPunishment')->getError());
  22. }
  23. $id = $data['id'];
  24. unset($data['id']);
  25. if($id > 0){
  26. $data['update_time'] = date('Y-m-d H:i:s');
  27. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  28. }else{
  29. $data['create_time'] = date('Y-m-d H:i:s');
  30. $ret = $this->allowField(true)->save($data);
  31. }
  32. if(!$ret){
  33. HelpHander::error('操作失败');
  34. }
  35. return true;
  36. }
  37. public function info($id){
  38. $info = $this->where('id',$id)->find();
  39. if(!$info){
  40. HelpHander::error('数据不存在');
  41. }
  42. $data = $info->toArray();
  43. return $data;
  44. }
  45. public function lists($page,$size,$uid){
  46. $lists = Db::name('user_punishment')
  47. ->where('user_id',$uid)
  48. ->page($page,$size)
  49. ->order('id desc')
  50. ->select();
  51. $total = Db::name('user_punishment')->where('user_id',$uid)->count();
  52. $data = [
  53. 'total' => $total,
  54. 'list' => $lists?$lists:[]
  55. ];
  56. return $data;
  57. }
  58. public function del($id){
  59. $ret = $this->where('id',$id)->delete();
  60. if(!$ret){
  61. HelpHander::error('删除失败');
  62. }
  63. return true;
  64. }
  65. }