Files
zzp-server/app/adminapi/logic/decorate/DecorateHintLogic.php
2026-01-19 14:19:22 +08:00

193 lines
6.7 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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\decorate;
use app\common\model\decorate\DecorateHint;
use app\common\logic\BaseLogic;
use app\common\model\user\{User,UserNotice};
use think\facade\Db;
use app\common\service\FileService;
/**
* 提示内容逻辑
* Class DecorateHintLogic
* @package app\adminapi\logic\decorate
*/
class DecorateHintLogic extends BaseLogic
{
/**
* @notes 添加提示内容
* @param array $params
* @return bool
* @author BD
* @date 2024/03/17 17:01
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
$langs = $params['langs'];
foreach ($langs as &$content_lang) {
if(!empty($content_lang['image'])){
$content_lang['image'] = FileService::setFileUrl($content_lang['image']);
}
if(!empty($content_lang['content'])){
$content_lang['content'] = clear_file_domain($content_lang['content']);
}
}
$hint = DecorateHint::create([
'cid' => $params['cid'],
'title' => $params['title'],
'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '',
'contract_y_logo' => $params['contract_y_logo'] ? FileService::setFileUrl($params['contract_y_logo']) : '',
'contract_b_logo' => $params['contract_b_logo'] ? FileService::setFileUrl($params['contract_b_logo']) : '',
'text' => $params['text'],
'content' => $params['content'] ?? '',
'is_show' => $params['is_show'],
'sort' => $params['sort'],
'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE),
]);
// //系统消息则创建用户消息记录
// if($params['cid'] == 5){
// $users = User::select()->toArray();
// foreach ($users as &$user) {
// UserNotice::create([
// 'user_id' => $user['id'],
// 'hint_id' => $hint['id'],
// 'title' => $params['text'],
// 'content' => $params['content'] ?? '',
// 'notice_type' => 3,
// '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/03/17 17:01
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
$langs = $params['langs'];
foreach ($langs as &$content_lang) {
if(!empty($content_lang['image'])){
$content_lang['image'] = FileService::setFileUrl($content_lang['image']);
}
if(!empty($content_lang['content'])){
$content_lang['content'] = clear_file_domain($content_lang['content']);
}
}
DecorateHint::update([
'id' => $params['id'],
'title' => $params['title'],
'image' => $params['image'] ? FileService::setFileUrl($params['image']) : '',
'contract_y_logo' => $params['contract_y_logo'] ? FileService::setFileUrl($params['contract_y_logo']) : '',
'contract_b_logo' => $params['contract_b_logo'] ? FileService::setFileUrl($params['contract_b_logo']) : '',
'text' => $params['text'],
'content' => $params['content'] ?? '',
'is_show' => $params['is_show'],
'sort' => $params['sort'],
'langs' => json_encode($langs, JSON_UNESCAPED_UNICODE),
]);
// $hint = DecorateHint::where(['id' => $params['id']])->findOrEmpty();
// //系统消息则创建用户消息记录
// $cidArr = array(5,6,7);
// if(in_array($hint['cid'], $cidArr)){
// $notices = UserNotice::where(['hint_id' => $params['id']])->select()->toArray();
// foreach ($notices as &$notice) {
// UserNotice::update([
// 'id' => $notice['id'],
// 'title' => $params['text'],
// 'content' => $params['content'] ?? '',
// '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/03/17 17:01
*/
public static function delete(array $params): bool
{
return DecorateHint::destroy($params['id']);
}
/**
* @notes 获取提示内容详情
* @param $params
* @return array
* @author BD
* @date 2024/03/17 17:01
*/
public static function detail($params): array
{
return DecorateHint::findOrEmpty($params['id'])->toArray();
}
/**
* @notes 消息列表
* @param $params
* @return array
* @author BD
* @date 2024/03/17 17:01
*/
public static function allByType($params) : array
{
$field = ['id', 'text'];
$notices = DecorateHint::field($field)
->where(['cid' => $params['cid'],'is_show' => 1])
->order(['sort' => 'desc','id' => 'desc'])
->select()->toArray();
return $notices;
}
}