Company.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\logic\CompanyLogic;
  4. use app\BaseController;
  5. use think\exception\ValidateException;
  6. use think\facade\Config;
  7. use think\facade\Validate;
  8. //企业
  9. class Company extends BaseController
  10. {
  11. //获取企业列表
  12. public function list()
  13. {
  14. $param = $this->request->only([
  15. 'page' => 1,
  16. 'size' => 10,
  17. 'title' => '',
  18. 'contacts' => '',
  19. 'mobile' => '',
  20. 'status' => '',
  21. ], 'post');
  22. return CompanyLogic::list($param);
  23. }
  24. //获取全部企业
  25. public function all()
  26. {
  27. $keyword = $this->request->post('keyword', '');
  28. return CompanyLogic::all($keyword);
  29. }
  30. //添加企业
  31. public function add()
  32. {
  33. $param = $this->request->only(['title', 'contacts', 'mobile', 'remark' => '',], 'post');
  34. $val = Validate::rule(Config::get('validate_rules.CompanyAdd'));
  35. if (!$val->check($param)) throw new ValidateException($val->getError());
  36. return CompanyLogic::add($param);
  37. }
  38. //读取企业详情
  39. public function read()
  40. {
  41. $id = $this->request->post('id/d', 0);
  42. return CompanyLogic::read($id);
  43. }
  44. //编辑企业
  45. public function edit()
  46. {
  47. $param = $this->request->only(['id', 'title', 'contacts', 'mobile', 'remark' => '',], 'post');
  48. $val = Validate::rule(array_merge(Config::get('validate_rules.CompanyAdd'), ['id' => 'require|number|gt:0']));
  49. if (!$val->check($param)) throw new ValidateException($val->getError());
  50. return CompanyLogic::edit($param);
  51. }
  52. //企业启禁用
  53. public function status()
  54. {
  55. $param = $this->request->only(['id', 'status'], 'post');
  56. $val = Validate::rule(Config::get('validate_rules.status'));
  57. if (!$val->check($param)) throw new ValidateException($val->getError());
  58. return CompanyLogic::status($param);
  59. }
  60. //删除企业
  61. public function delete()
  62. {
  63. $id = $this->request->post('id/d', 0);
  64. return CompanyLogic::delete($id);
  65. }
  66. }