作者 杨育虎

shequ

<?php
return array(
array(
'name' => 'qq',
'title' => 'QQ',
'type' => 'array',
'content' =>
array(
'app_id' => '',
'app_secret' => '',
'scope' => 'get_user_info',
),
'value' =>
array(
'app_id' => '100000000',
'app_secret' => '123456',
'scope' => 'get_user_info',
),
'rule' => 'required',
'msg' => '',
'tip' => '',
'ok' => '',
'extend' => '',
return array (
0 =>
array (
'name' => 'qq',
'title' => 'QQ',
'type' => 'array',
'content' =>
array (
'app_id' => '',
'app_secret' => '',
'scope' => 'get_user_info',
),
array(
'name' => 'wechat',
'title' => '微信',
'type' => 'array',
'content' =>
array(
'app_id' => '',
'app_secret' => '',
'callback' => '',
'scope' => 'snsapi_base',
),
'value' =>
array(
'app_id' => '100000000',
'app_secret' => '123456',
'scope' => 'snsapi_base',
),
'rule' => 'required',
'msg' => '',
'tip' => '',
'ok' => '',
'extend' => '',
'value' =>
array (
'app_id' => '100000000',
'app_secret' => '123456',
'scope' => 'get_user_info',
),
array(
'name' => 'weibo',
'title' => '微博',
'type' => 'array',
'content' =>
array(
'app_id' => '',
'app_secret' => '',
'scope' => 'get_user_info',
),
'value' =>
array(
'app_id' => '100000000',
'app_secret' => '123456',
'scope' => 'get_user_info',
),
'rule' => 'required',
'msg' => '',
'tip' => '',
'ok' => '',
'extend' => '',
'rule' => 'required',
'msg' => '',
'tip' => '',
'ok' => '',
'extend' => '',
),
1 =>
array (
'name' => 'wechat',
'title' => '微信',
'type' => 'array',
'content' =>
array (
'app_id' => '',
'app_secret' => '',
'callback' => '',
'scope' => 'snsapi_base',
),
array(
'name' => 'bindaccount',
'title' => '账号绑定',
'type' => 'radio',
'content' => [
'1' => '开启',
'0' => '关闭',
],
'value' => 1,
'rule' => 'required',
'msg' => '',
'tip' => '',
'ok' => '是否开启账号绑定',
'extend' => ''
'value' =>
array (
'app_id' => 'wxb345558fbe7123f4',
'app_secret' => '7f04ffc23a080d581542e2be5c71486e',
'scope' => 'snsapi_base',
),
'rule' => 'required',
'msg' => '',
'tip' => '',
'ok' => '',
'extend' => '',
),
2 =>
array (
'name' => 'weibo',
'title' => '微博',
'type' => 'array',
'content' =>
array (
'app_id' => '',
'app_secret' => '',
'scope' => 'get_user_info',
),
'value' =>
array (
'app_id' => '100000000',
'app_secret' => '123456',
'scope' => 'get_user_info',
),
'rule' => 'required',
'msg' => '',
'tip' => '',
'ok' => '',
'extend' => '',
),
3 =>
array (
'name' => 'bindaccount',
'title' => '账号绑定',
'type' => 'radio',
'content' =>
array (
1 => '开启',
0 => '关闭',
),
'value' => '1',
'rule' => 'required',
'msg' => '',
'tip' => '',
'ok' => '是否开启账号绑定',
'extend' => '',
),
4 =>
array (
'name' => 'status',
'title' => '前台第三方登录开关',
'type' => 'checkbox',
'content' =>
array (
'qq' => 'QQ',
'wechat' => '微信',
'weibo' => '微博',
),
array(
'name' => 'status',
'title' => '前台第三方登录开关',
'type' => 'checkbox',
'content' => [
'qq' => 'QQ',
'wechat' => '微信',
'weibo' => '微博',
],
'value' => 'qq,wechat,weibo',
'rule' => '',
'msg' => '',
'tip' => '',
'ok' => '前台第三方登录的开关',
'extend' => ''
'value' => 'qq,wechat,weibo',
'rule' => '',
'msg' => '',
'tip' => '',
'ok' => '前台第三方登录的开关',
'extend' => '',
),
5 =>
array (
'name' => 'rewrite',
'title' => '伪静态',
'type' => 'array',
'content' =>
array (
),
array(
'name' => 'rewrite',
'title' => '伪静态',
'type' => 'array',
'content' =>
array(),
'value' =>
array(
'index/index' => '/third$',
'index/connect' => '/third/connect/[:platform]',
'index/callback' => '/third/callback/[:platform]',
'index/bind' => '/third/bind/[:platform]',
'index/unbind' => '/third/unbind/[:platform]',
),
'rule' => 'required',
'msg' => '',
'tip' => '',
'ok' => '',
'extend' => '',
'value' =>
array (
'index/index' => '/third$',
'index/connect' => '/third/connect/[:platform]',
'index/callback' => '/third/callback/[:platform]',
'index/bind' => '/third/bind/[:platform]',
'index/unbind' => '/third/unbind/[:platform]',
),
'rule' => 'required',
'msg' => '',
'tip' => '',
'ok' => '',
'extend' => '',
),
);
... ...
... ... @@ -87,6 +87,7 @@ class House extends Backend
if ($params) {
$params = $this->preExcludeFields($params);
$data = Db::name('house')
->field('max(com_number) as num')
->find();
... ...
... ... @@ -59,6 +59,9 @@ class HouseAdmin extends Backend
->select();
$list = collection($list)->toArray();
foreach ($list as &$v){
$v['user_id'] = Db::name('user')->where('id',$v['user_id'])->value('nickname');
}
$result = array("total" => $total, "rows" => $list);
return json($result);
... ... @@ -77,15 +80,11 @@ class HouseAdmin extends Backend
if ($params) {
$params = $this->preExcludeFields($params);
$data = Db::name('house_admin')
->field('max(number) as num')
$data = Db::name('user')
->where('id',$params['user_id'])
->field('id,id_num')
->find();
if($data['num'] == 0){
$params['number'] = '100000';
}else{
$params['number'] = $data['num'] + 1;
}
$params['number'] = $data['id_num'];
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
... ... @@ -141,6 +140,13 @@ class HouseAdmin extends Backend
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
$data = Db::name('user')
->where('id',$params['user_id'])
->field('id,id_num')
->find();
$params['number'] = $data['id_num'];
$result = false;
Db::startTrans();
try {
... ...
... ... @@ -14,6 +14,12 @@
<ul class="row list-inline plupload-preview" id="p-image"></ul>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('链接')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-url" class="form-control" name="row[url]" type="text">
</div>
</div>
<!--<div class="form-group">-->
<!--<label class="control-label col-xs-12 col-sm-2">{:__('Typeswitch')}:</label>-->
<!--<div class="col-xs-12 col-sm-8">-->
... ...
... ... @@ -14,6 +14,12 @@
<ul class="row list-inline plupload-preview" id="p-image"></ul>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('链接')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-url" class="form-control" name="row[url]" type="text" value="{$row.url|htmlentities}">
</div>
</div>
<!--<div class="form-group">-->
<!--<label class="control-label col-xs-12 col-sm-2">{:__('Typeswitch')}:</label>-->
<!--<div class="col-xs-12 col-sm-8">-->
... ...
... ... @@ -27,6 +27,12 @@
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('地区')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-area" data-toggle="city-picker" data-rule="required" class="form-control" name="row[area]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('选择')}:</label>
... ...
... ... @@ -26,6 +26,13 @@
<ul class="row list-inline plupload-preview" id="p-image"></ul>
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('地区')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-area" data-toggle="city-picker" data-rule="required" class="form-control" name="row[area]" type="text" value="{$row.area}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('选择')}:</label>
<div class="col-xs-12 col-sm-8">
... ...
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('用户id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="nickname" class="form-control selectpage" name="row[user_id]" type="text" value="">
</div>
</div>
<!--<div class="form-group">-->
<!--<label class="control-label col-xs-12 col-sm-2">{:__('Number')}:</label>-->
<!--<div class="col-xs-12 col-sm-8">-->
... ...
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('用户id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="nickname" class="form-control selectpage" name="row[user_id]" type="text" value="{$row.user_id}">
</div>
</div>
<!--<div class="form-group">-->
<!--<label class="control-label col-xs-12 col-sm-2">{:__('Number')}:</label>-->
<!--<div class="col-xs-12 col-sm-8">-->
... ...
<?php
use \think\Db;
use app\nsms\nsms;
if (!function_exists('generate_user_token')) {
/**
* 生成token
* @param $userId
* @return string
*/
function generate_user_token($userId)
{
$userTokenQuery = Db::name("user_token")
->where('user_id', $userId);
$findUserToken = $userTokenQuery->find();
$currentTime = time();
$expireTime = $currentTime + 24 * 3600 * 180;
$token = md5(uniqid()) . md5(uniqid());
if (empty($findUserToken)) {
Db::name("user_token")->insert([
'token' => $token,
'user_id' => $userId,
'expiretime' => $expireTime,
'createtime' => $currentTime,
]);
} else {
Db::name("user_token")
->where('user_id', $userId)
->update([
'token' => $token,
'expiretime' => $expireTime,
'createtime' => $currentTime,
]);
}
return $token;
}
}
if(!function_exists('update_current_user')){
/**
* 更新当前登录前台用户的信息
* @param array $user 前台用户的信息
*/
function update_current_user($user)
{
session('user', $user);
}
}
if (!function_exists('get_current_user_id')) {
/**
* 获取当前登录前台用户id
* @return int
*/
function get_current_user_id()
{
$sessionUserId = session('user.id');
if (empty($sessionUserId)) {
return 0;
}
return $sessionUserId;
}
}
if (!function_exists('distance')) {
/**
* 根据经纬度计算两地的距离
* @param $work
* @param $user
* @return float|int
*/
function distance($work, $user)
{
$lng1 = $user['longitude'];//经度1
$lat1 = $user['latitude'];//纬度1
$lng2 = $work['longitude'];//经度2
$lat2 = $work['latitude'];//纬度2
$EARTH_RADIUS = 6378137; //地球半径
$RAD = pi() / 180.0;
$radLat1 = $lat1 * $RAD;
$radLat2 = $lat2 * $RAD;
$a = $radLat1 - $radLat2; // 两点纬度差
$b = ($lng1 - $lng2) * $RAD; // 两点经度差
$s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2)));
$s = $s * $EARTH_RADIUS;
$result = round($s * 10000) / 10000;
return $result;
}
}
if (!function_exists('getAge')) {
/**
* 根据出生日期计算出年龄
* @param $birthday
* @return false|string
*/
function getAge($birthday)
{
$birthday = strtotime($birthday);
//格式化出生时间年月日
$byear = date('Y', $birthday);
$bmonth = date('m', $birthday);
$bday = date('d', $birthday);
//格式化当前时间年月日
$tyear = date('Y');
$tmonth = date('m');
$tday = date('d');
//开始计算年龄
$age = $tyear - $byear;
if ($bmonth > $tmonth || $bmonth == $tmonth && $bday > $tday) {
$age--;
}
return $age;
}
}
if(!function_exists('get_order_sn')){
/**
* 获取惟一订单号
* @return string
*/
function get_order_sn()
{
return date('Ymd') . substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
}
}
if(!function_exists('get_client_ip')){
/**
* 获取客户端IP地址
* @param integer $type 返回类型 0 返回IP地址 1 返回IPV4地址数字
* @param boolean $adv 是否进行高级模式获取(有可能被伪装)
* @return string
*/
function get_client_ip($type = 0, $adv = false)
{
return request()->ip($type, $adv);
}
}
/**
* 生成n位随机数
* @param int $length
* @return int
*/
function generateCode($length = 6) {
$min = pow(10 , ($length - 1));
$max = pow(10, $length) - 1;
return rand($min, $max);
}
/**
* 发送手机短信
* @param $data 数据内容
* @return mixed
*/
function send_sms($data){
//todo 短信账号密码
// require_once EXTEND_PATH . 'nsms/nsms.php';
$url = "http://www.ztsms.cn/sendNSms.do";
$username = 'xiaoweiwenwen';
$password = 'Cxz307312';
$sendAPI = new nsms($url, $username, $password);
$sendAPI->data = $data;/*初始化数据包*/
$return = $sendAPI->sendSMS('POST');
return $return;
}
\ No newline at end of file
... ...
... ... @@ -13,7 +13,7 @@ use think\Config;
*/
class Common extends Api
{
protected $noNeedLogin = ['init'];
protected $noNeedLogin = ['init','upload'];
protected $noNeedRight = '*';
/**
... ... @@ -47,75 +47,68 @@ class Common extends Api
*/
public function upload()
{
Config::set('default_return_type', 'json');
$config = get_addon_config('qiniu');
$file = $this->request->file('file');
if (empty($file)) {
$this->error(__('No file upload or server upload limit exceeded'));
if (!$file || !$file->isValid()) {
$this->error("请上传有效的文件");
}
$fileInfo = $file->getInfo();
//判断是否已经存在附件
$sha1 = $file->hash();
$upload = Config::get('upload');
$filePath = $file->getRealPath() ?: $file->getPathname();
preg_match('/(\d+)(\w+)/', $upload['maxsize'], $matches);
preg_match('/(\d+)(\w+)/', $config['maxsize'], $matches);
$type = strtolower($matches[2]);
$typeDict = ['b' => 0, 'k' => 1, 'kb' => 1, 'm' => 2, 'mb' => 2, 'gb' => 3, 'g' => 3];
$size = (int)$upload['maxsize'] * pow(1024, isset($typeDict[$type]) ? $typeDict[$type] : 0);
$fileInfo = $file->getInfo();
$size = (int)$config['maxsize'] * pow(1024, isset($typeDict[$type]) ? $typeDict[$type] : 0);
$suffix = strtolower(pathinfo($fileInfo['name'], PATHINFO_EXTENSION));
$suffix = $suffix && preg_match("/^[a-zA-Z0-9]+$/", $suffix) ? $suffix : 'file';
$suffix = $suffix ? $suffix : 'file';
$mimetypeArr = explode(',', strtolower($upload['mimetype']));
$md5 = md5_file($filePath);
$search = ['$(year)', '$(mon)', '$(day)', '$(etag)', '$(ext)'];
$replace = [date("Y"), date("m"), date("d"), $md5, '.' . $suffix];
$object = ltrim(str_replace($search, $replace, $config['savekey']), '/');
$mimetypeArr = explode(',', strtolower($config['mimetype']));
$typeArr = explode('/', $fileInfo['type']);
//禁止上传PHP和HTML文件
if (in_array($fileInfo['type'], ['text/x-php', 'text/html']) || in_array($suffix, ['php', 'html', 'htm'])) {
$this->error(__('Uploaded file format is limited'));
//检查文件大小
if (!$file->checkSize($size)) {
$this->error("起过最大可上传文件限制");
}
//验证文件后缀
if ($upload['mimetype'] !== '*' &&
if ($config['mimetype'] !== '*' &&
(
!in_array($suffix, $mimetypeArr)
|| (stripos($typeArr[0] . '/', $upload['mimetype']) !== false && (!in_array($fileInfo['type'], $mimetypeArr) && !in_array($typeArr[0] . '/*', $mimetypeArr)))
|| (stripos($typeArr[0] . '/', $config['mimetype']) !== false && (!in_array($fileInfo['type'], $mimetypeArr) && !in_array($typeArr[0] . '/*', $mimetypeArr)))
)
) {
$this->error(__('Uploaded file format is limited'));
}
//验证是否为图片文件
$imagewidth = $imageheight = 0;
if (in_array($fileInfo['type'], ['image/gif', 'image/jpg', 'image/jpeg', 'image/bmp', 'image/png', 'image/webp']) || in_array($suffix, ['gif', 'jpg', 'jpeg', 'bmp', 'png', 'webp'])) {
$imgInfo = getimagesize($fileInfo['tmp_name']);
if (!$imgInfo || !isset($imgInfo[0]) || !isset($imgInfo[1])) {
$this->error(__('Uploaded file is not a valid image'));
}
$imagewidth = isset($imgInfo[0]) ? $imgInfo[0] : $imagewidth;
$imageheight = isset($imgInfo[1]) ? $imgInfo[1] : $imageheight;
$this->error(__('上传格式限制'));
}
$replaceArr = [
'{year}' => date("Y"),
'{mon}' => date("m"),
'{day}' => date("d"),
'{hour}' => date("H"),
'{min}' => date("i"),
'{sec}' => date("s"),
'{random}' => Random::alnum(16),
'{random32}' => Random::alnum(32),
'{filename}' => $suffix ? substr($fileInfo['name'], 0, strripos($fileInfo['name'], '.')) : $fileInfo['name'],
'{suffix}' => $suffix,
'{.suffix}' => $suffix ? '.' . $suffix : '',
'{filemd5}' => md5_file($fileInfo['tmp_name']),
];
$savekey = $upload['savekey'];
$savekey = str_replace(array_keys($replaceArr), array_values($replaceArr), $savekey);
$savekey = '/' . $object;
$uploadDir = substr($savekey, 0, strripos($savekey, '/') + 1);
$fileName = substr($savekey, strripos($savekey, '/') + 1);
//
$splInfo = $file->validate(['size' => $size])->move(ROOT_PATH . '/public' . $uploadDir, $fileName);
//先上传到本地
$splInfo = $file->move(ROOT_PATH . '/public' . $uploadDir, $fileName);
if ($splInfo) {
$extparam = $this->request->post();
$filePath = $splInfo->getRealPath() ?: $splInfo->getPathname();
$sha1 = sha1_file($filePath);
$imagewidth = $imageheight = 0;
if (in_array($suffix, ['gif', 'jpg', 'jpeg', 'bmp', 'png', 'swf'])) {
$imgInfo = getimagesize($splInfo->getPathname());
$imagewidth = isset($imgInfo[0]) ? $imgInfo[0] : $imagewidth;
$imageheight = isset($imgInfo[1]) ? $imgInfo[1] : $imageheight;
}
$params = array(
'admin_id' => 0,
'user_id' => (int)$this->auth->id,
'admin_id' => session('admin.id'),
// 'user_id' => $this->auth->id,
'filesize' => $fileInfo['size'],
'imagewidth' => $imagewidth,
'imageheight' => $imageheight,
... ... @@ -126,17 +119,47 @@ class Common extends Api
'uploadtime' => time(),
'storage' => 'local',
'sha1' => $sha1,
'extparam' => json_encode($extparam),
);
$attachment = model("attachment");
$attachment->data(array_filter($params));
$attachment = \app\common\model\Attachment::create(array_filter($params), true);
$policy = array(
'saveKey' => ltrim($savekey, '/'),
);
$auth = new \addons\qiniu\library\Auth($config['app_key'], $config['secret_key']);
$token = $auth->uploadToken($config['bucket'], null, $config['expire'], $policy);
$multipart = [
['name' => 'token', 'contents' => $token],
[
'name' => 'file',
'contents' => fopen($filePath, 'r'),
'filename' => $fileName,
]
];
try {
$client = new \GuzzleHttp\Client();
$res = $client->request('POST', $config['uploadurl'], [
'multipart' => $multipart
]);
$code = $res->getStatusCode();
//成功不做任何操作
} catch (\GuzzleHttp\Exception\ClientException $e) {
$attachment->delete();
unlink($filePath);
$this->error("上传失败");
}
$qiniu = get_addon_config('qiniu')['cdnurl'];
$info['url'] = '/' . $object;
$info['full_url'] = $qiniu.'/' . $object;
//上传成功后将存储变更为qiniu
$attachment->storage = 'qiniu';
$attachment->save();
\think\Hook::listen("upload_after", $attachment);
$this->success(__('Upload successful'), [
'url' => $uploadDir . $splInfo->getSaveName()
]);
$this->success("上传成功", $info);
} else {
// 上传失败获取错误信息
$this->error($file->getError());
$this->error('上传失败');
}
return;
}
}
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/7/10
* Time: 17:32
*/
namespace app\api\controller;
use app\common\controller\Api;
use think\Cache;
use think\Db;
/**
* 社区首页
*/
class House extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
/**
* @ApiTitle (首页轮播图)
* @ApiSummary (首页轮播图)
* @ApiMethod (POST)
* @ApiRoute (/api/house/banner)
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"id"://id
"image"://图片
"url"://跳转地址
"typeswitch"://开关0关1开
"createtime"://创建时间
}
]
}
})
*/
public function banner()
{
$qiniu = get_addon_config('qiniu')['cdnurl'];
$data = Db::name('banner')->field('updatetime',true)->order('createtime desc')->select();
foreach ($data as &$v){
$v['image'] = $qiniu.$v['image'];
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
}
$this->success('success',$data);
}
/**
* @ApiTitle (首页社区名称以及社区公告)
* @ApiSummary (首页社区名称以及社区公告)
* @ApiMethod (POST)
* @ApiRoute (/api/house/house)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"is_binding"://是否绑定1已绑定2未绑定
"house_name"://社区名称
"is_have"://是否有社区公告1有2没有
"title"://社区公告标题
"is_new"://是否是新 1是2否
"content"://公告内容
"look_num"://浏览人数
"createtime"://时间
}
]
}
})
*/
public function house()
{
$user_id = $this->auth->id;
$data = Db::name('user')
->where('id',$user_id)
->field('id,house_id')
->find();
if(empty($data['house_id'])){
$info['is_binding'] = 2;
}else{
$info['is_binding'] = 1;
$info['house_name'] = Db::name('house')->where('id',$data['house_id'])->value('name');
//查询该社区的社区公告
$house_board = Db::name('house_board')->where('house_id',$data['house_id'])->order('createtime desc')->find();
if(empty($house_board)){
$info['is_have'] = 2;
$info['title'] = '';
$info['content'] = '';
$info['createtime'] = '';
$info['look_num'] = '';
$info['is_new'] = 2;
}else{
$info['is_have'] = 1;
$info['title'] = $house_board['title'];
$info['content'] = $house_board['content'];
$info['look_num'] = $house_board['look_num'];
$info['createtime'] = date('Y-m-d',$house_board['createtime']);
//查询是否已读
$is_read = Db::name('house_board_detail')->where('user_id',$user_id)->where('house_board_id',$house_board['id'])->find();
if(empty($is_read)){
$info['is_new'] = 2;
}else{
$info['is_new'] = 1;
}
}
$this->success('success',$info);
}
}
/**
* @ApiTitle (首页展开公告)
* @ApiSummary (首页展开公告)
* @ApiMethod (POST)
* @ApiRoute (/api/house/house_board_detail)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="house_board_id", type="inter", required=true, description="公告id")
*
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"title"://社区公告标题
"content"://公告内容
"look_num"://浏览人数
"createtime"://时间
"avatar"://用户头像
}
]
}
})
*/
public function house_board_detail()
{
$user_id = $this->auth->id;
$id = $this->request->param('house_board_id');
if(empty($id)){
$this->error('缺少必要参数');
}
$info['user_id'] = $user_id;
$info['house_board_id'] = $id;
$info['createtime'] = time();
$res = Db::name('house_board_detail')->where('user_id',$info['user_id'])->where('house_board_id',$info['house_board_id'])->find();
if(empty($res)){
Db::name('house_board_detail')->insertGetId($info);
Db::name('house_board')->where('id',$id)->setInc('look_num');
}
$data = Db::name('house_board')
->field('id,house_id,title,content,look_num,createtime')
->where('deletime','')
->where('id',$id)
->find();
$data['createtime'] = date('Y-m-d',$data['createtime']);
$data['avatar'] = Db::name('house_board')
->alias('a')
->join('user b','a.user_id = b.id')
->where('a.house_board_id',$id)
->field('a.user_id,b.nickname,b.avatar')
->limit(6)
->select();
$this->success('success',$data);
}
/**
* @ApiTitle (公告全部已读用户头像信息)
* @ApiSummary (公告全部已读用户头像信息)
* @ApiMethod (POST)
* @ApiRoute (/api/house/avatar)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="house_board_id", type="inter", required=true, description="公告id")
*
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"id"://用户id
"avatar"://用户头像
}
]
}
})
*/
public function avatar()
{
$user_id = $this->auth->id;
$id = $this->request->param('house_board_id');
if(empty($id)){
$this->error('缺少必要参数');
}
$data = Db::name('house_board_detail')
->alias('a')
->join('user b','a.user_id = b.id')
->field('b.id,b.avatar')
->order('a.createtime desc')
->select();
$this->success('success',$data);
}
/**
* @ApiTitle (社区列表)
* @ApiSummary (社区列表)
* @ApiMethod (POST)
* @ApiRoute (/api/house/house_list)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="area", type="string", required=true, description="市区地址例如:'天津市/西青区'")
* @ApiParams (name="keyword", type="string", required=false, description="关键字")
*
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"id"://小区id
"name"://小区名称
"area"://所在区
"shen_status"://状态0选择1申请中2已绑定
}
]
}
})
*/
public function house_list()
{
$qiniu = get_addon_config('qiniu')['cdnurl'];
$user_id = $this->auth->id;
$area = $this->request->param('area');
if(empty($area)){
$this->error('缺少必要参数');
}
$keyword = $this->request->param('keyword');
if(!empty($keyword)){
$where['name'] = ['like',"%$keyword%"];
}else{
$where = true;
}
//查询该市区下的所有小区
$data = Db::name('house')
->where('area','like',"%$area%")
->where($where)
->field('id,name,area')
->order('createtime desc')
->select();
//查出该用户已绑定的和申请中的小区
$user_house = Db::name('user_house')
->where('user_id',$user_id)
->select();
foreach ($data as &$v){
foreach ($user_house as &$val){
if($v['id'] == $val['house_id']){
$v['shen_status'] = $val['status'];
}else{
$v['shen_status'] = 0;
}
}
}
$this->success('success',$data);
}
/**
* @ApiTitle (社区公告轮播图)
* @ApiSummary (社区公告轮播图)
* @ApiMethod (POST)
* @ApiRoute (/api/house/house_banner)
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"id"://id
"image"://图片
"url"://跳转地址
"typeswitch"://开关0关1开
"createtime"://创建时间
}
]
}
})
*/
public function house_banner()
{
$qiniu = get_addon_config('qiniu')['cdnurl'];
$data = Db::name('advertising')->field('updatetime',true)->order('createtime desc')->select();
foreach ($data as &$v){
$v['image'] = $qiniu.$v['image'];
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
}
$this->success('success',$data);
}
/**
* @ApiTitle (公告列表)
* @ApiSummary (公告列表)
* @ApiMethod (POST)
* @ApiRoute (/api/house/house_board_list)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="house_board_id", type=inter, required=true, description="社区id")
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
* @ApiParams (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"total_num"://总条数
"info":[
"id"://公告id
"title"://社区公告标题
"content"://公告内容
"look_num"://浏览人数
"createtime"://时间
"avatar"://用户头像
]
}
]
}
})
*/
public function house_board_list()
{
$page = $this->request->param('page', 1, 'intval');
$pageNum = $this->request->param('pageNum', 10, 'intval');
$user_id = $this->auth->id;
$house_id = $this->request->param('house_board_id');
if(empty($house_id)){
$this->error('社区id不能为空');
}
$data['total_num'] = Db::name('house_board')
->where('house_id',$house_id)
->count();
$data['info'] = Db::name('house_board')
->where('house_id',$house_id)
->order('weigh desc')
->page($page,$pageNum)
->select();
foreach ($data['info'] as &$v){
$v['createtime'] = date('Y-m-d',$v['createtime']);
//查询用户是否在已读公告详情中
$house_board_detail = Db::name('house_board_detail')
->where('user_id',$user_id)
->where('house_board_id',$v['id'])
->find();
if(empty($house_board_detail)){
$info['user_id'] = $user_id;
$info['house_board_id'] = $v['id'];
$info['createtime'] = time();
Db::name('house_board_detail')->insertGetId($info);
Db::name('house_board')->where('id',$v['id'])->setInc('look_num');
}
$v['avatar'] = Db::name('house_board_detail')
->alias('a')
->join('user b','a.user_id = b.id')
->where('a.house_board_id',$v['id'])
->field('b.avatar,b.id')
->limit(6)
->select();
}
$this->success('success',$data);
}
/**
* @ApiTitle (市级列表)
* @ApiSummary (市级列表)
* @ApiMethod (POST)
* @ApiRoute (/api/house/city_list)
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"id"://市级id
"name"://市级名称
}
]
}
})
*/
public function city_list()
{
$data = Db::name('area')->field('id,name')->where('level',2)->select();
$this->success('success',$data);
}
/**
* @ApiTitle (区级列表)
* @ApiSummary (区级列表)
* @ApiMethod (POST)
* @ApiRoute (/api/house/country_list)
*
* @ApiParams (name="id", type="string", required=true, description="市级id")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"id"://区级id
"name"://区级名称
}
]
}
})
*/
public function country_list()
{
$id = $this->request->param('id');
if(empty($id)){
$this->error('缺少必要参数');
}
$data = Db::name('area')
->where('level',3)
->where('pid',$id)
->field('id,name')
->select();
$this->success('success',$data);
}
/**
* @ApiTitle (申请加入社区)
* @ApiSummary (申请加入社区)
* @ApiMethod (POST)
* @ApiRoute (/api/house/joinhouse)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="house_id", type="string", required=true, description="小区id")
* @ApiParams (name="name", type="string", required=true, description="姓名")
* @ApiParams (name="phone", type="string", required=true, description="手机号")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
}
]
}
})
*/
public function joinhouse()
{
$param['user_id'] = $this->auth->id;
$param = $this->request->param();
$validate = new Validate([
'house_id' => 'require',
'name' => 'require',
'phone' => 'require'
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
$data = Db::name('user_house')->insertGetId($param);
if(empty($data)){
$this->error('申请失败');
}else{
Db::name('user')->where('id',$param['user_id'])->update(['mobile'=>$param['phone']]);
$this->success('成功');
}
}
/**
* @ApiTitle (邀请加入社区)
* @ApiSummary (邀请加入社区)
* @ApiMethod (POST)
* @ApiRoute (/api/house/invite_join)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="house_id", type="string", required=true, description="小区id")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"thumbnail"://二维码图片
}
})
*/
public function invite_join(){
$user_id = $this->auth->id;
$house_id = $this->request->param('house_id');
if(empty($house_id)){
$this->error('缺少必要参数');
}
$data = Db::name('house')->where('id',$house_id)->field('thumbnail')->find();
$this->success('success',$data);
}
/**
* @ApiTitle (社区电话)
* @ApiSummary (社区电话)
* @ApiMethod (POST)
* @ApiRoute (/api/house/house_phone)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="house_id", type="string", required=true, description="小区id")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"id"://id
"name"://电话名称
"phone"://电话
}
})
*/
public function house_phone()
{
$user_id = $this->auth->id;
$house_id = $this->request->param('house_id');
if(empty($house_id)){
$this->error('缺少必要参数');
}
$data = Db::name('house_phone')->field('id,name,phone')->where('house_id',$house_id)->select();
$this->success('success',$data);
}
/**
* @ApiTitle (获取验证码)
* @ApiSummary (获取验证码)
* @ApiMethod (POST)
* @ApiRoute (/api/login/getcode)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="mobile", type="string", required=false, description="手机号")
*
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
}
})
*/
public function getcode()
{
$phone = $this->request->param('mobile');
if (empty($phone)) {
$this->error(['code' => 40005, 'msg' => '手机号不能为空']);
}
if (!preg_match('/^1[0-9]{10}$/', $phone)) {
$this->error(['code' => 40005, 'msg' => "请输入正确的手机格式!"]);
}
//生成验证码
$number = generateCode();
//发送验证码
$data = array(
'content' => "【社区】提醒您,您的验证码是:" .$number.",十分钟之内有效,请勿向他人泄漏您的验证码",//短信内容
'mobile' => $phone,//手机号码
'productid' => '676767',//产品id
'xh' => ''//小号
);
$result = send_sms($data);
if (substr($result, 0, strpos($result, ',')) != "1") {
$this->error(['code' => 42001, 'msg' => $result]);
}
Cache::set($phone,$number,600);
$this->success('SUCCESS');
}
/**
* @ApiTitle (验证验证码)
* @ApiSummary (验证验证码)
* @ApiMethod (POST)
* @ApiRoute (/api/login/verify)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="mobile", type="string", required=true, description="手机号")
* @ApiParams (name="code", type="string", required=true, description="验证码")
*
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
}
})
*/
public function verify()
{
$param = $this->request->param();
$validate = new Validate([
'mobile' => 'require|max:11',
'code'=>'require'
]);
if (!$validate->check($param)) {
$this->error(['code'=>40005,'msg'=>$validate->getError()]);
}
$code = Cache::get($param['mobile']);
if($param['code'] == $code){
$this->success('SUCCESS');
}else{
$this->error('验证码错误或者失效,请重新发送');
}
}
}
\ No newline at end of file
... ...
<?php
namespace app\common\controller;
use app\common\controller\Frontend;
use EasyWeChat\Foundation\Application;
use think\Cache;
use think\Request;
use think\Session;
/**
* 微信公众号控制器基类
*/
class Wechat extends Frontend
{
protected $app = null;
protected $config = null;
public function _initialize()
{
parent::_initialize(); // TODO: Change the autogenerated stub
$this->config = \config('wechat');
$this->app = new Application($this->config);
$this->oauth();
}
public function oauth() {
$user = Session::get('user');
if(!$user) {
$request = Request::instance();
Session::set('target_url',$request->url(true));
$response = $this->app->oauth->scopes(['snsapi_userinfo'])
->redirect();
$response->send();
}
}
}
\ No newline at end of file
... ...
... ... @@ -142,6 +142,17 @@ class Auth
$ip = request()->ip();
$time = time();
//添加个人编号
$user_info = Db::name('user')
->field('max(id_num) as num')
->find();
if($user_info['num'] == 0){
$num = '100000';
}else{
$num = $user_info['num'] + 1;
}
$data = [
'username' => $username,
'password' => $password,
... ... @@ -150,6 +161,7 @@ class Auth
'level' => 1,
'score' => 0,
'avatar' => '',
'id_num' =>$num
];
$params = array_merge($data, [
'nickname' => $username,
... ...
<?php
namespace app\nsms;
date_default_timezone_set('PRC');//设置时区
/**
* 发送API
* demo仅供参考,demo最低运行环境PHP5.3
* 请确认开启PHP CURL 扩展
*/
class nsms {
public $data; //发送数据
public $timeout = 30; //超时
private $apiUrl; //发送地址
private $username; //用户名
private $password; //密码
function __construct($url, $username, $password) {
$this->apiUrl = $url;
$this->username = $username;
$this->password = $password;
}
private function httpGet() {
$url = $this->apiUrl . '?' . http_build_query($this->data);
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_URL, $url);
$res = curl_exec($curl);
if (curl_errno($curl)) {
echo 'Error GET '.curl_error($curl);
}
curl_close($curl);
return $res;
}
private function httpPost(){ // 模拟提交数据函数
$curl = curl_init(); // 启动一个CURL会话
curl_setopt($curl, CURLOPT_URL, $this->apiUrl); // 要访问的地址
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
curl_setopt($curl, CURLOPT_POST, true); // 发送一个常规的Post请求
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($this->data)); // Post提交的数据包
curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout); // 设置超时限制防止死循环
curl_setopt($curl, CURLOPT_HEADER, false); // 显示返回的Header区域内容
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回
$result = curl_exec($curl); // 执行操作
if (curl_errno($curl)) {
echo 'Error POST'.curl_error($curl);
}
curl_close($curl); // 关键CURL会话
return $result; // 返回数据
}
/**
* @param $type|提交类型 POST/GET
* @param $isTranscoding|是否需要转 $isTranscoding 是否需要转utf-8 默认 false
* @return mixed
*/
public function sendSMS($type, $isTranscoding = false) {
$this->data['content'] = $isTranscoding === true ? mb_convert_encoding($this->data['content'], "UTF-8") : $this->data['content'];
$this->data['username'] = $this->username;
$this->data['tkey'] = date('YmdHis');
$this->data['password'] = md5(md5($this->password) . $this->data['tkey']);
return $type == "POST" ? $this->httpPost() : $this->httpGet();
}
}
\ No newline at end of file
... ...
此 diff 太大无法显示。
... ... @@ -26,6 +26,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'image', title: __('Image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
{field: 'url', title: __('Url'), formatter: Table.api.formatter.url},
{field: 'typeswitch', title: __('Typeswitch'), table: table, formatter: Table.api.formatter.toggle},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
// {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
... ...
... ... @@ -28,7 +28,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'admin_user_id', title: __('Admin_user_id'), operate:false},
{field: 'name', title: __('Name'), operate:'like'},
{field: 'image', title: __('Image'), operate:false, events: Table.api.events.image, formatter: Table.api.formatter.image},
{field: 'address', title: __('Address'), operate:false},
{field: 'area', title: __('所在地区'), operate:false},
{field: 'address', title: __('详细地址'), operate:false},
{field: 'lon', title: __('Lon'), operate:false},
{field: 'lat', title: __('Lat'), operate:false},
{field: 'com_number', title: __('Com_number'), operate:false},
... ...
... ... @@ -25,6 +25,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
[
{checkbox: true},
{field: 'id', title: __('Id'), operate:false},
{field: 'user_id', title: __('用户id'), operate:false},
{field: 'number', title: __('Number'), operate:false},
{field: 'name', title: __('Name'), operate:'like'},
{field: 'phone', title: __('Phone')},
... ...