chore: 添加静态资源文件和版本配置文件
添加大量图片、字体、音频等静态资源文件,包括用户界面图片、模板文件和安装界面素材 添加系统版本配置文件(.version)和常量定义文件(.constant) 更新供应商依赖文件,包括Symfony VarDumper组件和相关许可证文件 添加验证码配置文件(captcha.php)和.gitignore规则
This commit is contained in:
122
app/services/article/ArticleCategoryServices.php
Normal file
122
app/services/article/ArticleCategoryServices.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\article;
|
||||
|
||||
use app\dao\article\ArticleCategoryDao;
|
||||
use app\services\BaseServices;
|
||||
use app\services\wechat\WechatNewsCategoryServices;
|
||||
use crmeb\exceptions\AdminException;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use think\annotation\Inject;
|
||||
use think\facade\Route as Url;
|
||||
|
||||
/**
|
||||
* 文章分类
|
||||
* Class ArticleCategoryServices
|
||||
* @package app\services\article
|
||||
* @mixin ArticleCategoryDao
|
||||
*/
|
||||
class ArticleCategoryServices extends BaseServices
|
||||
{
|
||||
/**
|
||||
* @var ArticleCategoryDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected ArticleCategoryDao $dao;
|
||||
|
||||
/**
|
||||
* 获取文章分类列表
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public function getList(array $where)
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->getList($where, $page, $limit);
|
||||
$count = $this->dao->count($where);
|
||||
return compact('list', 'count');
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成创建修改表单
|
||||
* @param int $id
|
||||
* @return array
|
||||
* @throws \FormBuilder\Exception\FormBuilderException
|
||||
*/
|
||||
public function createForm(int $id)
|
||||
{
|
||||
$method = 'POST';
|
||||
$url = '/cms/category';
|
||||
$title = '添加分类';
|
||||
if ($id) {
|
||||
$info = $this->dao->get($id);
|
||||
$method = 'PUT';
|
||||
$url = $url . '/' . $id;
|
||||
$title = '修改分类';
|
||||
}
|
||||
$f = array();
|
||||
$f[] = Form::hidden('id', $info['id'] ?? 0);
|
||||
$f[] = Form::input('title', '分类名称:', $info['title'] ?? '')->maxlength(20)->required();
|
||||
$f[] = Form::input('intr', '分类简介:', $info['intr'] ?? '')->type('textarea')->required();
|
||||
$f[] = Form::frameImage('image', '分类图片:', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')), $info['image'] ?? '')->icon('ios-add')->width('960px')->height('505px')->modal(['footer-hide' => true]);
|
||||
$f[] = Form::number('sort', '排序:', (int)($info['sort'] ?? 0))->min(0);
|
||||
$f[] = Form::radio('status', '状态:', $info['status'] ?? 1)->options([['value' => 1, 'label' => '显示'], ['value' => 0, 'label' => '隐藏']]);
|
||||
return create_form($title, $f, Url::buildUrl($url), $method);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
* @param array $data
|
||||
*/
|
||||
public function save(array $data)
|
||||
{
|
||||
$this->dao->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param array $data
|
||||
*/
|
||||
public function update(array $data)
|
||||
{
|
||||
$this->dao->update($data['id'], $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param int $id
|
||||
*/
|
||||
public function del(int $id)
|
||||
{
|
||||
/** @var WechatNewsCategoryServices $services */
|
||||
$services = app()->make(WechatNewsCategoryServices::class);
|
||||
$ids = $services->getNewIds();
|
||||
/** @var ArticleServices $articleService */
|
||||
$articleService = app()->make(ArticleServices::class);
|
||||
$count = $articleService->count(['cid' => $id, 'ids' => $ids]);
|
||||
if ($count > 0) {
|
||||
throw new AdminException('该分类下有文章,无法删除!');
|
||||
} else {
|
||||
$this->dao->delete($id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改状态
|
||||
* @param int $id
|
||||
* @param int $status
|
||||
*/
|
||||
public function setStatus(int $id, int $status)
|
||||
{
|
||||
$this->dao->update($id, ['status' => $status]);
|
||||
}
|
||||
}
|
||||
41
app/services/article/ArticleContentServices.php
Normal file
41
app/services/article/ArticleContentServices.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\article;
|
||||
|
||||
use app\dao\article\ArticleContentDao;
|
||||
use app\services\BaseServices;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
* 文章内容
|
||||
* Class ArticleContentServices
|
||||
* @package app\services\article
|
||||
* @mixin ArticleContentDao
|
||||
*/
|
||||
class ArticleContentServices extends BaseServices
|
||||
{
|
||||
/**
|
||||
* @var ArticleContentDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected ArticleContentDao $dao;
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param int $id
|
||||
* @return bool
|
||||
*/
|
||||
public function del(int $id)
|
||||
{
|
||||
return $this->dao->del($id);
|
||||
}
|
||||
}
|
||||
203
app/services/article/ArticleServices.php
Normal file
203
app/services/article/ArticleServices.php
Normal file
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\article;
|
||||
|
||||
use app\dao\article\ArticleDao;
|
||||
use app\services\BaseServices;
|
||||
use app\services\wechat\WechatNewsCategoryServices;
|
||||
use app\services\user\UserRelationServices;
|
||||
use crmeb\exceptions\AdminException;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
* 文章
|
||||
* Class ArticleServices
|
||||
* @package app\services\article
|
||||
* @mixin ArticleDao
|
||||
*/
|
||||
class ArticleServices extends BaseServices
|
||||
{
|
||||
/**
|
||||
* @var ArticleDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected ArticleDao $dao;
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public function getList(array $where, int $page = 0, int $limit = 0)
|
||||
{
|
||||
if (!$limit) {
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
}
|
||||
/** @var WechatNewsCategoryServices $services */
|
||||
$services = app()->make(WechatNewsCategoryServices::class);
|
||||
$where['ids'] = $services->getNewIds();
|
||||
$list = $this->dao->getList($where, $page, $limit);
|
||||
foreach ($list as &$item) {
|
||||
$item['store_name'] = $item['storeInfo']['store_name'] ?? '';
|
||||
}
|
||||
$count = $this->dao->count($where);
|
||||
return compact('list', 'count');
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增编辑文章
|
||||
* @param array $data
|
||||
*/
|
||||
public function save(array $data)
|
||||
{
|
||||
/** @var ArticleContentServices $articleContentService */
|
||||
$articleContentService = app()->make(ArticleContentServices::class);
|
||||
$content['content'] = $data['content'];
|
||||
$id = $data['id'];
|
||||
unset($data['content'], $data['id']);
|
||||
$info = $this->transaction(function () use ($id, $data, $articleContentService, $content) {
|
||||
if ($id) {
|
||||
$info = $this->dao->update($id, $data);
|
||||
$content['nid'] = $id;
|
||||
$res = $info && $articleContentService->update($id, $content, 'nid');
|
||||
} else {
|
||||
unset($data['id']);
|
||||
$data['add_time'] = time();
|
||||
$info = $this->dao->save($data);
|
||||
$content['nid'] = $info->id;
|
||||
$res = $info && $articleContentService->save($content);
|
||||
}
|
||||
if (!$res) {
|
||||
throw new AdminException('保存失败');
|
||||
} else {
|
||||
return $info;
|
||||
}
|
||||
});
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品详情
|
||||
* @param $id
|
||||
* @return array
|
||||
*/
|
||||
public function read(int $id)
|
||||
{
|
||||
$info = $this->dao->read($id);
|
||||
$info['cid'] = (int)$info['cid'];
|
||||
return compact('info');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品
|
||||
* @param int $id
|
||||
*/
|
||||
public function del(int $id)
|
||||
{
|
||||
/** @var ArticleContentServices $articleContentService */
|
||||
$articleContentService = app()->make(ArticleContentServices::class);
|
||||
$this->transaction(function () use ($id, $articleContentService) {
|
||||
$res = $this->dao->delete($id);
|
||||
$res = $res && $articleContentService->del($id);
|
||||
if (!$res) {
|
||||
throw new AdminException('删除失败');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 文章关联商品
|
||||
* @param int $id
|
||||
* @param int $product_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function bindProduct(int $id, int $product_id = 0)
|
||||
{
|
||||
return $this->dao->update($id, ['product_id' => $product_id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数量
|
||||
* @param array $where
|
||||
* @return int
|
||||
*/
|
||||
public function count(array $where)
|
||||
{
|
||||
return $this->dao->count($where);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一条数据
|
||||
* @param int $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function getInfo(int $uid, int $id)
|
||||
{
|
||||
$info = $this->dao->read($id);
|
||||
|
||||
if (!$info) {
|
||||
throw new AdminException('文章不存在或已删除');
|
||||
}
|
||||
$info->visit = ($info->visit ?? 0) + 1;
|
||||
if (!$info->save())
|
||||
throw new AdminException('请稍后查看');
|
||||
if ($info) {
|
||||
$info = $info->toArray();
|
||||
$info['visit'] = (int)$info['visit'];
|
||||
$info['add_time'] = date('Y-m-d', $info['add_time']);
|
||||
}
|
||||
/** @var UserRelationServices $relationServices */
|
||||
$relationServices = app()->make(UserRelationServices::class);
|
||||
$info['is_like'] = $relationServices->isProductRelation(['uid' => $uid, 'relation_id' => $id, 'type' => 'like', 'category' => 'article']);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文章点赞 添加、取消
|
||||
* @param int $id
|
||||
* @param array $where
|
||||
* @param int $uid
|
||||
* @return bool
|
||||
*/
|
||||
public function userArticleLikes(int $id, array $where, int $uid)
|
||||
{
|
||||
$info = $this->dao->read($id);
|
||||
if (!$info) {
|
||||
throw new AdminException('文章不存在或已删除');
|
||||
}
|
||||
$info->likes = $where['status'] > 0 ? ($info->likes ?? 0) + 1 : ($info->likes > 1 ? $info->likes - 1 : 0);
|
||||
if (!$info->save()) throw new AdminException('请稍后查看');
|
||||
$ids = [$id];
|
||||
/** @var UserRelationServices $relationServices */
|
||||
$relationServices = app()->make(UserRelationServices::class);
|
||||
return $relationServices->productRelation($uid, $ids, 'like', 'article', $where['status'] <= 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文章列表
|
||||
* @param $new_id
|
||||
* @return int
|
||||
*/
|
||||
public function articleList($new_id)
|
||||
{
|
||||
return $this->dao->articleLists($new_id);
|
||||
}
|
||||
|
||||
/**图文详情
|
||||
* @param $new_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function articlesList($new_id)
|
||||
{
|
||||
return $this->dao->articleContentList($new_id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user