Browse Source

竞标

master
lemon 4 years ago
parent
commit
a8be80039b
  1. 19
      app/AdminAgent/Controllers/DemandController.php
  2. 2
      app/AdminGuide/Controllers/DemandBiddingController.php
  3. 26
      app/AdminGuide/Controllers/DemandController.php
  4. 4
      app/AdminGuide/Controllers/MyDemandProductController.php
  5. 2
      app/AdminGuide/Controllers/WorkorderController.php
  6. 86
      app/AdminGuide/Extensions/Grid/ChooseDemand.php
  7. 48
      app/AdminGuide/Lazys/DemandBiddingLazys.php
  8. 16
      app/AdminGuide/Repositories/Workorder.php
  9. 22
      app/AdminSupplier/Controllers/DemandController.php
  10. 2
      app/AdminSupplier/Extensions/Grid/ChooseDemand.php
  11. 2
      app/Traits/DemandTraits.php

19
app/AdminAgent/Controllers/DemandController.php

@ -80,18 +80,31 @@ class DemandController extends AdminController
}); });
}else{ }else{
$grid->column('bidding','竞标') $grid->column('bidding','竞标')
->if(function (){
->if(function () {
$isBidding = DemandBidding::query() $isBidding = DemandBidding::query()
->where('demand_id',$this->id) ->where('demand_id',$this->id)
->where([ ->where([
'bidding_user_type' => DemandTraits::$col[0], 'bidding_user_type' => DemandTraits::$col[0],
'bidding_user_id' => Admin::user()->id 'bidding_user_id' => Admin::user()->id
]) ])
->doesntExist();
->exists();
return $this->state == 1 && $this->bidding_user_type == Arr::first(DemandTraits::$col) && $isBidding; return $this->state == 1 && $this->bidding_user_type == Arr::first(DemandTraits::$col) && $isBidding;
}) })
->then(function (Grid\Column $column) { ->then(function (Grid\Column $column) {
$column->append('<a class="btn btn-sm btn-primary" href="'.admin_url('/demand_bidding/create?demand_id='.$this->id).'">发起竞标</a>');
$column->display('已竞标');
})
->if(function (){
$isNotBidding = DemandBidding::query()
->where('demand_id',$this->id)
->where([
'bidding_user_type' => DemandTraits::$col[0],
'bidding_user_id' => Admin::user()->id
])
->doesntExist();
return $this->state == 1 && $this->bidding_user_type == Arr::first(DemandTraits::$col) && $isNotBidding;
})
->then(function (Grid\Column $column) {
$column->append('<a class="btn btn-sm btn-primary" href="'.admin_url('/demand_bidding/create?demand_id='.$this->id).'">参与竞标</a>');
}); });
} }

2
app/AdminGuide/Controllers/DemandBiddingController.php

@ -2,7 +2,7 @@
namespace App\AdminGuide\Controllers; namespace App\AdminGuide\Controllers;
use App\AdminAgent\Repositories\DemandBidding;
use App\AdminGuide\Repositories\DemandBidding;
use App\Models\Demand; use App\Models\Demand;
use App\Traits\DemandTraits; use App\Traits\DemandTraits;
use Dcat\Admin\Admin; use Dcat\Admin\Admin;

26
app/AdminGuide/Controllers/DemandController.php

