quanwei
2025-12-05 feda780069d64479c0c20493603717e100655da9
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
106
107
108
109
<?php
 
namespace app\common\model\plus\release;
 
use app\common\enum\order\OrderPayTypeEnum;
use app\common\model\BaseModel;
 
 
/**
 * 订单模型
 */
class Order extends BaseModel
{
    protected $name = 'release_order';
    protected $pk = 'id';
 
    /**
     * 追加字段
     * @var string[]
     */
    protected $append = [
        'state_text',
    ];
 
    /**
     * 需求用户
     * @return \think\model\relation\BelongsTo
     */
    public function demanduser()
    {
        return $this->belongsTo('app\common\model\user\User','demand_user_id','user_id');
    }
 
     /**
     * 供应用户
     * @return \think\model\relation\BelongsTo
     */
    public function supplyuser()
    {
        return $this->belongsTo('app\common\model\user\User','supply_user_id','user_id');
    }
 
    /**
     * 关联项目
     * @return \think\model\relation\hasMany
     */
    public function project()
    {
        return $this->belongsTo('app\common\model\plus\release\Project','project_id','project_id');
    }
 
 
 
    /**
     * 订单状态文字描述
     * @param $value
     * @param $data
     * @return string
     */
    public function getStateTextAttr($value, $data)
    {
        if($data['order_status'] == 20){
            return '已取消';
        }
        // 订单状态
        if ($data['pay_status'] == 10 && $data['pay_type'] == 40) {
            return '待确认支付';
        }else if ($data['pay_status'] == 10 && $data['pay_type'] != 40) {
            return '未付款';
        }else if($data['pay_status'] == 20 && $data['order_status'] == 10){
            return '进行中';
        }else if($data['pay_status'] == 20 && $data['order_status'] == 30){
            return '已完成';
        }
        return "";
    }
 
    /**
     * 付款状态
     * @param $value
     * @return array
     */
    public function getPayTypeAttr($value)
    {
        if(empty($value)){
            return ['text' => '', 'value' => 0];
        }
        return ['text' => OrderPayTypeEnum::data()[$value]['name'], 'value' => $value];
    }
 
    /**
     * 详情
     */
    public static function detail($id)
    {
        $model = new static();
        return $model->with(['demanduser','supplyuser',"project"])->find($id);
    }
 
    /**
     * 详情
     */
    public static function getDetail($order_no)
    {
        $model = new static();
        return $model->with(["project"])->where("order_no",'=',$order_no)->find();
    }
 
}