8 changed files with 214 additions and 0 deletions
-
63app/Admin/Controllers/WithdrawalController.php
-
113app/Admin/Extensions/Grid/Withdrawal.php
-
16app/Admin/Repositories/Withdrawal.php
-
2app/Admin/routes.php
-
5app/Models/Agent.php
-
5app/Models/Guide.php
-
5app/Models/Supplier.php
-
5app/Models/Withdrawal.php
@ -0,0 +1,63 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Controllers; |
|||
|
|||
use App\Admin\Repositories\Withdrawal; |
|||
use App\Traits\WithdrawalTraits; |
|||
use Dcat\Admin\Admin; |
|||
use Dcat\Admin\Form; |
|||
use Dcat\Admin\Grid; |
|||
use Dcat\Admin\Show; |
|||
use Dcat\Admin\Http\Controllers\AdminController; |
|||
|
|||
class WithdrawalController extends AdminController |
|||
{ |
|||
/** |
|||
* Make a grid builder. |
|||
* |
|||
* @return Grid |
|||
*/ |
|||
protected function grid() |
|||
{ |
|||
return Grid::make(new Withdrawal(['user','pay']), function (Grid $grid) { |
|||
$grid->disableActions(); |
|||
//$grid->disable();
|
|||
$grid->column('id')->sortable(); |
|||
$grid->column('price','提现金额'); |
|||
$grid->column('user.name','用户名称'); |
|||
$grid->column('pay_type','提现方式')->using(WithdrawalTraits::$userTypeText); |
|||
$grid->column('status','状态') |
|||
->if(fn() => $this->status == WithdrawalTraits::$state[0]) |
|||
->display('') |
|||
->then(function ($column) { |
|||
$column->append((new \App\Admin\Extensions\Grid\Withdrawal(null, 1))->setKey($this->id))->append(' '); |
|||
$column->append((new \App\Admin\Extensions\Grid\Withdrawal(null, 2))->setKey($this->id)); |
|||
}) |
|||
->if(fn() => $this->status == WithdrawalTraits::$state[2]) |
|||
->display('') |
|||
->then(function ($column) { |
|||
$column->append((new \App\Admin\Extensions\Grid\Withdrawal(null, 3))->setKey($this->id))->append(' '); |
|||
}) |
|||
->if(fn() => $this->status == WithdrawalTraits::$state[1] || $this->status == WithdrawalTraits::$state[3]) |
|||
->then(function ($column) { |
|||
$column->using(WithdrawalTraits::$stateText)->dot([ |
|||
|
|||
1 => Admin::color()->yellow(), |
|||
2 => 'danger', |
|||
3 => Admin::color()->info(), |
|||
4 => 'success', |
|||
|
|||
]); |
|||
}); |
|||
$grid->column('created_at'); |
|||
$grid->column('updated_at')->sortable(); |
|||
$grid->disableCreateButton(); |
|||
$grid->disableRowSelector(); |
|||
$grid->filter(function (Grid\Filter $filter) { |
|||
$filter->equal('id')->width(3); |
|||
$filter->equal('status','状态')->select(WithdrawalTraits::$stateTextSelect)->width(2); |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,113 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Extensions\Grid; |
|||
use App\Common\ProductStatus; |
|||
use App\Models\Agent; |
|||
use App\Models\Guide; |
|||
use App\Models\Product; |
|||
use App\Models\Supplier; |
|||
use App\Traits\DemandTraits; |
|||
use App\Traits\WithdrawalTraits; |
|||
use Dcat\Admin\Admin; |
|||
use Dcat\Admin\Grid\RowAction; |
|||
use Illuminate\Http\Request; |
|||
|
|||
/** |
|||
* 供应商审核 |
|||
* Class AuditProduct |
|||
* @package App\Admin\Extensions\Grid |
|||
*/ |
|||
class Withdrawal extends RowAction |
|||
{ |
|||
private $action; |
|||
|
|||
public function __construct($title = null, $action = 1) |
|||
{ |
|||
parent::__construct($title); |
|||
$this->action = $action; //$action:1=通过;2=拒绝
|
|||
|
|||
switch ($action) { |
|||
case 1: |
|||
$this->title = '通过'; |
|||
break; |
|||
case 2: |
|||
$this->title = '拒绝'; |
|||
break; |
|||
case 3: |
|||
$this->title = '确认打款'; |
|||
break; |
|||
default: |
|||
$this->title = '通过'; |
|||
} |
|||
} |
|||
|
|||
protected function html() |
|||
{ |
|||
switch ($this->action) { |
|||
case 1: |
|||
$class = 'btn btn-sm btn-success'; |
|||
break; |
|||
case 2: |
|||
$class = 'btn btn-sm btn-danger'; |
|||
break; |
|||
case 3: |
|||
$class = 'btn btn-sm btn-info'; |
|||
break; |
|||
default: |
|||
$class = 'btn btn-sm btn-success'; |
|||
} |
|||
$this->appendHtmlAttribute('class', $class); |
|||
$this->defaultHtmlAttribute('href', 'javascript:;'); |
|||
|
|||
return "<a {$this->formatHtmlAttributes()}>{$this->title}</a>"; |
|||
} |
|||
|
|||
public function handle(Request $request) |
|||
{ |
|||
try { |
|||
if ($request->action == 1) { |
|||
//同意打款
|
|||
$withdrawal = \App\Models\Withdrawal::find($this->getKey()); |
|||
$withdrawal->status = WithdrawalTraits::$state[2]; |
|||
} elseif ($request->action == 2) { |
|||
//拒绝打款
|
|||
$withdrawal = \App\Models\Withdrawal::find($this->getKey()); |
|||
$withdrawal->status = WithdrawalTraits::$state[1]; |
|||
|
|||
//退回余额
|
|||
if ($withdrawal->user_type == DemandTraits::$col[0]) { |
|||
$user = Agent::query(); |
|||
} elseif($withdrawal->user_type == DemandTraits::$col[1]) { |
|||
$user = Supplier::query(); |
|||
} elseif($withdrawal->user_type == DemandTraits::$col[2]) { |
|||
$user = Guide::query(); |
|||
} |
|||
|
|||
$user = $user->where('id', $withdrawal->user_id)->lockForUpdate()->first(); |
|||
|
|||
$user->balance = bcadd($user->balance,$withdrawal->price,6); |
|||
$user->save(); |
|||
} elseif ($request->action == 3) { |
|||
//确认打款
|
|||
$withdrawal = \App\Models\Withdrawal::find($this->getKey()); |
|||
$withdrawal->status = WithdrawalTraits::$state[3]; |
|||
} |
|||
|
|||
$withdrawal->save(); |
|||
|
|||
return $this->response()->success("操作成功")->refresh(); |
|||
} catch (\Exception $e) { |
|||
return $this->response()->error($e->getMessage()); |
|||
} |
|||
} |
|||
|
|||
public function confirm() |
|||
{ |
|||
return ['确定要'.$this->title.'本次提现吗?', '']; |
|||
} |
|||
|
|||
public function parameters() |
|||
{ |
|||
return ['action' => $this->action]; |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
<?php |
|||
|
|||
namespace App\Admin\Repositories; |
|||
|
|||
use App\Models\Withdrawal as Model; |
|||
use Dcat\Admin\Repositories\EloquentRepository; |
|||
|
|||
class Withdrawal extends EloquentRepository |
|||
{ |
|||
/** |
|||
* Model. |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $eloquentClass = Model::class; |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue