Files
yusheng-php/application/api/model/Activities.php

256 lines
12 KiB
PHP
Raw Normal View History

2025-08-07 20:21:47 +08:00
<?php
namespace app\api\model;
use think\Db;
use think\Model;
use think\Session;
class Activities extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
public static function init()
{
self::beforeWrite(function ($row) {
});
}
/*
* 首充好礼发放
*/
public static function first_charge_gift_send($user_id,$money=0)
{
//礼包
2025-10-20 09:59:39 +08:00
$gift_bag = DB::name('vs_gift_bag')->where(['activities_id'=>1,'status'=>1,'delete_time'=>0,'money'=>['<=',$money]])->order('money desc')->find();
$gift_bag_id = $gift_bag['id'] ?? 0;
2025-08-07 20:21:47 +08:00
if (!$gift_bag_id) {
return ['code' => 0, 'msg' => '礼包不存在','data' => null];
}
$gift_bag_detail = DB::name('vs_gift_bag_detail')->where(['gift_bag_id'=>$gift_bag_id])->select();
if (!$gift_bag_detail) {
return ['code' => 0, 'msg' => '礼包未配置','data' => null];
}
Db::startTrans();
try {
foreach ($gift_bag_detail as $k=>$v){
$gift_id =0;
$gift_price = 0;
$gift_num = $v['quantity'];
2025-08-07 20:21:47 +08:00
switch ($v['type']) {
case 1: //金币 方法1直接添加到用户钱包
$gift_price = $v['quantity'];
2025-08-07 20:21:47 +08:00
$res = model('common/UserWallet')->change_user_money($user_id, $v['quantity'], model('common/UserWallet')::MONEYTYPECOIN, model('common/UserWallet')::FIRST_CHARGE,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::FIRST_CHARGE));
break;
case 2: //礼物 方法2添加到用户礼物背包
$gift_id = $v['foreign_id'];
2025-08-07 20:21:47 +08:00
$res = model('UserGiftPack')->change_user_gift_pack($user_id,$v['foreign_id'],$v['quantity'],model('UserGiftPack')::FIRST_CHARGE,"首充好礼获得礼物");
break;
case 3: //坐骑 方法3添加到用户装扮
$gift_id = $v['foreign_id'];
2025-08-07 20:21:47 +08:00
$decorate_price_info = db::name('vs_decorate_price')->where(['id'=>$v['foreign_id']])->find();
if(empty($decorate_price_info)){
break;
2025-08-07 20:21:47 +08:00
}
$gift_price = $decorate_price_info['price'];
2025-08-07 20:21:47 +08:00
$res = model('Decorate')->pay_decorate($user_id,$decorate_price_info['did'],$decorate_price_info['day'],5);
break;
case 4: //道具 方法5钻石
$gift_price = $v['quantity'];
2025-08-07 20:21:47 +08:00
$res = model('common/UserWallet')->change_user_money($user_id, $v['quantity'], model('common/UserWallet')::MONEYTYPEARNINGS, model('common/UserWallet')::FIRST_CHARGE,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::FIRST_CHARGE));
default:
break;
}
if ($res['code'] != 1) {
Db::rollback();
return ['code' => 0, 'msg' => $res['msg'], 'data' => null];
}
// 记录日志
//添加礼盒记录
$reslut = Db::name('vs_gift_bag_receive_log')->insert([
'user_id' => $user_id,
'gift_bag_id' => $gift_bag_id,
'gift_id'=> $gift_id,
'gift_price' => $gift_price,
'num' => $gift_num,
'bag_price' => $money,
'createtime' => time(),
'updatetime' => time()
]);
2025-08-07 20:21:47 +08:00
}
// 添加活动记录
$reslut = Db::name('vs_activities_receive')->insert([
'user_id' => $user_id,
'activities_id' => 1,
'createtime' => time(),
'updatetime' => time()
]);
Db::commit();
return ['code' => 1, 'msg' => '操作成功','data' => null];
}catch (\Exception $e) {
// 回滚事务
Db::rollback();
return ['code' => 0, 'msg' => "请重试", 'data' => null];
}
}
/*
* 天降好礼发放
*/
2025-10-20 09:59:39 +08:00
public static function drop_gift_send($user_id,$money=0)
2025-08-07 20:21:47 +08:00
{
$activities_id = 3;
//礼包
2025-10-20 09:59:39 +08:00
$gift_bag = DB::name('vs_gift_bag')->where(['activities_id'=>$activities_id,'status'=>1])->find();
$gift_bag_id = $gift_bag['id'] ?? 0;
2025-08-07 20:21:47 +08:00
if (!$gift_bag_id) {
return ['code' => 0, 'msg' => '礼包不存在','data' => null];
}
2025-10-20 09:59:39 +08:00
if($money != $gift_bag['money']){
return ['code' => 0, 'msg' => '充值金额未命中天降好礼礼包','data' => null];
}
2025-08-07 20:21:47 +08:00
$gift_bag_detail = DB::name('vs_gift_bag_detail')->where(['gift_bag_id'=>$gift_bag_id])->select();
if (!$gift_bag_detail) {
return ['code' => 0, 'msg' => '礼包不存在','data' => null];
}
Db::startTrans();
try {
foreach ($gift_bag_detail as $k=>$v){
switch ($v['type']) {
case 1: //金币 方法1直接添加到用户钱包
$res = model('common/UserWallet')->change_user_money($user_id, $v['quantity'], model('common/UserWallet')::MONEYTYPECOIN, model('common/UserWallet')::DROP_GIFT_REWARD,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::DROP_GIFT_REWARD));
break;
case 2: //礼物 方法2添加到用户礼物背包
$res = model('UserGiftPack')->change_user_gift_pack($user_id,$v['foreign_id'],$v['quantity'],model('UserGiftPack')::DRAW_GIFT,"天降好礼获得礼物");
break;
case 3: //坐骑 方法3添加到用户装扮
$decorate_price_info = db::name('vs_decorate_price')->where(['id'=>$v['foreign_id']])->find();
if(empty($decorate_price_info)){
break;
2025-08-07 20:21:47 +08:00
}
$res = model('Decorate')->pay_decorate($user_id,$decorate_price_info['did'],$decorate_price_info['day'],6);
break;
case 4: //道具 方法5钻石
$res = model('common/UserWallet')->change_user_money($user_id, $v['quantity'], model('common/UserWallet')::MONEYTYPEARNINGS, model('common/UserWallet')::DROP_GIFT_REWARD,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::DROP_GIFT_REWARD));
default:
break;
}
if ($res['code'] != 1) {
Db::rollback();
return ['code' => 0, 'msg' => $res['msg'], 'data' => null];
}
2025-10-20 09:59:39 +08:00
// 记录日志
//添加礼盒记录
$reslut = Db::name('vs_gift_bag_receive_log')->insert([
'user_id' => $user_id,
'gift_bag_id' => $gift_bag_id,
'parent_id' => $v['id'],
'gift_id'=> $v['foreign_id'],
'num' => $v['quantity'],
'bag_price' => $gift_bag['money'],
'gift_price' => $v['gold'],
'createtime' => time(),
'updatetime' => time()
]);
2025-08-07 20:21:47 +08:00
}
2025-10-20 09:59:39 +08:00
// 添加活动记录
$reslut = Db::name('vs_activities_receive')->insert([
2025-08-07 20:21:47 +08:00
'user_id' => $user_id,
2025-10-20 09:59:39 +08:00
'activities_id' => $activities_id,
2025-08-07 20:21:47 +08:00
'createtime' => time(),
'updatetime' => time()
]);
2025-10-20 09:59:39 +08:00
Db::commit();
return ['code' => 1, 'msg' => '操作成功','data' => null];
}catch (\Exception $e) {
// 回滚事务
Db::rollback();
return ['code' => 0, 'msg' => "请重试", 'data' => null];
}
}
/*
* 新人好礼发放
*/
public static function new_charge_gift_send($user_id,$money=0)
{
//礼包
$activities_id = 7;
$gift_bag = DB::name('vs_gift_bag')->where(['activities_id'=>$activities_id,'status'=>1,'delete_time'=>0,'money'=>$money])->order('money desc')->find();
$gift_bag_id = $gift_bag['id'] ?? 0;
if (!$gift_bag_id) {
return ['code' => 0, 'msg' => '礼包不存在','data' => null];
}
$gift_bag_detail = DB::name('vs_gift_bag_detail')->where(['gift_bag_id'=>$gift_bag_id])->select();
if (!$gift_bag_detail) {
return ['code' => 0, 'msg' => '礼包未配置','data' => null];
}
Db::startTrans();
try {
foreach ($gift_bag_detail as $k=>$v){
$gift_id =0;
$gift_price = 0;
$gift_num = $v['quantity'];
switch ($v['type']) {
case 1: //金币 方法1直接添加到用户钱包
$gift_price = $v['quantity'];
$res = model('common/UserWallet')->change_user_money($user_id, $v['quantity'], model('common/UserWallet')::MONEYTYPECOIN, model('common/UserWallet')::NEW_USER_CHARGE_GIFT,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::NEW_USER_CHARGE_GIFT));
break;
case 2: //礼物 方法2添加到用户礼物背包
$gift_id = $v['foreign_id'];
$res = model('UserGiftPack')->change_user_gift_pack($user_id,$v['foreign_id'],$v['quantity'],model('UserGiftPack')::NEW_CHARGE_GIFT,"新人好礼获得礼物");
break;
case 3: //坐骑 方法3添加到用户装扮
$gift_id = $v['foreign_id'];
$decorate_price_info = db::name('vs_decorate_price')->where(['id'=>$v['foreign_id']])->find();
if(empty($decorate_price_info)){
break;
}
$gift_price = $decorate_price_info['price'];
$res = model('Decorate')->pay_decorate($user_id,$decorate_price_info['did'],$decorate_price_info['day'],8);
break;
case 4: //道具 方法5钻石
$gift_price = $v['quantity'];
$res = model('common/UserWallet')->change_user_money($user_id, $v['quantity'], model('common/UserWallet')::MONEYTYPEARNINGS, model('common/UserWallet')::NEW_USER_CHARGE_GIFT,model('common/UserWallet')::ChangeTypeLable(model('common/UserWallet')::NEW_USER_CHARGE_GIFT));
default:
break;
}
if ($res['code'] != 1) {
Db::rollback();
return ['code' => 0, 'msg' => $res['msg'], 'data' => null];
}
// 记录日志
//添加礼盒记录
$reslut = Db::name('vs_gift_bag_receive_log')->insert([
'user_id' => $user_id,
'gift_bag_id' => $gift_bag_id,
'parent_id' => $v['id'],
'gift_id'=> $v['foreign_id'],
'num' => $v['quantity'],
'bag_price' => $gift_bag['money'],
'gift_price' => $v['gold'],
'createtime' => time(),
'updatetime' => time()
]);
}
2025-08-07 20:21:47 +08:00
// 添加活动记录
$reslut = Db::name('vs_activities_receive')->insert([
'user_id' => $user_id,
2025-11-24 16:51:35 +08:00
'activities_id' => 7,
2025-08-07 20:21:47 +08:00
'createtime' => time(),
'updatetime' => time()
]);
Db::commit();
return ['code' => 1, 'msg' => '操作成功','data' => null];
}catch (\Exception $e) {
// 回滚事务
Db::rollback();
return ['code' => 0, 'msg' => "请重试", 'data' => null];
}
}
2025-10-20 09:59:39 +08:00
2025-08-07 20:21:47 +08:00
}