119 lines
4.7 KiB
PHP
119 lines
4.7 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 log_list()
|
||
{
|
||
// 1. 接收参数(前端传递:last_id=上一页最后一条的id,page_limit=每页条数)
|
||
$last_id = input('last_id', 0); // 第一页 last_id=0
|
||
$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, $last_id, $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_exits($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_unlocks($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);
|
||
}
|
||
} |