Parcourir la source

Merge branch 'master' of http://47.112.106.152:10880/tangyuanwang/zhijiayun

public il y a 1 mois
Parent
commit
07ef196f86

+ 110 - 3
app/Http/Controllers/Api/Login.php

@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Api;
 
 use App\Models\Api\Personnel\Employee as EmployeeModel;
 use App\Http\Requests\Api\Login as Request;
+use App\Facades\Servers\Sms\VerifyCode as Sms;
 
 /**
  * API登录控制器
@@ -54,12 +55,11 @@ class Login extends Api
 
 
     /**
-     * 登录方法				/manager/login/out
+     * 退出方法				/manager/login/out
      * @author 唐远望
      * @version   1.0
      * @date      2025-12-09
-     * @param string 	username	登录账号
-     * @param string 	password	登录密码
+     * @param string 	authcode	用户令牌
      * 
      */
     public function out(EmployeeModel $EmployeeModel)
@@ -110,4 +110,111 @@ class Login extends Api
         // 表单令牌
         return        json_send(['code' => 'success', 'msg' => '登录成功', 'data' => $accessToken]);
     }
+
+
+    /**
+	 * 发送验证码
+	 * @author 唐远望
+	 * @version   1.0
+	 * @date      2026-01-16
+	 * @param string 	phone		手机号码
+	 * 
+	 */
+	public function send_code(Request $Request, EmployeeModel $EmployeeModel)
+	{
+		// 验证规则
+		$Request->scene('send_code')->validate();
+		// 接收数据
+		$mobile		 = request('phone', '');
+		if (!$mobile)	return json_send(['code' => 'error', 'msg' => '请先填写手机号']);
+		// 获取数据
+		$session	= session('loginSmsCode');
+		// 如果有数据,并且验证码创建的时间在一分钟之内
+		if ($session && time() - $session['create_time'] < 60) return json_send(['code' => 'error', 'msg' => '请稍后再试']);
+		// 查询用户
+		$admin		= $EmployeeModel->query()->where('mobile', $mobile)->first(['status']);
+		if ($admin && $admin['status'])    return json_send(['code' => 'error', 'msg' => '用户已被停用']);
+		$code 		= strval(rand(100000, 999999));
+		$result    = Sms::sendCode($mobile, $code);
+		if (isset($result['error']))	return json_send(['code' => 'error', 'msg' => $result['error']]);
+		$session 	= ['code' => $code, 'mobile' => $mobile, 'create_time' => time()];
+		session(['loginSmsCode' => $session]);
+		return							json_send(['code' => 'success', 'msg' => '发送成功', 'data' => $code]);
+	}
+
+	/**
+	 * 邮箱登录			/manager/login/email
+	 * @author 唐远望
+	 * @version   1.0
+	 * @date      2026-01-16
+	 * @param string 	email		邮箱号码
+	 * @param string 	password	登录密码
+	 * 
+	 */
+	public function email(Request $Request,EmployeeModel $EmployeeModel)
+	{
+		// 验证规则
+		$Request->scene('email')->validate();
+		// 接收数据
+		$email    = $Request->input('email', '');
+		// 接收数据
+		$password    = $Request->input('password', '');
+		// 查询用户
+		$admin    	= $EmployeeModel->where('email', $email)->first(['id', 'name', 'mobile', 'status', 'password', 'insert_time', 'update_time']);
+		// 用户不存在
+		if (!$admin)	return json_send(['code' => 'error', 'msg' => '密码错误或账号不存在']);
+		// 用户不存在
+		if ($admin['status']) 				return json_send(['code' => 'error', 'msg' => '该账号已停用']);
+		// 转数组
+		$admin    	= $admin->toArray();
+		// 比对密码
+		if (md5($password) != $admin['password']) return json_send(['code' => 'error', 'msg' => '密码错误或账号不存在']);
+		// 登录
+		$accessToken 						= $EmployeeModel->Login($admin['uid'], 'api');
+		// 比对密码
+		if (isset($accessToken['error'])) 	return json_send(['code' => 'error', 'msg' => '登录失败', 'data' => $accessToken['data']]);
+		// 获取权限列表
+		$accessToken['username']			= $admin['name'];
+		// 表单令牌
+		return    	json_send(['code' => 'success', 'msg' => '登录成功', 'data' => $accessToken]);
+	}
+
+	/**
+	 * 手机验证码登录			/manager/login/mobile_code
+	 * @author 唐远望
+	 * @version   1.0
+	 * @date      2026-01-16
+	 * @param string 	mobile		手机号码
+	 * @param string 	code	验证码
+	 * 
+	 */
+	public function mobile_code(Request $Request,EmployeeModel $EmployeeModel)
+	{
+		// 验证规则
+		$Request->scene('mobile_code')->validate();
+		// 接收数据
+		$phone    = $Request->input('phone', '');
+		// 接收数据
+		$code    = $Request->input('code', '');
+		// 获取数据
+		$session						    = session('loginSmsCode');
+		if (!$session)                     return json_send(['code' => 'error', 'msg' => '请先获取手机号验证码']);
+		if ($session['code'] != $code || $session['phone'] != $phone) return json_send(['code' => 'error', 'msg' => '验证码错误']);
+		// 查询用户
+		$admin    	= $EmployeeModel->where('mobile', $phone)->first(['id', 'name', 'mobile', 'status', 'password', 'insert_time', 'update_time']);
+		// 用户不存在
+		if (!$admin)	return json_send(['code' => 'error', 'msg' => '账号不存在']);
+		// 用户不存在
+		if ($admin['status']) 				return json_send(['code' => 'error', 'msg' => '该账号已停用']);
+		// 转数组
+		$admin    	= $admin->toArray();
+		// 登录
+		$accessToken 						= $EmployeeModel->Login($admin['uid'],'api');
+		// 比对密码
+		if (isset($accessToken['error'])) 	return json_send(['code' => 'error', 'msg' => '登录失败', 'data' => $accessToken['data']]);
+		// 获取权限列表
+		$accessToken['username']			= $admin['name'];
+		// 表单令牌
+		return    	json_send(['code' => 'success', 'msg' => '登录成功', 'data' => $accessToken]);
+	}
 }

