quanwei
2025-11-26 6ae85f8ddbae19f5586f4b0c37680fe21889ef14
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
 
namespace app\common\model\order;
 
use app\common\model\BaseModel;
 
/**
 * 订单商品模型
 */
class OrderProduct extends BaseModel
{
    protected $name = 'order_product';
    protected $pk = 'order_product_id';
 
    /**
     * 订单商品列表
     * @return \think\model\relation\BelongsTo
     */
    public function image()
    {
        return $this->belongsTo('app\\common\\model\\file\\UploadFile', 'image_id', 'file_id');
    }
 
    /**
     * 关联商品表
     * @return \think\model\relation\BelongsTo
     */
    public function product()
    {
        return $this->belongsTo('app\\common\\model\\product\\Product');
    }
 
    /**
     * 关联商品sku表
     * @return \think\model\relation\BelongsTo
     */
    public function sku()
    {
        return $this->belongsTo('app\\common\\model\\product\\ProductSku', 'spec_sku_id', 'spec_sku_id');
    }
 
    /**
     * 关联订单主表
     * @return \think\model\relation\BelongsTo
     */
    public function orderM()
    {
        return $this->belongsTo('Order','order_id','order_id');
    }
 
    /**
     * 售后单记录表
     * @return \think\model\relation\HasOne
     */
    public function refund()
    {
        return $this->hasOne('app\\common\\model\\order\\OrderRefund');
    }
 
    /**
     * 关联分销商
     * @return \think\model\relation\BelongsTo
     */
    public function agent()
    {
        return $this->belongsTo('app\\common\\model\\agent\\Apply', 'agent_user_id', 'user_id');
    }
 
    /**
     * 订单商品详情
     */
    public static function detail($where)
    {
        return (new static())->with(['image', 'refund', 'orderM.advance'])->find($where);
    }
 
    /**
     * 获取商品数据 (可指定某天)
     */
    public function getProductData($startDate = null, $endDate = null, $type, $shop_supplier_id)
    {
        $model = $this;
        if($shop_supplier_id > 0){
            $model = $model->where('order.shop_supplier_id', '=', $shop_supplier_id);
        }
        $model = $model->alias('order_product')
            ->join('order order', 'order_product.order_id = order.order_id','left');
 
        $model = $model->where('order.create_time', '>=', strtotime($startDate));
        if(is_null($endDate)){
            $model = $model->where('order.create_time', '<', strtotime($startDate) + 86400);
        }else{
            $model = $model->where('order.create_time', '<', strtotime($endDate) + 86400);
        }
 
        if($type == 'no_pay'){
            // 未支付
            return $model->where('order.pay_status', '=', 10)->sum('order_product.total_num');
        }else if($type == 'pay'){
            // 已支付
            return $model->where('order.pay_status', '=', 20)->sum('order_product.total_num');
        }
        return 0;
    }
}