截流自动化的商城平台
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop开源商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | gitee下载:https://gitee.com/likeshop_gitee
  7. // | github下载:https://github.com/likeshop-github
  8. // | 访问官网:https://www.likeshop.cn
  9. // | 访问社区:https://home.likeshop.cn
  10. // | 访问手册:http://doc.likeshop.cn
  11. // | 微信公众号:likeshop技术社区
  12. // | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
  13. // | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
  14. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  15. // | likeshop团队版权所有并拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshop.cn.team
  18. // +----------------------------------------------------------------------
  19. namespace app\api\logic;
  20. use app\common\server\ConfigServer;
  21. use app\common\server\UrlServer;
  22. use think\facade\Db;
  23. class SeckillLogic{
  24. public static function seckillTime(){
  25. $time_list = Db::name('seckill_time')
  26. ->where(['del'=>0])
  27. ->order('start_time asc')
  28. ->field('id,start_time,end_time')
  29. ->select();
  30. $now = time();
  31. foreach ($time_list as &$item){
  32. $item['status'] = 2;
  33. $item['tips'] = '';
  34. $start_time = strtotime(date('Y-m-d'.$item['start_time']));
  35. $end_time = strtotime(date('Y-m-d'.$item['end_time']));
  36. if($now >= $end_time ){
  37. $item['tips'] = '已结束';
  38. }
  39. if($start_time <= $now && $now < $end_time){
  40. $item['status'] = 1;
  41. $item['tips'] = '抢购中';
  42. }
  43. if($start_time >= $now){
  44. $item['tips'] = '未开始';
  45. $item['status'] = 0;
  46. }
  47. }
  48. return $time_list;
  49. }
  50. public static function seckillGoods($id,$page,$size){
  51. $where[] = ['g.del','=',0];
  52. $where[] = ['sg.del','=',0];
  53. $where[] = ['g.status','=',1];
  54. $where[] = ['sg.seckill_id','=',$id];
  55. $goods_count = Db::name('goods g')
  56. ->join('seckill_goods sg','g.id = sg.goods_id')
  57. ->group('sg.goods_id')
  58. ->order('sg.sales_sum desc')
  59. ->where($where)
  60. ->count();
  61. $goods_list = Db::name('goods g')
  62. ->join('seckill_goods sg','g.id = sg.goods_id')
  63. ->where($where)
  64. ->group('sg.goods_id')
  65. ->order('sg.sales_sum,sg.id desc')
  66. ->page($page,$size)
  67. ->field('g.id,g.name,g.image,g.min_price,sg.price as seckill_price,sg.sales_sum')
  68. ->select();
  69. $default_image = UrlServer::getFileUrl(ConfigServer::get('website', 'goods_image', ''));
  70. foreach ($goods_list as &$item){
  71. // 传入默认商品主图
  72. if(empty( $item['image'])) {
  73. $item['image'] = $default_image;
  74. }else{
  75. $item['image'] = UrlServer::getFileUrl($item['image']);
  76. }
  77. }
  78. $more = is_more($goods_count,$page,$size); //是否有下一页
  79. $data = [
  80. 'list' => $goods_list,
  81. 'page' => $page,
  82. 'size' => $size,
  83. 'count' => $goods_count,
  84. 'more' => $more
  85. ];
  86. return $data;
  87. }
  88. //获取当前的秒杀时段
  89. public static function getSeckill()
  90. {
  91. $seckill_time = Db::name('seckill_time')
  92. ->where(['del'=>0])
  93. ->order('start_time asc')
  94. ->field('id,start_time,end_time')
  95. ->select();
  96. $seckill = [];
  97. $now = time();
  98. foreach ($seckill_time as $item){
  99. $start_time = strtotime(date('Y-m-d '.$item['start_time']));
  100. $end_time = strtotime(date('Y-m-d '.$item['end_time']));
  101. if($start_time <= $now && $now < $end_time){
  102. $item['end_time'] = $end_time;
  103. $seckill = $item;
  104. break;
  105. }
  106. }
  107. return $seckill;
  108. }
  109. //获取当前的秒杀信息和秒杀商品
  110. public static function getSeckillGoods()
  111. {
  112. $seckill = self::getSeckill();
  113. $seckill_goods = [];
  114. if ($seckill) {
  115. $seckill_goods = Db::name('seckill_goods')
  116. ->where(['seckill_id'=>$seckill['id'],'del'=>0,'review_status' => 1])
  117. // 需要加上日期限制
  118. ->where('start_date', '<=', date('Y-m-d'))
  119. ->where('end_date', '>=', date('Y-m-d'))
  120. ->column('id as seckill_goods_id,price,goods_id','item_id');
  121. }
  122. return ['seckill'=>$seckill,'seckill_goods'=>$seckill_goods];
  123. }
  124. }