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
173
174
175
176
177
<?php
namespace common\models;
use yii\behaviors\TimestampBehavior;
/**
* This is the model class for table "chain_integral_release".
*
* @property string $id
* @property string $uid
* @property integer $release_type
* @property integer $type
* @property string $integral
* @property integer $status
* @property string $created_at
* @property string $updated_at
*/
class IntegralRelease extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%integral_release}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['uid', 'type', 'status'], 'required'],
[['uid', 'report_id', 'type', 'status', 'created_at', 'updated_at'], 'integer'],
[['price'], 'number'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'uid' => '用户ID',
'report_id' => '销售中心UID',
'type' => '类型',
'price' => '积分',
'status' => '状态',
'created_at' => '创建时间',
'updated_at' => '更新时间',
];
}
/**
* @inheritdoc
*/
public function behaviors()
{
return [
[
'class' => TimestampBehavior::className(),
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at',
],
];
}
/**
* @param $data
* @return string
*/
public static function payType($data)
{
switch ($data) {
case 1 :
return '会员销售';
break;
case 2:
return '推荐';
break;
case 21:
return '推荐';
break;
case 3:
return '出局';
break;
case 4:
return '销售出局奖';
break;
// default :
// return '未知赠送';
}
}
/**
* @param $data
* @return string
*/
public static function releaseType($data)
{
switch ($data) {
case "已释放" :
return 1;
break;
case '未释放':
return 0;
break;
// default :
// return '未知赠送';
}
}
/**
* @param $data
* @return string
*/
public static function Type($data)
{
switch ($data) {
case "会员销售奖 " :
return 1;
break;
case '推荐奖 ':
return 2;
break;
case '出局奖':
return 3;
break;
}
}
/**
* 添加记录
* @param $data
* @return int
* @throws \yii\db\Exception
*/
public static function add($data)
{
$result = \Yii::$app->db->createCommand()->batchInsert(IntegralRelease::tableName(), ['report_id', 'uid', 'type', 'price', 'status', 'created_at', 'updated_at'], $data)->execute();
return $result;
}
/**
* 查找报单中心订单
* @param $uid
* @return array|\yii\db\ActiveRecord[]
*/
public static function findByReUid($uid, $page)
{
$list = self::find()->where(['report_id' => $uid])->andWhere(['type' => 1])->orderBy('id desc')->offset(($page - 1) * 6)->limit(6)->asArray()->all();
$ls = self::find()->where(['report_id' => $uid])->andWhere(['type' => 1])->count(1);
if (!empty($list)) {
foreach ($list as $k => &$value) {
$user = User::findOne($value['uid']);
// $value['uid'] = 'HC' . substr($user['mobile'], -6);
$value['uid'] = $user['id'];
$value['realname'] = $user['realname'];
$value['mobile'] = $user['mobile'];
$value['created_at'] = date("Y-m-d H:i:s", $value['created_at']);
$value['updated_at'] = date("Y-m-d H:i:s", $value['updated_at']);
}
}
$data['page'] = ceil($ls / 6);
$data['list'] = $list;
return $data;
}
}