|
@@ -151,17 +151,19 @@ class User extends Backend
|
|
|
}
|
|
|
} elseif ($params['type'] == 1) {
|
|
|
for ($i = 1; $i <= 3; $i++) {
|
|
|
- if ($has_add_relations[$i]){
|
|
|
+ if ($has_add_relations[$i]) {
|
|
|
$param_remarks = "remarks" . $i;
|
|
|
// 添加商家时,查看回收员or配送员是否已绑定过该备注,绑定会员关系
|
|
|
- $user_b = $this->model->where(['type_remarks' => $i, 'bind_remarks' => $params[$param_remarks]])->order('id', 'desc')->find();
|
|
|
- if (!empty($user_b)){
|
|
|
- $user_relation = [
|
|
|
- 'c_user_id' => $insert_user_id,
|
|
|
- 'b_user_id' => $user_b['id'],
|
|
|
- 'b_level' => $user_b['level'],
|
|
|
- ];
|
|
|
- model('user_relations')->insert($user_relation);
|
|
|
+ $user_b_list = $this->model->where(['type_remarks' => $i, 'bind_remarks' => $params[$param_remarks]])->order('id', 'desc')->select();
|
|
|
+ if (count($user_b_list) > 0) {
|
|
|
+ foreach ($user_b_list as $user_b) {
|
|
|
+ $user_relations[] = [
|
|
|
+ 'c_user_id' => $insert_user_id,
|
|
|
+ 'b_user_id' => $user_b['id'],
|
|
|
+ 'b_level' => $user_b['level'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ model('user_relations')->insertAll($user_relations);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -234,6 +236,7 @@ class User extends Backend
|
|
|
$row['user_remarks'] = $user_remarks_model->alias('remarks')->join('user u ', 'u.remarks' . $row['type_remarks'] . '=remarks.id')
|
|
|
->where(['remarks.type' => $row['type_remarks'], 'u.type' => 1])
|
|
|
->field('remarks.id,remarks.value,remarks.type')
|
|
|
+ ->group('remarks.id')
|
|
|
->select();
|
|
|
}
|
|
|
|
|
@@ -278,10 +281,27 @@ class User extends Backend
|
|
|
// 商家备注:1=回收备注,2=餐具备注,3=商城备注
|
|
|
for ($i = 1; $i <= 3; $i++) {
|
|
|
$param_remarks = "remarks" . $i;
|
|
|
+ $del_relations = false;
|
|
|
if ($params[$param_remarks]) {
|
|
|
$user_remarks = UserRemarks::where('value', $params[$param_remarks])->where('type', $i)->find();
|
|
|
if (!empty($user_remarks)) {
|
|
|
$params[$param_remarks] = $user_remarks->id;
|
|
|
+ if ($params[$param_remarks] != $row[$param_remarks]) {
|
|
|
+ // 原有绑定id变化--需要删除旧的C-B关系 && 绑定新关系
|
|
|
+ $del_relations = true;
|
|
|
+ // 绑定新关系
|
|
|
+ $user_b_list = $this->model->where(['type_remarks' => $i, 'bind_remarks' => $params[$param_remarks]])->order('id', 'desc')->select();
|
|
|
+ if(count($user_b_list)>0){
|
|
|
+ foreach ($user_b_list as $user_b){
|
|
|
+ $user_relation[] = [
|
|
|
+ 'c_user_id' => $row['id'],
|
|
|
+ 'b_user_id' => $user_b['id'],
|
|
|
+ 'b_level' => $user_b['level'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ model('user_relations')->insertAll($user_relation);
|
|
|
+ }
|
|
|
+ }
|
|
|
} else {
|
|
|
$user_remarks_insert = new UserRemarks;
|
|
|
$user_remarks_insert->type = $i;
|
|
@@ -289,7 +309,17 @@ class User extends Backend
|
|
|
$user_remarks_insert->save();
|
|
|
// 获取自增ID
|
|
|
$params[$param_remarks] = $user_remarks_insert->id;
|
|
|
+
|
|
|
+ $del_relations = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //删除旧关系
|
|
|
+ if ($row[$param_remarks] != 0 && $del_relations) {
|
|
|
+ $user_b = $this->model->where(['type_remarks' => $i, 'bind_remarks' => $row[$param_remarks]])->order('id', 'desc')->select();
|
|
|
+ foreach ($user_b as $vub){
|
|
|
+ $user_b_ids[] = $vub['id'];
|
|
|
}
|
|
|
+ model('user_relations')->where('c_user_id',$row['id'])->whereIn('b_user_id',$user_b_ids)->delete();
|
|
|
}
|
|
|
}
|
|
|
}
|