GoodsSearchController.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2020-09-22
  6. * Time: 17:11
  7. */
  8. namespace app\back\controller;
  9. use app\back\model\GoodsCategoryModel;
  10. use cmf\controller\AdminBaseController;
  11. use app\back\model\GoodsSearchModel;
  12. class GoodsSearchController extends AdminBaseController
  13. {
  14. public function index()
  15. {
  16. $GoodsSearchModel = new GoodsSearchModel();
  17. $list = $GoodsSearchModel::with('category')->select();
  18. $this->assign('list',$list);
  19. return $this->fetch();
  20. }
  21. public function add()
  22. {
  23. $GoodsCategoryModel = new GoodsCategoryModel();
  24. $list = $GoodsCategoryModel::where('is_show',1)->select();
  25. $this->assign('list',$list);
  26. return $this->fetch();
  27. }
  28. public function addPost()
  29. {
  30. $data = $this->request->param();
  31. $GoodsSearchModel = new GoodsSearchModel();
  32. $GoodsSearchModel->allowField(true)->isUpdate(false)->save($data);
  33. $this->success('添加成功');
  34. }
  35. public function edit()
  36. {
  37. $id = $this->request->param('id');
  38. $info = GoodsSearchModel::get($id);
  39. $info->category;
  40. $GoodsCategoryModel = new GoodsCategoryModel();
  41. $list = $GoodsCategoryModel::where('is_show',1)->where('id','<>',$info->category_id)->select();
  42. $this->assign('list',$list);
  43. $this->assign('info',$info);
  44. return $this->fetch();
  45. }
  46. public function editPost()
  47. {
  48. $data = $this->request->param();
  49. $GoodsSearchModel = new GoodsSearchModel();
  50. $GoodsSearchModel->allowField(true)->isUpdate(true)->save($data,['id'=>$data]);
  51. $this->success('编辑成功');
  52. }
  53. public function delete()
  54. {
  55. $id = $this->request->param('id');
  56. GoodsSearchModel::where('id',$id)->delete();
  57. $this->success('删除成功');
  58. }
  59. }