修改用户绑定

This commit is contained in:
lccsw
2025-11-21 00:37:51 +08:00
parent 586e07c336
commit 5acd1c6e82
7 changed files with 48 additions and 14 deletions
@@ -29,6 +29,7 @@ abstract class BaseController extends REST_Controller
];
const SERVICE_PHONE = '13388887777';
const APP_ID = 1; //应用id
const DEFAULT_AVATAR = 'https://img.liche.cn/space/agentadmin/202507/p_8087d3cfe434bb7a76eb4a7a802b6195.jpg?imageView2/2/w/200/h/200/interlace/1';
public function __construct()
{
+1 -1
View File
@@ -54,7 +54,7 @@ class Login extends BaseController
}
$responseData = $response->getData();
$data = [
'Authorization' => generateToken([$responseData['id'], $responseData['orgId'] ?: 0], 'jwt_key_auto'),
'Authorization' => Authorization::generateToken([$responseData['id'], $responseData['orgId'] ?: 0], 'jwt_key_auto'),
];
$this->return_response($data, API_CODE_SUCCESS);
} catch (Exception $e) {
+1 -1
View File
@@ -36,7 +36,7 @@ class Ucenter extends BaseController
{
$user = $this->autoUserModel->get(['id' => $this->userId]);
$data = [
'user_info' => ['username' => $user['nickname'], 'avatar' => $user['headimg']],
'user_info' => ['username' => $user['nickname'], 'avatar' => $user['headimg'] ?: self::DEFAULT_AVATAR],
'menu_list' => [
['title' => '我的券', 'type' => 1, 'url' => '/my/coupon'],
// ['title' => '我的订单', 'type' => 1, 'url' => '/my/order'],
+29 -5
View File
@@ -19,7 +19,7 @@ class Coupon extends BaseController
public function index_post()
{
try {
$user = $this->autoUserModel->get(['id' => $this->userId]);
$user = $this->autoUserModel->get(['id' => $this->userId]); //当前用户信息
if (!$this->userId) {
throw new Exception("请先登录");
}
@@ -28,7 +28,11 @@ class Coupon extends BaseController
if (!$couponId) {
throw new Exception("参数错误");
}
if (checkua() == 'wx') {
$mobile = $user['mobile'];
$userId = $user['id'];
$resData = [];
$bindUser = '';
if (checkua() == 'wx' && !$mobile) { //微信且未绑定手机号
$mobile = $this->post('mobile');
$code = $this->post('code');
if (!$mobile) {
@@ -42,17 +46,37 @@ class Coupon extends BaseController
throw new Exception("验证码错误");
}
$redis->delete($key);
//查找是否存在相同未绑定微信手机号
$bindUser = $this->autoUserModel->get(['mobile' => $mobile, 'openid' => '', 'status>' => Auto_user_model::STATUS_DELETE]);
if ($bindUser) {
$userId = $bindUser['id'];
}
} else {
$mobile = $user['mobile'];
if (!$mobile) {
throw new Exception("请先绑定手机号");
}
}
$result = $this->auto_user_coupon_model->getCoupon(self::APP_ID, $this->userId, $couponId, $mobile, $cityId);
$result = $this->auto_user_coupon_model->getCoupon(self::APP_ID, $userId, $couponId, $mobile, $cityId);
if (!$result->isSuccess()) {
throw new Exception($result->getMessage());
}
$this->return_response([], '领取成功');
// 绑定手机号
if ($bindUser) {
$updateUser = [
'openid' => $user['openid'], 'nickname' => $user['nickname'],
'headimg' => $user['headimg']
];
$this->autoUserModel->update($updateUser, ['id' => $bindUser['id']]);
//作废当前用户并返回新token
$this->autoUserModel->update(['status' => Auto_user_model::STATUS_DELETE], ['id' => $this->userId]);
$resData = [
'Authorization' => Authorization::generateToken([$bindUser['id'], $bindUser['orgId'] ?: 0], 'jwt_key_auto'),
];
} else {
//绑定手机号
$this->autoUserModel->update(['mobile' => $mobile], ['id' => $this->userId, 'mobile' => '']);
}
$this->return_response($resData, '领取成功');
} catch (Exception $e) {
$this->return_json($e->getMessage());
}
+3 -1
View File
@@ -87,6 +87,7 @@ class Product extends BaseController
if (!$result) {
$this->return_json('数据不存在');
}
$user = $this->autoUserModel->get(['id' => $this->userId]); //当前用户信息
$coupon = $result->getOneCoupons($this->userId);
$data = [
'id' => $result->id,
@@ -102,7 +103,8 @@ class Product extends BaseController
'brandId' => $result->brandId,
'seriesId' => $result->seriesId,
'brandName' => $result->getBrandName(),
'seriesName' => $result->getSeriesName()
'seriesName' => $result->getSeriesName(),
'bindMobile' => $user['mobile'] ? 1 : 0
];
$this->return_response($data);
}
+5 -5
View File
@@ -27,7 +27,7 @@ class ApiAuthHook
//h5白名单
$this->route_un_auto = [
'auto/config/*', 'auto/login/*', 'auto/area/*', 'auto/car/brand', 'auto/car/product/list',
'auto/car/coupon/bizs','auto/visit','auto/brand/*','auto/car/product/detail','auto/sms/login'
'auto/car/coupon/bizs', 'auto/visit', 'auto/brand/*', 'auto/car/product/detail', 'auto/sms/login'
];
}
@@ -40,10 +40,10 @@ class ApiAuthHook
$uri_string = uri_string();
$urlArray = explode("/", $uri_string);
if ($urlArray[0] == 'auto') { //h5
if (!in_array($uri_string, $this->route_un_auto) &&
!in_array($urlArray[0] . '/' . $urlArray[1] . '/*', $this->route_un_auto) &&
!in_array($urlArray[0] . '/' . $urlArray[1] . '/' . $urlArray[2] . '/*', $this->route_un_auto)) {
$headers = $this->CI->input->request_headers();
$headers = $this->CI->input->request_headers();
if ($headers['Authorization'] || (!in_array($uri_string, $this->route_un_auto) &&
!in_array($urlArray[0] . '/' . $urlArray[1] . '/*', $this->route_un_auto) &&
!in_array($urlArray[0] . '/' . $urlArray[1] . '/' . $urlArray[2] . '/*', $this->route_un_auto))) {
if ($this->tokenIsExist($headers)) {
$req = $this->validateToken($headers['Authorization'], 'jwt_key_auto');
$this->CI->userId = $req[0];
+8 -1
View File
@@ -3,6 +3,7 @@ defined('BASEPATH') or exit('No direct script access allowed');
class Auto_user_model extends HD_Model
{
const STATUS_DELETE = -1; //删除
const STATUS_DISABLE = 0; //禁用
const STATUS_NORMAL = 1; //正常
private $table_name = 'lc_auto_user';
@@ -21,6 +22,7 @@ class Auto_user_model extends HD_Model
/**
* @param $openid
* @param string $mobile
* @param string $accountId 平安用户编码
* @param string $from ain fish
* @param array $otherInfo
@@ -35,7 +37,12 @@ class Auto_user_model extends HD_Model
} else {
$this->load->model('agent/pingan/pingan_users_model', 'pingAnUsers');
}
$user = $this->get(['mobile' => $mobile, 'openid' => $openid]);
if ($mobile) {
$user = $this->get(['mobile' => $mobile, 'status>=' => self::STATUS_NORMAL]);
} else {
$user = $this->get(['openid' => $openid, 'status>=' => self::STATUS_DISABLE]);
}
if (!$user) {
$user = [
'mobile' => $mobile,