CompanyGood.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\logic\CompanyGoodLogic;
  4. use app\BaseController;
  5. use app\model\CommonModel;
  6. use think\exception\ValidateException;
  7. use think\facade\Config;
  8. use think\facade\Validate;
  9. //【公司商品】
  10. class CompanyGood extends BaseController
  11. {
  12. //列表
  13. public function list()
  14. {
  15. $param = $this->request->only(['group_id' => '', 'page' => 1, 'size' => 10, 'good_name' => '', 'good_code' => '', 'status' => ''], 'post');
  16. $val = Validate::rule([
  17. 'group_id|分组id' => 'number|gt:0',
  18. 'page|页码' => 'require|number|gt:0',
  19. 'size|每页数量' => 'require|number|elt:100',
  20. 'good_name|商品名称' => 'number|elt:100',
  21. 'good_cood|商品编码' => 'number|elt:100',
  22. 'status|状态' => 'number|in:' . CommonModel::$status_normal . ',' . CommonModel::$status_disable,
  23. ]);
  24. if (!$val->check($param)) throw new ValidateException($val->getError());
  25. return CompanyGoodLogic::list($param);
  26. }
  27. //添加
  28. public function add()
  29. {
  30. $param = $this->request->only(['group_id', 'good_id', 'is_top' => CommonModel::$top_no, 'weight' => 0], 'post');
  31. $val = Validate::rule(Config::get('validate_rules.CompanyGoodAdd'));
  32. if (!$val->check($param)) throw new ValidateException($val->getError());
  33. return CompanyGoodLogic::add($param);
  34. }
  35. //详情
  36. public function read()
  37. {
  38. $id = $this->request->post('id/d', 0);
  39. return CompanyGoodLogic::read($id);
  40. }
  41. //编辑
  42. public function edit()
  43. {
  44. $param = $this->request->only(['id','group_id', 'good_id', 'is_top' => CommonModel::$top_no, 'weight' => 0], 'post');
  45. $val = Validate::rule(array_merge(Config::get('validate_rules.CompanyGoodAdd'),[
  46. 'id|公司商品id' => 'require|number|gt:0',
  47. ]));
  48. if (!$val->check($param)) throw new ValidateException($val->getError());
  49. return CompanyGoodLogic::edit($param);
  50. }
  51. //删除
  52. public function delete()
  53. {
  54. $ids = $this->request->post('id/a', []);
  55. return CompanyGoodLogic::delete($ids);
  56. }
  57. //置顶
  58. public function top()
  59. {
  60. $param = $this->request->only(['id', 'is_top'], 'post');
  61. $val = Validate::rule([
  62. 'id' => 'require|number|gt:0',
  63. 'is_top|是否置顶' => 'require|number|in:' . CommonModel::$top_no . ',' . CommonModel::$top_yes,
  64. ]);
  65. if (!$val->check($param)) throw new ValidateException($val->getError());
  66. return CompanyGoodLogic::top($param);
  67. }
  68. //启禁用
  69. public function status()
  70. {
  71. $param = $this->request->only(['id', 'status'], 'post');
  72. $val = Validate::rule(Config::get('validate_rules.status'));
  73. if (!$val->check($param)) throw new ValidateException($val->getError());
  74. return CompanyGoodLogic::status($param);
  75. }
  76. }