From 7415193bba4c6a63bec3df0efc5ba11a0631aa79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Sat, 11 Oct 2025 14:49:25 +0800 Subject: [PATCH 01/17] =?UTF-8?q?=E7=BA=A2=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/controller/Redpacket.php | 41 +++---- application/api/model/UserWallet.php | 10 +- application/common/model/Redpacket.php | 18 ++- application/common/model/UserWallet.php | 20 +++- .../common/service/RedpacketService.php | 106 ++---------------- 5 files changed, 68 insertions(+), 127 deletions(-) diff --git a/application/api/controller/Redpacket.php b/application/api/controller/Redpacket.php index d8772f9..9a90ffd 100644 --- a/application/api/controller/Redpacket.php +++ b/application/api/controller/Redpacket.php @@ -4,6 +4,7 @@ namespace app\api\controller; use app\common\controller\BaseCom; use app\common\service\RedpacketService; +use think\Db; /** * 红包接口 @@ -32,14 +33,13 @@ class Redpacket extends BaseCom public function grab() { $redpacketId = $this->request->post('redpacket_id'); - $password = $this->request->post('password', ''); if (empty($redpacketId)) { return V(0, '红包ID不能为空'); } $service = new RedpacketService(); - $reslut = $service->grabWithResult($redpacketId, $this->uid, $password); + $reslut = $service->grabWithResult($redpacketId, $this->uid); return V($reslut['code'], $reslut['msg'], $reslut['data']); } @@ -49,21 +49,20 @@ class Redpacket extends BaseCom */ public function grabResult() { - $user = $this->auth->getUser(); $redpacketId = $this->request->get('redpacket_id'); if (empty($redpacketId)) { - $this->error('红包ID不能为空'); + return V(0, '红包ID不能为空'); } $service = new RedpacketService(); - $result = $service->getGrabResult($redpacketId, $user->id); + $result = $service->getGrabResult($redpacketId, $this->uid); if (!$result) { - $this->error('红包不存在'); + return V(0, '红包不存在'); } - $this->success('获取成功', $result); + return V(1, '获取成功', $result); } /** @@ -72,25 +71,19 @@ class Redpacket extends BaseCom public function detail() { $redpacketId = $this->request->get('redpacket_id'); - $currentUserId = $this->auth->isLogin() ? $this->auth->id : 0; if (empty($redpacketId)) { - $this->error('红包ID不能为空'); + return V(0, '红包ID不能为空'); } - try { - $service = new RedpacketService(); - $detail = $service->getDetail($redpacketId, $currentUserId); + $service = new RedpacketService(); + $detail = $service->getDetail($redpacketId, $this->uid); - if (!$detail) { - $this->error('红包不存在'); - } - - $this->success('获取成功', $detail); - - } catch (\Exception $e) { - $this->error($e->getMessage()); + if (!$detail) { + return V(0, '红包不存在'); } + + return V(1, '获取成功', $detail); } /** @@ -101,4 +94,12 @@ class Redpacket extends BaseCom $options = \app\common\model\Redpacket::$countdownOptions; $this->success('获取成功', $options); } + + // 获取房间内红包列表 + public function roomRedPackets() + { + $roomId = $this->request->get('room_id'); + $result = Db::name('redpacket')->where(['room_id' => $roomId, 'status' => [1, 0]])->select(); + return V(1, '获取成功', $result); + } } \ No newline at end of file diff --git a/application/api/model/UserWallet.php b/application/api/model/UserWallet.php index 1daefbd..cc3aca6 100644 --- a/application/api/model/UserWallet.php +++ b/application/api/model/UserWallet.php @@ -50,18 +50,18 @@ class UserWallet extends Model // 1.系统调节 2.充值 3.提现 4.金币转增(送出) 5.每日任务奖励 6.充值返利 7.购买装扮 // 8.礼盒奖励 9.房间补贴 10.购买礼物 11.收礼增加收益 12.工会补贴 13.转赠金币(接收) 14.收益兑换 // 15.首充 16.天降好礼充值 17.退出工会扣款 18.房主收益 19.主持人收益,20.发布头条扣除余额,21.公会长收益,22.提现驳回或提现失败返还,23.财富等级奖励金币领取,24.删除关系扣金币 - //27.小时榜获得 + //27.小时榜获得,28-发红包(金币),29-发红包(钻石),30-抢红包(金币),31-抢红包(钻石) if($gift_type == 1){ //1金币,2收益(钻石) if($in_out_type == 1){//1收入 - $in_out_types = [2,5,6,8,13,14,15,16,22,23,26,27]; + $in_out_types = [2,5,6,8,13,14,15,16,22,23,26,27,30]; }elseif($in_out_type == 2){//2支出 - $in_out_types = [4,7,10,17,20,24,25]; + $in_out_types = [4,7,10,17,20,24,25,28]; } }elseif($gift_type == 2){ //1金币,2收益(钻石) if($in_out_type == 1){//1收入 - $in_out_types = [6,9,11,12,18,19,21,22]; + $in_out_types = [6,9,11,12,18,19,21,22,31]; }elseif($in_out_type == 2){//2支出 - $in_out_types = [3,14]; + $in_out_types = [3,14,29]; } } diff --git a/application/common/model/Redpacket.php b/application/common/model/Redpacket.php index e061387..ec36c83 100644 --- a/application/common/model/Redpacket.php +++ b/application/common/model/Redpacket.php @@ -55,11 +55,27 @@ class Redpacket extends Model } // 扣除余额 - Db::name('user_wallet') + $delres = Db::name('user_wallet') ->where('user_id', $data['user_id']) ->dec($coinField, $data['total_amount']) ->update(); + //记录日志 32-发红包(金币),29-发红包(钻石),30-抢红包(金币),31-抢红包(钻石) + //记录用户金币日志 + $data = [ + 'user_id' => $data['user_id'], + 'change_value' => $data['total_amount'], + 'room_id' => $data['room_id'], + 'money_type' => $data['coin_type'], + 'change_type' => $coinField == self::COIN_GOLD ? 32 : 29, + 'from_id' => $data['room_id'], + 'remarks' => $coinField == self::COIN_GOLD ? '金币(发红包)' : '钻石(发红包)', + 'createtime' => time() + ]; + $res = Db::name('vs_user_money_log')->insert($data); + if(!$res || !$delres){ + Db::rollback(); + } // 计算开始时间 $startTime = $data['countdown'] > 0 ? (time() + $data['countdown']) : time(); $endTime = $startTime + 120; // 2分钟后结束 diff --git a/application/common/model/UserWallet.php b/application/common/model/UserWallet.php index df565cd..102dbc2 100644 --- a/application/common/model/UserWallet.php +++ b/application/common/model/UserWallet.php @@ -78,6 +78,14 @@ class UserWallet extends Model //新人充值好礼 const NEW_USER_CHARGE_GIFT = 28; + //发红包(金币) + const RED_PACKET_COIN = 32; + //发红包(钻石) + const RED_PACKET_DIAMOND = 29; + //抢红包(金币) + const RED_PACKET_COIN_RECEIVE = 30; + //抢红包(钻石) + const RED_PACKET_DIAMOND_RECEIVE = 31; //金币支出类型数组 public $coin_consumption_type_array = [ @@ -86,12 +94,14 @@ class UserWallet extends Model self::OPERATION_GIFT, self::GUILD_EXIT, self::HEADLINE_REWARD, - self::TRANSFER_COIN + self::TRANSFER_COIN, + self::RED_PACKET_COIN, ]; //钻石支出类型数组 public $diamond_consumption_type_array = [ self::OPERATION_WITHDRAW, - self::MONEY_CONVERSION + self::MONEY_CONVERSION, + self::RED_PACKET_DIAMOND ]; @@ -141,7 +151,11 @@ class UserWallet extends Model self::TRANSFER_COIN => '赠送好友金币', self::RECEIVE_COIN => '好友转赠所得金币', self::HOUR_RANK_COIN => '小时榜获得金币', - self::NEW_USER_CHARGE_GIFT => '新人充值好礼' + self::NEW_USER_CHARGE_GIFT => '新人充值好礼', + self::RED_PACKET_COIN => '发红包(金币)', + self::RED_PACKET_DIAMOND => '发红包(钻石)', + self::RED_PACKET_COIN_RECEIVE => '抢红包(金币)', + self::RED_PACKET_DIAMOND_RECEIVE => '抢红包(钻石)', ]; return $status[$type] ?? ''; } diff --git a/application/common/service/RedpacketService.php b/application/common/service/RedpacketService.php index 088ba66..3695825 100644 --- a/application/common/service/RedpacketService.php +++ b/application/common/service/RedpacketService.php @@ -30,7 +30,7 @@ class RedpacketService /** * 抢红包并返回详细结果 */ - public function grabWithResult($redpacketId, $userId, $password = '') + public function grabWithResult($redpacketId, $userId) { $redpacketModel = new Redpacket(); $redpacket = $redpacketModel->getRedpacketInfo($redpacketId); @@ -43,17 +43,6 @@ class RedpacketService ]; } - // 验证口令红包 - if ($redpacket['type'] == Redpacket::TYPE_PASSWORD) { - if (empty($password) || $password != $redpacket['password']) { - return [ - 'code' => 0, - 'msg' => '口令错误', - 'data' => null - ]; - } - } - // 验证领取条件 $conditionCheck = $this->checkConditionsWithResult($redpacket, $userId); if ($conditionCheck['code'] != 1) { @@ -129,7 +118,8 @@ class RedpacketService 'change_value' => $amount, 'room_id' => $redpacket['room_id'], 'money_type' => $redpacket['coin_type'], - 'change_type' => 66,//抢红包收入 + //记录日志 32-发红包(金币),29-发红包(钻石),30-抢红包(金币),31-抢红包(钻石) + 'change_type' => $redpacket['coin_type'] == 1 ? 30 : 31, 'from_id' => $redpacket['room_id'], 'remarks' => '抢红包收入', 'createtime' => time() @@ -153,9 +143,8 @@ class RedpacketService $grabResult = $this->getGrabResult($redpacketId, $userId); return [ - 'success' => true, - 'code' => 'grab_success', - 'message' => '抢红包成功', + 'code' => 1, + 'msg' => '抢红包成功', 'data' => $grabResult ]; @@ -167,9 +156,9 @@ class RedpacketService $redis->sRem($userSetKey, $userId); return [ - 'success' => false, - 'code' => 'system_error', - 'message' => '系统错误,请重试' + 'code' => 0, + 'msg' => '系统错误,请重试', + 'data' => null ]; } } @@ -357,85 +346,6 @@ class RedpacketService return ['code' => 1]; } - /** - * 抢红包 - */ -// public function grab($redpacketId, $userId, $password = '') -// { -// $redpacketModel = new Redpacket(); -// $redpacket = $redpacketModel->getRedpacketInfo($redpacketId); -// -// if (!$redpacket) { -// throw new \Exception('红包不存在'); -// } -// -// // 验证口令红包 -// if ($redpacket['type'] == Redpacket::TYPE_PASSWORD) { -// if (empty($password) || $password != $redpacket['password']) { -// throw new \Exception('口令错误'); -// } -// } -// -// // 验证领取条件 -// $this->checkConditions($redpacket, $userId); -// -// // 使用Redis+Lua保证原子性操作 -// $redis = Cache::store('redis')->handler(); -// $script = RedpacketLua::grabRedpacketScript(); -// -// $redpacketKey = "redpacket:{$redpacketId}"; -// $userSetKey = "redpacket_users:{$redpacketId}"; -// -// $result = $redis->eval($script, [ -// $redpacketKey, -// $userSetKey, -// $userId, -// time() -// ], 3); -// -// if ($result[0] == 0) { -// throw new \Exception($result[1]); -// } -// -// $amount = floatval($result[1]); -// -// // Lua脚本执行成功,记录到数据库 -// Db::startTrans(); -// try { -// // 创建领取记录 -// $recordData = [ -// 'redpacket_id' => $redpacketId, -// 'user_id' => $userId, -// 'amount' => $amount -// ]; -// -// $recordModel = new RedpacketRecord(); -// $recordModel->save($recordData); -// -// // 更新用户钱包 -// $walletModel = new UserWallet(); -// $walletModel->increaseBalance($userId, $redpacket['coin_type'], $amount); -// -// // 更新红包剩余数量和金额 -// Db::name('redpacket') -// ->where('id', $redpacketId) -// ->dec('left_amount', $amount) -// ->dec('left_count', 1) -// ->update(); -// -// Db::commit(); -// -// return $amount; -// -// } catch (\Exception $e) { -// Db::rollback(); -// // 回滚Redis操作 -// $redis->hIncrByFloat($redpacketKey, 'left_amount', $amount); -// $redis->hIncrBy($redpacketKey, 'left_count', 1); -// $redis->sRem($userSetKey, $userId); -// throw $e; -// } -// } /** * 获取红包详情和领取记录 From 204c19ff6d31c17ae62949509668059bad4eec9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Sat, 11 Oct 2025 14:53:39 +0800 Subject: [PATCH 02/17] =?UTF-8?q?=E7=BA=A2=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/model/Redpacket.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/application/common/model/Redpacket.php b/application/common/model/Redpacket.php index ec36c83..c12b94d 100644 --- a/application/common/model/Redpacket.php +++ b/application/common/model/Redpacket.php @@ -45,7 +45,7 @@ class Redpacket extends Model public function createRedpacket($data) { Db::startTrans(); - try { +// try { // 验证用户余额 $wallet = Db::name('user_wallet')->where('user_id', $data['user_id'])->find(); @@ -121,11 +121,11 @@ class Redpacket extends Model // return $redpacketId; return V(1, '发红包成功', $redpacketId); - } catch (\Exception $e) { - Db::rollback(); - return V(0, $e); -// throw $e; - } +// } catch (\Exception $e) { +// Db::rollback(); +// return V(0, $e); +//// throw $e; +// } } /** From 641368f78e0688d57b5b524050c75f85af774d67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Sat, 11 Oct 2025 14:54:43 +0800 Subject: [PATCH 03/17] =?UTF-8?q?=E7=BA=A2=E5=8C=85=E7=AC=AC=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/model/Redpacket.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/application/common/model/Redpacket.php b/application/common/model/Redpacket.php index c12b94d..ec36c83 100644 --- a/application/common/model/Redpacket.php +++ b/application/common/model/Redpacket.php @@ -45,7 +45,7 @@ class Redpacket extends Model public function createRedpacket($data) { Db::startTrans(); -// try { + try { // 验证用户余额 $wallet = Db::name('user_wallet')->where('user_id', $data['user_id'])->find(); @@ -121,11 +121,11 @@ class Redpacket extends Model // return $redpacketId; return V(1, '发红包成功', $redpacketId); -// } catch (\Exception $e) { -// Db::rollback(); -// return V(0, $e); -//// throw $e; -// } + } catch (\Exception $e) { + Db::rollback(); + return V(0, $e); +// throw $e; + } } /** From 8556184c1ab076d7f47e0e89cd5f088a9960f93c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Sat, 11 Oct 2025 14:58:51 +0800 Subject: [PATCH 04/17] =?UTF-8?q?=E7=BA=A2=E5=8C=85=E7=AC=AC=E4=BA=8C?= =?UTF-8?q?=E6=AC=A1=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/service/RedpacketService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/common/service/RedpacketService.php b/application/common/service/RedpacketService.php index 3695825..e2935ab 100644 --- a/application/common/service/RedpacketService.php +++ b/application/common/service/RedpacketService.php @@ -474,7 +474,7 @@ class RedpacketService return $res_con; } } - return true; + return V(1, '验证成功'); } /** From e76bf26819e4856940837fd97775dcc5998c9c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Sat, 11 Oct 2025 15:02:13 +0800 Subject: [PATCH 05/17] =?UTF-8?q?=E7=BA=A2=E5=8C=85=E7=AC=AC3=E6=AC=A1?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/service/RedpacketService.php | 57 ++++++++++++++++--- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/application/common/service/RedpacketService.php b/application/common/service/RedpacketService.php index e2935ab..0fe3400 100644 --- a/application/common/service/RedpacketService.php +++ b/application/common/service/RedpacketService.php @@ -438,44 +438,85 @@ class RedpacketService } } + + /** * 验证创建红包数据 */ private function validateCreateData($data) { if (empty($data['user_id'])) { - return V(0, '用户ID不能为空'); + return ['code' => 0, 'msg' => '用户ID不能为空', 'data' => null]; } if (!in_array($data['type'], [Redpacket::TYPE_NORMAL, Redpacket::TYPE_PASSWORD])) { - return V(0, '红包类型错误'); + return ['code' => 0, 'msg' => '红包类型错误', 'data' => null]; } if ($data['type'] == Redpacket::TYPE_PASSWORD && empty($data['password'])) { - return V(0, '口令红包必须设置口令'); + return ['code' => 0, 'msg' => '口令红包必须设置口令', 'data' => null]; } if (!in_array($data['coin_type'], [Redpacket::COIN_GOLD, Redpacket::COIN_DIAMOND])) { - return V(0, '币种类型错误'); + return ['code' => 0, 'msg' => '币种类型错误', 'data' => null]; } if ($data['total_amount'] <= 0 || $data['total_count'] <= 0) { - return V(0, '金额和数量必须大于0'); + return ['code' => 0, 'msg' => '金额和数量必须大于0', 'data' => null]; } if ($data['total_amount'] < $data['total_count']) { - return V(0, '总金额不能小于总个数'); + return ['code' => 0, 'msg' => '总金额不能小于总个数', 'data' => null]; } // 验证领取条件 if (isset($data['conditions'])) { - $res_con = $this->validateConditions($data['conditions']); + $res_con = $this->validateConditions($data['conditions']); if ($res_con !== true) { return $res_con; } } - return V(1, '验证成功'); + + return ['code' => 1, 'msg' => '验证成功', 'data' => null]; } + /** + * 验证创建红包数据 + */ +// private function validateCreateData($data) +// { +// if (empty($data['user_id'])) { +// return V(0, '用户ID不能为空'); +// } +// +// if (!in_array($data['type'], [Redpacket::TYPE_NORMAL, Redpacket::TYPE_PASSWORD])) { +// return V(0, '红包类型错误'); +// } +// +// if ($data['type'] == Redpacket::TYPE_PASSWORD && empty($data['password'])) { +// return V(0, '口令红包必须设置口令'); +// } +// +// if (!in_array($data['coin_type'], [Redpacket::COIN_GOLD, Redpacket::COIN_DIAMOND])) { +// return V(0, '币种类型错误'); +// } +// +// if ($data['total_amount'] <= 0 || $data['total_count'] <= 0) { +// return V(0, '金额和数量必须大于0'); +// } +// +// if ($data['total_amount'] < $data['total_count']) { +// return V(0, '总金额不能小于总个数'); +// } +// +// // 验证领取条件 +// if (isset($data['conditions'])) { +// $res_con = $this->validateConditions($data['conditions']); +// if ($res_con !== true) { +// return $res_con; +// } +// } +// return V(1, '验证成功'); +// } /** * 验证领取条件 From 757c36c830d7ee5c5ed353d64a77d23251c5dd13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Sat, 11 Oct 2025 15:08:25 +0800 Subject: [PATCH 06/17] =?UTF-8?q?=E7=BA=A2=E5=8C=85=E7=AC=AC4=E6=AC=A1?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/model/Redpacket.php | 8 ++-- .../common/service/RedpacketService.php | 39 +------------------ 2 files changed, 4 insertions(+), 43 deletions(-) diff --git a/application/common/model/Redpacket.php b/application/common/model/Redpacket.php index ec36c83..204db9f 100644 --- a/application/common/model/Redpacket.php +++ b/application/common/model/Redpacket.php @@ -51,7 +51,7 @@ class Redpacket extends Model $coinField = $data['coin_type'] == self::COIN_GOLD ? 'coin' : 'earnings'; if ($wallet[$coinField] < $data['total_amount']) { - return V(0, '余额不足'); + return ['code' => 0, 'msg' => '余额不足', 'data' => null]; } // 扣除余额 @@ -118,13 +118,11 @@ class Redpacket extends Model $redis->expireAt($redisKey, $endTime + 3600); // 结束后保留1小时 Db::commit(); -// return $redpacketId; - return V(1, '发红包成功', $redpacketId); + return ['code' => 1, 'msg' => '发红包成功', 'data' => $redpacketId]; } catch (\Exception $e) { Db::rollback(); - return V(0, $e); -// throw $e; + return ['code' => 0, 'msg' => $e->getMessage(), 'data' => null]; } } diff --git a/application/common/service/RedpacketService.php b/application/common/service/RedpacketService.php index 0fe3400..14b8de5 100644 --- a/application/common/service/RedpacketService.php +++ b/application/common/service/RedpacketService.php @@ -479,44 +479,7 @@ class RedpacketService return ['code' => 1, 'msg' => '验证成功', 'data' => null]; } - /** - * 验证创建红包数据 - */ -// private function validateCreateData($data) -// { -// if (empty($data['user_id'])) { -// return V(0, '用户ID不能为空'); -// } -// -// if (!in_array($data['type'], [Redpacket::TYPE_NORMAL, Redpacket::TYPE_PASSWORD])) { -// return V(0, '红包类型错误'); -// } -// -// if ($data['type'] == Redpacket::TYPE_PASSWORD && empty($data['password'])) { -// return V(0, '口令红包必须设置口令'); -// } -// -// if (!in_array($data['coin_type'], [Redpacket::COIN_GOLD, Redpacket::COIN_DIAMOND])) { -// return V(0, '币种类型错误'); -// } -// -// if ($data['total_amount'] <= 0 || $data['total_count'] <= 0) { -// return V(0, '金额和数量必须大于0'); -// } -// -// if ($data['total_amount'] < $data['total_count']) { -// return V(0, '总金额不能小于总个数'); -// } -// -// // 验证领取条件 -// if (isset($data['conditions'])) { -// $res_con = $this->validateConditions($data['conditions']); -// if ($res_con !== true) { -// return $res_con; -// } -// } -// return V(1, '验证成功'); -// } + /** * 验证领取条件 From 4fe5b7e1f07db59270244f864c3f31f236bf1b16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Sat, 11 Oct 2025 15:14:10 +0800 Subject: [PATCH 07/17] =?UTF-8?q?=E7=BA=A2=E5=8C=85=E7=AC=AC5=E6=AC=A1?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/model/Redpacket.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/common/model/Redpacket.php b/application/common/model/Redpacket.php index 204db9f..8d594e0 100644 --- a/application/common/model/Redpacket.php +++ b/application/common/model/Redpacket.php @@ -61,7 +61,7 @@ class Redpacket extends Model ->update(); //记录日志 32-发红包(金币),29-发红包(钻石),30-抢红包(金币),31-抢红包(钻石) //记录用户金币日志 - $data = [ + $data_log = [ 'user_id' => $data['user_id'], 'change_value' => $data['total_amount'], 'room_id' => $data['room_id'], @@ -72,7 +72,7 @@ class Redpacket extends Model 'createtime' => time() ]; - $res = Db::name('vs_user_money_log')->insert($data); + $res = Db::name('vs_user_money_log')->insert($data_log); if(!$res || !$delres){ Db::rollback(); } From 27ad16bb52537e761ff7e797ce8b607ee766a422 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Sat, 11 Oct 2025 15:19:14 +0800 Subject: [PATCH 08/17] =?UTF-8?q?=E7=BA=A2=E5=8C=85=E7=AC=AC6=E6=AC=A1?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/controller/Redpacket.php | 1 + 1 file changed, 1 insertion(+) diff --git a/application/api/controller/Redpacket.php b/application/api/controller/Redpacket.php index 9a90ffd..b32cde1 100644 --- a/application/api/controller/Redpacket.php +++ b/application/api/controller/Redpacket.php @@ -18,6 +18,7 @@ class Redpacket extends BaseCom public function create() { $data = $this->request->post(); + var_dump($data);exit; $data['user_id'] = $this->uid; From f5c2391032c717ab6d54b41968ff958cd93645f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Sat, 11 Oct 2025 15:20:49 +0800 Subject: [PATCH 09/17] =?UTF-8?q?=E7=BA=A2=E5=8C=85=E7=AC=AC7=E6=AC=A1?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/controller/Redpacket.php | 1 - application/common/model/Redpacket.php | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/application/api/controller/Redpacket.php b/application/api/controller/Redpacket.php index b32cde1..9a90ffd 100644 --- a/application/api/controller/Redpacket.php +++ b/application/api/controller/Redpacket.php @@ -18,7 +18,6 @@ class Redpacket extends BaseCom public function create() { $data = $this->request->post(); - var_dump($data);exit; $data['user_id'] = $this->uid; diff --git a/application/common/model/Redpacket.php b/application/common/model/Redpacket.php index 8d594e0..a3b1bf0 100644 --- a/application/common/model/Redpacket.php +++ b/application/common/model/Redpacket.php @@ -44,6 +44,7 @@ class Redpacket extends Model */ public function createRedpacket($data) { + var_dump($data);exit; Db::startTrans(); try { // 验证用户余额 From 4846be35382de7709007e0b5e15efc6c1ab84fbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Sat, 11 Oct 2025 15:23:35 +0800 Subject: [PATCH 10/17] =?UTF-8?q?=E7=BA=A2=E5=8C=85=E7=AC=AC8=E6=AC=A1?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/model/Redpacket.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/common/model/Redpacket.php b/application/common/model/Redpacket.php index a3b1bf0..93a7914 100644 --- a/application/common/model/Redpacket.php +++ b/application/common/model/Redpacket.php @@ -44,7 +44,7 @@ class Redpacket extends Model */ public function createRedpacket($data) { - var_dump($data);exit; +// var_dump($data);exit; Db::startTrans(); try { // 验证用户余额 From 05f61dfe11b55fbcfc11f6512d5bf68f343ff207 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Sat, 11 Oct 2025 16:07:12 +0800 Subject: [PATCH 11/17] =?UTF-8?q?=E7=BA=A2=E5=8C=85=E7=AC=AC9=E6=AC=A1?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/library/RedpacketLua.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/application/common/library/RedpacketLua.php b/application/common/library/RedpacketLua.php index 1ec11be..126fc20 100644 --- a/application/common/library/RedpacketLua.php +++ b/application/common/library/RedpacketLua.php @@ -46,14 +46,14 @@ if status == 0 then end end -if status ~= 1 then - return {0, "红包已结束"} -end +--if status ~= 1 then + -- return {0, "红包已结束"} +--end -if currentTime > endTime then - redis.call('HSET', redpacketKey, 'status', 2) - return {0, "红包已结束"} -end +--if currentTime > endTime then +-- redis.call('HSET', redpacketKey, 'status', 2) +-- return {0, "红包已结束"} +--end -- 检查是否已经抢过 local hasGrabbed = redis.call('SISMEMBER', userSetKey, userId) From ec2110c07d4c59cb24d8ec6589d70666b5e6fe6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Sat, 11 Oct 2025 16:19:19 +0800 Subject: [PATCH 12/17] =?UTF-8?q?=E7=BA=A2=E5=8C=85=E7=AC=AC10=E6=AC=A1?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/library/RedpacketLua.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/application/common/library/RedpacketLua.php b/application/common/library/RedpacketLua.php index 126fc20..99b6024 100644 --- a/application/common/library/RedpacketLua.php +++ b/application/common/library/RedpacketLua.php @@ -46,14 +46,14 @@ if status == 0 then end end ---if status ~= 1 then +-- if status ~= 1 then -- return {0, "红包已结束"} ---end +-- end ---if currentTime > endTime then +-- if currentTime > endTime then -- redis.call('HSET', redpacketKey, 'status', 2) -- return {0, "红包已结束"} ---end +-- end -- 检查是否已经抢过 local hasGrabbed = redis.call('SISMEMBER', userSetKey, userId) From 60283af40f07a43fd9443b4844f3ae8168d3d3bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Sat, 11 Oct 2025 16:26:18 +0800 Subject: [PATCH 13/17] =?UTF-8?q?=E7=BA=A2=E5=8C=85=E7=AC=AC11=E6=AC=A1?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/model/Redpacket.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/common/model/Redpacket.php b/application/common/model/Redpacket.php index 93a7914..219d281 100644 --- a/application/common/model/Redpacket.php +++ b/application/common/model/Redpacket.php @@ -67,9 +67,9 @@ class Redpacket extends Model 'change_value' => $data['total_amount'], 'room_id' => $data['room_id'], 'money_type' => $data['coin_type'], - 'change_type' => $coinField == self::COIN_GOLD ? 32 : 29, + 'change_type' => $data['coin_type'] == self::COIN_GOLD ? 32 : 29, 'from_id' => $data['room_id'], - 'remarks' => $coinField == self::COIN_GOLD ? '金币(发红包)' : '钻石(发红包)', + 'remarks' => $data['coin_type'] == self::COIN_GOLD ? '金币(发红包)' : '钻石(发红包)', 'createtime' => time() ]; From d995df1b66d60f35cfa994028505c240ffc6d3dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Sat, 11 Oct 2025 16:30:11 +0800 Subject: [PATCH 14/17] =?UTF-8?q?=E7=BA=A2=E5=8C=85=E7=AC=AC12=E6=AC=A1?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/model/UserWallet.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/application/api/model/UserWallet.php b/application/api/model/UserWallet.php index cc3aca6..7b4729b 100644 --- a/application/api/model/UserWallet.php +++ b/application/api/model/UserWallet.php @@ -50,16 +50,16 @@ class UserWallet extends Model // 1.系统调节 2.充值 3.提现 4.金币转增(送出) 5.每日任务奖励 6.充值返利 7.购买装扮 // 8.礼盒奖励 9.房间补贴 10.购买礼物 11.收礼增加收益 12.工会补贴 13.转赠金币(接收) 14.收益兑换 // 15.首充 16.天降好礼充值 17.退出工会扣款 18.房主收益 19.主持人收益,20.发布头条扣除余额,21.公会长收益,22.提现驳回或提现失败返还,23.财富等级奖励金币领取,24.删除关系扣金币 - //27.小时榜获得,28-发红包(金币),29-发红包(钻石),30-抢红包(金币),31-抢红包(钻石) + //27.小时榜获得,28-新人充值好礼,32-发红包(金币),29-发红包(钻石),30-抢红包(金币),31-抢红包(钻石) if($gift_type == 1){ //1金币,2收益(钻石) if($in_out_type == 1){//1收入 - $in_out_types = [2,5,6,8,13,14,15,16,22,23,26,27,30]; + $in_out_types = [2,5,6,8,13,14,15,16,22,23,26,27,30,28]; }elseif($in_out_type == 2){//2支出 - $in_out_types = [4,7,10,17,20,24,25,28]; + $in_out_types = [4,7,10,17,20,24,25,32]; } }elseif($gift_type == 2){ //1金币,2收益(钻石) if($in_out_type == 1){//1收入 - $in_out_types = [6,9,11,12,18,19,21,22,31]; + $in_out_types = [6,9,11,12,18,19,21,22,31,28]; }elseif($in_out_type == 2){//2支出 $in_out_types = [3,14,29]; } From 65bb1b0c537232df2374a4ec51db0f43ec391675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Sat, 11 Oct 2025 16:37:42 +0800 Subject: [PATCH 15/17] =?UTF-8?q?=E7=BA=A2=E5=8C=85=E7=AC=AC13=E6=AC=A1?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/library/RedpacketLua.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/common/library/RedpacketLua.php b/application/common/library/RedpacketLua.php index 99b6024..c3c02ac 100644 --- a/application/common/library/RedpacketLua.php +++ b/application/common/library/RedpacketLua.php @@ -77,7 +77,7 @@ if leftCount == 1 then else -- 随机算法:二倍均值法,保证公平性 local maxAmount = leftAmount / leftCount * 2 - amount = math.random(1, math.floor(maxAmount * 100)) / 100 + amount = math.random(1, math.floor(maxAmount)) -- 确保金额不会超过剩余金额 if amount > leftAmount then amount = leftAmount From d7c48a5ae05d37402c696bc944dcbd43ed8b4f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Sat, 11 Oct 2025 18:09:36 +0800 Subject: [PATCH 16/17] =?UTF-8?q?=E5=8F=91=E7=BA=A2=E5=8C=85=20=E6=8E=A8?= =?UTF-8?q?=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/model/Chat.php | 2 ++ application/common/model/Redpacket.php | 10 +++++++++- application/common/service/RedpacketService.php | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/application/api/model/Chat.php b/application/api/model/Chat.php index 6830fab..7ee1a97 100644 --- a/application/api/model/Chat.php +++ b/application/api/model/Chat.php @@ -119,6 +119,8 @@ class Chat extends Model //清空个人魅力 // ClearUserCharm = 1059, + //发红包 + // RedPacket = 1060, diff --git a/application/common/model/Redpacket.php b/application/common/model/Redpacket.php index 219d281..32e4543 100644 --- a/application/common/model/Redpacket.php +++ b/application/common/model/Redpacket.php @@ -117,8 +117,16 @@ class Redpacket extends Model // 设置过期时间 $redis->expireAt($redisKey, $endTime + 3600); // 结束后保留1小时 - Db::commit(); + + //给前端推送信息 + $data['nickname'] = Db::name('user')->where('id', $data['user_id'])->value('nickname'); + $text = [ + 'redpacketInfo' => $data, + 'text' => '' + ]; + model('api/Chat')->sendMsg(1060,$data['room_id'],$text); + return ['code' => 1, 'msg' => '发红包成功', 'data' => $redpacketId]; } catch (\Exception $e) { diff --git a/application/common/service/RedpacketService.php b/application/common/service/RedpacketService.php index 14b8de5..69e95ca 100644 --- a/application/common/service/RedpacketService.php +++ b/application/common/service/RedpacketService.php @@ -232,7 +232,8 @@ class RedpacketService 'left_amount' => $redpacket['left_amount'], 'left_count' => $redpacket['left_count'], 'coin_type' => $redpacket['coin_type'], - 'status' => $redpacket['status'] + 'status' => $redpacket['status'], + 'nickname' => Db::name('user')->where('id', $redpacket['user_id'])->value('nickname') ], 'my_record' => $myRecord ? [ 'amount' => $myRecord['amount'], From fcf912ac9014a9984c533e13316c0858649306af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Sat, 11 Oct 2025 18:18:43 +0800 Subject: [PATCH 17/17] =?UTF-8?q?=E7=BA=A2=E5=8C=85=E5=88=97=E8=A1=A8=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/controller/Redpacket.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/api/controller/Redpacket.php b/application/api/controller/Redpacket.php index 9a90ffd..b22222e 100644 --- a/application/api/controller/Redpacket.php +++ b/application/api/controller/Redpacket.php @@ -99,7 +99,7 @@ class Redpacket extends BaseCom public function roomRedPackets() { $roomId = $this->request->get('room_id'); - $result = Db::name('redpacket')->where(['room_id' => $roomId, 'status' => [1, 0]])->select(); + $result = Db::name('redpacket')->where(['room_id' => $roomId, 'status' => ['<=',1]])->select(); return V(1, '获取成功', $result); } } \ No newline at end of file