租房掌柜微信小程序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.
 
 
 
 
 
 

212 lines
7.0 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 think\App;
use think\Controller;
use think\Db;
/**
* 应用入口
* Class Index
* @package app\index\controller
*/
class Base extends Controller
{
protected static $table_user = "CloudMember";
public $table_room_crontab = 'CloudRoomCrontab';//房间时间切割
public function __construct(App $app = null)
{
parent::__construct($app);
//判断是否开启验证
if (config('istoken')) {
$this->run(); //token验证
}
}
/**
* 用户信息传递
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
protected static function auth()
{
//$this->info(); //获取相关信息
if (!isset($_SERVER['HTTP_USERID'])) {
exit(send_http_status(412));
}
$user_id = $_SERVER['HTTP_USERID'];
$_USER = Db::name(self::$table_user)->where('id', $user_id)->find();
if (!$_USER) {
exit(send_http_status(415));
}
!defined('USER_ID') ? define('USER_ID', $_USER['id']) : '';
!defined('MEMBER') ? define('MEMBER', $_USER) : '';
}
/**
* 会员发布权限判断
* @param int $curr_count 当前已有数据统计
* @param string $count_type 判断的类型 默认房源,否则根据传入的类型
*/
protected static function authAddHouse($curr_count = 0, $count_type = 'count')
{
//子账号不允许删除和添加
if ($_SERVER['HTTP_SUBUSERID'] > 0) {
exit(send_http_status(417));
}
//判断有没有手机号
if (empty(MEMBER['phone']) || strlen(MEMBER['phone']) != 11) {
exit(send_http_status(51016));
}
//暂时免费
return;
//超级管理员直接返回
if (MEMBER['is_manager'] == 1) {
return;
}
//判断当前用户 会员是否过期(普通用户不用判断)
if (MEMBER['vip_level'] > 0 && MEMBER['vip_endtime'] < time() && MEMBER['is_manager'] != 1) {
exit(send_http_status(416));
}
//获取等级配置信息
$vip_level = config('vip_level');
$member_vip = $vip_level[MEMBER['vip_level']];
if ($curr_count >= $member_vip[$count_type]) {
exit(send_http_status(51004));
}
}
/**
* 获取常用硬件信息
*/
protected function info()
{
$code = '';
if (!isset($_SERVER['HTTP_DEVICENAME'])) {
$code = 408;
}
if (!isset($_SERVER['HTTP_SYSTEMVERSION'])) {
$code = 409;
}
if (!isset($_SERVER['HTTP_DEVICECODE'])) {
$code = 410;
}
if (!isset($_SERVER['HTTP_PHONETYPE'])) {
$code = 411;
}
if (!isset($_SERVER['HTTP_USERID'])) {
$code = 412;
}
if ($code) {
exit(send_http_status($code));
}
//获取、设备号、机型、终端
$devicename = 'Android';
if (strtolower($_SERVER['HTTP_DEVICENAME']) != strtolower($devicename)) {
$devicename = 'iOS';
}
//获取版本号
$version = isset($_SERVER['HTTP_VERSION']) ? $_SERVER['HTTP_VERSION'] : 0;
defined('VERSION') or define("VERSION", $version); //版本号
defined('DEVICENAME') or define("DEVICENAME", $devicename); //终端名称
defined('SYSTEMVERSION') or define("SYSTEMVERSION", strtoupper($_SERVER['HTTP_SYSTEMVERSION'])); //系统版本
defined('DEVICECODE') or define("DEVICECODE", $_SERVER['HTTP_DEVICECODE']); //设备号
defined('PHONETYPE') or define("PHONETYPE", $_SERVER['HTTP_PHONETYPE']); //机型
defined('USERID') or define("USERID", $_SERVER['HTTP_USERID']);
}
/**
* 根据密钥、标识、时间戳、随机数 验证请求接口
*/
public function run()
{
//客户端标识列表
$_client = config('CLIENT');
$_secret = config('SECRET');
$code = '';
//没有指定平台标识
defined('CLIENT') or define("CLIENT", strtoupper($_SERVER['HTTP_CLIENT'])); //终端名称
if (empty(CLIENT) || !in_array(CLIENT, $_client)) {
$code = 201;
}
//判断标识是否正确
if (!isset($_SERVER['HTTP_APPID']) || $_SERVER['HTTP_APPID'] != $_secret[CLIENT]['APPID']) {
$code = 202;
}
//指定随机数
$nonce = $_SERVER['HTTP_NONCE'];
if (!isset($nonce) || empty($nonce)) {
$code = 203;
}
//判断加密串
$openkey = $_secret[CLIENT]['APPID'] . $nonce . $_secret[CLIENT]['SECRET'];
$encry_old = md5($openkey);
$encry = md5($openkey . $_SERVER['HTTP_USERID']);
if ($_SERVER['HTTP_OPENKEY'] != $encry && $encry_old != $_SERVER['HTTP_OPENKEY']) {
$code = 207;
}
if ($code) {
exit(send_http_status($code));
}
}
/**
* 根据收租方式 切割提醒的时间节点
* @param $_data 房间数据
* @param int $month 指定分割月数
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
protected function crontab_room($_data, $month = 3)
{
$start_time = $_data['start_time'];
$end_time = $_data['end_time'];
//计算指定天数后的时间戳
$_arr = [];
while ($start_time < $end_time) {
$arr_temp['room_id'] = $_data['id'];
$arr_temp['user_id'] = USER_ID;
$arr_temp['start_time'] = $start_time;
$arr_temp['end_time'] = $start_time = strtotime('+' . $month . ' month', $start_time);
$arr_temp['create_time'] = time();
$_arr[] = $arr_temp;
}
//删除最后一个元素,置换为end_time(防止开始时间与结束时间不一致)
$last_arr = array_pop($_arr);
$last_arr['end_time'] = $end_time;
$_arr[] = $last_arr;
//新增前先清空
$house_crontab = Db::name($this->table_room_crontab);
$house_crontab->where('room_id', $_data['id'])->where('user_id', USER_ID)->delete();
$house_crontab->insertAll($_arr);
}
}