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
76
77
78
79
80
81
<?php
 
namespace app\api\service\order\settled;
 
use app\api\model\order\OrderProduct;
use app\common\enum\order\OrderSourceEnum;
use app\api\model\order\Order as OrderModel;
/**
 * 普通订单结算服务类
 */
class MasterOrderSettledService extends OrderSettledService
{
    /**
     * 构造函数
     */
    public function __construct($user, $supplierData, $params)
    {
       parent::__construct($user, $supplierData, $params);
        //订单来源
        $this->orderSource = [
            'source' => OrderSourceEnum::MASTER,
            'activity_id' => 0
        ];
       //自身构造,差异化规则
    }
 
 
    /**
     * 验证订单商品的状态
     */
    public function validateProductList()
    {
        $newcomerNum =(new OrderModel())
            ->where('user_id', $this->user['user_id'])
            ->where('is_newcomer', 1)->count();
 
        foreach ($this->supplierData as $supplier) {
            foreach ($supplier['productList'] as $product) {
                // 判断商品是否下架
                if ($product['product_status']['value'] != 10) {
                    $this->error = "很抱歉,商品 [{$product['product_name']}] 已下架";
                    return false;
                }
                // 判断商品是否下架
                if ($product['is_newcomer'] == 1 && $product['total_num'] > 1) {
                    $this->error = "很抱歉,商品为新人专区商品只能购买1件";
                    return false;
                }
                if ($product['is_newcomer'] == 1 && $newcomerNum > 0) {
                    $this->error = "很抱歉,您已购买过新人专区商品,不能购买新人专区商品";
                    return false;
                }
                if ($this->user['purchase_count'] <= 0 && $product['is_repurchase'] == 1 ) {
                    $this->error = "很抱歉,还不是会员,不能购买复购专区商品,请到先到vip专区购买";
                    return false;
                }
                // 判断商品库存
                if ($product['total_num'] > $product['product_sku']['stock_num']) {
                    $this->error = "很抱歉,商品 [{$product['product_name']}] 库存不足";
                    return false;
                }
                // 是否是会员商品
                if(count($product['grade_ids']) > 0 && $product['grade_ids'][0] != ''){
                    if(!in_array($this->user['grade_id'], $product['grade_ids'])){
                        $this->error = '很抱歉,此商品仅特定会员可购买';
                        return false;
                    }
                }
                // 判断是否超过限购数量
                if($product['limit_num'] > 0){
                    $hasNum = OrderModel::getHasBuyOrderNum($this->user['user_id'], $product['product_id']);
                    if($hasNum + $product['total_num'] > $product['limit_num']){
                        $this->error = "很抱歉,购买超过此商品最大限购数量";
                        return false;
                    }
                }
            }
        }
        return true;
    }
}