GoodsController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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','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. * @notes 商品营销接口
  72. * @return \think\response\Json
  73. * @author cjhao
  74. * @date 2021/8/27 17:08
  75. */
  76. public function goodsMarketing()
  77. {
  78. $goodsId = $this->request->get('id');
  79. $marketing = (new GoodsLogic)->goodsMarketing($goodsId,$this->userId);
  80. return $this->success('获取成功',$marketing);
  81. }
  82. /**
  83. * @notes 清空搜索记录
  84. * @return \think\response\Json
  85. * @author cjhao
  86. * @date 2021/9/15 11:35
  87. */
  88. public function clearRecord()
  89. {
  90. if($this->userId){
  91. (new GoodsLogic)->clearRecord($this->userId);
  92. }
  93. return $this->success('');
  94. }
  95. /**
  96. * @notes 检测商品是否可购买
  97. * @return \think\response\Json
  98. * @author lbzy
  99. * @datetime 2023-07-07 10:28:52
  100. */
  101. function checkCanBuy()
  102. {
  103. $check = GoodsLogic::checkCanBuy(input('item_id/d'), input('num/d'));
  104. if($check === true) {
  105. return $this->success('可购买');
  106. }
  107. return $this->fail($check, [], 0, 0);
  108. }
  109. }