Initial commit: queue workspace
Made-with: Cursor
This commit is contained in:
256
pro_v3.5.1/app/services/activity/video/VideoCommentServices.php
Normal file
256
pro_v3.5.1/app/services/activity/video/VideoCommentServices.php
Normal file
@@ -0,0 +1,256 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\services\activity\video;
|
||||
|
||||
use app\dao\activity\video\VideoCommentDao;
|
||||
use app\services\BaseServices;
|
||||
use app\services\user\UserRelationServices;
|
||||
use app\services\user\UserServices;
|
||||
use crmeb\exceptions\AdminException;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use think\annotation\Inject;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Route as Url;
|
||||
|
||||
|
||||
/**
|
||||
* Class VideoCommentServices
|
||||
* @package app\services\activity\video
|
||||
* @mixin VideoCommentDao
|
||||
*/
|
||||
class VideoCommentServices extends BaseServices
|
||||
{
|
||||
/**
|
||||
* @var VideoCommentDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected VideoCommentDao $dao;
|
||||
|
||||
/**
|
||||
* 视频评价列表
|
||||
* @param array $where
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function sysPage(array $where)
|
||||
{
|
||||
$where['pid'] = 0;
|
||||
$where['is_del'] = 0;
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$with = ['video', 'replyContent'];
|
||||
$list = $this->dao->getList($where, '*', $with, $page, $limit);
|
||||
$count = $this->dao->count($where);
|
||||
return compact('list', 'count');
|
||||
}
|
||||
|
||||
/**
|
||||
* 回复评论
|
||||
* @param int $id
|
||||
* @param string $content
|
||||
*/
|
||||
public function setReply(int $id, string $content)
|
||||
{
|
||||
if ($content == '') throw new AdminException('请输入回复内容');
|
||||
$comment = $this->dao->get($id);
|
||||
if (!$comment) {
|
||||
throw new AdminException('回复的评论不存在');
|
||||
}
|
||||
$save = [];
|
||||
$save['type'] = $comment['type'];
|
||||
$save['relation_id'] = $comment['relation_id'];
|
||||
$save['pid'] = $comment['pid'] ? $comment['pid'] : $id;
|
||||
$save['video_id'] = $comment['video_id'];
|
||||
$save['content'] = $content;
|
||||
$save['nickname'] = sys_config('site_name');
|
||||
$save['avatar'] = sys_config('wap_login_logo');
|
||||
$where = ['video_id' => $comment['video_id'], 'uid' => 0, 'pid' => $id, 'is_del' => 0];
|
||||
if ($this->dao->count($where)) {
|
||||
$res = $this->dao->update($where, ['content' => $content, 'update_time' => time()]);
|
||||
} else {
|
||||
$save['add_time'] = time();
|
||||
$res = $this->dao->save($save);
|
||||
/** @var VideoServices $videoServices */
|
||||
$videoServices = app()->make(VideoServices::class);
|
||||
$videoServices->bcInc($comment['video_id'], 'comment_num', '1');
|
||||
}
|
||||
if (!$res) throw new AdminException('回复失败,请稍后再试');
|
||||
$this->dao->update($id, ['is_reply' => 1]);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取评论回复列表
|
||||
* @param int $id
|
||||
* @param array $where
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getCommentReplyList(int $id, array $where)
|
||||
{
|
||||
$comment = $this->dao->get($id);
|
||||
if (!$comment) {
|
||||
throw new AdminException('回复的评论不存在');
|
||||
}
|
||||
$where['pid'] = $id;
|
||||
$where['is_del'] = 0;
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->getList($where, '*', ['video', 'user' => function ($query) {
|
||||
$query->field('uid,avatar,nickname,is_money_level');
|
||||
}, 'children' => function ($query) {
|
||||
$query->with([
|
||||
'user' => function ($query) {
|
||||
$query->field('uid,avatar,nickname,is_money_level');
|
||||
}
|
||||
]);
|
||||
}], $page, $limit);
|
||||
$count = $this->dao->count($where);
|
||||
return compact('list', 'count');
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建虚拟评论表单
|
||||
* @param int $video_id
|
||||
* @param $store_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function createForm(int $video_id, $store_id = 0)
|
||||
{
|
||||
if ($video_id == 0) {
|
||||
$field[] = Form::frameImage('video', '视频', Url::buildUrl($store_id ? 'store/video.shortVideo/index' : 'admin/video.shortVideo/index', array('fodder' => 'video')))->icon('ios-add')->width('960px')->height('560px')->modal(['footer-hide' => true])->Props(['srcKey' => 'image']);
|
||||
} else {
|
||||
$field[] = Form::hidden('video_id', $video_id);
|
||||
}
|
||||
$field[] = Form::frameImage('avatar', '用户头像', Url::buildUrl($store_id ? 'store/widget.images/index' : 'admin/widget.images/index', array('fodder' => 'avatar')))->icon('ios-add')->width('960px')->height('505px')->modal(['footer-hide' => true]);
|
||||
$field[] = Form::input('nickname', '用户名称')->col(24);
|
||||
$field[] = Form::input('content', '评价文字')->type('textarea');
|
||||
$field[] = Form::dateTime('add_time', '评论时间', '')->placeholder('请选择评论时间(不选择默认当前添加时间)');
|
||||
return create_form('添加虚拟评论', $field, Url::buildUrl('/marketing/video/comment/save_fictitious'), 'POST');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存评价、回复
|
||||
* @param int $uid
|
||||
* @param int $video_id
|
||||
* @param $id
|
||||
* @param array $data
|
||||
* @return \crmeb\basic\BaseModel|\think\Model
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function saveComment(int $uid, int $video_id, $id, array $data)
|
||||
{
|
||||
/** @var VideoServices $videoServices */
|
||||
$videoServices = app()->make(VideoServices::class);
|
||||
$video = $videoServices->get($video_id);
|
||||
if (!$video) {
|
||||
throw new AdminException('评论的视频不存在');
|
||||
}
|
||||
$pid = $id;
|
||||
if ($id) {//回复评价
|
||||
$comment = $this->dao->get($id);
|
||||
if (!$comment) {
|
||||
throw new ValidateException('评论不存在或已删除');
|
||||
}
|
||||
if ($comment['pid']) $pid = $comment['pid'];
|
||||
}
|
||||
if ($uid && $uid != -1) {
|
||||
/** @var UserServices $userServices */
|
||||
$userServices = app()->make(UserServices::class);
|
||||
$userInfo = $userServices->getUserInfo($uid);
|
||||
if (!$userInfo) {
|
||||
throw new ValidateException('用户不存在');
|
||||
}
|
||||
$data['nickname'] = $userInfo['nickname'] ?? '';
|
||||
$data['avatar'] = $userInfo['avatar'] ?? '';
|
||||
}
|
||||
//ip转城市信息
|
||||
if (isset($data['ip']) && $data['ip']) {
|
||||
$data['city'] = $this->convertIp($data['ip']);
|
||||
}
|
||||
$data['uid'] = $uid;
|
||||
$data['video_id'] = $video_id;
|
||||
$data['pid'] = $pid;
|
||||
$data['type'] = $video['type'];
|
||||
$data['relation_id'] = $video['relation_id'];
|
||||
$time = time();
|
||||
if (isset($data['add_time']) && $data['add_time']) {
|
||||
if ($data['add_time'] > $time) {
|
||||
throw new AdminException('评论时间应小于当前时间');
|
||||
}
|
||||
$data['add_time'] = strtotime($data['add_time']);
|
||||
} else {
|
||||
$data['add_time'] = $time;
|
||||
}
|
||||
$res = $this->dao->save($data);
|
||||
/** @var VideoServices $videoServices */
|
||||
$videoServices = app()->make(VideoServices::class);
|
||||
$videoServices->bcInc($video_id, 'comment_num', 1);
|
||||
if (!$res) throw new AdminException('保存评论失败');
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取短视频评价列表
|
||||
* @param int $uid
|
||||
* @param int $id
|
||||
* @param int $pid
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getVideoCommentList(int $uid, int $id, int $pid = 0)
|
||||
{
|
||||
$where = ['video_id' => $id, 'is_del' => 0];
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
if ($limit > 20) $limit = 20;
|
||||
|
||||
if ($pid) {
|
||||
$comment = $this->dao->get($pid);
|
||||
if (!$comment) {
|
||||
throw new ValidateException('评论不存在或已删除');
|
||||
}
|
||||
$where['video_id'] = $comment['video_id'];
|
||||
}
|
||||
$where['pid'] = $pid;
|
||||
$list = $this->dao->getList($where, 'id,pid,video_id,uid,nickname,avatar,content,like_num,city,add_time', ['children' => function ($query) {
|
||||
$query->field("id,pid")->with(['userVip']);
|
||||
}, 'userVip'], $page, $limit);
|
||||
if ($list) {
|
||||
$userLike = [];
|
||||
if ($uid) {
|
||||
$ids = array_column($list, 'id');
|
||||
/** @var UserRelationServices $userRelationServices */
|
||||
$userRelationServices = app()->make(UserRelationServices::class);
|
||||
$userLike = $userRelationServices->getColumn([['uid', '=', $uid], ['relation_id', 'in', $ids], ['category', '=', 'video_comment'], ['type', '=', 'like']], 'id,relation_id', 'relation_id');
|
||||
}
|
||||
foreach ($list as &$item) {
|
||||
$item['add_time'] = $item['add_time'] ? date('Y-m-d H:i:s', $item['add_time']) : '';
|
||||
$item['is_like'] = isset($userLike[$item['id']]);
|
||||
$item['reply'] = [];
|
||||
$item['reply_count'] = isset($item['children']) ? (int)count($item['children']) : 0;
|
||||
$item['city'] = $this->addressHandle($item['city'])['city'] ?? '';
|
||||
unset($item['children']);
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
346
pro_v3.5.1/app/services/activity/video/VideoServices.php
Normal file
346
pro_v3.5.1/app/services/activity/video/VideoServices.php
Normal file
@@ -0,0 +1,346 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\services\activity\video;
|
||||
|
||||
use app\dao\activity\video\VideoDao;
|
||||
use app\jobs\activity\VideoJob;
|
||||
use app\services\activity\live\LiveRoomServices;
|
||||
use app\services\BaseServices;
|
||||
use app\services\product\product\StoreProductServices;
|
||||
use app\services\product\category\StoreProductCategoryServices;
|
||||
use app\services\user\UserRelationServices;
|
||||
use think\annotation\Inject;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
|
||||
/**
|
||||
* Class VideoServices
|
||||
* @package app\services\activity\video
|
||||
* @mixin VideoDao
|
||||
*/
|
||||
class VideoServices extends BaseServices
|
||||
{
|
||||
|
||||
/**
|
||||
* 移动端视频需要默认值
|
||||
* @var array
|
||||
*/
|
||||
protected array $videoDefault = [
|
||||
'isMore' => false,
|
||||
'state' => "pause",
|
||||
'playIng' => false,
|
||||
'isShowimage' => false,
|
||||
'isShowProgressBarTime' => false,
|
||||
'isplay' => true
|
||||
];
|
||||
|
||||
/**
|
||||
* @var VideoDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected VideoDao $dao;
|
||||
|
||||
/**
|
||||
* 获取短视频信息(获取不到抛出异常)
|
||||
* @param int $id
|
||||
* @param string $field
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getVideoInfo(int $id, string $field = '*')
|
||||
{
|
||||
$videoInfo = $this->dao->getOne(['id' => $id], $field);
|
||||
if (!$videoInfo) {
|
||||
throw new ValidateException('获取短视频信息失败');
|
||||
}
|
||||
return $videoInfo->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取视频详情
|
||||
* @param int $id
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getInfo(int $id)
|
||||
{
|
||||
$info = $this->dao->get($id);
|
||||
if (!$info) {
|
||||
throw new ValidateException('视频不存在');
|
||||
}
|
||||
$info = $info->toArray();
|
||||
$productInfo = [];
|
||||
$info['type_name'] = '平台';
|
||||
if ($info['product_id']) {
|
||||
$info['product_id'] = is_string($info['product_id']) ? explode(',', $info['product_id']) : $info['product_id'];
|
||||
/** @var StoreProductServices $productServices */
|
||||
$productServices = app()->make(StoreProductServices::class);
|
||||
$product_where = ['is_del' => 0, 'is_show' => 1, 'is_verify' => 1];
|
||||
$productInfo = $productServices->getSearchList($product_where + ['ids' => $info['product_id']], 0, 0, ['id', 'type', 'product_type', 'price', 'image', 'store_name', 'cate_id', 'sales', 'stock'], '', []);
|
||||
if ($productInfo) {
|
||||
$cateIds = implode(',', array_column($productInfo, 'cate_id'));
|
||||
/** @var StoreProductCategoryServices $categoryService */
|
||||
$categoryService = app()->make(StoreProductCategoryServices::class);
|
||||
$cateList = $categoryService->getCateParentAndChildName($cateIds);
|
||||
foreach ($productInfo as $key => &$item) {
|
||||
$item['cate_name'] = '';
|
||||
if (isset($item['cate_id']) && $item['cate_id']) {
|
||||
$cate_ids = explode(',', $item['cate_id']);
|
||||
$cate_name = $categoryService->getCateName($cate_ids, $cateList);
|
||||
if ($cate_name) {
|
||||
$item['cate_name'] = is_array($cate_name) ? implode(',', $cate_name) : '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$info['productInfo'] = $productInfo;
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台获取视频列表
|
||||
* @param $where
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function sysPage($where)
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->getList($where, '*', $page, $limit);
|
||||
$count = 0;
|
||||
if ($list) {
|
||||
$site_name = sys_config('site_name');
|
||||
$site_image = sys_config('wap_login_logo');
|
||||
/** @var StoreProductServices $productServices */
|
||||
$productServices = app()->make(StoreProductServices::class);
|
||||
$product_where = ['is_del' => 0, 'is_show' => 1, 'is_verify' => 1];
|
||||
foreach ($list as &$item) {
|
||||
$item['product_id'] = is_string($item['product_id']) ? explode(',', $item['product_id']) : $item['product_id'];
|
||||
$item['product_info'] = [];
|
||||
$item['product_num'] = 0;
|
||||
if ($item['product_id']) {
|
||||
$item['product_info'] = $productServices->getSearchList($product_where + ['ids' => $item['product_id']], 0, 0, ['id', 'store_name', 'image', 'price'], '', []);
|
||||
$item['product_num'] = count($item['product_info']);
|
||||
}
|
||||
|
||||
$item['type_name'] = $site_name;
|
||||
$item['type_image'] = $site_image;
|
||||
$item['add_time'] = $item['add_time'] ? date('Y-m-d H:i:s', $item['add_time']) : '';
|
||||
}
|
||||
$count = $this->dao->count($where);
|
||||
}
|
||||
|
||||
return compact('list', 'count');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取短视频列表
|
||||
* @param int $uid
|
||||
* @param string $field
|
||||
* @param int $order_type
|
||||
* @param int $id
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getVideoList(int $uid, string $field = '*', int $order_type = 1, int $id = 0)
|
||||
{
|
||||
//短视频未启用
|
||||
if (!sys_config('video_func_status', 1)) {
|
||||
return [];
|
||||
}
|
||||
$where = ['is_show' => 1, 'is_del' => 0, 'is_verify' => 1];
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
//限制一次最多请求条数
|
||||
if ($limit > 10) $limit = 10;
|
||||
if ($id) {//指定视频进入
|
||||
$ids = array_merge([$id], $this->dao->getColumn($where, 'id'));
|
||||
$where['order_by_id'] = array_slice($ids, 0, $limit);
|
||||
$order = '';
|
||||
} elseif ($order_type == 1) {//最新
|
||||
$order = 'id desc,sort desc';
|
||||
} else if ($order_type == 2) {//推荐
|
||||
$where['is_recommend'] = 1;
|
||||
$order = 'is_recommend desc,sort desc,id desc';
|
||||
} else {
|
||||
$order = 'sort desc,id desc';
|
||||
}
|
||||
$list = $this->dao->getList($where, $field, $page, $limit, $order);
|
||||
if ($list) {
|
||||
/** @var LiveRoomServices $liveServices */
|
||||
$liveServices = app()->make(LiveRoomServices::class);
|
||||
$liveCount = $liveServices->count(['is_show' => 1, 'is_del' => 0, 'status' => 1, 'live_status' => [101, 105, 106]]);
|
||||
$is_live = (bool)$liveCount;
|
||||
$site_name = sys_config('site_name');
|
||||
$site_image = sys_config('wap_login_logo');
|
||||
$userLike = $userCollect = [];
|
||||
$ids = array_column($list, 'id');
|
||||
if ($uid) {
|
||||
/** @var UserRelationServices $userRelationServices */
|
||||
$userRelationServices = app()->make(UserRelationServices::class);
|
||||
$userLike = $userRelationServices->getColumn([['uid', '=', $uid], ['relation_id', 'in', $ids], ['category', '=', 'video'], ['type', '=', 'like']], 'id,relation_id', 'relation_id');
|
||||
$userCollect = $userRelationServices->getColumn([['uid', '=', $uid], ['relation_id', 'in', $ids], ['category', '=', 'video'], ['type', '=', 'collect']], 'id,relation_id', 'relation_id');
|
||||
}
|
||||
/** @var StoreProductServices $storeProductServices */
|
||||
$storeProductServices = app()->make(StoreProductServices::class);
|
||||
$productWhere = ['is_show' => 1, 'is_del' => 0, 'is_verify' => 1];
|
||||
foreach ($list as &$item) {
|
||||
$item['product_id'] = is_string($item['product_id']) ? explode(',', $item['product_id']) : $item['product_id'];
|
||||
$item['product_num'] = count($item['product_id']);
|
||||
//过滤下架、审核中等商品
|
||||
$item['product_num'] = $item['product_num'] ? $storeProductServices->getCount($productWhere + ['ids' => $item['product_id']]) : 0;
|
||||
$item['type_name'] = $site_name;
|
||||
$item['type_image'] = $site_image;
|
||||
$item['date'] = $item['add_time'] ? date('m月d日', $item['add_time']) : '';
|
||||
$item['add_time'] = $item['add_time'] ? date('Y-m-d H:i:s', $item['add_time']) : '';
|
||||
$item['is_like'] = isset($userLike[$item['id']]);
|
||||
$item['is_collect'] = isset($userCollect[$item['id']]);
|
||||
//app需要
|
||||
$item['id'] = (string)$item['id'];
|
||||
$item = array_merge($item, $this->videoDefault);
|
||||
$item['is_live'] = $is_live;
|
||||
}
|
||||
//增加浏览量
|
||||
VideoJob::dispatchDo('setVideoPlayNum', [$ids, $uid]);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取推荐短信视频
|
||||
* @param int $id
|
||||
* @param int $limit
|
||||
* @return array|mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getRecommend(int $id, int $limit = 1)
|
||||
{
|
||||
$where = ['is_show' => 1, 'is_del' => 0, 'is_recommend' => 1, 'notId' => $id];
|
||||
$list = $this->dao->getList($where, 'id,desc', 0, $limit, 'rand');
|
||||
$res = [];
|
||||
if ($limit == 1) {
|
||||
if ($list) {
|
||||
$res = $list[0] ?? [];
|
||||
}
|
||||
} else {
|
||||
$res = $list;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* diy获取短视频
|
||||
* @param int $uid
|
||||
* @param string $field
|
||||
* @param int $order_type
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getDiyVideoList(int $uid, string $field = '*', int $order_type = 0)
|
||||
{
|
||||
//短视频未启用
|
||||
if (!sys_config('video_func_status', 1)) {
|
||||
return [];
|
||||
}
|
||||
$where = ['is_show' => 1, 'is_del' => 0, 'is_verify' => 1];
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
//限制一次最多请求条数
|
||||
if ($limit > 10) $limit = 10;
|
||||
if ($order_type == 1) {//最新
|
||||
$order = 'id desc,sort desc';
|
||||
} else if ($order_type == 2) {//推荐
|
||||
$where['is_recommend'] = 1;
|
||||
$order = 'is_recommend desc,sort desc,id desc';
|
||||
} else {
|
||||
$order = 'sort desc,id desc';
|
||||
}
|
||||
$list = $this->dao->getList($where, $field, $page, $limit, $order);
|
||||
if ($list) {
|
||||
$site_name = sys_config('site_name');
|
||||
$site_image = sys_config('wap_login_logo');
|
||||
/** @var StoreProductServices $productServices */
|
||||
$productServices = app()->make(StoreProductServices::class);
|
||||
$product_where = ['is_del' => 0, 'is_show' => 1, 'is_verify' => 1];
|
||||
foreach ($list as &$item) {
|
||||
$item['product_id'] = is_string($item['product_id']) ? explode(',', $item['product_id']) : $item['product_id'];
|
||||
$item['product_info'] = [];
|
||||
$item['product_num'] = 0;
|
||||
if ($item['product_id']) {
|
||||
$item['product_info'] = $productServices->getSearchList($product_where + ['ids' => $item['product_id']], 0, 0, ['id', 'store_name', 'image', 'price'], '', []);
|
||||
$item['product_num'] = count($item['product_info']);
|
||||
}
|
||||
$item['type_name'] = $site_name;
|
||||
$item['type_image'] = $site_image;
|
||||
$item['add_time'] = $item['add_time'] ? date('Y-m-d H:i:s', $item['add_time']) : '';
|
||||
}
|
||||
$ids = array_column($list, 'id');
|
||||
//增加浏览量
|
||||
VideoJob::dispatchDo('setVideoPlayNum', [$ids, $uid]);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户点赞、收藏、分享、浏览播放视频
|
||||
* @param int $uid
|
||||
* @param int $id
|
||||
* @param string $type
|
||||
* @param int $num
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function userRelationVideo(int $uid, int $id, string $type = 'like', int $num = 1)
|
||||
{
|
||||
$info = $this->getVideoInfo((int)$id);
|
||||
$data = ['uid' => $uid, 'relation_id' => $id, 'category' => UserRelationServices::CATEGORY_VIDEO, 'type' => $type];
|
||||
$typeArr = UserRelationServices::TYPE_NAME;
|
||||
if (!isset($typeArr[$type])) {
|
||||
throw new ValidateException('类型错误');
|
||||
}
|
||||
/** @var UserRelationServices $userRelationServices */
|
||||
$userRelationServices = app()->make(UserRelationServices::class);
|
||||
//播放 每一次都是增加数量
|
||||
if ($type != 'play') {
|
||||
$relation = $userRelationServices->get($data);
|
||||
} else {
|
||||
$relation = [];
|
||||
}
|
||||
$field = $type . '_num';
|
||||
$balance = $info[$field] ?? 0;
|
||||
if ($relation) {//取消
|
||||
$userRelationServices->delete($relation['id']);
|
||||
$new = (int)bcsub((string)$balance, (string)$num);
|
||||
} else {//增加
|
||||
$data['add_time'] = time();
|
||||
$userRelationServices->save($data);
|
||||
$new = (int)bcadd((string)$balance, (string)$num);
|
||||
}
|
||||
$new = max($new, 0);
|
||||
$this->dao->update($id, [$field => $new]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user