+ 191 - 8
app/Http/Controllers/Manager/Login.php

@@ -7,6 +7,9 @@ use App\Http\Requests\Manager\Login as Request;
 use App\Models\Manager\AuthRule;
 use App\Facades\Servers\Encrypts\AccessToken;
 use App\Models\Manager\Personnel\Employee as EmployeeModel;
+use App\Facades\Servers\Sms\VerifyCode as Sms;
+use App\Models\Manager\Personnel\EmployeeOpenid as EmployeeOpenidModel;
+use App\Servers\Wechat\WeChatWebApp;
 
 /**
  * 管理后台登录控制器
@@ -47,13 +50,13 @@ class Login extends Manager
 			// 比对密码
 			if (md5($password) != $admin['password']) return json_send(['code' => 'error', 'msg' => '密码错误或账号不存在']);
 			// 登录
-			$accessToken 						= $AdminUser->Login($admin['uid'],'manager');
+			$accessToken 						= $AdminUser->Login($admin['uid'], 'manager');
 			// 比对密码
 			if (isset($accessToken['error'])) 	return json_send(['code' => 'error', 'msg' => '登录失败', 'data' => $accessToken['data']]);
 			// 获取权限列表
 			$accessToken['username']			= $admin['username'];
 			// 获取权限列表
-			$accessToken['auth_rules']			= $AuthRule->getAuthList($admin['uid'],'1', 'manager');
+			$accessToken['auth_rules']			= $AuthRule->getAuthList($admin['uid'], '1', 'manager');
 		} else {
 			$admin    	= $EmployeeModel->where('employee_code', $username)->first(['id as uid', 'name as username', 'mobile as phone', 'status', 'password', 'insert_time', 'update_time']);
 			// 用户不存在
@@ -65,14 +68,14 @@ class Login extends Manager
 			// 比对密码
 			if (md5($password) != $admin['password']) return json_send(['code' => 'error', 'msg' => '密码错误或账号不存在']);
 			// 登录
-			$accessToken 						= $EmployeeModel->Login($admin['uid'],'manager');
+			$accessToken 						= $EmployeeModel->Login($admin['uid'], 'manager');
 			// 比对密码
 			if (isset($accessToken['error'])) 	return json_send(['code' => 'error', 'msg' => '登录失败', 'data' => $accessToken['data']]);
 			// 获取权限列表
 			$accessToken['username']			= $admin['username'];
-			$accessToken['auth_rules']			= $AuthRule->getAuthList($admin['uid'],'0','manager');
+			$accessToken['auth_rules']			= $AuthRule->getAuthList($admin['uid'], '0', 'manager');
 		}
-		
+
 		// 表单令牌
 		return    	json_send(['code' => 'success', 'msg' => '登录成功', 'data' => $accessToken]);
 	}
@@ -99,10 +102,10 @@ class Login extends Manager
 		if ($is_admin == '1') {
 			// 退出登录
 			$AdminUser->LoginOut($uid, 'manager');
-		}else{
+		} else {
 			$EmployeeModel->LoginOut($uid, 'manager');
 		}
-		
+
 		// 表单令牌
 		return    	json_send(['code' => 'success', 'msg' => '退出成功', 'data' => '']);
 	}
@@ -117,7 +120,7 @@ class Login extends Manager
 	 * @param string 	password	登录密码
 	 * 
 	 */
-	public function mobile(Request $Request,AuthRule $AuthRule, EmployeeModel $EmployeeModel)
+	public function mobile(Request $Request, AuthRule $AuthRule, EmployeeModel $EmployeeModel)
 	{
 		// 验证规则
 		$Request->scene('mobile')->validate();
@@ -146,4 +149,184 @@ class Login extends Manager
 		// 表单令牌
 		return    	json_send(['code' => 'success', 'msg' => '登录成功', 'data' => $accessToken]);
 	}
