commit 17096657dc2afaa5f29de4ee077a0d751c5e71e8
Author: 玄尘 <122383162@qq.com>
Date: Thu Aug 6 14:58:51 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..3ce1465
--- /dev/null
+++ b/.user.ini
@@ -0,0 +1 @@
+open_basedir=/disk/wwwroot/helper:/tmp/:/proc/
diff --git a/application/common.php b/application/common.php
new file mode 100644
index 0000000..70ea85c
--- /dev/null
+++ b/application/common.php
@@ -0,0 +1,86 @@
+
+// +----------------------------------------------------------------------
+
+// 应用公共文件
+//
+
+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;
+ }
+}
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/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..d13d150
--- /dev/null
+++ b/application/common/model/Experience.php
@@ -0,0 +1,38 @@
+ |
+// +------------------------------------------------+
+namespace app\common\model;
+
+class Experience extends _Init
+{
+ /**
+ * 模型初始化【事件注册】
+ */
+ protected static function init()
+ {
+ self::beforeInsert(function ($data) {
+ $data->status = 1;
+ });
+ }
+
+ public function user()
+ {
+ return $this->belongsTo('MemberInfo', 'uid', 'uid');
+ }
+
+ public function comment()
+ {
+ return $this->hasMany('Experience', 'pid', 'id')->order('id asc');
+ }
+
+ public function getCountAttr($value, $data)
+ {
+ $res = ExperienceTags::where(['experience_id' => $data['id'], 'uid' => UID])->count();
+ return $res;
+ }
+}
diff --git a/application/common/model/ExperienceTags.php b/application/common/model/ExperienceTags.php
new file mode 100644
index 0000000..bc1a846
--- /dev/null
+++ b/application/common/model/ExperienceTags.php
@@ -0,0 +1,15 @@
+ |
+// +------------------------------------------------+
+namespace app\common\model;
+
+class ExperienceTags extends _Init
+{
+ protected $updateTime = false;
+
+}
diff --git a/application/common/model/Help.php b/application/common/model/Help.php
new file mode 100644
index 0000000..693d6de
--- /dev/null
+++ b/application/common/model/Help.php
@@ -0,0 +1,36 @@
+ |
+// +------------------------------------------------+
+namespace app\common\model;
+
+use think\Config;
+
+class Help extends _Init
+{
+ /**
+ * 模型初始化【事件注册】
+ */
+ protected static function init()
+ {
+ self::beforeInsert(function ($data) {
+ $data->status = 1;
+ });
+ }
+
+ public function getCategoryAttr($value, $data)
+ {
+ $list = Config::get('help_type');
+ return empty($list[$data['category']]) ? '没这个分类' : $list[$data['category']];
+ }
+
+ public function getCreateTimeAttr($value, $data)
+ {
+ return date('Y-m-d', $value);
+ }
+
+}
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..adea410
--- /dev/null
+++ b/application/common/model/Member.php
@@ -0,0 +1,68 @@
+ |
+// +------------------------------------------------+
+namespace app\common\model;
+
+use think\Config as Conf;
+use think\Request;
+use tools\Crypt;
+
+class Member extends _Init
+{
+ protected $readonly = [''];
+
+ /**
+ * 模型初始化【事件注册】
+ */
+ protected static function init()
+ {
+ self::beforeInsert(function ($data) {
+ $data->reg_ip = Request::instance()->ip();
+ });
+ }
+
+ /**
+ * 格式化 最后登录时间
+ * @param [type] $value 最后登录时间 时间戳
+ */
+ protected function getLastTimeAttr($value)
+ {
+ return date(Conf::get('database.datetime_format'), $value);
+ }
+
+ /**
+ * 加密密码
+ * @param [type] $value [description]
+ */
+ protected function setPasswordAttr($value)
+ {
+ return Crypt::uMd5($value);
+ }
+
+ /**
+ * 用户资料
+ */
+ protected function info()
+ {
+ return $this->hasOne('MemberInfo', 'uid', 'id');
+ }
+
+ /**
+ * 关联 AuthUser 表
+ * @return [type] [description]
+ */
+ public function authUser()
+ {
+ return $this->hasOne('AuthUser', 'uid', 'id');
+ }
+
+ public function getJuniorAttr($value, $data)
+ {
+ return MemberList::where('uid', $data['id'])->count();
+ }
+}
diff --git a/application/common/model/MemberInfo.php b/application/common/model/MemberInfo.php
new file mode 100644
index 0000000..f148a6a
--- /dev/null
+++ b/application/common/model/MemberInfo.php
@@ -0,0 +1,96 @@
+ |
+// +------------------------------------------------+
+namespace app\common\model;
+
+class MemberInfo extends _Init
+{
+ protected $createTime = false;
+ protected $readonly = ['image'];
+ /**
+ * 获取头像地址
+ * @param [type] $value [description]
+ * @param [type] $data [description]
+ * @return [type] [description]
+ */
+ protected function getAvatarAttr($value, $data)
+ {
+ $avatar = $data['headimgurl'];
+ if (!empty($avatar) && strpos($avatar, 'wx.qlogo.cn')) {
+ return rtrim($avatar, '0') . '132';
+ } elseif (empty($avatar)) {
+ return '/static/system/images/avatar.jpg';
+ } else {
+ return $avatar;
+ }
+ }
+
+ /**
+ * 获取头像地址
+ * @param [type] $value [description]
+ * @param [type] $data [description]
+ * @return [type] [description]
+ */
+ protected function getQrcodeAttr($value, $data)
+ {
+ $path = Storage::where('id', $data['qrcode'])->value('path');
+ return $path ?? '';
+ }
+
+ /**
+ * 判断用户是否为 未过期的VIP会员
+ * @param [type] $value [description]
+ * @param [type] $data [description]
+ * @return [type] [description]
+ */
+ protected function getIsVipAttr($value, $data)
+ {
+ if ($data['vip_time'] > time() && $data["is_vip"] == 1) {
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+
+ protected function getVipTextAttr($value, $data)
+ {
+ if ($data['vip_time'] > time() && $data["is_vip"] == 1) {
+ return 'VIP会员';
+ } else {
+ return '普通会员';
+ }
+ }
+
+ protected function getVipTimeAttr($value, $data)
+ {
+ if ($value < time()) {
+ return '永久';
+ } else {
+ return date('Y-m-d', $value);
+ }
+ }
+
+ protected function getVipEndTimeAttr($value, $data)
+ {
+ return $data['vip_time'];
+ }
+
+ protected function getIndexTplAttr($value, $data)
+ {
+ if ($this->is_vip) {
+ return $value;
+ } else {
+ return 1;
+ }
+ }
+
+ protected function getMessageCountAttr($value, $data)
+ {
+ return Message::where('to_uid', $data['uid'])->count();
+ }
+}
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/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/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/Score.php b/application/common/model/Score.php
new file mode 100644
index 0000000..d8dc9db
--- /dev/null
+++ b/application/common/model/Score.php
@@ -0,0 +1,39 @@
+ |
+// +------------------------------------------------+
+namespace app\common\model;
+
+class Score extends _Init
+{
+ /**
+ * 关闭更新时间写入
+ */
+ protected $updateTime = false;
+
+ public function user()
+ {
+ return $this->belongsTo('MemberInfo', 'uid', 'uid');
+ }
+
+ public function getScoreAttr($value, $data)
+ {
+ return floatval($value);
+ }
+
+ public function getRulesAttr($value, $data)
+ {
+ $map = ['model' => $data['rule_id']];
+ return ScoreRules::where($map)->find();
+ }
+
+ public function getAddtimeAttr($value, $data)
+ {
+ return date('Y-m-d', $data['create_time']);
+ }
+
+}
diff --git a/application/common/model/ScoreRules.php b/application/common/model/ScoreRules.php
new file mode 100644
index 0000000..56d8c4f
--- /dev/null
+++ b/application/common/model/ScoreRules.php
@@ -0,0 +1,28 @@
+ |
+// +------------------------------------------------+
+namespace app\common\model;
+
+class ScoreRules extends _Init
+{
+ /**
+ * 模型初始化【事件注册】
+ */
+ protected static function init()
+ {
+ self::beforeInsert(function ($data) {
+ $data->status = 1;
+ });
+ }
+
+ public function getCreateTimeAttr($value, $data)
+ {
+ return date('Y-m-d', $value);
+ }
+
+}
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..84d7ff2
--- /dev/null
+++ b/application/common/model/Suggest.php
@@ -0,0 +1,17 @@
+ |
+// +------------------------------------------------+
+namespace app\common\model;
+
+class Suggest extends _Init
+{
+ public function info()
+ {
+ return $this->belongsTo('MemberInfo', 'uid', '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..fd67e4a
--- /dev/null
+++ b/application/common/model/VipOrder.php
@@ -0,0 +1,53 @@
+ |
+// +------------------------------------------------+
+namespace app\common\model;
+
+use tools\Str;
+
+class VipOrder extends _Init
+{
+ /**
+ * 模型初始化【事件注册】
+ */
+ protected static function init()
+ {
+ self::beforeInsert(function ($data) {
+ $data->orderid = Str::orderid('VIP');
+ });
+ }
+
+ public function getStatusAttr($value)
+ {
+ switch ($value) {
+ case '0':
+ return '未支付';
+ break;
+ case '20':
+ return '已支付';
+ break;
+ default:
+ break;
+ }
+ }
+ public function getModelAttr($value, $data)
+ {
+ if ($data['model'] == 'weixin') {
+ return '微信支付';
+ } else if ($data['model'] == 'score') {
+ return '积分兑换';
+ } else {
+ return '未知';
+ }
+ }
+
+ public function user()
+ {
+ return $this->belongsTo('MemberInfo', 'uid', 'uid');
+ }
+}
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/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..c6f2634
--- /dev/null
+++ b/application/common/service/Article.php
@@ -0,0 +1,265 @@
+ |
+// +------------------------------------------------+
+namespace app\common\service;
+
+use app\common\model\Article as ArticleModel;
+use app\common\model\Category as CategoryModel;
+use app\common\service\Score as ScoreService;
+use app\common\validate\Article as ArticleValidate;
+
+class Article extends _Init
+{
+ /**
+ * 添加信息
+ * @param [type] $data 文章数据
+ */
+ public static function create($data)
+ {
+ $validate = new ArticleValidate();
+ if (!$validate->scene('add')->check($data)) {
+ return $validate->getError();
+ }
+
+ $info = ArticleModel::create($data);
+ if ($info) {
+ return true;
+ } else {
+ return '创建文章失败';
+ }
+ }
+
+ /**
+ * 编辑文章
+ * @param [type] $data 更新的数据
+ * @return [type] 返回 修改的结果
+ */
+ public static function edit($data)
+ {
+ $validate = new ArticleValidate();
+ if (!$validate->scene('add')->check($data)) {
+ return $validate->getError();
+ }
+ $info = ArticleModel::update($data);
+ if ($info) {
+ return true;
+ } else {
+ return '编辑文章失败';
+ }
+ }
+
+ /**
+ * 前台用户添加文章
+ * @param [type] $data 更新的数据
+ * @return [type] 返回 修改的结果
+ */
+ public static function userAdd($data)
+ {
+ $data = [
+ 'uid' => $data['uid'] ?? 0,
+ 'title' => $data['title'] ?? '',
+ 'content' => $data['content'] ?? '',
+ 'description' => $data['description'] ?? '',
+ 'category_id' => $data['category_id'] ?? '0',
+ 'storage_id' => $data['storage_id'] ?? '0',
+ 'thumb' => $data['thumb'] ?? '0',
+ 'status' => $data['status'] ?? '1',
+ 'url' => $data['url'] ?? '',
+ 'nickname' => $data['nickname'] ?? '',
+ 'head_img' => $data['head_img'] ?? '',
+ 'click' => 0,
+ ];
+
+ $validate = new ArticleValidate();
+ if (!$validate->scene('add')->check($data)) {
+ return $validate->getError();
+ }
+ $info = ArticleModel::create($data);
+ if ($info) {
+ ScoreService::addArticle($data['uid'], 'add');
+ return true;
+ } else {
+ return '文章创建失败';
+ }
+ }
+
+ /**
+ * 修改文章状态
+ * @param [type] $id 文章id
+ * @param [type] $status 状态
+ * @return [type] 返回结果
+ */
+ public static function status($id, $status)
+ {
+ $info = ArticleModel::get($id);
+ if (!$info) {
+ return '文章不存在';
+ } elseif ($info->save(['status' => $status])) {
+ Logs::write('修改状态', ['status' => $status]);
+ return true;
+ } else {
+ return '修改状态失败';
+ }
+ }
+
+ /**
+ * 删除文章
+ * @param [type] $id 要删除的文章id
+ * @return [type] 返回 结果
+ */
+ public static function del($id)
+ {
+ $info = ArticleModel::get($id);
+ if (!$info) {
+ return '文章不存在';
+ } elseif ($info->save(['status' => -1])) {
+ return true;
+ } else {
+ return '删除失败';
+ }
+
+ // $model = new ArticleModel();
+ // if ($model->destroy($id)) {
+ // return true;
+ // } else {
+ // return '删除失败';
+ // }
+ }
+
+ /**
+ * 获取分类列表
+ * @return [type] [description]
+ */
+ public static function categoryList()
+ {
+ $map = [
+ 'status' => '1',
+ 'model' => 'article',
+ ];
+ return CategoryModel::where($map)->select();
+ }
+
+ /**
+ * 采集公众号文章
+ * @param [type] $url [description]
+ * @param integer $uid [description]
+ * @return [type] [description]
+ */
+ public static function collect($url, $uid = 1)
+ {
+ $map = [
+ 'url' => $url,
+ 'uid' => $uid,
+ ];
+
+ $userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A403 Safari/8536.25';
+
+ $info = ArticleModel::where($map)->find();
+ if ($info) {
+ return $info->id;
+ } else {
+ $info = new ArticleModel;
+ $html = file_get_contents($url);
+ // $html = http($url, 'GET', '', '', $userAgent);
+
+ //获取文章标题
+ preg_match_all("/id=\"activity-name\">(.*)<\/h2>/is", $html, $title);
+ //获取文章内容部分
+ preg_match_all("/id=\"js_content\">(.*)
+
+