feat(zy): 完善签到设置功能

This commit is contained in:
2025-06-17 16:20:22 +08:00
parent 335c6a6c68
commit db29a0f7c0
7 changed files with 154 additions and 10 deletions

View File

@@ -2,7 +2,11 @@
namespace app\admin\controller\zy\sign;
use think\Db;
use think\Exception;
use think\exception\PDOException;
use app\common\controller\Backend;
use think\exception\ValidateException;
/**
* 签到设置
@@ -69,4 +73,82 @@ class SignSet extends Backend
return $this->view->fetch();
}
public function add()
{
if (false === $this->request->isPost()) {
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
if (empty($params['begin_date'])) $params['begin_date'] = NULL;
if (empty($params['end_date'])) $params['end_date'] = NULL;
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
}
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->model->validateFailException()->validate($validate);
}
$result = $this->model->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result === false) {
$this->error(__('No rows were inserted'));
}
$this->success();
}
public function edit($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
if (false === $this->request->isPost()) {
$this->view->assign('row', $row);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
if (empty($params['begin_date'])) $params['begin_date'] = NULL;
if (empty($params['end_date'])) $params['end_date'] = NULL;
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException()->validate($validate);
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (false === $result) {
$this->error(__('No rows were updated'));
}
$this->success();
}
}

View File

@@ -2,10 +2,14 @@
return [
'Last' => '连续签到(a)',
'Name' => '名称',
'Chance1' => '概率(b)',
'Coupon1_id' => '券(c)',
'Chance2' => '概率(d)',
'Coupon2_id' => '券(e)',
'BeginDate' => '有效开始日期',
'EndDate' => '有效结束日期',
'Intro' => '内容介绍',
'Status' => '状态',
'Create_time' => '创建时间',
'Update_time' => '修改时间',

View File

@@ -1,5 +1,11 @@
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-2 col-sm-2">{:__('Name')}:</label>
<div class="col-xs-10 col-sm-8">
<input id="c-name" data-rule="required" class="form-control" name="row[name]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-2 col-sm-2">{:__('Last')}:</label>
<div class="col-xs-10 col-sm-8">
@@ -24,23 +30,36 @@
<div class="form-group">
<label class="control-label col-xs-2 col-sm-2">{:__('Chance2')}:</label>
<div class="col-xs-2 col-sm-2">
<input id="c-chance2" data-rule="required" class="form-control" name="row[chance2]" type="number" value="0"
<input id="c-chance2" class="form-control" name="row[chance2]" type="number" value="0"
min="0" max="100">
</div>
<label class="control-label col-xs-2 col-sm-1">{:__('Coupon2_id')}:</label>
<div class="col-xs-6 col-sm-5">
<input id="c-coupon2_id" data-rule="required" data-source="shopro/coupon/index"
<input id="c-coupon2_id" data-source="shopro/coupon/index"
class="form-control selectpage" name="row[coupon2_id]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-2 col-sm-2">{:__('BeginDate')}:</label>
<div class="col-xs-4 col-sm-3">
<input id="c-begin_date" class="form-control datetimepicker" data-date-format="YYYY-MM-DD"
data-use-current="true" name="row[begin_date]" type="text" value="">
</div>
<label class="control-label col-xs-2 col-sm-2">{:__('EndDate')}:</label>
<div class="col-xs-4 col-sm-3">
<input id="c-end_date" class="form-control datetimepicker" data-date-format="YYYY-MM-DD"
data-use-current="true" name="row[end_date]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-2 col-sm-2">{:__('Status')}:</label>
<div class="col-xs-10 col-sm-8">
{:build_radios('row[status]', ['0'=>__('Status0'), '1'=>__('Status1')],1)}
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">

View File

@@ -1,5 +1,11 @@
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-2 col-sm-2">{:__('Name')}:</label>
<div class="col-xs-10 col-sm-8">
<input id="c-name" data-rule="required" class="form-control" name="row[name]" type="text" value="{$row.name|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-2 col-sm-2">{:__('Last')}:</label>
<div class="col-xs-10 col-sm-8">
@@ -25,16 +31,29 @@
<div class="form-group">
<label class="control-label col-xs-2 col-sm-2">{:__('Chance2')}:</label>
<div class="col-xs-2 col-sm-2">
<input id="c-chance2" data-rule="required" class="form-control" name="row[chance2]" type="number" value="{$row.chance2|htmlentities}"
<input id="c-chance2" class="form-control" name="row[chance2]" type="number" value="{$row.chance2|htmlentities}"
min="0" max="100">
</div>
<label class="control-label col-xs-2 col-sm-1">{:__('Coupon2_id')}:</label>
<div class="col-xs-6 col-sm-5">
<input id="c-coupon2_id" data-rule="required" data-source="shopro/coupon/index"
<input id="c-coupon2_id" data-source="shopro/coupon/index"
class="form-control selectpage" name="row[coupon2_id]" type="text" value="{$row.coupon2_id|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-2 col-sm-2">{:__('BeginDate')}:</label>
<div class="col-xs-4 col-sm-3">
<input id="c-begin_date" class="form-control datetimepicker" data-date-format="YYYY-MM-DD"
data-use-current="true" name="row[begin_date]" type="text" value="{$row.begin_date|htmlentities}">
</div>
<label class="control-label col-xs-2 col-sm-2">{:__('EndDate')}:</label>
<div class="col-xs-4 col-sm-3">
<input id="c-end_date" class="form-control datetimepicker" data-date-format="YYYY-MM-DD"
data-use-current="true" name="row[end_date]" type="text" value="{$row.end_date|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
<div class="col-xs-12 col-sm-8">