作者 xwp
1 个管道 的构建 通过 耗费 12 秒

注册记录手机号关系

@@ -154,6 +154,7 @@ class User extends Backend @@ -154,6 +154,7 @@ class User extends Backend
154 $maxColumnNumber = Coordinate::columnIndexFromString($allColumn); 154 $maxColumnNumber = Coordinate::columnIndexFromString($allColumn);
155 $fields = []; 155 $fields = [];
156 $col = ''; 156 $col = '';
  157 + $mobile_col = '';
157 for ($currentRow = 1; $currentRow <= 1; $currentRow++) { 158 for ($currentRow = 1; $currentRow <= 1; $currentRow++) {
158 for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) { 159 for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
159 $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue(); 160 $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
@@ -161,6 +162,9 @@ class User extends Backend @@ -161,6 +162,9 @@ class User extends Backend
161 if($val == '产品id'){ 162 if($val == '产品id'){
162 $col = $currentColumn; 163 $col = $currentColumn;
163 } 164 }
  165 + if($val == '手机号'){
  166 + $mobile_col = $currentColumn;
  167 + }
164 } 168 }
165 } 169 }
166 170
@@ -179,8 +183,21 @@ class User extends Backend @@ -179,8 +183,21 @@ class User extends Backend
179 } 183 }
180 184
181 if ($row) { 185 if ($row) {
  186 +
  187 + if(!empty($mobile_col)){
  188 + //处理已有手机号
  189 + $mobile = $currentSheet->getCellByColumnAndRow($col, $currentRow)->getValue();
  190 +
  191 + $user = new \app\admin\model\User;
  192 + $user = $user->where(['mobile'=>$mobile,'openid' => ['<>','']])->find();
  193 + if(!empty($user)){
  194 + $row['openid'] = $user['openid'];
  195 + }
  196 + }
  197 +
182 $insert[] = $row; 198 $insert[] = $row;
183 199
  200 +
184 if(!empty($col)){ 201 if(!empty($col)){
185 //处理产品id 202 //处理产品id
186 $productId = $currentSheet->getCellByColumnAndRow($col, $currentRow)->getValue(); 203 $productId = $currentSheet->getCellByColumnAndRow($col, $currentRow)->getValue();
@@ -35,12 +35,14 @@ class User extends Api @@ -35,12 +35,14 @@ class User extends Api
35 * 35 *
36 * @param string $openid openid 36 * @param string $openid openid
37 * 37 *
  38 + * @param string $mobile
  39 + *
38 * @return boolean 40 * @return boolean
39 * @throws \think\db\exception\DataNotFoundException 41 * @throws \think\db\exception\DataNotFoundException
40 * @throws \think\db\exception\ModelNotFoundException 42 * @throws \think\db\exception\ModelNotFoundException
41 * @throws \think\exception\DbException 43 * @throws \think\exception\DbException
42 */ 44 */
43 - private function register($openid) 45 + private function register($openid,$mobile = '')
44 { 46 {
45 // 检测用户openid是否存在 47 // 检测用户openid是否存在
46 $user = new \app\admin\model\User; 48 $user = new \app\admin\model\User;
@@ -57,7 +59,7 @@ class User extends Api @@ -57,7 +59,7 @@ class User extends Api
57 'username' => '', 59 'username' => '',
58 'password' => '', 60 'password' => '',
59 'email' => '', 61 'email' => '',
60 - 'mobile' => '', 62 + 'mobile' => $mobile,
61 'level' => 1, 63 'level' => 1,
62 'score' => 0, 64 'score' => 0,
63 'avatar' => '', 65 'avatar' => '',
@@ -140,8 +142,9 @@ class User extends Api @@ -140,8 +142,9 @@ class User extends Api
140 142
141 $mini = new \WeMini\Crypt($this->config); 143 $mini = new \WeMini\Crypt($this->config);
142 $getUserInfo = $mini->decode($iv,$sessionKey,$encryptedData); 144 $getUserInfo = $mini->decode($iv,$sessionKey,$encryptedData);
143 - $mobile = $getUserInfo['purePhoneNumber'];  
144 - if(isset($mobile)){ 145 + $mobile = isset($getUserInfo['purePhoneNumber'])?$getUserInfo['purePhoneNumber']:'';
  146 +
  147 + if(!empty($mobile)){
145 $user = new \app\admin\model\User; 148 $user = new \app\admin\model\User;
146 $user->save(['openid'=>$openid],['mobile'=>$mobile,'openid'=>'']); 149 $user->save(['openid'=>$openid],['mobile'=>$mobile,'openid'=>'']);
147 } 150 }
@@ -155,7 +158,7 @@ class User extends Api @@ -155,7 +158,7 @@ class User extends Api
155 $user = new \app\admin\model\User; 158 $user = new \app\admin\model\User;
156 $user = $user->where(['openid'=>$openid])->find(); 159 $user = $user->where(['openid'=>$openid])->find();
157 if(empty($user)){ 160 if(empty($user)){
158 - $ret = $this->register($openid); 161 + $ret = $this->register($openid,empty($mobile)?'':$mobile);
159 } 162 }
160 } 163 }
161 if (!$ret) { 164 if (!$ret) {