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