HomeGoods.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace app\admin\controller\home;
  3. use app\admin\controller\BaseController;
  4. use app\admin\server\home\HomeGoodsServer;
  5. class HomeGoods extends BaseController
  6. {
  7. /**
  8. * Notes:获取项目列表
  9. * @return \support\Response
  10. * User: YCP
  11. * Date: 2022/10/31
  12. */
  13. public function getGoodsList()
  14. {
  15. [$page, $limit] = $this->getPage();
  16. $keywords = $this->request->get('keywords');
  17. $category_id = $this->request->get('category_id');//分类id
  18. $result = HomeGoodsServer::getGoodsList($page,$limit,$keywords,$category_id);
  19. return json_success($result, '成功');
  20. }
  21. /**
  22. * Notes:修改项目
  23. * @return \support\Response
  24. * User: YCP
  25. * Date: 2022/10/31
  26. */
  27. public function updateGoods()
  28. {
  29. $params = $this->request->post();
  30. $admin_id = $this->request->admin_id;
  31. $this->validateCheck('home\HomeGoodsValidate',
  32. [
  33. 'goods_id' => $params['goods_id']?? '',
  34. 'goods_category_id' => $params['goods_category_id']?? '',
  35. 'goods_name' => $params['goods_name']?? '',
  36. 'goods_img' => $params['goods_img']?? '',
  37. 'goods_mobile' => $params['goods_mobile']?? '',
  38. ],
  39. 'update');
  40. $result = HomeGoodsServer::updateGoods($params, $admin_id);
  41. return json_success($result, '修改成功');
  42. }
  43. /**
  44. * Notes:删除项目
  45. * @return \support\Response
  46. * User: YCP
  47. * Date: 2022/10/31
  48. */
  49. public function delGoods()
  50. {
  51. $goods_id = $this->request->get('goods_id');
  52. $admin_id = $this->request->admin_id;
  53. $this->validateCheck('home\HomeGoodsValidate', ['goods_id' => $goods_id], 'info');
  54. $result = HomeGoodsServer::delGoods($goods_id,$admin_id);
  55. if ($result){
  56. return json_success($result, '删除成功');
  57. }else{
  58. throw new \Exception('删除失败!');
  59. }
  60. }
  61. /**
  62. * Notes:添加项目
  63. * @return \support\Response
  64. * User: YCP
  65. * Date: 2022/10/31
  66. */
  67. public function addGoods()
  68. {
  69. $params = $this->request->post();
  70. $admin_id = $this->request->admin_id;
  71. $this->validateCheck('home\HomeGoodsValidate',
  72. [
  73. 'goods_category_id' => $params['goods_category_id']?? '',
  74. 'goods_name' => $params['goods_name']?? '',
  75. 'goods_img' => $params['goods_img']?? '',
  76. 'goods_mobile' => $params['goods_mobile']?? '',
  77. ],
  78. 'create');
  79. $result = HomeGoodsServer::insertGoods($params, $admin_id);
  80. return json_success($result, '添加成功');
  81. }
  82. /**
  83. * Notes:查询项目详情
  84. * @return \support\Response
  85. * User: YCP
  86. * Date: 2022/10/31
  87. */
  88. public function goodsInfo()
  89. {
  90. $goods_id = $this->request->get('goods_id');
  91. $this->validateCheck('home\HomeGoodsValidate', ['goods_id' => $goods_id], 'info');
  92. $result = HomeGoodsServer::goodsInfo($goods_id);
  93. return json_success($result, '成功');
  94. }
  95. }