创建新钱包和钻石兑换5分钟限制
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Cache;
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
use Yzh\YunPay;
|
||||
@@ -11,8 +12,14 @@ class UserWallet extends Model
|
||||
{
|
||||
public function create_data($uid)
|
||||
{
|
||||
$insert_data = ['user_id' => $uid];
|
||||
return Db::name('user_wallet')->insert($insert_data);
|
||||
$insert_data = ['user_id' => $uid, 'createtime' => time()];
|
||||
$coin = Db::name('user_wallet_coin')->insert($insert_data);
|
||||
$earnings = Db::name('user_wallet_earnings')->insert($insert_data);
|
||||
if($coin && $earnings){
|
||||
return true ;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//钱包
|
||||
@@ -21,8 +28,9 @@ class UserWallet extends Model
|
||||
if(!isset($uid)){
|
||||
return ['code' => 301, 'msg' => '登录失效,请重新登录!', 'data' => null];
|
||||
}
|
||||
|
||||
$user_info = db::name('user_wallet')->where('user_id', $uid)->find();
|
||||
// $user_info = db::name('user_wallet')->where('user_id', $uid)->find();
|
||||
$user_info['coin'] = db::name('user_wallet_coin')->where('user_id', $uid)->sum('coin');
|
||||
$user_info['earnings'] = db::name('user_wallet_earnings')->where('user_id', $uid)->sum('earnings');
|
||||
//获取云账号签约协议
|
||||
$yun_pay = new YunPay();
|
||||
$yun_pay_agreement = $yun_pay->getAgreementPreviewUrl();
|
||||
@@ -67,11 +75,9 @@ class UserWallet extends Model
|
||||
if($in_out_type == 1){
|
||||
$in_out_types = [2,5,6,8,13,14,15,16,22,23,26,27,30,28,33,40,51,57,58];
|
||||
$map['change_type'] = ['in', $in_out_types];
|
||||
|
||||
}else{//2-支出
|
||||
$in_out_types = [4,7,10,17,20,24,25,32,42,50,56,59];
|
||||
$map['change_type'] = ['in', $in_out_types];
|
||||
|
||||
}
|
||||
|
||||
$list = Db::name('user_coin_log')
|
||||
@@ -114,6 +120,13 @@ class UserWallet extends Model
|
||||
//收益(钻石)兑换金币
|
||||
public function exchange_coin($uid, $earnings_num)
|
||||
{
|
||||
//从缓存中获取
|
||||
$exchange_user = Cache::get('exchange_user_' . $uid);
|
||||
if($exchange_user){
|
||||
return ['code' => 0, 'msg' => '请5分钟后再次兑换', 'data' => null];
|
||||
}else{
|
||||
Cache::set('exchange_user_' . $uid, 1, 5 * 60);
|
||||
}
|
||||
if(empty($earnings_num)){
|
||||
return ['code' => 0, 'msg' => '请输入需要兑换的钻石数量', 'data' => null];
|
||||
}
|
||||
@@ -122,46 +135,19 @@ class UserWallet extends Model
|
||||
return ['code' => 0, 'msg' => '请输入正确的钻石数量', 'data' => null];
|
||||
}
|
||||
//判断用户的钻石数量是否大于等于兑换数量
|
||||
$user_info = db::name('user_wallet')->where('user_id',$uid)->find();
|
||||
$user_info = db::name('user_wallet_earnings')->where('user_id',$uid)->find();
|
||||
if($user_info['earnings'] < $earnings_num){
|
||||
return ['code' => 0, 'msg' => '钻石数量不足', 'data' => null];
|
||||
}
|
||||
|
||||
$ear_exchange_coin = get_system_config_value('coin_exchange_rate');
|
||||
$data = [
|
||||
'user_id' => $uid,
|
||||
'earnings_num' => $earnings_num,
|
||||
'coin_num' => $earnings_num * $ear_exchange_coin,
|
||||
'createtime' => time(),
|
||||
];
|
||||
$coin_num = $earnings_num * $ear_exchange_coin;
|
||||
//开启事务
|
||||
db::startTrans();
|
||||
try{
|
||||
$give_gift_id = db::name('user_exchange')->insertGetId($data);
|
||||
// 1.系统调节 2.充值 3.提现 4.金币转增(送出) 5.每日任务奖励 6.充值返利 7.购买装扮
|
||||
// 8.礼盒奖励 9.房间补贴 10.购买礼物 11.收礼增加收益 12.工会补贴 13.转赠金币(接收) 14.收益兑换
|
||||
$account_log[] = [
|
||||
'user_id' => $uid,
|
||||
'money_type' => 2,//1金币2钻石
|
||||
'change_value' => $earnings_num,
|
||||
'remarks' => '收益兑换',
|
||||
'change_type' => 14,
|
||||
'createtime' => time(),
|
||||
'from_id' => $give_gift_id,
|
||||
];
|
||||
$account_log[] = [
|
||||
'user_id' => $uid,
|
||||
'money_type' => 1,
|
||||
'change_value' => $earnings_num * $ear_exchange_coin,
|
||||
'remarks' => '收益兑换',
|
||||
'change_type' => 14,
|
||||
'createtime' => time(),
|
||||
'from_id' => $give_gift_id,
|
||||
];
|
||||
$re = db::name('vs_user_money_log')->insertAll($account_log);
|
||||
$re1 = db::name('user_wallet')->where(['user_id' => $uid,'earnings' => ['>=', $earnings_num]])->setDec('earnings',$earnings_num);
|
||||
$re2 = db::name('user_wallet')->where('user_id',$uid)->setInc('coin',$earnings_num * $ear_exchange_coin);
|
||||
if($re && $re1 && $re2){
|
||||
$earn = $this->change_user_earnings_log($uid,$earnings_num,0,14,'收益兑换');
|
||||
$coin = $this->change_user_cion_log($uid,$coin_num,0,14,'收益兑换');
|
||||
if($earn === true && $coin === true){
|
||||
db::commit();
|
||||
return ['code' => 1, 'msg' => '兑换成功', 'data' => null];
|
||||
}else{
|
||||
@@ -172,8 +158,6 @@ class UserWallet extends Model
|
||||
db::rollback();
|
||||
return ['code' => 0, 'msg' => '兑换失败', 'data' => null];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//转币
|
||||
|
||||
Reference in New Issue
Block a user