first commit

This commit is contained in:
2020-08-06 15:26:41 +08:00
commit 8c0aa3edc1
1416 changed files with 238374 additions and 0 deletions

103
application/common.php Normal file
View File

@@ -0,0 +1,103 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------
// 应用公共文件
//
use think\Db;
function get_array_url($k = '', $value = '', $emp = '')
{
$url = \think\Request::instance()->get();
unset($url['s']);
if ($k) {
if (isset($url[$k])) {
if ($value) {
$url[$k] = $value;
} else {
unset($url[$k]);
}
} else {
if ($value) {
$url[$k] = $value;
}
}
}
if ($emp) {
$array = explode(',', $emp);
if (is_array($array)) {
foreach ($array as $key => $value) {
if (isset($url[$value])) {
unset($url[$value]);
}
}
}
}
return http_build_query($url);
}
/**
* curl操作函数
* @param string $url 请求地址
* @param string $method 提交方式
* @param array $postFields 提交内容
* @param array $header 请求头
* @return mixed 返回数据
*/
function http($url, $method = "GET", $postFields = null, $headers = null)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
if (!is_null($postFields)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
}
//https request
if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
if (is_array($headers) && 0 < count($headers)) {
$httpHeaders = [];
foreach ($headers as $key => $value) {
array_push($httpHeaders, $key . ":" . $value);
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders);
}
$data = curl_exec($ch);
$err = curl_errno($ch);
curl_close($ch);
if ($err > 0) {
return curl_error($ch);
} else {
return $data;
}
}
function get_income($uid, $touid)
{
$map = [
'uid' => $touid,
'fromuser' => $uid,
];
$all = Db::name('AccountLogs')->where($map)->sum('increase') ?? '0.00';
return $all;
}
// 过滤掉特殊字符保留 中文 英文 数字 ,。【】
function check_text($str)
{
preg_match_all('/[\x{4e00}-\x{9fa5}\。\.a-zA-Z0-9【】,-]/u', $str, $jg);
return join('', $jg[0]);
}

View File

@@ -0,0 +1,57 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\service;
use app\common\service\WechatTpl as WechatTplService;
/**
* 信息
*/
class Sendtplmsg extends _Init
{
//开通7天vip试用-模版消息推送
public static function opened_7days($member)
{
if($member->openid){
$tpl_user = [
'openid' => $member->openid,
'first' => '恭喜您获得推广先锋7天试用特权',
'title' => '推广先锋7天试用',
'end_time' => $member->info->vip_time,
'remark' => '感谢您的使用。',
'url' => url('center/index')
];
WechatTplService::send_vip7days_opened($tpl_user);
}
}
//7天试用到/推广先锋/推广代理商期提醒-模版消息推送
public static function services_ending($member,$type = 1)
{
if($member->openid){
$tpl_user = [
'openid' => $member->openid,
'first' => '您的服务即将到期。',
'title' => $type == 1 ? $member->info->is_vip == 1 ? '推广先锋' : '推广先锋7天试用' : '推广代理商',
'end_time' => $type == 1 ? $member->info->vip_time : $member->info->agent_time,
'remark' => '避免影响试用,请您及时续费。',
'url' => url('center/index')
];
WechatTplService::send_ending($tpl_user);
}
}
}

View File

@@ -0,0 +1,34 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\model;
class Account extends _Init
{
protected function user()
{
return $this->hasOne('Member', 'id', 'uid');
}
protected function userinfo()
{
return $this->belongsTo('MemberInfo', 'uid', 'uid');
}
public function users()
{
return $this->belongsTo('Member', 'uid', 'id');
}
public function logs()
{
return $this->hasMany('AccountLogs', 'uid', 'uid');
}
}

View File

@@ -0,0 +1,66 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\model;
class AccountLogs extends _Init
{
/**
* 关闭更新时间写入
*/
protected $updateTime = false;
public function getTypeTextAttr($value, $data)
{
return Config::getValue($data['type'], 'account_type');
}
protected function getCreateTimeAttr($value)
{
return date('Y-m-d', $value);
}
protected function getIncreaseFormartAttr($value, $data)
{
if ($data['increase'] > 0) {
return '+' . $data['increase'];
} else {
return $data['increase'];
}
}
protected function getFreezTextAttr($value, $data)
{
switch ($data['freezing']) {
case 0:
return '发放';
break;
case 1:
return '未发放';
break;
default:
return '错误';
break;
}
}
protected function user()
{
return $this->hasOne('Member', 'id', 'uid');
}
protected function rules()
{
return $this->belongsTo('AccountRules', 'rule_id');
}
protected function fuser()
{
return $this->hasOne('Member', 'id', 'fromuser');
}
}

View File

@@ -0,0 +1,32 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\model;
class AccountRules extends _Init
{
public function getTypeTextAttr($value, $data)
{
return Config::getValue($data['type'], 'account_type');
}
protected function getTimesTextAttr($value, $data)
{
switch ($data['times']) {
case 0:
return '无限制';
break;
case -1:
return '一次性';
break;
default:
return $data['times'] . '次/日';
break;
}
}
}

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,43 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\model;
class Banner 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') ?? '';
}
public function member()
{
return $this->belongsTo('Member', 'id', 'uid');
}
public function user()
{
return $this->belongsTo('MemberInfo', 'uid', 'uid');
}
}

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,55 @@
<?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->hasOne('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']])->count();
return $res;
}
public function gettags()
{
return $this->hasMany('ExperienceTags', 'experience_id', 'id');
}
public function getTagsNicknameAttr($value, $data)
{
$list = ExperienceTags::where(['experience_id' => $data['id']])->select();
$name = [];
foreach ($list as $key => $value) {
if (!empty($value->user->nickname)) {
$name[] = $value->user->nickname;
}
}
return implode('、', $name);
}
}

View File

@@ -0,0 +1,19 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\model;
class ExperienceTags extends _Init
{
protected $updateTime = false;
public function user()
{
return $this->hasOne('MemberInfo', 'uid', 'uid');
}
}

View File

@@ -0,0 +1,40 @@
<?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 getYCategoryAttr($value, $data)
{
return $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,123 @@
<?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();
$data->status = 1;
});
}
/**
* 格式化 最后登录时间
* @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);
}
/**
* 用户资料
*/
public function info()
{
return $this->hasOne('MemberInfo', 'uid', 'id');
}
public function account()
{
return $this->hasOne('Account', 'uid', 'id');
}
public function logs($type = '')
{
if ($type) {
return $this->belongsTo('AccountLogs', 'id', 'uid')->where('type', $type);
} else {
return $this->belongsTo('AccountLogs', 'id', 'uid');
}
}
/**
* 关联 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();
}
public function getVipIsEmptyAttr($value, $data)
{
switch ($data['empty_vip']) {
case '0':
return "";
break;
case '1':
return "<span style='color:red' > 是 </span>";
break;
default:
return "";
break;
}
}
public function getAgentIsEmptyAttr($value, $data)
{
switch ($data['empty_agent']) {
case '0':
return "";
break;
case '1':
return "<span style='color:red' > 是 </span>";
break;
default:
return "";
break;
}
}
public function puser()
{
return $this->hasOne('Member', 'id', 'pid');
}
public function childs()
{
return $this->hasMany('Member', 'pid', 'id');
}
}

View File

@@ -0,0 +1,174 @@
<?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');
} elseif (empty($avatar)) {
return '/static/mobile/images/head.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 ?? '';
}
/**
* 获取头像地址
* @param [type] $value [description]
* @param [type] $data [description]
* @return [type] [description]
*/
protected function getYQrcodeAttr($value, $data)
{
return $data['qrcode'];
}
/**
* 判断用户是否为 未过期的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 '推广先锋';
} 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();
}
/**
* 判断用户是否为 代理商
* @param [type] $value [description]
* @param [type] $data [description]
* @return [type] [description]
*/
protected function getIsAgentAttr($value, $data)
{
if ($data['agent_time'] > time() && $data["is_agent"] == 1) {
return 1;
} else {
return 0;
}
}
protected function getAgentTextAttr($value, $data)
{
if ($data['agent_time'] > time() && $data["is_agent"] == 1) {
return '推广代理商';
} else {
return '未开通代理';
}
}
protected function getAgentTimeAttr($value, $data)
{
if ($value < time()) {
return '';
} else {
return date('Y-m-d', $value);
}
}
protected function getAgentEndTimeAttr($value, $data)
{
return $data['agent_time'];
}
public function member()
{
return $this->hasOne('Member', 'id', 'uid');
}
protected function getBannerImgAttr($value, $data)
{
$banner = Banner::where('uid', $data['uid'])->find();
if ($banner) {
return $banner->cover;
} else {
return '';
}
}
protected function getBannerUrlAttr($value, $data)
{
$banner = Banner::where('uid', $data['uid'])->find();
if ($banner) {
return $banner->url;
} else {
return '';
}
}
}

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,54 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\model;
use think\Config;
class MemberSet extends _Init
{
/**
* 关闭更新时间写入
*/
protected $updateTime = false;
/**
* 模型初始化【事件注册】
*/
protected static function init()
{
self::beforeInsert(function ($data) {
});
}
public function getTypeTextAttr($value, $data)
{
switch ($data['type']) {
case 'vip':
return Config::get('role_type.vip');
break;
case 'agent':
return Config::get('role_type.agent');
break;
default:
return "未知";
break;
}
}
protected function user()
{
return $this->hasOne('Member', 'id', 'uid');
}
public function operation()
{
return $this->hasOne('Member', 'id', 'operator');
}
}

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,26 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\model;
class Permission extends _Init
{
protected function setVipAttr($value)
{
return self::parseStatus($value);
}
protected function getVipTextAttr($value, $data)
{
if ($data['vip'] == 1) {
return '是';
} else {
return '否';
}
}
}

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,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,78 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\model;
class Suggest extends _Init
{
/**
* 模型初始化【事件注册】
*/
protected static function init()
{
self::beforeInsert(function ($data) {
$data->status = 1;
});
}
public function member()
{
return $this->hasOne('Member', 'id', 'uid');
}
public function child()
{
return $this->hasMany('Suggest', 'pid', 'id')->order('create_time asc');
}
public function last()
{
return $this->hasOne('Suggest', 'pid', 'id')->order('create_time desc');
}
protected function getCreateTimeAttr($value, $data)
{
return $data['create_time'] ? date('Y-m-d H:i:s', $data['create_time']) : '无';
}
protected function getStatusTextAttr($value, $data)
{
switch ($data['status']) {
case 2:
return '关闭';
break;
case 1:
return '正常';
break;
default:
return '状态错误';
break;
}
}
public function getWhoAttr($value, $data)
{
return ($data['uid'] == UID) ? 'me' : 'user';
}
//是否是新消息
public function getIsNewAttr($value, $data)
{
$last = $this->last;
if (!$last) {
return 0;
} else {
if ($last->uid != UID && $last->read != 1) {
return 1;
} else {
return 0;
}
}
}
}

