first commit

This commit is contained in:
Your Name
2026-01-19 14:19:22 +08:00
commit fe2d9c1868
4777 changed files with 665503 additions and 0 deletions

View File

@@ -0,0 +1,292 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\finance;
use app\common\model\finance\WithdrawRecord;
use app\common\service\{ConfigService,UtilsService};
use app\common\model\user\{User,UserRelationAgent};
use app\common\model\withdraw\WithdrawMethod;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 提现记录逻辑
* Class WithdrawRecordLogic
* @package app\adminapi\logic\finance
*/
class WithdrawRecordLogic extends BaseLogic
{
/**
* @notes 删除提现记录
* @param array $params
* @return bool
* @author BD
* @date 2024/02/25 12:35
*/
public static function delete(array $params): bool
{
return WithdrawRecord::destroy($params['id']);
}
/**
* @notes udun代付
* @param array $params
* @return bool
* @author bd
* @date 2024/01/31 14:07
*/
public static function udunPay(array $params)
{
Db::startTrans();
try {
$record = WithdrawRecord::find($params['id']);
if ($record->isEmpty()) {
throw new \Exception('记录不存在');
}
if ($record['status']!=0) {
throw new \Exception('状态异常');
}
//重新发起代付需修改订单号
if($record['remark_df'] != ''){
$record['sn'] = generate_sn(WithdrawRecord::class, 'sn');
}
$udun = ConfigService::get('website', 'udun');
if($udun['is_open_df'] == 0){
throw new \Exception('请先开启代付');
}
$method = WithdrawMethod::where(['id' => $record['method_id']])->findOrEmpty();
if ($method->isEmpty()) {
throw new \Exception('提现方式不存在');
}
if ($method['is_open_df'] == 0) {
throw new \Exception('该记录提现方式未开启代付');
}
$main_coin_type = $method['main_coin_type'];
$coin_type = $method['coin_type'];
$udunDispatch = UtilsService::get_udunDispatch();
//验证地址合法性
$result1 = $udunDispatch->checkAddress($main_coin_type,$record['account']);
if($result1['code'] == 200){
//申请提币
$amount_df = round($record['amount']- $record['charge'],2);
$result2 = $udunDispatch->withdraw($record['sn'],$main_coin_type,$coin_type,$record['account'],$amount_df);
if($result2['code'] == 200){
WithdrawRecord::update([
'id' => $record['id'],
'status2' => 1,
'remark_df' => '',
'sn' => $record['sn']
]);
}
}
Db::commit();
return 'success';
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return 'fail';
}
}
/**
* @notes 同意提现
* @param array $params
* @return bool
* @author bd
* @date 2024/01/31 14:07
*/
public static function agree(array $params): bool
{
Db::startTrans();
try {
$record = WithdrawRecord::find($params['id']);
if ($record->isEmpty()) {
throw new \Exception('记录不存在');
}
if ($record['status']!=0) {
throw new \Exception('状态异常');
}
WithdrawRecord::update([
'id' => $params['id'],
'status' => 1,
'status2' => 0,
'remark_df' => '',
]);
//更新充值记录用户余额
$user = User::where(['id' => $record['user_id']])->findOrEmpty();
if ($user->isEmpty()) {
throw new \Exception('用户不存在');
}
//提现次数+1
User::update([
'id' => $user['id'],
'withdraw_num' => $user['withdraw_num'] + 1
]);
WithdrawRecord::update([
'id' => $params['id'],
'user_money' => $user['user_money']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 拒绝提现
* @param array $params
* @return bool
* @author bd
* @date 2024/01/31 14:07
*/
public static function refuse(array $params): bool
{
Db::startTrans();
try {
$record = WithdrawRecord::find($params['id']);
if ($record->isEmpty()) {
throw new \Exception('记录不存在');
}
if ($record['status']!=0) {
throw new \Exception('状态异常');
}
WithdrawRecord::update([
'id' => $params['id'],
'status' => 2,
'remark' => $params['remark'],
'status2' => 0,
'remark_df' => '',
]);
//返还提现金额
//记录日志
UtilsService::user_finance_add(
$record['user_id'],
3,
1,
$record['amount'],
$record['sn'],
$params['remark']
);
//用户资金修改
UtilsService::user_money_change($record['user_id'], 1, $record['amount'],'user_money');
//提现金额修改
UtilsService::user_money_change($record['user_id'], 2, $record['amount'],'total_withdraw');
//更新充值记录用户余额
$user = User::where(['id' => $record['user_id']])->findOrEmpty();
if ($user->isEmpty()) {
throw new \Exception('用户不存在');
}
WithdrawRecord::update([
'id' => $params['id'],
'user_money' => $user['user_money']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 提现记录备注
* @param array $params
* @return bool
* @author bd
* @date 2024/01/31 14:07
*/
public static function remark(array $params): bool
{
Db::startTrans();
try {
$record = WithdrawRecord::find($params['id']);
if ($record->isEmpty()) {
throw new \Exception('记录不存在');
}
//代理操作需查询是否有权限
$user = User::where(['agent_id' => $params['admin_id']])->findOrEmpty();
if (!$user->isEmpty()) {
$userRelation = UserRelationAgent::where(['user_id' => $record['user_id'],'parent_id' => $user['id']])->findOrEmpty();
if ($userRelation->isEmpty()) {
throw new \Exception('参数异常');
}
}
WithdrawRecord::update([
'id' => $params['id'],
'remark2' => $params['content']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 提现统计
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author bd
* @date 2024/01/31 14:07
*/
public static function stat()
{
$total = WithdrawRecord::sum('amount');
$ing = WithdrawRecord::where(['status' => 0])->sum('amount');
$success = WithdrawRecord::where(['status' => 1])->sum('amount');
$error = WithdrawRecord::where(['status' => 2])->sum('amount');
return [
'total' => round($total, 2),
'ing' => round($ing, 2),
'success' => round($success, 2),
'error' => round($error, 2),
];
}
}