3 changed files with 57 additions and 11 deletions
			
			
		- 
					10app/AdminAgent/Controllers/OrderController.php
 - 
					8app/AdminSupplier/Controllers/OrderController.php
 - 
					50app/AdminSupplier/Extensions/Grid/ChangeOrderStatus.php
 
@ -0,0 +1,50 @@ | 
			
		|||||
 | 
				<?php | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				namespace App\AdminSupplier\Extensions\Grid; | 
			
		||||
 | 
				use App\Common\OrderStatus; | 
			
		||||
 | 
				use App\Models\Order; | 
			
		||||
 | 
				use Dcat\Admin\Admin; | 
			
		||||
 | 
				use Dcat\Admin\Grid\RowAction; | 
			
		||||
 | 
				use Illuminate\Support\Facades\DB; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
				/** | 
			
		||||
 | 
				 * 改变订单状态 | 
			
		||||
 | 
				 * Class ChangeOrderStatus | 
			
		||||
 | 
				 * @package App\AdminAgent\Extensions\Grid | 
			
		||||
 | 
				 */ | 
			
		||||
 | 
				class ChangeOrderStatus extends RowAction | 
			
		||||
 | 
				{ | 
			
		||||
 | 
					protected $title = '设为 [线下]已付款'; | 
			
		||||
 | 
				
 | 
			
		||||
 | 
					protected function html() | 
			
		||||
 | 
					{ | 
			
		||||
 | 
						$this->appendHtmlAttribute('class', 'btn btn-sm btn-success'); | 
			
		||||
 | 
						$this->defaultHtmlAttribute('href', 'javascript:;'); | 
			
		||||
 | 
				
 | 
			
		||||
 | 
						return "<a {$this->formatHtmlAttributes()}>{$this->title}</a>"; | 
			
		||||
 | 
					} | 
			
		||||
 | 
				
 | 
			
		||||
 | 
					public function handle() | 
			
		||||
 | 
					{ | 
			
		||||
 | 
						try { | 
			
		||||
 | 
							$order = Order::query()->whereHas('orderProductItem', function ($query) { | 
			
		||||
 | 
								$query->where(['supplier_id' => Admin::user()->id, 'order_id' => $this->getKey()]); | 
			
		||||
 | 
							})->firstWhere(['id' => $this->getKey(), 'status' => OrderStatus::OFFLINE_UNPAID]); | 
			
		||||
 | 
							if (!$order) { | 
			
		||||
 | 
								return $this->response()->error("订单不存在或已处理过了")->refresh(); | 
			
		||||
 | 
							} | 
			
		||||
 | 
							$order->status = OrderStatus::OFFLINE_PAID; | 
			
		||||
 | 
							$order->verify_code = uniqid(); //生成核销码
 | 
			
		||||
 | 
							$order->save(); | 
			
		||||
 | 
				
 | 
			
		||||
 | 
							return $this->response()->success("操作成功,已设置为“线下已付款”")->refresh(); | 
			
		||||
 | 
						} catch (\Exception $e) { | 
			
		||||
 | 
							return $this->response()->error($e->getMessage()); | 
			
		||||
 | 
						} | 
			
		||||
 | 
					} | 
			
		||||
 | 
				
 | 
			
		||||
 | 
					public function confirm() | 
			
		||||
 | 
					{ | 
			
		||||
 | 
						return ['确定要设置为已付款吗?', '']; | 
			
		||||
 | 
					} | 
			
		||||
 | 
				} | 
			
		||||
						Write
						Preview
					
					
					Loading…
					
					Cancel
						Save
					
		Reference in new issue