+
+	/**
+	 * 发送验证码
+	 * @author 唐远望
+	 * @version   1.0
+	 * @date      2026-01-15
+	 * @param string 	phone		手机号码
+	 * 
+	 */
+	public function send_code(Request $Request, EmployeeModel $EmployeeModel)
+	{
+		// 验证规则
+		$Request->scene('send_code')->validate();
+		// 接收数据
+		$mobile		 = request('phone', '');
+		if (!$mobile)	return json_send(['code' => 'error', 'msg' => '请先填写手机号']);
+		// 获取数据
+		$session	= session('loginSmsCode');
+		// 如果有数据,并且验证码创建的时间在一分钟之内
+		if ($session && time() - $session['create_time'] < 60) return json_send(['code' => 'error', 'msg' => '请稍后再试']);
+		// 查询用户
+		$admin		= $EmployeeModel->query()->where('mobile', $mobile)->first(['status']);
+		if ($admin && $admin['status'])    return json_send(['code' => 'error', 'msg' => '用户已被停用']);
+		$code 		= strval(rand(100000, 999999));
+		$result    = Sms::sendCode($mobile, $code);
+		if (isset($result['error']))	return json_send(['code' => 'error', 'msg' => $result['error']]);
+		$session 	= ['code' => $code, 'mobile' => $mobile, 'create_time' => time()];
+		session(['loginSmsCode' => $session]);
+		return							json_send(['code' => 'success', 'msg' => '发送成功', 'data' => $code]);
+	}
+
+	/**
+	 * 邮箱登录			/manager/login/email
+	 * @author 唐远望
+	 * @version   1.0
+	 * @date      2025-12-04
+	 * @param string 	email		邮箱号码
+	 * @param string 	password	登录密码
+	 * 
+	 */
+	public function email(Request $Request, AuthRule $AuthRule, EmployeeModel $EmployeeModel)
+	{
+		// 验证规则
+		$Request->scene('email')->validate();
+		// 接收数据
+		$email    = $Request->input('email', '');
+		// 接收数据
+		$password    = $Request->input('password', '');
+		// 查询用户
+		$admin    	= $EmployeeModel->where('email', $email)->first(['id as uid', 'name as username', 'mobile as phone', 'status', 'password', 'insert_time', 'update_time']);
+		// 用户不存在
+		if (!$admin)	return json_send(['code' => 'error', 'msg' => '密码错误或账号不存在']);
+		// 用户不存在
+		if ($admin['status']) 				return json_send(['code' => 'error', 'msg' => '该账号已停用']);
+		// 转数组
+		$admin    	= $admin->toArray();
+		// 比对密码
+		if (md5($password) != $admin['password']) return json_send(['code' => 'error', 'msg' => '密码错误或账号不存在']);
+		// 登录
+		$accessToken 						= $EmployeeModel->Login($admin['uid'], 'manager');
+		// 比对密码
+		if (isset($accessToken['error'])) 	return json_send(['code' => 'error', 'msg' => '登录失败', 'data' => $accessToken['data']]);
+		// 获取权限列表
+		$accessToken['username']			= $admin['username'];
+		// 获取权限列表
+		$accessToken['auth_rules']			= $AuthRule->getAuthList($admin['uid'], 'manager');;
+		// 表单令牌
+		return    	json_send(['code' => 'success', 'msg' => '登录成功', 'data' => $accessToken]);
+	}
+
+	/**
+	 * 手机验证码登录			/manager/login/mobile_code
+	 * @author 唐远望
+	 * @version   1.0
+	 * @date      2026-01-15
+	 * @param string 	mobile		手机号码
+	 * @param string 	code	验证码
+	 * 
+	 */
+	public function mobile_code(Request $Request, AuthRule $AuthRule, EmployeeModel $EmployeeModel)
+	{
+		// 验证规则
+		$Request->scene('mobile_code')->validate();
+		// 接收数据
+		$phone    = $Request->input('phone', '');
+		// 接收数据
+		$code    = $Request->input('code', '');
+		// 获取数据
+		$session						    = session('loginSmsCode');
+		if (!$session)                     return json_send(['code' => 'error', 'msg' => '请先获取手机号验证码']);
+		if ($session['code'] != $code || $session['phone'] != $phone) return json_send(['code' => 'error', 'msg' => '验证码错误']);
+		// 查询用户
+		$admin    	= $EmployeeModel->where('mobile', $phone)->first(['id as uid', 'name as username', 'mobile as phone', 'status', 'password', 'insert_time', 'update_time']);
+		// 用户不存在
+		if (!$admin)	return json_send(['code' => 'error', 'msg' => '账号不存在']);
+		// 用户不存在
+		if ($admin['status']) 				return json_send(['code' => 'error', 'msg' => '该账号已停用']);
+		// 转数组
+		$admin    	= $admin->toArray();
+		// 登录
+		$accessToken 						= $EmployeeModel->Login($admin['uid'], 'manager');
+		// 比对密码
+		if (isset($accessToken['error'])) 	return json_send(['code' => 'error', 'msg' => '登录失败', 'data' => $accessToken['data']]);
+		// 获取权限列表
+		$accessToken['username']			= $admin['username'];
+		// 获取权限列表
+		$accessToken['auth_rules']			= $AuthRule->getAuthList($admin['uid'], 'manager');;
+		// 表单令牌
+		return    	json_send(['code' => 'success', 'msg' => '登录成功', 'data' => $accessToken]);
+	}
+
+
+	/**
+	 * 微信扫码登录			/manager/login/wechat
+	 * @author 唐远望
+	 * @version   1.0
+	 * @date      2026-01-19
+	 * @param string 	open_code		微信扫码登录的code
+	 * 
+	 */
+	public function wechat(Request $Request, AuthRule $AuthRule, EmployeeModel $EmployeeModel, EmployeeOpenidModel $EmployeeOpenidModel)
+	{
+		// 验证规则
+		$Request->scene('wechat')->validate();
+		// 接收数据
+		$open_code    = $Request->input('open_code', '');
+		$wechatApp = new WeChatWebApp();
+		$tokenData = $wechatApp->getAccessTokenByCode($open_code);
+		if (!$tokenData) return json_send(['code' => 'error', 'msg' => '获取微信用户信息失败']);
+		$user_open_data = $EmployeeOpenidModel->where(['openid' => $tokenData['openid']])->first();
+		if (!$user_open_data)   return json_send(['code' => 'error', 'msg' => '未绑定账号,请登录后在绑定']);
+		// 查询用户
+		$admin    	= $EmployeeModel->where('id', $user_open_data->employee_id)->first(['id as uid', 'name as username', 'mobile as phone', 'status', 'password', 'insert_time', 'update_time']);
+		// 用户不存在
+		if (!$admin)	return json_send(['code' => 'error', 'msg' => '账号不存在']);
+		// 用户不存在
+		if ($admin['status']) 				return json_send(['code' => 'error', 'msg' => '该账号已停用']);
+		// 转数组
+		$admin    	= $admin->toArray();
+		// 登录
+		$accessToken 						= $EmployeeModel->Login($admin['uid'], 'manager');
+		// 比对密码
+		if (isset($accessToken['error'])) 	return json_send(['code' => 'error', 'msg' => '登录失败', 'data' => $accessToken['data']]);
+		// 获取权限列表
+		$accessToken['username']			= $admin['username'];
+		// 获取权限列表
+		$accessToken['auth_rules']			= $AuthRule->getAuthList($admin['uid'], 'manager');;
+		// 表单令牌
+		return    	json_send(['code' => 'success', 'msg' => '登录成功', 'data' => $accessToken]);
+	}
+
+	/**
+	 * 微信扫码授权绑定			/manager/login/wechat_bind
+	 * @author 唐远望
+	 * @version   1.0
+	 * @date      2026-01-19
+	 * @param string 	open_code		微信扫码登录的code
+	 * 
+	 */
+	public function wechat_bind(Request $Request,EmployeeOpenidModel $EmployeeOpenidModel)
+	{
+		// 验证规则
+		$Request->scene('wechat_bind')->validate();
+		$uid             = request('access_token.uid', 0);
+		// 接收数据
+		$open_code    = $Request->input('open_code', '');
+		$wechatApp = new WeChatWebApp();
+		$tokenData = $wechatApp->getAccessTokenByCode($open_code);
+		if (!$tokenData) return json_send(['code' => 'error', 'msg' => '获取微信用户信息失败']);
+		$user_open_data = $EmployeeOpenidModel->where(['openid' => $tokenData['openid'],'employee_id'=> $uid])->first();
+		if ($user_open_data)   return json_send(['code' => 'error', 'msg' => '微信已绑定,无需重复绑定']);
+		//新增绑定记录
+		$EmployeeOpenidModel->create([
+			'openid' => $tokenData['openid'],
+			'unionid' => isset($tokenData['unionid']) ? $tokenData['unionid'] : '',
+			'employee_id' => $uid,
+			'insert_time' => time(),
+		]);
+		return json_send(['code' => 'success', 'msg' => '绑定成功','data'=>'']);
+	}
 }