@ -2,12 +2,9 @@
namespace App\AdminGuide\Controllers; namespace App\AdminGuide\Controllers;
use App\AdminAgent\Actions\Grid\DemandConfirm;
use App\AdminAgent\Lazys\DemandBiddingLazys;
use App\Models\AgentProduct;
use App\Models\Product;
use App\AdminGuide\Lazys\DemandBiddingLazys;
use App\Traits\ResponseHelper; use App\Traits\ResponseHelper;
use App\AdminAgent\Repositories\Demand;
use App\AdminGuide\Repositories\Demand;
use App\Models\DemandBidding; use App\Models\DemandBidding;
use Dcat\Admin\Admin; use Dcat\Admin\Admin;
use Dcat\Admin\Form; use Dcat\Admin\Form;
@ -79,18 +76,31 @@ class DemandController extends AdminController
}); });
}else{ }else{
$grid->column('bidding','竞标') $grid->column('bidding','竞标')
->if(function (){
->if(function () {
$isBidding = DemandBidding::query() $isBidding = DemandBidding::query()
->where('demand_id',$this->id) ->where('demand_id',$this->id)
->where([ ->where([
'bidding_user_type' => DemandTraits::$col[2], 'bidding_user_type' => DemandTraits::$col[2],
'bidding_user_id' => Admin::user()->id 'bidding_user_id' => Admin::user()->id
]) ])
->doesntExist();
->exists();
return $this->state == 1 && $this->bidding_user_type == DemandTraits::$col[2] && $isBidding; return $this->state == 1 && $this->bidding_user_type == DemandTraits::$col[2] && $isBidding;
}) })
->then(function (Grid\Column $column) { ->then(function (Grid\Column $column) {
$column->append('<a class="btn btn-sm btn-primary" href="'.admin_url('/demand_bidding/create?demand_id='.$this->id).'">发起竞标</a>');
$column->display('已竞标');
})
->if(function (){
$isNotBidding = DemandBidding::query()
->where('demand_id',$this->id)
->where([
'bidding_user_type' => DemandTraits::$col[2],
'bidding_user_id' => Admin::user()->id
])
->doesntExist();
return $this->state == 1 && $this->bidding_user_type == DemandTraits::$col[2] && $isNotBidding;
})
->then(function (Grid\Column $column) {
$column->append('<a class="btn btn-sm btn-primary" href="'.admin_url('/demand_bidding/create?demand_id='.$this->id).'">参与竞标</a>');
}); });
} }

4
app/AdminGuide/Controllers/MyDemandProductController.php

@ -2,14 +2,12 @@
namespace App\AdminGuide\Controllers; namespace App\AdminGuide\Controllers;
use App\AdminAgent\Actions\Grid\DemandConfirm;
use App\AdminAgent\Lazys\DemandBiddingLazys;
use App\Common\ProductStatus; use App\Common\ProductStatus;
use App\Models\AgentProduct; use App\Models\AgentProduct;
use App\Models\Channel; use App\Models\Channel;
use App\Models\Product; use App\Models\Product;
use App\Traits\ResponseHelper; use App\Traits\ResponseHelper;
use App\AdminAgent\Repositories\Demand;
use App\AdminGuide\Repositories\Demand;
use App\Models\DemandBidding; use App\Models\DemandBidding;
use Dcat\Admin\Admin; use Dcat\Admin\Admin;
use Dcat\Admin\Form; use Dcat\Admin\Form;

2
app/AdminGuide/Controllers/WorkorderController.php

@ -2,7 +2,7 @@
namespace App\AdminGuide\Controllers; namespace App\AdminGuide\Controllers;
use App\AdminAgent\Repositories\Workorder;
use App\AdminGuide\Repositories\Workorder;
use App\Common\AgentType; use App\Common\AgentType;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\Agent; use App\Models\Agent;

86
app/AdminGuide/Extensions/Grid/ChooseDemand.php

@ -0,0 +1,86 @@
<?php
namespace App\AdminGuide\Extensions\Grid;
use App\Models\AgentProduct;
use App\Models\DemandBidding;
use App\Traits\DemandTraits;
use Dcat\Admin\Grid\RowAction;
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 $this->response()->error('订单异常');
}
$demand = \App\Models\Demand::find($demandBidding->demand_id);
if (empty($demand)) {
return $this->response()->error('订单异常');
}
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();
//如果是地接类型 绑定地接到订单
if ($demand->bidding_user_type == DemandTraits::$col[2]){
$agentProduct = AgentProduct::find($demand->agent_product_id);
$agentProduct->guide_id = $demandBidding->bidding_user_id;
$agentProduct->guide_price = $demandBidding->price;
$agentProduct->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];
}
}

48
app/AdminGuide/Lazys/DemandBiddingLazys.php

