SeckillController.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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\lists\SeckillLists;
  21. use app\shopapi\logic\SeckillLogic;
  22. use app\shopapi\validate\SeckillValidate;
  23. class SeckillController extends BaseShopController
  24. {
  25. public array $notNeedLogin = ['lists', 'detail'];
  26. /**
  27. * @notes 秒杀活动列表
  28. * @author 张无忌
  29. * @date 2021/7/27 15:12
  30. */
  31. public function lists()
  32. {
  33. return $this->dataLists(new SeckillLists());
  34. }
  35. /**
  36. * @notes 秒杀活动详细
  37. * @author 张无忌
  38. * @date 2021/7/27 15:15
  39. */
  40. public function detail()
  41. {
  42. $params = (new SeckillValidate())->goCheck('id');
  43. $params['user_id'] = $this->userId;
  44. $result = SeckillLogic::detail($params);
  45. if (is_array($result)) {
  46. return $this->success('获取成功', $result);
  47. }
  48. return $this->fail($result);
  49. }
  50. /**
  51. * @notes 秒杀下单
  52. * @return \think\response\Json
  53. * @throws @\Exception
  54. * @author 张无忌
  55. * @date 2021/8/5 17:28
  56. */
  57. public function buy()
  58. {
  59. $params = (new SeckillValidate())->post()->goCheck('buy');
  60. $info = SeckillLogic::settlement($params, $this->userId);
  61. if ($params['action'] == 'settle') {
  62. if (is_array($info)) {
  63. return $this->success('获取成功', $info);
  64. }
  65. return $this->fail($info);
  66. }
  67. if (!is_array($info)) {
  68. return $this->fail($info);
  69. }
  70. $result = SeckillLogic::buy($info, $this->userId);
  71. if (is_array($result)) {
  72. return $this->success('下单成功', $result);
  73. }
  74. return $this->fail($result);
  75. }
  76. }