diff --git a/add.sql b/add.sql index 711e521..23c0b23 100644 --- a/add.sql +++ b/add.sql @@ -40,4 +40,11 @@ DROP TABLE IF EXISTS `zy_sign`; ALTER TABLE `zy_sign_record` -ADD COLUMN `remark` varchar(255) NOT NULL DEFAULT '' COMMENT '获得礼物备注' AFTER `last`; \ No newline at end of file +ADD COLUMN `remark` varchar(255) NOT NULL DEFAULT '' COMMENT '获得礼物备注' AFTER `last`; + +ALTER TABLE `zy_sign_set` +ADD COLUMN `name` varchar(255) NOT NULL DEFAULT '' COMMENT '名称' AFTER `status`, +ADD COLUMN `begin_date` date NULL DEFAULT NULL COMMENT '有效期开始' AFTER `name`, +ADD COLUMN `end_date` date NULL DEFAULT NULL COMMENT '有效期结束' AFTER `begin_date`, +ADD COLUMN `intro` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '说明' AFTER `end_date`; +-- 已执行 2025-06-17 \ No newline at end of file diff --git a/addons/shopro/controller/zy/Sys.php b/addons/shopro/controller/zy/Sys.php index 10a96f7..2cc6a93 100644 --- a/addons/shopro/controller/zy/Sys.php +++ b/addons/shopro/controller/zy/Sys.php @@ -142,4 +142,16 @@ class Sys extends Base $res = $query->paginate($params['pageSize'] ?? 10); $this->success('Success', ['list' => $res->items(), 'count' => $res->total()]); } -} + + public function task() + { + $record = Record::where('user_id', $this->auth->id)->where('date', date('Y-m-d'))->find(); + $query = SignSet::field('name,begin_date,end_date,intro')->where('status', 1); + $res = $query->paginate($params['pageSize'] ?? 10); + $list = $res->items(); + foreach ($list as &$val) { + $val['progress'] = empty($record) ? '今日未完成' : '今日已完成'; + } + $this->success('Success', ['list' => $list, 'count' => $res->total()]); + } +} \ No newline at end of file diff --git a/application/admin/controller/zy/sign/SignSet.php b/application/admin/controller/zy/sign/SignSet.php index ae85d6d..662b819 100644 --- a/application/admin/controller/zy/sign/SignSet.php +++ b/application/admin/controller/zy/sign/SignSet.php @@ -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(); + } + } diff --git a/application/admin/lang/zh-cn/zy/sign/sign_set.php b/application/admin/lang/zh-cn/zy/sign/sign_set.php index c3005e6..ec79911 100644 --- a/application/admin/lang/zh-cn/zy/sign/sign_set.php +++ b/application/admin/lang/zh-cn/zy/sign/sign_set.php @@ -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' => '修改时间', diff --git a/application/admin/view/zy/sign/sign_set/add.html b/application/admin/view/zy/sign/sign_set/add.html index c0aca5e..ada477f 100644 --- a/application/admin/view/zy/sign/sign_set/add.html +++ b/application/admin/view/zy/sign/sign_set/add.html @@ -1,5 +1,11 @@
+
+ +
+ +
+
@@ -24,23 +30,36 @@
-
-
+
+ +
+ +
+ +
+ +
+
+
{:build_radios('row[status]', ['0'=>__('Status0'), '1'=>__('Status1')],1)}
- +