173 lines
5.2 KiB
PHP
173 lines
5.2 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||
// +----------------------------------------------------------------------
|
||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||
// | 开源版本可自由商用,可去除界面版权logo
|
||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||
// | 访问官网:https://www.likeadmin.cn
|
||
// | likeadmin团队 版权所有 拥有最终解释权
|
||
// +----------------------------------------------------------------------
|
||
// | author: likeadminTeam
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\adminapi\logic\item;
|
||
|
||
|
||
use app\common\model\item\Item;
|
||
use app\common\logic\BaseLogic;
|
||
use think\facade\Db;
|
||
use app\common\service\FileService;
|
||
|
||
|
||
/**
|
||
* 项目逻辑
|
||
* Class ItemLogic
|
||
* @package app\adminapi\logic\item
|
||
*/
|
||
class ItemLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加项目
|
||
* @param array $params
|
||
* @return bool
|
||
* @author BD
|
||
* @date 2024/01/16 13:23
|
||
*/
|
||
public static function add(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
$langs = $params['langs'];
|
||
|
||
foreach ($langs as &$content_lang) {
|
||
$content_lang['image'] = FileService::setFileUrl($content_lang['image']);
|
||
$content_lang['content'] = clear_file_domain($content_lang['content']);
|
||
}
|
||
|
||
Item::create([
|
||
'cid' => $params['cid'],
|
||
'type' => $params['type'],
|
||
'title' => $params['title'],
|
||
'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '',
|
||
'content' => $params['content'],
|
||
'min_money' => $params['min_money'],
|
||
'max_money' => $params['max_money'],
|
||
'rate' => $params['rate'],
|
||
'cycle' => $params['cycle'],
|
||
'point' => $params['point'],
|
||
'member_id' => $params['member_id'],
|
||
'progress' => $params['progress'],
|
||
'progress_auto' => $params['progress_auto'],
|
||
'is_show' => $params['is_show'],
|
||
'sort' => $params['sort'],
|
||
'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE),
|
||
]);
|
||
|
||
Db::commit();
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
self::setError($e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑项目
|
||
* @param array $params
|
||
* @return bool
|
||
* @author BD
|
||
* @date 2024/01/16 13:23
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
$langs = $params['langs'];
|
||
|
||
foreach ($langs as &$content_lang) {
|
||
$content_lang['image'] = FileService::setFileUrl($content_lang['image']);
|
||
$content_lang['content'] = clear_file_domain($content_lang['content']);
|
||
}
|
||
Item::update([
|
||
'id' => $params['id'],
|
||
'cid' => $params['cid'],
|
||
'type' => $params['type'],
|
||
'title' => $params['title'],
|
||
'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '',
|
||
'content' => $params['content'],
|
||
'min_money' => $params['min_money'],
|
||
'max_money' => $params['max_money'],
|
||
'rate' => $params['rate'],
|
||
'cycle' => $params['cycle'],
|
||
'point' => $params['point'],
|
||
'member_id' => $params['member_id'],
|
||
'progress' => $params['progress'],
|
||
'progress_auto' => $params['progress_auto'],
|
||
'is_show' => $params['is_show'],
|
||
'sort' => $params['sort'],
|
||
'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE),
|
||
]);
|
||
|
||
Db::commit();
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
self::setError($e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 删除项目
|
||
* @param array $params
|
||
* @return bool
|
||
* @author BD
|
||
* @date 2024/01/16 13:23
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return Item::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取项目详情
|
||
* @param $params
|
||
* @return array
|
||
* @author BD
|
||
* @date 2024/01/16 13:23
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$item = Item::findOrEmpty($params['id'])->toArray();
|
||
$langs = json_decode($item['langs'], true);
|
||
if(empty($langs)){
|
||
$langs = [];
|
||
}
|
||
$item['langs'] = $langs;
|
||
return $item;
|
||
}
|
||
|
||
/**
|
||
* @notes 更改状态
|
||
* @param array $params
|
||
* @return bool
|
||
* @author BD
|
||
* @date 2023/9/22 16:38
|
||
*/
|
||
public static function updateIndexStatus(array $params)
|
||
{
|
||
Item::update([
|
||
'id' => $params['id'],
|
||
'is_index' => $params['is_index']
|
||
]);
|
||
return true;
|
||
}
|
||
} |