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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
namespace common\models;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
/**
* This is the model class for table "chain_user_order".
*
* @property string $id
* @property integer $uid
* @property string $order_id
* @property integer $gid
* @property integer $num
* @property string $title
* @property string $thumb
* @property integer $price
* @property string $logistics_num
* @property integer $status
* @property integer $spay_status
* @property integer $level
* @property string $pay_type
* @property string $pay_order
* @property string $deal_num
* @property string $created_at
* @property string $updated_at
*/
class UserOrder extends ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%user_order}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['uid', 'order_id', 'gid', 'num',], 'required'],
[['uid', 'gid', 'num', 'status', 'pay_status', 'created_at', 'updated_at'], 'integer'],
[['order_id', 'logistics_num', 'pay_type', 'deal_num'], 'string', 'max' => 50],
[['pay_order'], 'string', 'max' => 255],
[['title', 'thumb', 'price'], 'safe']
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'uid' => '用户uid',
'order_id' => '订单号',
'level' => "购买等级",
'gid' => '商品id',
'num' => '购买数量',
'title' => '商品名称',
'thumb' => '缩略图',
'price' => '单价',
'logistics_num' => '物流单号',
'status' => '状态',
'pay_type' => '支付类型',
'deal_num' => '交易号',
'created_at' => '创建时间',
'updated_at' => '更新时间',
];
}
/**
* @inheritdoc
*/
public function behaviors()
{
return [
[
'class' => TimestampBehavior::className(),
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at',
],
];
}
/**
* @param integer $uid
* @param array $info
* @param string $orderId
* @return integer
* 增加用户账单记录
*/
public function addUserOrder($uid, $info, $orderId)
{
$data = [
'uid' => $uid,
'status' => 1,
'info' => $info['info'],
'title' => $info['title'],
'orderId' => $orderId,
'pay_type' => $info['pay_type'],
];
if ($info['op'] == 'add') {
$data['price'] = $info['price'];
}
if ($info['op'] == 'ded') {
$data['price'] = -$info['price'];
}
foreach ($data as $k => $v) {
$this->$k = $v;
}
return self::save();
}
/**
* 关联用户信息
* @return \yii\db\ActiveQuery
*/
public function getUser()
{
return $this->hasOne(User::className(), ['uid' => 'uid']);
}
public static function partnerApply($data)
{
switch ($data) {
case 1 :
return '一级志愿者';
break;
case 2:
return '二级志愿者';
break;
case 3:
return '三级志愿者';
break;
case 4:
return '四级志愿者';
break;
case 5:
return '五级志愿者';
break;
case 6:
return '六级志愿者';
break;
default :
return '未知等级志愿者';
}
}
/**
* 添加订单
* @param $data
* @return bool
*/
public static function add($data)
{
$model = new self();
$model->uid = $data['uid'];
$model->order_id = $data['order_id'];
$model->gid = $data['gid'];
$model->num = $data['num'];
$model->status = 1;
$model->created_at = time();
return self::save();
}
}