添加经销商提现接口
parent
ada73cdd43
commit
a70f4280ad
|
|
@ -39,6 +39,9 @@ class Dealer extends Form
|
|||
public function form()
|
||||
{
|
||||
$this->currency('fee_rate', '手续费比例(百分比)')->symbol('%');
|
||||
$this->number('withdraw_threshold_amount', '起提金额(元)');
|
||||
$this->currency('withdraw_fee_rate', '提现费率')->symbol('%');
|
||||
|
||||
$this->currency('upgrade_amount_'.DealerLvl::Contracted->value, '签约门槛')->symbol('¥');
|
||||
$this->currency('upgrade_amount_'.DealerLvl::Special->value, '特邀门槛')->symbol('¥');
|
||||
$this->currency('upgrade_amount_'.DealerLvl::Gold->value, '金牌门槛')->symbol('¥');
|
||||
|
|
@ -127,8 +130,10 @@ class Dealer extends Form
|
|||
{
|
||||
$dealerSettings = (array) Setting::where('key', 'dealer')->value('value');
|
||||
return [
|
||||
'fee_rate'=>$dealerSettings['fee_rate'] ?? '',
|
||||
'order_auto_allocate_times'=>$dealerSettings['order_auto_allocate_times'] ?? 1,
|
||||
'fee_rate'=> $dealerSettings['fee_rate'] ?? '',
|
||||
'withdraw_threshold_amount'=> $dealerSettings['withdraw_threshold_amount'] ?? 0,
|
||||
'withdraw_fee_rate'=> $dealerSettings['withdraw_fee_rate'] ?? 0,
|
||||
'order_auto_allocate_times'=> $dealerSettings['order_auto_allocate_times'] ?? 1,
|
||||
'upgrade_amount_'.DealerLvl::Contracted->value => $dealerSettings['upgrade_amount_'.DealerLvl::Contracted->value] ?? '',
|
||||
'upgrade_amount_'.DealerLvl::Special->value => $dealerSettings['upgrade_amount_'.DealerLvl::Special->value] ?? '',
|
||||
'upgrade_amount_'.DealerLvl::Gold->value => $dealerSettings['upgrade_amount_'.DealerLvl::Gold->value] ?? '',
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ class UserController extends Controller
|
|||
return response()->json([
|
||||
'phone' => $user->phone,
|
||||
'dealer'=> $user->dealer ? DealerResource::make($user->dealer) : [],
|
||||
'dealer_wallet' => $user->dealerWallet?->balance,
|
||||
'user_info' => UserInfoResource::make($user->userInfo),
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,121 @@
|
|||
<?php
|
||||
|
||||
namespace App\Endpoint\Api\Http\Controllers\Dealer;
|
||||
|
||||
use App\Endpoint\Api\Http\Controllers\Controller;
|
||||
use App\Endpoint\Api\Http\Resources\Dealer\WalletLogResource;
|
||||
use App\Endpoint\Api\Http\Resources\Dealer\WalletToBankLogResource;
|
||||
use App\Endpoint\Api\Http\Resources\Dealer\WalletToBankLogSimpleResource;
|
||||
use App\Enums\DealerWalletAction;
|
||||
use App\Exceptions\BizException;
|
||||
use App\Helpers\Paginator as PaginatorHelper;
|
||||
use App\Models\DealerWalletToBankLog;
|
||||
use App\Services\Dealer\WalletService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class WalletController extends Controller
|
||||
{
|
||||
/**
|
||||
* 余额明细
|
||||
*
|
||||
* @param Request $request
|
||||
* @return void
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$perPage = PaginatorHelper::resolvePerPage('per_page', 20, 50);
|
||||
return WalletLogResource::collection($request->user()->dealerWalletLogs()
|
||||
->latest('id')
|
||||
->simplePaginate($perPage));
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现到银行
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function walletToBank(Request $request, WalletService $walletService)
|
||||
{
|
||||
$input = $request->validate([
|
||||
'amount' => ['bail', 'required', 'int', 'min:1'],
|
||||
]);
|
||||
|
||||
$user = $request->user();
|
||||
$amount = Arr::get($input, 'amount', 0);
|
||||
|
||||
if (is_null($user->dealer->pay_info)) {
|
||||
throw new BizException('请先绑定设置收款信息');
|
||||
}
|
||||
//校验是否关闭提现
|
||||
if (!$user->dealerWallet?->withdrawable) {
|
||||
throw new BizException('可提账户已被限制提现');
|
||||
}
|
||||
|
||||
// 校验提现门槛
|
||||
if (bcdiv($amount, 100, 2) < app_settings('dealer.withdraw_threshold_amount', 0)) {
|
||||
throw new BizException('提现金额需大于'.app_settings('dealer.withdraw_threshold_amount', 0).'元');
|
||||
}
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$rate = app_settings('dealer.withdraw_fee_rate', '0.00');//手续费率
|
||||
// $rate = 0;
|
||||
//计算手续费(四舍五入)
|
||||
$serviceAmount = round(bcdiv($rate, 100, 4)*$amount);
|
||||
|
||||
//生成提现记录
|
||||
$log = DealerWalletToBankLog::create([
|
||||
'user_id' =>$user->id,
|
||||
'amount'=> $amount,
|
||||
'rate' => $rate,
|
||||
'service_amount' => $serviceAmount,
|
||||
'account_amount' => $amount-$serviceAmount,
|
||||
]);
|
||||
|
||||
//减去用户可提金额
|
||||
$walletService->changeBalance($user, -$amount, DealerWalletAction::WithdrawBank, '提现', $log);
|
||||
DB::commit();
|
||||
} catch (BizException $th) {
|
||||
DB::rollBack();
|
||||
throw new BizException($th->getMessage());
|
||||
} catch (Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
throw new BizException('系统繁忙,请稍后再试');
|
||||
}
|
||||
return response()->noContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现记录
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function walletToBankLogs(Request $request)
|
||||
{
|
||||
$perPage = PaginatorHelper::resolvePerPage('per_page', 20, 50);
|
||||
|
||||
$logs = $request->user()->dealerWalletToBankLogs()
|
||||
->latest('id')
|
||||
->simplePaginate($perPage);
|
||||
|
||||
return WalletToBankLogSimpleResource::collection($logs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现记录详情
|
||||
*
|
||||
* @param [type] $id
|
||||
* @param Request $request
|
||||
* @return void
|
||||
*/
|
||||
public function walletToBankLogShow($id, Request $request)
|
||||
{
|
||||
$log = $request->user()->dealerWalletToBankLogs()->findOrFail($id);
|
||||
return WalletToBankLogResource::make($log);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Endpoint\Api\Http\Resources\Dealer;
|
||||
|
||||
use App\Models\DealerWalletToBankLog;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class DealerResource extends JsonResource
|
||||
|
|
@ -19,7 +20,9 @@ class DealerResource extends JsonResource
|
|||
'lvl_name'=> $this->lvl_text,
|
||||
'sale_values'=> $this->sale_values, //团队销售业绩基数
|
||||
'guanli_values'=> $this->calculate_total_amount, //预计管理津贴
|
||||
'team_sales_value' => $this->team_sales_value,
|
||||
'pay_info'=>$this->pay_info ?: null,
|
||||
'can_withdraw'=> DealerWalletToBankLog::where('user_id', $this->user_id)->where('created_at', '>', now()->subDays(7))->doesntExist(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Endpoint\Api\Http\Resources\Dealer;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class WalletLogResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'remarks' => $this->remarks,
|
||||
'created_at' => $this->created_at->format('y-m-d H:i'),
|
||||
'change_balance' => $this->change_balance,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace App\Endpoint\Api\Http\Resources\Dealer;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class WalletToBankLogResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'amount' => $this->amount,
|
||||
'service_amount' => $this->service_amount,
|
||||
'created_at' => $this->created_at->toDateTimeString(),
|
||||
'status' => $this->status,
|
||||
'remarks' => $this->remarks,
|
||||
'pay_info' => $this->getPayInfo(),
|
||||
'pay_image' => $this->pay_image,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Endpoint\Api\Http\Resources\Dealer;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class WalletToBankLogSimpleResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'amount' => $this->amount,
|
||||
'service_amount' => $this->service_amount,
|
||||
'created_at' => $this->created_at->toDateTimeString(),
|
||||
'status' => $this->status,
|
||||
'remarks' => $this->remarks,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -260,5 +260,10 @@ Route::group([
|
|||
Route::get('earnings/{earning}', [Dealer\EarningController::class, 'show']);
|
||||
Route::post('earnings/{earning}/pay', [Dealer\EarningController::class, 'payEarning']);
|
||||
Route::post('earnings/{earning}/confirm', [Dealer\EarningController::class, 'confirmEarning']);
|
||||
//余额提现
|
||||
Route::get('wallet', [Dealer\WalletController::class, 'index']);
|
||||
Route::post('wallet/withdraw', [Dealer\WalletController::class, 'walletToBank']);
|
||||
Route::get('wallet/withdraw-logs', [Dealer\WalletController::class, 'walletToBankLogs']);
|
||||
Route::get('wallet/withdraw-logs/{withdraw_log}', [Dealer\WalletController::class, 'walletToBankLogShow']);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,4 +3,5 @@
|
|||
namespace App\Enums;
|
||||
|
||||
enum DealerWalletAction: int {
|
||||
case WithdrawBank = 4;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DealerWalletToBankLog extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasDateTimeFormatter;
|
||||
|
||||
public const STATUS_PENDING = 0;//'待处理'
|
||||
public const STATUS_AGREE = 1;//'已同意'
|
||||
public const STATUS_REFUSE = 2;//'已拒绝'
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'amount',
|
||||
'status',
|
||||
'remarks',
|
||||
'rate',
|
||||
'service_amount',
|
||||
'account_amount',
|
||||
];
|
||||
|
||||
/**
|
||||
* 提现记录所属用户
|
||||
*
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 待打款状态
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isPending()
|
||||
{
|
||||
return $this->status == self::STATUS_PENDING;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户的打款信息
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getPayInfo()
|
||||
{
|
||||
if ($this->isPending()) {//待打款订单显示发货人收款信息
|
||||
$payInfo = $this->user->dealer->pay_info;
|
||||
} else {
|
||||
$payInfo = $this->pay_info;
|
||||
}
|
||||
return $payInfo ?: null;
|
||||
}
|
||||
}
|
||||
|
|
@ -170,6 +170,15 @@ class User extends Model implements AuthorizableContract, AuthenticatableContrac
|
|||
return $this->hasMany(DealerWalletLog::class, 'user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 属于此用户的经销商余额提现日志
|
||||
*/
|
||||
public function dealerWalletToBankLogs()
|
||||
{
|
||||
return $this->hasMany(DealerWalletToBankLog::class, 'user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 经销商订购订单
|
||||
*
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ class AppServiceProvider extends ServiceProvider
|
|||
'dealer_manage_subsidy' => \App\Models\DealerManageSubsidy::class,
|
||||
'dealer_channel_subsidy_log' => \App\Models\DealerChannelSubsidyLog::class,
|
||||
'dealer_purchase_subsidy' => \App\Models\DealerPurchaseSubsidy::class,
|
||||
'dealer_wallet_to_bank_log' => \App\Models\DealerWalletToBankLog::class,
|
||||
]);
|
||||
|
||||
JsonResource::withoutWrapping();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateDealerWalletToBankLogsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('dealer_wallet_to_bank_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('user_id')->comment('用户ID');
|
||||
$table->unsignedDecimal('amount')->comment('提现金额');
|
||||
$table->unsignedDecimal('rate', 18, 2)->default(0)->comment('费率');
|
||||
$table->unsignedDecimal('service_amount')->default(0)->comment('手续费');
|
||||
$table->unsignedDecimal('account_amount')->comment('到账金额');
|
||||
$table->unsignedTinyInteger('status')->default(0)->comment('状态:0未处理,1成功,2失败');
|
||||
$table->text('pay_info')->nullable()->comment('收款信息');
|
||||
$table->string('pay_image')->nullable()->comment('打款凭证');
|
||||
$table->string('remarks')->nullable()->comment('备注');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('dealer_wallet_to_bank_logs');
|
||||
}
|
||||
}
|
||||
|
|
@ -177,6 +177,8 @@ class AppSettingSeeder extends Seeder
|
|||
'dealer' => [
|
||||
'value' => [
|
||||
'fee_rate' => '6', // 手续费比例(百分比)
|
||||
'withdraw_threshold_amount'=>'0', //提现门槛金额
|
||||
'withdraw_fee_rate'=>'0.00', //提现手续费率
|
||||
|
||||
// 金牌经销商升级金额
|
||||
'upgrade_amount_'.DealerLvl::Gold->value => '2520',
|
||||
|
|
|
|||
Loading…
Reference in New Issue