first commit
This commit is contained in:
5
.env
Normal file
5
.env
Normal file
@@ -0,0 +1,5 @@
|
||||
app_debug = false
|
||||
app_trace = false
|
||||
|
||||
[trace]
|
||||
type = Console
|
||||
86
application/common.php
Normal file
86
application/common.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 流年 <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// 应用公共文件
|
||||
//
|
||||
|
||||
function get_array_url($k = '', $value = '', $emp = '')
|
||||
{
|
||||
$url = \think\Request::instance()->get();
|
||||
unset($url['s']);
|
||||
if ($k) {
|
||||
if (isset($url[$k])) {
|
||||
if ($value) {
|
||||
$url[$k] = $value;
|
||||
} else {
|
||||
unset($url[$k]);
|
||||
}
|
||||
} else {
|
||||
if ($value) {
|
||||
$url[$k] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($emp) {
|
||||
$array = explode(',', $emp);
|
||||
if (is_array($array)) {
|
||||
foreach ($array as $key => $value) {
|
||||
if (isset($url[$value])) {
|
||||
unset($url[$value]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return http_build_query($url);
|
||||
}
|
||||
|
||||
/**
|
||||
* curl操作函数
|
||||
* @param string $url 请求地址
|
||||
* @param string $method 提交方式
|
||||
* @param array $postFields 提交内容
|
||||
* @param array $header 请求头
|
||||
* @return mixed 返回数据
|
||||
*/
|
||||
function http($url, $method = "GET", $postFields = null, $headers = null)
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_FAILONERROR, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
|
||||
|
||||
if (!is_null($postFields)) {
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
|
||||
}
|
||||
//https request
|
||||
if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||||
}
|
||||
if (is_array($headers) && 0 < count($headers)) {
|
||||
$httpHeaders = [];
|
||||
foreach ($headers as $key => $value) {
|
||||
array_push($httpHeaders, $key . ":" . $value);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders);
|
||||
}
|
||||
$data = curl_exec($ch);
|
||||
$err = curl_errno($ch);
|
||||
curl_close($ch);
|
||||
if ($err > 0) {
|
||||
return curl_error($ch);
|
||||
} else {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
34
application/common/model/Advert.php
Normal file
34
application/common/model/Advert.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
class Advert extends _Init
|
||||
{
|
||||
/**
|
||||
* 模型初始化【事件注册】
|
||||
*/
|
||||
protected static function init()
|
||||
{
|
||||
self::beforeUpdate(function ($data) {
|
||||
$data->update_time = time();
|
||||
});
|
||||
|
||||
self::beforeInsert(function ($data) {
|
||||
$data->create_time = time();
|
||||
$data->update_time = 0;
|
||||
$data->status = 1;
|
||||
});
|
||||
}
|
||||
|
||||
public function detail()
|
||||
{
|
||||
return $this->hasMany('AdvertDetail')->where('status', '>=', 0);
|
||||
}
|
||||
|
||||
}
|
||||
34
application/common/model/AdvertDetail.php
Normal file
34
application/common/model/AdvertDetail.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
class AdvertDetail extends _Init
|
||||
{
|
||||
/**
|
||||
* 模型初始化【事件注册】
|
||||
*/
|
||||
protected static function init()
|
||||
{
|
||||
self::beforeUpdate(function ($data) {
|
||||
$data->update_time = time();
|
||||
});
|
||||
|
||||
self::beforeInsert(function ($data) {
|
||||
$data->create_time = time();
|
||||
$data->update_time = 0;
|
||||
$data->click = 0;
|
||||
$data->status = 1;
|
||||
});
|
||||
}
|
||||
|
||||
public function getCoverAttr($value, $data)
|
||||
{
|
||||
return Storage::where('id', $data['storage_id'])->value('path') ?: '';
|
||||
}
|
||||
}
|
||||
58
application/common/model/Article.php
Normal file
58
application/common/model/Article.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
class Article extends _Init
|
||||
{
|
||||
/**
|
||||
* 模型初始化【事件注册】
|
||||
*/
|
||||
protected static function init()
|
||||
{
|
||||
self::beforeInsert(function ($data) {
|
||||
$data->status = 1;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取封面地址
|
||||
* @param [type] $value 封面id
|
||||
* @param [type] $data 文章数据
|
||||
* @return [type] 图片地址
|
||||
*/
|
||||
public function getCoverAttr($value, $data)
|
||||
{
|
||||
return Storage::where('id', $data['storage_id'])->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取封面地址
|
||||
* @param [type] $value 封面id
|
||||
* @param [type] $data 文章数据
|
||||
* @return [type] 图片地址
|
||||
*/
|
||||
public function getCreateTimeAttr($value, $data)
|
||||
{
|
||||
return date('Y-m-d', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取关联的分类
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function category()
|
||||
{
|
||||
return $this->hasOne('Category', 'id', 'category_id');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('MemberInfo', 'uid', 'uid');
|
||||
}
|
||||
}
|
||||
20
application/common/model/ArticleModel.php
Normal file
20
application/common/model/ArticleModel.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
class ArticleModel extends _Init
|
||||
{
|
||||
protected static function init()
|
||||
{
|
||||
self::beforeInsert(function ($data) {
|
||||
$data->status = 1;
|
||||
$data->sort = $data['sort'] ?: 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
20
application/common/model/Auth.php
Normal file
20
application/common/model/Auth.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
class Auth extends _Init
|
||||
{
|
||||
/**
|
||||
* 获取用户数量
|
||||
*/
|
||||
protected function getUserCountAttr()
|
||||
{
|
||||
return $this->hasMany('AuthUser')->count();
|
||||
}
|
||||
}
|
||||
35
application/common/model/AuthUser.php
Normal file
35
application/common/model/AuthUser.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
class AuthUser extends _Init
|
||||
{
|
||||
/**
|
||||
* 关闭更新时间写入
|
||||
*/
|
||||
protected $updateTime = false;
|
||||
|
||||
/**
|
||||
* 关联用户模型
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne('Member', 'id', 'uid');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联分组
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function auth()
|
||||
{
|
||||
return $this->belongsTo('Auth');
|
||||
}
|
||||
}
|
||||
33
application/common/model/Category.php
Normal file
33
application/common/model/Category.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Config;
|
||||
|
||||
class Category extends _Init
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取封面地址
|
||||
* @param [type] $value 封面id
|
||||
* @param [type] $data 文章数据
|
||||
* @return [type] 图片地址
|
||||
*/
|
||||
public function getCoverAttr($value, $data)
|
||||
{
|
||||
return Storage::where('id', $data['storage_id'])->value('path');
|
||||
}
|
||||
public function getModelAttr($value, $data)
|
||||
{
|
||||
$list = config::get('category_model');
|
||||
$name = $list[$data['model']];
|
||||
return $name ?? '没有';
|
||||
}
|
||||
|
||||
}
|
||||
13
application/common/model/City.php
Normal file
13
application/common/model/City.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
class City extends _Init
|
||||
{
|
||||
}
|
||||
96
application/common/model/Config.php
Normal file
96
application/common/model/Config.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Cache;
|
||||
|
||||
class Config extends _Init
|
||||
{
|
||||
|
||||
/**
|
||||
* 模型初始化【事件注册】
|
||||
*/
|
||||
protected static function init()
|
||||
{
|
||||
self::afterWrite(function () {
|
||||
Cache::clear();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取器
|
||||
*/
|
||||
protected function getTypeTextAttr($value, $data)
|
||||
{
|
||||
return Config::getValue($data['type'], 'config_type_list');
|
||||
}
|
||||
protected function getGroupTextAttr($value, $data)
|
||||
{
|
||||
return Config::getValue($data['group'], 'config_group_list');
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置列表,优化输出
|
||||
*/
|
||||
protected function getValueTextAttr($value, $data)
|
||||
{
|
||||
return preg_replace('/\r\n/', "<br/>", $data['value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化枚举类型的配置
|
||||
*/
|
||||
protected function getExtraArrayAttr($value, $data)
|
||||
{
|
||||
$array = preg_split('/[\r\n]+/', trim($data['extra'], "\r\n"));
|
||||
$enum = [];
|
||||
if (strpos($data['extra'], ':')) {
|
||||
foreach ($array as $val) {
|
||||
list($k, $v) = explode(':', $val, 2);
|
||||
$enum[$k] = $v;
|
||||
}
|
||||
} else {
|
||||
$enum = $array;
|
||||
}
|
||||
return $enum;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置内容
|
||||
* @param string $key
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
public static function getValue($key, $type = null)
|
||||
{
|
||||
if ($key == -1) {
|
||||
return '<span style="color:#D2322D;">已删除</span>';
|
||||
}
|
||||
if (!is_null($type) && is_string($type)) {
|
||||
$res = \think\Config::get($type);
|
||||
$res = isset($res[$key]) ? $res[$key] : '';
|
||||
} elseif (!is_null($type) && is_array($type)) {
|
||||
$res = isset($type[$key]) ? $type[$key] : '';
|
||||
} else {
|
||||
switch ($key) {
|
||||
case 0:$res = '<span style="color:#E48600;">禁用</span>';
|
||||
break;
|
||||
case 1:$res = '<span style="color:#229F24;">正常</span>';
|
||||
break;
|
||||
case 2:$res = '<span style="color:#39B3D7;">待审核</span>';
|
||||
break;
|
||||
case 3:$res = '<span style="color:#E48600;">被驳回</span>';
|
||||
break;
|
||||
default:$res = '';
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
42
application/common/model/Content.php
Normal file
42
application/common/model/Content.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
class Content extends _Init
|
||||
{
|
||||
/**
|
||||
* 模型初始化【事件注册】
|
||||
*/
|
||||
protected static function init()
|
||||
{
|
||||
self::beforeInsert(function ($data) {
|
||||
$data->status = 1;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 获取封面地址
|
||||
* @param [type] $value 封面id
|
||||
* @param [type] $data 文章数据
|
||||
* @return [type] 图片地址
|
||||
*/
|
||||
public function getCoverAttr($value, $data)
|
||||
{
|
||||
return Storage::where('id', $data['storage_id'])->value('path');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取关联的分类
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function category()
|
||||
{
|
||||
return $this->hasOne('Category', 'id', 'category_id');
|
||||
}
|
||||
|
||||
}
|
||||
44
application/common/model/Direct.php
Normal file
44
application/common/model/Direct.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
class Direct extends _Init
|
||||
{
|
||||
/**
|
||||
* 模型初始化【事件注册】
|
||||
*/
|
||||
protected static function init()
|
||||
{
|
||||
self::beforeInsert(function ($data) {
|
||||
$data->status = 1;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取封面地址
|
||||
* @param [type] $value 封面id
|
||||
* @param [type] $data 文章数据
|
||||
* @return [type] 图片地址
|
||||
*/
|
||||
public function getCoverAttr($value, $data)
|
||||
{
|
||||
return Storage::where('id', $data['storage_id'])->value('path');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取音/视频地址
|
||||
* @param [type] $value 封面id
|
||||
* @param [type] $data 文章数据
|
||||
* @return [type] 图片地址
|
||||
*/
|
||||
public function getExtPathAttr($value, $data)
|
||||
{
|
||||
return Storage::where('id', $data['ext_id'])->value('path');
|
||||
}
|
||||
}
|
||||
38
application/common/model/Experience.php
Normal file
38
application/common/model/Experience.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
class Experience extends _Init
|
||||
{
|
||||
/**
|
||||
* 模型初始化【事件注册】
|
||||
*/
|
||||
protected static function init()
|
||||
{
|
||||
self::beforeInsert(function ($data) {
|
||||
$data->status = 1;
|
||||
});
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('MemberInfo', 'uid', 'uid');
|
||||
}
|
||||
|
||||
public function comment()
|
||||
{
|
||||
return $this->hasMany('Experience', 'pid', 'id')->order('id asc');
|
||||
}
|
||||
|
||||
public function getCountAttr($value, $data)
|
||||
{
|
||||
$res = ExperienceTags::where(['experience_id' => $data['id'], 'uid' => UID])->count();
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
15
application/common/model/ExperienceTags.php
Normal file
15
application/common/model/ExperienceTags.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
class ExperienceTags extends _Init
|
||||
{
|
||||
protected $updateTime = false;
|
||||
|
||||
}
|
||||
36
application/common/model/Help.php
Normal file
36
application/common/model/Help.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Config;
|
||||
|
||||
class Help extends _Init
|
||||
{
|
||||
/**
|
||||
* 模型初始化【事件注册】
|
||||
*/
|
||||
protected static function init()
|
||||
{
|
||||
self::beforeInsert(function ($data) {
|
||||
$data->status = 1;
|
||||
});
|
||||
}
|
||||
|
||||
public function getCategoryAttr($value, $data)
|
||||
{
|
||||
$list = Config::get('help_type');
|
||||
return empty($list[$data['category']]) ? '没这个分类' : $list[$data['category']];
|
||||
}
|
||||
|
||||
public function getCreateTimeAttr($value, $data)
|
||||
{
|
||||
return date('Y-m-d', $value);
|
||||
}
|
||||
|
||||
}
|
||||
59
application/common/model/Logs.php
Normal file
59
application/common/model/Logs.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
class Logs extends _Init
|
||||
{
|
||||
/**
|
||||
* 关闭更新时间写入
|
||||
*/
|
||||
protected $updateTime = false;
|
||||
|
||||
/**
|
||||
* 转换datas数据
|
||||
* @param [type] $value 数据内容
|
||||
*/
|
||||
protected function setDatasAttr($value)
|
||||
{
|
||||
return !empty($value) ? json_encode($value, JSON_UNESCAPED_UNICODE) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取昵称
|
||||
*/
|
||||
protected function getUidTextAttr($value, $data)
|
||||
{
|
||||
return MemberInfo::where('uid', $data['uid'])->value('nickname');
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化datas数据
|
||||
* @param [type] $value datas数据
|
||||
* @param [type] $data 数据集合
|
||||
*/
|
||||
protected function getDatasTextAttr($value, $data)
|
||||
{
|
||||
$content = $data['datas'];
|
||||
|
||||
if (!empty($content)) {
|
||||
$content = json_decode($content);
|
||||
$string = '';
|
||||
if (is_object($content) && !empty($content)) {
|
||||
foreach ($content as $key => $value) {
|
||||
$string .= $key . ' : ' . json_encode($value, JSON_UNESCAPED_UNICODE) . '<br/>';
|
||||
}
|
||||
} else {
|
||||
$string = $content;
|
||||
}
|
||||
return $string;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
68
application/common/model/Member.php
Normal file
68
application/common/model/Member.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Config as Conf;
|
||||
use think\Request;
|
||||
use tools\Crypt;
|
||||
|
||||
class Member extends _Init
|
||||
{
|
||||
protected $readonly = [''];
|
||||
|
||||
/**
|
||||
* 模型初始化【事件注册】
|
||||
*/
|
||||
protected static function init()
|
||||
{
|
||||
self::beforeInsert(function ($data) {
|
||||
$data->reg_ip = Request::instance()->ip();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化 最后登录时间
|
||||
* @param [type] $value 最后登录时间 时间戳
|
||||
*/
|
||||
protected function getLastTimeAttr($value)
|
||||
{
|
||||
return date(Conf::get('database.datetime_format'), $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密密码
|
||||
* @param [type] $value [description]
|
||||
*/
|
||||
protected function setPasswordAttr($value)
|
||||
{
|
||||
return Crypt::uMd5($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户资料
|
||||
*/
|
||||
protected function info()
|
||||
{
|
||||
return $this->hasOne('MemberInfo', 'uid', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联 AuthUser 表
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function authUser()
|
||||
{
|
||||
return $this->hasOne('AuthUser', 'uid', 'id');
|
||||
}
|
||||
|
||||
public function getJuniorAttr($value, $data)
|
||||
{
|
||||
return MemberList::where('uid', $data['id'])->count();
|
||||
}
|
||||
}
|
||||
96
application/common/model/MemberInfo.php
Normal file
96
application/common/model/MemberInfo.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
class MemberInfo extends _Init
|
||||
{
|
||||
protected $createTime = false;
|
||||
protected $readonly = ['image'];
|
||||
/**
|
||||
* 获取头像地址
|
||||
* @param [type] $value [description]
|
||||
* @param [type] $data [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
protected function getAvatarAttr($value, $data)
|
||||
{
|
||||
$avatar = $data['headimgurl'];
|
||||
if (!empty($avatar) && strpos($avatar, 'wx.qlogo.cn')) {
|
||||
return rtrim($avatar, '0') . '132';
|
||||
} elseif (empty($avatar)) {
|
||||
return '/static/system/images/avatar.jpg';
|
||||
} else {
|
||||
return $avatar;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取头像地址
|
||||
* @param [type] $value [description]
|
||||
* @param [type] $data [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
protected function getQrcodeAttr($value, $data)
|
||||
{
|
||||
$path = Storage::where('id', $data['qrcode'])->value('path');
|
||||
return $path ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断用户是否为 未过期的VIP会员
|
||||
* @param [type] $value [description]
|
||||
* @param [type] $data [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
protected function getIsVipAttr($value, $data)
|
||||
{
|
||||
if ($data['vip_time'] > time() && $data["is_vip"] == 1) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected function getVipTextAttr($value, $data)
|
||||
{
|
||||
if ($data['vip_time'] > time() && $data["is_vip"] == 1) {
|
||||
return 'VIP会员';
|
||||
} else {
|
||||
return '普通会员';
|
||||
}
|
||||
}
|
||||
|
||||
protected function getVipTimeAttr($value, $data)
|
||||
{
|
||||
if ($value < time()) {
|
||||
return '永久';
|
||||
} else {
|
||||
return date('Y-m-d', $value);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getVipEndTimeAttr($value, $data)
|
||||
{
|
||||
return $data['vip_time'];
|
||||
}
|
||||
|
||||
protected function getIndexTplAttr($value, $data)
|
||||
{
|
||||
if ($this->is_vip) {
|
||||
return $value;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
protected function getMessageCountAttr($value, $data)
|
||||
{
|
||||
return Message::where('to_uid', $data['uid'])->count();
|
||||
}
|
||||
}
|
||||
14
application/common/model/MemberList.php
Normal file
14
application/common/model/MemberList.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
class MemberList extends _Init
|
||||
{
|
||||
|
||||
}
|
||||
34
application/common/model/Menu.php
Normal file
34
application/common/model/Menu.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
class Menu extends _Init
|
||||
{
|
||||
protected function getUrlTextAttr($value, $data)
|
||||
{
|
||||
if ($data['url']) {
|
||||
return url($data['url']);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改器
|
||||
*/
|
||||
protected function setAuthAttr($value, $data)
|
||||
{
|
||||
return parent::parseStatus($value);
|
||||
}
|
||||
|
||||
protected function setHideAttr($value, $data)
|
||||
{
|
||||
return parent::parseStatus($value);
|
||||
}
|
||||
}
|
||||
22
application/common/model/Message.php
Normal file
22
application/common/model/Message.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
/**
|
||||
*留言
|
||||
*/
|
||||
class Message extends _Init
|
||||
{
|
||||
protected $updateTime = false;
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('MemberInfo', 'from_uid', 'uid');
|
||||
}
|
||||
}
|
||||
21
application/common/model/Province.php
Normal file
21
application/common/model/Province.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
class Province extends _Init
|
||||
{
|
||||
/**
|
||||
* 模型初始化【事件注册】
|
||||
*/
|
||||
protected static function init()
|
||||
{
|
||||
self::beforeInsert(function ($data) {
|
||||
});
|
||||
}
|
||||
}
|
||||
39
application/common/model/Score.php
Normal file
39
application/common/model/Score.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
class Score extends _Init
|
||||
{
|
||||
/**
|
||||
* 关闭更新时间写入
|
||||
*/
|
||||
protected $updateTime = false;
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('MemberInfo', 'uid', 'uid');
|
||||
}
|
||||
|
||||
public function getScoreAttr($value, $data)
|
||||
{
|
||||
return floatval($value);
|
||||
}
|
||||
|
||||
public function getRulesAttr($value, $data)
|
||||
{
|
||||
$map = ['model' => $data['rule_id']];
|
||||
return ScoreRules::where($map)->find();
|
||||
}
|
||||
|
||||
public function getAddtimeAttr($value, $data)
|
||||
{
|
||||
return date('Y-m-d', $data['create_time']);
|
||||
}
|
||||
|
||||
}
|
||||
28
application/common/model/ScoreRules.php
Normal file
28
application/common/model/ScoreRules.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
class ScoreRules extends _Init
|
||||
{
|
||||
/**
|
||||
* 模型初始化【事件注册】
|
||||
*/
|
||||
protected static function init()
|
||||
{
|
||||
self::beforeInsert(function ($data) {
|
||||
$data->status = 1;
|
||||
});
|
||||
}
|
||||
|
||||
public function getCreateTimeAttr($value, $data)
|
||||
{
|
||||
return date('Y-m-d', $value);
|
||||
}
|
||||
|
||||
}
|
||||
27
application/common/model/Sms.php
Normal file
27
application/common/model/Sms.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
class Sms extends _Init
|
||||
{
|
||||
|
||||
public function getStatusAttr($value)
|
||||
{
|
||||
switch ($value) {
|
||||
case '0':
|
||||
return '<span style="color:red">未使用</span>';
|
||||
break;
|
||||
case '1':
|
||||
return '<span style="color:green">已使用</span>';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
17
application/common/model/Storage.php
Normal file
17
application/common/model/Storage.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
class Storage extends _Init
|
||||
{
|
||||
/**
|
||||
* 关闭更新时间写入
|
||||
*/
|
||||
protected $updateTime = false;
|
||||
}
|
||||
17
application/common/model/Suggest.php
Normal file
17
application/common/model/Suggest.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
class Suggest extends _Init
|
||||
{
|
||||
public function info()
|
||||
{
|
||||
return $this->belongsTo('MemberInfo', 'uid', 'uid');
|
||||
}
|
||||
}
|
||||
14
application/common/model/Template.php
Normal file
14
application/common/model/Template.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
class Template extends _Init
|
||||
{
|
||||
|
||||
}
|
||||
53
application/common/model/VipOrder.php
Normal file
53
application/common/model/VipOrder.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
use tools\Str;
|
||||
|
||||
class VipOrder extends _Init
|
||||
{
|
||||
/**
|
||||
* 模型初始化【事件注册】
|
||||
*/
|
||||
protected static function init()
|
||||
{
|
||||
self::beforeInsert(function ($data) {
|
||||
$data->orderid = Str::orderid('VIP');
|
||||
});
|
||||
}
|
||||
|
||||
public function getStatusAttr($value)
|
||||
{
|
||||
switch ($value) {
|
||||
case '0':
|
||||
return '<span style="color:red">未支付</span>';
|
||||
break;
|
||||
case '20':
|
||||
return '<span style="color:green">已支付</span>';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
public function getModelAttr($value, $data)
|
||||
{
|
||||
if ($data['model'] == 'weixin') {
|
||||
return '微信支付';
|
||||
} else if ($data['model'] == 'score') {
|
||||
return '积分兑换';
|
||||
} else {
|
||||
return '未知';
|
||||
}
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('MemberInfo', 'uid', 'uid');
|
||||
}
|
||||
}
|
||||
30
application/common/model/_Init.php
Normal file
30
application/common/model/_Init.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class _Init extends Model
|
||||
{
|
||||
protected function setStatusAttr($value)
|
||||
{
|
||||
return self::parseStatus($value);
|
||||
}
|
||||
|
||||
protected function parseStatus($status)
|
||||
{
|
||||
if (is_numeric($status)) {
|
||||
return $status;
|
||||
} elseif ($status == 'true' || $status == 'on') {
|
||||
return 1;
|
||||
} elseif ($status == 'false' || $status == 'off') {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
78
application/common/service/Advert.php
Normal file
78
application/common/service/Advert.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\Advert as AdvertModel;
|
||||
use app\common\validate\Advert as AdvertValidate;
|
||||
|
||||
class Advert extends _Init
|
||||
{
|
||||
public static function add($data)
|
||||
{
|
||||
$validate = new AdvertValidate();
|
||||
|
||||
if (!$validate->check($data)) {
|
||||
return $$validate->getError();
|
||||
}
|
||||
|
||||
if (AdvertModel::create($data)) {
|
||||
return true;
|
||||
} else {
|
||||
return '添加失败';
|
||||
}
|
||||
}
|
||||
|
||||
public static function edit($data)
|
||||
{
|
||||
$validate = new AdvertValidate();
|
||||
|
||||
if (!$validate->check($data)) {
|
||||
return $$validate->getError();
|
||||
}
|
||||
|
||||
if (AdvertModel::update($data)) {
|
||||
return true;
|
||||
} else {
|
||||
return '编辑失败';
|
||||
}
|
||||
}
|
||||
|
||||
public static function del($id)
|
||||
{
|
||||
$info = AdvertModel::get($id);
|
||||
|
||||
if (!$info) {
|
||||
return $this->error('数据不存在');
|
||||
} elseif ($info->save(['status' => -1])) {
|
||||
return true;
|
||||
} else {
|
||||
return '删除失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [status description]
|
||||
* @param [type] $id [description]
|
||||
* @param [type] $status [description]
|
||||
* @param [type] $type [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function status($id, $status, $type)
|
||||
{
|
||||
$info = AdvertModel::get($id);
|
||||
if (!$info) {
|
||||
return $this->error('数据不存在');
|
||||
} elseif ($info->save([$type => $status])) {
|
||||
Logs::write('修改状态', [$type => $status]);
|
||||
return true;
|
||||
} else {
|
||||
return '设置失败';
|
||||
}
|
||||
}
|
||||
}
|
||||
78
application/common/service/AdvertDetail.php
Normal file
78
application/common/service/AdvertDetail.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\AdvertDetail as AdvertDetailModel;
|
||||
use app\common\validate\AdvertDetail as AdvertDetailValidate;
|
||||
|
||||
class AdvertDetail extends _Init
|
||||
{
|
||||
public static function add($data)
|
||||
{
|
||||
$validate = new AdvertDetailValidate();
|
||||
|
||||
if (!$validate->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
|
||||
if (AdvertDetailModel::create($data)) {
|
||||
return true;
|
||||
} else {
|
||||
return '添加失败';
|
||||
}
|
||||
}
|
||||
|
||||
public static function edit($data)
|
||||
{
|
||||
$validate = new AdvertDetailValidate();
|
||||
|
||||
if (!$validate->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
|
||||
if (AdvertDetailModel::update($data)) {
|
||||
return true;
|
||||
} else {
|
||||
return '修改失败';
|
||||
}
|
||||
}
|
||||
|
||||
public static function del($id)
|
||||
{
|
||||
$info = AdvertDetailModel::get($id);
|
||||
|
||||
if (!$info) {
|
||||
return $this->error('数据不存在');
|
||||
} elseif ($info->save(['status' => -1])) {
|
||||
return true;
|
||||
} else {
|
||||
return '删除失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [status description]
|
||||
* @param [type] $id [description]
|
||||
* @param [type] $status [description]
|
||||
* @param [type] $type [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function status($id, $status, $type)
|
||||
{
|
||||
$info = AdvertDetailModel::get($id);
|
||||
if (!$info) {
|
||||
return $this->error('数据不存在');
|
||||
} elseif ($info->save([$type => $status])) {
|
||||
Logs::write('修改状态', [$type => $status]);
|
||||
return true;
|
||||
} else {
|
||||
return '设置失败';
|
||||
}
|
||||
}
|
||||
}
|
||||
265
application/common/service/Article.php
Normal file
265
application/common/service/Article.php
Normal file
@@ -0,0 +1,265 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\Article as ArticleModel;
|
||||
use app\common\model\Category as CategoryModel;
|
||||
use app\common\service\Score as ScoreService;
|
||||
use app\common\validate\Article as ArticleValidate;
|
||||
|
||||
class Article extends _Init
|
||||
{
|
||||
/**
|
||||
* 添加信息
|
||||
* @param [type] $data 文章数据
|
||||
*/
|
||||
public static function create($data)
|
||||
{
|
||||
$validate = new ArticleValidate();
|
||||
if (!$validate->scene('add')->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
|
||||
$info = ArticleModel::create($data);
|
||||
if ($info) {
|
||||
return true;
|
||||
} else {
|
||||
return '创建文章失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑文章
|
||||
* @param [type] $data 更新的数据
|
||||
* @return [type] 返回 修改的结果
|
||||
*/
|
||||
public static function edit($data)
|
||||
{
|
||||
$validate = new ArticleValidate();
|
||||
if (!$validate->scene('add')->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
$info = ArticleModel::update($data);
|
||||
if ($info) {
|
||||
return true;
|
||||
} else {
|
||||
return '编辑文章失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 前台用户添加文章
|
||||
* @param [type] $data 更新的数据
|
||||
* @return [type] 返回 修改的结果
|
||||
*/
|
||||
public static function userAdd($data)
|
||||
{
|
||||
$data = [
|
||||
'uid' => $data['uid'] ?? 0,
|
||||
'title' => $data['title'] ?? '',
|
||||
'content' => $data['content'] ?? '',
|
||||
'description' => $data['description'] ?? '',
|
||||
'category_id' => $data['category_id'] ?? '0',
|
||||
'storage_id' => $data['storage_id'] ?? '0',
|
||||
'thumb' => $data['thumb'] ?? '0',
|
||||
'status' => $data['status'] ?? '1',
|
||||
'url' => $data['url'] ?? '',
|
||||
'nickname' => $data['nickname'] ?? '',
|
||||
'head_img' => $data['head_img'] ?? '',
|
||||
'click' => 0,
|
||||
];
|
||||
|
||||
$validate = new ArticleValidate();
|
||||
if (!$validate->scene('add')->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
$info = ArticleModel::create($data);
|
||||
if ($info) {
|
||||
ScoreService::addArticle($data['uid'], 'add');
|
||||
return true;
|
||||
} else {
|
||||
return '文章创建失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改文章状态
|
||||
* @param [type] $id 文章id
|
||||
* @param [type] $status 状态
|
||||
* @return [type] 返回结果
|
||||
*/
|
||||
public static function status($id, $status)
|
||||
{
|
||||
$info = ArticleModel::get($id);
|
||||
if (!$info) {
|
||||
return '文章不存在';
|
||||
} elseif ($info->save(['status' => $status])) {
|
||||
Logs::write('修改状态', ['status' => $status]);
|
||||
return true;
|
||||
} else {
|
||||
return '修改状态失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文章
|
||||
* @param [type] $id 要删除的文章id
|
||||
* @return [type] 返回 结果
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
$info = ArticleModel::get($id);
|
||||
if (!$info) {
|
||||
return '文章不存在';
|
||||
} elseif ($info->save(['status' => -1])) {
|
||||
return true;
|
||||
} else {
|
||||
return '删除失败';
|
||||
}
|
||||
|
||||
// $model = new ArticleModel();
|
||||
// if ($model->destroy($id)) {
|
||||
// return true;
|
||||
// } else {
|
||||
// return '删除失败';
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分类列表
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function categoryList()
|
||||
{
|
||||
$map = [
|
||||
'status' => '1',
|
||||
'model' => 'article',
|
||||
];
|
||||
return CategoryModel::where($map)->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 采集公众号文章
|
||||
* @param [type] $url [description]
|
||||
* @param integer $uid [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function collect($url, $uid = 1)
|
||||
{
|
||||
$map = [
|
||||
'url' => $url,
|
||||
'uid' => $uid,
|
||||
];
|
||||
|
||||
$userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A403 Safari/8536.25';
|
||||
|
||||
$info = ArticleModel::where($map)->find();
|
||||
if ($info) {
|
||||
return $info->id;
|
||||
} else {
|
||||
$info = new ArticleModel;
|
||||
$html = file_get_contents($url);
|
||||
// $html = http($url, 'GET', '', '', $userAgent);
|
||||
|
||||
//获取文章标题
|
||||
preg_match_all("/id=\"activity-name\">(.*)<\/h2>/is", $html, $title);
|
||||
//获取文章内容部分
|
||||
preg_match_all("/id=\"js_content\">(.*)<script/iUs", $html, $content, PREG_PATTERN_ORDER);
|
||||
//格式化标题
|
||||
$title = str_replace("\r\n", "", str_replace(" ", "", $title[1][0]));
|
||||
|
||||
//拼接正确的内容标签
|
||||
$content = "<div id='js_content' class='ce-padding-sm'>" . $content[1][0];
|
||||
//将所有图片的data-src更改为src
|
||||
$content = str_replace("data-src", "src", $content);
|
||||
$content = str_replace('0?"', '0"', $content);
|
||||
|
||||
//获取所有图片地址
|
||||
$pattern = "/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png]))[\'|\"].*?[\/]?>/";
|
||||
preg_match_all('/<img.*?src="(.*?)".*?>/is', $content, $img);
|
||||
//遍历所有图片,采集到服务器
|
||||
$i = 0;
|
||||
$thumb = '';
|
||||
$img_pre = uniqid(); // 确保每篇文章的图片前缀一致,路径按照日期存储
|
||||
$dir = './uploads/collect/' . date('Y-m/d/');
|
||||
foreach ($img[1] as $key => $value) {
|
||||
//判断图片是否存在http头
|
||||
if (preg_match('/(http:\/\/)|(https:\/\/)/i', $value)) {
|
||||
//分割微信图片地址
|
||||
$str = explode('/', $value);
|
||||
//获取图片地址名称,不包括拓展名
|
||||
$allname = $str[4];
|
||||
//识别拓展名
|
||||
if (strrpos($value, 'wx_fmt=') > 0) {
|
||||
$ext = substr($value, strrpos($value, 'wx_fmt=') + 7);
|
||||
$allname = $img_pre . '_' . $i . '.' . $ext;
|
||||
}
|
||||
//拓展名拼接图片名称
|
||||
//获取图片数据
|
||||
// $image = file_get_contents($value);
|
||||
$image = http($value, 'GET', '', '', $userAgent);
|
||||
//保存服务器目录文件
|
||||
try {
|
||||
if (!is_dir($dir)) {
|
||||
mkdir($dir, 0755, true);
|
||||
}
|
||||
file_put_contents($dir . $allname, $image);
|
||||
//更替图片文件地址为服务器图片地址
|
||||
$content = str_replace($value, ltrim($dir, '.') . $allname, $content);
|
||||
if ($i == 0) {
|
||||
$thumb = ltrim($dir, '.') . $allname;
|
||||
}
|
||||
$i++;
|
||||
} catch (Exception $e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
//修正视频内容
|
||||
$content = str_replace("preview.html", "player.html", $content);
|
||||
//重新设置 iframe
|
||||
preg_match('/<iframe[^>]*\s+src="([^"]*)"[^>]*>/is', $content, $matched);
|
||||
if (!empty($matched[0])) {
|
||||
$src = explode('&', $matched['1']);
|
||||
$str = '<p style="max-width:100%; margin:14px"><iframe frameborder="0" src="' . $src['0'] . '&auto=0" style="z-index: 1; width: 100% ! important; height: 231.75px ! important; overflow: hidden;" class="video_iframe" scrolling="no"></iframe></p>';
|
||||
$content = str_replace($matched['0'], $str, $content);
|
||||
}
|
||||
//获取公众号名称
|
||||
preg_match_all('/var nickname = \"(.*?)\";/si', $html, $m);
|
||||
$nickname = $m[1][0];
|
||||
//获取公众号头像
|
||||
preg_match_all('/var round_head_img = \"(.*?)\";/si', $html, $m);
|
||||
$head_img = $m[1][0];
|
||||
$data = [
|
||||
'title' => $title,
|
||||
'content' => $content,
|
||||
'description' => '',
|
||||
'category_id' => 0,
|
||||
'storage_id' => 0,
|
||||
'thumb' => $thumb,
|
||||
'status' => 1,
|
||||
'create_time' => time(),
|
||||
'update_time' => 0,
|
||||
'url' => $url,
|
||||
'nickname' => $nickname,
|
||||
'head_img' => $head_img,
|
||||
'uid' => $uid,
|
||||
'click' => 0,
|
||||
];
|
||||
$info->save($data);
|
||||
if ($info) {
|
||||
ScoreService::addArticle($data['uid'], 'collect');
|
||||
return $info->id;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
88
application/common/service/ArticleModel.php
Normal file
88
application/common/service/ArticleModel.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\ArticleModel as ArticleModelModel;
|
||||
use app\common\validate\ArticleModel as ArticleModelValidate;
|
||||
|
||||
class ArticleModel extends _Init
|
||||
{
|
||||
/**
|
||||
* 添加信息
|
||||
* @param [type] $data 文章数据
|
||||
*/
|
||||
public static function create($data)
|
||||
{
|
||||
$validate = new ArticleModelValidate();
|
||||
|
||||
if (!$validate->scene('add')->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
$info = ArticleModelModel::create($data);
|
||||
|
||||
if ($info) {
|
||||
return true;
|
||||
} else {
|
||||
return '创建文章模板失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑文章
|
||||
* @param [type] $data 更新的数据
|
||||
* @return [type] 返回 修改的结果
|
||||
*/
|
||||
public static function edit($data)
|
||||
{
|
||||
$validate = new ArticleModelValidate();
|
||||
if (!$validate->scene('add')->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
$info = ArticleModelModel::update($data);
|
||||
if ($info) {
|
||||
return true;
|
||||
} else {
|
||||
return '编辑文章模板失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改文章状态
|
||||
* @param [type] $id 文章id
|
||||
* @param [type] $status 状态
|
||||
* @return [type] 返回结果
|
||||
*/
|
||||
public static function status($id, $status)
|
||||
{
|
||||
$info = ArticleModelModel::get($id);
|
||||
if (!$info) {
|
||||
return '文章模板不存在';
|
||||
} elseif ($info->save(['status' => $status])) {
|
||||
Logs::write('修改状态', ['status' => $status]);
|
||||
return true;
|
||||
} else {
|
||||
return '修改状态失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文章
|
||||
* @param [type] $id 要删除的文章id
|
||||
* @return [type] 返回 结果
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
$model = new ArticleModelModel();
|
||||
if ($model->destroy($id)) {
|
||||
return true;
|
||||
} else {
|
||||
return '删除失败';
|
||||
}
|
||||
}
|
||||
}
|
||||
206
application/common/service/Auth.php
Normal file
206
application/common/service/Auth.php
Normal file
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\Auth as AuthModel;
|
||||
use app\common\model\AuthUser as AuthUserModel;
|
||||
use app\common\validate\Auth as AuthValidate;
|
||||
use think\Db;
|
||||
use tools\Tree;
|
||||
|
||||
class Auth extends _Init
|
||||
{
|
||||
/**
|
||||
* 添加授权分组
|
||||
* @param [type] $data 要添加的数据
|
||||
*/
|
||||
public static function add($data)
|
||||
{
|
||||
$validate = new AuthValidate();
|
||||
|
||||
if (!$validate->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
|
||||
if (AuthModel::create($data)) {
|
||||
Logs::write('增加分组', $data);
|
||||
return true;
|
||||
} else {
|
||||
return '增加失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑分组信息
|
||||
* @param [type] $data 要更新的信息
|
||||
* @return [type] 返回的信息 true 和 错误信息
|
||||
*/
|
||||
public static function edit($data)
|
||||
{
|
||||
$validate = new AuthValidate();
|
||||
|
||||
if (!$validate->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
|
||||
if (AuthModel::update($data)) {
|
||||
Logs::write('编辑分组', $data);
|
||||
return true;
|
||||
} else {
|
||||
return '编辑失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除方法
|
||||
* @param [type] $id 要删除的id
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
$info = AuthModel::get($id);
|
||||
|
||||
if (!$info) {
|
||||
return '数据不存在';
|
||||
} elseif ($info->getAttr('user_count') > 0) {
|
||||
return '分组下有用户,不允许删除';
|
||||
} elseif ($info->save(['status' => -1])) {
|
||||
Logs::write('删除分组', $info);
|
||||
return true;
|
||||
} else {
|
||||
return '删除失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改分组状态
|
||||
* @param [type] $id 分组id
|
||||
* @param [type] $status 分组的状态
|
||||
* @return [type] 返回的信息 true 和 错误信息
|
||||
*/
|
||||
public static function status($id, $status)
|
||||
{
|
||||
$info = AuthModel::get($id);
|
||||
|
||||
if (!$info) {
|
||||
return '分组不存在';
|
||||
} elseif ($info->save(['status' => $status])) {
|
||||
Logs::write('修改分组状态', ['status' => $status]);
|
||||
return true;
|
||||
} else {
|
||||
return '状态修改失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置授权菜单节点
|
||||
* @param [type] $id [description]
|
||||
* @param array $rules [description]
|
||||
*/
|
||||
public static function setAuthRuels($id, $rules = [])
|
||||
{
|
||||
$info = AuthModel::get($id);
|
||||
|
||||
if (!$info) {
|
||||
return '授权组不存在';
|
||||
}
|
||||
if (empty($rules)) {
|
||||
$data['rules'] = '';
|
||||
} else {
|
||||
sort($rules);
|
||||
$data['rules'] = implode(',', $rules);
|
||||
}
|
||||
|
||||
if ($info->save($data)) {
|
||||
Logs::write('设置授权菜单节点', $data);
|
||||
return true;
|
||||
} else {
|
||||
return '设置授权菜单节点失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取组所有授权节点
|
||||
* @param [type] $id 分组id
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function getAuthRules($id)
|
||||
{
|
||||
$map = [
|
||||
'status' => 1,
|
||||
'auth' => 1,
|
||||
];
|
||||
// 获取节点列表
|
||||
$node_list = Db::name('Menu')->where($map)->order('sort asc')->select();
|
||||
$auth_rules = explode(',', AuthModel::where('id', $id)->value('rules'));
|
||||
|
||||
foreach ($node_list as $key => $value) {
|
||||
if (in_array($value['id'], $auth_rules)) {
|
||||
$node_list[$key]['checked'] = "checked";
|
||||
} else {
|
||||
$node_list[$key]['checked'] = "";
|
||||
}
|
||||
}
|
||||
|
||||
return Tree::list2tree($node_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分组内未授权的所有用户
|
||||
* @param [type] $id 分组id
|
||||
* @return [type] 用户ids
|
||||
*/
|
||||
public static function getAuthedUids($id)
|
||||
{
|
||||
return AuthUserModel::where('auth_id', $id)->column('uid') ?: [0];
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加用户
|
||||
* @param [type] $id 分组id
|
||||
* @param array $uids 用户ids
|
||||
*/
|
||||
public static function setAuthUser($id, $uid = [])
|
||||
{
|
||||
$AuthUserModel = new AuthUserModel();
|
||||
if (empty($uid)) {
|
||||
return '授权用户不能是空的';
|
||||
}
|
||||
$list = [];
|
||||
foreach ($uid as $userid) {
|
||||
$list[] = ['auth_id' => $id, 'uid' => $userid];
|
||||
}
|
||||
if ($AuthUserModel->saveAll($list)) {
|
||||
Logs::write('授权用户', ['auth_id' => $id, 'uid' => $uid]);
|
||||
return true;
|
||||
} else {
|
||||
return '授权用户失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除授权
|
||||
* @param [type] $id 分组id
|
||||
* @param [type] $uid 用户id
|
||||
* @return [type]
|
||||
*/
|
||||
public static function removeAuthUser($id, $uid = [])
|
||||
{
|
||||
$map = [
|
||||
'auth_id' => $id,
|
||||
'uid' => ['in', $uid],
|
||||
];
|
||||
|
||||
if (AuthUserModel::where($map)->delete()) {
|
||||
Logs::write('移除授权', ['auth_id' => $id, 'uid' => $uid]);
|
||||
return true;
|
||||
} else {
|
||||
return '移除授权失败';
|
||||
}
|
||||
}
|
||||
}
|
||||
135
application/common/service/Category.php
Normal file
135
application/common/service/Category.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\Category as CategoryModel;
|
||||
use app\common\validate\Category as CategoryValidate;
|
||||
use think\Db;
|
||||
use tools\Tree;
|
||||
|
||||
class Category extends _Init
|
||||
{
|
||||
/**
|
||||
* 树形展示
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function tree()
|
||||
{
|
||||
$map = [
|
||||
'status' => 1,
|
||||
];
|
||||
$field = [
|
||||
'id',
|
||||
'pid',
|
||||
'title' => 'name',
|
||||
'true as spread',
|
||||
];
|
||||
$list = Db::name('Category')->field($field)->where($map)->order('sort asc')->select();
|
||||
$menu = Tree::list2tree($list);
|
||||
return json_encode($menu);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分类列表
|
||||
* @param integer $id 要排查的分类id
|
||||
* @return [type] 返回分类列表
|
||||
*/
|
||||
public static function treeList($id = 0)
|
||||
{
|
||||
$map = [];
|
||||
if ($id) {
|
||||
$map['id'] = ['neq', $id];
|
||||
}
|
||||
|
||||
$menus = Db::name('Category')->where($map)->order('sort asc')->select();
|
||||
$menus = Tree::toFormatTree($menus);
|
||||
$menus = array_merge([0 => ['id' => 0, 'title_show' => '顶级分类']], $menus);
|
||||
return $menus;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加分类
|
||||
* @param [type] $data 分类数据
|
||||
*/
|
||||
public static function add($data)
|
||||
{
|
||||
$validate = new CategoryValidate();
|
||||
|
||||
if (!$validate->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
|
||||
if (CategoryModel::create($data)) {
|
||||
Logs::write('新增分类', $data);
|
||||
return true;
|
||||
} else {
|
||||
return '新曾分类失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑分类
|
||||
* @param [type] $data 编辑分类的数据
|
||||
*/
|
||||
public static function edit($data)
|
||||
{
|
||||
$validate = new CategoryValidate();
|
||||
|
||||
if (!$validate->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
|
||||
if (CategoryModel::update($data)) {
|
||||
Logs::write('编辑分类', $data);
|
||||
return true;
|
||||
} else {
|
||||
return '新增分类失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分类
|
||||
* @param [type] $id 分类id
|
||||
* @return [type] 返回删除的结果 true 和 错误信息
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
if (CategoryModel::where('pid', 'in', $id)->find()) {
|
||||
return $this->error('该分类有下级分类,不允许直接删除');
|
||||
}
|
||||
|
||||
$info = CategoryModel::get($id);
|
||||
if (!$info) {
|
||||
return '数据不存在';
|
||||
} elseif ($info->save(['status' => -1])) {
|
||||
return true;
|
||||
} else {
|
||||
return '删除分类失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置分类状态
|
||||
* @param [type] $id 分类id
|
||||
* @param [type] $status 状态信息 true false
|
||||
* @param [type] $type 设置的字段
|
||||
*/
|
||||
public static function status($id, $status, $type)
|
||||
{
|
||||
$info = CategoryModel::get($id);
|
||||
if (!$info) {
|
||||
return $this->error('数据不存在');
|
||||
} elseif ($info->save([$type => $status])) {
|
||||
Logs::write('修改状态', [$type => $status]);
|
||||
return true;
|
||||
} else {
|
||||
return '设置状态失败';
|
||||
}
|
||||
}
|
||||
}
|
||||
38
application/common/service/City.php
Normal file
38
application/common/service/City.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\City as CityModel;
|
||||
use app\common\model\Province as ProvinceModel;
|
||||
|
||||
class City extends _Init
|
||||
{
|
||||
public static function getData($id)
|
||||
{
|
||||
$list = CityModel::where('province_id', $id)->select();
|
||||
$opt = '';
|
||||
foreach ($list as $key => $val) {
|
||||
$opt .= "<option value='{$val['name']}' ";
|
||||
$opt .= " >{$val['name']}</option>";
|
||||
}
|
||||
echo $opt;
|
||||
}
|
||||
|
||||
public static function getCity($name)
|
||||
{
|
||||
$province = ProvinceModel::where('name', $name)->find();
|
||||
if (!empty($province)) {
|
||||
$list = CityModel::where('province_id', $province->id)->select();
|
||||
return $list;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
112
application/common/service/Config.php
Normal file
112
application/common/service/Config.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\Config as ConfigModel;
|
||||
use app\common\validate\Config as ConfigValidate;
|
||||
|
||||
class Config extends _Init
|
||||
{
|
||||
|
||||
/**
|
||||
* 添加配置项
|
||||
* @param [type] $data 配置数据
|
||||
*/
|
||||
public static function add($data)
|
||||
{
|
||||
$validate = new ConfigValidate();
|
||||
|
||||
if (!$validate->scene('add')->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
|
||||
if (ConfigModel::create($data)) {
|
||||
Logs::write('新增配置', $data);
|
||||
return true;
|
||||
} else {
|
||||
return '新增配置失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改配置
|
||||
* @param [type] $data 配置数据集合
|
||||
* @return [type] 返回的信息 true 和 错误信息
|
||||
*/
|
||||
public static function edit($data)
|
||||
{
|
||||
$validate = new ConfigValidate();
|
||||
|
||||
if (!$validate->scene('edit')->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
|
||||
if (ConfigModel::update($data)) {
|
||||
Logs::write('编辑配置', $data);
|
||||
return true;
|
||||
} else {
|
||||
return '编辑配置失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除配置
|
||||
* @param [type] $id 配置id
|
||||
* @return [type] 返回的信息 true 和 错误信息
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
$info = ConfigModel::get($id);
|
||||
if (!$info) {
|
||||
return '数据不存在';
|
||||
} elseif ($info->save(['status' => -1])) {
|
||||
Logs::write('删除配置', $info);
|
||||
return true;
|
||||
} else {
|
||||
return '删除配置失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置配置状态
|
||||
* @param [type] $id 配置id
|
||||
* @param [type] $status 要设置的状态
|
||||
* @param [type] $type 要设置的字段
|
||||
* @return [type] 返回的信息
|
||||
*/
|
||||
public static function status($id, $status, $type)
|
||||
{
|
||||
$info = ConfigModel::get($id);
|
||||
if (!$info) {
|
||||
return '配置不存在';
|
||||
} elseif ($info->save([$type => $status])) {
|
||||
Logs::write('修改状态', [$type => $status]);
|
||||
return true;
|
||||
} else {
|
||||
return '状态修改失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量编辑配置
|
||||
* @param array $config 编辑的信息
|
||||
* @return
|
||||
*/
|
||||
public static function batchEdit($config)
|
||||
{
|
||||
if ($config && is_array($config)) {
|
||||
foreach ($config as $name => $value) {
|
||||
ConfigModel::update(['value' => $value], ['name' => $name]);
|
||||
}
|
||||
}
|
||||
Logs::write('批量修改配置', $config);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
124
application/common/service/Content.php
Normal file
124
application/common/service/Content.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\Category as CategoryModel;
|
||||
use app\common\model\Content as ContentModel;
|
||||
use app\common\validate\Content as ContentValidate;
|
||||
|
||||
class Content extends _Init
|
||||
{
|
||||
/**
|
||||
* 添加信息
|
||||
* @param [type] $data 文章数据
|
||||
*/
|
||||
public static function create($data)
|
||||
{
|
||||
$validate = new ContentValidate();
|
||||
if (!$validate->scene('add')->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
|
||||
$info = ContentModel::create($data);
|
||||
if ($info) {
|
||||
return true;
|
||||
} else {
|
||||
return '创建文章失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑文章
|
||||
* @param [type] $data 更新的数据
|
||||
* @return [type] 返回 修改的结果
|
||||
*/
|
||||
public static function edit($data)
|
||||
{
|
||||
$validate = new ContentValidate();
|
||||
if (!$validate->scene('add')->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
$info = ContentModel::update($data);
|
||||
if ($info) {
|
||||
return true;
|
||||
} else {
|
||||
return '编辑文章失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改文章状态
|
||||
* @param [type] $id 文章id
|
||||
* @param [type] $status 状态
|
||||
* @return [type] 返回结果
|
||||
*/
|
||||
public static function status($id, $status)
|
||||
{
|
||||
$info = ContentModel::get($id);
|
||||
if (!$info) {
|
||||
return '文章不存在';
|
||||
} elseif ($info->save(['status' => $status])) {
|
||||
Logs::write('修改状态', ['status' => $status]);
|
||||
return true;
|
||||
} else {
|
||||
return '修改状态失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文章
|
||||
* @param [type] $id 要删除的文章id
|
||||
* @return [type] 返回 结果
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
$info = ContentModel::get($id);
|
||||
if (!$info) {
|
||||
return '文章不存在';
|
||||
} elseif ($info->save(['status' => -1])) {
|
||||
return true;
|
||||
} else {
|
||||
return '删除失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据model活动分类id
|
||||
* @param [type] $name 模型名称
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function getCategoryIds($name)
|
||||
{
|
||||
$map = [
|
||||
'status' => 1,
|
||||
'model' => $name,
|
||||
];
|
||||
$list = CategoryModel::where($map)->column('id');
|
||||
|
||||
if (!empty($list)) {
|
||||
return implode(',', $list);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分类列表
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function categoryList($name)
|
||||
{
|
||||
$map = [
|
||||
'status' => 1,
|
||||
'model' => $name,
|
||||
];
|
||||
return CategoryModel::where($map)->order('sort asc')->select();
|
||||
}
|
||||
|
||||
}
|
||||
182
application/common/service/Database.php
Normal file
182
application/common/service/Database.php
Normal file
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
use think\Config;
|
||||
use think\Loader;
|
||||
use think\Session;
|
||||
use tools\Format;
|
||||
|
||||
class Database extends _Init
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取表信息
|
||||
* @return array
|
||||
*/
|
||||
public static function getTables()
|
||||
{
|
||||
$list = array_map('array_change_key_case', Loader::db()->query('SHOW TABLE STATUS'));
|
||||
foreach ($list as $key => $value) {
|
||||
$list[$key]['data_length'] = Format::byte($value['data_length']);
|
||||
$list[$key]['index_length'] = Format::byte($value['index_length']);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 备份数据库
|
||||
* @param [type] $tables [description]
|
||||
* @param [type] $id [description]
|
||||
* @param [type] $start [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function backup($tables = null, $id = null, $start = null)
|
||||
{
|
||||
if (IS_POST && !empty($tables) && is_array($tables)) {
|
||||
//初始化
|
||||
$config = Config::get('backdata');
|
||||
// 检查是否有正在执行的任务
|
||||
if (!is_writeable($config['path'])) {
|
||||
return '备份目录不存在或不可写,请检查后重试!';
|
||||
}
|
||||
$lock = "{$config['path']}backup.lock";
|
||||
if (is_file($lock)) {
|
||||
return '检测到一个任务正在执行,请稍后再试!';
|
||||
} else {
|
||||
file_put_contents($lock, time()); //创建锁文件
|
||||
}
|
||||
|
||||
Session::set('backup_config', $config);
|
||||
//生成备份文件信息
|
||||
$file = array(
|
||||
'name' => date('Ymd-His', time()),
|
||||
'part' => 1,
|
||||
);
|
||||
Session::set('backup_file', $file);
|
||||
//缓存要备份的表
|
||||
Session::set('backup_tables', $tables);
|
||||
//创建备份文件
|
||||
$Database = new \tools\Database($file, $config);
|
||||
if (false !== $Database->create()) {
|
||||
Logs::write('备份数据库', ['table' => $tables]);
|
||||
return [
|
||||
'msg' => '初始化成功!',
|
||||
'data' => ['id' => 0, 'start' => 0],
|
||||
];
|
||||
} else {
|
||||
return '初始化失败,备份文件创建失败!';
|
||||
}
|
||||
} elseif (IS_GET && is_numeric($id) && is_numeric($start)) {
|
||||
//备份数据
|
||||
$tables = Session::get('backup_tables');
|
||||
//备份指定表
|
||||
$Database = new \tools\Database(Session::get('backup_file'), Session::get('backup_config'));
|
||||
$start = $Database->backup($tables[$id], $start);
|
||||
if (false === $start) {
|
||||
return '备份出错!';
|
||||
} elseif (0 === $start) {
|
||||
//下一表
|
||||
if (isset($tables[++$id])) {
|
||||
return [
|
||||
'msg' => '备份完成!',
|
||||
'data' => ['id' => $id, 'start' => 0],
|
||||
];
|
||||
} else {
|
||||
//备份完成,清空缓存
|
||||
unlink(Session::get('backup_config.path') . 'backup.lock');
|
||||
Session::delete('backup_tables');
|
||||
Session::delete('backup_file');
|
||||
Session::delete('backup_config');
|
||||
return [
|
||||
'msg' => '备份完成!',
|
||||
'data' => '',
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$rate = floor(100 * ($start[0] / $start[1]));
|
||||
return [
|
||||
'msg' => '"正在备份..({$rate}%)"',
|
||||
'data' => ['id' => $id, 'start' => $start[0]],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [del description]
|
||||
* @param [type] $time [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function del($time)
|
||||
{
|
||||
$path = [];
|
||||
if (is_array($time)) {
|
||||
foreach ($time as $value) {
|
||||
$name = date('Ymd-His', $value) . '-*.sql*';
|
||||
$file = Config::get('backdata.path') . $name;
|
||||
$path = array_merge($path, glob($file));
|
||||
}
|
||||
} else {
|
||||
$name = date('Ymd-His', $time) . '-*.sql*';
|
||||
$file = Config::get('backdata.path') . $name;
|
||||
$path = glob($file);
|
||||
}
|
||||
try {
|
||||
array_map("unlink", $path);
|
||||
Logs::write('删除备份文件', ['files' => $path]);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
return '备份文件删除失败,请检查权限!';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 备份文件卷列表
|
||||
* @return array
|
||||
*/
|
||||
public static function backupList()
|
||||
{
|
||||
$path = Config::get('backdata.path');
|
||||
|
||||
$list = [];
|
||||
if (is_dir($path)) {
|
||||
$flag = \FilesystemIterator::KEY_AS_FILENAME;
|
||||
$glob = new \FilesystemIterator($path, $flag);
|
||||
$list = [];
|
||||
foreach ($glob as $name => $file) {
|
||||
if (preg_match('/^\d{8,8}-\d{6,6}-\d+\.sql(?:\.gz)?$/', $name)) {
|
||||
$name = sscanf($name, '%4s%2s%2s-%2s%2s%2s-%d');
|
||||
$date = "{$name[0]}-{$name[1]}-{$name[2]}";
|
||||
$time = "{$name[3]}:{$name[4]}:{$name[5]}";
|
||||
$part = $name[6];
|
||||
if (isset($list["{$date} {$time}"])) {
|
||||
$info = $list["{$date} {$time}"];
|
||||
$info['part'] = max($info['part'], $part);
|
||||
$info['size'] += $file->getSize();
|
||||
} else {
|
||||
$info['part'] = $part;
|
||||
$info['size'] = $file->getSize();
|
||||
}
|
||||
$extension = strtoupper(pathinfo($file->getFilename(), PATHINFO_EXTENSION));
|
||||
$info['compress'] = ($extension === 'SQL') ? '-' : $extension;
|
||||
$info['time'] = strtotime("{$date} {$time}");
|
||||
$list["{$date} {$time}"] = $info;
|
||||
}
|
||||
krsort($list);
|
||||
}
|
||||
}
|
||||
array_walk($list, function ($val, $key) use (&$list) {
|
||||
$list[$key]['size'] = Format::byte($val['size']);
|
||||
});
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
86
application/common/service/Direct.php
Normal file
86
application/common/service/Direct.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\Direct as DirectModel;
|
||||
use app\common\validate\Direct as DirectValidate;
|
||||
|
||||
class Direct extends _Init
|
||||
{
|
||||
/**
|
||||
* 添加信息
|
||||
* @param [type] $data 文章数据
|
||||
*/
|
||||
public static function create($data)
|
||||
{
|
||||
$validate = new DirectValidate();
|
||||
if (!$validate->scene('add')->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
$info = DirectModel::create($data);
|
||||
if ($info) {
|
||||
return true;
|
||||
} else {
|
||||
return '创建文章失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑文章
|
||||
* @param [type] $data 更新的数据
|
||||
* @return [type] 返回 修改的结果
|
||||
*/
|
||||
public static function edit($data)
|
||||
{
|
||||
$validate = new DirectValidate();
|
||||
if (!$validate->scene('add')->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
$info = DirectModel::update($data);
|
||||
if ($info) {
|
||||
return true;
|
||||
} else {
|
||||
return '编辑文章失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改文章状态
|
||||
* @param [type] $id 文章id
|
||||
* @param [type] $status 状态
|
||||
* @return [type] 返回结果
|
||||
*/
|
||||
public static function status($id, $status)
|
||||
{
|
||||
$info = DirectModel::get($id);
|
||||
if (!$info) {
|
||||
return '文章不存在';
|
||||
} elseif ($info->save(['status' => $status])) {
|
||||
Logs::write('修改状态', ['status' => $status]);
|
||||
return true;
|
||||
} else {
|
||||
return '修改状态失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文章
|
||||
* @param [type] $id 要删除的文章id
|
||||
* @return [type] 返回 结果
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
$model = new DirectModel();
|
||||
if ($model->destroy($id)) {
|
||||
return true;
|
||||
} else {
|
||||
return '删除失败';
|
||||
}
|
||||
}
|
||||
}
|
||||
107
application/common/service/Experience.php
Normal file
107
application/common/service/Experience.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\Experience as ExperienceModel;
|
||||
use app\common\model\ExperienceTags as ExperienceTagsModel;
|
||||
use app\common\validate\Experience as ExperienceValidate;
|
||||
|
||||
class Experience extends _Init
|
||||
{
|
||||
|
||||
/**
|
||||
* 点赞
|
||||
* @param [type] $uid [description]
|
||||
* @param [type] $id [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function tags($uid, $id)
|
||||
{
|
||||
$ExperienceInfo = ExperienceModel::get($id);
|
||||
if (!$ExperienceInfo) {
|
||||
return '要评论的信息不存在';
|
||||
} elseif ($ExperienceInfo->status != 1) {
|
||||
return '信息被禁用';
|
||||
}
|
||||
$map = [
|
||||
'experience_id' => $id,
|
||||
'uid' => $uid,
|
||||
];
|
||||
$comment = ExperienceTagsModel::where($map)->find();
|
||||
if ($comment) {
|
||||
return '不能重复点赞';
|
||||
}
|
||||
$data = [
|
||||
'experience_id' => $id,
|
||||
'uid' => $uid,
|
||||
];
|
||||
if (ExperienceTagsModel::create($data)) {
|
||||
$ExperienceInfo->setInc('tags');
|
||||
return true;
|
||||
} else {
|
||||
return '点赞失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发表评论
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function comment($pid, $uid, $content)
|
||||
{
|
||||
$ExperienceInfo = ExperienceModel::get($pid);
|
||||
if (!$ExperienceInfo) {
|
||||
return '要评论的信息不存在';
|
||||
} elseif ($ExperienceInfo->status != 1) {
|
||||
return '信息被禁用';
|
||||
}
|
||||
$data = [
|
||||
'pid' => $pid,
|
||||
'uid' => $uid,
|
||||
'content' => $content,
|
||||
];
|
||||
$validate = new ExperienceValidate();
|
||||
if (!$validate->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
if (ExperienceModel::create($data)) {
|
||||
return true;
|
||||
} else {
|
||||
return '评论失败';
|
||||
}
|
||||
}
|
||||
|
||||
public static function add($data, $uid)
|
||||
{
|
||||
$data['uid'] = $uid;
|
||||
$validate = new ExperienceValidate();
|
||||
if (!$validate->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
if (ExperienceModel::create($data)) {
|
||||
return true;
|
||||
} else {
|
||||
return '发布失败';
|
||||
}
|
||||
}
|
||||
|
||||
public static function del($id, $uid)
|
||||
{
|
||||
$ExperienceInfo = ExperienceModel::get($id);
|
||||
if (!$ExperienceInfo) {
|
||||
return '没有这条信息';
|
||||
} else if ($ExperienceInfo->uid != $uid) {
|
||||
return '这个不是您的经验信息,您不能删除。';
|
||||
} else if ($ExperienceInfo->save(['status' => -1])) {
|
||||
return true;
|
||||
} else {
|
||||
return '删除失败';
|
||||
}
|
||||
}
|
||||
}
|
||||
87
application/common/service/Help.php
Normal file
87
application/common/service/Help.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\Help as HelpModel;
|
||||
use app\common\validate\Help as HelpValidate;
|
||||
|
||||
class Help extends _Init
|
||||
{
|
||||
/**
|
||||
* 添加信息
|
||||
* @param [type] $data 文章数据
|
||||
*/
|
||||
public static function create($data)
|
||||
{
|
||||
$validate = new HelpValidate();
|
||||
if (!$validate->scene('add')->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
$info = HelpModel::create($data);
|
||||
if ($info) {
|
||||
return true;
|
||||
} else {
|
||||
return '创建文章失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑文章
|
||||
* @param [type] $data 更新的数据
|
||||
* @return [type] 返回 修改的结果
|
||||
*/
|
||||
public static function edit($data)
|
||||
{
|
||||
$validate = new HelpValidate();
|
||||
if (!$validate->scene('add')->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
$info = HelpModel::update($data);
|
||||
if ($info) {
|
||||
return true;
|
||||
} else {
|
||||
return '编辑文章失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改文章状态
|
||||
* @param [type] $id 文章id
|
||||
* @param [type] $status 状态
|
||||
* @return [type] 返回结果
|
||||
*/
|
||||
public static function status($id, $status)
|
||||
{
|
||||
$info = HelpModel::get($id);
|
||||
if (!$info) {
|
||||
return '文章不存在';
|
||||
} elseif ($info->save(['status' => $status])) {
|
||||
Logs::write('修改状态', ['status' => $status]);
|
||||
return true;
|
||||
} else {
|
||||
return '修改状态失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文章
|
||||
* @param [type] $id 要删除的文章id
|
||||
* @return [type] 返回 结果
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
$model = new HelpModel();
|
||||
if ($model->destroy($id)) {
|
||||
return true;
|
||||
} else {
|
||||
return '删除失败';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
30
application/common/service/Logs.php
Normal file
30
application/common/service/Logs.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\Logs as LogsModel;
|
||||
|
||||
class Logs extends _Init
|
||||
{
|
||||
/**
|
||||
* 写入日志
|
||||
* @param string $logs 日志内容
|
||||
* @param array $data 操作数据
|
||||
* @param boolean|integer $uid boolean 自动记录当前用户 integer 指定用户UID
|
||||
*/
|
||||
public static function write($logs, $data = [], $uid = true)
|
||||
{
|
||||
$save = [
|
||||
'uid' => $uid === true ? Member::isLogin() : $uid,
|
||||
'logs' => $logs,
|
||||
'datas' => $data,
|
||||
];
|
||||
LogsModel::create($save);
|
||||
}
|
||||
}
|
||||
379
application/common/service/Member.php
Normal file
379
application/common/service/Member.php
Normal file
@@ -0,0 +1,379 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\Member as MemberModel;
|
||||
use app\common\model\MemberInfo as MemberInfoModel;
|
||||
use app\common\model\Template as TemplateModel;
|
||||
use app\common\service\Score as ScoreService;
|
||||
use app\common\validate\Member as MemberValidate;
|
||||
use app\common\validate\MemberInfo as MemberInfoValidate;
|
||||
use think\Config;
|
||||
use think\Request;
|
||||
use think\Session;
|
||||
use tools\Crypt;
|
||||
|
||||
class Member extends _Init
|
||||
{
|
||||
/**
|
||||
* 获取用户信息
|
||||
* @param integer 用户id
|
||||
* @return object
|
||||
*/
|
||||
public static function info($uid)
|
||||
{
|
||||
return MemberInfoModel::get($uid);
|
||||
}
|
||||
|
||||
public static function isBind($uid)
|
||||
{
|
||||
$user = MemberModel::find($uid);
|
||||
if (\tools\Verify::isMobilePhone($user->username)) {
|
||||
return true;
|
||||
} else {
|
||||
return '用户尚未绑定手机号';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑用户资料
|
||||
* @param integer 用户id
|
||||
* @param array 更新的数据
|
||||
* @param string 数据验证的名称
|
||||
* @return boolean|string
|
||||
*/
|
||||
public static function editInfo($uid, $data, $scene = '')
|
||||
{
|
||||
$validate = new MemberInfoValidate();
|
||||
|
||||
if (!$validate->scene($scene)->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
|
||||
$MemberInfo = self::info($uid);
|
||||
|
||||
if (MemberInfoModel::update($data, ['uid' => $uid])) {
|
||||
if (empty($MemberInfo->$scene)) {
|
||||
ScoreService::setting(UID, $scene);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return '更新失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加 用户资料
|
||||
* @param [type] $user 添加的信息
|
||||
*/
|
||||
private static function createInfo($user)
|
||||
{
|
||||
$data = [
|
||||
'uid' => $user->id,
|
||||
'mobile' => $user->username,
|
||||
];
|
||||
MemberInfoModel::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册一个用户
|
||||
* @param string $username 用户名
|
||||
* @param string $password 密码
|
||||
* @param integer $status 初始状态
|
||||
* @return [type] 返回结果
|
||||
*/
|
||||
public static function register($username, $password, $status = null, $pid = 0, $extends = [])
|
||||
{
|
||||
$status = is_numeric($status) ?: (Config::get('new_member_status') ?: 0);
|
||||
$data = [
|
||||
'username' => $username,
|
||||
'password' => $password,
|
||||
'status' => $status,
|
||||
'pid' => $pid,
|
||||
];
|
||||
$validate = new MemberValidate();
|
||||
|
||||
if (!$validate->scene('register')->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
|
||||
if (is_array($extends) && !empty($extends)) {
|
||||
$data = array_merge($data, $extends);
|
||||
}
|
||||
|
||||
$user = MemberModel::create($data);
|
||||
if ($user) {
|
||||
Logs::write('注册用户', $data);
|
||||
// 自动的注册一个用户资料
|
||||
self::createInfo($user);
|
||||
//增加积分
|
||||
Score::register($user->id);
|
||||
if (!empty($pid)) {
|
||||
Score::invite($pid);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return '注册失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
* @param integer $uid 用户编号
|
||||
* @param string $old 旧密码
|
||||
* @param string $new 新密码
|
||||
* @return [type]
|
||||
*/
|
||||
public static function changePassword($uid, $old, $new, $repass)
|
||||
{
|
||||
$data = [
|
||||
'uid' => $uid,
|
||||
'oldpass' => $old,
|
||||
'newpass' => $new,
|
||||
'repass' => $repass,
|
||||
];
|
||||
|
||||
$validate = new MemberValidate();
|
||||
if (!$validate->scene('changepass')->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
|
||||
return self::updatePassword($uid, $new);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新密码
|
||||
* @param [type] $uid 用户id
|
||||
* @param [type] $password 更新的密码
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function updatePassword($uid, $password)
|
||||
{
|
||||
$data = [
|
||||
'password' => $password,
|
||||
];
|
||||
|
||||
$validate = new MemberValidate();
|
||||
|
||||
if (!$validate->scene('updatepass')->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
|
||||
$user = MemberModel::update($data, ['id' => $uid]);
|
||||
if ($user) {
|
||||
Logs::write('重置密码');
|
||||
return true;
|
||||
} else {
|
||||
return '重置密码失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
* @param [type] $username 用户民
|
||||
* @param [type] $password 密码
|
||||
* @return [type] 登录的结果
|
||||
*/
|
||||
public static function login($username, $password)
|
||||
{
|
||||
$data = [
|
||||
'username' => $username,
|
||||
'password' => $password,
|
||||
];
|
||||
|
||||
$validate = new MemberValidate();
|
||||
if (!$validate->scene('login')->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
|
||||
$user = MemberModel::where('username', $username)->find();
|
||||
|
||||
if (!$user) {
|
||||
return '用户不存在';
|
||||
} elseif ($user->status != 1) {
|
||||
return '用户被禁用';
|
||||
} elseif ($user->password != Crypt::uMd5($password)) {
|
||||
return '密码错误';
|
||||
} else {
|
||||
// 设置session
|
||||
$auth = [
|
||||
'uid' => $user->id,
|
||||
'username' => $user->username,
|
||||
'last_time' => $user->last_time,
|
||||
'last_ip' => $user->last_ip,
|
||||
];
|
||||
|
||||
Session::set('user_auth', $auth);
|
||||
Session::set('user_auth_sign', Crypt::dataAuthSign($auth));
|
||||
// 保存登录记录
|
||||
$save = [
|
||||
'login' => $user->login + 1,
|
||||
'last_time' => time(),
|
||||
'last_ip' => Request::instance()->ip(),
|
||||
];
|
||||
$user->save($save);
|
||||
Logs::write('用户登录成功');
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据openid 登录
|
||||
* @param [type] $openid [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function openid_login($openid)
|
||||
{
|
||||
$user = MemberModel::where('openid', $openid)->find();
|
||||
if (!$user) {
|
||||
return '用户不存在';
|
||||
} elseif ($user->status != 1) {
|
||||
return '用户被禁用';
|
||||
} else {
|
||||
// 设置session
|
||||
$auth = [
|
||||
'uid' => $user->id,
|
||||
'username' => $user->username,
|
||||
'last_time' => $user->last_time,
|
||||
'last_ip' => $user->last_ip,
|
||||
];
|
||||
|
||||
Session::set('user_auth', $auth);
|
||||
Session::set('user_auth_sign', Crypt::dataAuthSign($auth));
|
||||
// 保存登录记录
|
||||
$save = [
|
||||
'login' => $user->login + 1,
|
||||
'last_time' => time(),
|
||||
'last_ip' => Request::instance()->ip(),
|
||||
];
|
||||
$user->save($save);
|
||||
Logs::write('用户登录成功');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出当前账户
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function logout()
|
||||
{
|
||||
Logs::write('注销登录');
|
||||
|
||||
Session::delete('user_auth');
|
||||
Session::delete('user_auth_sign');
|
||||
Session::clear();
|
||||
Session::destroy();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户状态
|
||||
* @param [type] $uid 要修改的用户id
|
||||
* @param [type] $status 要修改的状态 正常 禁用
|
||||
*/
|
||||
public static function status($uid, $status)
|
||||
{
|
||||
$user = MemberModel::get($uid);
|
||||
|
||||
if (!$user) {
|
||||
return '用户不存在';
|
||||
} elseif ($user->save(['status' => $status])) {
|
||||
Logs::write('修改状态', ['status' => $status]);
|
||||
return true;
|
||||
} else {
|
||||
return '状态修改失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户登录判断
|
||||
* @return boolean 返回用户id 失败返回0
|
||||
*/
|
||||
public static function isLogin()
|
||||
{
|
||||
$user = Session::get('user_auth');
|
||||
if (empty($user)) {
|
||||
return 0;
|
||||
} else {
|
||||
return Session::get('user_auth_sign') == Crypt::dataAuthSign($user) ? $user['uid'] : 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换模版
|
||||
* @param [type] $uid [description]
|
||||
* @param [type] $tpl [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function changeTpl($uid, $tpl)
|
||||
{
|
||||
if (!TemplateModel::get($tpl)) {
|
||||
return '模板不存在';
|
||||
}
|
||||
if (MemberInfoModel::update(['index_tpl' => $tpl], ['uid' => $uid])) {
|
||||
return true;
|
||||
} else {
|
||||
return '操作失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定微信
|
||||
* @param [type] $uid [description]
|
||||
* @param [type] $data [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function bindWechat($uid, $data)
|
||||
{
|
||||
$validate = new MemberValidate();
|
||||
|
||||
if (!$validate->scene('openid')->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
$MemberInfo = self::info($uid);
|
||||
$scene = 'openid';
|
||||
if (MemberModel::update($data, ['id' => $uid])) {
|
||||
if (empty($MemberInfo->$scene)) {
|
||||
ScoreService::setting(UID, $scene);
|
||||
}
|
||||
return true;
|
||||
|
||||
} else {
|
||||
return '更新失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解除绑定
|
||||
* @param [type] $uid [description]
|
||||
* @param [type] $data [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function unBindWechat($uid, $openid)
|
||||
{
|
||||
$ids = MemberModel::where('openid', $openid)->column('id');
|
||||
$data = [
|
||||
'openid' => '',
|
||||
];
|
||||
|
||||
$map = [
|
||||
'id' => ['in', $ids],
|
||||
];
|
||||
|
||||
if (MemberModel::update($data, $map)) {
|
||||
return true;
|
||||
} else {
|
||||
return '解除绑定失败';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
67
application/common/service/MemberInfo.php
Normal file
67
application/common/service/MemberInfo.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\MemberInfo as MemberInfoModel;
|
||||
|
||||
class MemberInfo extends _Init
|
||||
{
|
||||
|
||||
public static function show($uid)
|
||||
{
|
||||
$info = MemberInfoModel::get($uid);
|
||||
if (!$info) {
|
||||
return [];
|
||||
}
|
||||
if ($info->is_vip == 1) {
|
||||
return $info;
|
||||
} else {
|
||||
return [
|
||||
'nickname' => self::hideSub($info->nickname, 1),
|
||||
'position' => $info->position ?: '未设置',
|
||||
'mobile' => self::hideSub($info->mobile, 4),
|
||||
'qq' => self::hideSub($info->qq),
|
||||
'wechat' => self::hideSub($info->wechat),
|
||||
'province' => self::hideSub($info->province),
|
||||
'city' => self::hideSub($info->city),
|
||||
'avatar' => $info->avatar,
|
||||
'is_vip' => $info->is_vip,
|
||||
'uid' => $info->uid,
|
||||
'qrcode' => $info->qrcode,
|
||||
'index_tpl' => $info->index_tpl,
|
||||
'click' => $info->click,
|
||||
'tags' => $info->tags,
|
||||
'email' => self::hideSub($info->email),
|
||||
'signature' => $info->signature,
|
||||
'message_count' => $info->message_count,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏后半段的字符串
|
||||
* @param [type] $str [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
private static function hideSub($str, $len = 0)
|
||||
{
|
||||
if (empty($str)) {
|
||||
return '未设置';
|
||||
}
|
||||
$leng = mb_strlen($str);
|
||||
if (!empty($len)) {
|
||||
// $pre = ceil($len / 2);
|
||||
$ext = $leng - $len;
|
||||
return mb_substr($str, 0, $len) . str_repeat("*", $ext);
|
||||
} else {
|
||||
$len = $leng;
|
||||
return str_repeat('*', $len ?: 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
60
application/common/service/MemberList.php
Normal file
60
application/common/service/MemberList.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\MemberList as MemberListModel;
|
||||
use app\common\validate\MemberList as MemberListValidate;
|
||||
|
||||
class MemberList extends _Init
|
||||
{
|
||||
/**
|
||||
* 添加信息
|
||||
* @param [type] $data 文章数据
|
||||
*/
|
||||
public static function create($data, $uid)
|
||||
{
|
||||
$validate = new MemberListValidate();
|
||||
if (!$validate->scene('add')->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
$info = MemberListModel::create($data);
|
||||
if ($info) {
|
||||
return true;
|
||||
} else {
|
||||
return '创建报单失败';
|
||||
}
|
||||
}
|
||||
|
||||
public static function edit($data)
|
||||
{
|
||||
$validate = new MemberListValidate();
|
||||
if (!$validate->scene('add')->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
$info = MemberListModel::update($data);
|
||||
if ($info) {
|
||||
return true;
|
||||
} else {
|
||||
return '编辑失败';
|
||||
}
|
||||
}
|
||||
|
||||
public static function del($id)
|
||||
{
|
||||
$info = MemberListModel::get($id);
|
||||
if (!$info) {
|
||||
return '此人不存在';
|
||||
} elseif ($info->save(['status' => '-1'])) {
|
||||
return true;
|
||||
} else {
|
||||
return '删除失败';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
169
application/common/service/Menu.php
Normal file
169
application/common/service/Menu.php
Normal file
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\Auth as AuthModel;
|
||||
use app\common\model\AuthUser as AuthUserModel;
|
||||
use app\common\model\Menu as MenuModel;
|
||||
use app\common\validate\Menu as MenuValidate;
|
||||
use think\Config;
|
||||
use think\Db;
|
||||
use tools\Tree;
|
||||
|
||||
class Menu extends _Init
|
||||
{
|
||||
|
||||
/**
|
||||
* 树形展示
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function tree()
|
||||
{
|
||||
$map = [
|
||||
'status' => 1,
|
||||
'hide' => 0,
|
||||
];
|
||||
$field = [
|
||||
'id',
|
||||
'pid',
|
||||
'title' => 'name',
|
||||
"case when pid = 0 then true else false end" => 'spread',
|
||||
];
|
||||
$list = Db::name('Menu')->field($field)->where($map)->order('sort asc')->select();
|
||||
$menu = Tree::list2tree($list);
|
||||
return json_encode($menu);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示菜单
|
||||
* 下一步增加权限管理
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function show($uid)
|
||||
{
|
||||
$map = [
|
||||
'status' => 1,
|
||||
'hide' => 0,
|
||||
'pid' => 0,
|
||||
];
|
||||
|
||||
if (!in_array($uid, Config::get('administrator'))) {
|
||||
$authId = AuthUserModel::where('uid', $uid)->column('auth_id');
|
||||
|
||||
if (!empty($authId)) {
|
||||
$rules = AuthModel::where('id', 'in', $authId)->column('rules');
|
||||
$rules = implode($rules, ',');
|
||||
$rules = explode(',', $rules);
|
||||
$rules = array_unique($rules);
|
||||
$map['id'] = ['in', $rules];
|
||||
} else {
|
||||
// return null;
|
||||
// $map = [];
|
||||
}
|
||||
}
|
||||
$field = [
|
||||
'id',
|
||||
'title',
|
||||
'url' => 'href',
|
||||
'icon',
|
||||
];
|
||||
$list = Db::name('Menu')->field($field)->where($map)->order('sort asc')->select();
|
||||
|
||||
foreach ($list as $key => $value) {
|
||||
if ($key == 0) {
|
||||
$list[$key]['spread'] = true;
|
||||
}
|
||||
$map = [
|
||||
'status' => 1,
|
||||
'hide' => 0,
|
||||
'pid' => $value['id'],
|
||||
];
|
||||
$list[$key]['children'] = Db::name('Menu')->field($field)->where($map)->order('sort asc')->select();
|
||||
}
|
||||
return json_encode($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增菜单
|
||||
* @param [type] $data [description]
|
||||
*/
|
||||
public static function add($data)
|
||||
{
|
||||
$validate = new MenuValidate();
|
||||
|
||||
if (!$validate->scene('add')->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
|
||||
if (MenuModel::create($data)) {
|
||||
Logs::write('新增菜单', $data);
|
||||
return true;
|
||||
} else {
|
||||
return '新增菜单失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑菜单
|
||||
* @param [type] $data 需要编辑的数据
|
||||
* @return [type] 成功返回 true 失败返回错误信息
|
||||
*/
|
||||
public static function edit($data)
|
||||
{
|
||||
$validate = new MenuValidate();
|
||||
|
||||
if (!$validate->scene('edit')->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
|
||||
if (MenuModel::update($data)) {
|
||||
Logs::write('编辑菜单', $data);
|
||||
return true;
|
||||
} else {
|
||||
return '编辑菜单失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
* @param [type] $id 要删除的菜单id
|
||||
* @return [type] 成功返回 true 失败返回错误信息
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
if (MenuModel::where('pid', 'in', $id)->find()) {
|
||||
return $this->error('该菜单有下级菜单,不允许直接删除');
|
||||
}
|
||||
if (MenuModel::destroy($id)) {
|
||||
Logs::write('删除菜单', $id);
|
||||
return true;
|
||||
} else {
|
||||
return '删除菜单失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置菜单状态
|
||||
* @param [type] $id 要设置的id
|
||||
* @param [type] $status 要设置的状态
|
||||
* @param [type] $type 要设置的字段
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function status($id, $status, $type)
|
||||
{
|
||||
$info = MenuModel::get($id);
|
||||
if (!$info) {
|
||||
return '菜单不存在';
|
||||
} elseif ($info->save([$type => $status])) {
|
||||
return true;
|
||||
} else {
|
||||
return '设置菜单状态失败';
|
||||
}
|
||||
}
|
||||
}
|
||||
172
application/common/service/Message.php
Normal file
172
application/common/service/Message.php
Normal file
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\Member as MemberModel;
|
||||
use app\common\model\MemberInfo as MemberInfoModel;
|
||||
use app\common\model\Message as MessageModel;
|
||||
use app\common\validate\Message as MessageValidate;
|
||||
use cjango\Wechat;
|
||||
use think\Cache;
|
||||
use think\Config;
|
||||
|
||||
class Message extends _Init
|
||||
{
|
||||
public static function send($data, $uid)
|
||||
{
|
||||
if ($uid == $data['to_uid']) {
|
||||
return '不能自己给自己留言';
|
||||
}
|
||||
|
||||
$data['from_uid'] = $uid;
|
||||
|
||||
$validate = new MessageValidate();
|
||||
if (!$validate->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
|
||||
if (MessageModel::create($data)) {
|
||||
return true;
|
||||
} else {
|
||||
return '添加失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 点赞
|
||||
* @param [type] $uid [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function tags($uid)
|
||||
{
|
||||
$MemberInfo = MemberInfoModel::get($uid);
|
||||
if (!$MemberInfo) {
|
||||
return '没有这个人';
|
||||
}
|
||||
if ($MemberInfo->setInc('tags')) {
|
||||
return true;
|
||||
} else {
|
||||
return '点赞失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param [type] $uid [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function getList($uid)
|
||||
{
|
||||
return MessageModel::where('to_uid', $uid)->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除留言
|
||||
* @param [type] $id [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
|
||||
$info = MessageModel::get($id);
|
||||
if (!$info) {
|
||||
return '没有这条留言';
|
||||
} elseif ($info->delete()) {
|
||||
return true;
|
||||
} else {
|
||||
return '删除失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送积分变更消息
|
||||
* @param [type] $no
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function addScoreMessage($ruleInfo, $MemberInfo, $remark)
|
||||
{
|
||||
self::initWechat();
|
||||
$Member = MemberModel::get($MemberInfo->uid);
|
||||
$openid = $Member->openid;
|
||||
if (empty($openid)) {
|
||||
die();
|
||||
}
|
||||
//发送给客户
|
||||
$msgdata = [
|
||||
'first' => [
|
||||
'value' => '您好,您的会员积分信息有了新的变更',
|
||||
],
|
||||
'keyword1' => [
|
||||
'value' => $MemberInfo->nickname,
|
||||
],
|
||||
'keyword2' => [
|
||||
'value' => $Member->username,
|
||||
],
|
||||
'keyword3' => [
|
||||
'value' => $remark . $ruleInfo->score . ' 积分',
|
||||
],
|
||||
'keyword4' => [
|
||||
'value' => $MemberInfo->score,
|
||||
],
|
||||
'remark' => [
|
||||
'value' => '如有疑问请联系客服',
|
||||
],
|
||||
];
|
||||
$res = Wechat\Template::send($openid, 'q4Hv3qfG7a_2sqOPXd99vc9Z5M33ri98Gp5pgUNEk-U', $msgdata);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送开通会员消息
|
||||
* @param [type] $ruleInfo [description]
|
||||
* @param [type] $MemberInfo [description]
|
||||
* @param [type] $remark [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function openvip($MemberInfo)
|
||||
{
|
||||
self::initWechat();
|
||||
//发送给客户
|
||||
$msgdata = [
|
||||
'first' => [
|
||||
'value' => '您好,您开通会员成功.',
|
||||
],
|
||||
'keyword1' => [
|
||||
'value' => date("Y-m-d H:i:s"),
|
||||
],
|
||||
'keyword2' => [
|
||||
'value' => '点击查看详情',
|
||||
],
|
||||
'remark' => [
|
||||
'value' => '如有疑问请联系客服',
|
||||
],
|
||||
];
|
||||
$res = Wechat\Template::send($openid, 'frAafbX_CaZgtlGGleNHH6o8PdH3ESqMU05SaJPJa0c', $msgdata, url('vip/index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化微信
|
||||
* @param [type] $config [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function initWechat()
|
||||
{
|
||||
$config = Config::get('wechat_config');
|
||||
$token = Cache::get('wechat_access_token');
|
||||
// 检测TOKEN是否过期
|
||||
if (!$token) {
|
||||
$token = Wechat\Token::get();
|
||||
Cache::set('wechat_access_token', $token, 7000);
|
||||
$config['access_token'] = $token;
|
||||
} else {
|
||||
$config['access_token'] = $token;
|
||||
}
|
||||
Wechat::instance($config, true);
|
||||
}
|
||||
|
||||
}
|
||||
197
application/common/service/Score.php
Normal file
197
application/common/service/Score.php
Normal file
@@ -0,0 +1,197 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\Member as MemberModel;
|
||||
use app\common\model\MemberInfo as MemberInfoModel;
|
||||
use app\common\model\Score as ScoreModel;
|
||||
use app\common\model\ScoreRules as ScoreRulesModel;
|
||||
use app\common\model\VipOrder as VipOrderModel;
|
||||
use tools\Time;
|
||||
|
||||
class Score extends _Init
|
||||
{
|
||||
/**
|
||||
* 注册赠送积分
|
||||
* @param [type] $uid [description]
|
||||
* @param [type] $remark [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function register($uid)
|
||||
{
|
||||
$ruleInfo = self::getRule('register');
|
||||
$MemberInfo = MemberInfoModel::where('uid', $uid)->find();
|
||||
|
||||
if ($ruleInfo->status == 1) {
|
||||
self::addScore($ruleInfo, $MemberInfo, '注册赠送');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置信息
|
||||
* @param [type] $uid [description]
|
||||
* @param [type] $name [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function setting($uid, $name)
|
||||
{
|
||||
$title = [
|
||||
'headimgurl' => '头像',
|
||||
'nickname' => '姓名',
|
||||
'wechat' => '微信',
|
||||
'qq' => 'qq',
|
||||
'email' => '邮箱',
|
||||
'qrcode' => '微信二维码',
|
||||
'position' => '职位',
|
||||
'city' => '所在城市',
|
||||
'openid' => '绑定微信',
|
||||
];
|
||||
$ruleInfo = self::getRule('setting');
|
||||
$MemberInfo = MemberInfoModel::where('uid', $uid)->find();
|
||||
if ($ruleInfo->status == 1) {
|
||||
self::addScore($ruleInfo, $MemberInfo, '设置 ' . $title[$name] . ' 获取');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 邀请/采集文章
|
||||
* @param [type] $uid [description]
|
||||
* @param [type] $name [description]
|
||||
*/
|
||||
public static function addArticle($uid, $name)
|
||||
{
|
||||
$ruleInfo = self::getRule($name);
|
||||
$MemberInfo = MemberInfoModel::where('uid', $uid)->find();
|
||||
$count = ScoreModel::where('create_time', 'between', Time::day())->where('rule_id', $ruleInfo->id)->count();
|
||||
$str = $name == 'add' ? '添加文章' : '采集文章';
|
||||
if ($ruleInfo->status == 1 && $count < $ruleInfo->times) {
|
||||
self::addScore($ruleInfo, $MemberInfo, $str . '获取');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 邀请好友
|
||||
* @param [type] $uid [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function invite($uid)
|
||||
{
|
||||
$ruleInfo = self::getRule('invite');
|
||||
$MemberInfo = MemberInfoModel::where('uid', $uid)->find();
|
||||
if (!$MemberInfo) {
|
||||
die();
|
||||
}
|
||||
$count = ScoreModel::where('create_time', 'between', Time::day())->where('rule_id', $ruleInfo->id)->count();
|
||||
if ($ruleInfo->status == 1 && $count < $ruleInfo->times) {
|
||||
self::addScore($ruleInfo, $MemberInfo, '邀请好友获取 ');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 开通vip
|
||||
* @param [type] $uid [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function vip($uid)
|
||||
{
|
||||
$ruleInfo = self::getRule('vip');
|
||||
$MemberInfo = MemberInfoModel::where('uid', $uid)->find();
|
||||
if ($ruleInfo->status == 1) {
|
||||
self::addScore($ruleInfo, $MemberInfo, '开通vip 获取');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 积分兑换vip
|
||||
* @param [type] $uid [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function buyVip($uid, $orderid)
|
||||
{
|
||||
$ruleInfo = self::getRule('buy_vip');
|
||||
$MemberInfo = MemberInfoModel::where('uid', $uid)->find();
|
||||
|
||||
if (empty($ruleInfo) || $ruleInfo->status != 1) {
|
||||
return '兑换功能已经关闭';
|
||||
} else if ($MemberInfo->score < $ruleInfo->score) {
|
||||
return '您的积分不够兑换,兑换一年Vip需要 ' . $ruleInfo->score . ' 积分';
|
||||
} else {
|
||||
$order = VipOrderModel::where('orderid', $orderid)->find();
|
||||
$order->save(['status' => 20, 'money' => $ruleInfo->score, 'model' => 'score']);
|
||||
$res = self::addScore($ruleInfo, $MemberInfo, '积分兑换一年vip 使用', false);
|
||||
|
||||
if ($res == 1) {
|
||||
$rule = ScoreRulesModel::where('model', 'vip')->find();
|
||||
self::addScore($rule, $MemberInfo, '开通vip获取');
|
||||
$time = ($MemberInfo->is_vip == 1) ? $MemberInfo->vip_end_time : time();
|
||||
$res = $MemberInfo->save(['is_vip' => 1, 'vip_time' => $time + 31536000]);
|
||||
return $res;
|
||||
} else {
|
||||
return '兑换失败';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分享文章
|
||||
* @param [type] $uid [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function share($uid)
|
||||
{
|
||||
$ruleInfo = self::getRule('share');
|
||||
$MemberInfo = MemberInfoModel::where('uid', $uid)->find();
|
||||
$count = ScoreModel::where('create_time', 'between', Time::day())->where('rule_id', $ruleInfo->id)->count();
|
||||
if ($ruleInfo->status == 1 && $count < $ruleInfo->times) {
|
||||
self::addScore($ruleInfo, $MemberInfo, '分享文章获取 ');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取规则信息
|
||||
* @param [type] $model [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function getRule($model)
|
||||
{
|
||||
return ScoreRulesModel::where('model', $model)->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加积分
|
||||
* @param [type] $uid [description]
|
||||
* @param [type] $ruleInfo [description]
|
||||
*/
|
||||
public static function addScore($ruleInfo, $MemberInfo, $remark, $add = true)
|
||||
{
|
||||
$data = [
|
||||
'uid' => $MemberInfo->uid,
|
||||
'rule_id' => $ruleInfo->id,
|
||||
'score' => $ruleInfo->score,
|
||||
'remark' => $remark . $ruleInfo->score . ' 积分',
|
||||
];
|
||||
ScoreModel::create($data);
|
||||
//增加积分
|
||||
if ($add) {
|
||||
$res = $MemberInfo->setInc('score', $ruleInfo->score);
|
||||
} else {
|
||||
$res = $MemberInfo->setDec('score', $ruleInfo->score);
|
||||
}
|
||||
$Member = MemberModel::get($MemberInfo->uid);
|
||||
$openid = $Member->openid;
|
||||
if (!empty($openid)) {
|
||||
if ($ruleInfo->model == 'buy_vip') {
|
||||
Message::openvip($MemberInfo);
|
||||
}
|
||||
Message::addScoreMessage($ruleInfo, $MemberInfo, $remark);
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
87
application/common/service/ScoreRules.php
Normal file
87
application/common/service/ScoreRules.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\ScoreRules as ScoreRulesModel;
|
||||
use app\common\validate\ScoreRules as ScoreRulesValidate;
|
||||
|
||||
class ScoreRules extends _Init
|
||||
{
|
||||
/**
|
||||
* 添加信息
|
||||
* @param [type] $data 积分规则数据
|
||||
*/
|
||||
public static function create($data)
|
||||
{
|
||||
$validate = new ScoreRulesValidate();
|
||||
if (!$validate->scene('add')->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
$info = ScoreRulesModel::create($data);
|
||||
if ($info) {
|
||||
return true;
|
||||
} else {
|
||||
return '创建积分规则失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑积分规则
|
||||
* @param [type] $data 更新的数据
|
||||
* @return [type] 返回 修改的结果
|
||||
*/
|
||||
public static function edit($data)
|
||||
{
|
||||
$validate = new ScoreRulesValidate();
|
||||
if (!$validate->scene('add')->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
$info = ScoreRulesModel::update($data);
|
||||
if ($info) {
|
||||
return true;
|
||||
} else {
|
||||
return '编辑积分规则失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改积分规则状态
|
||||
* @param [type] $id 积分规则id
|
||||
* @param [type] $status 状态
|
||||
* @return [type] 返回结果
|
||||
*/
|
||||
public static function status($id, $status)
|
||||
{
|
||||
$info = ScoreRulesModel::get($id);
|
||||
if (!$info) {
|
||||
return '积分规则不存在';
|
||||
} elseif ($info->save(['status' => $status])) {
|
||||
Logs::write('修改状态', ['status' => $status]);
|
||||
return true;
|
||||
} else {
|
||||
return '修改状态失败';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除积分规则
|
||||
* @param [type] $id 要删除的积分规则id
|
||||
* @return [type] 返回 结果
|
||||
*/
|
||||
public static function del($id)
|
||||
{
|
||||
$model = new ScoreRulesModel();
|
||||
if ($model->destroy($id)) {
|
||||
return true;
|
||||
} else {
|
||||
return '删除失败';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
85
application/common/service/Sms.php
Normal file
85
application/common/service/Sms.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\Sms as SmsModel;
|
||||
use app\common\validate\Sms as SmsValidate;
|
||||
use think\Config;
|
||||
use tools\Str;
|
||||
|
||||
class Sms extends _Init
|
||||
{
|
||||
|
||||
public static function send($mobile)
|
||||
{
|
||||
$code = Str::number(1, 9999);
|
||||
$data = [
|
||||
'mobile' => $mobile,
|
||||
'code' => $code,
|
||||
];
|
||||
$validate = new SmsValidate();
|
||||
|
||||
if (!$validate->check($data)) {
|
||||
return $validate->getError();
|
||||
}
|
||||
|
||||
$res = SmsModel::create($data);
|
||||
|
||||
if ($res) {
|
||||
$result = self::ali($mobile, $code);
|
||||
if ($result) {
|
||||
return true;
|
||||
} else {
|
||||
return '发送失败';
|
||||
}
|
||||
} else {
|
||||
return '验证码发送失败';
|
||||
}
|
||||
}
|
||||
|
||||
public static function check($mobile, $code)
|
||||
{
|
||||
$data = [
|
||||
'mobile' => $mobile,
|
||||
'code' => $code,
|
||||
];
|
||||
|
||||
$res = SmsModel::where('mobile', $mobile)->where('status', 0)->order('id desc')->find();
|
||||
|
||||
if ($res && $res['code'] == $code) {
|
||||
$res->save(['status' => 1]);
|
||||
return true;
|
||||
} else {
|
||||
return '验证码有误';
|
||||
}
|
||||
}
|
||||
|
||||
private static function ali($mobile, $code)
|
||||
{
|
||||
$config = Config::get('sms_config');
|
||||
$params = [
|
||||
'appid' => $config['appid'],
|
||||
'timestamp' => time(),
|
||||
'receive' => $mobile,
|
||||
'tpl_id' => 'SMS_85730027',
|
||||
'sign_method' => '身份验证',
|
||||
'params' => '{"code":"' . $code . '","product":"【超级助手】"}',
|
||||
];
|
||||
ksort($params);
|
||||
$sign = http_build_query($params);
|
||||
$sign = urldecode($sign) . '&secret=' . $config['secret'];
|
||||
$params['sign'] = strtoupper(md5($sign));
|
||||
$res = json_decode(http('http://api.cjango.com/sms/send?' . http_build_query($params), 'GET'), true);
|
||||
if ($res && $res['code'] == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
112
application/common/service/Storage.php
Normal file
112
application/common/service/Storage.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\Storage as StorageModel;
|
||||
use think\Config;
|
||||
use think\Loader;
|
||||
use think\Request;
|
||||
use tools\Format;
|
||||
|
||||
class Storage extends _Init
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取存储总量
|
||||
* @param array $map
|
||||
* @return string
|
||||
*/
|
||||
public static function total($map = [])
|
||||
{
|
||||
return Format::byte(StorageModel::where($map)->sum('size'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储文件所有类型
|
||||
* @return array
|
||||
*/
|
||||
public static function types()
|
||||
{
|
||||
return StorageModel::field('type')->distinct('type')->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 磁盘剩余空间
|
||||
* @return string
|
||||
*/
|
||||
public static function diskUse()
|
||||
{
|
||||
$total = disk_total_space(".");
|
||||
return round((($total - disk_free_space(".")) / $total) * 100, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
* @param string $name
|
||||
* @return string|array
|
||||
*/
|
||||
public static function upload($name)
|
||||
{
|
||||
$File = Request::instance()->file($name);
|
||||
// 文件验证
|
||||
$validate = Loader::validate('Storage');
|
||||
if (!$validate->check([$name => $File])) {
|
||||
return $validate->getError();
|
||||
}
|
||||
|
||||
// 检查是否有该文件,如果上传过,直接返回文件信息
|
||||
$info = StorageModel::where('hash', $File->hash())->find();
|
||||
if ($info) {
|
||||
$data = [
|
||||
'id' => $info->id,
|
||||
'name' => $info->name,
|
||||
'path' => ltrim($info->path, '.'),
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
// 保存的规则
|
||||
$File->rule(function ($file) {
|
||||
$rule = explode('/', $file->getMime())[0] . '/';
|
||||
$rule .= date('Y-m/d');
|
||||
$rule .= '/' . $file->hash();
|
||||
$rule .= '.' . strtolower(pathinfo($file->getInfo('name'), PATHINFO_EXTENSION)); // 文件后缀
|
||||
return $rule;
|
||||
});
|
||||
|
||||
$config = Config::get('storage');
|
||||
|
||||
$fileInfo = $File->move($config['path'], true, $config['replace']);
|
||||
|
||||
if ($fileInfo) {
|
||||
$data = [
|
||||
'type' => explode('/', $fileInfo->getMime())[0],
|
||||
'name' => rtrim($fileInfo->getInfo('name'), '.' . $fileInfo->getExtension()),
|
||||
'ext' => $fileInfo->getExtension(),
|
||||
'hash' => $fileInfo->hash(),
|
||||
'path' => ltrim($fileInfo->getPathname(), '.'),
|
||||
'size' => $fileInfo->getSize(),
|
||||
];
|
||||
// 保存文件信息
|
||||
if ($insert = StorageModel::create($data)) {
|
||||
$ret = [
|
||||
'id' => $insert->id,
|
||||
'name' => $insert->name,
|
||||
'path' => ltrim($insert->path, '.'),
|
||||
];
|
||||
Logs::write('上传文件', $data);
|
||||
return $ret;
|
||||
} else {
|
||||
return '数据保存失败';
|
||||
}
|
||||
} else {
|
||||
return $File->getError();
|
||||
}
|
||||
}
|
||||
}
|
||||
14
application/common/service/Suggest.php
Normal file
14
application/common/service/Suggest.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
class Suggest extends _Init
|
||||
{
|
||||
|
||||
}
|
||||
35
application/common/service/Vip.php
Normal file
35
application/common/service/Vip.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\VipOrder;
|
||||
|
||||
class Vip extends _Init
|
||||
{
|
||||
|
||||
public static function createPayOrder($uid, $money, $openid = '')
|
||||
{
|
||||
$data = [
|
||||
'uid' => $uid,
|
||||
'money' => $money,
|
||||
'openid' => $openid,
|
||||
];
|
||||
$res = VipOrder::create($data);
|
||||
return ['code' => 1, 'data' => $res->orderid];
|
||||
}
|
||||
|
||||
public static function getIds($name)
|
||||
{
|
||||
$map = [
|
||||
'nickname' => ['like', "%$name%"],
|
||||
];
|
||||
$ids = MemberInfoModel::where($map)->column('uid');
|
||||
return $ids;
|
||||
}
|
||||
}
|
||||
23
application/common/service/_Init.php
Normal file
23
application/common/service/_Init.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\service;
|
||||
|
||||
class _Init
|
||||
{
|
||||
protected static $error = '';
|
||||
|
||||
/**
|
||||
* 返回错误信息
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public static function getError()
|
||||
{
|
||||
return self::$error;
|
||||
}
|
||||
}
|
||||
33
application/common/validate/Advert.php
Normal file
33
application/common/validate/Advert.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class Advert extends Validate
|
||||
{
|
||||
/**
|
||||
* 验证规则
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'title' => 'require',
|
||||
'limit' => 'require|number',
|
||||
];
|
||||
|
||||
/**
|
||||
* 错误提示消息
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
'title.require' => 'Banner名称必须填写',
|
||||
'limit.require' => '显示上限必须填写',
|
||||
'limit.number' => '显示上限必须填数字',
|
||||
];
|
||||
}
|
||||
52
application/common/validate/AdvertDetail.php
Normal file
52
application/common/validate/AdvertDetail.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class AdvertDetail extends Validate
|
||||
{
|
||||
/**
|
||||
* 验证规则
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'title' => 'require',
|
||||
// 'url' => 'require|url:/^http(s?):\/\/(?:[A-za-z0-9-]+\.)+[A-za-z]{2,4}(:\d+)?(?:[\/\?#][\/=\?%\-&~`@[\]\':+!\.#\w]*)?$/',
|
||||
'sort' => 'require|number',
|
||||
];
|
||||
|
||||
/**
|
||||
* 错误提示消息
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
'title.require' => '标题必须填写',
|
||||
// 'url.require' => 'url必须填写',
|
||||
// 'url.url' => 'url地址添加错误,应类似 http://www.baidu.com',
|
||||
'sort.require' => '排序必须填写',
|
||||
'sort.number' => '排序必须为数字',
|
||||
];
|
||||
|
||||
/**
|
||||
* url验证
|
||||
* @param [type] $mobile [description]
|
||||
* @param [type] $rule [description]
|
||||
* @param [type] $data [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
protected function url($url, $rule, $data)
|
||||
{
|
||||
if (preg_match($rule, $url)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
61
application/common/validate/Article.php
Normal file
61
application/common/validate/Article.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Config;
|
||||
use think\Validate;
|
||||
|
||||
class Article extends Validate
|
||||
{
|
||||
|
||||
/**
|
||||
* 验证规则
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'title' => 'require|length:4,20|checkDenied',
|
||||
'description' => 'require',
|
||||
'content' => 'require|checkDenied:',
|
||||
'storage_id' => 'require',
|
||||
'category_id' => 'require',
|
||||
];
|
||||
|
||||
/**
|
||||
* 提示信息
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
'title.require' => '标题必须填写',
|
||||
'title.length' => '标题长度应在:1-:2位之间',
|
||||
'description.require' => '描述必须填写',
|
||||
'content.require' => '内容必须填写',
|
||||
'storage_id.require' => '必须上传图片',
|
||||
'category_id.require' => '分类必须选择',
|
||||
];
|
||||
|
||||
/**
|
||||
* 验证场景
|
||||
* @var array
|
||||
*/
|
||||
protected $scene = [
|
||||
'add' => ['title', 'description', 'content', 'storage_id', 'category_id'],
|
||||
];
|
||||
|
||||
protected function checkDenied($value, $rule, $data)
|
||||
{
|
||||
|
||||
$find = Config::get('denied');
|
||||
foreach ($find as $k => $v) {
|
||||
if (substr_count($value, $v)) {
|
||||
return '文章中包含非法关键词 ' . $v;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
32
application/common/validate/ArticleModel.php
Normal file
32
application/common/validate/ArticleModel.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class ArticleModel extends Validate
|
||||
{
|
||||
|
||||
/**
|
||||
* 验证规则
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'content' => 'require',
|
||||
];
|
||||
|
||||
/**
|
||||
* 提示信息
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
'content.require' => '内容必须填写',
|
||||
];
|
||||
|
||||
}
|
||||
40
application/common/validate/Auth.php
Normal file
40
application/common/validate/Auth.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
* 用户授权部分验证
|
||||
*/
|
||||
class Auth extends Validate
|
||||
{
|
||||
/**
|
||||
* 验证规则
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'title' => 'require|min:3|max:32|unique:auth',
|
||||
'remark' => 'length:0,255',
|
||||
'status' => 'in:0,1',
|
||||
];
|
||||
|
||||
/**
|
||||
* 错误提示消息
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
'title.require' => '分组名称必须填写',
|
||||
'title.min' => '分组名称不应少于:rule字符',
|
||||
'title.max' => '分组名称不应大于:rule字符',
|
||||
'title.unique' => '分组名称已经存在',
|
||||
'remark.length' => '备注信息请保持在:1-:2字符之间',
|
||||
'status.in' => '不合法的分组状态',
|
||||
];
|
||||
}
|
||||
74
application/common/validate/Category.php
Normal file
74
application/common/validate/Category.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Config;
|
||||
use think\Db;
|
||||
use think\Validate;
|
||||
|
||||
class Category extends Validate
|
||||
{
|
||||
/**
|
||||
* 验证规则
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'title' => 'require|length:1,100',
|
||||
'model' => 'require|checkModel:lvyang|checkExtends:lvyang',
|
||||
'pid' => 'require|integer',
|
||||
'sort' => 'require|integer',
|
||||
'description' => 'length:0,255',
|
||||
];
|
||||
|
||||
/**
|
||||
* 错误提示消息
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
'title.require' => '分类名称必须填写',
|
||||
'title.length' => '分类名称请保持在:1-:2字符之间',
|
||||
'model.require' => '分类模型必须选择',
|
||||
'model.checkModel' => '分类选择有误',
|
||||
'model.checkExtends' => '分类模型必须与上级模型一致',
|
||||
'pid.require' => '上级分类必须选择',
|
||||
'pid.integer' => '上级分类选择错误',
|
||||
'sort.require' => '排序必须填写',
|
||||
'sort.integer' => '排序必须是整数',
|
||||
'description.length' => '分类备注请保持在:rule字符以内',
|
||||
];
|
||||
|
||||
/**
|
||||
* 检测模型是否合法
|
||||
* @param [type] $value 检查的值
|
||||
* @param [type] $rule 规则
|
||||
* @param [type] $data 数据
|
||||
* @return [type] 返回结果
|
||||
*/
|
||||
protected function checkModel($value, $rule, $data)
|
||||
{
|
||||
$keys = array_keys(Config::get('category_model'));
|
||||
return in_array($value, $keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测继承分类是否是相同的模型
|
||||
* @param [type] $value 检查的值
|
||||
* @param [type] $rule 规则
|
||||
* @param [type] $data 数据
|
||||
* @return [type] 返回结果
|
||||
*/
|
||||
protected function checkExtends($value, $rule, $data)
|
||||
{
|
||||
if (0 != $data['pid']) {
|
||||
return $value == Db::name('Category')->where('id', $data['pid'])->value('model');
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
44
application/common/validate/Config.php
Normal file
44
application/common/validate/Config.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
* 配置验证器
|
||||
*/
|
||||
class Config extends Validate
|
||||
{
|
||||
/**
|
||||
* 验证规则
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'title' => 'require|min:3|max:32',
|
||||
'name' => 'require|min:3|max:32|unique:config',
|
||||
'sort' => 'number',
|
||||
'value' => 'require',
|
||||
];
|
||||
|
||||
/**
|
||||
* 错误提示消息
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
'title.require' => '配置名称必须填写',
|
||||
'title.min' => '配置名称不应少于:rule个字符',
|
||||
'title.max' => '配置名称不应大于:rule字符',
|
||||
'name.require' => '配置标识必须填写',
|
||||
'name.min' => '配置标识不应少于:rule个字符',
|
||||
'name.max' => '配置标识不应大于:rule字符',
|
||||
'name.unique' => '配置标识已经存在',
|
||||
'sort.number' => '排序必须是数字',
|
||||
'value.require' => '配置值必须填写',
|
||||
];
|
||||
}
|
||||
49
application/common/validate/Content.php
Normal file
49
application/common/validate/Content.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class Content extends Validate
|
||||
{
|
||||
|
||||
/**
|
||||
* 验证规则
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'title' => 'require|length:2,100',
|
||||
'description' => 'require',
|
||||
'content' => 'require',
|
||||
'storage_id' => 'require',
|
||||
'category_id' => 'require',
|
||||
];
|
||||
|
||||
/**
|
||||
* 提示信息
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
'title.require' => '标题必须填写',
|
||||
'title.length' => '标题长度应在:1-:2位之间',
|
||||
'description.require' => '描述必须填写',
|
||||
'content.require' => '内容必须填写',
|
||||
'storage_id.require' => '必须上传图片',
|
||||
'category_id.require' => '分类必须选择',
|
||||
];
|
||||
|
||||
/**
|
||||
* 验证场景
|
||||
* @var array
|
||||
*/
|
||||
protected $scene = [
|
||||
'add' => ['title', 'description', 'content', 'storage_id', 'category_id'],
|
||||
];
|
||||
|
||||
}
|
||||
50
application/common/validate/Direct.php
Normal file
50
application/common/validate/Direct.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
// 完整内容 article/video/audio ext_id
|
||||
class Direct extends Validate
|
||||
{
|
||||
|
||||
/**
|
||||
* 验证规则
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'title' => 'require|length:2,100',
|
||||
'type' => 'require',
|
||||
'sort' => 'require',
|
||||
'content' => 'require',
|
||||
'storage_id' => 'require',
|
||||
];
|
||||
|
||||
/**
|
||||
* 提示信息
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
'title.require' => '标题必须填写',
|
||||
'title.length' => '标题长度应在:1-:2位之间',
|
||||
'type.require' => '分类必须选择',
|
||||
'sort.require' => '排序必须选择',
|
||||
'content.require' => '内容必须填写',
|
||||
'storage_id.require' => '必须上传图片',
|
||||
];
|
||||
|
||||
/**
|
||||
* 验证场景
|
||||
* @var array
|
||||
*/
|
||||
protected $scene = [
|
||||
'add' => ['title', 'description', 'type', 'content', 'storage_id', 'category_id'],
|
||||
];
|
||||
|
||||
}
|
||||
35
application/common/validate/Experience.php
Normal file
35
application/common/validate/Experience.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class Experience extends Validate
|
||||
{
|
||||
|
||||
/**
|
||||
* 验证规则
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'pid' => 'require',
|
||||
'uid' => 'require',
|
||||
'content' => 'require',
|
||||
];
|
||||
|
||||
/**
|
||||
* 提示信息
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
'pid.require' => '上级id没有获取到',
|
||||
'uid.require' => '用户id没有获取到',
|
||||
'content.require' => '内容必须填写',
|
||||
];
|
||||
}
|
||||
45
application/common/validate/Help.php
Normal file
45
application/common/validate/Help.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class Help extends Validate
|
||||
{
|
||||
|
||||
/**
|
||||
* 验证规则
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'title' => 'require|length:2,100',
|
||||
'content' => 'require',
|
||||
'category' => 'require',
|
||||
];
|
||||
|
||||
/**
|
||||
* 提示信息
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
'title.require' => '标题必须填写',
|
||||
'title.length' => '标题长度应在:1-:2位之间',
|
||||
'content.require' => '内容必须填写',
|
||||
'category.require' => '分类必须选择',
|
||||
];
|
||||
|
||||
/**
|
||||
* 验证场景
|
||||
* @var array
|
||||
*/
|
||||
protected $scene = [
|
||||
'add' => ['title', 'content', 'category'],
|
||||
];
|
||||
|
||||
}
|
||||
71
application/common/validate/Member.php
Normal file
71
application/common/validate/Member.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Db;
|
||||
use think\Validate;
|
||||
use tools\Crypt;
|
||||
|
||||
class Member extends Validate
|
||||
{
|
||||
|
||||
/**
|
||||
* 验证规则
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'username' => 'require|length:4,32|unique:member',
|
||||
'password' => 'require|length:6,32',
|
||||
'openid' => 'require',
|
||||
'oldpass' => 'require|length:6,32|verifyPassword:',
|
||||
'newpass' => 'require|length:6,32|different:oldpass',
|
||||
'repass' => 'require|length:6,32|confirm:newpass',
|
||||
];
|
||||
|
||||
/**
|
||||
* 提示信息
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
'username.require' => '用户名必须填写',
|
||||
'username.length' => '用户名长度应在:1-:2位之间',
|
||||
'username.unique' => '用户名已经存在',
|
||||
'password.require' => '密码必须填写',
|
||||
'password.length' => '密码长度应在:1-:2位之间',
|
||||
'oldpass.require' => '原始密码必须填写',
|
||||
'oldpass.length' => '原始密码长度应在:1-:2位之间',
|
||||
'oldpass.verifyPassword' => '原始密码不正确',
|
||||
'newpass.require' => '新密码必须填写',
|
||||
'newpass.length' => '新密码长度应在:1-:2位之间',
|
||||
'newpass.different' => '新密码不能与原始密码相同',
|
||||
'repass.require' => '确认密码必须填写',
|
||||
'repass.length' => '确认密码长度应在:1-:2位之间',
|
||||
'repass.confirm' => '两次输入的密码不一致',
|
||||
'openid.require' => '绑定失败',
|
||||
];
|
||||
|
||||
/**
|
||||
* 验证场景
|
||||
* @var array
|
||||
*/
|
||||
protected $scene = [
|
||||
'changepass' => ['oldpass', 'newpass', 'repass'],
|
||||
'updatepass' => ['password'],
|
||||
'openid' => ['openid'],
|
||||
'forget' => ['newpass', 'repass'],
|
||||
'register' => ['username', 'password'],
|
||||
'login' => ['username' => 'require|length:4,32', 'password'],
|
||||
'mobileRegister' => ['username', 'password', 'repass' => 'require|confirm:password'],
|
||||
];
|
||||
|
||||
protected function verifyPassword($value, $rule, $data)
|
||||
{
|
||||
return Crypt::uMd5($value) == Db::name('Member')->where('id', $data['uid'])->value('password');
|
||||
}
|
||||
}
|
||||
70
application/common/validate/MemberInfo.php
Normal file
70
application/common/validate/MemberInfo.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
use tools\Verify;
|
||||
|
||||
class MemberInfo extends Validate
|
||||
{
|
||||
/**
|
||||
* 验证规则
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'nickname' => 'require|min:2|max:4',
|
||||
'mobile' => 'require|length:11|verifyMobile:',
|
||||
'wechat' => 'require|length:2,30',
|
||||
'qq' => 'require|integer|length:5,11',
|
||||
'email' => 'require|email',
|
||||
'position' => 'require|length:2,20',
|
||||
'province' => 'require',
|
||||
'city' => 'require',
|
||||
'signature' => 'require',
|
||||
];
|
||||
|
||||
/**
|
||||
* 错误提示消息
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
'nickname.require' => '用户昵称必须填写',
|
||||
'nickname.max' => '用户昵称最大长度:rule位',
|
||||
'email.require' => '邮箱地址不能为空',
|
||||
'email.email' => '邮箱地址不正确',
|
||||
'qq.require' => 'QQ不能为空',
|
||||
'qq.integer' => 'QQ必须是整数',
|
||||
'qq.length' => 'QQ长度应为:rule位',
|
||||
'mobile.require' => '手机号必须填写',
|
||||
'mobile.length' => '手机号长度应为:rule位',
|
||||
'province.require' => '省份必须选择',
|
||||
'city.require' => '城市必须选择',
|
||||
'signature.require' => '内容必须填写',
|
||||
'mobile.verifyMobile' => '手机号码格式不正确',
|
||||
];
|
||||
|
||||
protected $scene = [
|
||||
'nickname' => ['nickname'],
|
||||
'mobile' => ['mobile'],
|
||||
'wechat' => ['wechat'],
|
||||
'qq' => ['qq'],
|
||||
'email' => ['email'],
|
||||
'position' => ['position'],
|
||||
'wxapi' => ['nickname'],
|
||||
'qrcode' => ['qrcode'],
|
||||
'signature' => ['signature'],
|
||||
'headimgurl' => ['headimgurl'],
|
||||
'city' => ['province', 'city'],
|
||||
];
|
||||
|
||||
protected function verifyMobile($value)
|
||||
{
|
||||
return Verify::isMobilePhone($value);
|
||||
}
|
||||
}
|
||||
132
application/common/validate/MemberList.php
Normal file
132
application/common/validate/MemberList.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class MemberList extends Validate
|
||||
{
|
||||
|
||||
/**
|
||||
* 验证规则
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'username' => 'require',
|
||||
'level' => 'require',
|
||||
'mobile' => 'require|number|length:11',
|
||||
'id_card' => 'require|checkIdCard',
|
||||
'bank' => 'require|chs',
|
||||
' ' => 'require|number',
|
||||
'password' => 'require',
|
||||
'referee' => 'require',
|
||||
'referee_number' => 'require',
|
||||
'contact' => 'require',
|
||||
'contact_number' => 'require',
|
||||
|
||||
];
|
||||
|
||||
/**
|
||||
* 提示信息
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
'username.require' => '姓名必须填写',
|
||||
'level.require' => '会员级别必须填写',
|
||||
'mobile.require' => '电话必须填写',
|
||||
'mobile.number' => '电话必须是数字',
|
||||
'mobile.length' => '电话号码位数不对,应该是11位',
|
||||
'id_card.require' => '身份证号必须填写',
|
||||
'id_card.checkIdCard' => '身份证号错误',
|
||||
'bank.require' => '银行必须填写',
|
||||
'bank.chs' => '银行只能是中文',
|
||||
'bank_card.require' => '卡号必须填写',
|
||||
'bank_card.number' => '卡号必须是数字',
|
||||
'password.require' => '密码必须填写',
|
||||
'referee.require' => '推荐人必须填写',
|
||||
'referee_number.require' => '推荐人编号必须填写',
|
||||
'contact.require' => '接点人必须填写',
|
||||
'contact_number.require' => '接点人编号必须填写',
|
||||
];
|
||||
|
||||
/**
|
||||
* 验证场景
|
||||
* @var array
|
||||
*/
|
||||
protected $scene = [
|
||||
'add' => ['username', 'level', 'mobile', 'id_card', 'bank', 'bank_card', 'password', 'referee', 'referee_number', 'contact', 'contact_number'],
|
||||
];
|
||||
|
||||
protected function checkIdCard($value, $rule, $data)
|
||||
{
|
||||
$idcard = $value;
|
||||
$City = array(11 => "北京", 12 => "天津", 13 => "河北", 14 => "山西", 15 => "内蒙古", 21 => "辽宁", 22 => "吉林", 23 => "黑龙江", 31 => "上海", 32 => "江苏", 33 => "浙江", 34 => "安徽", 35 => "福建", 36 => "江西", 37 => "山东", 41 => "河南", 42 => "湖北", 43 => "湖南", 44 => "广东", 45 => "广西", 46 => "海南", 50 => "重庆", 51 => "四川", 52 => "贵州", 53 => "云南", 54 => "西藏", 61 => "陕西", 62 => "甘肃", 63 => "青海", 64 => "宁夏", 65 => "新疆", 71 => "台湾", 81 => "香港", 82 => "澳门", 91 => "国外");
|
||||
$iSum = 0;
|
||||
$idCardLength = strlen($idcard);
|
||||
|
||||
//长度验证
|
||||
if (!preg_match('/^\d{17}(\d|x)$/i', $idcard) and !preg_match('/^\d{15}$/i', $idcard)) {
|
||||
return false;
|
||||
}
|
||||
//地区验证
|
||||
if (!array_key_exists(intval(substr($idcard, 0, 2)), $City)) {
|
||||
return false;
|
||||
}
|
||||
// 15位身份证验证生日,转换为18位
|
||||
if ($idCardLength == 15) {
|
||||
$sBirthday = '19' . substr($idcard, 6, 2) . '-' . substr($idcard, 8, 2) . '-' . substr($idcard, 10, 2);
|
||||
$d = new \DateTime($sBirthday);
|
||||
$dd = $d->format('Y-m-d');
|
||||
if ($sBirthday != $dd) {
|
||||
return false;
|
||||
}
|
||||
$idcard = substr($idcard, 0, 6) . "19" . substr($idcard, 6, 9); //15to18
|
||||
$Bit18 = self::getVerifyBit($idcard); //算出第18位校验码
|
||||
$idcard = $idcard . $Bit18;
|
||||
}
|
||||
// 判断是否大于2078年,小于1900年
|
||||
$year = substr($idcard, 6, 4);
|
||||
if ($year < 1900 || $year > 2078) {
|
||||
return false;
|
||||
}
|
||||
//18位身份证处理
|
||||
$sBirthday = substr($idcard, 6, 4) . '-' . substr($idcard, 10, 2) . '-' . substr($idcard, 12, 2);
|
||||
$d = new \DateTime($sBirthday);
|
||||
$dd = $d->format('Y-m-d');
|
||||
if ($sBirthday != $dd) {
|
||||
return false;
|
||||
}
|
||||
//身份证编码规范验证
|
||||
$idcard_base = substr($idcard, 0, 17);
|
||||
if (strtoupper(substr($idcard, 17, 1)) != self::getVerifyBit($idcard_base)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 计算身份证校验码,根据国家标准GB 11643-1999
|
||||
public function getVerifyBit($idcard_base)
|
||||
{
|
||||
if (strlen($idcard_base) != 17) {
|
||||
return false;
|
||||
}
|
||||
//加权因子
|
||||
$factor = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
|
||||
//校验码对应值
|
||||
$verify_number_list = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
|
||||
$checksum = 0;
|
||||
for ($i = 0; $i < strlen($idcard_base); $i++) {
|
||||
$checksum += substr($idcard_base, $i, 1) * $factor[$i];
|
||||
}
|
||||
$mod = $checksum % 11;
|
||||
$verify_number = $verify_number_list[$mod];
|
||||
return $verify_number;
|
||||
}
|
||||
|
||||
}
|
||||
47
application/common/validate/Menu.php
Normal file
47
application/common/validate/Menu.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
* 菜单验证器
|
||||
*/
|
||||
class Menu extends Validate
|
||||
{
|
||||
/**
|
||||
* 验证规则
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'title' => 'require|max:32',
|
||||
'sort' => 'number',
|
||||
'url' => 'requireWith:pid|max:30',
|
||||
];
|
||||
|
||||
/**
|
||||
* 错误提示消息
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
'title.require' => '菜单名称必须填写',
|
||||
'title.max' => '菜单名称不应大于:rule字符',
|
||||
'sort.number' => '排序必须是数字',
|
||||
'url.requireWith' => '菜单URL连接必须填写',
|
||||
'url.max' => '菜单URL最大长度:rule字符',
|
||||
];
|
||||
|
||||
/**
|
||||
* 验证场景
|
||||
* @var array
|
||||
*/
|
||||
protected $scene = [
|
||||
'add' => ['title', 'sort', 'url'],
|
||||
];
|
||||
}
|
||||
42
application/common/validate/Message.php
Normal file
42
application/common/validate/Message.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class Message extends Validate
|
||||
{
|
||||
|
||||
/**
|
||||
* 验证规则
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'from_uid' => 'require',
|
||||
'to_uid' => 'require',
|
||||
'content' => 'require',
|
||||
];
|
||||
|
||||
/**
|
||||
* 提示信息
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
'content.require' => '内容必须填写',
|
||||
];
|
||||
|
||||
/**
|
||||
* 验证场景
|
||||
* @var array
|
||||
*/
|
||||
protected $scene = [
|
||||
'add' => ['from_uid', 'to_uid', 'content'],
|
||||
];
|
||||
|
||||
}
|
||||
49
application/common/validate/ScoreRules.php
Normal file
49
application/common/validate/ScoreRules.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class ScoreRules extends Validate
|
||||
{
|
||||
|
||||
/**
|
||||
* 验证规则
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'title' => 'require|length:2,100',
|
||||
'score' => 'require|number',
|
||||
'times' => 'require|number',
|
||||
'model' => 'require',
|
||||
];
|
||||
|
||||
/**
|
||||
* 提示信息
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
'title.require' => '名称必须填写',
|
||||
'title.length' => '名称长度应在:1-:2位之间',
|
||||
'score.require' => '积分必须填写',
|
||||
'score.number' => '积分必须是数字',
|
||||
'times.require' => '每日次数必须填写',
|
||||
'times.require' => '每日次数必须是数字',
|
||||
'model.require' => '规则名必须填写',
|
||||
];
|
||||
|
||||
/**
|
||||
* 验证场景
|
||||
* @var array
|
||||
*/
|
||||
protected $scene = [
|
||||
'add' => ['title', 'score', 'times', 'model'],
|
||||
];
|
||||
|
||||
}
|
||||
54
application/common/validate/Sms.php
Normal file
54
application/common/validate/Sms.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Db;
|
||||
use think\Validate;
|
||||
use tools\Verify;
|
||||
|
||||
class Sms extends Validate
|
||||
{
|
||||
/**
|
||||
* 验证规则
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'mobile' => 'require|checkMobile:|checkTimes:',
|
||||
'code' => 'require|length:4,6',
|
||||
];
|
||||
|
||||
/**
|
||||
* 错误提示消息
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
'mobile.require' => '手机号码 必须填写',
|
||||
'mobile.checkMobile' => '手机号码 格式有误',
|
||||
'code.require' => '验证码 必须填写',
|
||||
'code.length' => '验证码 长度有误',
|
||||
];
|
||||
|
||||
protected $scene = [
|
||||
|
||||
];
|
||||
|
||||
protected function checkTimes($value)
|
||||
{
|
||||
if (time() - Db::name('Sms')->where('mobile', $value)->order('id desc')->value('create_time') < 60) {
|
||||
return '发送频率过快';
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkMobile($value)
|
||||
{
|
||||
return Verify::isMobilePhone($value);
|
||||
}
|
||||
}
|
||||
32
application/common/validate/Storage.php
Normal file
32
application/common/validate/Storage.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\common\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class Storage extends Validate
|
||||
{
|
||||
/**
|
||||
* 验证规则
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'image' => 'file|image:|fileExt:jpg,png,gif,jpeg,bmp|fileSize:2097152',
|
||||
'file' => 'file|fileExt:doc,docx,xls,xlsx,ppt,pptx,zip,rar,jpg,png,gif,jpeg,bmp|fileSize:5242880',
|
||||
'video' => 'file|fileExt:mp4,flv,swf|fileSize:52428800',
|
||||
'audio' => 'file|fileExt:mp3|fileSize:52428800',
|
||||
];
|
||||
|
||||
/**
|
||||
* 错误提示消息
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
];
|
||||
}
|
||||
47
application/config.php
Normal file
47
application/config.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
use think\Env;
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | 应用设置
|
||||
// +----------------------------------------------------------------------
|
||||
return [
|
||||
// 应用Trace
|
||||
'app_trace' => false,
|
||||
// +----------------------------------------------------------------------
|
||||
// | Trace设置 开启 app_trace 后 有效
|
||||
// +----------------------------------------------------------------------
|
||||
'trace' => [
|
||||
'type' => Env::get('trace.type', false),
|
||||
],
|
||||
// +----------------------------------------------------------------------
|
||||
// | 异常及错误设置
|
||||
// +----------------------------------------------------------------------
|
||||
// 异常页面的模板文件
|
||||
'exception_tmpl' => APP_PATH . 'exception.tpl',
|
||||
// 错误显示信息,非调试模式有效
|
||||
'error_message' => '页面错误!请稍后再试~',
|
||||
// 显示错误信息
|
||||
'show_error_msg' => false,
|
||||
// URL普通方式参数 用于自动生成
|
||||
'url_common_param' => true,
|
||||
// 域名部署
|
||||
'url_domain_deploy' => true,
|
||||
'url_html_suffix' => '',
|
||||
// +----------------------------------------------------------------------
|
||||
// | 默认全局过滤方法 用逗号分隔多个
|
||||
// +----------------------------------------------------------------------
|
||||
'default_filter' => 'trim',
|
||||
// +----------------------------------------------------------------------
|
||||
// | 用户密码加密串
|
||||
// +----------------------------------------------------------------------
|
||||
'data_auth_key' => 'Vg#:dxp4Tv=?1}3EeDA/KY]2qX$2RDnNwC.O+rQH',
|
||||
];
|
||||
404
application/exception.tpl
Normal file
404
application/exception.tpl
Normal file
@@ -0,0 +1,404 @@
|
||||
<?php
|
||||
if(!function_exists('parse_padding')){
|
||||
function parse_padding($source)
|
||||
{
|
||||
$length = strlen(strval(count($source['source']) + $source['first']));
|
||||
return 40 + ($length - 1) * 8;
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists('parse_class')){
|
||||
function parse_class($name)
|
||||
{
|
||||
$names = explode('\\', $name);
|
||||
return '<abbr title="'.$name.'">'.end($names).'</abbr>';
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists('parse_file')){
|
||||
function parse_file($file, $line)
|
||||
{
|
||||
return '<a class="toggle" title="'."{$file} line {$line}".'">'.basename($file)." line {$line}".'</a>';
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists('parse_args')){
|
||||
function parse_args($args)
|
||||
{
|
||||
$result = [];
|
||||
|
||||
foreach ($args as $key => $item) {
|
||||
switch (true) {
|
||||
case is_object($item):
|
||||
$value = sprintf('<em>object</em>(%s)', parse_class(get_class($item)));
|
||||
break;
|
||||
case is_array($item):
|
||||
if(count($item) > 3){
|
||||
$value = sprintf('[%s, ...]', parse_args(array_slice($item, 0, 3)));
|
||||
} else {
|
||||
$value = sprintf('[%s]', parse_args($item));
|
||||
}
|
||||
break;
|
||||
case is_string($item):
|
||||
if(strlen($item) > 20){
|
||||
$value = sprintf(
|
||||
'\'<a class="toggle" title="%s">%s...</a>\'',
|
||||
htmlentities($item),
|
||||
htmlentities(substr($item, 0, 20))
|
||||
);
|
||||
} else {
|
||||
$value = sprintf("'%s'", htmlentities($item));
|
||||
}
|
||||
break;
|
||||
case is_int($item):
|
||||
case is_float($item):
|
||||
$value = $item;
|
||||
break;
|
||||
case is_null($item):
|
||||
$value = '<em>null</em>';
|
||||
break;
|
||||
case is_bool($item):
|
||||
$value = '<em>' . ($item ? 'true' : 'false') . '</em>';
|
||||
break;
|
||||
case is_resource($item):
|
||||
$value = '<em>resource</em>';
|
||||
break;
|
||||
default:
|
||||
$value = htmlentities(str_replace("\n", '', var_export(strval($item), true)));
|
||||
break;
|
||||
}
|
||||
|
||||
$result[] = is_int($key) ? $value : "'{$key}' => {$value}";
|
||||
}
|
||||
|
||||
return implode(', ', $result);
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title><?php echo lang('System Error'); ?></title>
|
||||
<meta name="robots" content="noindex,nofollow" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
||||
<style>
|
||||
/* Base */
|
||||
body {
|
||||
color: #333;
|
||||
font: 14px Verdana, "Helvetica Neue", helvetica, Arial, 'Microsoft YaHei', sans-serif;
|
||||
margin: 0;
|
||||
padding: 0 20px 20px;
|
||||
word-break: break-word;
|
||||
}
|
||||
h1{
|
||||
margin: 10px 0 0;
|
||||
font-size: 28px;
|
||||
font-weight: 500;
|
||||
line-height: 32px;
|
||||
}
|
||||
h2{
|
||||
color: #4288ce;
|
||||
font-weight: 400;
|
||||
padding: 6px 0;
|
||||
margin: 6px 0 0;
|
||||
font-size: 18px;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
h3.subheading {
|
||||
color: #4288ce;
|
||||
margin: 6px 0 0;
|
||||
font-weight: 400;
|
||||
}
|
||||
h3{
|
||||
margin: 12px;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
}
|
||||
abbr{
|
||||
cursor: help;
|
||||
text-decoration: underline;
|
||||
text-decoration-style: dotted;
|
||||
}
|
||||
a{
|
||||
color: #868686;
|
||||
cursor: pointer;
|
||||
}
|
||||
a:hover{
|
||||
text-decoration: underline;
|
||||
}
|
||||
.line-error{
|
||||
background: #f8cbcb;
|
||||
}
|
||||
|
||||
.echo table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.echo pre {
|
||||
padding: 16px;
|
||||
overflow: auto;
|
||||
font-size: 85%;
|
||||
line-height: 1.45;
|
||||
background-color: #f7f7f7;
|
||||
border: 0;
|
||||
border-radius: 3px;
|
||||
font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
|
||||
}
|
||||
|
||||
.echo pre > pre {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
/* Layout */
|
||||
.col-md-3 {
|
||||
width: 25%;
|
||||
}
|
||||
.col-md-9 {
|
||||
width: 75%;
|
||||
}
|
||||
[class^="col-md-"] {
|
||||
float: left;
|
||||
}
|
||||
.clearfix {
|
||||
clear:both;
|
||||
}
|
||||
@media only screen
|
||||
and (min-device-width : 375px)
|
||||
and (max-device-width : 667px) {
|
||||
.col-md-3,
|
||||
.col-md-9 {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
/* Exception Info */
|
||||
.exception {
|
||||
margin-top: 20px;
|
||||
}
|
||||
.exception .message{
|
||||
padding: 12px;
|
||||
border: 1px solid #ddd;
|
||||
border-bottom: 0 none;
|
||||
line-height: 18px;
|
||||
font-size:16px;
|
||||
border-top-left-radius: 4px;
|
||||
border-top-right-radius: 4px;
|
||||
font-family: Consolas,"Liberation Mono",Courier,Verdana,"微软雅黑";
|
||||
}
|
||||
|
||||
.exception .code{
|
||||
float: left;
|
||||
text-align: center;
|
||||
color: #fff;
|
||||
margin-right: 12px;
|
||||
padding: 16px;
|
||||
border-radius: 4px;
|
||||
background: #999;
|
||||
}
|
||||
.exception .source-code{
|
||||
padding: 6px;
|
||||
border: 1px solid #ddd;
|
||||
|
||||
background: #f9f9f9;
|
||||
overflow-x: auto;
|
||||
|
||||
}
|
||||
.exception .source-code pre{
|
||||
margin: 0;
|
||||
}
|
||||
.exception .source-code pre ol{
|
||||
margin: 0;
|
||||
color: #4288ce;
|
||||
display: inline-block;
|
||||
min-width: 100%;
|
||||
box-sizing: border-box;
|
||||
font-size:14px;
|
||||
font-family: "Century Gothic",Consolas,"Liberation Mono",Courier,Verdana;
|
||||
padding-left: <?php echo (isset($source) && !empty($source)) ? parse_padding($source) : 40; ?>px;
|
||||
}
|
||||
.exception .source-code pre li{
|
||||
border-left: 1px solid #ddd;
|
||||
height: 18px;
|
||||
line-height: 18px;
|
||||
}
|
||||
.exception .source-code pre code{
|
||||
color: #333;
|
||||
height: 100%;
|
||||
display: inline-block;
|
||||
border-left: 1px solid #fff;
|
||||
font-size:14px;
|
||||
font-family: Consolas,"Liberation Mono",Courier,Verdana,"微软雅黑";
|
||||
}
|
||||
|
||||
/* SPAN elements with the classes below are added by prettyprint. */
|
||||
pre.prettyprint .pln { color: #000 } /* plain text */
|
||||
pre.prettyprint .str { color: #080 } /* string content */
|
||||
pre.prettyprint .kwd { color: #008 } /* a keyword */
|
||||
pre.prettyprint .com { color: #800 } /* a comment */
|
||||
pre.prettyprint .typ { color: #606 } /* a type name */
|
||||
pre.prettyprint .lit { color: #066 } /* a literal value */
|
||||
/* punctuation, lisp open bracket, lisp close bracket */
|
||||
pre.prettyprint .pun, pre.prettyprint .opn, pre.prettyprint .clo { color: #660 }
|
||||
pre.prettyprint .tag { color: #008 } /* a markup tag name */
|
||||
pre.prettyprint .atn { color: #606 } /* a markup attribute name */
|
||||
pre.prettyprint .atv { color: #080 } /* a markup attribute value */
|
||||
pre.prettyprint .dec, pre.prettyprint .var { color: #606 } /* a declaration; a variable name */
|
||||
pre.prettyprint .fun { color: red } /* a function name */
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="echo">
|
||||
<?php echo $echo;?>
|
||||
</div>
|
||||
<?php if(\think\App::$debug) { ?>
|
||||
<div class="exception">
|
||||
<div class="message">
|
||||
|
||||
<div class="info">
|
||||
<div>
|
||||
<h2>[<?php echo $code; ?>] <?php echo sprintf('%s in %s', parse_class($name), parse_file($file, $line)); ?></h2>
|
||||
</div>
|
||||
<div><h1><?php echo nl2br(htmlentities($message)); ?></h1></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<?php if(!empty($source)){?>
|
||||
<div class="source-code">
|
||||
<pre class="prettyprint lang-php"><ol start="<?php echo $source['first']; ?>"><?php foreach ((array) $source['source'] as $key => $value) { ?><li class="line-<?php echo $key + $source['first']; ?>"><code><?php echo htmlentities($value); ?></code></li><?php } ?></ol></pre>
|
||||
</div>
|
||||
<?php }?>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<div class="exception">
|
||||
|
||||
<div class="info"><h1><?php echo htmlentities($message); ?></h1></div>
|
||||
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if(!empty($datas)){ ?>
|
||||
<div class="exception-var">
|
||||
<h2>Exception Datas</h2>
|
||||
<?php foreach ((array) $datas as $label => $value) { ?>
|
||||
<table>
|
||||
<?php if(empty($value)){ ?>
|
||||
<caption><?php echo $label; ?><small>empty</small></caption>
|
||||
<?php } else { ?>
|
||||
<caption><?php echo $label; ?></caption>
|
||||
<tbody>
|
||||
<?php foreach ((array) $value as $key => $val) { ?>
|
||||
<tr>
|
||||
<td><?php echo htmlentities($key); ?></td>
|
||||
<td>
|
||||
<?php
|
||||
if(is_array($val) || is_object($val)){
|
||||
echo htmlentities(json_encode($val, JSON_PRETTY_PRINT));
|
||||
} else if(is_bool($val)) {
|
||||
echo $val ? 'true' : 'false';
|
||||
} else if(is_scalar($val)) {
|
||||
echo htmlentities($val);
|
||||
} else {
|
||||
echo 'Resource';
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
<?php } ?>
|
||||
</table>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if(\think\App::$debug) { ?>
|
||||
<script>
|
||||
var LINE = <?php echo $line; ?>;
|
||||
|
||||
function $(selector, node){
|
||||
var elements;
|
||||
|
||||
node = node || document;
|
||||
if(document.querySelectorAll){
|
||||
elements = node.querySelectorAll(selector);
|
||||
} else {
|
||||
switch(selector.substr(0, 1)){
|
||||
case '#':
|
||||
elements = [node.getElementById(selector.substr(1))];
|
||||
break;
|
||||
case '.':
|
||||
if(document.getElementsByClassName){
|
||||
elements = node.getElementsByClassName(selector.substr(1));
|
||||
} else {
|
||||
elements = get_elements_by_class(selector.substr(1), node);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
elements = node.getElementsByTagName();
|
||||
}
|
||||
}
|
||||
return elements;
|
||||
|
||||
function get_elements_by_class(search_class, node, tag) {
|
||||
var elements = [], eles,
|
||||
pattern = new RegExp('(^|\\s)' + search_class + '(\\s|$)');
|
||||
|
||||
node = node || document;
|
||||
tag = tag || '*';
|
||||
|
||||
eles = node.getElementsByTagName(tag);
|
||||
for(var i = 0; i < eles.length; i++) {
|
||||
if(pattern.test(eles[i].className)) {
|
||||
elements.push(eles[i])
|
||||
}
|
||||
}
|
||||
|
||||
return elements;
|
||||
}
|
||||
}
|
||||
|
||||
$.getScript = function(src, func){
|
||||
var script = document.createElement('script');
|
||||
|
||||
script.async = 'async';
|
||||
script.src = src;
|
||||
script.onload = func || function(){};
|
||||
|
||||
$('head')[0].appendChild(script);
|
||||
}
|
||||
|
||||
;(function(){
|
||||
var files = $('.toggle');
|
||||
var ol = $('ol', $('.prettyprint')[0]);
|
||||
var li = $('li', ol[0]);
|
||||
|
||||
// 短路径和长路径变换
|
||||
for(var i = 0; i < files.length; i++){
|
||||
files[i].ondblclick = function(){
|
||||
var title = this.title;
|
||||
|
||||
this.title = this.innerHTML;
|
||||
this.innerHTML = title;
|
||||
}
|
||||
}
|
||||
|
||||
// 设置出错行
|
||||
var err_line = $('.line-' + LINE, ol[0])[0];
|
||||
err_line.className = err_line.className + ' line-error';
|
||||
|
||||
$.getScript('//cdn.bootcss.com/prettify/r298/prettify.min.js', function(){
|
||||
prettyPrint();
|
||||
|
||||
// 解决Firefox浏览器一个很诡异的问题
|
||||
// 当代码高亮后,ol的行号莫名其妙的错位
|
||||
// 但是只要刷新li里面的html重新渲染就没有问题了
|
||||
if(window.navigator.userAgent.indexOf('Firefox') >= 0){
|
||||
ol[0].innerHTML = ol[0].innerHTML;
|
||||
}
|
||||
});
|
||||
|
||||
})();
|
||||
</script>
|
||||
<?php } ?>
|
||||
</body>
|
||||
</html>
|
||||
16
application/extra/cache.php
Normal file
16
application/extra/cache.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
|
||||
return [
|
||||
'type' => 'File',
|
||||
'path' => CACHE_PATH,
|
||||
'prefix' => '',
|
||||
'expire' => 0,
|
||||
'cache_subdir' => false,
|
||||
];
|
||||
14
application/extra/captcha.php
Normal file
14
application/extra/captcha.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
|
||||
return [
|
||||
'useCurve' => false,
|
||||
'length' => 4,
|
||||
'reset' => true,
|
||||
];
|
||||
55
application/extra/database.php
Normal file
55
application/extra/database.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
return [
|
||||
// 数据库类型
|
||||
'type' => 'mysql',
|
||||
// 服务器地址
|
||||
'hostname' => 'localhost',
|
||||
// 数据库名
|
||||
'database' => 'helper',
|
||||
// 用户名
|
||||
'username' => 'helper',
|
||||
// 密码
|
||||
'password' => 'wjyBRncHHY2ls4Cd',
|
||||
// 端口
|
||||
'hostport' => 3306,
|
||||
// 连接dsn
|
||||
'dsn' => '',
|
||||
// 数据库连接参数
|
||||
// 'params' => [\PDO::ATTR_PERSISTENT => true],
|
||||
// 数据库编码默认采用utf8
|
||||
'charset' => 'utf8mb4',
|
||||
// 数据库表前缀
|
||||
'prefix' => '',
|
||||
// 数据库调试模式
|
||||
'debug' => false,
|
||||
// 是否严格检查字段是否存在
|
||||
'fields_strict' => true,
|
||||
// 数据集返回类型
|
||||
'resultset_type' => 'array',
|
||||
// 自动写入时间戳字段
|
||||
'auto_timestamp' => true,
|
||||
// 时间字段取出后的默认时间格式
|
||||
'datetime_format' => 'Y-m-d H:i',
|
||||
// 是否需要进行SQL性能分析
|
||||
'sql_explain' => false,
|
||||
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
|
||||
'deploy' => 0,
|
||||
// 数据库读写是否分离 主从式有效
|
||||
'rw_separate' => false,
|
||||
// 读写分离后 主服务器数量
|
||||
'master_num' => 1,
|
||||
// 指定从服务器序号
|
||||
'slave_no' => '',
|
||||
// 是否需要断线重连
|
||||
'break_reconnect' => true,
|
||||
];
|
||||
16
application/extra/paginate.php
Normal file
16
application/extra/paginate.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
use think\Request;
|
||||
|
||||
return [
|
||||
'type' => '\tools\Pager',
|
||||
'list_rows' => Request::instance()->get('pageSize', 15),
|
||||
'var_page' => 'page',
|
||||
'query' => Request::instance()->get(),
|
||||
];
|
||||
20
application/extra/session.php
Normal file
20
application/extra/session.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
//
|
||||
// +----------------------------------------------------------------------
|
||||
// | 会话设置
|
||||
// +----------------------------------------------------------------------
|
||||
return [
|
||||
'id' => '',
|
||||
'name' => 'CJANGO_SID',
|
||||
'var_session_id' => 'session_id',
|
||||
'prefix' => '',
|
||||
'type' => '',
|
||||
'auto_start' => true,
|
||||
];
|
||||
14
application/extra/storage.php
Normal file
14
application/extra/storage.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
|
||||
return [
|
||||
'size' => 20 * 1024 * 1024,
|
||||
'path' => './uploads/', // 保存路径
|
||||
'replace' => true, // 存在同名是否覆盖
|
||||
];
|
||||
17
application/extra/wechat.php
Normal file
17
application/extra/wechat.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
|
||||
return [
|
||||
'token' => 'A2aj8BtAv',
|
||||
'appid' => 'wxa655be02706ddeea',
|
||||
'secret' => '06196cb22490c323a5edcbf1d9e67403',
|
||||
'AESKey' => 'u7xi2oB8FcFJ4dn2MiP3wFhOaM65WQQUgHIpnbTnEiv',
|
||||
'mch_id' => '1486263952',
|
||||
'paykey' => 'CA72BE33311570FE25AFD91DE880376D',
|
||||
];
|
||||
35
application/index/config.php
Normal file
35
application/index/config.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
|
||||
return [
|
||||
// +----------------------------------------------------------------------
|
||||
// | 日志设置
|
||||
// +----------------------------------------------------------------------
|
||||
'log' => [
|
||||
'type' => 'file',
|
||||
'path' => LOG_PATH . 'index/',
|
||||
'time_format' => ' c ',
|
||||
'file_size' => 2097152,
|
||||
],
|
||||
// +----------------------------------------------------------------------
|
||||
// | 模板设置
|
||||
// +----------------------------------------------------------------------
|
||||
'template' => [
|
||||
'tpl_cache' => true,
|
||||
'strip_space' => false,
|
||||
'taglib_pre_load' => '',
|
||||
'cache_path' => TEMP_PATH . 'index/',
|
||||
],
|
||||
'view_replace_str' => [
|
||||
'__STATIC__' => '/static/index',
|
||||
'__JS__' => '/static/index/js',
|
||||
'__CSS__' => '/static/index/css',
|
||||
'__IMG__' => '/static/index/images',
|
||||
],
|
||||
];
|
||||
20
application/index/controller/Index.php
Normal file
20
application/index/controller/Index.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\index\controller;
|
||||
|
||||
use tools\Initialize;
|
||||
|
||||
class Index extends Initialize
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
dump(strtoupper(md5(uniqid())));
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
11
application/index/view/index/index.html
Normal file
11
application/index/view/index/index.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>{$Think.config.web_site_title}</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>{$Think.config.web_site_title}</h1>
|
||||
</body>
|
||||
</html>
|
||||
19
application/mobile/common.php
Normal file
19
application/mobile/common.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
use think\Loader;
|
||||
//幻灯
|
||||
function advert($id)
|
||||
{
|
||||
$info = Loader::model('Advert')->find($id);
|
||||
if ($info && $info->status == 1) {
|
||||
return $info->detail()->where('status', 1)->limit($info->limit)->order('sort asc')->select();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
53
application/mobile/config.php
Normal file
53
application/mobile/config.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
|
||||
return [
|
||||
// +----------------------------------------------------------------------
|
||||
// | 日志设置
|
||||
// +----------------------------------------------------------------------
|
||||
'log' => [
|
||||
'type' => 'file',
|
||||
'path' => LOG_PATH . 'mobile/',
|
||||
'time_format' => ' c ',
|
||||
'file_size' => 2097152,
|
||||
],
|
||||
// +----------------------------------------------------------------------
|
||||
// | 模板设置
|
||||
// +----------------------------------------------------------------------
|
||||
'template' => [
|
||||
'tpl_cache' => false,
|
||||
'strip_space' => false,
|
||||
'taglib_pre_load' => '',
|
||||
'cache_path' => TEMP_PATH . 'mobile/',
|
||||
],
|
||||
'view_replace_str' => [
|
||||
'__SELF__' => __SELF__,
|
||||
'__STATIC__' => '/static/mobile',
|
||||
'__JS__' => '/static/mobile/js',
|
||||
'__CSS__' => '/static/mobile/css',
|
||||
'__IMG__' => '/static/mobile/img',
|
||||
'__EDIT__' => '/static/mobile/edit',
|
||||
],
|
||||
'upload' => [
|
||||
'mimes' => [], // 允许上传的文件MiMe类型
|
||||
'maxSize' => 0, // 上传的文件大小限制 (0-不做限制)
|
||||
'exts' => [], // 允许上传的文件后缀
|
||||
'autoSub' => true, // 自动子目录保存文件
|
||||
'subName' => ['date', 'Y/m/d'], // 子目录创建方式,[0]-函数名,[1]-参数,多个参数使用数组
|
||||
'rootPath' => './uploads/', // 保存根路径
|
||||
'savePath' => '', // 保存路径
|
||||
'saveName' => ['uniqid', ''], // 上传文件命名规则,[0]-函数名,[1]-参数,多个参数使用数组
|
||||
'saveExt' => '', // 文件保存后缀,空则使用原后缀
|
||||
'replace' => false, // 存在同名是否覆盖
|
||||
'hash' => true, // 是否生成hash编码
|
||||
'callback' => true, // 检测文件是否存在回调,如果存在返回文件信息数组
|
||||
'driver' => 'local', // 文件上传驱动
|
||||
'driverConfig' => [], // 上传驱动配置
|
||||
],
|
||||
];
|
||||
28
application/mobile/controller/Ajax.php
Normal file
28
application/mobile/controller/Ajax.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\mobile\controller;
|
||||
|
||||
use app\common\model\ArticleModel as ArticleModelModel;
|
||||
|
||||
class Ajax extends _Init
|
||||
{
|
||||
public function _initialize()
|
||||
{
|
||||
if (!IS_AJAX) {
|
||||
return $this->error('请不要非法访问');
|
||||
}
|
||||
}
|
||||
|
||||
public function modelstyle()
|
||||
{
|
||||
$list = ArticleModelModel::where(['status' => 1])->select();
|
||||
$this->assign('list', $list);
|
||||
return $this->success($this->fetch('ajax/modelstyle'));
|
||||
}
|
||||
}
|
||||
146
application/mobile/controller/Article.php
Normal file
146
application/mobile/controller/Article.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\mobile\controller;
|
||||
|
||||
use app\common\model\Article as ArticleModel;
|
||||
use app\common\model\MemberInfo as MemberInfoModel;
|
||||
use app\common\service\Article as ArticleService;
|
||||
|
||||
class Article extends _Init
|
||||
{
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->nav = 1;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$map = [
|
||||
'uid' => UID,
|
||||
'status' => 1,
|
||||
];
|
||||
$list = ArticleModel::where($map)->order("id desc")->paginate(10);
|
||||
$this->assign('list', $list);
|
||||
if (IS_AJAX) {
|
||||
if (count($list) > 0) {
|
||||
return $this->success($this->fetch('article/lists'));
|
||||
} else {
|
||||
return $this->error('已经到最后一页');
|
||||
}
|
||||
}
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$info = ArticleModel::find($id);
|
||||
if (!empty($info)) {
|
||||
$info->setInc('click');
|
||||
}
|
||||
$this->assign('info', $info);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$data = $this->request->post();
|
||||
$data['uid'] = UID;
|
||||
$res = ArticleService::userAdd($data);
|
||||
if ($res === true) {
|
||||
return $this->success('发布成功', url('mobile/article/index'));
|
||||
} else {
|
||||
return $this->error('发布失败,' . $res);
|
||||
}
|
||||
} else {
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
public function edit($id = '')
|
||||
{
|
||||
if (IS_POST) {
|
||||
$data = $this->request->post();
|
||||
$info = ArticleModel::find($data['id'] ?: 0);
|
||||
|
||||
if ($info) {
|
||||
unset($data['id']);
|
||||
if ($info->save($data)) {
|
||||
return $this->success('发表成功', url('mobile/article/index'));
|
||||
} else {
|
||||
return $this->error('发表失败');
|
||||
}
|
||||
} else {
|
||||
return $this->error('您修改的文章已不存在');
|
||||
}
|
||||
} else {
|
||||
$info = ArticleModel::find($id);
|
||||
if ($info->uid != UID) {
|
||||
$this->redirect(url('center/index'));
|
||||
}
|
||||
$this->assign('info', $info);
|
||||
return $this->fetch('add');
|
||||
}
|
||||
}
|
||||
|
||||
public function collect()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$info = MemberInfoModel::get(UID);
|
||||
if (!$info->is_vip) {
|
||||
return $this->error('采集失败,您还不是VIP。', url('vip/index'));
|
||||
}
|
||||
$url = $this->request->post('url') ?: '';
|
||||
if ($url) {
|
||||
if (!preg_match('/(http:\/\/)|(https:\/\/)/i', $url)) {
|
||||
return $this->error('您粘贴的地址不正确!');
|
||||
}
|
||||
if (!preg_match('/(mp.weixin.qq.com)/i', $url)) {
|
||||
return $this->error('您粘贴的地址不是微信文章地址!');
|
||||
}
|
||||
$id = ArticleService::collect($url, UID);
|
||||
if ($id) {
|
||||
return $this->success('采集成功', url('mobile/article/edit', 'id=' . $id));
|
||||
} else {
|
||||
return $this->error('采集失败');
|
||||
}
|
||||
} else {
|
||||
return $this->error('请输入文章地址');
|
||||
}
|
||||
} else {
|
||||
$this->nav = 2;
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
public function del($id)
|
||||
{
|
||||
if (IS_AJAX) {
|
||||
$info = ArticleModel::find($id);
|
||||
if ($info->uid != UID) {
|
||||
return $this->error('非法操作');
|
||||
} else {
|
||||
if ($info->delete()) {
|
||||
return $this->success('删除成功');
|
||||
} else {
|
||||
return $this->error('删除失败');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return $this->error('请不要非法访问');
|
||||
}
|
||||
}
|
||||
|
||||
public function video()
|
||||
{
|
||||
$this->meta_title = '发布文章视频教程';
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
47
application/mobile/controller/Cause.php
Normal file
47
application/mobile/controller/Cause.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\mobile\controller;
|
||||
|
||||
use app\common\model\Content as ContentModel;
|
||||
use app\common\service\Content as ContentService;
|
||||
|
||||
class Cause extends _Init
|
||||
{
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->nav = 2;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->list = ContentService::categoryList('cause');
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function lists($category)
|
||||
{
|
||||
$this->list = ContentModel::where('category_id', $category)->where('status', 1)->order('create_time desc')->paginate(20);
|
||||
if (IS_AJAX) {
|
||||
if (count($this->list) > 0) {
|
||||
return $this->success($this->fetch('cause/list'));
|
||||
} else {
|
||||
return $this->error('已经到最后一页');
|
||||
}
|
||||
}
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function detail($id)
|
||||
{
|
||||
parent::shareArticle();
|
||||
$this->info = ContentModel::where('id', $id)->where('status', 1)->find();
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
73
application/mobile/controller/Center.php
Normal file
73
application/mobile/controller/Center.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\mobile\controller;
|
||||
|
||||
use app\common\model\Member as MemberModel;
|
||||
|
||||
class Center extends _Init
|
||||
{
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->user = MemberModel::find(UID);
|
||||
$this->nav = 5;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 操作成功跳转的快捷方法
|
||||
* @access protected
|
||||
* @param mixed $msg 提示信息
|
||||
* @param string $url 跳转的URL地址
|
||||
* @param mixed $data 返回的数据
|
||||
* @param integer $wait 跳转等待时间
|
||||
* @param array $header 发送的Header信息
|
||||
* @return void
|
||||
*/
|
||||
protected function success($msg = '', $url = null, $data = '', $wait = 3, array $header = [])
|
||||
{
|
||||
$msg = $msg ?: '操作成功';
|
||||
return parent::success($msg, $url, $data, $wait, $header);
|
||||
}
|
||||
|
||||
/**
|
||||
* 操作错误跳转的快捷方法
|
||||
* @access protected
|
||||
* @param mixed $msg 提示信息
|
||||
* @param string $url 跳转的URL地址
|
||||
* @param mixed $data 返回的数据
|
||||
* @param integer $wait 跳转等待时间
|
||||
* @param array $header 发送的Header信息
|
||||
* @return void
|
||||
*/
|
||||
protected function error($msg = '', $url = null, $data = '', $wait = 3, array $header = [])
|
||||
{
|
||||
$msg = $msg ?: '未知错误';
|
||||
return parent::error($msg, $url, $data, $wait, $header);
|
||||
}
|
||||
|
||||
protected function back($result)
|
||||
{
|
||||
if ($result === true) {
|
||||
return $this->success();
|
||||
} else {
|
||||
return $this->error($result);
|
||||
}
|
||||
}
|
||||
|
||||
public function tishi()
|
||||
{
|
||||
return $this->fetch('');
|
||||
}
|
||||
}
|
||||
135
application/mobile/controller/Experience.php
Normal file
135
application/mobile/controller/Experience.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\mobile\controller;
|
||||
|
||||
use app\common\model\Experience as ExperienceModel;
|
||||
use app\common\model\MemberInfo as MemberInfoModel;
|
||||
use app\common\service\Experience as ExperienceService;
|
||||
|
||||
class Experience extends _Init
|
||||
{
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->nav = 5;
|
||||
}
|
||||
|
||||
public function checkVip($title)
|
||||
{
|
||||
$info = MemberInfoModel::get(UID);
|
||||
if (!$info->is_vip) {
|
||||
return $this->error('您还不是vip,不能' . $title, url('vip/index'));
|
||||
}
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$map = [
|
||||
'pid' => 0,
|
||||
'status' => 1,
|
||||
];
|
||||
$this->list = ExperienceModel::where($map)->order('id desc')->paginate(10);
|
||||
|
||||
if (IS_AJAX) {
|
||||
if (count($this->list) > 0) {
|
||||
return $this->success($this->fetch('experience/lists'));
|
||||
} else {
|
||||
return $this->error('已经到最后一页');
|
||||
}
|
||||
}
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交评论
|
||||
* @param [type] $id [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function detail($id)
|
||||
{
|
||||
parent::shareArticle();
|
||||
|
||||
if (IS_POST) {
|
||||
self::checkVip('评论');
|
||||
$content = $this->request->post('content');
|
||||
$res = ExperienceService::comment($id, UID, $content);
|
||||
return $this->back($res);
|
||||
} else {
|
||||
$this->info = ExperienceModel::get($id);
|
||||
$this->info->setInc('click');
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 点赞
|
||||
* @param [type] $id [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function tags($id)
|
||||
{
|
||||
self::checkVip('点赞');
|
||||
$res = ExperienceService::tags(UID, $id);
|
||||
if ($res === true) {
|
||||
return $this->success();
|
||||
} else {
|
||||
return $this->error($res);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 我的分享
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function mine()
|
||||
{
|
||||
$map = [
|
||||
'pid' => 0,
|
||||
'uid' => UID,
|
||||
'status' => 1,
|
||||
];
|
||||
$this->list = ExperienceModel::where($map)->order('id desc')->paginate(10);
|
||||
|
||||
if (IS_AJAX) {
|
||||
if (count($this->list) > 0) {
|
||||
return $this->success($this->fetch('experience/minelists'));
|
||||
} else {
|
||||
return $this->error('已经到最后一页');
|
||||
}
|
||||
}
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
if (IS_POST) {
|
||||
self::checkVip('添加信息');
|
||||
$data = $this->request->post();
|
||||
$res = ExperienceService::add($data, UID);
|
||||
if ($res === true) {
|
||||
return $this->success('添加成功!', url('Experience/index'));
|
||||
} else {
|
||||
return $this->error('添加失败!');
|
||||
}
|
||||
} else {
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param [type] $id [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function del($id)
|
||||
{
|
||||
$res = ExperienceService::del($id, UID);
|
||||
return $this->back($res);
|
||||
}
|
||||
}
|
||||
63
application/mobile/controller/Help.php
Normal file
63
application/mobile/controller/Help.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\mobile\controller;
|
||||
|
||||
use app\common\model\Direct as DirectModel;
|
||||
use app\common\model\Help as HelpModel;
|
||||
|
||||
class Help extends _Init
|
||||
{
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->nav = 4;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function desc()
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function lists($category)
|
||||
{
|
||||
$this->list = HelpModel::where(['status' => 1, 'category' => $category])->select();
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function detail($id)
|
||||
{
|
||||
parent::shareArticle();
|
||||
$this->info = HelpModel::get($id);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 直销技巧
|
||||
*/
|
||||
public function direct()
|
||||
{
|
||||
$this->list = DirectModel::where('status', 1)->order('sort desc,id desc')->select();
|
||||
$this->nav = 5;
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function directDetail($id)
|
||||
{
|
||||
$this->info = DirectModel::get($id);
|
||||
$this->info->setInc('click');
|
||||
$this->nav = 4;
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
47
application/mobile/controller/Index.php
Normal file
47
application/mobile/controller/Index.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\mobile\controller;
|
||||
|
||||
use app\common\model\MemberInfo;
|
||||
|
||||
class Index extends _Init
|
||||
{
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->nav = 1;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
if (UID || $this->shareUser) {
|
||||
if ($this->shareUser) {
|
||||
$this->info = $this->shareUser;
|
||||
} else {
|
||||
$this->info = MemberInfo::get(UID);
|
||||
}
|
||||
|
||||
return $this->fetch('user_' . $this->info['index_tpl']);
|
||||
} else {
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
public function info()
|
||||
{
|
||||
if (UID == $this->shareUser['uid']) {
|
||||
$this->info = MemberInfo::get(UID);
|
||||
} else {
|
||||
$this->info = $this->shareUser;
|
||||
}
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
42
application/mobile/controller/Invite.php
Normal file
42
application/mobile/controller/Invite.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\mobile\controller;
|
||||
|
||||
use app\common\model\MemberInfo as MemberInfoModel;
|
||||
use Endroid\QrCode\QrCode;
|
||||
|
||||
class Invite extends _Init
|
||||
{
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->nav = 5;
|
||||
}
|
||||
|
||||
public function index($uid = '')
|
||||
{
|
||||
if (empty($uid)) {
|
||||
$uid == UID;
|
||||
}
|
||||
$qr = new QrCode();
|
||||
$url = url('login/reg', 'invite=' . $uid);
|
||||
$this->img = $qr->setText($url)->setSize(350)->writeDataUri();
|
||||
|
||||
$info = MemberInfoModel::get($uid);
|
||||
if (empty($info)) {
|
||||
$this->redirect('login/info', 'title=邀请人已经被删除或者禁用');
|
||||
}
|
||||
$info['description'] = '';
|
||||
$info['title'] = $info['nickname'];
|
||||
$info['thumb'] = $info['avatar'];
|
||||
$this->assign('info', $info);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
}
|
||||
157
application/mobile/controller/Login.php
Normal file
157
application/mobile/controller/Login.php
Normal file
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
// +------------------------------------------------+
|
||||
// |http://www.cjango.com |
|
||||
// +------------------------------------------------+
|
||||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||||
// +------------------------------------------------+
|
||||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||||
// +------------------------------------------------+
|
||||
namespace app\mobile\controller;
|
||||
|
||||
use app\common\model\Member as MemberModel;
|
||||
use app\common\service\Member as MemberService;
|
||||
use app\common\service\Sms as SmsService;
|
||||
use app\common\validate\Member as MemberValidate;
|
||||
use cjango\Wechat\Oauth;
|
||||
|
||||
class Login extends _Init
|
||||
{
|
||||
public function _initialize()
|
||||
{
|
||||
// parent::fenxiang();
|
||||
$this->showWx = 1;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$user = $this->request->post('username');
|
||||
$pass = $this->request->post('password');
|
||||
$res = MemberService::login($user, $pass);
|
||||
if ($res === true) {
|
||||
return $this->success('登录成功', 'center/index');
|
||||
} else {
|
||||
return $this->error($res);
|
||||
}
|
||||
} else {
|
||||
if (parent::isLogin()) {
|
||||
$this->redirect('center/index');
|
||||
}
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function reg($invite = 0)
|
||||
{
|
||||
if (IS_POST) {
|
||||
$user = $this->request->post('username');
|
||||
$pass = $this->request->post('password');
|
||||
$repass = $this->request->post('repassword');
|
||||
$code = $this->request->post('mobile_code');
|
||||
|
||||
//校验注册数据
|
||||
$data = [
|
||||
'username' => $user,
|
||||
'password' => $pass,
|
||||
'repass' => $repass,
|
||||
];
|
||||
$validate = new MemberValidate();
|
||||
if (!$validate->scene('mobileRegister')->check($data)) {
|
||||
return $this->error($validate->getError());
|
||||
}
|
||||
|
||||
//验证码校验
|
||||
$checkCode = SmsService::check($user, $code);
|
||||
if ($checkCode !== true) {
|
||||
return $this->error($checkCode);
|
||||
}
|
||||
|
||||
$res = MemberService::register($user, $pass, 1, $invite);
|
||||
if ($res === true) {
|
||||
return $this->success('注册成功', 'login/index');
|
||||
} else {
|
||||
return $this->error($res);
|
||||
}
|
||||
} else {
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 忘记密码
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function forget()
|
||||
{
|
||||
if (IS_POST) {
|
||||
$mobile = $this->request->post('mobile');
|
||||
$pass = $this->request->post('password');
|
||||
$repass = $this->request->post('repassword');
|
||||
$code = $this->request->post('mobile_code');
|
||||
//验证码校验
|
||||
$checkCode = SmsService::check($mobile, $code);
|
||||
if ($checkCode !== true) {
|
||||
return $this->error($checkCode);
|
||||
}
|
||||
$userInfo = MemberModel::where('username', $mobile)->find();
|
||||
$data = [
|
||||
'newpass' => $pass,
|
||||
'repass' => $repass,
|
||||
];
|
||||
$validate = new MemberValidate();
|
||||
if (!$validate->scene('forget')->check(['newpass' => $pass, 'repass' => $repass])) {
|
||||
return $this->error($validate->getError());
|
||||
}
|
||||
if (!$userInfo) {
|
||||
return '没有这个用户';
|
||||
} elseif ($userInfo->save(['password' => $pass])) {
|
||||
return $this->success('', url('login/index'));
|
||||
} else {
|
||||
return $this->error('更新失败');
|
||||
}
|
||||
|
||||
}
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
// 自动登录
|
||||
public function autoLogin()
|
||||
{
|
||||
parent::initWechat();
|
||||
$token = Oauth::token();
|
||||
if (!$token) {
|
||||
$url = Oauth::url(url('login/autoLogin'));
|
||||
$this->redirect($url);
|
||||
} else {
|
||||
$openid = $token['openid'];
|
||||
$res = MemberService::openid_login($openid);
|
||||
if ($res === true) {
|
||||
$this->redirect(url('center/index'));
|
||||
} else {
|
||||
$this->redirect(url('login/info', ['title' => $res]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 信息提示 错误提示
|
||||
* @param [type] $title [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function info($title)
|
||||
{
|
||||
|
||||
$this->info = $title;
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
MemberService::logout();
|
||||
return $this->success('退出成功', 'login/index');
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user