quanwei
2025-12-31 48d31672b4d88900080093cd1632f9d2eb978d4d
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
<?php
 
namespace app\api\service\order\settled;
 
use app\common\enum\order\OrderSourceEnum;
use app\common\model\settings\Setting as SettingModel;
use app\api\model\order\OrderAdvance as OrderAdvanceModel;
 
/**
 * 预售订单定金结算服务类
 */
class FrontOrderSettledService extends AdvanceSettledService
{
    private $config;
 
    /**
     * 构造函数
     */
    public function __construct($user, $supplierData, $params)
    {
        parent::__construct($user, $supplierData, $params);
        // 订单来源
        $this->orderSource = [
            'source' => OrderSourceEnum::ADVANCE,
        ];
        $this->config = SettingModel::getItem('advance');
        // 自身构造,差异化规则
        $this->settledRule = array_merge($this->settledRule, [
            'is_agent' => $this->config['is_agent'],
        ]);
    }
 
    /**
     * 验证订单商品的状态
     */
    public function validateProductList()
    {
 
        foreach ($this->supplierData[0]['productList'] as $product) {
            // 判断商品是否开始预售
            if ($product['advance']['start_time'] > time()) {
                $this->error = "很抱歉,还未到达预售时间";
                return false;
            }
            if ($product['advance']['end_time'] < time()) {
                $this->error = "很抱歉,预售商品时间已结束";
                return false;
            }
            if ($product['advance']['audit_status'] != 20 || $product['advance']['status'] != 10) {
                $this->error = "很抱歉,预售商品已下架";
                return false;
            }
            // 判断商品是否下架
            if ($product['product_status']['value'] != 10) {
                $this->error = "很抱歉,预售商品已下架";
                return false;
            }
            // 判断商品库存
            if ($product['total_num'] > $product['advance_sku']['advance_stock']) {
                $this->error = "很抱歉,预售商品库存不足";
                return false;
            }
 
            // 是否超过购买数
            if ($product['advance_product']['limit_num'] > 0) {
                $hasNum = OrderAdvanceModel::getPlusOrderNum($this->user['user_id'], $product['product_source_id']);
                if ($hasNum + $product['total_num'] > $product['advance_product']['limit_num']) {
                    $this->error = "很抱歉,你购买数量超过最大限购数量";
                    return false;
                }
            }
        }
        return true;
    }
}