1
0

first commit

This commit is contained in:
2020-08-06 14:58:51 +08:00
commit 17096657dc
780 changed files with 92857 additions and 0 deletions

View 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);
}
}

View 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') ?: '';
}
}

View 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');
}
}

View 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;
});
}
}

View 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();
}
}

View 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');
}
}

View 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 ?? '没有';
}
}

View File

@@ -0,0 +1,13 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\model;
class City extends _Init
{
}

View 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;
}
}

View 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');
}
}

View 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');
}
}

View 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;
}
}

View 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;
}

View 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);
}
}

View 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 '';
}
}
}

View 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();
}
}

View 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();
}
}

View File

@@ -0,0 +1,14 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\model;
class MemberList extends _Init
{
}

View 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);
}
}

View 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');
}
}

View 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) {
});
}
}

View 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']);
}
}

View 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);
}
}

View 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;
}
}
}

View 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;
}

View 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');
}
}

View File

@@ -0,0 +1,14 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\model;
class Template extends _Init
{
}

View 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');
}
}

View 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;
}
}
}

View 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 '设置失败';
}
}
}

View 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 '设置失败';
}
}
}

View 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;
}
}
}
}

View 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 '删除失败';
}
}
}

View 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 '移除授权失败';
}
}
}

View 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 '设置状态失败';
}
}
}

View 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 [];
}
}
}

View 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;
}
}

View 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();
}
}

View 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;
}
}

View 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 '删除失败';
}
}
}

View 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 '删除失败';
}
}
}

View 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 '删除失败';
}
}
}

View 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);
}
}

View 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 '解除绑定失败';
}
}
}

View 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);
}
}
}

View 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 '删除失败';
}
}
}

View 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 '设置菜单状态失败';
}
}
}

View 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);
}
}

View 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;
}
}

View 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 '删除失败';
}
}
}

View 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;
}
}
}

View 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();
}
}
}

View File

@@ -0,0 +1,14 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\service;
class Suggest extends _Init
{
}

View 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;
}
}

View 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;
}
}

View 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' => '显示上限必须填数字',
];
}

View 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;
}
}
}

View 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;
}
}

View 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' => '内容必须填写',
];
}

View 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' => '不合法的分组状态',
];
}

View 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;
}
}
}

View 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' => '配置值必须填写',
];
}

View 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'],
];
}

View 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'],
];
}

View 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' => '内容必须填写',
];
}

View 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'],
];
}

View 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');
}
}

View 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);
}
}

View 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;
}
}

View 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'],
];
}

View 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'],
];
}

View 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'],
];
}

View 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);
}
}

View 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 = [
];
}