jingcai-php/app/Http/Controllers/Api/Seller/WalletController.php

278 lines
8.6 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace App\Http\Controllers\Api\Seller;
use App\Enums\PayType;
use App\Enums\UserType;
use App\Events\PaySuccessEvent;
use App\Model\Seller\ShopBill;
use App\Model\Seller\ShopWithdraw;
use App\Providers\Pay\Alipay;
use App\Service\RechargeService;
use App\Service\SellerWalletService;
use Illuminate\Http\Request;
class WalletController extends BaseController
{
/**
* @api {GET} /api/seller/wallet/pay_types 支付-支付方式
* @apiVersion 0.1.0
* @apiGroup 店主
*
* @apiSuccessExample {json} 返回结果
* {
* "code": 200,
* "message": "",
* "data": [
* {
* "pay_type": "alipay", // 支付方式
* "name": "支付宝" // 支付方式名称
* }
* ]
* }
*/
public function payTypes()
{
$data = [
[
'pay_type' => PayType::ALIPAY,
'name' => '支付宝'
]
];
return $this->jsonSuccess($data);
}
/**
* @api {POST} /api/seller/wallet/recharge 支付-充值(获取充值单号)
* @apiVersion 0.1.0
* @apiGroup 店主
*
* @apiParam {Float} pay_money 支付金额
* @apiParam {String} pay_type 支付方式
*
* @apiParamExample {json} 请求示例
* {
* "order_sn":"xxxx",
* "pay_type":"alipay",
* "pay_money":2.0,
* }
*
* @apiSuccessExample {json} 返回结果
* {
* "code": 200,
* "message": "",
* "data": {
* "recharge_sn": "R202304033597596106" // 充值订单编号
* }
* }
*/
public function recharge(Request $request, RechargeService $rechargeService)
{
$data = $request->all();
$recharge = $rechargeService->shopCreateRecharge($this->seller(), $data);
$ali = new Alipay();
$money = $recharge->pay_money;
$subject = '充值';
$res = $ali->faceToFaceTradePreCreate($recharge->recharge_sn, $money, $subject);
return $this->jsonSuccess($res);
}
/**
* @api {POST} /api/seller/wallet/redirect_pay 支付-跳转到第三方支付
* @apiVersion 0.1.0
* @apiGroup 店主
*
* @apiParam {String} recharge_sn 充值订单编号
* @apiParamExample {json} 请求示例
* {
* "pay_type":"alipay",
* "pay_money":2.0,
* }
*
* @apiSuccessExample {json} 返回结果
* {
* "code": 200,
* "message": "",
* "data": "xxxxxx" // 此处应该是个form
* }
*/
public function redirectPay(Request $request, RechargeService $rechargeService)
{
$rechargeSn = $request->input('recharge_sn');
$form = $rechargeService->shopRedirectPay($this->seller(), $rechargeSn);
return $this->jsonSuccess($form);
}
/**
* @api {GET} /api/seller/wallet/recharge_query 支付-查询充值结果
* @apiVersion 0.1.0
* @apiGroup 店主
*
* @apiParam {String} recharge_sn 充值订单编号
*
* @apiSuccessExample {json} 返回结果
* {
* "code": 200,
* "message": "",
* "data": "xxxxxx" // 此处应该是个form
* }
*/
public function rechargeQuery(Request $request, RechargeService $rechargeService)
{
$rechargeSn = $request->input('recharge_sn');
// $rechargeService->customerRechargeQuery($this->customer(), $rechargeSn);
event(new PaySuccessEvent(UserType::SELLER, [], '', $rechargeSn));
return $this->jsonSuccess([]);
}
/**
* @api {POST} /api/seller/wallet/withdraw_money 我的-提现
* @apiVersion 0.1.0
* @apiGroup 店主
*
* @apiParam {Int} type 1支付宝2银行卡
* @apiParam {Float} money 提现金额
* @apiParam {String} ali_account 支付宝账号
* @apiParam {String} bank_no 银行卡号
* @apiParam {String} bank_area 银行卡所在地
* @apiParam {String} bank_master 开户行
* @apiParam {String} [bank_branch] 支行
* @apiParam {String} password_pay 支付密码
*
* @apiSuccessExample {json} 返回结果
* {
* "code": 200,
* "message": "",
* "data": []
* }
*/
public function withdrawMoney(Request $request, SellerWalletService $walletService)
{
$walletService->withdrawMoney($this->seller(), $request->all());
return $this->jsonSuccess();
}
/**
* @api {GET} /api/seller/wallet/withdraw_list 我的-提现记录
* @apiVersion 0.1.0
* @apiGroup 店主
*
* @apiSuccessExample {json} 返回结果
* {
* "code": 200,
* "message": "",
* "data": {
* "current_page": 1,
* "data": [
* {
* "id": 1,
* "shop_id": 1,
* "seller_id": 1,
* "freeze_id": 1,
* "money": 10, // 提现金额
* "type": 2, // 1支付宝2银行卡
* "ali_account": "",
* "bank_no": "3143243243124312",
* "bank_area": "3143243243124312",
* "bank_master": "3143243243124312",
* "bank_branch": "3143243243124312",
* "state": 1, // 1代理处2成功3失败
* "admin_id": 0,
* "admin_remark": "", // 处理结果
* "remark_at": null,
* "created_at": "2023-04-25T13:27:45.000000Z",
* "updated_at": "2023-04-25T13:27:45.000000Z",
* "deleted_at": null
* }
* ],
* "per_page": 20,
* "total": 1
* }
* }
*/
public function withdrawList(Request $request)
{
$size = $request->input('size');
$list = ShopWithdraw::where('shop_id', $this->shopId())
->orderBy('id', 'desc')
->paging($size);
return $this->jsonSuccess($list);
}
/**
* @api {GET} /api/seller/wallet/bills 店铺余额-账户明细/充值记录
* @apiVersion 0.1.0
* @apiGroup 店主
*
* @apiParam {String} [type] 6充值记录
* @apiParam {String} [ie] -:支出;+:收入
* @apiParam {String} [date_start] 开始日期(2001-01-01),默认本月第一天
* @apiParam {String} [date_end] 结束日期(2001-01-01),默认当前
*
* @apiSuccessExample {json} 返回结果
* {
* "code": 200,
* "message": "",
* "data": {
* "current_page": 1,
* "data": [
* {
* "id": 19,
* "type": 5,
* "seller_id": 1,
* "shop_id": 1,
* "begin_balance": "1.04",
* "begin_balance_withdraw": "0.00",
* "begin_balance_cash": "1.04",
* "seller_balance": "0.00",
* "ie": "-", // -支出 +收入
* "money": "1.00", // 金额
* "end_balance": "0.04", // 余额
* "end_balance_withdraw": "0.00",
* "end_balance_cash": "0.04",
* "title": "相扣你", // 名称
* "created_at": "2023-04-24T14:16:01.000000Z", // 时间
* "updated_at": "2023-04-24T14:16:01.000000Z",
* "deleted_at": null
* },
*
* ],
* "total": 5
* }
* }
*/
public function bills(Request $request)
{
$size = $request->input('size');
$ie = $request->input('ie');
$dateStart = $request->input('date_start');
$dateEnd = $request->input('date_end');
if (!$dateStart) {
$dateStart = date('Y-m-01 00:00:00');
} else {
$dateStart = date('Y-m-d 00:00:00', strtotime($dateStart));
}
if ($dateEnd) {
$dateEnd = date('Y-m-d 23:59:59', strtotime($dateEnd));
}
$query = ShopBill::where('shop_id', $this->shopId());
if ($dateStart) {
$query->where('created_at', '>=', $dateStart);
}
if ($dateEnd) {
$query->where('created_at', '<=', $dateEnd);
}
if ($ie == '-' || $ie == '+') {
$query->where('ie', $ie);
}
$list = $query->orderBy('id', 'desc')
->paging($size);
return $this->jsonSuccess($list);
}
}