commit 8c0aa3edc195a382ec2a305776f49529f1898995
Author: 玄尘 <122383162@qq.com>
Date: Thu Aug 6 15:26:41 2020 +0800
first commit
diff --git a/.env b/.env
new file mode 100644
index 0000000..05a5032
--- /dev/null
+++ b/.env
@@ -0,0 +1,5 @@
+app_debug = false
+app_trace = false
+
+[trace]
+type = Console
diff --git a/.user.ini b/.user.ini
new file mode 100644
index 0000000..de1c45d
--- /dev/null
+++ b/.user.ini
@@ -0,0 +1 @@
+open_basedir=/disk/wwwroot/newhelper:/tmp/:/proc/
diff --git a/application/common.php b/application/common.php
new file mode 100644
index 0000000..4a3027f
--- /dev/null
+++ b/application/common.php
@@ -0,0 +1,103 @@
+
+// +----------------------------------------------------------------------
+
+// 应用公共文件
+//
+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]);
+}
diff --git a/application/common/Sendtplmsg.php b/application/common/Sendtplmsg.php
new file mode 100644
index 0000000..86345b8
--- /dev/null
+++ b/application/common/Sendtplmsg.php
@@ -0,0 +1,57 @@
+ |
+// +------------------------------------------------+
+
+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);
+ }
+
+ }
+
+
+
+}
diff --git a/application/common/model/Account.php b/application/common/model/Account.php
new file mode 100644
index 0000000..4b4e8dc
--- /dev/null
+++ b/application/common/model/Account.php
@@ -0,0 +1,34 @@
+ |
+// +------------------------------------------------+
+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');
+ }
+
+}
diff --git a/application/common/model/AccountLogs.php b/application/common/model/AccountLogs.php
new file mode 100644
index 0000000..099b4a2
--- /dev/null
+++ b/application/common/model/AccountLogs.php
@@ -0,0 +1,66 @@
+ |
+// +------------------------------------------------+
+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');
+ }
+}
diff --git a/application/common/model/AccountRules.php b/application/common/model/AccountRules.php
new file mode 100644
index 0000000..e2ddc8e
--- /dev/null
+++ b/application/common/model/AccountRules.php
@@ -0,0 +1,32 @@
+ |
+// +------------------------------------------------+
+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;
+ }
+ }
+}
diff --git a/application/common/model/Advert.php b/application/common/model/Advert.php
new file mode 100644
index 0000000..ea35467
--- /dev/null
+++ b/application/common/model/Advert.php
@@ -0,0 +1,34 @@
+ |
+// +------------------------------------------------+
+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);
+ }
+
+}
diff --git a/application/common/model/AdvertDetail.php b/application/common/model/AdvertDetail.php
new file mode 100644
index 0000000..b7da139
--- /dev/null
+++ b/application/common/model/AdvertDetail.php
@@ -0,0 +1,34 @@
+ |
+// +------------------------------------------------+
+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') ?: '';
+ }
+}
diff --git a/application/common/model/Article.php b/application/common/model/Article.php
new file mode 100644
index 0000000..f075082
--- /dev/null
+++ b/application/common/model/Article.php
@@ -0,0 +1,58 @@
+ |
+// +------------------------------------------------+
+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');
+ }
+}
diff --git a/application/common/model/ArticleModel.php b/application/common/model/ArticleModel.php
new file mode 100644
index 0000000..82bd66c
--- /dev/null
+++ b/application/common/model/ArticleModel.php
@@ -0,0 +1,20 @@
+ |
+// +------------------------------------------------+
+namespace app\common\model;
+
+class ArticleModel extends _Init
+{
+ protected static function init()
+ {
+ self::beforeInsert(function ($data) {
+ $data->status = 1;
+ $data->sort = $data['sort'] ?: 0;
+ });
+ }
+}
diff --git a/application/common/model/Auth.php b/application/common/model/Auth.php
new file mode 100644
index 0000000..4896a18
--- /dev/null
+++ b/application/common/model/Auth.php
@@ -0,0 +1,20 @@
+ |
+// +------------------------------------------------+
+namespace app\common\model;
+
+class Auth extends _Init
+{
+ /**
+ * 获取用户数量
+ */
+ protected function getUserCountAttr()
+ {
+ return $this->hasMany('AuthUser')->count();
+ }
+}
diff --git a/application/common/model/AuthUser.php b/application/common/model/AuthUser.php
new file mode 100644
index 0000000..11f8818
--- /dev/null
+++ b/application/common/model/AuthUser.php
@@ -0,0 +1,35 @@
+ |
+// +------------------------------------------------+
+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');
+ }
+}
diff --git a/application/common/model/Banner.php b/application/common/model/Banner.php
new file mode 100644
index 0000000..2fe4702
--- /dev/null
+++ b/application/common/model/Banner.php
@@ -0,0 +1,43 @@
+ |
+// +------------------------------------------------+
+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');
+ }
+}
diff --git a/application/common/model/Category.php b/application/common/model/Category.php
new file mode 100644
index 0000000..ba91d87
--- /dev/null
+++ b/application/common/model/Category.php
@@ -0,0 +1,33 @@
+ |
+// +------------------------------------------------+
+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 ?? '没有';
+ }
+
+}
diff --git a/application/common/model/City.php b/application/common/model/City.php
new file mode 100644
index 0000000..00734c9
--- /dev/null
+++ b/application/common/model/City.php
@@ -0,0 +1,13 @@
+ |
+// +------------------------------------------------+
+namespace app\common\model;
+
+class City extends _Init
+{
+}
diff --git a/application/common/model/Config.php b/application/common/model/Config.php
new file mode 100644
index 0000000..16131fa
--- /dev/null
+++ b/application/common/model/Config.php
@@ -0,0 +1,96 @@
+ |
+// +------------------------------------------------+
+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/', "
", $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 '已删除';
+ }
+ 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 = '禁用';
+ break;
+ case 1:$res = '正常';
+ break;
+ case 2:$res = '待审核';
+ break;
+ case 3:$res = '被驳回';
+ break;
+ default:$res = '';
+ break;
+ }
+ }
+ return $res;
+ }
+}
diff --git a/application/common/model/Content.php b/application/common/model/Content.php
new file mode 100644
index 0000000..32cd042
--- /dev/null
+++ b/application/common/model/Content.php
@@ -0,0 +1,42 @@
+ |
+// +------------------------------------------------+
+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');
+ }
+
+}
diff --git a/application/common/model/Direct.php b/application/common/model/Direct.php
new file mode 100644
index 0000000..371293b
--- /dev/null
+++ b/application/common/model/Direct.php
@@ -0,0 +1,44 @@
+ |
+// +------------------------------------------------+
+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');
+ }
+}
diff --git a/application/common/model/Experience.php b/application/common/model/Experience.php
new file mode 100644
index 0000000..a6ae2fa
--- /dev/null
+++ b/application/common/model/Experience.php
@@ -0,0 +1,55 @@
+ |
+// +------------------------------------------------+
+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);
+ }
+}
diff --git a/application/common/model/ExperienceTags.php b/application/common/model/ExperienceTags.php
new file mode 100644
index 0000000..08fd5e8
--- /dev/null
+++ b/application/common/model/ExperienceTags.php
@@ -0,0 +1,19 @@
+ |
+// +------------------------------------------------+
+namespace app\common\model;
+
+class ExperienceTags extends _Init
+{
+ protected $updateTime = false;
+
+ public function user()
+ {
+ return $this->hasOne('MemberInfo', 'uid', 'uid');
+ }
+}
diff --git a/application/common/model/Help.php b/application/common/model/Help.php
new file mode 100644
index 0000000..50f3d20
--- /dev/null
+++ b/application/common/model/Help.php
@@ -0,0 +1,40 @@
+ |
+// +------------------------------------------------+
+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);
+ }
+
+}
diff --git a/application/common/model/Logs.php b/application/common/model/Logs.php
new file mode 100644
index 0000000..a7121a7
--- /dev/null
+++ b/application/common/model/Logs.php
@@ -0,0 +1,59 @@
+ |
+// +------------------------------------------------+
+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) . '
';
+ }
+ } else {
+ $string = $content;
+ }
+ return $string;
+ } else {
+ return '';
+ }
+ }
+}
diff --git a/application/common/model/Member.php b/application/common/model/Member.php
new file mode 100644
index 0000000..3ab01eb
--- /dev/null
+++ b/application/common/model/Member.php
@@ -0,0 +1,123 @@
+ |
+// +------------------------------------------------+
+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 " 是 ";
+ break;
+ default:
+ return "";
+ break;
+ }
+ }
+
+ public function getAgentIsEmptyAttr($value, $data)
+ {
+ switch ($data['empty_agent']) {
+ case '0':
+ return "";
+ break;
+ case '1':
+ return " 是 ";
+ break;
+ default:
+ return "";
+ break;
+ }
+ }
+
+ public function puser()
+ {
+ return $this->hasOne('Member', 'id', 'pid');
+ }
+
+ public function childs()
+ {
+ return $this->hasMany('Member', 'pid', 'id');
+ }
+}
diff --git a/application/common/model/MemberInfo.php b/application/common/model/MemberInfo.php
new file mode 100644
index 0000000..e6e602b
--- /dev/null
+++ b/application/common/model/MemberInfo.php
@@ -0,0 +1,174 @@
+ |
+// +------------------------------------------------+
+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 '';
+ }
+
+ }
+}
diff --git a/application/common/model/MemberList.php b/application/common/model/MemberList.php
new file mode 100644
index 0000000..358488c
--- /dev/null
+++ b/application/common/model/MemberList.php
@@ -0,0 +1,14 @@
+ |
+// +------------------------------------------------+
+namespace app\common\model;
+
+class MemberList extends _Init
+{
+
+}
diff --git a/application/common/model/MemberSet.php b/application/common/model/MemberSet.php
new file mode 100644
index 0000000..c78b953
--- /dev/null
+++ b/application/common/model/MemberSet.php
@@ -0,0 +1,54 @@
+ |
+// +------------------------------------------------+
+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');
+ }
+}
diff --git a/application/common/model/Menu.php b/application/common/model/Menu.php
new file mode 100644
index 0000000..5d3ca02
--- /dev/null
+++ b/application/common/model/Menu.php
@@ -0,0 +1,34 @@
+ |
+// +------------------------------------------------+
+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);
+ }
+}
diff --git a/application/common/model/Message.php b/application/common/model/Message.php
new file mode 100644
index 0000000..9dbc05f
--- /dev/null
+++ b/application/common/model/Message.php
@@ -0,0 +1,22 @@
+ |
+// +------------------------------------------------+
+namespace app\common\model;
+
+/**
+ *留言
+ */
+class Message extends _Init
+{
+ protected $updateTime = false;
+
+ public function user()
+ {
+ return $this->belongsTo('MemberInfo', 'from_uid', 'uid');
+ }
+}
diff --git a/application/common/model/Permission.php b/application/common/model/Permission.php
new file mode 100644
index 0000000..5508553
--- /dev/null
+++ b/application/common/model/Permission.php
@@ -0,0 +1,26 @@
+ |
+// +------------------------------------------------+
+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 '否';
+ }
+ }
+}
diff --git a/application/common/model/Province.php b/application/common/model/Province.php
new file mode 100644
index 0000000..5727667
--- /dev/null
+++ b/application/common/model/Province.php
@@ -0,0 +1,21 @@
+ |
+// +------------------------------------------------+
+namespace app\common\model;
+
+class Province extends _Init
+{
+ /**
+ * 模型初始化【事件注册】
+ */
+ protected static function init()
+ {
+ self::beforeInsert(function ($data) {
+ });
+ }
+}
diff --git a/application/common/model/Sms.php b/application/common/model/Sms.php
new file mode 100644
index 0000000..82740db
--- /dev/null
+++ b/application/common/model/Sms.php
@@ -0,0 +1,27 @@
+ |
+// +------------------------------------------------+
+namespace app\common\model;
+
+class Sms extends _Init
+{
+
+ public function getStatusAttr($value)
+ {
+ switch ($value) {
+ case '0':
+ return '未使用';
+ break;
+ case '1':
+ return '已使用';
+ break;
+ default:
+ break;
+ }
+ }
+}
diff --git a/application/common/model/Storage.php b/application/common/model/Storage.php
new file mode 100644
index 0000000..868415d
--- /dev/null
+++ b/application/common/model/Storage.php
@@ -0,0 +1,17 @@
+ |
+// +------------------------------------------------+
+namespace app\common\model;
+
+class Storage extends _Init
+{
+ /**
+ * 关闭更新时间写入
+ */
+ protected $updateTime = false;
+}
diff --git a/application/common/model/Suggest.php b/application/common/model/Suggest.php
new file mode 100644
index 0000000..a3626af
--- /dev/null
+++ b/application/common/model/Suggest.php
@@ -0,0 +1,78 @@
+ |
+// +------------------------------------------------+
+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;
+ }
+ }
+ }
+}
diff --git a/application/common/model/Team.php b/application/common/model/Team.php
new file mode 100644
index 0000000..2e40b52
--- /dev/null
+++ b/application/common/model/Team.php
@@ -0,0 +1,28 @@
+ |
+// +------------------------------------------------+
+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');
+ }
+
+}
diff --git a/application/common/model/Template.php b/application/common/model/Template.php
new file mode 100644
index 0000000..dca4a02
--- /dev/null
+++ b/application/common/model/Template.php
@@ -0,0 +1,14 @@
+ |
+// +------------------------------------------------+
+namespace app\common\model;
+
+class Template extends _Init
+{
+
+}
diff --git a/application/common/model/VipOrder.php b/application/common/model/VipOrder.php
new file mode 100644
index 0000000..6abba30
--- /dev/null
+++ b/application/common/model/VipOrder.php
@@ -0,0 +1,71 @@
+ |
+// +------------------------------------------------+
+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 '未支付';
+ break;
+ case '20':
+ return '已支付';
+ 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');
+ }
+}
diff --git a/application/common/model/Wechat.php b/application/common/model/Wechat.php
new file mode 100644
index 0000000..4ee3ef3
--- /dev/null
+++ b/application/common/model/Wechat.php
@@ -0,0 +1,14 @@
+ |
+// +------------------------------------------------+
+namespace app\common\model;
+
+class Wechat extends _Init
+{
+
+}
diff --git a/application/common/model/Withdrawal.php b/application/common/model/Withdrawal.php
new file mode 100644
index 0000000..a7137d0
--- /dev/null
+++ b/application/common/model/Withdrawal.php
@@ -0,0 +1,48 @@
+ |
+// +------------------------------------------------+
+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 '待审核';
+ break;
+ case 2:
+ return '通过';
+ break;
+ case 3:
+ return '驳回';
+ break;
+ default:
+ return '状态错误';
+ break;
+ }
+ }
+
+ //审核操作人
+ public function inguser()
+ {
+ return $this->hasOne('Member', 'id', 'audit');
+ }
+
+}
diff --git a/application/common/model/_Init.php b/application/common/model/_Init.php
new file mode 100644
index 0000000..d590cd0
--- /dev/null
+++ b/application/common/model/_Init.php
@@ -0,0 +1,30 @@
+ |
+// +------------------------------------------------+
+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;
+ }
+ }
+}
diff --git a/application/common/service/Account.php b/application/common/service/Account.php
new file mode 100644
index 0000000..a704490
--- /dev/null
+++ b/application/common/service/Account.php
@@ -0,0 +1,190 @@
+ |
+// +------------------------------------------------+
+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;
+ }
+ }
+ }
+}
diff --git a/application/common/service/AccountRules.php b/application/common/service/AccountRules.php
new file mode 100644
index 0000000..699e83b
--- /dev/null
+++ b/application/common/service/AccountRules.php
@@ -0,0 +1,101 @@
+ |
+// +------------------------------------------------+
+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;
+ }
+}
diff --git a/application/common/service/Advert.php b/application/common/service/Advert.php
new file mode 100644
index 0000000..561f97b
--- /dev/null
+++ b/application/common/service/Advert.php
@@ -0,0 +1,78 @@
+ |
+// +------------------------------------------------+
+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 '设置失败';
+ }
+ }
+}
diff --git a/application/common/service/AdvertDetail.php b/application/common/service/AdvertDetail.php
new file mode 100644
index 0000000..1c82fbc
--- /dev/null
+++ b/application/common/service/AdvertDetail.php
@@ -0,0 +1,78 @@
+ |
+// +------------------------------------------------+
+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 '设置失败';
+ }
+ }
+}
diff --git a/application/common/service/Article.php b/application/common/service/Article.php
new file mode 100644
index 0000000..4048cd4
--- /dev/null
+++ b/application/common/service/Article.php
@@ -0,0 +1,528 @@
+ |
+// +------------------------------------------------+
+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\">(.*)
+
+