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

注册记录手机号关系

... ... @@ -154,6 +154,7 @@ class User extends Backend
$maxColumnNumber = Coordinate::columnIndexFromString($allColumn);
$fields = [];
$col = '';
$mobile_col = '';
for ($currentRow = 1; $currentRow <= 1; $currentRow++) {
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
... ... @@ -161,6 +162,9 @@ class User extends Backend
if($val == '产品id'){
$col = $currentColumn;
}
if($val == '手机号'){
$mobile_col = $currentColumn;
}
}
}
... ... @@ -179,8 +183,21 @@ class User extends Backend
}
if ($row) {
if(!empty($mobile_col)){
//处理已有手机号
$mobile = $currentSheet->getCellByColumnAndRow($col, $currentRow)->getValue();
$user = new \app\admin\model\User;
$user = $user->where(['mobile'=>$mobile,'openid' => ['<>','']])->find();
if(!empty($user)){
$row['openid'] = $user['openid'];
}
}
$insert[] = $row;
if(!empty($col)){
//处理产品id
$productId = $currentSheet->getCellByColumnAndRow($col, $currentRow)->getValue();
... ...
... ... @@ -35,12 +35,14 @@ class User extends Api
*
* @param string $openid openid
*
* @param string $mobile
*
* @return boolean
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
private function register($openid)
private function register($openid,$mobile = '')
{
// 检测用户openid是否存在
$user = new \app\admin\model\User;
... ... @@ -57,7 +59,7 @@ class User extends Api
'username' => '',
'password' => '',
'email' => '',
'mobile' => '',
'mobile' => $mobile,
'level' => 1,
'score' => 0,
'avatar' => '',
... ... @@ -140,8 +142,9 @@ class User extends Api
$mini = new \WeMini\Crypt($this->config);
$getUserInfo = $mini->decode($iv,$sessionKey,$encryptedData);
$mobile = $getUserInfo['purePhoneNumber'];
if(isset($mobile)){
$mobile = isset($getUserInfo['purePhoneNumber'])?$getUserInfo['purePhoneNumber']:'';
if(!empty($mobile)){
$user = new \app\admin\model\User;
$user->save(['openid'=>$openid],['mobile'=>$mobile,'openid'=>'']);
}
... ... @@ -155,7 +158,7 @@ class User extends Api
$user = new \app\admin\model\User;
$user = $user->where(['openid'=>$openid])->find();
if(empty($user)){
$ret = $this->register($openid);
$ret = $this->register($openid,empty($mobile)?'':$mobile);
}
}
if (!$ret) {
... ...