diff --git a/add.sql b/add.sql index b33b26b..711e521 100644 --- a/add.sql +++ b/add.sql @@ -37,3 +37,7 @@ ADD COLUMN `status` tinyint NOT NULL DEFAULT 0 COMMENT '状态(0禁用,1启 DROP TABLE IF EXISTS `zy_sign`; -- 已执行 2025-06-16 + + +ALTER TABLE `zy_sign_record` +ADD COLUMN `remark` varchar(255) NOT NULL DEFAULT '' COMMENT '获得礼物备注' AFTER `last`; \ No newline at end of file diff --git a/addons/shopro/controller/zy/Sys.php b/addons/shopro/controller/zy/Sys.php index 6ea619c..10a96f7 100644 --- a/addons/shopro/controller/zy/Sys.php +++ b/addons/shopro/controller/zy/Sys.php @@ -2,19 +2,22 @@ namespace addons\shopro\controller\zy; - use think\Db; use think\Exception; use app\admin\model\zy\Tags; use think\exception\PDOException; +use app\admin\model\zy\sign\Record; use app\admin\model\zy\link\Visitor; +use app\admin\model\zy\sign\SignSet; use app\admin\model\shopro\user\User; use app\admin\model\zy\circle\Circle; use app\admin\model\zy\link\Complaint; use think\exception\ValidateException; +use addons\shopro\library\activity\traits\GiveGift; class Sys extends Base { + use GiveGift; public function index() { @@ -79,4 +82,64 @@ class Sys extends Base $res = Visitor::where('type', $params['type'])->where('obj_id', $params['obj_id'])->paginate($params['pageSize'] ?? 10); $this->success('Success', ['list' => $res->items(), 'count' => $res->total()]); } + + public function signin() + { + $signSet = SignSet::where('status', 1)->select(); + if (empty($signSet)) { + $this->error('没有签到活动'); + } + Db::startTrans(); + try { + $user = auth_user(); + $newRecord = new Record; + $newRecord->user_id = $user->id; + $newRecord->date = date('Y-m-d'); + $newRecord->last = 1; + $record = Record::where('user_id', $user->id)->order('id', 'desc')->find(); + if (!empty($record)) { + if ($newRecord->date == $record->date) { + $this->error('您今天已签到,请勿重复签到'); + } + if ($record['date'] == date('Y-m-d', strtotime('-1 day'))) { + $newRecord->last = $record->last + 1; //连续签到 + } + } + $newRecord->remark = ''; + foreach ($signSet as $set) { + if ($newRecord->last >= $set['last']) { // 达成连续签到天数 + if ($set['chance1'] > 0 && rand(0, 100) <= $set['chance1']) { + $res1 = $this->giveCoupons($user, $set['coupon1_id']); + if ($res1['errors']) $this->error('优惠券赠送失败,请联系管理员', $res1); + $newRecord->remark .= '获得【' . implode(',', $res1['success']) . '】;'; + } + if ($set['chance2'] > 0 && mt_rand(0, 100) <= $set['chance2']) { + $res2 = $this->giveCoupons($user, $set['coupon2_id']); + if ($res2['errors']) $this->error('优惠券赠送失败,请联系管理员', $res2); + $newRecord->remark .= '获得【' . implode(',', $res2['success']) . '】;'; + } + } + } + $newRecord->save(); + Db::commit(); + } catch (ValidateException | PDOException | Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + $this->success('Success', $newRecord); + } + + public function signList() + { + $params = $this->request->param(); + $query = Record::where('user_id', $this->auth->id)->order('id', 'desc'); + if (!empty($params['date_begin'])) { + $query->where('date', '>=', $params['date_begin']); + } + if (!empty($params['date_end'])) { + $query->where('date', '<=', $params['date_end']); + } + $res = $query->paginate($params['pageSize'] ?? 10); + $this->success('Success', ['list' => $res->items(), 'count' => $res->total()]); + } } diff --git a/addons/shopro/traits/CouponSend.php b/addons/shopro/traits/CouponSend.php index 6a16c4d..3dba646 100644 --- a/addons/shopro/traits/CouponSend.php +++ b/addons/shopro/traits/CouponSend.php @@ -70,7 +70,7 @@ trait CouponSend foreach ($coupons as $coupon) { try { $userCoupon = $this->send($user, $coupon); - $success[] = $coupon->id; + $success[] = $coupon->name; } catch (HttpResponseException $e) { $data = $e->getResponse()->getData(); $message = $data ? ($data['msg'] ?? '') : $e->getMessage(); diff --git a/application/admin/lang/zh-cn/zy/sign/record.php b/application/admin/lang/zh-cn/zy/sign/record.php index 600347d..dcfd6ef 100644 --- a/application/admin/lang/zh-cn/zy/sign/record.php +++ b/application/admin/lang/zh-cn/zy/sign/record.php @@ -4,6 +4,7 @@ return [ 'User_id' => '用户id', 'Date' => '签到日期', 'Last' => '已持续天数', + 'Remark' => '获得礼物', 'Create_time' => '创建时间', 'Update_time' => '修改时间', 'User.username' => '用户名' diff --git a/public/assets/js/backend/zy/sign/record.js b/public/assets/js/backend/zy/sign/record.js index 057371a..d564e59 100644 --- a/public/assets/js/backend/zy/sign/record.js +++ b/public/assets/js/backend/zy/sign/record.js @@ -30,6 +30,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin {field: 'user.username', title: __('User.username'), operate: 'LIKE'}, {field: 'date', title: __('Date')}, {field: 'last', title: __('Last')}, + {field: 'remark', title: __('Remark')}, {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false}, {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false}, {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}