198 lines
6.7 KiB
PHP
198 lines
6.7 KiB
PHP
<?php
|
|
/**
|
|
* SaaSMall商城系统 - 团队十年电商经验汇集巨献!
|
|
* =========================================================
|
|
* Copy right 2019-2029 成都SAAS云科技有限公司, 保留所有权利。
|
|
* ----------------------------------------------
|
|
* 官方网址: https://www.gobuysaas.com
|
|
* =========================================================
|
|
*/
|
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
|
|
use app\model\account\Account as accountModel;
|
|
use think\Exception;
|
|
use think\facade\Db;
|
|
|
|
class MemberFinance extends BaseApi{
|
|
/**
|
|
* Common: 获取提现设置信息
|
|
* Author: wu-hui
|
|
* Time: 2024/05/22 14:28
|
|
* @return false|string
|
|
*/
|
|
public function financeSet(){
|
|
$set = (new accountModel())->getConfig($this->site_id);
|
|
|
|
|
|
return $this->response(success(0,'success',$set));
|
|
}
|
|
/**
|
|
* Common: 提现账户 - 获取用户默认提现账户
|
|
* Author: wu-hui
|
|
* Time: 2024/05/22 14:38
|
|
* @return false|string
|
|
*/
|
|
public function withdrawalAccount(){
|
|
$token = $this->checkToken();
|
|
if ($token['code'] < 0) return $this->response($token);
|
|
// 参数获取
|
|
$id = $this->params['id'] ?? 0;
|
|
$where = [
|
|
['member_id', '=', $this->member_id],
|
|
];
|
|
if($id > 0) $where[] = ['id', '=', $id];
|
|
else $where[] = ['is_default', '=', 1];
|
|
|
|
// 获取提现账户
|
|
$account = model('member_finance_account')->getInfo($where);
|
|
|
|
return $this->response(success(0,'success',$account));
|
|
}
|
|
/**
|
|
* Common: 提现账户 - 获取用户账户列表
|
|
* Author: wu-hui
|
|
* Time: 2024/05/22 15:05
|
|
* @return false|string
|
|
*/
|
|
public function accountList(){
|
|
$token = $this->checkToken();
|
|
if ($token['code'] < 0) return $this->response($token);
|
|
// 获取提现账户
|
|
$accountList = model('member_finance_account')->getList([
|
|
['member_id', '=', $this->member_id],
|
|
]);
|
|
|
|
return $this->response(success(0,'success', $accountList));
|
|
}
|
|
/**
|
|
* Common: 提现账户 - 编辑提现账户
|
|
* Author: wu-hui
|
|
* Time: 2024/05/22 16:52
|
|
* @return false|string
|
|
*/
|
|
public function accountEdit(){
|
|
$token = $this->checkToken();
|
|
if ($token['code'] < 0) return $this->response($token);
|
|
// 参数
|
|
$this->params['member_id'] = $this->member_id;
|
|
$res = (new accountModel())->editInfo($this->params);
|
|
// 判断:如果不存在默认账户 设置当前账户为默认
|
|
$defaultId = (int)model('member_finance_account')->getValue([
|
|
['member_id', '=', $this->member_id],
|
|
['is_default', '=', 1]
|
|
], 'id');
|
|
if($defaultId <= 0) (new accountModel())->setDefaultAccount($this->member_id,$res);
|
|
|
|
return $this->response(success(0,'success'));
|
|
}
|
|
/**
|
|
* Common: 提现账户 - 设置默认账户
|
|
* Author: wu-hui
|
|
* Time: 2024/05/22 17:07
|
|
* @return false|string
|
|
*/
|
|
public function setDefault(){
|
|
$token = $this->checkToken();
|
|
if ($token['code'] < 0) return $this->response($token);
|
|
// 参数
|
|
$id = $this->params['id'] ?? 0;
|
|
(new accountModel())->setDefaultAccount($this->member_id,$id);
|
|
|
|
return $this->response(success(0,'success'));
|
|
}
|
|
/**
|
|
* Common: 提现账户 - 删除
|
|
* Author: wu-hui
|
|
* Time: 2024/05/22 17:09
|
|
* @return false|string
|
|
*/
|
|
public function accountDel(){
|
|
$token = $this->checkToken();
|
|
if ($token['code'] < 0) return $this->response($token);
|
|
// 参数
|
|
$id = $this->params['id'] ?? 0;
|
|
model('member_finance_account')->delete([
|
|
'id' => $id,
|
|
'member_id' => $this->member_id
|
|
]);
|
|
|
|
return $this->response(success(0,'success'));
|
|
}
|
|
/**
|
|
* Common: 获取指定类型可提现佣金
|
|
* Author: wu-hui
|
|
* Time: 2024/05/22 17:44
|
|
* @return false|string
|
|
*/
|
|
public function incomeInfo(){
|
|
$token = $this->checkToken();
|
|
if ($token['code'] < 0) return $this->response($token);
|
|
$incomeType = $this->params['income_type'] ?? '';
|
|
$incomeMoney = (new accountModel())->getIncomeMoney($this->member_id, $incomeType);
|
|
|
|
|
|
return $this->response(success(0,'success', $incomeMoney));
|
|
}
|
|
/**
|
|
* Common: 添加申请
|
|
* Author: wu-hui
|
|
* Time: 2024/05/22 18:16
|
|
* @return false|string
|
|
*/
|
|
public function addApply(){
|
|
$token = $this->checkToken();
|
|
if ($token['code'] < 0) return $this->response($token);
|
|
// 设置获取
|
|
$set = (new accountModel())->getConfig($this->site_id);
|
|
// 可提现金额
|
|
$incomeType = $this->params['income_type'] ?? '';
|
|
$incomeMoney = (new accountModel())->getIncomeMoney($this->member_id, $incomeType);
|
|
// 数据
|
|
$data = [
|
|
'site_id' => $this->site_id,
|
|
'member_id' => $this->member_id,
|
|
'finance_account_id' => $this->params['finance_account_id'] ?? 0,
|
|
'income_type' => $this->params['income_type'] ?? '',
|
|
'apply_money' => $this->params['apply_money'] ?? 0,
|
|
'handling_fees_rate' => $set['commission_handling_fees'],
|
|
'handling_fees_money' => 0,
|
|
'money' => $this->params['apply_money'] ?? 0,
|
|
];
|
|
// 是否存在手续费
|
|
if($data['handling_fees_rate'] > 0){
|
|
$handlingFeesMoney = sprintf("%.2f", $data['apply_money'] * $data['handling_fees_rate'] / 100);
|
|
$data['handling_fees_money'] = $handlingFeesMoney;
|
|
$data['money'] = sprintf("%.2f", $data['money'] - $handlingFeesMoney);
|
|
}
|
|
Db::startTrans();
|
|
try{
|
|
// 判断
|
|
if($data['finance_account_id'] <= 0) throw new Exception('账户不存在');
|
|
if(!$data['income_type']) throw new Exception('收益类型不明确');
|
|
if($data['apply_money'] <= 0) throw new Exception('提现金额必须大于0');
|
|
if($data['apply_money'] > $incomeMoney) throw new Exception('提现金额不能大于可提现金额');
|
|
// 记录
|
|
model('member_finance_apply')->add($data);
|
|
// 修改用户信息
|
|
model('member')->setInc([
|
|
['member_id', '=', $this->member_id]
|
|
],'commission_freeze', (float)$data['apply_money']);
|
|
model('member')->setDec([
|
|
['member_id', '=', $this->member_id]
|
|
],'commission_money', (float)$data['apply_money']);
|
|
|
|
|
|
Db::commit();
|
|
return $this->response(success(0,'success'));
|
|
}catch(\Exception $e){
|
|
Db::rollback();
|
|
|
|
return $this->response(error(-1,$e->getMessage()));
|
|
}
|
|
}
|
|
|
|
|
|
} |