提交代码
This commit is contained in:
126
app/Agent/Controllers/CashOutController.php
Normal file
126
app/Agent/Controllers/CashOutController.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace App\Agent\Controllers;
|
||||
|
||||
use App\Models\CashAccount;
|
||||
use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use RuLong\UserAccount\Account;
|
||||
use Validator;
|
||||
|
||||
class CashOutController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = Auth::guard('agent')->user();
|
||||
if ($request->isMethod('post')) {
|
||||
$check = $user->cashouts()->whereDate('created_at', Carbon::today()->toDateString())->get()->toArray();
|
||||
if ($check) {
|
||||
// return $this->error('每天只能提现一次');
|
||||
}
|
||||
$validator = Validator::make($request->all(), [
|
||||
'variable' => ['required', 'numeric', function ($attribute, $value, $fail) use ($user) {
|
||||
if ($value == 0) {
|
||||
return $fail('输入金额不能为0');
|
||||
}
|
||||
if ($value > $user->account->cash) {
|
||||
return $fail('输入金额不能大于可提现金额');
|
||||
}
|
||||
}],
|
||||
], [
|
||||
'variable.required' => '金额不能为空',
|
||||
'variable.numeric' => '金额格式不正确',
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return $this->error($validator->errors()->first());
|
||||
}
|
||||
$result = $user->cashouts()->create([
|
||||
'cash_account_id' => $user->cashAccount->id,
|
||||
'variable' => $request->variable,
|
||||
'state' => 'INIT',
|
||||
'cash_account_no' => $user->cashAccount->alipay_account,
|
||||
]);
|
||||
if ($result) {
|
||||
$user->rule('cashout', -$request->variable);
|
||||
return $this->success('操作成功', route('Agent.index'));
|
||||
} else {
|
||||
return $this->error('提现失败');
|
||||
}
|
||||
} else {
|
||||
return view('Agent::cashout.index', compact('user'));
|
||||
}
|
||||
}
|
||||
|
||||
public function cashadd(Request $request)
|
||||
{
|
||||
if ($request->isMethod('post')) {
|
||||
$user = Auth::guard('agent')->user();
|
||||
$validator = Validator::make($request->all(), [
|
||||
'alipay_account' => 'required',
|
||||
'name' => 'required',
|
||||
'alipay_account_code' => 'required',
|
||||
], [
|
||||
'alipay_account.required' => '支付宝账号不能为空',
|
||||
'name.required' => '姓名不能为空',
|
||||
'alipay_account_code' => '商户二维码必须上传',
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return $this->error($validator->errors()->first());
|
||||
}
|
||||
$result = $user->cashAccount()->create([
|
||||
'alipay_account' => $request->alipay_account,
|
||||
'name' => $request->name,
|
||||
'alipay_account_code' => $request->alipay_account_code,
|
||||
]);
|
||||
if ($result) {
|
||||
return $this->success('操作成功', route('Agent.cashout'));
|
||||
} else {
|
||||
return $this->error('失败');
|
||||
}
|
||||
} else {
|
||||
return view('Agent::cashout.cashadd');
|
||||
}
|
||||
}
|
||||
|
||||
public function cashedit(Request $request, CashAccount $cashaccount)
|
||||
{
|
||||
if ($request->isMethod('put')) {
|
||||
$validator = Validator::make($request->all(), [
|
||||
'alipay_account' => 'required',
|
||||
'name' => 'required',
|
||||
'alipay_account_code' => 'required',
|
||||
], [
|
||||
'alipay_account.required' => '支付宝账号不能为空',
|
||||
'name.required' => '姓名不能为空',
|
||||
'alipay_account_code' => '商户二维码必须上传',
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
return $this->error($validator->errors()->first());
|
||||
}
|
||||
if ($cashaccount->update($request->all())) {
|
||||
return $this->success('操作成功', route('Agent.cashout'));
|
||||
} else {
|
||||
return $this->error('失败');
|
||||
}
|
||||
} else {
|
||||
return view('Agent::cashout.cashedit', compact('cashaccount'));
|
||||
}
|
||||
}
|
||||
|
||||
public function logs(Request $request)
|
||||
{
|
||||
$user = Auth::guard('agent')->user();
|
||||
$lists = $user->cashouts()->paginate();
|
||||
if ($request->isMethod('POST')) {
|
||||
if ($lists->isNotEmpty()) {
|
||||
$html = response(view('Agent::cashout.more', compact('lists')))->getContent();
|
||||
return $this->success($html);
|
||||
} else {
|
||||
return $this->error('没有数据了');
|
||||
}
|
||||
} else {
|
||||
return view('Agent::cashout.logs', compact('user', 'lists'));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user