Service.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\logic\ServiceLogic;
  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 Service extends BaseController
  11. {
  12. //获取服务列表
  13. public function list()
  14. {
  15. $param = $this->request->only(['page' => 1, 'size' => 10, 'status' => '', 'activity_status' => '', 'company_title' => '', 'card_title' => ''], 'post');
  16. return ServiceLogic::list($param);
  17. }
  18. //添加服务
  19. public function add()
  20. {
  21. $param = $this->request->only(['company_id', 'card_id', 'original_price', 'activity_price', 'title', 'content', 'starttime', 'endtime', 'expiretime', 'remark' => ''], 'post');
  22. $val = Validate::rule(Config::get('validate_rules.ServiceAdd'));
  23. if (!$val->check($param)) throw new ValidateException($val->getError());
  24. return ServiceLogic::add($param);
  25. }
  26. //获取服务详情
  27. public function read()
  28. {
  29. $id = $this->request->post('id/d', 0);
  30. return ServiceLogic::read($id);
  31. }
  32. //编辑服务
  33. public function edit()
  34. {
  35. $param = $this->request->only(['id', 'company_id', 'card_id', 'original_price', 'activity_price', 'title', 'content', 'starttime', 'endtime', 'expiretime'], 'post');
  36. $val = Validate::rule(array_merge(Config::get('validate_rules.ServiceAdd'), ['id|服务id' => 'require|number|gt:0']));
  37. if (!$val->check($param)) throw new ValidateException($val->getError());
  38. return ServiceLogic::edit($param);
  39. }
  40. //服务上下架
  41. public function status()
  42. {
  43. $param = $this->request->only(['id', 'status'], 'post');
  44. $val = Validate::rule(Config::get('validate_rules.status'));
  45. if (!$val->check($param)) throw new ValidateException($val->getError());
  46. return ServiceLogic::status($param);
  47. }
  48. //删除服务
  49. public function delete()
  50. {
  51. $ids = $this->request->post('id/a', []);
  52. return ServiceLogic::delete($ids);
  53. }
  54. }