|
@@ -4,6 +4,7 @@ namespace app\admin\controller\user;
|
|
|
|
|
|
use AlibabaCloud\Client\Request\UserAgent;
|
|
|
use AlibabaCloud\Ecs\V20140526\UnassignIpv6Addresses;
|
|
|
+use app\admin\model\UserRemarks;
|
|
|
use app\common\controller\Backend;
|
|
|
use app\common\library\Auth;
|
|
|
use fast\Random;
|
|
@@ -33,6 +34,7 @@ class User extends Backend
|
|
|
parent::_initialize();
|
|
|
$this->model = model('User');
|
|
|
$this->view->assign("levelList", $this->model->getLevelList());
|
|
|
+ $this->view->assign("bindRemarksList", $this->model->bindRemarksList());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -91,14 +93,52 @@ class User extends Backend
|
|
|
}
|
|
|
|
|
|
// 复制数据
|
|
|
- $c_user_ids = explode(',', $params['c_user_id']);
|
|
|
- unset($params['c_user_id']);
|
|
|
+// if (isset($params['c_user_id'])){
|
|
|
+// $c_user_ids = explode(',', $params['c_user_id']);
|
|
|
+// unset($params['c_user_id']);
|
|
|
+// }
|
|
|
+
|
|
|
+ //添加备注信息
|
|
|
+ if ($params['type'] == 1) {
|
|
|
+ // 商家备注:1=回收备注,2=餐具备注,3=商城备注
|
|
|
+ for ($i = 1; $i <= 3; $i++) {
|
|
|
+ $has_add_relations[$i] = false;
|
|
|
+ $param_remarks = "remarks" . $i;
|
|
|
+ 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;
|
|
|
+ $has_add_relations[$i] = true; //原有备注,要查看B端账号,绑定
|
|
|
+ } else {
|
|
|
+ $user_remarks_insert = new UserRemarks;
|
|
|
+ $user_remarks_insert->type = $i;
|
|
|
+ $user_remarks_insert->value = $params[$param_remarks];
|
|
|
+ $user_remarks_insert->save();
|
|
|
+ // 获取自增ID
|
|
|
+ $params[$param_remarks] = $user_remarks_insert->id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($params['type'] == 2 && $params['type_remarks'] != "" && $params['bind_remarks'] != "") {
|
|
|
+ //查询绑定过商户 list 当前备注的商户
|
|
|
+ $column_remarks = 'remarks' . $params['type_remarks'];
|
|
|
+ $remarks_list_user = $this->model->where($column_remarks, $params['bind_remarks'])->select();
|
|
|
+ //$remarks_list_user = $this->model->where(['type_remarks' => $params['type_remarks'], 'bind_remarks' => $params['bind_remarks']])->select();
|
|
|
+ if (count($remarks_list_user) > 0) {
|
|
|
+ foreach ($remarks_list_user as $v) {
|
|
|
+ $c_user_ids[] = $v['id'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
$insert_user_id = model('user')->insert($params, false, true);
|
|
|
- // 添加关联关系
|
|
|
- if ($params['type'] == 2) {
|
|
|
- // todo 服务关系是否之前存在过 ,状态:0=未服务,1=已服务,2=已注销
|
|
|
|
|
|
+ // 添加关联关系 -- 添加回收员or配送员时
|
|
|
+ if ($params['type'] == 2 && $params['type_remarks'] != "" && $params['bind_remarks'] != "") {
|
|
|
+ // todo 服务关系是否之前存在过 ,状态:0=未服务,1=已服务,2=已注销
|
|
|
+ // 直接绑定商户时
|
|
|
if (count($c_user_ids) > 0) {
|
|
|
foreach ($c_user_ids as $v) {
|
|
|
$user_relations[] = [
|
|
@@ -109,6 +149,24 @@ class User extends Backend
|
|
|
}
|
|
|
model('user_relations')->insertAll($user_relations);
|
|
|
}
|
|
|
+ } elseif ($params['type'] == 1) {
|
|
|
+ for ($i = 1; $i <= 3; $i++) {
|
|
|
+ if ($has_add_relations[$i]) {
|
|
|
+ $param_remarks = "remarks" . $i;
|
|
|
+ // 添加商家时,查看回收员or配送员是否已绑定过该备注,绑定会员关系
|
|
|
+ $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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
Db::commit();
|
|
@@ -144,17 +202,44 @@ class User extends Backend
|
|
|
if (false === $this->request->isPost()) {
|
|
|
$row['c_user_id'] = '';
|
|
|
// 查询和商家的关联数据显示
|
|
|
+ if ($row['type'] == 1) {
|
|
|
+ // 商家备注:1=回收备注,2=餐具备注,3=商城备注
|
|
|
+ for ($i = 1; $i <= 3; $i++) {
|
|
|
+ $param_remarks = "remarks" . $i;
|
|
|
+ if ($row[$param_remarks]) {
|
|
|
+ $user_remarks = UserRemarks::where('id', $row[$param_remarks])->where('type', $i)->find();
|
|
|
+ if (!empty($user_remarks)) {
|
|
|
+ $row[$param_remarks] = $user_remarks->value;
|
|
|
+ } else {
|
|
|
+ $row[$param_remarks] = "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $row['user_remarks'] = [];
|
|
|
if ($row['type'] == 2) {
|
|
|
- $user_relations_list = model('user_relations')
|
|
|
- ->field('c_user_id')
|
|
|
- ->where(['b_user_id' => $row['id'], 'b_level' => $row['level']])
|
|
|
- ->select();
|
|
|
- $ids = [];
|
|
|
- foreach ($user_relations_list as $v) {
|
|
|
- $ids[] = $v['c_user_id'];
|
|
|
+ // 直接绑定时
|
|
|
+// $user_relations_list = model('user_relations')
|
|
|
+// ->field('c_user_id')
|
|
|
+// ->where(['b_user_id' => $row['id'], 'b_level' => $row['level']])
|
|
|
+// ->select();
|
|
|
+// $ids = [];
|
|
|
+// foreach ($user_relations_list as $v) {
|
|
|
+// $ids[] = $v['c_user_id'];
|
|
|
+// }
|
|
|
+//
|
|
|
+// $row['c_user_id'] = implode(',', $ids);
|
|
|
+ // 绑定过商户的备注
|
|
|
+ if ($row['type_remarks']) {
|
|
|
+ $user_remarks_model = new UserRemarks();
|
|
|
+ $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();
|
|
|
}
|
|
|
|
|
|
- $row['c_user_id'] = implode(',', $ids);
|
|
|
}
|
|
|
|
|
|
$this->view->assign('row', $row);
|
|
@@ -178,10 +263,65 @@ class User extends Backend
|
|
|
$row->validateFailException()->validate($validate);
|
|
|
}
|
|
|
|
|
|
+ $params_c_user_ids = $db_c_user_ids = [];
|
|
|
if ($row['type'] == 2) {
|
|
|
// 处理 c_user_id
|
|
|
- $params_c_user_ids = explode(',', $params['c_user_id']);
|
|
|
- unset($params['c_user_id']);
|
|
|
+// $params_c_user_ids = explode(',', $params['c_user_id']);
|
|
|
+// unset($params['c_user_id']);
|
|
|
+ //查询商户 list // 绑定过 当前备注的商户
|
|
|
+ $column_remarks = 'remarks' . $params['type_remarks'];
|
|
|
+ $remarks_list_user = $this->model->where($column_remarks, $params['bind_remarks'])->select();
|
|
|
+ foreach ($remarks_list_user as $vrlu) {
|
|
|
+ $params_c_user_ids[] = $vrlu['id'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加备注信息
|
|
|
+ if ($row['type'] == 1) {
|
|
|
+ // 商家备注: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;
|
|
|
+ $user_remarks_insert->value = $params[$param_remarks];
|
|
|
+ $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();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
$result = $row->allowField(true)->save($params);
|
|
@@ -263,8 +403,8 @@ class User extends Backend
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
|
|
|
- $password =$this->getEncryptPassword( '123456',$row['salt']);
|
|
|
- Db::name('user')->where('id',$ids)->update(['password'=>$password]);
|
|
|
+ $password = $this->getEncryptPassword('123456', $row['salt']);
|
|
|
+ Db::name('user')->where('id', $ids)->update(['password' => $password]);
|
|
|
Db::commit();
|
|
|
} catch (\Exception $e) {
|
|
|
Db::rollback();
|
|
@@ -272,6 +412,7 @@ class User extends Backend
|
|
|
}
|
|
|
$this->success("重置成功");
|
|
|
}
|
|
|
+
|
|
|
public function getEncryptPassword($password, $salt = '')
|
|
|
{
|
|
|
return md5(md5($password) . $salt);
|