feat: 新增
This commit is contained in:
parent
a2997edbb7
commit
afaccea23d
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace App\Utils\API;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
/**
|
||||
* 第三方api转账
|
||||
*/
|
||||
class Payment
|
||||
{
|
||||
/**
|
||||
* 转账
|
||||
*/
|
||||
public static function pushMoney($money,$payeeAccountName,$payeeAccountNumber,$payeeBankName)
|
||||
{
|
||||
$client = new Client(); // 创建 Guzzle 客户端
|
||||
|
||||
// 请求数据
|
||||
$data = [
|
||||
"Amount" => $money,
|
||||
"CurrencyId" => 11,
|
||||
"IsTest" => false,
|
||||
"PayeeAccountName" => $payeeAccountName,
|
||||
"PayeeAccountNumber" => $payeeAccountNumber,
|
||||
"PayeeBankName" => $payeeBankName,
|
||||
"PayeeIFSCCode" => "abc123",
|
||||
"PaymentChannelId" => 34,
|
||||
"ShopInformUrl" => "https://www.google.com",
|
||||
"ShopOrderId" => "10",
|
||||
"ShopRemark" => "", // 留空时可不给此参数
|
||||
"ShopUserLongId" => "776ae472-d4fc-435c-9639-be5763138d95"
|
||||
];
|
||||
|
||||
// 发送 POST 请求
|
||||
$response = $client->post('https://example.com/api/createPaymentOrder', [
|
||||
'json' => $data, // 以 JSON 格式发送数据
|
||||
]);
|
||||
|
||||
// 获取响应体内容
|
||||
$body = $response->getBody();
|
||||
$responseData = json_decode($body, true); // 如果返回的是 JSON 格式,解析它
|
||||
return $responseData;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace app\controller\api;
|
||||
|
||||
use app\model\Pay;
|
||||
|
||||
use App\Utils\ApiResponseApp;
|
||||
|
||||
|
||||
use hg\apidoc\annotation as Apidoc;
|
||||
|
||||
/**
|
||||
* @Apidoc\Title("银行账户信息")
|
||||
*/
|
||||
|
||||
class PayController
|
||||
{
|
||||
|
||||
/**
|
||||
* @Apidoc\Title("查询账户信息")
|
||||
* @Apidoc\Url("api/pay/lists")
|
||||
* @Apidoc\Method("POST")
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
|
||||
$db = Pay::all();
|
||||
return ApiResponseApp::success($db);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
namespace app\controller\api;
|
||||
|
||||
use app\model\Userbank;
|
||||
use app\model\User;
|
||||
use support\Request;
|
||||
|
||||
use App\Utils\ApiResponseApp;
|
||||
|
||||
|
||||
use hg\apidoc\annotation as Apidoc;
|
||||
|
||||
|
||||
/**
|
||||
* @Apidoc\Title("银行信息")
|
||||
*/
|
||||
|
||||
class UserbankController
|
||||
{
|
||||
|
||||
/**
|
||||
* @Apidoc\Title("查询账户信息")
|
||||
* @Apidoc\Url("api/userbank/get_bank")
|
||||
* @Apidoc\Method("POST")
|
||||
*/
|
||||
public function get_bank(Request $request)
|
||||
{
|
||||
$user_id=$request->data['id'];
|
||||
$db = Userbank::where('user_id',$user_id);
|
||||
$db = $db->get();
|
||||
return ApiResponseApp::success($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Apidoc\Title("添加账户信息")
|
||||
* @Apidoc\Url("api/userbank/add")
|
||||
* @Apidoc\Method("POST")
|
||||
*/
|
||||
public function add(Request $request)
|
||||
{
|
||||
$type = $request->post('type');
|
||||
$account = $request->post('account');
|
||||
$bank_name = $request->post('bank_name');
|
||||
$bank_username = $request->post('bank_username');
|
||||
$remark = $request->post('remark');
|
||||
$password = $request->post('password');
|
||||
$user_id=$request->data['id'];
|
||||
$user=User::find($user_id);
|
||||
if (!password_verify($password, $user->password)) {
|
||||
return ApiResponseApp::error('登录密码错误');
|
||||
}
|
||||
$userbank = Userbank::where('user_id',$user_id)->first();
|
||||
if ($userbank) {
|
||||
$userbank->update([
|
||||
'account' => $account,
|
||||
'type' => $type,
|
||||
'bank_name' => $bank_name,
|
||||
'bank_username' => $bank_username,
|
||||
'remark' => $remark,
|
||||
]);
|
||||
}else{
|
||||
var_dump(22);
|
||||
|
||||
Userbank::create([
|
||||
'user_id' => $user_id,
|
||||
'account' => $account,
|
||||
'type' => $type,
|
||||
'bank_name' => $bank_name,
|
||||
'bank_username' => $bank_username,
|
||||
'remark' => $remark,
|
||||
]);
|
||||
}
|
||||
return ApiResponseApp::success('操作成功');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,170 @@
|
|||
<?php
|
||||
|
||||
namespace app\controller\api;
|
||||
|
||||
use app\model\Withdraw;
|
||||
use app\model\User;
|
||||
use app\model\ExchangeRate;
|
||||
use app\model\Userbank;
|
||||
|
||||
use support\Request;
|
||||
use App\Utils\API\Payment;
|
||||
|
||||
use App\Utils\ApiResponseApp;
|
||||
|
||||
use App\dao\UserRewardDao;
|
||||
use hg\apidoc\annotation as Apidoc;
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* @Apidoc\Title("提现订单")
|
||||
*/
|
||||
|
||||
class WithdrawController
|
||||
{
|
||||
|
||||
/**
|
||||
* @Apidoc\Title("1.0 查询当前用户提现订单")
|
||||
* @Apidoc\Url("api/withdraw/withdrawCashList")
|
||||
* @Apidoc\Method("POST")
|
||||
*/
|
||||
public function withdrawCashList(Request $request)
|
||||
{
|
||||
$page = $request->post('page');
|
||||
$size = $request->post('size');
|
||||
$status = $request->post('status');
|
||||
$time = $request->post('time');
|
||||
|
||||
$userId = $request->data['id'];
|
||||
// 初始化查询构建器
|
||||
$query = Withdraw::query();
|
||||
|
||||
// 根据状态过滤
|
||||
if ($status != 0) {
|
||||
$query->where('status', $status);
|
||||
}
|
||||
|
||||
// 根据时间过滤
|
||||
if (!is_null($time)) {
|
||||
$todayStart = Carbon::now()->startOfDay(); // 今天的开始时间 (00:00:00)
|
||||
$todayEnd = Carbon::now()->endOfDay(); // 今天的结束时间 (23:59:59)
|
||||
$yesterdayStart = Carbon::now()->subDay()->startOfDay(); // 昨天的开始时间
|
||||
$sevenDaysAgoStart = Carbon::now()->subDays(7)->startOfDay(); // 七天前的开始时间
|
||||
|
||||
switch ($time) {
|
||||
case 1:
|
||||
$query->whereBetween('createtime2', [$todayStart, $todayEnd]);
|
||||
break;
|
||||
case 2:
|
||||
$query->whereBetween('createtime2', [$yesterdayStart, $todayStart]);
|
||||
break;
|
||||
case 3:
|
||||
$query->whereBetween('createtime2', [$sevenDaysAgoStart, $todayEnd]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 添加用户ID过滤条件
|
||||
$query->where('user_id', $userId);
|
||||
$withdrawOrders = $query->orderBy('createtime2', 'desc')->get();
|
||||
return ApiResponseApp::success($withdrawOrders);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Apidoc\Title("小于1000直接转账,大于1000生成审批")
|
||||
* @Apidoc\Url("api/withdraw/submit")
|
||||
* @Apidoc\Method("POST")
|
||||
*/
|
||||
public function submit(Request $request)
|
||||
{
|
||||
$money_no = $request->post('money');
|
||||
//不知道啥用
|
||||
$bank_id = $request->post('bank_id');
|
||||
$user_id=$request->data['id'];
|
||||
$user=User::find($user_id);
|
||||
//提现金额
|
||||
$rate = ExchangeRate::where('type','BDT')->get();
|
||||
$money = $money_no/100*$rate[0]['points'];
|
||||
//用户积分减少$money
|
||||
UserRewardDao::base($user_id, 1, -$money_no, '提现');
|
||||
//大于1000等待管理员审核
|
||||
if($money>=1000){
|
||||
Withdraw::create([
|
||||
'user_id' => $user_id,
|
||||
'amount' => $money,
|
||||
'status' => 1,
|
||||
'createtime2' => date('Y-m-d H:i:s'),
|
||||
'username' => $user->username,
|
||||
'status_text' => '申请中',
|
||||
]);
|
||||
return ApiResponseApp::success(null,'等待管理员审核');
|
||||
}
|
||||
$userbank = Userbank::where('user_id',$user_id)->first();
|
||||
$res = Payment::pushMoney($money,$userbank->bank_username,$userbank->account,$userbank->bank_name);
|
||||
var_dump($res);
|
||||
if ($res['Success'] == 200) {
|
||||
Withdraw::create([
|
||||
'user_id' => $user_id,
|
||||
'amount' => $money,
|
||||
'status' => 2,
|
||||
'createtime2' => date('Y-m-d H:i:s'),
|
||||
'username' => $user->username,
|
||||
'status_text' => '已到账',
|
||||
]);
|
||||
return ApiResponseApp::success(null,'转账成功');
|
||||
}else{
|
||||
return ApiResponseApp::error(null,'转账失败');
|
||||
}
|
||||
return ApiResponseApp::success(null,'转账成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Apidoc\Title("管理员同意转账")
|
||||
* @Apidoc\Url("api/withdraw/pushMoney")
|
||||
* @Apidoc\Method("POST")
|
||||
*/
|
||||
public function pushMoney(Request $request)
|
||||
{
|
||||
//金额
|
||||
$amount = $request->post('amount');
|
||||
//收款户名
|
||||
$bank_username = $request->post('bank_username');
|
||||
//收款帐号
|
||||
$account = $request->post('account');
|
||||
//收款银行名称
|
||||
$bank_name = $request->post('bank_name');
|
||||
//转账订单id
|
||||
$id = $request->post('id');
|
||||
//管理员审批结果
|
||||
$type = $request->post('type');
|
||||
|
||||
if($type == 1){
|
||||
$res = Payment::pushMoney($amount,$bank_username,$account,$bank_name);
|
||||
var_dump($res);
|
||||
if ($res['Success'] == 200) {
|
||||
$userbank = Userbank::where('id',$id)->first();
|
||||
$userbank->status = 2;
|
||||
$userbank->status_text = '已到账';
|
||||
$userbank->save();
|
||||
return ApiResponseApp::success(null,'转账成功');
|
||||
}else{
|
||||
return ApiResponseApp::error(null,'转账失败');
|
||||
}
|
||||
}else{
|
||||
$userbank = Userbank::where('id',$id)->first();
|
||||
$userbank->status = 3;
|
||||
$userbank->status_text = '已驳回';
|
||||
$userbank->save();
|
||||
$rate = ExchangeRate::where('type','BDT')->get();
|
||||
//计算积分
|
||||
$money = $amount*100/$rate[0]['points'];
|
||||
//用户id
|
||||
$user_id=$request->data['id'];
|
||||
//用户积分增加$money
|
||||
UserRewardDao::base($user_id, 1, $money, '提现失败返还');
|
||||
return ApiResponseApp::error(null,'操作成功');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -32,24 +32,4 @@ class WithdrawController
|
|||
}
|
||||
return ApiResponse::success (200, $db );
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @Apidoc\Title("根据username找子级")
|
||||
// * @Apidoc\Url("/api/v1/Invite/getSonId")
|
||||
// * @Apidoc\Method("POST")
|
||||
// * @Apidoc\Query("id", type="string",require=true, desc="账户id",default="1")
|
||||
// */
|
||||
// public function getSonId(Request $request)
|
||||
// {
|
||||
// $data = $request->post();
|
||||
// $db = Invite::where('username', $data['id'])->get();
|
||||
|
||||
// // 如果查询结果为空,返回错误信息
|
||||
// if ($db->isEmpty()) {
|
||||
// return ApiResponse::error(402, '操作失败');
|
||||
// }
|
||||
|
||||
// // 成功时返回查询结果
|
||||
// return ApiResponse::success(200, $db);
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
class Pay extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'pay';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
|
||||
public $timestamps = false;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
class Userbank extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'userbank';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'account',
|
||||
'type',
|
||||
'bank_name',
|
||||
'bank_username',
|
||||
'remark',
|
||||
];
|
||||
public $timestamps = false;
|
||||
}
|
|
@ -22,4 +22,13 @@ class Withdraw extends Model
|
|||
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'amount',
|
||||
'status',
|
||||
'createtime2',
|
||||
'username',
|
||||
'status_text',
|
||||
];
|
||||
}
|
||||
|
|
|
@ -5074,6 +5074,6 @@
|
|||
"platform": {
|
||||
"php": ">=7.2"
|
||||
},
|
||||
"platform-dev": [],
|
||||
"platform-dev": {},
|
||||
"plugin-api-version": "2.6.0"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue