GoodsController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\shopapi\controller;
  20. use app\shopapi\logic\GoodsLogic;
  21. /**
  22. * 商品接口控制器
  23. * Class GoodsController
  24. * @package app\shopapi\controller
  25. */
  26. class GoodsController extends BaseShopController
  27. {
  28. public array $notNeedLogin = ['lists','detail','shopGoods','goodsMarketing','searchRecord'];
  29. /**
  30. * @notes 首页商品列表
  31. * @return \think\response\Json
  32. * @author cjhao
  33. * @date 2021/7/26 16:48
  34. */
  35. public function lists()
  36. {
  37. return $this->dataLists();
  38. }
  39. /**
  40. * @notes 搜索记录
  41. * @return \think\response\Json
  42. * @author cjhao
  43. * @date 2021/8/11 17:43
  44. */
  45. public function searchRecord()
  46. {
  47. $limit = $this->request->get('limit ',10);
  48. $lists = [];
  49. if($this->userId){
  50. $lists = (new GoodsLogic())->searchRecord($this->userId,$limit);
  51. }
  52. return $this->success('', $lists);
  53. }
  54. /**
  55. * @note 商品详情
  56. * @return \think\response\Json
  57. * @author cjhao
  58. * @date 2021/7/26 17:15
  59. */
  60. public function detail()
  61. {
  62. $params = $this->request->get();
  63. $params['user_id'] = $this->userId;
  64. $detail = (new GoodsLogic)->detail($params);
  65. if (false === $detail) {
  66. return $this->fail(GoodsLogic::getError());
  67. }
  68. return $this->success('获取成功', $detail);
  69. }
  70. /**
  71. * @note 商城分类商品
  72. * @return \think\response\Json
  73. * @author cjhao
  74. * @date 2021/7/26 17:15
  75. */
  76. public function shopGoods()
  77. {
  78. $list = (new GoodsLogic)->getshopGoods();
  79. if (false === $list) {
  80. return $this->fail(GoodsLogic::getError());
  81. }
  82. return $this->success('获取成功', $list);
  83. }
  84. /**
  85. * @notes 商品营销接口
  86. * @return \think\response\Json
  87. * @author cjhao
  88. * @date 2021/8/27 17:08
  89. */
  90. public function goodsMarketing()
  91. {
  92. $goodsId = $this->request->get('id');
  93. $marketing = (new GoodsLogic)->goodsMarketing($goodsId,$this->userId);
  94. return $this->success('获取成功',$marketing);
  95. }
  96. /**
  97. * @notes 清空搜索记录
  98. * @return \think\response\Json
  99. * @author cjhao
  100. * @date 2021/9/15 11:35
  101. */
  102. public function clearRecord()
  103. {
  104. if($this->userId){
  105. (new GoodsLogic)->clearRecord($this->userId);
  106. }
  107. return $this->success('');
  108. }
  109. /**
  110. * @notes 检测商品是否可购买
  111. * @return \think\response\Json
  112. * @author lbzy
  113. * @datetime 2023-07-07 10:28:52
  114. */
  115. function checkCanBuy()
  116. {
  117. $check = GoodsLogic::checkCanBuy(input('item_id/d'), input('num/d'));
  118. if($check === true) {
  119. return $this->success('可购买');
  120. }
  121. return $this->fail($check, [], 0, 0);
  122. }
  123. }