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.
		
		
		
		
		
			
		
			
				
					
					
						
							99 lines
						
					
					
						
							2.5 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							99 lines
						
					
					
						
							2.5 KiB
						
					
					
				
								<?php
							 | 
						|
								
							 | 
						|
								namespace App\AdminSupplier\Extensions\Grid;
							 | 
						|
								
							 | 
						|
								use App\Models\AgentProduct;
							 | 
						|
								use App\Models\DemandBidding;
							 | 
						|
								use App\Models\DemandProduct;
							 | 
						|
								use App\Traits\DemandTraits;
							 | 
						|
								use Dcat\Admin\Grid\RowAction;
							 | 
						|
								use Illuminate\Database\Eloquent\Model;
							 | 
						|
								use Illuminate\Http\Request;
							 | 
						|
								use Illuminate\Support\Facades\DB;
							 | 
						|
								use Illuminate\Support\Facades\Log;
							 | 
						|
								
							 | 
						|
								/**
							 | 
						|
								 * 供应商审核
							 | 
						|
								 * Class AuditSupplier
							 | 
						|
								 * @package App\Admin\Extensions\Grid
							 | 
						|
								 */
							 | 
						|
								class ChooseDemand extends RowAction
							 | 
						|
								{
							 | 
						|
									private $id;
							 | 
						|
								
							 | 
						|
									public function __construct($biddingId = '')
							 | 
						|
									{
							 | 
						|
										parent::__construct('参与竞标');
							 | 
						|
										$this->id = $biddingId;
							 | 
						|
										$this->title = '选中竞标';
							 | 
						|
									}
							 | 
						|
								
							 | 
						|
									protected function html()
							 | 
						|
									{
							 | 
						|
										$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)
							 | 
						|
									{
							 | 
						|
										$demandBiddingId = request('bidding_id',0);
							 | 
						|
										$demandBidding = DemandBidding::find($demandBiddingId);
							 | 
						|
										if (empty($demandBidding)) {
							 | 
						|
											return false;
							 | 
						|
										}
							 | 
						|
								
							 | 
						|
										$demand = \App\Models\Demand::find($demandBidding->demand_id);
							 | 
						|
								
							 | 
						|
										if (empty($demand)) {
							 | 
						|
											return false;
							 | 
						|
										}
							 | 
						|
								
							 | 
						|
										DB::beginTransaction();
							 | 
						|
										try {
							 | 
						|
											$demandBidding->state = 1;
							 | 
						|
											$demandBidding->save();
							 | 
						|
											//改变订单状态
							 | 
						|
											$demand->bidding_id = $demandBidding->id;
							 | 
						|
											$demand->bidding_user_id = $demandBidding->bidding_user_id;
							 | 
						|
											$demand->state = DemandTraits::$stateKey[1];
							 | 
						|
											$demand->save();
							 | 
						|
											//将产品绑给代理商
							 | 
						|
											$demandProduct = DemandProduct::find($demand->demand_product_id);
							 | 
						|
											$product = new Product();
							 | 
						|
								
							 | 
						|
											$product->supplier_id = $demandProduct->supplier_id;
							 | 
						|
											$product->category_id = $demandProduct->category_id;
							 | 
						|
											$product->title = $demandProduct->title;
							 | 
						|
											$product->price = $demandBidding->price;
							 | 
						|
											$product->original_price = $demandBidding->price;
							 | 
						|
											$product->pictures = $demandProduct->pictures;
							 | 
						|
											$product->stock = $demand->stock;
							 | 
						|
											$product->know = $demandProduct->know;
							 | 
						|
											$product->content = $demandProduct->content;
							 | 
						|
											$product->agent_id = $demandBidding->bidding_user_id;
							 | 
						|
											$product->save();
							 | 
						|
								
							 | 
						|
											$demand->product_id = $product->id;
							 | 
						|
											$demand->save();
							 | 
						|
											DB::commit();
							 | 
						|
											return $this->response()->success("选中竞标成功")->refresh();
							 | 
						|
										} catch (\Exception $e) {
							 | 
						|
											Log::error('选中竞标失败::'.$e->getTraceAsString());
							 | 
						|
											DB::rollBack();
							 | 
						|
											return $this->response()->error($e->getMessage());
							 | 
						|
										}
							 | 
						|
									}
							 | 
						|
								
							 | 
						|
									public function confirm()
							 | 
						|
									{
							 | 
						|
										return ['确定要选中该竞标吗?', ''];
							 | 
						|
									}
							 | 
						|
								
							 | 
						|
									public function parameters()
							 | 
						|
									{
							 | 
						|
										return ['bidding_id' => $this->id];
							 | 
						|
									}
							 | 
						|
								}
							 |