Goods.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | A3Mall
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2020 http://www.a3-mall.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: xzncit <158373108@qq.com>
  8. // +----------------------------------------------------------------------
  9. namespace app\api\controller;
  10. use app\common\exception\BaseException;
  11. use think\facade\Request;
  12. use app\api\service\Goods as GoodsService;
  13. class Goods extends Base {
  14. /**
  15. * 商品列表
  16. * @return \think\response\Json
  17. */
  18. public function index(){
  19. try{
  20. return $this->returnAjax("ok",1,GoodsService::getList(Request::param()));
  21. }catch (BaseException $ex){
  22. return $this->returnAjax($ex->getMessage(),$ex->getCode(),$ex->getRaw());
  23. }
  24. }
  25. /**
  26. * 商品详情
  27. * @return \think\response\Json
  28. */
  29. public function view(){
  30. try {
  31. return $this->returnAjax("ok",1,GoodsService::detail(Request::param("id","0","intval")));
  32. }catch (\Exception $ex){
  33. return $this->returnAjax($ex->getMessage(),$ex->getCode());
  34. }
  35. }
  36. /**
  37. * 收藏商品
  38. * @return \think\response\Json
  39. */
  40. public function favorite(){
  41. try{
  42. $res = GoodsService::favorite(Request::param("id","","intval"));
  43. return $this->returnAjax($res==1?"收藏成功":"取消成功",1,$res);
  44. }catch (\Exception $ex){
  45. return $this->returnAjax($ex->getMessage(),$ex->getCode());
  46. }
  47. }
  48. }