Supplier.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use app\common\model\SupplierModel;
  5. use think\App;
  6. use think\facade\View;
  7. use think\Request;
  8. class Supplier extends BaseController
  9. {
  10. private $model;
  11. public function __construct(App $app)
  12. {
  13. $this->model = new SupplierModel();
  14. parent::__construct($app);
  15. }
  16. public function index() {
  17. View::assign([
  18. "list" => $this->model->findByPaginate($this->request->param())
  19. ]);
  20. return view();
  21. }
  22. public function add() {
  23. $params = $this->request->param();
  24. if ($this->request->isAjax()) {
  25. $res = $this->model->save([
  26. 'name' => $params['name'],
  27. 'introduce' => $params['introduce']
  28. ]);
  29. return $res ? $this->ok(true) : $this->fail(false);
  30. }
  31. return view();
  32. }
  33. public function edit() {
  34. $params = $this->request->param();
  35. $supplier = $this->model->findById($params['id']);
  36. if($this->request->isAjax()) {
  37. $res = $this->model->where('id', $params['id'])->update([
  38. 'name' => $params['name'],
  39. 'introduce' => $params['introduce'],
  40. 'update_time' => time()
  41. ]);
  42. return $res ? $this->ok(true) : $this->fail(false);
  43. }
  44. View::assign('supplier',$supplier);
  45. return view();
  46. }
  47. public function delete(Request $request) {
  48. $params = $request->param();
  49. if(!isset($params['ids']))
  50. return $this->fail(lang("Please select the data you want to delete"));
  51. $this->model->deleteByIds(explode(',', $params['ids']));
  52. return $this->ok(true);
  53. }
  54. }