Addr.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\mobile\controller;
  3. //地址
  4. use app\BaseController;
  5. use app\mobile\logic\AddrLogic;
  6. use think\exception\ValidateException;
  7. use think\facade\Config;
  8. use think\facade\Validate;
  9. class Addr extends BaseController
  10. {
  11. //列表
  12. public function list()
  13. {
  14. $param = $this->request->only(['page' => 1, 'size' => 10], 'post');
  15. return AddrLogic::list($param);
  16. }
  17. //添加
  18. public function add()
  19. {
  20. $param = $this->request->only(['addr_code', 'addr', 'contactor', 'mobile'], 'post');
  21. $val = Validate::rule(Config::get('validate_rules.AddrAdd'));
  22. if (!$val->check($param)) throw new ValidateException($val->getError());
  23. return AddrLogic::add($param);
  24. }
  25. //详情
  26. public function read()
  27. {
  28. $id = $this->request->post('id/d', 0);
  29. return AddrLogic::read($id);
  30. }
  31. //修改
  32. public function edit()
  33. {
  34. $param = $this->request->only(['id', 'addr_code', 'addr', 'contactor', 'mobile'], 'post');
  35. $val = Validate::rule(array_merge(Config::get('validate_rules.AddrAdd'), ['id' => 'require|number|gt:0']));
  36. if (!$val->check($param)) throw new ValidateException($val->getError());
  37. return AddrLogic::edit($param);
  38. }
  39. //删除
  40. public function delete()
  41. {
  42. $id = $this->request->post('id/d', 0);
  43. return AddrLogic::delete($id);
  44. }
  45. }