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,279 @@
<?php
namespace app\adminapi\logic\finance;
use app\common\service\{UtilsService};
use app\common\model\finance\{RechargeRecord,WithdrawRecord};
use app\common\model\goods\{GoodsRecord};
use app\common\model\user\{User,UserRelationAgent};
use app\common\model\setting\RechargeMethod;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 充值记录逻辑
* Class RechargeRecordLogic
* @package app\adminapi\logic\finance
*/
class RechargeRecordLogic extends BaseLogic
{
/**
* @notes 删除充值记录
* @param array $params
* @return bool
* @author bd
* @date 2024/01/31 14:07
*/
public static function delete(array $params): bool
{
return RechargeRecord::destroy($params['id']);
}
/**
* @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 = RechargeRecord::find($params['id']);
if ($record->isEmpty()) {
throw new \Exception('记录不存在');
}
if ($record['status']!=0) {
throw new \Exception('状态异常');
}
$user = User::where(['id' => $record['user_id']])->findOrEmpty();
if ($record->isEmpty()) {
throw new \Exception('用户不存在');
}
RechargeRecord::update([
'id' => $params['id'],
'status' => 1
]);
//记录日志
UtilsService::user_finance_add(
$record['user_id'],
1,
1,
$record['amount'],
$record['sn'],
'',
1//冻结
);
//用户资金修改
UtilsService::user_money_change($record['user_id'], 1, $record['amount'],'user_money');
//充值金额增加
UtilsService::user_money_change($record['user_id'], 1, $record['amount'],'total_recharge');
//团队充值奖励
// UtilsService::team_reward_add($record['user_id'],$record['amount'],1);
//充值活动奖励
UtilsService::activity_reward_add($record['user_id'],$record['amount']);
//更新充值记录用户余额
$user = User::where(['id' => $record['user_id']])->findOrEmpty();
if ($user->isEmpty()) {
throw new \Exception('用户不存在');
}
//充值次数+1
User::update([
'id' => $user['id'],
'recharge_num' => $user['recharge_num'] + 1
]);
RechargeRecord::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 = RechargeRecord::find($params['id']);
if ($record->isEmpty()) {
throw new \Exception('记录不存在');
}
if ($record['status']!=0) {
throw new \Exception('状态异常');
}
RechargeRecord::update([
'id' => $params['id'],
'status' => 2
]);
//更新充值记录用户余额
$user = User::where(['id' => $record['user_id']])->findOrEmpty();
if ($user->isEmpty()) {
throw new \Exception('用户不存在');
}
RechargeRecord::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 = RechargeRecord::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('参数异常');
}
}
RechargeRecord::update([
'id' => $params['id'],
'remark2' => $params['content']
]);
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 changeAmount(array $params): bool
{
Db::startTrans();
try {
$record = RechargeRecord::where(['status' => 0])->find($params['id']);
if ($record->isEmpty()) {
throw new \Exception('记录不存在');
}
if($params['amount'] <= 0){
throw new \Exception('请输入正确的金额');
}
$precision = 2;
$method = RechargeMethod::find($record['method_id']);
if (!$method->isEmpty()) {
$precision = $method['precision'];
}
$amount_act = round($params['amount'] * $method['rate'] , $precision);
RechargeRecord::update([
'id' => $params['id'],
'amount' => $params['amount'],
'amount_act' => $amount_act,
]);
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 warmCount()
{
$rechargeCount = RechargeRecord::where(['status' => 0])->count();
$withdrawCount = WithdrawRecord::where(['status' => 0])->count();
// $orderCount = GoodsRecord::where(['status' => 5])->count();
return [
'recharge' => $rechargeCount,
'withdraw' => $withdrawCount,
// 'order' => $orderCount
];
}
/**
* @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 = RechargeRecord::sum('amount');
$ing = RechargeRecord::where(['status' => 0])->sum('amount');
$success = RechargeRecord::where(['status' => 1])->sum('amount');
$error = RechargeRecord::where(['status' => 2])->sum('amount');
return [
'total' => round($total, 2),
'ing' => round($ing, 2),
'success' => round($success, 2),
'error' => round($error, 2),
];
}
}

View File

@@ -0,0 +1,157 @@
<?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\UserFinance;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 资金明细逻辑
* Class UserFinanceLogic
* @package app\adminapi\logic\finance
*/
class UserFinanceLogic extends BaseLogic
{
/**
* @notes 添加资金明细
* @param array $params
* @return bool
* @author BD
* @date 2024/03/07 13:10
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
UserFinance::create([
'sn' => $params['sn'],
'user_id' => $params['user_id'],
'change_object' => $params['change_object'],
'change_type' => $params['change_type'],
'action' => $params['action'],
'change_amount' => $params['change_amount'],
'left_amount' => $params['left_amount'],
'source_sn' => $params['source_sn'],
'remark' => $params['remark'],
'extra' => $params['extra']
]);
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/03/07 13:10
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
UserFinance::where('id', $params['id'])->update([
'sn' => $params['sn'],
'user_id' => $params['user_id'],
'change_object' => $params['change_object'],
'change_type' => $params['change_type'],
'action' => $params['action'],
'change_amount' => $params['change_amount'],
'left_amount' => $params['left_amount'],
'source_sn' => $params['source_sn'],
'remark' => $params['remark'],
'extra' => $params['extra']
]);
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/03/07 13:10
*/
public static function delete(array $params): bool
{
return UserFinance::destroy($params['id']);
}
/**
* @notes 获取资金明细详情
* @param $params
* @return array
* @author BD
* @date 2024/03/07 13:10
*/
public static function detail($params): array
{
return UserFinance::findOrEmpty($params['id'])->toArray();
}
/**
* @notes 解冻
* @param array $params
* @return bool
* @author bd
* @date 2024/01/31 14:07
*/
public static function unfrozen(array $params): bool
{
Db::startTrans();
try {
$record = UserFinance::find($params['id']);
if ($record->isEmpty()) {
throw new \Exception('记录不存在');
}
if ($record['frozen']!=1) {
throw new \Exception('状态异常');
}
UserFinance::update([
'id' => $params['id'],
'frozen' => 0,
'thaw_time' => time(),
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
}

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),
];
}
}