143 lines
5.8 KiB
PHP
143 lines
5.8 KiB
PHP
<?php
|
||
|
||
namespace app\api\controller;
|
||
|
||
use app\common\controller\BaseCom;
|
||
use think\Db;
|
||
|
||
class UserWallet extends BaseCom
|
||
{
|
||
//钱包
|
||
public function wallet()
|
||
{
|
||
$reslut = model('UserWallet')->wallet($this->uid);
|
||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||
}
|
||
|
||
// //给前端的类型组装一个
|
||
// public function gift_type()
|
||
// {
|
||
// // 1.系统调节 2.充值 3.提现 4.金币转增(送出) 5.每日任务奖励 6.充值返利 7.购买装扮
|
||
// // 8.礼盒奖励 9.房间补贴 10.购买礼物 11.收礼增加收益 12.工会补贴 13.转赠金币(接收) 14.收益兑换
|
||
// $data = [
|
||
//// ['id' => 1, 'name' => '系统调节'],
|
||
// ['id' => 2, 'name' => '充值'],
|
||
// ['id' => 3, 'name' => '提现'],
|
||
// ['id' => 4, 'name' => '金币转增'],
|
||
// ['id' => 5, 'name' => '每日任务奖励'],
|
||
// ['id' => 6, 'name' => '充值返利'],
|
||
// ['id' => 7, 'name' => '购买装扮'],
|
||
// ['id' => 8, 'name' => '礼盒奖励'],
|
||
// ['id' => 9, 'name' => '房间补贴'],
|
||
// ['id' => 10, 'name' => '购买礼物'],
|
||
// ['id' => 11, 'name' => '收礼增加收益'],
|
||
// ['id' => 12, 'name' => '工会补贴'],
|
||
// ['id' => 13, 'name' => '金币转增'],
|
||
// ['id' => 14, 'name' => '收益兑换'],
|
||
// ['id' => 15, 'name' => '送礼'],
|
||
// ];
|
||
// return V(1, '获取成功', $data);
|
||
// }
|
||
|
||
//金币(钻石)明细
|
||
public function log_list()
|
||
{
|
||
$page = input('page', 1);
|
||
$page_limit = input('page_limit', 30);
|
||
$in_out_type = input('in_out_type', 1);//1收入2支出
|
||
$gift_type = input('gift_type', 1);//1金币,2收益(钻石)
|
||
//开始时间
|
||
$start_time = input('start_time', '');
|
||
$end_time = input('end_time', '');
|
||
|
||
$reslut = model('UserWallet')->log_list($this->uid, $page, $page_limit,$in_out_type,$start_time,$end_time,$gift_type);
|
||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||
}
|
||
|
||
//收益(钻石)兑换金币
|
||
public function exchange_coin()
|
||
{
|
||
$key_name = 'exchange_coin_' . $this->uid;
|
||
redis_lock_exit($key_name, 10, 10);
|
||
$earnings_num = input('earnings_num', 0);
|
||
//最少兑换钻石
|
||
$min_earnings_num = get_system_config_value('min_earnings_num');
|
||
if ($earnings_num < $min_earnings_num) {
|
||
return V(0, '兑换金额不能小于' . $min_earnings_num);
|
||
}
|
||
$reslut = model('UserWallet')->exchange_coin($this->uid,$earnings_num);
|
||
redis_unlock($key_name);
|
||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||
}
|
||
|
||
//收益(钻石)兑换金币汇率
|
||
public function exchange_coin_rate()
|
||
{
|
||
$reslut['data'] = get_system_config()['coin_exchange_rate'];
|
||
return V(1, '获取成功', $reslut['data']);
|
||
}
|
||
/*
|
||
* 可选充值金额列表
|
||
*/
|
||
public function can_recharge_list(){
|
||
$reslut = db::name("vs_can_recharge")->where("status",1)->where("delete_time",0)->order('money asc')->select();
|
||
$reslut_data = [];
|
||
foreach ($reslut as $k=>$v){
|
||
$reslut_data[$k]['money'] = $v['money'];
|
||
$reslut_data[$k]['coins'] = $v['coins'];
|
||
$reslut_data[$k]['ios_coins'] = $v['coins'] * 7 / 10;
|
||
$reslut_data[$k]['product_id'] = $v['product_id'];
|
||
}
|
||
return V(1, '获取成功', $reslut_data);
|
||
}
|
||
|
||
//苹果商店充值金额列表
|
||
public function can_recharge_list_ios(){
|
||
$app_version = request()->header('App-Version');
|
||
$system = request()->header('system');
|
||
|
||
$reslut = db::name("vs_can_recharge")->where("status",1)->where("delete_time",0)->order('money asc')->select();
|
||
$reslut_data = [];
|
||
|
||
if ($system == 'iOS') {
|
||
$api_versions = db::name('version')->where(['type' => 2, 'status' => 1])->order('id', 'desc')->find();
|
||
//app的版本和用户使用的当前版本比对
|
||
//$api_versions['newversion'] 是数据库当前的版本 也是用户使用的版本
|
||
//$app_version 有可能是appstore里面的审核版本 审核版本比用户的版本高
|
||
|
||
$result = version_compare($api_versions['newversion'],$app_version);
|
||
if ($result < 0) {//-1:前面版本小于后面版本,0:相等,1:前面版本大于后面版本
|
||
// $api_version = 1;//商店审核版本给前端返回1
|
||
foreach ($reslut as $k=>$v){
|
||
if($v['money'] == 2000){
|
||
$reslut_data[$k]['money'] = '1999.00';
|
||
}else{
|
||
$reslut_data[$k]['money'] = $v['money'];
|
||
}
|
||
$reslut_data[$k]['coins'] = $v['coins'];
|
||
$reslut_data[$k]['ios_coins'] = $v['coins'] * 7 / 10;
|
||
$reslut_data[$k]['product_id'] = $v['product_id'];
|
||
}
|
||
}else{
|
||
foreach ($reslut as $k=>$v){
|
||
$reslut_data[$k]['money'] = $v['money'];
|
||
$reslut_data[$k]['coins'] = $v['coins'];
|
||
$reslut_data[$k]['ios_coins'] = $v['coins'] * 7 / 10;
|
||
$reslut_data[$k]['product_id'] = $v['product_id'];
|
||
}
|
||
}
|
||
}
|
||
|
||
return V(1, '获取成功', $reslut_data);
|
||
}
|
||
|
||
/*
|
||
* 钻石兑换金币比例
|
||
*/
|
||
public function get_wallet_config(){
|
||
$reslut['coin_exchange_rate'] = get_system_config_value('coin_exchange_rate');
|
||
$reslut['withdrawal_service_fee'] = get_system_config_value('withdrawal_service_fee');
|
||
$reslut['rmb_coin_ratio'] = get_system_config_value('rmb_coin_ratio');
|
||
return V(1, '获取成功', $reslut);
|
||
}
|
||
} |