Files
douba_shop/app/services/system/SystemSignRewardServices.php
Karlcarlo c9a98f342c chore: 添加静态资源文件和版本配置文件
添加大量图片、字体、音频等静态资源文件,包括用户界面图片、模板文件和安装界面素材
添加系统版本配置文件(.version)和常量定义文件(.constant)
更新供应商依赖文件,包括Symfony VarDumper组件和相关许可证文件
添加验证码配置文件(captcha.php)和.gitignore规则
2026-03-06 20:14:23 +08:00

111 lines
3.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
// +----------------------------------------------------------------------
// | 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\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];
}
}