租房掌柜微信小程序Api以及小程序前端模板
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

106 lines
4.1 KiB

<?php
// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://demo.thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------
namespace app\index\controller;
use library\Controller;
use think\Db;
/**
* 用户登录
* Class Plugs
* @package app\admin\controller\api
*/
class Login extends Controller
{
private $table_member = 'CloudMember';
private $table_subaccount = 'CloudSubaccount';
/**
* 用户登录,先获取用户信息,再入库操作
* @return \type
* @throws \WeChat\Exceptions\InvalidDecryptException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function index()
{
$iv = $this->request->param('iv');
$encryptedData = $this->request->param('encryptedData');
$code = $this->request->param('code');
$config = config('appid');
//实例化类解密类
$crypt = \We::WeMiniCrypt($config);
$_data = $crypt->userInfo($code, $iv, $encryptedData);
if (isset($_data['openid'])) {
//先查询openid是否存在
$_result = Db::name($this->table_member)->where('openid', $_data['openid'])->find();
if ($_result) {
$_result['imgList'] = !empty($_result['qrcode']) ? explode(',', $_result['qrcode']) : '';
self::formatMemberData($_result);
return send_http_status(200, $_result);
}
$_data['headimg'] = $_data['avatarUrl'];
$_data['sex'] = $_data['gender'];
$_data['nickname'] = $_data['nickName'];
$_data['create_time'] = $_data['update_time'] = time();
if ($insert_id = Db::name($this->table_member)->strict(false)->insertGetId($_data)) {
$_data['id'] = $insert_id;
$_data['subaccount_id'] = 0;
return send_http_status(200, $_data);
}
return send_http_status(51006);
}
}
/**
* 子账号登录
*/
public function subaccount()
{
$_data = $this->request->post();
//比对账号密码
$_user = Db::name($this->table_subaccount)->where('username', $_data['username'])->where('status', 1)->find();
if (!$_user) {
return send_http_status(51012);
}
if ($_user['password'] != sha1($_data['password'])) {
return send_http_status(51012);
}
$_member = Db::name($this->table_member)->find($_user['user_id']);
if (!$_member) {
return send_http_status(415);
}
$_member['subaccount_id'] = $_user['id']; //赋值子账号id
self::formatMemberData($_member);
return send_http_status(200, $_member);
}
static private function formatMemberData(&$data)
{
if (!$data) {
return;
}
!empty($data['create_time']) ? $data['create_time'] = date('Y-m-d', $data['create_time']) : $data['create_time'] = '';
!empty($data['update_time']) ? $data['update_time'] = date('Y-m-d', $data['update_time']) : $data['update_time'] = '';
!empty($data['vip_time']) ? $data['vip_time'] = date('Y-m-d', $data['vip_time']) : $data['vip_time'] = '';
!empty($data['vip_endtime']) ? $data['vip_endtime'] = date('Y-m-d', $data['vip_endtime']) : $data['vip_endtime'] = '';
}
}