Files
huangjingfen/pro_v3.5.1/app/services/system/SystemSignRewardServices.php
panchengyong c1e74d8e68 chore(php): 统一 ScottPan 文件头与注释域名替换
- 按 docs/renew-code-comment.md 将 PHP 文件头改为带边框的 Author 注释\n- 注释中的 crmeb.com 替换为 uj345.cn(代码字符串中的外链未改)\n- 新增 docs/renew-code-comment.md 说明

Made-with: Cursor
2026-03-29 11:22:58 +08:00

105 lines
3.2 KiB
PHP

<?php
// +----------------------------------------------------------------------
// | Author: ScottPan Team
// +----------------------------------------------------------------------
namespace app\services\system;
use app\services\BaseServices;
use app\dao\system\SystemSignRewardDao;
use crmeb\exceptions\AdminException;
use crmeb\services\FormBuilder as Form;
use think\annotation\Inject;
use think\facade\Route as Url;
/**
* Class SystemSignRewardServices
* @package app\services\system
* @mixin SystemSignRewardDao
*/
class SystemSignRewardServices extends BaseServices
{
/**
* @var SystemSignRewardDao
*/
#[Inject]
protected SystemSignRewardDao $dao;
/**
* 签到奖励列表
* @param $type
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList($type = 0)
{
[$page, $limit] = $this->getPageValue();
$list = $this->dao->selectList(['type' => $type], '*', $page, $limit, 'days asc');
$count = $this->dao->count(['type' => $type]);
return compact('list', 'count');
}
/**
* 新增修改签到奖励表单
* @param $id
* @param $type
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function rewardsForm($id = 0, $type = 0)
{
$info = $this->dao->get($id);
if ($info) $type = $info['type'];
$form[] = Form::hidden('type', $type);
$form[] = Form::number('days', $type == 1 ? '累积签到天数:' : '连续签到天数:', (int)($info['days'] ?? 0))->max(sys_config('sign_mode') == 1 ? 7 : 30);
$form[] = Form::number('point', '赠送积分:', (int)($info['point'] ?? 0))->max(999)->min(0);
$form[] = Form::number('exp', '赠送经验:', (int)($info['exp'] ?? 0))->max(999)->min(0);
return create_form($type == 1 ? '累积签到奖励' : '连续签到奖励', $form, Url::buildUrl('/setting/sign/save_rewards/' . $id), 'POST');
}
/**
* 保存签到奖励
* @param $id
* @param $data
* @return bool
* @throws \think\db\exception\DbException
*/
public function saveRewards($id, $data)
{
if ($id) {
$this->dao->update($id, $data);
} else {
if ($this->dao->count(['type' => $data['type'], 'days' => $data['days']])) {
throw new AdminException('签到奖励已存在');
} else {
$this->dao->save($data);
}
}
return true;
}
/**
* 获取累积或者连续签到奖励数据
* @param $type
* @param $days
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getSignRewards($type, $days)
{
$info = $this->dao->get(['type' => $type, 'days' => $days]);
if ($info) return [true, $info['point'], $info['exp']];
return [false, 0, 0];
}
}