CompanyGood.php 3.0 KB

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