2025-02-20 13:30:37 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\controller\admin\api\v1;
|
|
|
|
|
|
|
|
use app\dao\UserDao;
|
2025-02-20 23:27:27 +08:00
|
|
|
use app\dao\UserRewardDao;
|
2025-02-20 13:30:37 +08:00
|
|
|
use support\Request;
|
|
|
|
use App\Utils\ApiResponse;
|
|
|
|
use App\model\Admin;
|
2025-02-20 23:27:27 +08:00
|
|
|
use app\model\ExchangeRate;
|
|
|
|
use app\model\Userbank;
|
2025-02-20 13:30:37 +08:00
|
|
|
use hg\apidoc\annotation as Apidoc;
|
|
|
|
use app\model\Withdraw;
|
2025-02-20 23:27:27 +08:00
|
|
|
use App\Utils\API\PaymentNew;
|
2025-02-20 13:30:37 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @Apidoc\Title("账变明细控制器")
|
|
|
|
* @Apidoc\Group("admin")
|
|
|
|
*/
|
|
|
|
class WithdrawController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @Apidoc\Title("1.0 获取系统所有账变明细")
|
|
|
|
* @Apidoc\Url("admin/api/v1/withdraw/lists1")
|
|
|
|
* @Apidoc\Method("POST")
|
|
|
|
*/
|
|
|
|
public function lists(Request $request)
|
|
|
|
{
|
|
|
|
// 获取请求的参数
|
|
|
|
$data = $request->post();
|
|
|
|
|
|
|
|
// 构建查询构造器
|
|
|
|
$query = Withdraw::query();
|
|
|
|
|
|
|
|
if (isset($data['updatedat']) && is_array($data['updatedat']) && count($data['updatedat']) == 2) {
|
|
|
|
// 直接从数组中获取开始和结束日期
|
|
|
|
$startDate = $data['updatedat'][0];
|
|
|
|
$endDate = $data['updatedat'][1];
|
2025-02-20 23:27:27 +08:00
|
|
|
|
2025-02-20 13:30:37 +08:00
|
|
|
if ($startDate === $endDate) {
|
|
|
|
// 如果开始日期和结束日期相同,则查询这一天的所有记录
|
|
|
|
$query->whereDate('updated_at', '=', $startDate);
|
|
|
|
} else {
|
|
|
|
// 否则查询日期范围内的记录
|
|
|
|
$query->whereBetween('updated_at', [$startDate . ' 00:00:00', $endDate . ' 23:59:59']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 根据 username 进行模糊查询
|
|
|
|
if (!empty($data['username'])) {
|
|
|
|
$query->where('username', 'like', '%' . $data['username'] . '%');
|
|
|
|
}
|
2025-02-21 17:19:45 +08:00
|
|
|
// var_dump($data['updatedat']);
|
2025-02-20 13:30:37 +08:00
|
|
|
// 根据 status 过滤,假设 status 字段存在并且不是 -1
|
|
|
|
if (isset($data['status']) && $data['status'] != -1) {
|
|
|
|
$status = (int)$data['status']; // 强制转换为整数
|
|
|
|
$query->where('status', $status);
|
|
|
|
}
|
2025-02-22 20:26:02 +08:00
|
|
|
$query->orderBy('id', 'desc');
|
2025-02-20 13:30:37 +08:00
|
|
|
// 执行查询并返回数据
|
|
|
|
$users = $query->paginate($data['pageSize'], ['*'], 'page', $data['current']); // 或者使用 paginate() 来进行分页
|
|
|
|
|
|
|
|
// 格式化结果为数组
|
|
|
|
return ApiResponse::success(200, $users);
|
|
|
|
}
|
2025-02-20 23:27:27 +08:00
|
|
|
/**
|
|
|
|
* @Apidoc\Title("管理员同意转账")
|
|
|
|
* @Apidoc\Url("admin/api/v1/withdraw/")
|
|
|
|
* @Apidoc\Method("POST")
|
|
|
|
*/
|
|
|
|
public function pushMoney(Request $request)
|
|
|
|
{
|
|
|
|
//金额
|
|
|
|
$amount = $request->post('amount');
|
|
|
|
//转账订单id
|
|
|
|
$id = $request->post('id');
|
|
|
|
//管理员审批结果
|
|
|
|
$type = $request->post('type');
|
|
|
|
//用户id
|
|
|
|
$user_id = $request->post('user_id');
|
|
|
|
//是否同意转账
|
|
|
|
$type = $request->post('type');
|
2025-02-22 15:26:30 +08:00
|
|
|
|
|
|
|
$rate = ExchangeRate::where('type', 'BDT')->get();
|
|
|
|
//计算积分
|
|
|
|
$money = $amount * 100 / $rate[0]['points'] + 300;
|
2025-02-20 23:27:27 +08:00
|
|
|
//不同意
|
|
|
|
if ($type == 1) {
|
|
|
|
$Withdraw = Withdraw::where('id', $id)->first();
|
|
|
|
$Withdraw->status = 3;
|
|
|
|
$Withdraw->status_text = '已驳回';
|
|
|
|
$Withdraw->save();
|
|
|
|
//用户积分增加$money
|
|
|
|
UserRewardDao::base($user_id, 1, $money, '提现失败返还');
|
|
|
|
return ApiResponse::success(200, null, '操作成功');
|
|
|
|
}
|
|
|
|
//同意
|
|
|
|
$userbank = Userbank::where('user_id', $user_id)->first();
|
|
|
|
if ($userbank) {
|
2025-02-22 20:04:28 +08:00
|
|
|
$res = PaymentNew::pushMoney($amount, $userbank->bank_username, $userbank->account, $userbank->bank_name, $id);
|
|
|
|
if(!$res->Success){
|
|
|
|
$Withdraw = Withdraw::where('id', $id)->first();
|
|
|
|
$Withdraw->status = 5;
|
|
|
|
$Withdraw->status_text = '支付失败:用户银行信息存在问题';
|
|
|
|
$Withdraw->save();
|
|
|
|
UserRewardDao::base($user_id, 1, $money, '提现失败返还');
|
|
|
|
return ApiResponse::error(null, '用户银行信息存在问题');
|
|
|
|
}
|
2025-02-20 23:27:27 +08:00
|
|
|
$Withdraw = Withdraw::where('id', $id)->first();
|
|
|
|
$Withdraw->status = 2;
|
|
|
|
$Withdraw->status_text = '已到账';
|
|
|
|
$Withdraw->save();
|
|
|
|
return ApiResponse::success(200, null, '操作成功');
|
|
|
|
} else {
|
2025-02-22 15:26:30 +08:00
|
|
|
$Withdraw = Withdraw::where('id', $id)->first();
|
|
|
|
$Withdraw->status = 5;
|
|
|
|
$Withdraw->status_text = '支付失败:用户银行信息存在问题';
|
|
|
|
$Withdraw->save();
|
|
|
|
UserRewardDao::base($user_id, 1, $money, '提现失败返还');
|
2025-02-20 23:27:27 +08:00
|
|
|
return ApiResponse::error(200, null, '用户银行信息存在问题');
|
|
|
|
}
|
|
|
|
}
|
2025-02-20 13:30:37 +08:00
|
|
|
}
|