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.
		
		
		
		
		
			
		
			
				
					
					
						
							113 lines
						
					
					
						
							2.6 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							113 lines
						
					
					
						
							2.6 KiB
						
					
					
				
								<?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];
							 | 
						|
									}
							 | 
						|
								}
							 |