UserSubsidies.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 UserSubsidies extends Model
  8. {
  9. public function add(){
  10. $data = [
  11. 'id' => input('id/d',0),
  12. 'title' => input('title','','trim'),
  13. 'name' => input('name','','trim'),
  14. 'type' => input('type/d',1),
  15. 'cate' => input('cate/d',1),
  16. 'values' => input('values','','trim'),
  17. 'money' => input('money/f',0),
  18. 'remark' => input('remark','','trim'),
  19. 'pay_type' => input('payType/d',1),
  20. 'gender' => input('gender/d',0),
  21. 'sorts' => input('sorts/d',0),
  22. 'prop' => input('prop/d',1),
  23. 'sbtype' => input('sbtype/d',0)
  24. ];
  25. $result = validate('UserSubsidies')->check($data,[],'');
  26. if(true !== $result){
  27. HelpHander::error(validate('UserSubsidies')->getError());
  28. }
  29. $id = $data['id'];
  30. unset($data['id']);
  31. if($id > 0){
  32. $data['update_time'] = date('Y-m-d H:i:s');
  33. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  34. }else{
  35. $data['create_time'] = date('Y-m-d H:i:s');
  36. $ret = $this->allowField(true)->save($data);
  37. }
  38. if(!$ret){
  39. HelpHander::error('操作失败');
  40. }
  41. return true;
  42. }
  43. public function info($id){
  44. $info = $this->where('id',$id)->find();
  45. if(!$info){
  46. HelpHander::error('数据不存在');
  47. }
  48. $data = $info->toArray();
  49. return $data;
  50. }
  51. public function lists($page,$size,$title,$payType){
  52. if($title != ''){
  53. $map[] = ['title','like','%'.$title.'%'];
  54. }
  55. $map[] = ['pay_type','=',$payType];
  56. $map[] = ['del','=',0];
  57. $lists = Db::name('user_subsidies')
  58. ->where($map)
  59. ->page($page,$size)
  60. ->select();
  61. $total = Db::name('user_subsidies')->where($map)->count();
  62. $data = [
  63. 'total' => $total,
  64. 'list' => $lists?$lists:[]
  65. ];
  66. return $data;
  67. }
  68. public function all(){
  69. $map[] = ['del','=',0];
  70. $lists = Db::name('user_subsidies')
  71. ->where($map)
  72. ->order('sorts asc,id asc')
  73. ->select();
  74. return $lists?$lists:[];
  75. }
  76. public function del($id){
  77. $ret = $this->where('id',$id)->setField('del',1);
  78. if(!$ret){
  79. HelpHander::error('删除失败');
  80. }
  81. return true;
  82. }
  83. }