Commit e53fbf36 by hcy001

1.0

parent 2db22a13
......@@ -25,18 +25,48 @@ use App\Http\Requests;
use RedisDB;
/*
* pc接口
* 公共接口
*/
class ApiController extends Controller
{
public $user_id = "";
public $user_name = "";
public function Entrance(Request $request, $id){
// //统一入口
// $perm=perm($request->user->userId,$id,'api');
// if($perm!==true){
// $this->Export(10010,'没有操作权限');
// }
//允许跨域
$origin = isset($_SERVER['HTTP_ORIGIN'])? $_SERVER['HTTP_ORIGIN'] : '';
$origin_arr = explode('//', $origin);
$allow_origin = config('website.ALLOW_ORIGIN');
if(in_array($origin_arr['1'], $allow_origin)){
header('Access-Control-Allow-Origin:'.$origin);
header('Access-Control-Allow-Credentials:true');
header('Access-Control-Allow-Methods:POST');
header('Access-Control-Allow-Headers:x-requested-with,content-type');
}
$Redis= \RedisDB::connection();
//来自不一样的端,判断是否已经登录
$source = $request->input("source","pc"); //来源端:内部后台:pc 云芯系统:yunxin App: app 小程序:h5_app
switch ($source){
case "pc"://来源 内部后台
$oa_skey = $request->cookie("oa_skey");
$oa_user_id = $request->cookie("oa_user_id");
$key = $oa_user_id.":".substr($oa_skey,0,8);
$userInfo = $Redis->get($key);
if (empty($oa_skey) || empty($oa_user_id) || empty($userInfo)){
Export(1001,"请先登录");
}
$userInfoArr = \GuzzleHttp\json_decode($userInfo,true);
$this->user_id = $userInfoArr["userId"];
$this->user_name = $userInfoArr["email"];
break;
}
$this->$id($request, $id);
}
//关闭整个询价单
private function ApiInquiryClose($request, $id){
Export((new InquiryModel())->inquiryClose($request->input('inquiry_id')));
......@@ -130,7 +160,7 @@ class ApiController extends Controller
// 新增报价
public function ApiAddQuote($request, $id)
{
$this->Export((new QuoteModel())->add($request));
Export((new QuoteModel())->add($request));
}
}
<?php
namespace App\Model;
use ClassPreloader\Config;
use Illuminate\Database\Eloquent\Model;
use League\Flysystem\Exception;
use Request;
use DB;
use Illuminate\Support\Facades\Redis;
use App\Plugin\Session;
class LoginModel extends Model
{
protected $connection='yunxin';
protected $table='supplier_account';
protected $primaryKey='id';
public $timestamps = false;
private $CheckCode = true; //是否开启验证码验证
public $isOneLogin = true; //是否开启单一账号登录
/*
* 供应商登录
* @param int $account_id 账号id
*/
public function Login($request){
session_start();
$account_name = Request::input('account_name');
$password = Request::input('password');
$code= Request::input('code');//验证码
if (empty($account_name)) return [1001,'账号不得为空'];
if (empty($password) ) return [1001,'登录密码不得为空'];
if (utf8_strlen($password) != 32 ) return [1001,'登录密码长度不对'];
if (empty($code)) return [1001,'验证码不得为空'];
if ($this->CheckCode && Session::get('yunxin_captcha',true) != $code) {
return [1001,'验证码不正确'];
}
$account = $this->where("mobile",$account_name)->first();
if (!$account){
return [1002,'不存在此账号'];
}
if ($account['password'] != createPassword($password)){
return [1003,'密码错误'];
}
if (!$account['status']){
return [1006,'此账号已被禁用'];
}
$account_id = $account['id']; //账号id
//用户详情
$supplierInfo = DB::connection("pur")->table("supplier_channel")->where("supplier_id",$account['supplier_id'])->first();
//用户角色
$yunxinCon = DB::connection("yunxin");
$roleInfo = $yunxinCon->table("auth_role_access")->where("account_id",$account_id)->first();
$info = [
'supplier_id'=>$account['supplier_id'],
'supplier_name'=>$account['supplier_name'],
'supplier_code'=>$account['supplier_code'],
'supplier_com_id'=>$account['supplier_com_id'],
'supplier_com_name'=>$account['supplier_com_name'],
'supplier_com_code'=>$account['supplier_com_code'],
'mobile'=>$account['mobile'],
'account_id'=>$account['id'],
'appid'=>$account['appid'],
'key'=>$account['key'],
'role_id'=>$roleInfo['role_id'],
];
try{
$con = DB::connection('yunxin');
$con->beginTransaction();
#登录信息写入缓存
$key = md5($account_name.$code.time());
$expire = 3600*24;//过期24个小时
$res = Redis::setex('yunxin_login_'.$key."_supplier_accountid_".$account_id, $expire, utf8JsonEncode($info));
if ($res != 'OK'){
throw new Exception('写入缓存失败',1004);
}
#记录登录日志
$log['account_id'] = $account['id'];
$log['action_ip'] = $request->getClientIp();
$log['create_time'] = time();
$log['remark'] = utf8JsonEncode($info);
$logid = $yunxinCon->table("login_log")->insertGetId($log);
if (!$logid){
throw new Exception('插入日志失败',1005);
}
$con->commit();
return ['0','登录成功',$key,$account['password'] == createPassword(md5('ichunt123')) ? 1:0];
}catch (\Exception $e) {
$con->rollBack();
return [$e->getCode(),$e->getMessage()];
}
}
/*
* 重置密码
* @param int $account_id 账号id
*/
public function RestPassword($request){
session_start();
$old_password = $request->input('old_password');
$new_password = $request->input('new_password');
$code= Request::input('code');//验证码
if ($this->CheckCode && (empty($code) || Session::get('yunxin_captcha',true) != $code)) {
return [1001,'验证码不正确'];
}
$account = $this->where("id",$request->account_id)->first();
if (!$account){
return [1002,'不存在此账号'];
}
if ($account['password'] != createPassword($old_password)){
return [1003,'旧密码错误'];
}
if (utf8_strlen($new_password) != 32 ) return [1001,'新密码长度不对'];
$password = createPassword($new_password);
$this->where("id",$request->account_id)->update(['password'=>$password]);
$userInfoKey = Redis::keys('yunxin_login_'.$request->yunxin_token."*");
foreach ($userInfoKey as $k=>$v){
Redis::del($v);//删除登录信息
}
setcookie('yunxin_token','',time()-3600); //清除cookie
return [0,"重置密码成功,请重新登录"];
}
/*
* 更新密码
* @param int $account_id 账号id
*/
public function ForgetPassword($request){
$account_name = $request->input('account_name');
$new_password = $request->input('new_password');
$mobile_code= Request::input('moblie_code');//手机验证码
$yunxin_mobile_code = Redis::get('yunxin_mobile_code_'.$account_name);
if ($yunxin_mobile_code != $mobile_code){
return [1001,'手机验证码不正确'];
}
$account = $this->where("id",$request->account_id)->first();
if (!$account){
return [1002,'不存在此账号'];
}
if (utf8_strlen($new_password) != 32 ) return [1001,'新密码长度不对'];
$password = createPassword($new_password);
$this->where("id",$request->account_id)->update(['password'=>$password]);
$userInfoKey = Redis::keys('yunxin_login_'.$request->yunxin_token."*");
foreach ($userInfoKey as $k=>$v){
Redis::del($v);//删除登录信息
}
return [0,"成功,请登录"];
}
/*
* 退出登录
*/
public function LoginOut($request){
$userInfoKey = Redis::keys('yunxin_login_'.$request->yunxin_token."*");
foreach ($userInfoKey as $k=>$v){
Redis::del($v);//删除登录信息
}
setcookie('yunxin_token','',time()-3600); //清除cookie
}
/*
* 找回密码发送手机验证码
*/
public function forgetMobileCode($input){
$mobile = $input['mobile']; //手机号码
$code = $input['code']; //图形验证码
if (Session::get('yunxin_captcha',true) != $code) {
//用户输入验证码错误
Export([1001,'验证码输入错误']);
}
$checkTime = Redis::ttl('yunxin_mobile_code_'.$mobile);
if ($checkTime > 0){
Export([1001,'同一手机号一分钟只能请求一次验证码!']);
}
$check = $this->where("mobile",$mobile)->first();
if (!$check){
Export([1001,'系统不存在此手机号']);
}
$moblie_code = mt_rand(9999, 99999); //手机随机码
$expire = 80;//60秒
$check1 = Redis::setex('yunxin_mobile_code_'.$mobile, $expire, $moblie_code);
$check2 = SendMsg(['code'=>$moblie_code],'login-code',[$mobile]);//发送验证码
if ($check1 == 'OK'){
$forget_password_token = md5(time().$moblie_code.$mobile);
Redis::setex('yunxin_forget_password_token_'.$mobile, $expire, $forget_password_token);
Export([0,'成功',$forget_password_token]);
}else{
Export([1002,'生成手机验证码失败']);
}
}
/*
* 判断是否存在手机验证码
*/
public function checkMobileCode($mobile,$code){
if (Redis::get('yunxin_mobile_code_'.$mobile) == $code ){
Redis::del('yunxin_mobile_code_'.$mobile);
return true;
}else{
return false;
}
}
/*
* 找回密码
*/
public function ForgetPassword2($request){
$mobile = $request->input('mobile');
$new_password = $request->input('new_password');
$token= Request::input('token');//手机验证码
$redis_token = Redis::get('yunxin_forget_password_token_'.$mobile);
if ($token != $redis_token){
return [1001,'token已过期,请重试'];
}
$account = $this->where("mobile",$mobile)->first();
if (!$account){
return [1002,'不存在此账号'];
}
if (utf8_strlen($new_password) != 32 ) return [1001,'新密码长度不对'];
$password = createPassword($new_password);
$this->where("mobile",$mobile)->update(['password'=>$password]);
$userInfoKey = Redis::keys('yunxin_login_'.$request->yunxin_token."*");
foreach ($userInfoKey as $k=>$v){
Redis::del($v);//删除登录信息
}
setcookie('yunxin_token','',time()-3600); //清除cookie
return [0,"成功,请登录"];
}
}
\ No newline at end of file
......@@ -23,6 +23,17 @@ return [
'release' =>'http://frq.ichunt.net',
],
//允许跨域站点
'ALLOW_ORIGIN' => array(
'www.frq.liexin.com' ,
'frq.liexin.com' ,
'szfrq.liexin.com',
'frq.ichunt.com',
'szfrq.ichunt.com',
'yunxin.ichunt.com',
),
"domain" => "liexin.net",
'export_domain' => "http://export.liexin.com", //通用导出网址
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment