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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<?php
namespace common\models;
use common\helpers\Utils;
use yii\behaviors\TimestampBehavior;
use Yii;
/**
* This is the model class for table "{{%report_form}}".
*
* @property int $id
* @property int $report_uid 报单中心uid
* @property int $uid 报单uid
* @property int $recomm_id 推荐人UId
* @property int $team_list 推荐人UId
* @property string $price 金额
* @property string $thumb 图片
* @property string $card_front 图片
* @property string $card_negative 图片
* @property string $remark 备注
* @property string $remarks 备注
* @property string $name 备注
* @property string $address 备注
* @property string $mobile 备注
* @property int $created_at 创建时间
* @property int $status 状态
* @property int $updated_at 更新时间
*/
class ReportForm extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%report_form}}';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['report_uid', 'uid', 'price', 'created_at',], 'required'],
[['id', 'report_uid', 'uid', 'created_at', 'updated_at', 'status', 'goods_id', 'team_list'], 'integer'],
[['price'], 'number'],
[['thumb', 'remark', 'remarks', 'card_front', 'card_negative', 'name', 'address', 'mobile'], 'string'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'report_uid' => '销售中心UID',
'uid' => '销售UID',
'price' => '金额',
'thumb' => '凭证',
'status' => '状态',
'remark' => '驳回',
'remarks' => '备注',
'team_id' => '站队UID',
'card_front' => '身份证正面',
'card_negative' => '身份证反面',
'created_at' => '创建时间',
'updated_at' => '更新时间',
"goods_status"=>"订单状态",
"express_type"=>"快递公司",
"express_no"=>"快递单号",
];
}
/**
* @inheritdoc
*/
public function behaviors()
{
return [
[
'class' => TimestampBehavior::className(),
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at',
],
];
}
/**
* 查找自己及下级的报单记录
* @param $uid
* @return array
*/
public static function findByUid($uid, $page)
{
$uids = User::find()->select('uid')->where(" superior REGEXP '^{$uid}_' ")->offset(($page - 1) * 5)->limit(5)->asArray()->all();
array_push($uids, ['uid' => $uid]);
$list = $lists = [];
foreach ($uids as $item) {
$list[] = self::find()->where(['uid' => $item['uid']])->orderBy("id desc")->asArray()->one();
}
foreach ($list as &$value) {
if (!empty($value)) {
// foreach ($item as &$value){
$value['thumb'] = Utils::toMedia($value['thumb']);
$user = User::findOne(['uid' => $value['uid']]);
$value['name'] = $user['realname'];
$value['price'] = $value['price'] . " 元";
$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']);
if ($value['status'] == 2) {
$value['status'] = '已审核';
} elseif ($value['status'] == 1) {
$value['status'] = '待审核';
} else {
$value['status'] = '已驳回';
}
// }
$lists[] = $value;
}
}
return $lists;
}
/**
* 报单中心记录
* @param $uid
* @return array|\yii\db\ActiveRecord[]
*/
public static function findByreid($uid, $page)
{
$pages = self::find()->where(['report_uid' => $uid])->count(1);
$list = self::find()->where(['report_uid' => $uid])->orderBy("id desc")->offset(($page - 1) * 5)->limit(5)->asArray()->all();
$num = self::find()->where(['report_uid' => $uid,"status"=>2])->all();
foreach ($list as $k => &$value) {
$user = User::findOne(['uid' => $value['uid']]);
$report_user = User::findOne(['uid' => $value['report_uid']]);
// $value['report_uid'] = 'HC' . substr($report_user['mobile'], -6);
$value['report_uid'] = $report_user['uid'];
$value['thumb'] = Utils::toMedia($value['thumb']);
$value['name'] = $user['realname'];
$value['accountname'] = $user['accountname'];
$value['created_at'] = date("Y-m-d H:i:s", $value['created_at']);
$value['status'] = self::status($value['status']);
}
$ls['page'] = ceil($pages / 5);
$ls['list'] = $list;
$ls['count'] = count($num);
return $ls;
}
/**
* 查找单条
* @param $uid
* @return array|ReportForm|null|\yii\db\ActiveRecord
*/
public static function findByID($uid)
{
$list = self::find()->where(['uid' => $uid])->orderBy("id desc")->asArray()->one();
if (!empty($list)) {
$list['thumb'] = empty($list['thumb']) ? '' : Utils::toMedia($list['thumb']);
$list['created_at'] = date("Y-m-d H:i:s", $list['created_at']);
$list['status'] = self::status($list['status']);
$user = User::findOne(['uid' => $list['uid']]);
$list['name'] = $user['realname'];
}
return $list;
}
//查询该组的位置上是否有人存在
public static function findTeamPosi($team,$posi){
$ishave = self::find()->where(['team_id' => $posi,"team_list"=>$team])->one();
if(!empty($ishave)){
return true;
}else{
return false;
}
}
//查询该用户是否在该组报过单
public static function findMembOnTeam($team=0,$uid=0){
// $ishaves = self::find()->where(['uid' => $uid,"team_list"=>$team,'status'=>2])->one();
$ishaves = self::find()->where(['uid' => $uid,'status'=>2])->all();
if(!empty($ishaves)){
return count($ishaves);
}else{
return count($ishaves);
}
}
public static function status($data)
{
switch ($data) {
case 1 :
return '待审核';
break;
case 2 :
return '通过审核';
break;
case 3:
return '驳回';
break;
default :
return '未知类型';
}
}
//手动添加数据
public static function addreport($data){
$model=new ReportForm();
$model->report_uid=$data['report_uid'];
$model->uid=$data['uid'];
$model->name=$data['name'];
$model->address=$data['address'];
$model->mobile=$data['mobile'];
$model->team_list=$data['team_list'];
$model->posi=$data['posi'];
$model->is_auto=$data['is_auto'];
$model->recomm_id=$data['recomm_id'];
$model->is_auto=$data['is_auto'];
$model->goods_id=$data['goods_id'];
$model->price=$data['price'];
$model->status=$data['status'];
$model->goods_status=$data['goods_status']; //已收货
$model->operateid=$data['operateid'];
$model->created_at=$data['created_at'];
$model->updated_at=$data['updated_at'];
// if($model->load($data)){
if($model->save(false)){
$arr=['code'=>1,'data'=>Yii::$app->db->getLastInsertID(),'msg'=>"成功报单"];
}else{
$arr=['code'=>0,'data'=>"",'msg'=>"报单失败"];
}
// }
return $arr;
}
}