@ -0,0 +1,48 @@
<?php
namespace App\AdminGuide\Lazys;
use App\AdminGuide\Extensions\Grid\ChooseDemand;
use App\AdminGuide\Repositories\DemandBidding;
use App\Models\Demand;
use App\Traits\DemandTraits;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;
use Illuminate\Support\Arr;
class DemandBiddingLazys extends LazyRenderable
{
public function grid(): Grid
{
return Grid::make(new DemandBidding(['biddingUser']), function (Grid $grid) {
$demandId = request('demand_id','');
$demand = Demand::find($demandId);
$grid->model()->where('demand_id',$demandId);
$grid->column('id');
$grid->column('price','出价')->sortable();
$grid->column('comment','内容');
$grid->column('biddingUser.name','竞拍人');
$grid->column('bidding','竞标')
->if(function () use ($demand){
return $demand->state == 1;
})
->then(function (Grid\Column $column) {
$column->append(new ChooseDemand($this->id));
})
->if(function () use ($demand){
return $demand->state == 2;
})
->then(function (Grid\Column $column) use ($demand){
if ($demand->bidding_id == $this->id) {
$column->append('<span class="text-success">已中标</span>');
} else {
$column->append('<span class="text-danger">未中标</span>');
}
});
$grid->column('created_at');
$grid->disableActions();
$grid->disableRowSelector();
});
}
}

16
app/AdminGuide/Repositories/Workorder.php

@ -0,0 +1,16 @@
<?php
namespace App\AdminGuide\Repositories;
use App\Models\Workorder as Model;
use Dcat\Admin\Repositories\EloquentRepository;
class Workorder extends EloquentRepository
{
/**
* Model.
*
* @var string
*/
protected $eloquentClass = Model::class;
}

22
app/AdminSupplier/Controllers/DemandController.php

@ -64,23 +64,33 @@ class DemandController extends AdminController
return DemandBiddingLazys::make(['demand_id' => $this->id]); return DemandBiddingLazys::make(['demand_id' => $this->id]);
}); });
}else{ }else{
$grid->column('bidding', '竞标')
$grid->column('bidding','竞标')
->if(function () { ->if(function () {
// $isBidding 表示参加过竞标后不再显示
$isBidding = DemandBidding::query() $isBidding = DemandBidding::query()
->where('demand_id',$this->id) ->where('demand_id',$this->id)
->where([ ->where([
'bidding_user_type' => DemandTraits::$col[1], 'bidding_user_type' => DemandTraits::$col[1],
'bidding_user_id' => Admin::user()->id 'bidding_user_id' => Admin::user()->id
]) ])
->doesntExist();
->exists();
return $this->state == 1 && $this->bidding_user_type == DemandTraits::$col[1] && $isBidding; return $this->state == 1 && $this->bidding_user_type == DemandTraits::$col[1] && $isBidding;
}) })
->then(function (Grid\Column $column) { ->then(function (Grid\Column $column) {
$column->append('<a class="btn btn-sm btn-primary" href="' . admin_url('/demand_bidding/create?demand_id=' . $this->id) . '">发起竞标</a>');
$column->display('已竞标');
})
->if(function (){
$isNotBidding = DemandBidding::query()
->where('demand_id',$this->id)
->where([
'bidding_user_type' => DemandTraits::$col[1],
'bidding_user_id' => Admin::user()->id
])
->doesntExist();
return $this->state == 1 && $this->bidding_user_type == DemandTraits::$col[1] && $isNotBidding;
}) })
->else()
->display('');
->then(function (Grid\Column $column) {
$column->append('<a class="btn btn-sm btn-primary" href="'.admin_url('/demand_bidding/create?demand_id='.$this->id).'">参与竞标</a>');
});
} }
$grid->column('created_at')->sortable(); $grid->column('created_at')->sortable();

2
app/AdminSupplier/Extensions/Grid/ChooseDemand.php

@ -1,6 +1,6 @@
<?php <?php
namespace App\AdminAgent\Extensions\Grid;
namespace App\AdminSupplier\Extensions\Grid;
use App\Models\AgentProduct; use App\Models\AgentProduct;
use App\Models\DemandBidding; use App\Models\DemandBidding;

2
app/Traits/DemandTraits.php

@ -25,7 +25,7 @@ trait DemandTraits
public static $state = [ public static $state = [
1 => '竞标中' , 1 => '竞标中' ,
2 => '已标' ,
2 => '已标' ,
3 => '流拍' 3 => '流拍'
]; ];

Loading…
Cancel
Save