View File

@@ -0,0 +1,28 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\model;
class Team extends _Init
{
/**
* 模型初始化【事件注册】
*/
protected static function init()
{
self::beforeInsert(function ($data) {
$data->status = 1;
});
}
public function member()
{
return $this->hasOne('Member', 'id', '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,71 @@
<?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 = ($data['type'] == 'vip') ? Str::orderid('VIP') : Str::orderid('Agent');
});
}
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 {
return '未知';
}
}
public function getTypeTextAttr($value, $data)
{
switch ($data['type']) {
case 'vip':
return "会员";
break;
case 'agent':
return "代理商";
break;
default:
return "未知";
break;
}
}
public function user()
{
return $this->belongsTo('MemberInfo', 'uid', 'uid');
}
public function member()
{
return $this->belongsTo('Member', 'uid', 'id');
}
}

View File

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

View File

@@ -0,0 +1,48 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\model;
class Withdrawal extends _Init
{
protected function user()
{
return $this->hasOne('Member', 'id', 'uid');
}
public function userinfo()
{
return $this->hasOne('MemberInfo', 'uid', 'uid');
}
protected function getStatusTextAttr($value, $data)
{
switch ($data['status']) {
case 1:
return '<span style="color:orangered">待审核</span>';
break;
case 2:
return '<span style="color:darkgreen">通过</span>';
break;
case 3:
return '<span style="color:red">驳回</span>';
break;
default:
return '状态错误';
break;
}
}
//审核操作人
public function inguser()
{
return $this->hasOne('Member', 'id', 'audit');
}
}

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,190 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\service;
use app\common\model\Account as AccountModel;
use app\common\model\AccountLogs as AccountLogsModel;
use app\common\model\AccountRules as AccountRulesModel;
use app\common\model\Member as MemberModel;
use app\common\model\VipOrder as VipOrderModel;
use app\common\service\Member as MemberService;
use think\Config;
use think\Db;
use tools\Time;
class Account extends _Init
{
/**
* [add description]
* @param [type] $data [description]
*/
public static function create($uid)
{
$info = AccountModel::find($uid);
if (!$info) {
$data = [
'uid' => $uid,
];
AccountModel::create($data);
}
}
/**
* 对某一个用户执行账户规则
* @param [type] $uid [执行用户]
* @param [type] $rule [规则ID或关键字]
* @param integer $increase [执行数量/如果规则写了固定数量可以为空]
* @param string $remark [规则描述,空为规则默认描述]
* @param integer $fromuser [溯源用户ID,可以为空]
* @param integer $freezing [是否冻结1冻结 0即时到账]
* @param string $ordeid [关联订单ID 可以为空]
* @return [type] [description]
*/
public static function rule($uid, $rule, $increase = 0, $remark = '', $fromuser = 0, $freezing = 0, $orderid = '')
{
if (is_numeric($rule)) {
$ruleMap['id'] = $rule;
} else {
$ruleMap['name'] = $rule;
}
$rule = AccountRulesModel::where($ruleMap)->find();
if (!$rule) {
return '规则不存在';
}
$account = AccountModel::where('uid', $uid)->find();
$balance = $account->getData($rule->type);
if ($rule->times == -1 && AccountLogsModel::where(['rule_id' => $rule->id, 'uid' => $uid])->find()) {
return '用户行为已经执行过';
} elseif ($rule->times > 0) {
// 判断当日最大可执行次数
$todayTime = \tools\Time::day();
$AccountLog = AccountLogsModel::where(['rule_id' => $rule->id, 'uid' => $uid, 'create_time' => ['between', $todayTime]])->count('id');
if ($AccountLog >= $rule->times) {
return '今日行为次数已用尽';
}
}
if ($increase != 0) {
$rule->increase = $increase;
}
if ($rule->increase < 0 && $balance < abs($rule->increase)) {
return '账户余额不足';
}
if (!$remark) {
$remark = $rule->remark;
}
Db::startTrans();
$ruleLog = [
'uid' => $uid,
'rule_id' => $rule->id,
'type' => $rule->type,
'increase' => $rule->increase,
'balance' => $balance + $rule->increase,
'remark' => $remark,
'fromuser' => $fromuser,
'freezing' => $freezing,
'orderid' => $orderid,
];
if (AccountLogsModel::create($ruleLog)) {
if (!$freezing) {
AccountModel::where(['uid' => $uid])->exp($rule->type, $rule->type . '+' . $rule->increase)->update();
}
Db::commit();
return true;
} else {
Db::rollback();
return '行为执行失败';
}
}
//推荐奖
public static function commission($orderid)
{
$order = VipOrderModel::where('orderid', $orderid)->find();
if ($order->commission == 1) {
return "已经执行过了";
}
$user = $order->member ?? '';
if ($order && $user) {
$puser = $user->puser;
if ($puser) {
$share_commission = Config::get('share_commission');
$cash = round($order->money * $share_commission, 2); //计算实际获得金额
$res = self::rule($puser->id, 'open_' . $order->type, $cash, '', $order->uid, '', $order->orderid);
if ($res === true && $puser->openid) {
$account = [
'openid' => $puser->openid,
'create_time' => date('Y-m-d'),
'increase' => (string) $cash,
'balance' => $puser->account->price,
];
if ($order->type == 'vip') {
$type = 1;
} elseif ($order->type == 'agent') {
$type = 2;
} else {
$type = '';
}
//加模板消息
Tmplmsg::account($account);
self::management($puser, $cash, $order->orderid);
}
}
$order->commission = 1;
$order->save();
}
}
//管理奖
protected static function management($user, $money, $orderid)
{
$plist = MemberService::getSub($user->id);
if ($plist) {
$management_ratio = Config::get('management_ratio');
$prev = $user->id;
foreach ($plist as $key => $p) {
$puser = MemberModel::get($p);
//如果不是代理商分润到此
if ($puser->info->is_agent != 1) {
break;
}
$temp = $money * $management_ratio;
if ($temp < 0.01) {
break;
}
$cash = intval($temp * 100) / 100;
$res = self::rule($p, 'management', $cash, '', $prev, '', $orderid);
if ($res && $puser->openid) {
$account = [
'openid' => $puser->openid,
'create_time' => date('Y-m-d'),
'increase' => (string) $cash,
'balance' => $puser->account->price,
];
//加模板消息
Tmplmsg::account($account);
}
$money = $cash;
$prev = $p;
}
}
}
}

View File

