LuckdrawPrize.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace app\data\controller;
  3. use think\admin\Controller;
  4. use think\admin\extend\CodeExtend;
  5. /**
  6. * 活动奖品管理
  7. * Class LuckdrawPrize
  8. * @package app\data\controller
  9. */
  10. class LuckdrawPrize extends Controller
  11. {
  12. /**
  13. * 绑定数据表
  14. * @var string
  15. */
  16. protected $table = 'ActivityLuckdrawPrize';
  17. /**
  18. * 活动奖品管理
  19. * @auth true
  20. * @menu true
  21. * @throws \think\Exception
  22. * @throws \think\db\exception\DataNotFoundException
  23. * @throws \think\db\exception\ModelNotFoundException
  24. * @throws \think\exception\DbException
  25. * @throws \think\exception\PDOException
  26. */
  27. public function index()
  28. {
  29. $this->title = '活动奖品管理';
  30. $query = $this->_query($this->table)->like('code,name');
  31. $query->equal('status')->dateBetween('create_at')->page();
  32. }
  33. /**
  34. * 添加活动奖品
  35. * @auth true
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\DbException
  38. * @throws \think\db\exception\ModelNotFoundException
  39. */
  40. public function add()
  41. {
  42. $this->_form($this->table, 'form', 'code');
  43. }
  44. /**
  45. * 编辑活动奖品
  46. * @auth true
  47. * @throws \think\db\exception\DataNotFoundException
  48. * @throws \think\db\exception\DbException
  49. * @throws \think\db\exception\ModelNotFoundException
  50. */
  51. public function edit()
  52. {
  53. $this->_form($this->table, 'form', 'code');
  54. }
  55. /**
  56. * 表单数据处理
  57. * @param array $data
  58. */
  59. protected function _form_filter(array &$data)
  60. {
  61. $data['code'] = $data['code'] ?? CodeExtend::uniqidNumber(16, 'P');
  62. }
  63. /**
  64. * 修改奖品状态
  65. * @auth true
  66. * @throws \think\db\exception\DbException
  67. */
  68. public function state()
  69. {
  70. $this->_save($this->table, $this->_vali([
  71. 'status.in:0,1' => '状态值范围异常!',
  72. 'status.require' => '状态值不能为空!',
  73. ]));
  74. }
  75. /**
  76. * 删除活动奖品
  77. * @auth true
  78. * @throws \think\db\exception\DbException
  79. */
  80. public function remove()
  81. {
  82. $this->_delete($this->table);
  83. }
  84. }