作者 开飞机的舒克

绑定学生之后更改用户昵称

@@ -39,13 +39,13 @@ class Bind extends Api @@ -39,13 +39,13 @@ class Bind extends Api
39 if (empty($unique)) { 39 if (empty($unique)) {
40 $this->error('参数错误', ['status' => 2]); 40 $this->error('参数错误', ['status' => 2]);
41 } 41 }
42 - $res = \db('study')->where('unique',$unique)->value('user_id'); 42 + $res = \db('study')->where(['unique'=>$unique,'user_id'=>$user['id']])->find();
43 if (!empty($res)){ 43 if (!empty($res)){
44 $this->error('当前学生已经被绑定了'); 44 $this->error('当前学生已经被绑定了');
45 } 45 }
46 - $is_bind = db('user')->where('id', $user['id'])->value('bind_study');  
47 - if ($is_bind == 1) {  
48 - $this->error('您当前已经绑定过学生了,请勿重复操作', $is_bind); 46 + $users = db('user')->where('id', $user['id'])->find();
  47 + if ($users['bind_study'] == 1) {
  48 + $this->error('您当前已经绑定过学生了,请勿重复操作');
49 } 49 }
50 Db::startTrans(); 50 Db::startTrans();
51 try { 51 try {
@@ -55,12 +55,16 @@ class Bind extends Api @@ -55,12 +55,16 @@ class Bind extends Api
55 'user_id' => $user['id'], 55 'user_id' => $user['id'],
56 'updatetime' => time() 56 'updatetime' => time()
57 ]); 57 ]);
  58 + if ($users['is_tech'] == 0){
  59 + $update['nickname'] = $res['name']."家长";
  60 + }
  61 + $update = [
  62 + 'bind_study' => 1,
  63 + 'updatetime' => time()
  64 + ];
58 \db('user') 65 \db('user')
59 ->where('id', $user['id']) 66 ->where('id', $user['id'])
60 - ->update([  
61 - 'bind_study' => 1,  
62 - 'updatetime' => time()  
63 - ]); 67 + ->update($update);
64 Db::commit(); 68 Db::commit();
65 } catch (Exception $e) { 69 } catch (Exception $e) {
66 Db::rollback(); 70 Db::rollback();
@@ -87,13 +91,13 @@ class Bind extends Api @@ -87,13 +91,13 @@ class Bind extends Api
87 if (empty($unique)) { 91 if (empty($unique)) {
88 $this->error('参数错误', ['status' => 2]); 92 $this->error('参数错误', ['status' => 2]);
89 } 93 }
90 - $res = \db('study')->where('unique',$unique)->value('user_id'); 94 + $res = \db('study')->where(['unique'=>$unique,'user_id'=>$user['id']])->find();
91 if (!empty($res)){ 95 if (!empty($res)){
92 $this->error('当前学生已经被绑定了'); 96 $this->error('当前学生已经被绑定了');
93 } 97 }
94 - $is_bind = db('user')->where('id', $user['id'])->value('bind_study');  
95 - if ($is_bind == 1) {  
96 - $this->error('您当前已经绑定过学生了,请勿重复操作', $is_bind); 98 + $users = db('user')->where('id', $user['id'])->find();
  99 + if ($users['bind_study'] == 1) {
  100 + $this->error('您当前已经绑定过学生了,请勿重复操作');
97 } 101 }
98 Db::startTrans(); 102 Db::startTrans();
99 try { 103 try {
@@ -103,12 +107,16 @@ class Bind extends Api @@ -103,12 +107,16 @@ class Bind extends Api
103 'user_id' => $user['id'], 107 'user_id' => $user['id'],
104 'updatetime' => time() 108 'updatetime' => time()
105 ]); 109 ]);
  110 + if ($users['is_tech'] == 0){
  111 + $update['nickname'] = $res['name']."家长";
  112 + }
  113 + $update = [
  114 + 'bind_study' => 1,
  115 + 'updatetime' => time()
  116 + ];
106 \db('user') 117 \db('user')
107 ->where('id', $user['id']) 118 ->where('id', $user['id'])
108 - ->update([  
109 - 'bind_study' => 1,  
110 - 'updatetime' => time()  
111 - ]); 119 + ->update($update);
112 Db::commit(); 120 Db::commit();
113 } catch (Exception $e) { 121 } catch (Exception $e) {
114 Db::rollback(); 122 Db::rollback();
@@ -6324,7 +6324,7 @@ @@ -6324,7 +6324,7 @@
6324 6324
6325 </div> 6325 </div>
6326 <div class="col-md-6" align="right"> 6326 <div class="col-md-6" align="right">
6327 - Generated on 2023-04-23 14:14:47 <a href="./" target="_blank">校园活动</a> 6327 + Generated on 2023-04-23 14:59:57 <a href="./" target="_blank">校园活动</a>
6328 </div> 6328 </div>
6329 </div> 6329 </div>
6330 6330