Commit 846af201 authored by hujun's avatar hujun

登陆、注册、忘记密码 修改 增加分享二维

parent 3e4f19d3
......@@ -6,5 +6,5 @@ define('PAGESIZE', 15); //分页每页条数
return [
'jwt_key' => 'tonglian+123',
// 应用模式状态
'app_status' => 'prdConfig',
'app_status' => 'dev-config',
];
\ No newline at end of file
......@@ -25,7 +25,7 @@ class Broker extends Basic{
public function index() {
$params = $this->params;
$data['status'] = 101;
$data['data'] = '';
$data['data'] = array();
if ($params['house_id']) {
$pageNo = empty($params['pageNo']) ? 1 : $params['pageNo'];
......@@ -51,7 +51,7 @@ class Broker extends Basic{
public function appraiser() {
$params = $this->params;
$data['status'] = 101;
$data['data'] = '';
$data['data'] = array();
$data['msg'] = '';
if (empty($params['agents_id'])) {
return $this->response($data['status'], 'agents_id is null');
......@@ -119,7 +119,7 @@ class Broker extends Basic{
public function commentAndDeal() {
$params = $this->params;
$data['status'] = 200;
$data['data'] = '';
$data['data'] = array();
$data['msg'] = '';
if ($params['agent_id']) {
......@@ -169,8 +169,8 @@ class Broker extends Basic{
public function brokerDetail() {
$data['status'] = 200;
$data['data'] = '';
$data['msg'] = '';
$data['data'] = array();
$data['msg'] = '';
if ($this->params['id']) {
$agents = new Agents();
......
......@@ -20,10 +20,10 @@ class Member extends Basic
public function login() {
$data['data'] = '';
$data['data'] = array();
$data['status'] = 101;
if ($this->request->has('phone','post') && $this->request->has('pwd','post')) {
if ($this->params['phone'] && $this->params['pwd']) {
$user_data = $this->user->get([
'user_phone' => $this->params['phone'],
'status' => 0,
......@@ -69,7 +69,6 @@ class Member extends Basic
$id = $this->userId ? $this->userId : $this->params['id'];
$data['status'] = 101;
$data['data'] = '';
$data['msg'] = '';
$u_user = Session::get('u_user');
......@@ -81,7 +80,7 @@ class Member extends Basic
$data['msg'] = 'logout error';
}
return $this->response($data['status'], $data['msg'], $data['data']);
return $this->response($data['status'], $data['msg']);
}
/**
......@@ -90,7 +89,7 @@ class Member extends Basic
* @return type
*/
public function sendSms() {
$data['data'] = '';
$data['data'] = array();
$data['status'] = 101;
if ($this->request->param('phone')) {
$phone = $this->request->param('phone');
......@@ -107,7 +106,7 @@ class Member extends Basic
$message = new MessageUntils();
$_code = mt_rand(1000, 9999) . '';
// $result = $message->sendCCPSMS($phone, array($_code, '5分钟'), 214759);
$jwt = new JwtUntils();
$noteLog->phone = $phone;
$noteLog->template_msg = '【同联商业】您的验证码为'.$_code.',请于5分钟内正确输入,如非本人操作,请忽略此短信。';
$noteLog->code = $_code;
......@@ -116,8 +115,11 @@ class Member extends Basic
$noteLog->save();
Session::set('_code', $_code);
$data['data'] = ['code'=> $_code];
$jwt_data['phone'] = $phone;
$jwt_data['code'] = $_code;
$data['data']['sms_code'] = $_code;
$data['data']['token'] = $jwt->createToken($jwt_data);
$data['msg'] = ($result['statusCode'] == 0) ? '发送短信成功':$result['statusMsg'];
$data['status'] = ($result['statusCode'] == 0) ? 200 : 101;
}
......@@ -138,8 +140,8 @@ class Member extends Basic
*/
public function register() {
$result = 0;
if ($this->request->has('type','post')) {
if ($this->params['type']) {
$type = $this->params['type'];
//根据不同的类型验证不同的场景
......@@ -159,20 +161,44 @@ class Member extends Basic
'referrer_id' => $this->request->param('referrer_id'),
'referrer_source' => $this->request->param('referrer_source'),
'code' => $this->request->param('code'),
'user_nick' => $this->request->param('user_nick')
'user_nick' => $this->request->param('user_nick'),
'token' => $this->request->param('token')
], $check);
} else {
return $this->response(101, 'type is null');
}
$phone = $this->request->param('phone');
if ($this->params['token']) {
$jwt = new JwtUntils();
$jwt_data = $jwt->getDecode($this->params['token']);
$code = Session::get('_code')? Session::get('_code') : $jwt_data['data']['code'];
$jwt_phone = $jwt_data['data']['phone'];
$note = new NoteLog();
$note_data = $note->field('send_time')->where([
'phone'=> $phone,
'code'=>$code,
'is_success'=>1
])->find();
if (time()-$note_data->send_time > 18000) {
return $this->response(101, '请重新获取验证码');
}
}
$data['status'] = 101;
$data['data'] = '';
$data['data'] = array();
if (true === $result){
$user_data = $this->user->get(['user_phone' => $this->params['phone']]);
$date = date('Y-m-d H:i:s');
$pwd = md5(md5($this->request->param('pwd')) . '+123');
if (empty($user_data->id)) {
$code = Session::get('_code');
if ($this->request->param('code') == $code && $code != '') {
if ($this->request->param('code') == $code && $code != '' && $jwt_phone == $phone) {
$insert_data['referrer_id'] = $this->request->param('referrer_id');
$insert_data['referrer_source'] = $this->request->param('referrer_source');
......@@ -181,8 +207,8 @@ class Member extends Basic
$insert_data['update_time'] = $date;
$insert_data['last_login_time'] = $date;
$insert_data['last_login_ip'] = ip2long($this->request->ip());
$insert_data['user_phone'] = $this->request->param('phone');
$insert_data['user_pswd'] = md5(md5($this->request->param('pwd')) . '+123');
$insert_data['user_phone'] = $phone;
$insert_data['user_pswd'] = $pwd;
$insert_data['user_nick'] = $this->request->param('user_nick');
$insert_data['user_pic'] = $this->request->param('user_pic');
......@@ -211,25 +237,54 @@ class Member extends Basic
$data['msg'] = '验证码错误';
}
} else {
}
$user_data->update_time = $date;
//编辑
if ($type == 'edit') {
$user_data->user_nick = $this->request->param('user_nick')? $this->request->param('user_nick') : $user_data->user_nick;
$user_data->user_phone = $this->request->param('phone') ? $this->request->param('phone') : $user_data->user_phone;
$user_data->user_pic = $this->request->param('user_pic') ? $this->request->param('user_pic') : $user_data->user_pic;
$user_data->update_time = $date;
$user_data->last_login_ip = $this->request->param('last_login_ip') ? $this->params['last_login_ip'] : $user_data->last_login_ip;
//修改密码
if ($this->request->param('pwd') == $user_data->user_pswd) {
$user_data->user_pswd = md5(md5($this->request->param('pwd')).'+123');
$user_data->user_pswd = $pwd;
}
$user_data->save();
$data['data'] = ['id' => $user_data->id];
$data['status'] = 200;
$data['msg'] = '修改成功';
if ($user_data->id) {
$data['data'] = ['id' => $user_data->id];
$data['status'] = 200;
$data['msg'] = '修改成功';
} else {
$data['msg'] = '编辑失败';
}
}
//忘记密码
if ($type == 'forget') {
if ($this->request->param('code') == $code && $code != '' && $jwt_phone == $phone) {
$user_data->user_pswd = $pwd;
$user_data->save();
if ($user_data->id) {
$data['data'] = ['id' => $user_data->id];
$data['status'] = 200;
$data['msg'] = '修改成功';
} else {
$data['msg'] = '密码修改失败';
}
} else {
$data['status'] = 101;
$data['msg'] = '修改失败';
}
}
} else {
$data['msg'] = $result? $result:'type参数为空' ;
$data['msg'] = $result;
}
return $this->response($data['status'], $data['msg'], $data['data']);
}
......@@ -242,7 +297,7 @@ class Member extends Basic
public function inviteList() {
$id = $this->params['id'];
$data['status'] = 101;
$data['data'] = '';
$data['data'] = array();
$data['msg'] = '';
if ($id) {
......@@ -265,4 +320,34 @@ class Member extends Basic
return $this->response($data['status'], $data['msg'], $data['data']);
}
/**
* 生成邀请二维码
*
* @return type
*/
public function qrCode() {
$parms = $this->params;
$data['status'] = 101;
$data['data'] = array();
$data['msg'] = '';
if ($parms['id'] && $parms['referrer_source']) {
$result = $this->user->where('status',0)->where('id',$parms['id'])->find();
if ($result) {
$code = new \app\api\untils\GenerateCode();
$url = config('url').'test.html?referrer_source=0&id='.$result->id;
$path = $code->getCode($url, $result->id);
$data['data'] = ['path' => config('url').$path];
$data['status'] = 200;
} else {
$data['msg'] = '没有该用户';
}
} else {
$data['msg'] = 'id or referrer_source is null';
}
return $this->response($data['status'], $data['msg'], $data['data']);
}
}
<?php
//开发配置
return [
'url' => 'http://192.168.0.90/'
];
\ No newline at end of file
<?php
namespace app\api\untils;
use Endroid\QrCode\QrCode;
/**
* Description of Qrcode
*
* @author fuju
*/
class GenerateCode {
/**
* 生成二维码
*
* @param type $param
*/
public function getCode($param, $file_name) {
$qrCode = new QrCode($param);
$qrCode->setSize(300);
$qrCode->setWriterByName('png');
$qrCode->setMargin(10);
$qrCode->setEncoding('UTF-8');
$qrCode->setForegroundColor(['r' => 0, 'g' => 0, 'b' => 0]);
$qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255]);
$qrCode->setValidateResult(false);
$path = './qrcode/'.$file_name.'.png';
$qrCode->writeFile($path);
return $path;
}
}
<?php
namespace app\api\untils;
use think\helper\Time;
use think\Session;
use Firebase\JWT\JWT;
/**
* Created by fuju
* User : hj
......@@ -21,11 +22,39 @@ class JwtUntils {
if ($data) {
$jwt_data['data'] = $data;
$jwt_data['timeStamp_'] = time();
$result = \Firebase\JWT\JWT::encode($jwt_data, config('jwt_key'));
$jwt = new JWT();
$result = $jwt->encode($jwt_data, config('jwt_key'));
Session::set('authToken', $result);
} else {
$result = false;
}
return $result;
}
/**
* 解码token
*
* @param type $token
* @return int
*/
public function getDecode($token) {
if ($token) {
$result = \Firebase\JWT\JWT::decode($token, config('jwt_key'), array( 'HS256' ));
$today = Time::today();
//注册和忘记密码
if ($result->timeStamp_ < 2592000) {
$data['status'] = 101;
$data['msg'] = 'jwt_token time expire';
} else {
$data['data'] = (array)$result->data;
}
} else{
$data['status'] = 101;
}
return $data;
}
}
......@@ -21,6 +21,7 @@ class Users extends Validate {
'code' => 'require|number',
'user_nick' => 'require',
'user_pswd' => 'require|min:6',
'token' => 'require'
];
protected $message = [
'user_phone' => '手机号码错误',
......@@ -38,7 +39,7 @@ class Users extends Validate {
protected $scene = [
'invite' => 'user_phone,referrer_id,referrer_source',
'cPost' => 'user_phone,referrer_id,referrer_source,code',
'register' => 'user_phone,user_pswd',
'register' => 'user_phone,user_pswd,token',
'edit' => ''
];
......
......@@ -20,7 +20,7 @@ class Agents extends Model
*/
public function getUser($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field, $params, $house_id = '') {
if ($house_id == '') {
$data = $this->field($field)->alias('a')
$agent_data = $this->field($field)->alias('a')
->join('u_evaluate b', 'a.id = b.agents_id', 'left')
->where($params)
->where('level=2 or level=5')
......@@ -42,7 +42,11 @@ class Agents extends Model
->select();
}
return $agent_data;
foreach ($agent_data as $k=>$v) {
$data[$k] = $v->toArray();
}
return $data;
}
/**
......
......@@ -111,14 +111,12 @@ class JournalAccounts extends Model
->join('applies a', 'j.apply_id = a.id')
->where('a.agent_id', $agent_id)
->where('j.transaction_status = 3')
->where($param)
->find();
} else {
$result = $this->field($fields)->alias('j')
->join('applies a', 'j.apply_id = a.id')
->where('a.agent_id', $agent_id)
->where('j.transaction_status = 3')
->where($param)
->find();
}
return $result;
......
......@@ -9,16 +9,8 @@ class Users extends Model
{
// 设置当前模型对应的完整数据表名称
protected $table = 'u_users';
protected $db ;
public function __construct()
{
$this->db = Db($this->table);
}
public function selectUser($user_id){
return $this->db
->field("id,status,user_phone")
->find($user_id);
public function add() {
}
}
......@@ -70,8 +70,11 @@ Route::group('api', [
'appraiser' => [ 'api/broker/appraiser', [ 'method' => 'post' ] ], //评价经纪人
//get member
'logout' => [ 'api/member/logout', [ 'method' => 'get' ] ],
'inviteList/:id' => [ 'api/member/inviteList', [ 'method' => 'get' ] ], //邀请记录
'logout' => ['api/member/logout',['method' => 'get']],
'inviteList/:id' => ['api/member/inviteList', ['method' => 'get']], //邀请记录
'qrCode' => ['api/member/qrCode', ['method' => 'get']], //邀请二维码
//post member
'login' => [ 'api/member/login', [ 'method' => 'post' ] ], //c端登陆
'register' => [ 'api/member/register', [ 'method' => 'post' ] ], //注册|邀请注册|编辑
......
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 to comment