+ 4 - 0
app/Http/Controllers/Manager/Personnel/Employee.php

@@ -229,6 +229,8 @@ class Employee extends Controller
         $request->scene('add')->validate();
         // 接收数据
         $all_data = request()->all();
+        $email = request('email', '');
+        $all_data['email'] = $email;
         //查询是否存在
         $map = ['name' => $all_data['name']];
         $department_ids =  request('department_ids', '');
@@ -268,6 +270,8 @@ class Employee extends Controller
         $id         = request('id', 0);
         // 接收数据
         $all_data = request()->all();
+        $email = request('email', '');
+        $all_data['email'] = $email;
         $department_ids =  request('department_ids', '');
         $all_data['department_ids'] = $department_ids;
         $city_ids =  request('city_ids', '');

+ 5 - 1
app/Http/Middleware/Manager/AccessAuth.php

@@ -14,7 +14,11 @@ class AccessAuth
     protected   $except     = [
         'manager/login/index',
         'manager/login/mobile',
-        'manager/citys/list'
+        'manager/login/email',
+        'manager/login/send_code',
+        'manager/login/mobile_code',
+        'manager/citys/list',
+        'manager/login/wechat'
     ];
     //默认配置
     protected   $_config    = [

+ 5 - 1
app/Http/Middleware/Manager/Login.php

@@ -12,7 +12,11 @@ class Login
     protected   $except     = [
         'manager/login/index',
         'manager/login/mobile',
-        'manager/citys/list'
+        'manager/login/email',
+        'manager/login/send_code',
+        'manager/login/mobile_code',
+        'manager/citys/list',
+        'manager/login/wechat'
     ];
     //默认配置
     protected   $_config    = [

+ 3 - 0
app/Http/Requests/Api/Login.php

@@ -32,6 +32,9 @@ class Login extends BaseRequest
     protected   $scenes         = [
         'login'                  => ['employee_code', 'password'],
         'mobile'                 => ['phone', 'password'],
+        'send_code'              => ['phone'],
+        'email'                  => ['email', 'password'],
+        'mobile_code'            => ['phone', 'code']
     ];
 
     /**

+ 4 - 0
app/Http/Requests/Manager/Login.php

@@ -32,6 +32,10 @@ class Login extends BaseRequest
     protected   $scenes         = [
         'login'                  => ['username', 'password'],
         'mobile'                 => ['phone', 'password'],
+        'send_code'              => ['phone'],
+        'email'                  => ['email', 'password'],
+        'mobile_code'            => ['phone', 'code'],
+        'wechat'                 => ['open_code'],
     ];
 
     /**

+ 4 - 0
app/Models/Manager/Personnel/Employee.php

@@ -38,6 +38,7 @@ class Employee extends Model
         $insert_data = [
             'name' => $data['name'],
             'mobile'    => $data['mobile'],
+            'email' => $data['email'],
             'password'  => md5($data['password']),
             'role_id'     => $data['role_id'],
             'province_ids'    => isset($data['province_ids']) ? $data['province_ids'] : '',
@@ -98,6 +99,7 @@ class Employee extends Model
             $insert_data = [
                 'name' => $data['name'],
                 'mobile'    => $data['mobile'],
+                'email' => $data['email'],
                 'password'  => md5($data['password']),
                 'role_id'     => $data['role_id'],
                 'province_ids'    => isset($data['province_ids']) ? $data['province_ids'] : '',
@@ -160,6 +162,7 @@ class Employee extends Model
         }
         $Employee->name = $data['name'];
         $Employee->mobile = $data['mobile'];
+        $Employee->email = $data['email'];
         if (isset($data['password']) && $data['password'] != '') $Employee->password = md5($data['password']);
         $Employee->role_id = $data['role_id'];
         $Employee->city_ids = isset($data['city_ids']) ? ',' . $data['city_ids'] . ',' : '';
@@ -189,6 +192,7 @@ class Employee extends Model
             $EmployeeDepartmentModel = new EmployeeDepartmentModel();
             $Employee->name = $data['name'];
             $Employee->mobile = $data['mobile'];
+            $Employee->email = $data['email'];
             if (isset($data['password']) && $data['password'] != '') $Employee->password = md5($data['password']);
             $Employee->role_id = $data['role_id'];
             $Employee->city_ids = isset($data['city_ids']) ? ',' . $data['city_ids'] . ',' : '';

+ 151 - 0
app/Models/Manager/Personnel/EmployeeOpenid.php

@@ -0,0 +1,151 @@
+<?php
+
+namespace App\Models\Manager\Personnel;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Facades\DB;
+
+/**
+ * 员工openid模型
+ * @author 唐远望
+ * @version 1.0
+ * @date 2026-01-19
+ */
+class EmployeeOpenid extends Model
+{
+    use HasFactory;
+    // 与模型关联的表名
+    protected $table = 'personnel_employee_openid';
+    // 是否主动维护时间戳
+    public $timestamps = false;
+    // 定义时间戳字段名
+    // const CREATED_AT = 'insert_time';
+    // const UPDATED_AT = 'update_time';
+
+
+    /**
+     * 添加
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-04
+     */
+    public function addEmployeeOpenid_content($data)
+    {
+        $insert_data = [
+            'employee_id' => $data['employee_id'],
+            'unionid'    => $data['unionid'],
+            'openid' => $data['openid'],
+            'type'  => isset($data['type']) ? $data['type'] : '3',
+            'insert_time' => time(),
+        ];
+        $EmployeeOpenid_id = $this->insertGetId($insert_data);
+        return $EmployeeOpenid_id;
+    }
+
+
+
+    /**
+     * 写入数据
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-04
+     * @param $data
+     * @return bool
+     */
+    public function addEmployeeOpenid($data)
+    {
+        DB::beginTransaction();
+        try {
+            $insert_data = [
+                'employee_id' => $data['employee_id'],
+                'unionid'    => $data['unionid'],
+                'openid' => $data['openid'],
+                'type'  => isset($data['type']) ? $data['type'] : '3',
+                'insert_time' => time(),
+            ];
+            $EmployeeOpenid_id = $this->insertGetId($insert_data);
+            DB::commit();
+            return $EmployeeOpenid_id;
+            // 成功处理...
+        } catch (\Exception $e) {
+            DB::rollBack();
+            // 错误处理...
+            return false;
+        }
+    }
+
+
+    /**
+     * 编辑内容
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-04
+     * @param $data
+     * @return bool
+     */
+    public function editEmployeeOpenid_content($where, $data)
+    {
+        $EmployeeOpenid = $this->where($where)->first();
+        if (!$EmployeeOpenid) {
+            return false;
+        }
+        $EmployeeOpenid->employee_id = $data['employee_id'];
+        $EmployeeOpenid->unionid = $data['unionid'];
+        $EmployeeOpenid->openid = $data['openid'];
+        $EmployeeOpenid->type = isset($data['type']) ? $data['type'] : '3';
+        $EmployeeOpenid->update_time = time();
+        $EmployeeOpenid->save();
+        return true;
+    }
+
+
+
+    /**
+     * 更新数据
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-04
+     * @param $data
+     * @return bool
+     */
+    public function updateEmployeeOpenid($EmployeeOpenid, $data)
+    {
+        DB::beginTransaction();
+        try {
+            $EmployeeOpenid->employee_id = $data['employee_id'];
+            $EmployeeOpenid->unionid = $data['unionid'];
+            $EmployeeOpenid->openid = $data['openid'];
+            $EmployeeOpenid->type = isset($data['type']) ? $data['type'] : '3';
+            $EmployeeOpenid->update_time = time();
+            $EmployeeOpenid->save();
+
+            DB::commit();
+            return true;
+            // 成功处理...
+        } catch (\Exception $e) {
+            DB::rollBack();
+            print_r($e->getMessage());
+            exit;
+            // 错误处理...
+            return false;
+        }
+    }
+    /**
+     * 删除数据
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-12-04
+     * @param $id
+     * @return bool
+     */
+    public function deleteEmployeeOpenid($where)
+    {
+        $EmployeeOpenid = $this->where($where)->first();
+        if (!$EmployeeOpenid) {
+            return false;
+        }
+        $EmployeeOpenid->delete();
+        return true;
+    }
+}

+ 59 - 0
app/Servers/Sms/GuoDu.php

@@ -0,0 +1,59 @@
+<?php namespace App\Servers\Sms;
+
+use Ixudra\Curl\Facades\Curl;
+
+/**
+ * 验证码模型
+ *
+ * @author    刘相欣
+ */
+class GuoDu {
+
+    // 已开通的帐号名称
+    private $operId     = 'dfwyyz';
+    //与帐号名称对应的密码
+    private $operPass   = 'vTfTsYzX';
+
+    /**
+     * 发送短信
+     * @param  string $desMobile    接收手机号码
+     * @param  string $content      短信内容
+     * @param  string $sign         签名
+     * 
+     * @return array
+     * 
+     */
+    public function sendSms($desMobile,$content,$sign){
+        $result         = Curl::to('http://qxtsms.guodulink.net/QxtSms/QxtFirewall')->withData([
+                            'OperID'=>$this->operId,
+                            'OperPass'=>$this->operPass,
+                            'DesMobile'=>$desMobile,
+                            'Content'=>'【'.$sign.'】'.$content,
+                            'Content_Code'=>1
+                        ])->post();
+        //如果没有返回值
+        if( !$result )  return['error'=>'短信通道未正确返回格式'];
+        // XML格式转PHP数组
+        $result         = simplexml_load_string($result);
+        $result         = json_decode(json_encode($result),true);
+        // 返回结果
+        return          $result;
+    }
+
+    /**
+     * 查询余额
+     * 
+     * @return array|int
+     * 
+     */
+    public function surplus(){
+		// 查询
+        $result         = Curl::to('http://124.251.7.68:8100/QxtSms_surplus/surplus')->withData(['OperID'=>$this->operId,'OperPass'=>$this->operPass])->get();
+        //如果没有返回值
+        if( !$result )  return['error'=>'短信通道未正确返回格式'];
+        // 返回结果
+        return          $result;
+    }
+
+}
+

+ 88 - 0
app/Servers/Sms/VerifyCode.php

@@ -0,0 +1,88 @@
+<?php
+
+namespace App\Servers\Sms;
+
+use App\Facades\Servers\Sms\GuoDu;
+use App\Facades\Servers\Aliyun\Sms as Aliyun;
+use App\Facades\Servers\Tencent\Sms as Tencent;
+
+/**
+ * 验证码模型
+ * @author 唐远望
+ * @version   1.0
+ * @date      2026-01-15
+ * 
+ */
+class VerifyCode
+{
+
+
+    public function sendCode($phone, $verifyCode)
+    {
+        // 判断运营商,以方便发送短信
+        $type                               = config('verifycode.operator_type');
+        // 如果是国都
+        if ($type == 'guodu') {
+            // 发送短信
+            $result                         = GuoDu::sendSms($phone, '您的验证码是:' . $verifyCode . ',5分钟内有效,请勿外泄。', config('verifycode.guodu.sms_sign'));
+            // 如果code不是03
+            if ($result['code'] != '03' &&  $result['code'] != '01')    return ['error' => '发送失败', 'data' => $result];
+            // 返回结果
+            return                          $result;
+        }
+        // 如果是阿里云
+        if ($type == 'aliyun') {
+            // 发送短信
+            $result                         = Aliyun::sendSms($phone, config('verifycode.aliyun.sms_sign'), config('verifycode.aliyun.sms_tpl'), ['code' => $verifyCode]);;
+            // 如果code不是03
+            if (isset($result['error']))    return ['error' => $result['error'], 'data' => $result];
+            // 返回结果
+            return                          $result;
+        }
+        // 如果是阿里云
+        if ($type == 'tencent') {
+            // 发送短信
+            $result                         = Tencent::sendSms($phone, config('verifycode.tencent.sms_sign'), config('verifycode.tencent.sms_tpl'), [$verifyCode]);
+            // 如果code不是03
+            if (isset($result['error']))    return ['error' => $result['error'], 'data' => $result];
+            // 返回结果
+            return                          $result;
+        }
+        // 返回结果
+        return                              ['error' => '未知运营商,请配置运营商类型'];
+    }
+    public function sendRemind($phone, $content)
+    {
+        // 判断运营商,以方便发送短信
+        $type                               = config('verifycode.operator_type');
+        // 如果是国都
+        if ($type == 'guodu') {
+            // 发送短信
+            $result                         = GuoDu::sendSms($phone, $content, config('verifycode.guodu.sms_sign'));
+            // 如果code不是03
+            if ($result['code'] != '03' &&  $result['code'] != '01')    return ['error' => '发送失败', 'data' => $result];
+            // 返回结果
+            return                          $result;
+        }
+        // 如果是阿里云
+        if ($type == 'aliyun') {
+            // 发送短信
+            $result                         = Aliyun::sendSms($phone, config('verifycode.aliyun.sms_sign'), config('verifycode.aliyun.sms_tpl'), ['code' => $content]);;
+            // 如果code不是03
+            if (isset($result['error']))    return ['error' => $result['error'], 'data' => $result];
+            // 返回结果
+            return                          $result;
+        }
+        // 如果是阿里云
+        if ($type == 'tencent') {
+            // 发送短信
+            $result                         = Tencent::sendSms($phone, config('verifycode.tencent.sms_sign'), config('verifycode.tencent.sms_tpl'), [$content]);
+            // 如果code不是03
+            if (isset($result['error']))    return ['error' => $result['error'], 'data' => $result];
+            // 返回结果
+            return                          $result;
+        }
+        // 返回结果
+        return                              ['error' => '未知运营商,请配置运营商类型'];
+    }
+}

+ 304 - 0
app/Servers/Wechat/WeChatWebApp.php

@@ -0,0 +1,304 @@
+<?php
+
+namespace App\Servers\Wechat;
+
+/**
+ * 微信网站应用
+ * @author 唐远望
+ * @version 1.0
+ * @date 2026-01-19
+ */
+class WeChatWebApp
+{
+    private $appId;
+    private $appSecret;
+    private $redirectUri;
+
+    /**
+     * 构造函数
+     * 
+     * @param string $appId 应用唯一标识
+     * @param string $appSecret 应用密钥
+     * @param string $redirectUri 授权回调地址
+     */
+    public function __construct()
+    {
+        $this->appId = config('wechat.openplat.app_id',[]);
+        $this->appSecret = config('wechat.openplat.secret',[]);
+        $this->redirectUri = urlencode(config('wechat.openplat.release_host_url',[]));
+    }
+
+    /**
+     * 第一步:生成授权URL,引导用户跳转到微信授权页面
+     * 
+     * @param string $scope 应用授权作用域
+     *        snsapi_base - 静默授权,不弹出授权页面,只能获取openid
+     *        snsapi_userinfo - 弹出授权页面,可获取用户信息
+     * @param string $state 重定向后会带上state参数,开发者可以填写任意参数值
+     * @return string 授权URL
+     */
+    public function getAuthorizeUrl($scope = 'snsapi_base', $state = 'STATE')
+    {
+        $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$this->appId}&redirect_uri={$this->redirectUri}&response_type=code&scope={$scope}&state={$state}#wechat_redirect";
+        return $url;
+    }
+
+    /**
+     * 第二步:通过code获取access_token和openid
+     * 
+     * @param string $code 授权code
+     * @return array|false 成功返回数组,失败返回false
+     */
+    public function getAccessTokenByCode($code)
+    {
+        $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$this->appId}&secret={$this->appSecret}&code={$code}&grant_type=authorization_code";
+
+        $result = $this->httpGet($url);
+
+        if ($result) {
+            $data = json_decode($result, true);
+
+            if (!isset($data['errcode'])) {
+                return $data; // 成功返回
+            } else {
+                $this->logError("获取access_token失败", $data);
+                return false;
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * 刷新access_token
+     * 
+     * @param string $refreshToken 刷新token
+     * @return array|false 成功返回数组,失败返回false
+     */
+    public function refreshAccessToken($refreshToken)
+    {
+        $url = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid={$this->appId}&grant_type=refresh_token&refresh_token={$refreshToken}";
+
+        $result = $this->httpGet($url);
+
+        if ($result) {
+            $data = json_decode($result, true);
+
+            if (!isset($data['errcode'])) {
+                return $data; // 成功返回
+            } else {
+                $this->logError("刷新access_token失败", $data);
+                return false;
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * 获取用户信息(需要scope为snsapi_userinfo)
+     * 
+     * @param string $accessToken 接口调用凭证
+     * @param string $openid 用户唯一标识
+     * @return array|false 成功返回数组,失败返回false
+     */
+    public function getUserInfo($accessToken, $openid)
+    {
+        $url = "https://api.weixin.qq.com/sns/userinfo?access_token={$accessToken}&openid={$openid}&lang=zh_CN";
+
+        $result = $this->httpGet($url);
+
+        if ($result) {
+            $data = json_decode($result, true);
+
+            if (!isset($data['errcode'])) {
+                return $data; // 成功返回
+            } else {
+                $this->logError("获取用户信息失败", $data);
+                return false;
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * 验证access_token是否有效
+     * 
+     * @param string $accessToken 接口调用凭证
+     * @param string $openid 用户唯一标识
+     * @return bool 是否有效
+     */
+    public function checkAccessToken($accessToken, $openid)
+    {
+        $url = "https://api.weixin.qq.com/sns/auth?access_token={$accessToken}&openid={$openid}";
+
+        $result = $this->httpGet($url);
+
+        if ($result) {
+            $data = json_decode($result, true);
+
+            if (isset($data['errcode']) && $data['errcode'] == 0) {
+                return true; // 有效
+            }
+        }
+
+        return false; // 无效
+    }
+
+    /**
+     * 完整的授权流程处理
+     * 
+     * @return array|false 成功返回用户信息数组,失败返回false
+     */
+    public function handleAuthorization()
+    {
+        // 检查是否有授权code
+        if (!isset($_GET['code'])) {
+            // 没有code,跳转到授权页面
+            $url = $this->getAuthorizeUrl('snsapi_userinfo', 'authorize');
+            header("Location: {$url}");
+            exit;
+        }
+
+        // 获取授权code
+        $code = $_GET['code'];
+
+        // 通过code获取access_token
+        $tokenData = $this->getAccessTokenByCode($code);
+
+        if (!$tokenData) {
+            return false;
+        }
+
+        // 存储token信息到session
+        session_start();
+        $_SESSION['wechat_access_token'] = $tokenData['access_token'];
+        $_SESSION['wechat_refresh_token'] = $tokenData['refresh_token'];
+        $_SESSION['wechat_openid'] = $tokenData['openid'];
+        $_SESSION['wechat_token_expire'] = time() + $tokenData['expires_in'];
+
+        return $tokenData;
+    }
+
+    /**
+     * 获取当前有效的access_token(自动刷新)
+     * 
+     * @return string|false 有效的access_token
+     */
+    public function getValidAccessToken()
+    {
+        session_start();
+
+        // 检查session中是否有token信息
+        if (!isset($_SESSION['wechat_access_token'])) {
+            return false;
+        }
+
+        $accessToken = $_SESSION['wechat_access_token'];
+        $refreshToken = $_SESSION['wechat_refresh_token'];
+        $openid = $_SESSION['wechat_openid'];
+        $expireTime = $_SESSION['wechat_token_expire'];
+
+        // 检查token是否即将过期(提前5分钟刷新)
+        if (time() > $expireTime - 300) {
+            // 刷新token
+            $newTokenData = $this->refreshAccessToken($refreshToken);
+
+            if ($newTokenData) {
+                // 更新session中的token信息
+                $_SESSION['wechat_access_token'] = $newTokenData['access_token'];
+                $_SESSION['wechat_refresh_token'] = $newTokenData['refresh_token'];
+                $_SESSION['wechat_token_expire'] = time() + $newTokenData['expires_in'];
+
+                $accessToken = $newTokenData['access_token'];
+            } else {
+                // 刷新失败,需要重新授权
+                return false;
+            }
+        }
+
+        return $accessToken;
+    }
+
+    /**
+     * HTTP GET 请求
+     * 
+     * @param string $url 请求URL
+     * @return string|false 响应内容
+     */
+    private function httpGet($url)
+    {
+        if (function_exists('curl_init')) {
+            $ch = curl_init();
+            curl_setopt($ch, CURLOPT_URL, $url);
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
+            curl_setopt($ch, CURLOPT_TIMEOUT, 30);
+
+            $response = curl_exec($ch);
+
+            if (curl_errno($ch)) {
+                $this->logError("CURL错误", curl_error($ch));
+                curl_close($ch);
+                return false;
+            }
+
+            curl_close($ch);
+            return $response;
+        } else {
+            // 备用方法:使用file_get_contents
+            $context = stream_context_create([
+                'ssl' => [
+                    'verify_peer' => false,
+                    'verify_peer_name' => false,
+                ]
+            ]);
+
+            return file_get_contents($url, false, $context);
+        }
+    }
+
+    /**
+     * 错误日志记录
+     * 
+     * @param string $message 错误信息
+     * @param mixed $data 错误数据
+     */
+    private function logError($message, $data = null)
+    {
+        $log = date('Y-m-d H:i:s') . " - {$message}";
+
+        if ($data !== null) {
+            $log .= " - " . (is_array($data) ? json_encode($data) : $data);
+        }
+
+        error_log($log . PHP_EOL, 3, 'wechat_oauth_error.log');
+    }
+
+    /**
+     * 获取当前openid
+     * 
+     * @return string|false openid
+     */
+    public function getOpenId()
+    {
+        session_start();
+        return isset($_SESSION['wechat_openid']) ? $_SESSION['wechat_openid'] : false;
+    }
+
+    /**
+     * 清除session中的授权信息
+     */
+    public function clearSession()
+    {
+        session_start();
+        unset(
+            $_SESSION['wechat_access_token'],
+            $_SESSION['wechat_refresh_token'],
+            $_SESSION['wechat_openid'],
+            $_SESSION['wechat_token_expire']
+        );
+    }
+}

+ 18 - 0
config/verifycode.php

@@ -0,0 +1,18 @@
+<?php
+
+return [
+
+    'operator_type'     => env('VERIFYCODE_OPERATOR_TYPE', 'aliyun'), // 运营商,aliyun or tencent or guodu
+    'aliyun'=>[
+        'sms_sign'      => env('VERIFYCODE_ALIYUN_SMS_SIGN', '开邻'),
+        'sms_tpl'       => env('VERIFYCODE_ALIYUN_SMS_TPL', 'SMS_483305249'),
+    ],
+    'guodu'=>[
+        'sms_sign'      => env('VERIFYCODE_GUODU_SMS_SIGN', '开邻'),
+    ],
+    'tencent'=>[
+        'sms_sign'      => env('VERIFYCODE_TENCENT_SMS_SIGN', '开邻'),
+        'sms_tpl'       => env('VERIFYCODE_TENCENT_SMS_TPL', '2475442'),
+    ],
+    
+];

+ 24 - 0
config/wechat.php

@@ -0,0 +1,24 @@
+<?php
+
+return [
+    'mini' => [
+        'app_id' => env('WECHAT_APP_ID', 'wx246605ec671bf08d'),
+        'secret' => env('WECHAT_SECRET', '5dfa6b60f10347ffa7b959658b3f2496'),
+        // 下面为可选项
+        // 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
+        'response_type' => 'array',
+        'log' => [
+            'level' => 'debug',
+            'file' => storage_path('logs') . '/wechat.log',
+        ],
+    ],
+    'openplat' => [
+        'app_id'               => env('WECHAT_OPENPLAT_APP_ID', 'wx2386988b9b706ff5'),
+        'secret'               => env('WECHAT_OPENPLAT_SECRET', '3b487dd62a738939bb833f928d4fa4bd'),
+        'token'                => env('WECHAT_OPENPLAT_TOKEN', 'Afd61RPH3GzEwfEATRwdJVKhy'),
+        'aes_key'              => env('WECHAT_OPENPLAT_AES_KEY', 'FL1brptJzQeDMwp5nvuojb8YEDx9GXy9kxaQ8JQl2Zi'),
+        'host_url'             => env('WECHAT_OPENPLAT_HOST_URL', 'https://retrieveapi.dfwy.tech/'),
+        'release_host_url'     => env('WECHAT_OPENPLAT_RELEASE_HOST_URL', 'https://retrieveapi.findit.ltd/'),
+    ],
+
+];

+ 6 - 0
routes/api.php

@@ -20,6 +20,12 @@ Route::any('login/index', [App\Http\Controllers\Api\Login::class, 'index']);
 Route::any('login/mobile', [App\Http\Controllers\Api\Login::class, 'mobile']);
 // 退出登录
 Route::any('login/out', [App\Http\Controllers\Api\Login::class, 'out']);
+//发送短信验证码
+Route::any('login/send_code',[App\Http\Controllers\Api\Login::class,'send_code']);
+//邮箱密码登录
+Route::any('login/email', [App\Http\Controllers\Api\Login::class, 'email']);
+//手机验证码登录
+Route::any('login/mobile_code', [App\Http\Controllers\Api\Login::class,'mobile_code']);
 
 // ------违规处理------
 // 低价挂网商品违规处理-列表

+ 10 - 0
routes/manager.php

@@ -19,6 +19,16 @@ Route::any('login/index', [App\Http\Controllers\Manager\Login::class, 'index']);
 Route::any('login/mobile', [App\Http\Controllers\Manager\Login::class, 'mobile']);
 // 退出登录
 Route::any('login/out', [App\Http\Controllers\Manager\Login::class, 'out']);
+//发送短信验证码
+Route::any('login/send_code',[App\Http\Controllers\Manager\Login::class,'send_code']);
+//邮箱密码登录
+Route::any('login/email', [App\Http\Controllers\Manager\Login::class, 'email']);
+//手机验证码登录
+Route::any('login/mobile_code', [App\Http\Controllers\Manager\Login::class,'mobile_code']);
+//微信扫码登录
+Route::any('login/wechat', [App\Http\Controllers\Manager\Login::class, 'wechat']);
+//微信扫码授权绑定
+Route::any('login/wechat_bind', [App\Http\Controllers\Manager\Login::class, 'wechat_bind']);
 
 //城市列表
 Route::any('citys/list', [App\Http\Controllers\Manager\Citys::class, 'list']);