GroupItem.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\logic\GroupItemLogic;
  4. use app\BaseController;
  5. use app\model\CommonModel;
  6. use app\model\GroupModel;
  7. use think\exception\ValidateException;
  8. use think\facade\Config;
  9. use think\facade\Validate;
  10. //【分组明细】
  11. class GroupItem extends BaseController
  12. {
  13. //获取分组明细列表
  14. public function list()
  15. {
  16. $param = $this->request->only(['group_id' => 0, 'type' => GroupModel::$type_good, 'page' => 1, 'size' => 10, 'title' => ''], 'post');
  17. $val = Validate::rule([
  18. 'group_id|分组id' => 'require|number|gt:0',
  19. 'type|明细类型' => 'require|number|in:' . GroupModel::$type_good . ',' . GroupModel::$type_video,
  20. 'page|页码' => 'require|number|gt:0',
  21. 'size|每页数量' => 'require|number|elt:100',
  22. ]);
  23. if (!$val->check($param)) throw new ValidateException($val->getError());
  24. return GroupItemLogic::list($param);
  25. }
  26. //添加分组明细
  27. public function add()
  28. {
  29. $param = $this->request->only(['group_id', 'type', 'item_id', 'weight' => 0], 'post');
  30. $val = Validate::rule(Config::get('validate_rules.GroupItemAdd'));
  31. if (!$val->check($param)) throw new ValidateException($val->getError());
  32. return GroupItemLogic::add($param);
  33. }
  34. //获取分组明细详情
  35. public function read()
  36. {
  37. $id = $this->request->post('id/d', 0);
  38. return GroupItemLogic::read($id);
  39. }
  40. //编辑分组明细
  41. public function edit()
  42. {
  43. $param = $this->request->only(['id', 'item_id', 'weight' => 0], 'post');
  44. $val = Validate::rule([
  45. 'id|分组明细id' => 'require|number|gt:0',
  46. 'item_id|明细id' => 'require|number|gt:0',
  47. 'weight|权重' => 'number|egt:0',
  48. ]);
  49. if (!$val->check($param)) throw new ValidateException($val->getError());
  50. return GroupItemLogic::edit($param);
  51. }
  52. //删除分组明细
  53. public function delete()
  54. {
  55. $ids = $this->request->post('id/a', []);
  56. return GroupItemLogic::delete($ids);
  57. }
  58. //置顶
  59. public function top()
  60. {
  61. $param = $this->request->only(['id', 'is_top'], 'post');
  62. $val = Validate::rule([
  63. 'id' => 'require|number|gt:0',
  64. 'is_top|是否置顶' => 'require|number|in:' . CommonModel::$top_no . ',' . CommonModel::$top_yes,
  65. ]);
  66. if (!$val->check($param)) throw new ValidateException($val->getError());
  67. return GroupItemLogic::top($param);
  68. }
  69. }