You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
4.9 KiB
138 lines
4.9 KiB
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Admin\Common\WxPay;
|
|
use App\Admin\Repositories\LanzuCsWithdraw;
|
|
use App\Models\LanzuCsInfo;
|
|
use App\Models\LanzuUserBalance;
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Controllers\AdminController;
|
|
use Illuminate\Support\Facades\Log;
|
|
use App\Models\LanzuCsWithdraw as modelCsWithdraw;
|
|
class LanzuCsWithdrawController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
return Grid::make(new LanzuCsWithdraw(), function (Grid $grid) {
|
|
$user = Admin::user();
|
|
if (!$user->isRole('lanzu_cs')) {//如果不是社区站点的角色登陆,则隐藏提现入口
|
|
$grid->disableCreateButton();
|
|
$grid->actions(function (Grid\Displayers\Actions $actions) use ($grid){
|
|
if ($actions->row->status!=0){//状态一但改变,就不能编辑
|
|
$actions->disableEdit();
|
|
}
|
|
});
|
|
} else {
|
|
$grid->disableEditButton();
|
|
}
|
|
$grid->disableViewButton();
|
|
$grid->disableDeleteButton();
|
|
$grid->id->sortable();
|
|
$grid->cs_id('提现用户')->display(function () {
|
|
return LanzuCsInfo::where('id', $this->cs_id)->first()->name;
|
|
});
|
|
$grid->money;
|
|
$grid->status('状态')->using([1 => '已同意', -1 => '已拒绝', 0 => '待审核'])->label([1 => 'success', -1 => 'danger', 0 => 'default']);
|
|
$grid->is_pay('是否到账')->using(['否', '是']);
|
|
$grid->created_at;
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->equal('id');
|
|
});
|
|
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, new LanzuCsWithdraw(), function (Show $show) {
|
|
$show->id;
|
|
$show->cs_id('提现用户');
|
|
$show->money;
|
|
$show->status('状态');
|
|
$show->is_pay('是否到帐');
|
|
$show->created_at;
|
|
$show->updated_at;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new LanzuCsWithdraw('csInfo'), function (Form $form) {
|
|
$form->display('id');
|
|
$user = Admin::user();
|
|
|
|
if ($form->isCreating()) {//如果是添加操作
|
|
if ($user->isRole('lanzu_cs')) {//如果是社区站点角色
|
|
$cs = LanzuCsInfo::where('admin_user_id', $user->id)->first();
|
|
if ($cs) {
|
|
$form->text('amount', '可提现金额')->value(LanzuUserBalance::getBalance($cs->id, 3))->disable();
|
|
$form->hidden('cs_id', '提现用户id')->value($cs->id);
|
|
$form->text('csInfo.name', '提现用户')->value($cs->name)->disable();
|
|
$form->text('money');
|
|
}
|
|
}
|
|
|
|
$form->saved(function ()use ($cs,$form){//扣减提现金额
|
|
LanzuUserBalance::reduceBalance($cs->id,3,$form->money);
|
|
});
|
|
|
|
|
|
} else {//编辑操作
|
|
$form->display('amount', '可提现金额')->value(LanzuUserBalance::getBalance($form->model()->cs_id, 3));
|
|
$form->display('cs_id', '提现用户')->value($form->model()->name);
|
|
$form->display('money');
|
|
|
|
if ($form->model()->status!=0){//提现审核后 就能再编辑
|
|
$form->radio('status', '状态')->options([1 => '同意', -1 => '拒绝'])->disable();
|
|
}else{
|
|
$form->radio('status', '状态')->options([1 => '同意', -1 => '拒绝'])->default(-1);
|
|
}
|
|
|
|
$form->saved(function ()use ($form){
|
|
if ($form->status==-1){//如何审核被拒绝,退回提现金额
|
|
LanzuUserBalance::returnBalance($form->model()->cs_id,3,$form->model()->money);
|
|
}elseif ($form->status==1){//调用微信企业付
|
|
//获取站点信息
|
|
$csInfo = LanzuCsInfo::find($form->model()->cs_id);
|
|
$res = WxPay::pay($csInfo,$form);
|
|
if ($res['result_code'] == "SUCCESS") {//更新到账状态
|
|
$csw = modelCsWithdraw::find($form->model()->id);
|
|
$csw->is_pay = 1;
|
|
$csw->save();
|
|
} else {
|
|
//记录失败日志
|
|
Log::error('提现失败.', $res);
|
|
}
|
|
|
|
|
|
dd($res);
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|