@@ -0,0 +1,101 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\service;
use app\common\model\AccountRules as AccountRulesModel;
use app\common\validate\AccountRules as AccountRulesValidate;
class AccountRules extends _Init
{
/**
* [add description]
* @param [type] $data [description]
*/
public static function create($data)
{
$validate = new AccountRulesValidate();
if (!$validate->check($data)) {
return $validate->getError();
}
$info = AccountRulesModel::create($data);
if ($info) {
return true;
} else {
return '添加失败';
}
}
/**
* [edit description]
* @param [type] $data [description]
* @return [type] [description]
*/
public static function edit($data)
{
$validate = new AccountRulesValidate();
if (!$validate->check($data)) {
return $validate->getError();
}
$info = AccountRulesModel::update($data);
if ($info) {
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)
{
$info = AccountRulesModel::get($id);
if (!$info) {
return '规则不存在';
} elseif ($info->save(['status' => $status])) {
return true;
} else {
return '修改状态失败';
}
}
/**
* [del description]
* @param [type] $id [description]
* @return [type] [description]
*/
public static function del($id)
{
$model = new AccountRulesModel();
if ($model->destroy($id)) {
return true;
} else {
return '删除失败';
}
}
public static function get_ids($rules)
{
$ru = explode(',', $rules);
$ids = array();
foreach ($ru as $key => $value) {
$map = [
'name' => $value,
];
$ids[] = \think\Db::name('AccountRules')->where($map)->value('id') ?: '';
}
return $ids;
}
}

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,528 @@
<?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\validate\Article as ArticleValidate;
use tools\Str;
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) {
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 collect2($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]));
$title = self::get_title($title);
//拼接正确的内容标签
$content = "<div id='js_content' class='ce-padding-sm'>" . $content[1][0];
//将所有图片的data-src更改为src
//获取所有图片地址
$parrent = "/[img|IMG].*?src=([\"|']?)([^\"'>]+.(jpg|JPG|jpeg|JPEG|gif|GIF|png|PNG))/i";
preg_match_all($parrent, $content, $img);
/* $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[2] as $key => $value) {
//判断图片是否存在http头
if (preg_match('/(http:\/\/)|(https:\/\/)/i', $value)) {
//分割微信图片地址
$str = explode('/', $value);
//获取图片地址名称,不包括拓展名
if (count($str) < 5) {
continue;
}
// $allname = $str[4];
$allname = $str[5];
//识别拓展名
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);
}
$description = self::get_description($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' => $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) {
return $info->id;
} else {
return false;
}
}
}
/**
* 采集公众号文章
* @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) {
$info->delete();
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]));
$title = self::get_title($title);
//拼接正确的内容标签
$content = "<div id='js_content' class='ce-padding-sm'>" . $content[1][0];
//获取所有图片地址
preg_match_all('/<[img|IMG].*?>/is', $content, $img);
/* $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[0] as $key => $value) {
if (strpos($value, 'iframe') !== false) {
continue;
}
if (strpos($value, 'data-src') !== false) {
preg_match_all('/data-src=".*?"/is', $value, $imim);
} elseif (strpos($value, 'data-croporisrc') !== false) {
preg_match_all('/data-croporisrc=".*?"/is', $value, $imim);
} elseif (strpos($value, 'src') !== false) {
preg_match_all('/src=".*?"/is', $value, $imim);
}
$vv = $imim[0][0];
$str = explode('"', $vv);
$fstr = explode('/', $str[1]);
$allname = $fstr[4];
if (strrpos($str[1], 'wx_fmt=') > 0) {
$ext = substr($str[1], strrpos($str[1], 'wx_fmt=') + 7);
$allname .= '.' . $ext;
} else {
$allname .= '.png';
}
try {
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}
$image = file_get_contents($str[1]);
$realfile = $dir . $allname;
file_put_contents($realfile, $image);
preg_match_all('/style=".*?"/is', $value, $style);
if (empty($style[0][0]) || $style[0][0] == 'style=""') {
$styleAttr = 'style="width: auto !important; height: auto !important; visibility: visible !important;"';
} else {
$styleAttr = $style[0][0];
}
//更替图片文件地址为服务器图片地址
$content = str_replace($value, '<img src="' . ltrim($realfile, '.') . '" ' . $styleAttr . '>', $content);
if ($i == 0) {
$thumb = ltrim($dir, '.') . $allname;
}
$i++;
} catch (Exception $e) {
continue;
}
// $content = str_replace($str[1], ltrim($realfile, '.'), $content);
// if ($i == 0) {
// $thumb = ltrim($realfile, '.');
// }
// $i++;
}
//处理背景图
$content = str_replace("background-image: url", "background-image:url", $content);
$preg_title = "|background-image:url\((.*)\);|U";
preg_match_all($preg_title, $content, $backimage);
if (!empty($backimage)) {
foreach ($backimage[1] as $key => $value) {
$str = str_replace("&quot;", "", $value);
$fstr = explode('/', $str);
$allname = $fstr[4];
if (strrpos($str, 'wx_fmt=') > 0) {
$ext = substr($str, strrpos($str, 'wx_fmt=') + 7);
$allname .= '.' . $ext;
} else {
$allname .= '.png';
}
$image = file_get_contents($str);
$realfile = $dir . $allname;
file_put_contents($realfile, $image);
$content = str_replace($str, ltrim($realfile, '.'), $content);
}
}
//修正视频内容
$content = str_replace("preview.html", "player.html", $content);
//重新设置 iframe
preg_match_all('/<iframe[^>]*\s+data-src="([^"]*)"[^>]*>/is', $content, $matched);
if (!empty($matched[0])) {
foreach ($matched[0] as $key => $value) {
$src = explode('&', $matched['1'][$key]);
$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($value, $str, $content);
}
}
$description = self::get_description($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' => $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) {
return $info->id;
} else {
return false;
}
}
}
public static function get_title($chars)
{
$find = stripos($chars, "document.write");
if ($find > 0) {
$title = explode('"', $chars);
$title = $title[7];
} else {
$title = $find;
}
if (empty($title)) {
$title = explode('</h2>', $chars);
$title = $title[0] ?? '';
}
return trim($title);
}
public static function get_description($content)
{
$content = self::clearHtml($content);
$content = strip_tags($content);
$content = str_replace("'", '', $content);
// preg_match_all('/[\x{4e00}-\x{9fff}]+/u', $content, $matches);
// $content = join('', $matches[0]);
$des = self::trimall($content);
$des = Str::msubstr($des, 0, 140);
return $des;
}
//删除html 标签
public static function strip_html_tags($tags, $str)
{
$html = array();
foreach ($tags as $tag) {
$html[] = '/<' . $tag . '.*?>[\s|\S]*?<\/' . $tag . '>/';
$html[] = '/<' . $tag . '.*?>/';
}
$data = preg_replace($html, '', $str);
return $data;
}
public static function clearHtml($descclear)
{
$descclear = str_replace("\r", "", $descclear); //过滤换行
$descclear = str_replace("\n", "", $descclear); //过滤换行
$descclear = str_replace("\t", "", $descclear); //过滤换行
$descclear = str_replace("\r\n", "", $descclear); //过滤换行
$descclear = str_replace("&nbsp;", "", $descclear); //过滤&nbsp;
$descclear = preg_replace("/\s+/", " ", $descclear); //过滤多余回车
$descclear = preg_replace("/<[ ]+/si", "<", $descclear); //过滤<__("<"号后面带空格)
$descclear = preg_replace("/<\!--.*?-->/si", "", $descclear); //过滤html注释
$descclear = preg_replace("/<(\!.*?)>/si", "", $descclear); //过滤DOCTYPE
$descclear = preg_replace("/<(\/?html.*?)>/si", "", $descclear); //过滤html标签
$descclear = preg_replace("/<(\/?head.*?)>/si", "", $descclear); //过滤head标签
$descclear = preg_replace("/<(\/?meta.*?)>/si", "", $descclear); //过滤meta标签
$descclear = preg_replace("/<(\/?body.*?)>/si", "", $descclear); //过滤body标签
$descclear = preg_replace("/<(\/?link.*?)>/si", "", $descclear); //过滤link标签
$descclear = preg_replace("/<(\/?form.*?)>/si", "", $descclear); //过滤form标签
$descclear = preg_replace("/cookie/si", "COOKIE", $descclear); //过滤COOKIE标签
$descclear = preg_replace("/<(applet.*?)>(.*?)<(\/applet.*?)>/si", "", $descclear); //过滤applet标签
$descclear = preg_replace("/<(\/?applet.*?)>/si", "", $descclear); //过滤applet标签
$descclear = preg_replace("/<(style.*?)>(.*?)<(\/style.*?)>/si", "", $descclear); //过滤style标签
$descclear = preg_replace("/<(\/?style.*?)>/si", "", $descclear); //过滤style标签
$descclear = preg_replace("/<(title.*?)>(.*?)<(\/title.*?)>/si", "", $descclear); //过滤title标签
$descclear = preg_replace("/<(\/?title.*?)>/si", "", $descclear); //过滤title标签
$descclear = preg_replace("/<(object.*?)>(.*?)<(\/object.*?)>/si", "", $descclear); //过滤object标签
$descclear = preg_replace("/<(\/?objec.*?)>/si", "", $descclear); //过滤object标签
$descclear = preg_replace("/<(noframes.*?)>(.*?)<(\/noframes.*?)>/si", "", $descclear); //过滤noframes标签
$descclear = preg_replace("/<(\/?noframes.*?)>/si", "", $descclear); //过滤noframes标签
$descclear = preg_replace("/<(i?frame.*?)>(.*?)<(\/i?frame.*?)>/si", "", $descclear); //过滤frame标签
$descclear = preg_replace("/<(\/?i?frame.*?)>/si", "", $descclear); //过滤frame标签
$descclear = preg_replace("/<(script.*?)>(.*?)<(\/script.*?)>/si", "", $descclear); //过滤script标签
$descclear = preg_replace("/<(\/?script.*?)>/si", "", $descclear); //过滤script标签
$descclear = preg_replace("/javascript/si", "Javascript", $descclear); //过滤script标签
$descclear = preg_replace("/vbscript/si", "Vbscript", $descclear); //过滤script标签
$descclear = preg_replace("/on([a-z]+)\s*=/si", "On\\1=", $descclear); //过滤script标签
$descclear = preg_replace("/&#/si", "&", $descclear); //过滤script标签如javAsCript:alert();
//使用正则替换
$pat = "/<(\/?)(script|i?frame|style|html|body|li|i|map|title|img|link|span|u|font|table|tr|b|marquee|td|strong|div|a|meta|\?|\%)([^>]*?)>/isU";
$descclear = preg_replace($pat, "", $descclear);
return $descclear;
}
//删除空格
public static function trimall($str)
{
$qian = array(" ", " ", "\t", "\n", "\r");
$hou = array("", "", "", "", "");
return str_replace($qian, $hou, $str);
}
}

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,70 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\service;
use app\common\model\Banner as BannerModel;
use app\common\validate\Banner as BannerValidate;
class Banner extends _Init
{
/**
* 添加信息
* @param [type] $data 广告数据
*/
public static function create($data)
{
$validate = new BannerValidate();
if (!$validate->scene('add')->check($data)) {
return $validate->getError();
}
$info = BannerModel::create($data);
if ($info) {
return true;
} else {
return '创建广告失败';
}
}
/**
* 编辑广告
* @param [type] $data 更新的数据
* @return [type] 返回 修改的结果
*/
public static function edit($data)
{
$validate = new BannerValidate();
if (!$validate->scene('add')->check($data)) {
return $validate->getError();
}
$info = BannerModel::update($data);
if ($info) {
return true;
} else {
return '编辑广告失败';
}
}
/**
* 删除广告
* @param [type] $id 要删除的广告id
* @return [type] 返回 结果
*/
public static function del($uid)
{
if (BannerModel::where('uid',$uid)->delete()) {
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,274 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\service;
use app\common\model\Article as ArticleModel;
use tools\Str;
class CeArticle extends _Init
{
/**
* 采集公众号文章
* @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) {
$info->delete();
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]));
$title = self::get_title($title);
//拼接正确的内容标签
$content = "<div id='js_content' class='ce-padding-sm'>" . $content[1][0];
//获取所有图片地址
preg_match_all('/<[img|IMG].*?>/is', $content, $img);
/* $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[0] as $key => $value) {
if (strpos($value, 'iframe') !== false) {
continue;
}
if (strpos($value, 'data-src') !== false) {
preg_match_all('/data-src=".*?"/is', $value, $imim);
} elseif (strpos($value, 'data-croporisrc') !== false) {
preg_match_all('/data-croporisrc=".*?"/is', $value, $imim);
} elseif (strpos($value, 'src') !== false) {
preg_match_all('/src=".*?"/is', $value, $imim);
}
$vv = $imim[0][0];
$str = explode('"', $vv);
$fstr = explode('/', $str[1]);
$allname = $fstr[4];
if (strrpos($str[1], 'wx_fmt=') > 0) {
$ext = substr($str[1], strrpos($str[1], 'wx_fmt=') + 7);
$allname .= '.' . $ext;
} else {
$allname .= '.png';
}
try {
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}
$image = file_get_contents($str[1]);
$realfile = $dir . $allname;
file_put_contents($realfile, $image);
preg_match_all('/style=".*?"/is', $value, $style);
if (empty($style[0][0]) || $style[0][0] == 'style=""') {
$styleAttr = 'style="width: auto !important; height: auto !important; visibility: visible !important;"';
} else {
$styleAttr = $style[0][0];
}
//更替图片文件地址为服务器图片地址
$content = str_replace($value, '<img src="' . ltrim($realfile, '.') . '" ' . $styleAttr . '>', $content);
if ($i == 0) {
$thumb = ltrim($dir, '.') . $allname;
}
$i++;
} catch (Exception $e) {
continue;
}
// $content = str_replace($str[1], ltrim($realfile, '.'), $content);
// if ($i == 0) {
// $thumb = ltrim($realfile, '.');
// }
// $i++;
}
//处理背景图
$content = str_replace("background-image: url", "background-image:url", $content);
$preg_title = "|background-image:url\((.*)\);|U";
preg_match_all($preg_title, $content, $backimage);
if (!empty($backimage)) {
foreach ($backimage[1] as $key => $value) {
$str = str_replace("&quot;", "", $value);
$fstr = explode('/', $str);
$allname = $fstr[4];
if (strrpos($str, 'wx_fmt=') > 0) {
$ext = substr($str, strrpos($str, 'wx_fmt=') + 7);
$allname .= '.' . $ext;
} else {
$allname .= '.png';
}
$image = file_get_contents($str);
$realfile = $dir . $allname;
file_put_contents($realfile, $image);
$content = str_replace($str, ltrim($realfile, '.'), $content);
}
}
//修正视频内容
$content = str_replace("preview.html", "player.html", $content);
//重新设置 iframe
preg_match_all('/<iframe[^>]*\s+data-src="([^"]*)"[^>]*>/is', $content, $matched);
if (!empty($matched[0])) {
foreach ($matched[0] as $key => $value) {
$src = explode('&', $matched['1'][$key]);
$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($value, $str, $content);
}
}
$description = self::get_description($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' => $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) {
return $info->id;
} else {
return false;
}
}
}
public static function get_title($chars)
{
$find = stripos($chars, "document.write");
if ($find > 0) {
$title = explode('"', $chars);
$title = $title[7];
} else {
$title = $find;
}
if (empty($title)) {
$title = explode('</h2>', $chars);
$title = $title[0];
}
return $title;
}
public static function get_description($content)
{
$content = self::clearHtml($content);
$content = strip_tags($content);
$content = str_replace("'", '', $content);
// preg_match_all('/[\x{4e00}-\x{9fff}]+/u', $content, $matches);
// $content = join('', $matches[0]);
$des = self::trimall($content);
$des = Str::msubstr($des, 0, 140);
return $des;
}
//删除html 标签
public static function strip_html_tags($tags, $str)
{
$html = array();
foreach ($tags as $tag) {
$html[] = '/<' . $tag . '.*?>[\s|\S]*?<\/' . $tag . '>/';
$html[] = '/<' . $tag . '.*?>/';
}
$data = preg_replace($html, '', $str);
return $data;
}
public static function clearHtml($descclear)
{
$descclear = str_replace("\r", "", $descclear); //过滤换行
$descclear = str_replace("\n", "", $descclear); //过滤换行
$descclear = str_replace("\t", "", $descclear); //过滤换行
$descclear = str_replace("\r\n", "", $descclear); //过滤换行
$descclear = str_replace("&nbsp;", "", $descclear); //过滤&nbsp;
$descclear = preg_replace("/\s+/", " ", $descclear); //过滤多余回车
$descclear = preg_replace("/<[ ]+/si", "<", $descclear); //过滤<__("<"号后面带空格)
$descclear = preg_replace("/<\!--.*?-->/si", "", $descclear); //过滤html注释
$descclear = preg_replace("/<(\!.*?)>/si", "", $descclear); //过滤DOCTYPE
$descclear = preg_replace("/<(\/?html.*?)>/si", "", $descclear); //过滤html标签
$descclear = preg_replace("/<(\/?head.*?)>/si", "", $descclear); //过滤head标签
$descclear = preg_replace("/<(\/?meta.*?)>/si", "", $descclear); //过滤meta标签
$descclear = preg_replace("/<(\/?body.*?)>/si", "", $descclear); //过滤body标签
$descclear = preg_replace("/<(\/?link.*?)>/si", "", $descclear); //过滤link标签
$descclear = preg_replace("/<(\/?form.*?)>/si", "", $descclear); //过滤form标签
$descclear = preg_replace("/cookie/si", "COOKIE", $descclear); //过滤COOKIE标签
$descclear = preg_replace("/<(applet.*?)>(.*?)<(\/applet.*?)>/si", "", $descclear); //过滤applet标签
$descclear = preg_replace("/<(\/?applet.*?)>/si", "", $descclear); //过滤applet标签
$descclear = preg_replace("/<(style.*?)>(.*?)<(\/style.*?)>/si", "", $descclear); //过滤style标签
$descclear = preg_replace("/<(\/?style.*?)>/si", "", $descclear); //过滤style标签
$descclear = preg_replace("/<(title.*?)>(.*?)<(\/title.*?)>/si", "", $descclear); //过滤title标签
$descclear = preg_replace("/<(\/?title.*?)>/si", "", $descclear); //过滤title标签
$descclear = preg_replace("/<(object.*?)>(.*?)<(\/object.*?)>/si", "", $descclear); //过滤object标签
$descclear = preg_replace("/<(\/?objec.*?)>/si", "", $descclear); //过滤object标签
$descclear = preg_replace("/<(noframes.*?)>(.*?)<(\/noframes.*?)>/si", "", $descclear); //过滤noframes标签
$descclear = preg_replace("/<(\/?noframes.*?)>/si", "", $descclear); //过滤noframes标签
$descclear = preg_replace("/<(i?frame.*?)>(.*?)<(\/i?frame.*?)>/si", "", $descclear); //过滤frame标签
$descclear = preg_replace("/<(\/?i?frame.*?)>/si", "", $descclear); //过滤frame标签
$descclear = preg_replace("/<(script.*?)>(.*?)<(\/script.*?)>/si", "", $descclear); //过滤script标签
$descclear = preg_replace("/<(\/?script.*?)>/si", "", $descclear); //过滤script标签
$descclear = preg_replace("/javascript/si", "Javascript", $descclear); //过滤script标签
$descclear = preg_replace("/vbscript/si", "Vbscript", $descclear); //过滤script标签
$descclear = preg_replace("/on([a-z]+)\s*=/si", "On\\1=", $descclear); //过滤script标签
$descclear = preg_replace("/&#/si", "&", $descclear); //过滤script标签如javAsCript:alert();
//使用正则替换
$pat = "/<(\/?)(script|i?frame|style|html|body|li|i|map|title|img|link|span|u|font|table|tr|b|marquee|td|strong|div|a|meta|\?|\%)([^>]*?)>/isU";
$descclear = preg_replace($pat, "", $descclear);
return $descclear;
}
//删除空格
public static function trimall($str)
{
$qian = array(" ", " ", "\t", "\n", "\r");
$hou = array("", "", "", "", "");
return str_replace($qian, $hou, $str);
}
}

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,161 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\service;
class Excel extends _Init
{
/**
* 导出提现管理
* @param [type] $list [description]
* @return [type] [description]
*/
public static function withdrawal_excel($list)
{
$data = array();
foreach ($list as $key => $v) {
$data[] = [
$v->userinfo->nickname,
$v->money,
$v->charge,
$v->price,
strip_tags($v->status_text),
$v->create_time,
];
}
$header = ['姓名', '提现金额', '手续费', '实收', '状态', '创建时间'];
self::writer($header, $data, '提现记录 - ', true);
}
/**
* 全部账户
* @param [type] $list [description]
* @return [type] [description]
*/
public static function account_excel($list)
{
$n = array();
foreach ($list as $key => $v) {
if ($v->user->is_country) {
$level = ' 分公司';
} elseif ($v->user->is_center) {
$level = '报单中心';
} else {
$level = $v->user->levelinfo->title;
}
$n[] = [
$v->uid,
$v->user->username,
$v->user->info->nickname ?? '',
$level,
$v->user->identity->title ?? '',
$v->user->account->price,
$v->user->account->earnings,
$v->user->account->cash,
$v->user->account->balance,
$v->user->spot_text,
$v->user->create_time,
];
}
$header = ['会员编号', '帐号', '真实名称', '会员等级', '套餐类型', '消费积分账户', '收益账户', '注册积分账户', '余额宝账户', '空点', '注册时间'];
self::writer($header, $n, '全部账户 - ', true);
}
/**
* 导出账变
* @param [type] $list [description]
* @return [type] [description]
*/
public static function account_logs_excel($list)
{
$n = array();
foreach ($list as $key => $v) {
$n[] = [
$v->uid,
$v->user->info->nickname ?? '',
$v->type_text,
$v->rules->title,
$v->increase,
$v->remark,
$v->create_time,
$v->fromuser,
$v->fuser->info->nickname ?? '',
];
}
$header = ['会员编号', '真实名称', '账户类型', '获取规则', '获取数值', '描述', '产生时间', '产生会员', '会员名称'];
self::writer($header, $n, '账变明细 - ', true);
}
/**
* [writer description]
* @param [type] $header 表头信息
* @param [type] $data 表数据
* @param boolean $type 是否输出 true 直接下载 false 保存文件
*/
public static function writer($header, $data, $fileName = '', $output = false)
{
$cacheMethod = \PHPExcel_CachedObjectStorageFactory::cache_in_memory_gzip;
$cacheSettings = array('memoryCacheSize' => '16MB');
$istrue = \PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
$objPHPExcel = new \PHPExcel();
$objProps = $objPHPExcel->getProperties();
$objProps->setCreator("skyxu");
//设置表头
$key = ord("A");
foreach ($header as $v) {
$colum = chr($key);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue($colum . '1', $v);
$objPHPExcel->getActiveSheet()->getStyle($colum . '1')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle($colum . '1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$key += 1;
}
$column = 2;
$objActSheet = $objPHPExcel->getActiveSheet();
foreach ($data as $key => $rows) {
//行写入
$span = ord("A");
foreach ($rows as $keyName => $value) {
// 列写入
$j = chr($span); //'f'
$objActSheet->setCellValue($j . $column, $value);
$span++;
}
$column++;
}
$objPHPExcel->getActiveSheet()->setTitle($fileName);
$objPHPExcel->setActiveSheetIndex(0);
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$saveName = $fileName . date('YmdHis', time()) . '.xls';
if ($output) {
//$fileName = iconv("utf-8", "gb2312", $fileName);
header('Content-Type: application/vnd.ms-excel');
header("Content-Disposition: attachment;filename=\"$saveName\"");
header('Cache-Control: max-age=0');
$objWriter->save('php://output');
} else {
//$fileName = iconv("utf-8", "gb2312", $fileName);
$objWriter->save($saveName);
return $saveName . '.xls';
}
}
/**
* 使用的内存
* @return [type] [description]
*/
public static function memory_usage()
{
$memory = (!function_exists('memory_get_usage')) ? '0' : round(memory_get_usage() / 1024 / 1024, 2) . 'MB';
return $memory;
}
}

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,605 @@
<?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\MemberSet as MemberSetModel;
use app\common\model\Template as TemplateModel;
use app\common\validate\Member as MemberValidate;
use app\common\validate\MemberInfo as MemberInfoValidate;
use think\Config;
use think\Db;
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 '用户尚未绑定手机号';
}
}
public static function create($data)
{
Db::startTrans();
try {
$member = [
'pid' => $data['pid'],
'username' => '',
'password' => Crypt::uMd5('111111'),
'openid' => $data['openid'],
];
$result = MemberModel::create($member);
$info = [
'nickname' => $data['nickname'],
'sex' => $data['sex'],
'headimgurl' => $data['headimgurl'],
'city' => $data['city'],
'province' => $data['province'],
];
$result->info()->save($info);
$account = [
'price' => 0,
];
$result->account()->save($account);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
return false;
}
}
/**
* 编辑用户资料
* @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)) {
Account::rule(UID, 'setting');
}
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);
Account::create($user->id);
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)) {
Account::rule(UID, 'setting');
}
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 '解除绑定失败';
}
}
protected static $list = [];
protected static $plist = [];
/**
* 获取会员所有上级的数列,管理关系
* @param [int] $uid [用户ID]
* @return [array] [用户数组]
*/
public static function getSub($uid, $addme = false)
{
self::$plist = [];
self::$list = MemberModel::column('pid', 'id');
if ($addme) {
array_push(self::$plist, $uid);
}
return self::_getSub($uid);
}
public static function _getSub($uid)
{
$puser = self::$list[$uid];
// dump(self::$plist);
if ($puser != 0) {
array_push(self::$plist, $puser);
self::_getSub($puser);
}
return self::$plist;
}
//设置会员或者代理商
public static function memberSet($uid, $time, $type, $team_id)
{
$member = MemberInfoModel::where('uid', $uid)->find();
$time = strtotime($time);
$key = 'is_' . $type;
$name = ($type == 'vip') ? '推广先锋' : '推广代理商';
if (!in_array($type, ['vip', 'agent'])) {
return "类型错误";
}
if ($time < time()) {
return "日期错误,必须大于当前时间";
}
if (!$member) {
return "没有这个会员";
} else {
if ($type == 'vip') {
if ($member->is_vip == 1 && $member->is_fee == 1) {
return "这个用户已经是推广先锋了";
} else {
$member->save([$type . '_time' => $time, 'is_' . $type => 1, 'is_fee' => 1]);
}
} else {
if ($member->is_agent == 1) {
return "这个用户已经是推广代理商了";
} else {
$member->save([$type . '_time' => $time, 'is_' . $type => 1]);
}
}
$this_user = MemberModel::get($uid);
$sendtype = ($type == 'vip') ? 1 : 2;
Tmplmsg::services_opened($this_user, $sendtype);
$in_data = [
'type' => $type,
'end_time' => $time,
'uid' => $uid,
'team_id' => $team_id,
'operator' => UID,
];
if (MemberSetModel::create($in_data)) {
$member->member->save(['empty_' . $type => 1]);
Logs::write("设置" . $name, array_merge($in_data, ['nickname' => $member->nickname]), UID);
return true;
} else {
$member->save([$type . '_time' => 0, 'is_' . $type => 0]);
return "设置失败";
}
}
}
/**
* 开通代理赠送会员
* @param [type] $uid [description]
* @return [type] [description]
*/
public static function open_vip($uid)
{
$member = MemberInfoModel::where('uid', $uid)->find();
if (!$member) {
return "会员不存在";
}
if ($member->is_vip == 1) {
$member->vip_time = strtotime("+1 year", $member->vip_end_time);
$member->save();
} else {
$member->vip_time = strtotime("+1 year");
$member->is_vip = 1;
$member->save();
}
}
/**
* 绑定手机号
* @param [type] $data [description]
* @return [type] [description]
*/
public static function bindMobile($data, $uid)
{
$validate = new MemberValidate();
if (!$validate->scene('bindmobile')->check($data)) {
return $validate->getError();
}
if ($uid == 276) {
dump($data);
dump($uid);
}
Db::startTrans();
try {
$user = MemberModel::get($uid);
$user->username = $data['username'];
$user->save();
Db::commit();
$user->info->mobile = $data['username'];
$user->info->is_vip = 1;
$user->info->vip_time = time() + 7 * 24 * 3600;
$user->info->share_mobile = $data['username'];
$user->info->open_mobile = 1;
$user->info->save();
Db::commit();
// 发送模板消息
Tmplmsg::opened_7days($user);
return true;
} catch (\Exception $e) {
Db::rollback();
return '操作失败';
}
}
/**
* 获取所有下级
* @param [type] $uid [description]
* @return [type] [description]
*/
public static function getChilds($uid)
{
$member = MemberModel::get($uid);
if (!$member) {
return "没有这个会员";
}
$chids = $member->childs()->column('id');
if (!empty($chids)) {
$one_list = $member->childs;
$two_list = MemberModel::where('pid', 'in', $chids)->select();
} else {
$one_list = [];
$two_list = [];
}
$data = [
'one_list' => $one_list,
'two_list' => $two_list,
];
return $data;
}
//获取推荐网络
public static function recommend($uid)
{
$name = 'name';
$datas = MemberModel::hasWhere('Info')->column('id,pid,CONCAT(nickname," (",username,") ") as ' . $name);
$list = \tools\Tree::list2tree($datas, 'id', 'pid', 'children', $uid);
$user = $datas[$uid];
$user['children'] = $list;
return json_encode($user);
}
public static function setParent($data)
{
$user = MemberModel::get($data['uid']);
$parentinfo = MemberModel::get($data['puid']);
if (!$user) {
return "没有这个用户";
} elseif (!$parentinfo) {
return "没有这个推荐人";
} elseif ($user->save(['pid' => $data['puid']])) {
// SysLogs::create(UID, 'edit_member_pid', ['data' => $user]);
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 '该菜单有下级菜单,不允许直接删除';
}
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,178 @@
<?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($uid)
{
$member = MemberModel::get($uid);
$openid = $member->openid;
if (!$openid) {
return "没有openid";
}
self::initWechat();
//发送给客户
$msgdata = [
'first' => [
'value' => '您好,您开通会员成功.',
],
'keyword1' => [
'value' => date("Y-m-d H:i:s"),
],
'keyword2' => [
'value' => '点击查看详情',
],
'remark' => [
'value' => '如有疑问请联系客服',
],
];
$res = Wechat\Template::send($openid, '834mh2zll5d1dw15AslgcyhL_-h_GRw_I74Itlrr9K4', $msgdata, url('vip/index'));
}
/**
* 初始化微信
* @param [type] $config [description]
* @return [type] [description]
*/
public static function initWechat()
{
$config = Config::get('wechat');
$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,57 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\service;
use app\common\model\Permission as PermissionModel;
use app\common\validate\Permission as PermissionValidate;
class Permission extends _Init
{
public static function create($data)
{
$validate = new PermissionValidate();
if (!$validate->check($data)) {
return $validate->getError();
}
if (PermissionModel::create($data)) {
return true;
} else {
return '创建数据失败';
}
}
public static function update($data)
{
$validate = new PermissionValidate();
if (!$validate->check($data)) {
return $validate->getError();
}
if (PermissionModel::update($data)) {
return true;
} else {
return '修改数据失败';
}
}
public static function delete($id)
{
$info = PermissionModel::get($id);
if (!$info) {
return '数据不存在';
} elseif (PermissionModel::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,96 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\service;
use app\common\model\Suggest as SuggestModel;
use app\common\validate\Suggest as SuggestValidate;
class Suggest extends _Init
{
/**
* 添加信息
* @param [type] $data 意见数据
*/
public static function create($data)
{
$scene = empty($data['pid']) ? 'add' : 'remark';
$validate = new SuggestValidate();
if (!$validate->scene($scene)->check($data)) {
return $validate->getError();
}
$info = SuggestModel::create($data);
if ($info) {
return true;
} else {
return "添加失败";
}
}
/**
* 编辑意见
* @param [type] $data 更新的数据
* @return [type] 返回 修改的结果
*/
public static function edit($data)
{
$validate = new SuggestValidate();
if (!$validate->scene('add')->check($data)) {
return $validate->getError();
}
$info = SuggestModel::update($data);
if ($info) {
return true;
} else {
return "操作失败";
}
}
/**
* 修改意见状态
* @param [type] $id 意见id
* @param [type] $status 状态
* @return [type] 返回结果
*/
public static function status($id, $status)
{
$info = SuggestModel::get($id);
if (!$info) {
return lang("信息不存在");
} elseif ($info->save(['status' => $status])) {
Logs::write('修改状态', ['status' => $status]);
return true;
} else {
return "设置失败";
}
}
public static function read($id)
{
$info = SuggestModel::get($id);
SuggestModel::where('pid',$id)->update(['read'=>1]);
return $info;
}
/**
* 删除意见
* @param [type] $id 要删除的意见id
* @return [type] 返回 结果
*/
public static function del($id)
{
$model = new SuggestModel();
if ($model->destroy($id)) {
return true;
} else {
return "删除失败";
}
}
}

View File

@@ -0,0 +1,98 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\service;
use app\common\model\Team as TeamModel;
use app\common\validate\Team as TeamValidate;
class Team extends _Init
{
/**
* 添加信息
* @param [type] $data 团队数据
*/
public static function create($data)
{
$validate = new TeamValidate();
if (!$validate->scene('add')->check($data)) {
return $validate->getError();
}
$info = TeamModel::create($data);
if ($info) {
return true;
} else {
return '创建团队失败';
}
}
/**
* 编辑团队
* @param [type] $data 更新的数据
* @return [type] 返回 修改的结果
*/
public static function edit($data)
{
$validate = new TeamValidate();
if (!$validate->scene('add')->check($data)) {
return $validate->getError();
}
$info = TeamModel::update($data);
if ($info) {
return true;
} else {
return '编辑团队失败';
}
}
/**
* 修改团队状态
* @param [type] $id 团队id
* @param [type] $status 状态
* @return [type] 返回结果
*/
public static function status($id, $status)
{
$info = TeamModel::get($id);
if (!$info) {
return '团队不存在';
} elseif ($info->save(['status' => $status])) {
return true;
} else {
return '修改状态失败';
}
}
/**
* 删除团队
* @param [type] $id 要删除的团队id
* @return [type] 返回 结果
*/
public static function del($id)
{
$info = TeamModel::get($id);
if (!$info) {
return '团队不存在';
// } elseif ($info->save(['status' => -1])) {
} elseif ($info->destroy($id)) {
return true;
} else {
return '删除失败';
}
// $model = new TeamModel();
// if ($model->destroy($id)) {
// return true;
// } else {
// return '删除失败';
// }
}
}

View File

@@ -0,0 +1,139 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\service;
class Tmplmsg extends _Init
{
protected static $tplid = [
'vip7days_opened' => 'tYfa7Lhakw8e_qdwQLCdKBuk82jBRtpzn2W9IMLeFEY', //7天vip试用开通试用申请成功提醒
'ending' => '', //7天vip/vip/代理商到期提醒,服务到期提醒
'opened' => 'kyg6lX_BQ9fS6LBgPSo_26QrsCkARgQOFYlZAZdqqSY', //vip/代理商开通提醒,开通成功提醒
'renewed' => 'IkkhxXwu04EFvHDnOBF_eUWf61SwjSyOmpV8C9RB-b4', //vip/代理商续费成功提醒,续费成功提醒
'account' => 'UB5WQDITm9mxZQhybimFxP5J643YWnBXGk6tyBL3wqw', //分润/提现提醒,帐户资金变动提醒
];
//开通7天vip试用-模版消息推送
public static function opened_7days($member)
{
if ($member->openid) {
$msgdata = [
'first' => array('value' => '恭喜您获得推广先锋7天试用特权'),
'keyword1' => array('value' => '推广先锋7天试用'), //申请项目
'keyword2' => array('value' => $member->info->vip_time), //有效期
'remark' => array('value' => '感谢您的使用。'),
];
$url = self::geturl('finance/vip');
self::create($member->openid, self::$tplid['vip7days_opened'], $msgdata, $url);
return true;
} else {
return false;
}
}
//推广先锋/推广代理商开通提醒-模版消息推送
public static function services_opened($member, $type = 1)
{
if ($member->openid) {
$msgdata = [
'first' => [
'value' => '恭喜您成功开通以下项目',
],
'keyword1' => [
'value' => $type == 1 ? '推广先锋' : '推广代理商',
],
'keyword2' => [
'value' => '已开通',
],
'keyword3' => [
'value' => $type == 1 ? $member->info->vip_time : $member->info->agent_time,
],
'keyword4' => [
'value' => date('Y-m-d'),
],
'remark' => '感谢您的支持!',
];
$url = $type == 1 ? 'center/index' : 'agent/index';
$url = self::geturl($url);
self::create($member->openid, self::$tplid['opened'], $msgdata, $url);
return true;
} else {
return false;
}
}
//推广先锋/推广代理商续费提醒-模版消息推送
public static function services_renewed($member, $type = 1)
{
if ($member->openid) {
$msgdata = [
'first' => [
'value' => '恭喜您成功续费以下项目:',
],
'keyword1' => [
'value' => $type == 1 ? '推广先锋' : '推广代理商',
],
'keyword2' => [
'value' => $type == 1 ? $member->info->vip_time : $member->info->agent_time,
],
'remark' => '感谢您的支持!',
];
$url = $type == 1 ? 'center/index' : 'agent/index';
$url = self::geturl($url);
self::create($member->openid, self::$tplid['renewed'], $msgdata, $url);
return true;
} else {
return false;
}
}
//获得分润提醒-模版消息推送
public static function account($data, $type = 1)
{
if ($type == 1) {
$title = '分润到账提醒';
$increase = $data['increase'];
} else {
$title = '提现成功提醒';
$increase = $data['increase'] . '(实际到账' . $data['price'] . '';
}
$msgdata = [
'first' => array('value' => $title),
'keyword1' => array('value' => date('Y-m-d')), //变动时间
'keyword2' => array('value' => $increase), //变动金额
'keyword3' => array('value' => $data['balance']), //帐户余额
'remark' => array('value' => ''),
];
$url = self::geturl('agent/index');
self::create($data['openid'], self::$tplid['account'], $msgdata, $url);
return true;
}
protected static function geturl($url = '', $attr = '')
{
return 'http://m.tgzs.cnskl.com/' . $url . '?' . $attr;
}
protected static function create($openid, $type, $d_array, $url)
{
$dt = [
'openid' => $openid,
'type' => $type,
'd_array' => json_encode($d_array),
'url' => $url,
];
\think\Queue::push('Test@fire', $dt);
return true;
}
}

View File

@@ -0,0 +1,36 @@
<?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 = '', $type = 'vip')
{
$data = [
'uid' => $uid,
'money' => $money,
'openid' => $openid,
'type' => $type,
];
$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,91 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\service;
use app\common\model\Wechat as WechatModel;
use cjango\Wechat as Wexin;
use cjango\Wechat\Token;
use think\Cache;
class Wechat extends _Init
{
public static $config = [];
public static $Wechat = null;
public static function set_init()
{
self::$Wechat = WechatModel::find(1);
self::$config = [
'appid' => self::$Wechat->appid,
'secret' => self::$Wechat->secret,
'access_token' => self::$Wechat->access_token,
'mch_id' => self::$Wechat->mch_id,
'paykey' => self::$Wechat->paykey,
'token' => self::$Wechat->token,
];
}
/**
* [instance description]
* @param object $agent Member模型数据
* @return [type] [description]
*/
public static function instance()
{
self::set_init();
if (empty(self::$Wechat->access_token) || self::$Wechat->access_time < (time() - 7000)) {
Wexin::instance(self::$config, true);
$token = Wexin\Token::get();
WechatModel::update(['access_token' => $token, 'access_time' => time()], ['id' => 1]);
self::$config['access_token'] = $token;
Wexin::instance(self::$config, true);
} else {
Wexin::instance(self::$config);
}
}
/**
* 微信分享
*/
public static function jsWechat()
{
$ticket = Cache::get('Wechat_ticket');
self::instance();
if (!$ticket) {
$ticket = Token::ticket();
Cache::set('Wechat_ticket', $ticket, 7000);
}
$now_time = time();
$wx['appid'] = self::$config['appid'];
$wx['timestamp'] = $now_time;
$wx['noncestr'] = $noncestr = \tools\Str::random(32);
$sign = array(
'noncestr' => $noncestr,
'jsapi_ticket' => $ticket,
'timestamp' => $now_time,
'url' => __SELF__,
);
ksort($sign);
$signStr = sha1(urldecode(http_build_query($sign)));
$wx['signature'] = $signStr;
return $wx;
}
public static function sendT($uid, $data)
{
}
}

View File

@@ -0,0 +1,108 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\service;
use app\common\model\Member;
use app\common\model\Withdrawal as WithdrawalModel;
use app\common\service\Wechat as WechatService;
use app\common\validate\Withdrawal as WithdrawalValidate;
use cjango\Wechat;
class Withdrawal extends _Init
{
/**
* 创建提现记录
* @param [type] $data [description]
*/
public static function create($data)
{
$data['charge'] = $data['money'] * 0.05;
$data['price'] = $data['money'] - $data['charge'];
$data['status'] = 1;
$validate = new WithdrawalValidate();
if (!$validate->check($data)) {
return $validate->getError();
}
$info = WithdrawalModel::create($data);
if ($info) {
$res = Account::rule($data['uid'], 'withdrawal', -$data['money']);
if ($res === true) {
return true;
} else {
$info->delete();
return $res;
}
} 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)
{
$list = WithdrawalModel::where('id', 'in', $id)->select();
if (empty($list)) {
return '提现信息不存在';
}
$data = [
'status' => $status,
];
$data['audit'] = UID;
foreach ($list as $key => $value) {
if ($value->status == 1 && in_array($status, [2, 3])) {
if ($status == 3) {
Account::rule($value->uid, 'rejected', $value->money);
} else {
$userinfo = Member::get($value->uid);
$remark = "会员" . $userinfo->info->nickname . '提现:' . $value->money . '元';
self::initWechat();
$result = Wechat\Pay::transfers(\tools\Str::orderid(), $userinfo->openid, $value->price, $remark);
if (!$result) {
return Wechat::error();
}
if ($userinfo->openid) {
$account = [
'openid' => $userinfo->openid,
'create_time' => date('Y-m-d'),
'increase' => (string) $value->money,
'balance' => $userinfo->account->price,
];
//加模板消息
Tmplmsg::account($account);
}
}
$value->status = $status;
$value->save();
}
}
return true;
}
/**
* 初始化微信
* @return void
*/
public static function initWechat()
{
WechatService::instance();
}
}

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,111 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\service;
use app\common\service\WechatTpl as WechatTplService;
/**
* 信息
*/
class Sendtplmsg extends _Init
{
//开通7天vip试用-模版消息推送
public static function opened_7days($member)
{
if ($member->openid) {
$tpl_user = [
'openid' => $member->openid,
'first' => '恭喜您获得推广先锋7天试用特权',
'title' => '推广先锋7天试用',
'end_time' => $member->info->vip_time,
'remark' => '感谢您的使用。',
'url' => url('center/index'),
];
WechatTplService::send_vip7days_opened($tpl_user);
}
}
//7天试用到/推广先锋/推广代理商到期提醒-模版消息推送
public static function services_ending($member, $type = 1)
{
if ($member->openid) {
$tpl_user = [
'openid' => $member->openid,
'first' => '您的服务即将到期。',
'title' => $type == 1 ? $member->info->is_vip == 1 ? '推广先锋' : '推广先锋7天试用' : '推广代理商',
'end_time' => $type == 1 ? $member->info->vip_time : $member->info->agent_time,
'remark' => '避免影响试用,请您及时续费。',
'url' => url('center/index'),
];
WechatTplService::send_ending($tpl_user);
}
}
//推广先锋/推广代理商开通提醒-模版消息推送
public static function services_opened($member, $type = 1)
{
if ($member->openid) {
$tpl_user = [
'openid' => $member->openid,
'first' => '恭喜您成功开通以下项目:',
'title' => $type == 1 ? '推广先锋' : '推广代理商',
'status' => '已开通',
'end_time' => $type == 1 ? $member->info->vip_time : $member->info->agent_time,
'begin_time' => date('Y-m-d'),
'remark' => '感谢您的支持!',
'url' => url('center/index'),
];
WechatTplService::send_opened($tpl_user);
}
}
//推广先锋/推广代理商续费提醒-模版消息推送
public static function services_renewed($member, $type = 1)
{
if ($member->openid) {
$tpl_user = [
'openid' => $member->openid,
'first' => '恭喜您成功续费以下项目:',
'title' => $type == 1 ? '推广先锋' : '推广代理商',
'end_time' => $type == 1 ? $member->info->vip_time : $member->info->agent_time,
'remark' => '感谢您的支持!',
'url' => url('center/index'),
];
WechatTplService::send_renewed($tpl_user);
}
}
//获得分润提醒-模版消息推送
public static function account($data, $type = 1)
{
if ($type == 1) {
$title = '分润到账提醒';
$increase = $data['increase'];
} else {
$title = '提现成功提醒';
$increase = $data['increase'] . '(实际到账' . $data['price'] . '';
}
$tpl_user = [
'openid' => $data['openid'],
'first' => $title,
'create_time' => $data['create_time'],
'increase' => $increase,
'balance' => $data['balance'],
'remark' => '',
'url' => url('mobile/center/index'),
];
return WechatTplService::send_account($tpl_user);
}
}

View File

@@ -0,0 +1,168 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\service;
use cjango\Wechat;
use cjango\Wechat\Template;
use cjango\Wechat\Token;
use think\Cache;
use think\Config;
/**
* 信息
*/
class WechatTpl extends _Init
{
//切换到超级助手公众号下的模版消息
protected static $tplid = [
'vip7days_opened' => 'tYfa7Lhakw8e_qdwQLCdKBuk82jBRtpzn2W9IMLeFEY', //7天vip试用开通试用申请成功提醒
'ending' => '', //7天vip/vip/代理商到期提醒,服务到期提醒
'opened' => 'kyg6lX_BQ9fS6LBgPSo_26QrsCkARgQOFYlZAZdqqSY', //vip/代理商开通提醒,开通成功提醒
'renewed' => 'IkkhxXwu04EFvHDnOBF_eUWf61SwjSyOmpV8C9RB-b4', //vip/代理商续费成功提醒,续费成功提醒
'account' => 'UB5WQDITm9mxZQhybimFxP5J643YWnBXGk6tyBL3wqw', //分润/提现提醒,帐户资金变动提醒
];
//切换到商客连公众号下的模版消息
// protected static $tplid = [
// 'vip7days_opened' => 'VDAErEXFRX422z6Eb-sk2F-D_BGhC884R-msyQdGFzA', //7天vip试用开通试用申请成功提醒
// 'ending' => '', //7天vip/vip/代理商到期提醒,服务到期提醒
// 'opened' => 'zQ7dPKX9zyEA3-qsK01Zy_9yOdUKKyldV6rvXd_Iu1s', //vip/代理商开通提醒,开通成功提醒
// 'renewed' => 'nYFSyPM2g8ciVUEkhtbZOeIKJ-1fzrbYUjUVJ9wR3MU', //vip/代理商续费成功提醒,续费成功提醒
// 'account' => 'wqKGqbWR9aZOClEjpDic9B3Vra6zOFwZQrE-TMVJ3pc', //分润/提现提醒,帐户资金变动提醒
// ];
// protected static $tplid = [
// 'vip7days_opened' => 'sMCBkHpECqchIiITkd1S4rv0fQUt08hDAGXiSb4MxVU', //7天vip试用开通试用申请成功提醒
// 'ending' => 'y7jq1gxzsyyuNpnkFFEeOk2OaEw0lWl1USuIhVu4gKE', //7天vip/vip/代理商到期提醒,服务到期提醒
// 'opened' => 'ShNDbGpvygXv9OPw_AXm7BwQpqgBu3UMc2qXwhdR4rY', //vip/代理商开通提醒,开通成功提醒
// 'renewed' => 'byWRFskrSgDksZ9RwozwOfM8ZerifCuZLQIJYn0WSZ0', //vip/代理商续费成功提醒,续费成功提醒
// 'account' => 'UodPDTZsvPZ8ZuT7HXuOGkozaNzt1Y-eptqxO1HySEA', //分润/提现提醒,帐户资金变动提醒
// ];
public static function send_vip7days_opened($tpl_data)
{
$data = [
'first' => array('value' => $tpl_data['first']),
'keyword1' => array('value' => $tpl_data['title']), //申请项目
'keyword2' => array('value' => $tpl_data['end_time']), //有效期
'remark' => array('value' => $tpl_data['remark']),
];
self::send($tpl_data['openid'], self::$tplid['vip7days_opened'], $data, $tpl_data['url']);
}
public static function send_ending($tpl_data)
{
$data = [
'first' => array('value' => $tpl_data['first']),
'keyword1' => array('value' => $tpl_data['title']), //服务类型
'keyword2' => array('value' => $tpl_data['end_time']), //到期时间
'remark' => array('value' => $tpl_data['remark']),
];
self::send($tpl_data['openid'], self::$tplid['ending'], $data, $tpl_data['url']);
}
public static function send_opened($tpl_data)
{
$data = [
'first' => array('value' => $tpl_data['first']),
'keyword1' => array('value' => $tpl_data['title']), //开通项目
'keyword2' => array('value' => $tpl_data['status']), //开通状态
'keyword3' => array('value' => $tpl_data['end_time']), //有效期
'keyword4' => array('value' => $tpl_data['begin_time']), //开通时间
'remark' => array('value' => $tpl_data['remark']),
];
self::send($tpl_data['openid'], self::$tplid['opened'], $data, $tpl_data['url']);
}
public static function send_renewed($tpl_data)
{
$data = [
'first' => array('value' => $tpl_data['first']),
'keyword1' => array('value' => $tpl_data['title']), //续费类型
'keyword2' => array('value' => $tpl_data['end_time']), //有效期
'remark' => array('value' => $tpl_data['remark']),
];
self::send($tpl_data['openid'], self::$tplid['renewed'], $data, $tpl_data['url']);
}
public static function send_account($tpl_data)
{
$data = [
'first' => array('value' => $tpl_data['first']),
'keyword1' => array('value' => $tpl_data['create_time']), //变动时间
'keyword2' => array('value' => $tpl_data['increase']), //变动金额
'keyword3' => array('value' => $tpl_data['balance']), //帐户余额
'remark' => array('value' => $tpl_data['remark']),
];
return self::send($tpl_data['openid'], self::$tplid['account'], $data, $tpl_data['url']);
}
public static function send($openid, $tpl_sn, $data, $url)
{
self::initWechat();
return Template::send($openid, $tpl_sn, $data, $url);
}
// /**
// * 初始化微信
// * @return void
// */
// protected static function initWechat()
// {
// $token = Cache::get('wechat_access_token');
// $config = Config::get('wechat');
// // 检测TOKEN是否过期
// if (!$token) {
// Wechat::instance($config);
// $token = Token::get();
// // 重新设置TOKEN并缓存重新初始化微信
// Cache::set('wechat_access_token', Token::get(), 7200);
// $config['access_token'] = $token;
// Wechat::instance($config, true);
// } else {
// $config['access_token'] = $token;
// Wechat::instance($config);
// }
// }
/**
* 初始化微信
* @param [type] $config [description]
* @return [type] [description]
*/
public static function initWechat()
{
$config = Config::get('wechat');
$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,41 @@
<?php
namespace app\common\validate;
use think\Validate;
/**
* 用户登录验证器
*/
class AccountRules extends Validate
{
/**
* 验证规则
* @var array
*/
protected $rule = [
'title' => 'require|min:2|max:200',
'name' => 'require|unique:AccountRules',
'type' => 'require',
'increase' => 'require|float',
'times' => 'require|integer',
'remark' => 'max:255',
];
/**
* 错误提示消息
* @var array
*/
protected $message = [
'title.require' => '规则标题必须填写',
'title.min' => '规则标题不应少于:rule字符',
'title.max' => '规则标题不应大于:rule字符',
'name.require' => '规则标识必须填写',
'name.unique' => '规则标识已经存在',
'type.require' => '规则类别必须选择',
'increase.require' => '触发数额必须填写',
'increase.float' => '触发数额必须为数字',
'times.integer' => '触发次数必须为数字',
'times.integer' => '触发次数必须为数字',
'remark.max' => '规则描述不应大于:rule字符',
];
}

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|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,41 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\validate;
use think\Validate;
class Banner extends Validate
{
/**
* 验证规则
* @var array
*/
protected $rule = [
'storage_id' => 'require',
];
/**
* 提示信息
* @var array
*/
protected $message = [
'storage_id.require' => '必须上传图片',
];
/**
* 验证场景
* @var array
*/
protected $scene = [
'add' => ['storage_id'],
];
}

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,89 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\validate;
use app\common\model\Sms as SmsModel;
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',
'verify' => 'require|number|length:4|checkVerify:',
];
/**
* 提示信息
* @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' => '绑定失败',
'verify.require' => '验证码必须填写',
'verify.number' => '验证码只允许数字',
'verify.length' => '请输入:rule位验证码',
];
/**
* 验证场景
* @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'],
'bindmobile' => ['username', 'verify'],
];
protected function verifyPassword($value, $rule, $data)
{
return Crypt::uMd5($value) == Db::name('Member')->where('id', $data['uid'])->value('password');
}
protected function checkVerify($val, $rule, $data)
{
$res = SmsModel::where('mobile', $data['username'])->where('status', 0)->order('id desc')->find();
if ($res && $res['code'] == $val) {
$res->save(['status' => 1]);
return true;
} else {
return '验证码有误';
}
}
}

View File

@@ -0,0 +1,78 @@
<?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',
'share_mobile' => 'require|verifyMobile:',
'open_mobile' => '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' => '手机号码格式不正确',
'share_mobile.require' => '业务手机号码不能为空',
'share_mobile.verifyMobile' => '业务手机号码格式不正确',
'open_mobile.require' => '必选选择是否显示',
];
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'],
'share_mobile' => ['share_mobile', 'open_mobile'],
];
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,33 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\validate;
use think\Validate;
class Permission extends Validate
{
/**
* 验证规则
* @var array
*/
protected $rule = [
'title' => 'require|unique:permission',
'url' => 'require',
];
/**
* 提示信息
* @var array
*/
protected $message = [
'title.require' => '权限名称必须填写',
'title.unique' => '权限名称已经存在',
'url.require' => '权限地址必须填写',
];
}

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

View File

@@ -0,0 +1,44 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\validate;
use think\Validate;
class Suggest extends Validate
{
/**
* 验证规则
* @var array
*/
protected $rule = [
// 'title' => 'require|length:4,20',
'title' => 'require',
'remark' => 'require',
];
/**
* 提示信息
* @var array
*/
protected $message = [
'title.require' => '反馈标题不能为空',
'remark.require' => '反馈内容不能为空',
];
/**
* 验证场景
* @var array
*/
protected $scene = [
'add' => ['title', 'remark'],
'remark' => ['remark'],
];
}

View File

@@ -0,0 +1,40 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\validate;
use think\Validate;
class Team extends Validate
{
/**
* 验证规则
* @var array
*/
protected $rule = [
'title' => 'require',
];
/**
* 提示信息
* @var array
*/
protected $message = [
'title.require' => '团队名称必须填写',
];
/**
* 验证场景
* @var array
*/
protected $scene = [
'add' => ['title'],
];
}

View File

@@ -0,0 +1,66 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\validate;
use think\Db;
use think\Validate;
class Withdrawal extends Validate
{
/**
* 验证规则
* @var array
*/
protected $rule = [
'money' => 'require|number|checkmoney:|checkaccount:',
'price' => 'checkprice:',
];
/**
* 提示信息
* @var array
*/
protected $message = [
'money.require' => '提现金额不能为空',
'money.number' => '提现金额必须是数字',
'money.checkmoney' => '提现金额必须大于100小于2000',
'money.checkaccount' => '账户余额不足',
'price.checkprice' => '实到金额不足1元不能提现',
];
public function checkaccount($value, $rule, $data)
{
$acc = Db::name('Account')->where(['uid' => $data['uid']])->value('price') ?: 0;
if ($value > abs($acc)) {
return false;
} else {
return true;
}
}
public function checkprice($value, $rule, $data)
{
if ($value < 1) {
return false;
} else {
return true;
}
}
protected function checkmoney($value, $rule, $data)
{
if ($value < 100 || $value > 2000) {
return false;
} else {
return true;
}
}
}

47
application/config.php Normal file
View File

@@ -0,0 +1,47 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
use think\Env;
// +----------------------------------------------------------------------
// | 应用设置
// +----------------------------------------------------------------------
return [
// 应用Trace
'app_trace' => true,
// +----------------------------------------------------------------------
// | Trace设置 开启 app_trace 后 有效
// +----------------------------------------------------------------------
'trace' => [
'type' => Env::get('trace.type', false),
],
// +----------------------------------------------------------------------
// | 异常及错误设置
// +----------------------------------------------------------------------
// 异常页面的模板文件
'exception_tmpl' => APP_PATH . 'exception.tpl',
// 错误显示信息,非调试模式有效
'error_message' => '页面错误!请稍后再试~',
// 显示错误信息
'show_error_msg' => false,
// URL普通方式参数 用于自动生成
'url_common_param' => true,
// 域名部署
'url_domain_deploy' => true,
'url_html_suffix' => '',
// +----------------------------------------------------------------------
// | 默认全局过滤方法 用逗号分隔多个
// +----------------------------------------------------------------------
'default_filter' => 'trim',
// +----------------------------------------------------------------------
// | 用户密码加密串
// +----------------------------------------------------------------------
'data_auth_key' => 'Vg#:dxp4Tv=?1}3EeDA/KY]2qX$2RDnNwC.O+rQH',
];

404
application/exception.tpl Normal file
View File

@@ -0,0 +1,404 @@
<?php
if(!function_exists('parse_padding')){
function parse_padding($source)
{
$length = strlen(strval(count($source['source']) + $source['first']));
return 40 + ($length - 1) * 8;
}
}
if(!function_exists('parse_class')){
function parse_class($name)
{
$names = explode('\\', $name);
return '<abbr title="'.$name.'">'.end($names).'</abbr>';
}
}
if(!function_exists('parse_file')){
function parse_file($file, $line)
{
return '<a class="toggle" title="'."{$file} line {$line}".'">'.basename($file)." line {$line}".'</a>';
}
}
if(!function_exists('parse_args')){
function parse_args($args)
{
$result = [];
foreach ($args as $key => $item) {
switch (true) {
case is_object($item):
$value = sprintf('<em>object</em>(%s)', parse_class(get_class($item)));
break;
case is_array($item):
if(count($item) > 3){
$value = sprintf('[%s, ...]', parse_args(array_slice($item, 0, 3)));
} else {
$value = sprintf('[%s]', parse_args($item));
}
break;
case is_string($item):
if(strlen($item) > 20){
$value = sprintf(
'\'<a class="toggle" title="%s">%s...</a>\'',
htmlentities($item),
htmlentities(substr($item, 0, 20))
);
} else {
$value = sprintf("'%s'", htmlentities($item));
}
break;
case is_int($item):
case is_float($item):
$value = $item;
break;
case is_null($item):
$value = '<em>null</em>';
break;
case is_bool($item):
$value = '<em>' . ($item ? 'true' : 'false') . '</em>';
break;
case is_resource($item):
$value = '<em>resource</em>';
break;
default:
$value = htmlentities(str_replace("\n", '', var_export(strval($item), true)));
break;
}
$result[] = is_int($key) ? $value : "'{$key}' => {$value}";
}
return implode(', ', $result);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><?php echo lang('System Error'); ?></title>
<meta name="robots" content="noindex,nofollow" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<style>
/* Base */
body {
color: #333;
font: 14px Verdana, "Helvetica Neue", helvetica, Arial, 'Microsoft YaHei', sans-serif;
margin: 0;
padding: 0 20px 20px;
word-break: break-word;
}
h1{
margin: 10px 0 0;
font-size: 28px;
font-weight: 500;
line-height: 32px;
}
h2{
color: #4288ce;
font-weight: 400;
padding: 6px 0;
margin: 6px 0 0;
font-size: 18px;
border-bottom: 1px solid #eee;
}
h3.subheading {
color: #4288ce;
margin: 6px 0 0;
font-weight: 400;
}
h3{
margin: 12px;
font-size: 16px;
font-weight: bold;
}
abbr{
cursor: help;
text-decoration: underline;
text-decoration-style: dotted;
}
a{
color: #868686;
cursor: pointer;
}
a:hover{
text-decoration: underline;
}
.line-error{
background: #f8cbcb;
}
.echo table {
width: 100%;
}
.echo pre {
padding: 16px;
overflow: auto;
font-size: 85%;
line-height: 1.45;
background-color: #f7f7f7;
border: 0;
border-radius: 3px;
font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
}
.echo pre > pre {
padding: 0;
margin: 0;
}
/* Layout */
.col-md-3 {
width: 25%;
}
.col-md-9 {
width: 75%;
}
[class^="col-md-"] {
float: left;
}
.clearfix {
clear:both;
}
@media only screen
and (min-device-width : 375px)
and (max-device-width : 667px) {
.col-md-3,
.col-md-9 {
width: 100%;
}
}
/* Exception Info */
.exception {
margin-top: 20px;
}
.exception .message{
padding: 12px;
border: 1px solid #ddd;
border-bottom: 0 none;
line-height: 18px;
font-size:16px;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
font-family: Consolas,"Liberation Mono",Courier,Verdana,"微软雅黑";
}
.exception .code{
float: left;
text-align: center;
color: #fff;
margin-right: 12px;
padding: 16px;
border-radius: 4px;
background: #999;
}
.exception .source-code{
padding: 6px;
border: 1px solid #ddd;
background: #f9f9f9;
overflow-x: auto;
}
.exception .source-code pre{
margin: 0;
}
.exception .source-code pre ol{
margin: 0;
color: #4288ce;
display: inline-block;
min-width: 100%;
box-sizing: border-box;
font-size:14px;
font-family: "Century Gothic",Consolas,"Liberation Mono",Courier,Verdana;
padding-left: <?php echo (isset($source) && !empty($source)) ? parse_padding($source) : 40; ?>px;
}
.exception .source-code pre li{
border-left: 1px solid #ddd;
height: 18px;
line-height: 18px;
}
.exception .source-code pre code{
color: #333;
height: 100%;
display: inline-block;
border-left: 1px solid #fff;
font-size:14px;
font-family: Consolas,"Liberation Mono",Courier,Verdana,"微软雅黑";
}
/* SPAN elements with the classes below are added by prettyprint. */
pre.prettyprint .pln { color: #000 } /* plain text */
pre.prettyprint .str { color: #080 } /* string content */
pre.prettyprint .kwd { color: #008 } /* a keyword */
pre.prettyprint .com { color: #800 } /* a comment */
pre.prettyprint .typ { color: #606 } /* a type name */
pre.prettyprint .lit { color: #066 } /* a literal value */
/* punctuation, lisp open bracket, lisp close bracket */
pre.prettyprint .pun, pre.prettyprint .opn, pre.prettyprint .clo { color: #660 }
pre.prettyprint .tag { color: #008 } /* a markup tag name */
pre.prettyprint .atn { color: #606 } /* a markup attribute name */
pre.prettyprint .atv { color: #080 } /* a markup attribute value */
pre.prettyprint .dec, pre.prettyprint .var { color: #606 } /* a declaration; a variable name */
pre.prettyprint .fun { color: red } /* a function name */
</style>
</head>
<body>
<div class="echo">
<?php echo $echo;?>
</div>
<?php if(\think\App::$debug) { ?>
<div class="exception">
<div class="message">
<div class="info">
<div>
<h2>[<?php echo $code; ?>] <?php echo sprintf('%s in %s', parse_class($name), parse_file($file, $line)); ?></h2>
</div>
<div><h1><?php echo nl2br(htmlentities($message)); ?></h1></div>
</div>
</div>
<?php if(!empty($source)){?>
<div class="source-code">
<pre class="prettyprint lang-php"><ol start="<?php echo $source['first']; ?>"><?php foreach ((array) $source['source'] as $key => $value) { ?><li class="line-<?php echo $key + $source['first']; ?>"><code><?php echo htmlentities($value); ?></code></li><?php } ?></ol></pre>
</div>
<?php }?>
</div>
<?php } else { ?>
<div class="exception">
<div class="info"><h1><?php echo htmlentities($message); ?></h1></div>
</div>
<?php } ?>
<?php if(!empty($datas)){ ?>
<div class="exception-var">
<h2>Exception Datas</h2>
<?php foreach ((array) $datas as $label => $value) { ?>
<table>
<?php if(empty($value)){ ?>
<caption><?php echo $label; ?><small>empty</small></caption>
<?php } else { ?>
<caption><?php echo $label; ?></caption>
<tbody>
<?php foreach ((array) $value as $key => $val) { ?>
<tr>
<td><?php echo htmlentities($key); ?></td>
<td>
<?php
if(is_array($val) || is_object($val)){
echo htmlentities(json_encode($val, JSON_PRETTY_PRINT));
} else if(is_bool($val)) {
echo $val ? 'true' : 'false';
} else if(is_scalar($val)) {
echo htmlentities($val);
} else {
echo 'Resource';
}
?>
</td>
</tr>
<?php } ?>
</tbody>
<?php } ?>
</table>
<?php } ?>
</div>
<?php } ?>
<?php if(\think\App::$debug) { ?>
<script>
var LINE = <?php echo $line; ?>;
function $(selector, node){
var elements;
node = node || document;
if(document.querySelectorAll){
elements = node.querySelectorAll(selector);
} else {
switch(selector.substr(0, 1)){
case '#':
elements = [node.getElementById(selector.substr(1))];
break;
case '.':
if(document.getElementsByClassName){
elements = node.getElementsByClassName(selector.substr(1));
} else {
elements = get_elements_by_class(selector.substr(1), node);
}
break;
default:
elements = node.getElementsByTagName();
}
}
return elements;
function get_elements_by_class(search_class, node, tag) {
var elements = [], eles,
pattern = new RegExp('(^|\\s)' + search_class + '(\\s|$)');
node = node || document;
tag = tag || '*';
eles = node.getElementsByTagName(tag);
for(var i = 0; i < eles.length; i++) {
if(pattern.test(eles[i].className)) {
elements.push(eles[i])
}
}
return elements;
}
}
$.getScript = function(src, func){
var script = document.createElement('script');
script.async = 'async';
script.src = src;
script.onload = func || function(){};
$('head')[0].appendChild(script);
}
;(function(){
var files = $('.toggle');
var ol = $('ol', $('.prettyprint')[0]);
var li = $('li', ol[0]);
//
for(var i = 0; i < files.length; i++){
files[i].ondblclick = function(){
var title = this.title;
this.title = this.innerHTML;
this.innerHTML = title;
}
}
//
var err_line = $('.line-' + LINE, ol[0])[0];
err_line.className = err_line.className + ' line-error';
$.getScript('//cdn.bootcss.com/prettify/r298/prettify.min.js', function(){
prettyPrint();
// Firefox浏览器一个很诡异的问题
// ol的行号莫名其妙的错位
// li里面的html重新渲染就没有问题了
if(window.navigator.userAgent.indexOf('Firefox') >= 0){
ol[0].innerHTML = ol[0].innerHTML;
}
});
})();
</script>
<?php } ?>
</body>
</html>

Some files were not shown because too many files have changed in this diff Show More