其余文件
This commit is contained in:
230
app/common/model/community/CommunityArticle.php
Normal file
230
app/common/model/community/CommunityArticle.php
Normal file
@ -0,0 +1,230 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\model\community;
|
||||
|
||||
|
||||
use app\common\basics\Models;
|
||||
use app\common\enum\CommunityArticleEnum;
|
||||
use app\common\model\goods\Goods;
|
||||
use app\common\model\shop\Shop;
|
||||
use app\common\model\user\User;
|
||||
|
||||
/**
|
||||
* 种草社区文章
|
||||
* Class CommunityCategory
|
||||
* @package app\common\model\content
|
||||
*/
|
||||
class CommunityArticle extends Models
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 关联作者信息
|
||||
* @return \think\model\relation\HasOne
|
||||
* @author 段誉
|
||||
* @date 2022/4/29 17:59
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne(User::class, 'id', 'user_id');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 关联文章图片
|
||||
* @return \think\model\relation\HasMany
|
||||
* @author 段誉
|
||||
* @date 2022/4/29 11:29
|
||||
*/
|
||||
public function images()
|
||||
{
|
||||
return $this->hasMany(CommunityArticleImage::class, 'article_id', 'id');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 关联话题
|
||||
* @return \think\model\relation\HasOne
|
||||
* @author 段誉
|
||||
* @date 2022/5/6 14:37
|
||||
*/
|
||||
public function topic()
|
||||
{
|
||||
return $this->hasOne(CommunityTopic::class, 'id', 'topic_id');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 关联商品相关信息
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @return array|\think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/5/6 10:05
|
||||
*/
|
||||
public function getGoodsDataAttr($value, $data)
|
||||
{
|
||||
if (empty($data['goods'])) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$result = Goods::field(['id', 'name', 'image'])
|
||||
->where(['status' => 1, 'del' => 0])
|
||||
->whereIn('id', $data['goods'])
|
||||
->select();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 关联店铺信息
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @return array|\think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/5/6 17:55
|
||||
*/
|
||||
public function getShopDataAttr($value, $data)
|
||||
{
|
||||
if (empty($data['shop'])) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$result = Shop::field(['id', 'name', 'logo'])
|
||||
->where(['is_freeze' => 0, 'del' => 0, 'is_run' => 1])
|
||||
->whereIn('id', $data['shop'])
|
||||
->select();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @notes 状态属性
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @return string|string[]
|
||||
* @author 段誉
|
||||
* @date 2022/5/9 18:13
|
||||
*/
|
||||
public function getStatusDescAttr($value, $data)
|
||||
{
|
||||
return CommunityArticleEnum::getStatusDesc($data['status']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 文章所选店铺格式化
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @return false|string|string[]
|
||||
* @author 段誉
|
||||
* @date 2022/4/29 10:55
|
||||
*/
|
||||
public function getShopAttr($value, $data)
|
||||
{
|
||||
return $this->formattingData($value, 'explode');
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 文章所选店铺格式化
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @return false|string|string[]
|
||||
* @author 段誉
|
||||
* @date 2022/4/29 10:55
|
||||
*/
|
||||
public function setShopAttr($value, $data)
|
||||
{
|
||||
return $this->formattingData($value, 'implode');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 文章所选商品格式化
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @return false|string|string[]
|
||||
* @author 段誉
|
||||
* @date 2022/4/29 10:55
|
||||
*/
|
||||
public function getGoodsAttr($value, $data)
|
||||
{
|
||||
return $this->formattingData($value, 'explode');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 文章所选商品格式化
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @return false|string|string[]
|
||||
* @author 段誉
|
||||
* @date 2022/4/29 10:55
|
||||
*/
|
||||
public function setGoodsAttr($value, $data)
|
||||
{
|
||||
return $this->formattingData($value, 'implode');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 格式化数据
|
||||
* @param $params
|
||||
* @param $operation
|
||||
* @return array|string
|
||||
* @author 段誉
|
||||
* @date 2022/5/6 9:50
|
||||
*/
|
||||
protected function formattingData($params, $operation)
|
||||
{
|
||||
if (empty($params) || !in_array($operation, ['explode', 'implode'])) {
|
||||
return $operation == 'explode' ? [] : $params;
|
||||
}
|
||||
|
||||
if ('explode' == $operation) {
|
||||
return array_map('intval', explode(',', $params));
|
||||
}
|
||||
return implode(',', $params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 增加点赞数量
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @author 段誉
|
||||
* @date 2022/5/9 15:34
|
||||
*/
|
||||
public static function incLike($id)
|
||||
{
|
||||
return self::where(['id' => $id])->inc('like')->update();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 减少点赞数量
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @author 段誉
|
||||
* @date 2022/5/9 15:37
|
||||
*/
|
||||
public static function decLike($id)
|
||||
{
|
||||
$where = [
|
||||
['id', '=', $id],
|
||||
['like', '>=', 1]
|
||||
];
|
||||
return self::where($where)->dec('like')->update();
|
||||
}
|
||||
|
||||
}
|
||||
17
app/common/model/community/CommunityArticleImage.php
Normal file
17
app/common/model/community/CommunityArticleImage.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\model\community;
|
||||
|
||||
|
||||
use app\common\basics\Models;
|
||||
|
||||
/**
|
||||
* 种草社区文章图片
|
||||
* Class CommunityCategory
|
||||
* @package app\common\model\content
|
||||
*/
|
||||
class CommunityArticleImage extends Models
|
||||
{
|
||||
|
||||
}
|
||||
29
app/common/model/community/CommunityCategory.php
Normal file
29
app/common/model/community/CommunityCategory.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\model\community;
|
||||
|
||||
|
||||
use app\common\basics\Models;
|
||||
|
||||
/**
|
||||
* 种草社区分类
|
||||
* Class CommunityCategory
|
||||
* @package app\common\model\content
|
||||
*/
|
||||
class CommunityCategory extends Models
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 关联话题
|
||||
* @return \think\model\relation\HasMany
|
||||
* @author 段誉
|
||||
* @date 2022/4/29 16:33
|
||||
*/
|
||||
public function topic()
|
||||
{
|
||||
return $this->hasMany(CommunityTopic::class, 'cid', 'id');
|
||||
}
|
||||
|
||||
}
|
||||
109
app/common/model/community/CommunityComment.php
Normal file
109
app/common/model/community/CommunityComment.php
Normal file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\model\community;
|
||||
|
||||
|
||||
use app\common\basics\Models;
|
||||
use app\common\enum\CommunityCommentEnum;
|
||||
use app\common\model\user\User;
|
||||
|
||||
|
||||
/**
|
||||
* 种草社区评论
|
||||
* Class CommunityComment
|
||||
* @package app\common\model\community
|
||||
*/
|
||||
class CommunityComment extends Models
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 关联用户
|
||||
* @return \think\model\relation\HasOne
|
||||
* @author 段誉
|
||||
* @date 2022/5/7 15:22
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne(User::class, 'id', 'user_id')
|
||||
->bind(['nickname', 'avatar', 'sn']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 子级
|
||||
* @return \think\model\relation\HasMany
|
||||
* @author 段誉
|
||||
* @date 2022/5/10 11:45
|
||||
*/
|
||||
public function child()
|
||||
{
|
||||
return $this->hasMany(self::class, 'id', 'pid');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 关联文章
|
||||
* @return \think\model\relation\HasOne
|
||||
* @author 段誉
|
||||
* @date 2022/5/10 11:46
|
||||
*/
|
||||
public function article()
|
||||
{
|
||||
return $this->hasOne(CommunityArticle::class, 'id', 'article_id');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 一级评论的所有子级评论
|
||||
* @param $value
|
||||
* @param $data
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/5/9 14:28
|
||||
*/
|
||||
public function getChildAttr($value, $data)
|
||||
{
|
||||
$lists = self::with(['user'])
|
||||
->whereFindInSet('ancestor_relation', $data['id'])
|
||||
->where(['del' => 0, 'status' => CommunityCommentEnum::STATUS_SUCCESS])
|
||||
->order(['like' => 'desc'])
|
||||
->select()->toArray();
|
||||
return $lists;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 增加点赞数量
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @author 段誉
|
||||
* @date 2022/5/9 15:35
|
||||
*/
|
||||
public static function incLike($id)
|
||||
{
|
||||
return self::where(['id' => $id])->inc('like')->update();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 减少点赞数量
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @author 段誉
|
||||
* @date 2022/5/9 15:38
|
||||
*/
|
||||
public static function decLike($id)
|
||||
{
|
||||
$where = [
|
||||
['id', '=', $id],
|
||||
['like', '>=', 1]
|
||||
];
|
||||
return self::where($where)->dec('like')->update();
|
||||
}
|
||||
|
||||
}
|
||||
22
app/common/model/community/CommunityFollow.php
Normal file
22
app/common/model/community/CommunityFollow.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\model\community;
|
||||
|
||||
|
||||
use app\common\basics\Models;
|
||||
|
||||
|
||||
/**
|
||||
* 种草社区关注
|
||||
* Class CommunityFollow
|
||||
* @package app\common\model\community
|
||||
*/
|
||||
class CommunityFollow extends Models
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
31
app/common/model/community/CommunityLike.php
Normal file
31
app/common/model/community/CommunityLike.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\model\community;
|
||||
|
||||
|
||||
use app\common\basics\Models;
|
||||
use app\common\model\user\User;
|
||||
|
||||
/**
|
||||
* 种草社区点赞
|
||||
* Class CommunityLike
|
||||
* @package app\common\model\community
|
||||
*/
|
||||
class CommunityLike extends Models
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 关联用户
|
||||
* @return \think\model\relation\HasOne
|
||||
* @author 段誉
|
||||
* @date 2022/5/10 19:03
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne(User::class, 'id', 'user_id')
|
||||
->bind(['nickname', 'avatar', 'sn']);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
31
app/common/model/community/CommunitySearchRecord.php
Normal file
31
app/common/model/community/CommunitySearchRecord.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\model\community;
|
||||
|
||||
|
||||
use app\common\basics\Models;
|
||||
|
||||
|
||||
/**
|
||||
* 种草社区搜索记录
|
||||
* Class CommunitySearchRecord
|
||||
* @package app\common\model\community
|
||||
*/
|
||||
class CommunitySearchRecord extends Models
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 增加搜索次数
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @author 段誉
|
||||
* @date 2022/5/9 16:18
|
||||
*/
|
||||
public static function incCount($id)
|
||||
{
|
||||
return self::where(['id' => $id])->inc('count')->update();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
45
app/common/model/community/CommunityTopic.php
Normal file
45
app/common/model/community/CommunityTopic.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\model\community;
|
||||
|
||||
|
||||
use app\common\basics\Models;
|
||||
|
||||
/**
|
||||
* 种草社区话题
|
||||
* Class CommunityCategory
|
||||
* @package app\common\model\content
|
||||
*/
|
||||
class CommunityTopic extends Models
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 关联分类
|
||||
* @return \think\model\relation\HasOne
|
||||
* @author 段誉
|
||||
* @date 2022/4/28 14:18
|
||||
*/
|
||||
public function cate()
|
||||
{
|
||||
return $this->hasOne(CommunityCategory::class, 'id', 'cid');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 扣减文章数量
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @author 段誉
|
||||
* @date 2022/5/10 16:43
|
||||
*/
|
||||
public static function decArticleNum($id)
|
||||
{
|
||||
return self::where([
|
||||
['id', '=', $id],
|
||||
['article_num', '>=', 1]
|
||||
])->dec('article_num')->update();
|
||||
}
|
||||
|
||||
}
|
||||
37
app/common/model/community/CommunityUser.php
Normal file
37
app/common/model/community/CommunityUser.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\model\community;
|
||||
|
||||
|
||||
use app\common\basics\Models;
|
||||
|
||||
/**
|
||||
* 种草社区用户信息
|
||||
* Class CommunityUser
|
||||
* @package app\common\model\community
|
||||
*/
|
||||
class CommunityUser extends Models
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 获取用户信息
|
||||
* @param $user_id
|
||||
* @return array|\think\Model
|
||||
* @author 段誉
|
||||
* @date 2022/5/5 18:00
|
||||
*/
|
||||
public static function getUserInfo($user_id)
|
||||
{
|
||||
$user = self::where(['user_id' => $user_id])->findOrEmpty();
|
||||
|
||||
if ($user->isEmpty()) {
|
||||
$user = self::create([
|
||||
'user_id' => $user_id
|
||||
]);
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user