quanwei
2025-11-21 2d9362ae6f528f57e6133d5d80f0b633c24e8eb6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
 
namespace app\api\model\plus\seckill;
 
use app\common\model\plus\seckill\Active as ActiveModel;
use app\common\service\product\BaseProductService;
 
/**
 * 秒杀活动模型
 */
class Active extends ActiveModel
{
    public function checkOrderTime($data)
    {
        $result = ['code' => 0];
        if ($data['start_time'] > time()) {
            $result = ['code' => 10, 10 => '该活动未开始'];
        }
        if ($data['end_time'] < time()) {
            $result = ['code' => 20, 20 => '该活动已结束'];
        }
        $now_start_time = strtotime(date('Y-m-d') . ' ' . $data['day_start_time']);
        $now_end_time = strtotime(date('Y-m-d') . ' ' . $data['day_end_time']);
        if ($now_start_time > time()) {
            $result = ['code' => 30, 30 => '该活动今天未开始'];
        }
        if ($now_end_time < time()) {
            $result = ['code' => 40, 40 => '该活动今天已结束'];
        }
        return $result;
    }
 
    /**
     * 取最近要结束的一条记录
     * 未开始也显示
     */
    public static function getActive()
    {
        return (new static())->where('end_time', '>', time())
            ->where('status', '=', 1)
            ->where('is_delete', '=', 0)
            ->order(['sort' => 'asc', 'create_time' => 'asc'])
            ->find();
    }
 
    /**
     * 获取秒杀活动
     * 未开始也显示
     */
    public function activityList()
    {
        return $this->where('end_time', '>', time())
            ->where('status', '=', 1)
            ->where('is_delete', '=', 0)
            ->select();
    }
 
    /**
     * 获取秒杀商品
     * 6.10显示未开始
     */
    public static function getProductSecKillDetail($product_id)
    {
        $active = (new static())->alias('a')
            ->where('a.end_time', '>', time())
            ->where('a.status', '=', 1)
            ->where('a.is_delete', '=', 0)
            ->join('seckill_product s', 's.seckill_activity_id=a.seckill_activity_id')
            ->where('product_id', '=', $product_id)
            ->field('s.*')
            ->find();
        $detail = "";
        if ($active) {
            $detail = (new Product())->getSeckillDetail($active['seckill_product_id']);
            $detail['active'] = self::detailWithTrans($active['seckill_activity_id']);
            $detail['specData'] = BaseProductService::getSpecData($detail['product']);
        }
        return $detail;
    }
}