UserReward.php 1.9 KB

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