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.
|
|
<?php
namespace App\Admin\Extensions\Grid;use App\Common\ProductStatus;use App\Common\StatementType;use App\Models\Agent;use App\Models\Guide;use App\Models\Product;use App\Models\Supplier;use App\Service\WithdrawalService;use App\Traits\DemandTraits;use App\Traits\StatementTraits;use App\Traits\WithdrawalTraits;use Dcat\Admin\Admin;use Dcat\Admin\Grid\RowAction;use Illuminate\Http\Request;use Illuminate\Support\Facades\DB;
/** * 供应商审核 * 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) { DB::beginTransaction(); 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,bcadd($withdrawal->cut_price,$withdrawal->price,6),6); $user->save();
//流水
$service = new WithdrawalService(); //退余额
$service->create( $withdrawal->price, StatementType::REFUND, Admin::user()->id, $withdrawal->user_type, $withdrawal->id, StatementTraits::$type[1] ); //退手续费
$service->create( $withdrawal->cut_price, StatementType::REFUND, Admin::user()->id, $withdrawal->user_type, $withdrawal->id, StatementTraits::$type[1] ); } elseif ($request->action == 3) { //确认打款
$withdrawal = \App\Models\Withdrawal::find($this->getKey()); $withdrawal->status = WithdrawalTraits::$state[3]; }
$withdrawal->save(); DB::commit(); 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]; }}
|