19 changed files with 862 additions and 168 deletions
-
87app/AdminAgent/Actions/Grid/DemandConfirm.php
-
5app/AdminAgent/Controllers/AgentProductController.php
-
17app/AdminAgent/Controllers/DemandBiddingController.php
-
63app/AdminAgent/Controllers/DemandController.php
-
132app/AdminAgent/Controllers/MyDemandController.php
-
2app/AdminAgent/Renderable/SelectProduct.php
-
1app/AdminAgent/routes.php
-
171app/AdminSupplier/Controllers/DemandBiddingController.php
-
224app/AdminSupplier/Controllers/DemandController.php
-
139app/AdminSupplier/Controllers/DemandProductController.php
-
48app/AdminSupplier/Renderable/SelectProduct.php
-
16app/AdminSupplier/Repositories/Demand.php
-
16app/AdminSupplier/Repositories/DemandBidding.php
-
16app/AdminSupplier/Repositories/DemandProduct.php
-
7app/AdminSupplier/routes.php
-
5app/Models/DemandBidding.php
-
52app/Models/DemandProduct.php
-
6app/Traits/DemandTraits.php
-
23resources/lang/zh_CN/demand-product.php
@ -0,0 +1,87 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\AdminAgent\Actions\Grid; |
||||
|
|
||||
|
use Dcat\Admin\Actions\Response; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Dcat\Admin\Grid\Tools\AbstractTool; |
||||
|
use Dcat\Admin\Traits\HasPermissions; |
||||
|
use Illuminate\Contracts\Auth\Authenticatable; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
class DemandConfirm extends RowAction |
||||
|
{ |
||||
|
protected $model; |
||||
|
|
||||
|
public function __construct(string $model = null) |
||||
|
{ |
||||
|
$this->model = $model; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 标题 |
||||
|
* |
||||
|
* @return string |
||||
|
*/ |
||||
|
public function title() |
||||
|
{ |
||||
|
return 'Copy'; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 设置确认弹窗信息,如果返回空值,则不会弹出弹窗 |
||||
|
* |
||||
|
* 允许返回字符串或数组类型 |
||||
|
* |
||||
|
* @return array|string|void |
||||
|
*/ |
||||
|
public function confirm() |
||||
|
{ |
||||
|
return [ |
||||
|
// 确认弹窗 title
|
||||
|
"您确定要复制这行数据吗?", |
||||
|
// 确认弹窗 content
|
||||
|
$this->row->username, |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 处理请求 |
||||
|
* |
||||
|
* @param Request $request |
||||
|
* |
||||
|
* @return \Dcat\Admin\Actions\Response |
||||
|
*/ |
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
// 获取当前行ID
|
||||
|
$id = $this->getKey(); |
||||
|
|
||||
|
// 获取 parameters 方法传递的参数
|
||||
|
$username = $request->get('username'); |
||||
|
$model = $request->get('model'); |
||||
|
|
||||
|
// 复制数据
|
||||
|
$model::find($id)->replicate()->save(); |
||||
|
|
||||
|
// 返回响应结果并刷新页面
|
||||
|
return $this->response()->success("复制成功: [{$username}]")->refresh(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 设置要POST到接口的数据 |
||||
|
* |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function parameters() |
||||
|
{ |
||||
|
return [ |
||||
|
// 发送当前行 username 字段数据到接口
|
||||
|
'username' => $this->row->username, |
||||
|
// 把模型类名传递到接口
|
||||
|
'model' => $this->model, |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -1,132 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace App\AdminAgent\Controllers; |
|
||||
|
|
||||
use App\AdminAgent\Lazys\DemandBiddingLazys; |
|
||||
use App\AdminAgent\Repositories\Demand; |
|
||||
use App\Models\DemandBidding; |
|
||||
use Dcat\Admin\Admin; |
|
||||
use Dcat\Admin\Form; |
|
||||
use Dcat\Admin\Grid; |
|
||||
use Dcat\Admin\Show; |
|
||||
use Dcat\Admin\Http\Controllers\AdminController; |
|
||||
use App\Traits\DemandTraits; |
|
||||
use Illuminate\Support\Arr; |
|
||||
|
|
||||
class MyDemandController extends AdminController |
|
||||
{ |
|
||||
/** |
|
||||
* Make a grid builder. |
|
||||
* |
|
||||
* @return Grid |
|
||||
*/ |
|
||||
protected function grid() |
|
||||
{ |
|
||||
return Grid::make(new Demand(['publisher','biddingUser']), function (Grid $grid) { |
|
||||
$grid->model()->where(['publisher_id' => Admin::user()->id,'publisher_type' => Arr::first(DemandTraits::$col)]); |
|
||||
$grid->column('id')->sortable(); |
|
||||
$grid->column('title'); |
|
||||
$grid->column('detail','内容')->display('查看')->modal('详情',function ($modal) { |
|
||||
$modal->xl(); |
|
||||
return $this->comment; |
|
||||
}); |
|
||||
$grid->column('images','图片')->display(function ($image) { |
|
||||
return json_decode($image,true); |
|
||||
})->image(); |
|
||||
$grid->column('deadline'); |
|
||||
$grid->column('biddingUser.name','中标人'); |
|
||||
$grid->column('bidding_user_type','竞标用户类型')->using(DemandTraits::$polymorphic); |
|
||||
$grid->column('price'); |
|
||||
$grid->column('stock'); |
|
||||
$grid->column('state')->using(DemandTraits::$state)->dot( |
|
||||
[ |
|
||||
1 => 'yellow', |
|
||||
2 => 'success', |
|
||||
3 => 'danger', |
|
||||
] |
|
||||
); |
|
||||
|
|
||||
$grid->column('bidding','竞标明细') |
|
||||
->display(function (){ |
|
||||
return '竞标数 : '. DemandBidding::query()->where('demand_id',$this->id)->count(); |
|
||||
}) |
|
||||
->modal('竞标明细',function () { |
|
||||
return DemandBiddingLazys::make(['demand_id' => $this->id]); |
|
||||
}); |
|
||||
|
|
||||
$grid->column('created_at')->sortable(); |
|
||||
$grid->disableDeleteButton(); |
|
||||
$grid->disableEditButton(); |
|
||||
$grid->disableQuickEditButton(); |
|
||||
$grid->disableViewButton(); |
|
||||
$grid->disableActions(); |
|
||||
$grid->filter(function (Grid\Filter $filter) { |
|
||||
$filter->equal('id'); |
|
||||
$filter->equal('bidding_user_type','竞标用户类型')->select(DemandTraits::$polymorphic); |
|
||||
}); |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Make a show builder. |
|
||||
* |
|
||||
* @param mixed $id |
|
||||
* |
|
||||
* @return Show |
|
||||
*/ |
|
||||
protected function detail($id) |
|
||||
{ |
|
||||
return Show::make($id, new Demand(['publisher','biddingUser']), function (Show $show) { |
|
||||
$show->field('id'); |
|
||||
$show->field('title'); |
|
||||
$show->field('comment'); |
|
||||
$show->field('images')->image(); |
|
||||
$show->field('deadline'); |
|
||||
$show->field('bidding_user_type','竞标用户类型')->using(DemandTraits::$polymorphic); |
|
||||
$show->field('price'); |
|
||||
$show->field('stock'); |
|
||||
$show->field('state')->using(DemandTraits::$state)->dot( |
|
||||
[ |
|
||||
1 => 'yellow', |
|
||||
2 => 'danger', |
|
||||
3 => 'success', |
|
||||
] |
|
||||
);; |
|
||||
$show->field('created_at'); |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* Make a form builder. |
|
||||
* |
|
||||
* @return Form |
|
||||
*/ |
|
||||
protected function form() |
|
||||
{ |
|
||||
return Form::make(new Demand(), function (Form $form) { |
|
||||
$form->display('id'); |
|
||||
$form->text('title'); |
|
||||
$form->text('comment'); |
|
||||
$form->multipleImage('images','图片'); |
|
||||
$form->hidden('deadline'); |
|
||||
$form->select('bidding_user_type','竞标用户类型')->options([ |
|
||||
'App\models\Supplier' => '供应商', |
|
||||
'App\models\Guides' => '地接' |
|
||||
]); |
|
||||
$form->decimal('price'); |
|
||||
$form->number('stock'); |
|
||||
$form->hidden('publisher_type'); |
|
||||
$form->hidden('publisher_id'); |
|
||||
$form->saving(function (Form $form) { |
|
||||
// 判断是否是新增操作
|
|
||||
if ($form->isCreating()) { |
|
||||
//处理流拍时间
|
|
||||
$form->deadline = now()->addDays(5); |
|
||||
//发布人身份
|
|
||||
$form->publisher_type = 'App\models\Agent'; |
|
||||
$form->publisher_id = Admin::user()->id; |
|
||||
} |
|
||||
}); |
|
||||
}); |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,171 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\AdminSupplier\Controllers; |
||||
|
|
||||
|
use App\AdminSupplier\Renderable\SelectProduct; |
||||
|
use App\AdminSupplier\Repositories\DemandBidding; |
||||
|
use App\Models\AgentProduct; |
||||
|
use App\Models\AgentProductItem; |
||||
|
use App\Models\Demand; |
||||
|
use App\Models\DemandProduct; |
||||
|
use App\Models\Product; |
||||
|
use App\Traits\DemandTraits; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Http\Controllers\AdminController; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Support\Arr; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
use Illuminate\Support\Facades\Log; |
||||
|
|
||||
|
class DemandBiddingController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new DemandBidding(['demand']), function (Grid $grid) { |
||||
|
$grid->model()->where(['bidding_user_id' => Admin::user()->id,'bidding_user_type' => DemandTraits::$col[1]]); |
||||
|
$grid->column('id')->sortable(); |
||||
|
$grid->column('price'); |
||||
|
$grid->column('comment'); |
||||
|
$grid->column('demand.title','竞拍标题'); |
||||
|
$grid->column('demand.comment','竞拍内容'); |
||||
|
$grid->column('state','状态')->using(DemandTraits::$biddingState)->dot( |
||||
|
[ |
||||
|
'yellow', |
||||
|
'success', |
||||
|
'danger', |
||||
|
] |
||||
|
); |
||||
|
$grid->column('bidding','操作') |
||||
|
->if(function (){ |
||||
|
return $this->state == 1 && $this->bidding_user_type == DemandTraits::$col[1] && empty($this->demand->demand_product_id); |
||||
|
}) |
||||
|
->then(function (Grid\Column $column) { |
||||
|
$column->append('<a class="btn btn-sm btn-success" href="'.admin_url('/demand_bidding/'.$this->id.'/edit?is_bidding=true').'">绑定产品</a>'); |
||||
|
}) |
||||
|
->if(function (){ |
||||
|
return $this->state == 1 && $this->bidding_user_type == DemandTraits::$col[1] && !empty($this->demand->demand_product_id); |
||||
|
}) |
||||
|
->then(function (Grid\Column $column) { |
||||
|
$column->append('<a class="btn btn-sm btn-primary" href="'.admin_url('/demand_product/'.$this->demand->demand_product_id).'">查看产品</a>'); |
||||
|
}); |
||||
|
$grid->column('created_at'); |
||||
|
$grid->column('updated_at')->sortable(); |
||||
|
$grid->disableDeleteButton(); |
||||
|
$grid->disableEditButton(); |
||||
|
$grid->disableQuickEditButton(); |
||||
|
$grid->disableViewButton(); |
||||
|
$grid->disableCreateButton(); |
||||
|
$grid->disableActions(); |
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->equal('id'); |
||||
|
|
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new DemandBidding(), function (Show $show) { |
||||
|
$show->field('id'); |
||||
|
$show->field('price'); |
||||
|
$show->field('comment'); |
||||
|
$show->field('created_at'); |
||||
|
$show->field('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new DemandBidding(), function (Form $form) { |
||||
|
$form->disableEditingCheck(); |
||||
|
$form->disableCreatingCheck(); |
||||
|
$form->disableDeleteButton(); |
||||
|
$form->disableViewButton(); |
||||
|
$form->disableViewCheck(); |
||||
|
$form->display('id')->disable(); |
||||
|
if(request('is_bidding',0)) { |
||||
|
$form->textarea('comment')->disable(); |
||||
|
$form->selectTable('demand_product_id', '产品') |
||||
|
->title('选择产品') |
||||
|
->dialogWidth('50%;min-width:600px;') //不起作用
|
||||
|
->from(SelectProduct::make()) |
||||
|
->model(DemandProduct::class, 'id', 'title'); |
||||
|
}else{ |
||||
|
$form->text('price'); |
||||
|
$form->textarea('comment'); |
||||
|
} |
||||
|
$form->hidden('demand_id')->value(request('demand_id',0)); |
||||
|
$form->hidden('bidding_user_type')->disable(); |
||||
|
$form->hidden('bidding_user_id')->disable(); |
||||
|
$form->saving(function (Form $form) { |
||||
|
$form->deleteInput('demand_product_id'); |
||||
|
//发布人身份
|
||||
|
$form->bidding_user_type = DemandTraits::$col[1]; |
||||
|
$form->bidding_user_id = Admin::user()->id; |
||||
|
}); |
||||
|
|
||||
|
$form->saved(function (Form $form) { |
||||
|
if($form->isEditing()) { |
||||
|
$productId = request('demand_product_id', 0); |
||||
|
if (!empty($productId)) { |
||||
|
DB::beginTransaction(); |
||||
|
try { |
||||
|
//处理订单
|
||||
|
//将产品绑给代理商
|
||||
|
$demand = Demand::find($form->model()->demand_id); |
||||
|
$demand->demand_product_id = $productId; |
||||
|
$demand->save(); |
||||
|
|
||||
|
$demandProduct = DemandProduct::find($productId); |
||||
|
$product = new Product(); |
||||
|
|
||||
|
$product->supplier_id = $demandProduct->supplier_id; |
||||
|
$product->category_id = $demandProduct->category_id; |
||||
|
$product->title = $demandProduct->title; |
||||
|
$product->price = $form->model()->price; |
||||
|
$product->original_price = $demandProduct->original_price; |
||||
|
$product->pictures = $demandProduct->pictures; |
||||
|
$product->stock = $demand->stock; |
||||
|
$product->know = $demandProduct->know; |
||||
|
$product->content = $demandProduct->content; |
||||
|
$product->pictures = $demandProduct->pictures; |
||||
|
$product->agent_id = $form->model()->bidding_user_id; |
||||
|
$product->pictures = $demandProduct->pictures; |
||||
|
$product->save(); |
||||
|
//处理需求
|
||||
|
$demand = Demand::find($form->model()->demand_id); |
||||
|
$demand->demand_product_id = $productId; |
||||
|
$demand->save(); |
||||
|
DB::commit(); |
||||
|
} catch (\Exception $e) { |
||||
|
Log::error('分配订单失败::' . $e->getTraceAsString()); |
||||
|
DB::rollBack(); |
||||
|
return $form->response()->error('分配订单失败,稍后重试或联系管理员!' . $e->getMessage()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
$form->response()->success('操作成功')->redirect('demand_bidding'); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,224 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\AdminSupplier\Controllers; |
||||
|
|
||||
|
use App\AdminAgent\Lazys\DemandBiddingLazys; |
||||
|
use App\Models\AgentProduct; |
||||
|
use App\Models\DemandProduct; |
||||
|
use App\Models\Product; |
||||
|
use App\Traits\ResponseHelper; |
||||
|
use App\AdminAgent\Repositories\Demand; |
||||
|
use App\Models\DemandBidding; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Http\Controllers\AdminController; |
||||
|
use App\Traits\DemandTraits; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
use Illuminate\Http\Request; |
||||
|
use Illuminate\Support\Arr; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
use Illuminate\Support\Facades\Log; |
||||
|
use Illuminate\Support\Facades\URL; |
||||
|
|
||||
|
class DemandController extends AdminController |
||||
|
{ |
||||
|
|
||||
|
use ResponseHelper; |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new Demand(['publisher','biddingUser']), function (Grid $grid) { |
||||
|
if (\request('self',0)) { |
||||
|
$grid->model()->where(['publisher_id' => Admin::user()->id,'publisher_type' => DemandTraits::$col[1]]); |
||||
|
} |
||||
|
$grid->column('id')->sortable(); |
||||
|
$grid->column('title'); |
||||
|
$grid->column('detail','内容')->display('查看')->modal('详情',function ($modal) { |
||||
|
$modal->xl(); |
||||
|
return $this->comment; |
||||
|
}); |
||||
|
$grid->column('images','图片')->display(function ($image) { |
||||
|
return json_decode($image,true); |
||||
|
})->image(); |
||||
|
$grid->column('deadline'); |
||||
|
$grid->column('publisher.name','发布人'); |
||||
|
$grid->column('publisher_type')->using(DemandTraits::$polymorphic); |
||||
|
$grid->column('biddingUser.name','中标人'); |
||||
|
$grid->column('bidding_user_type','竞标用户类型')->using(DemandTraits::$polymorphic); |
||||
|
$grid->column('price'); |
||||
|
$grid->column('stock'); |
||||
|
$grid->column('state')->using(DemandTraits::$state)->dot( |
||||
|
[ |
||||
|
1 => 'yellow', |
||||
|
2 => 'success', |
||||
|
3 => 'danger', |
||||
|
] |
||||
|
); |
||||
|
|
||||
|
if (\request('self',0)) { |
||||
|
$grid->column('bidding','竞标明细') |
||||
|
->display(function (){ |
||||
|
return '竞标数 : '. DemandBidding::query()->where('demand_id',$this->id)->count(); |
||||
|
}) |
||||
|
->modal('竞标明细',function () { |
||||
|
return DemandBiddingLazys::make(['demand_id' => $this->id]); |
||||
|
}); |
||||
|
}else{ |
||||
|
$grid->column('bidding','竞标') |
||||
|
->if(function (){ |
||||
|
return $this->state == 1 && $this->bidding_user_type == DemandTraits::$col[1]; |
||||
|
}) |
||||
|
->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->disableDeleteButton(); |
||||
|
$grid->disableEditButton(); |
||||
|
$grid->disableQuickEditButton(); |
||||
|
$grid->disableViewButton(); |
||||
|
$grid->disableActions(); |
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->equal('id'); |
||||
|
$filter->equal('bidding_user_type','竞标用户类型')->select(DemandTraits::$polymorphic); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new Demand(['publisher','biddingUser']), function (Show $show) { |
||||
|
$show->field('id'); |
||||
|
$show->field('title'); |
||||
|
$show->field('comment'); |
||||
|
$show->field('images')->image(); |
||||
|
$show->field('deadline'); |
||||
|
$show->field('bidding_user_type','竞标用户类型')->using(DemandTraits::$polymorphic); |
||||
|
$show->field('price'); |
||||
|
$show->field('stock'); |
||||
|
$show->field('publisher_type')->using(DemandTraits::$polymorphic); |
||||
|
$show->field('publisher.name','发布人'); |
||||
|
$show->field('state')->using(DemandTraits::$state)->dot( |
||||
|
[ |
||||
|
1 => 'yellow', |
||||
|
2 => 'danger', |
||||
|
3 => 'success', |
||||
|
] |
||||
|
);; |
||||
|
$show->field('created_at'); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new Demand(), function (Form $form) { |
||||
|
$form->disableEditingCheck(); |
||||
|
$form->disableCreatingCheck(); |
||||
|
$form->disableViewCheck(); |
||||
|
$form->display('id'); |
||||
|
$form->text('title'); |
||||
|
$form->text('comment'); |
||||
|
$form->multipleImage('images','图片')->limit(5)->saving(function ($path) { |
||||
|
return json_encode($path); |
||||
|
}); |
||||
|
$form->hidden('deadline'); |
||||
|
$form->select('bidding_user_type','竞标用户类型') |
||||
|
->when([0],function (Form $form){ |
||||
|
$form->select('demand_product_id','产品')->options(function (){ |
||||
|
return DemandProduct::query()->where('supplier_id',Admin::user()->id)->where('agent_id',0)->pluck('title','id'); |
||||
|
}); |
||||
|
}) |
||||
|
->options([ |
||||
|
'代理商' |
||||
|
]) |
||||
|
->default(0); |
||||
|
$form->decimal('price'); |
||||
|
$form->number('stock'); |
||||
|
$form->hidden('publisher_type'); |
||||
|
$form->hidden('publisher_id'); |
||||
|
$form->saving(function (Form $form) { |
||||
|
// 判断是否是新增操作
|
||||
|
if ($form->isCreating()) { |
||||
|
//if ($form->bidding_user_type != 2) {
|
||||
|
// $form->demand_product_id = 0;
|
||||
|
//}
|
||||
|
$form->bidding_user_type = DemandTraits::$col[$form->bidding_user_type]; |
||||
|
//处理流拍时间
|
||||
|
$form->deadline = now()->addDays(5); |
||||
|
//发布人身份
|
||||
|
$form->publisher_type = DemandTraits::$col[1]; |
||||
|
$form->publisher_id = Admin::user()->id; |
||||
|
} |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
public function binding() |
||||
|
{ |
||||
|
$demandBiddingId = request('demand_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 = $demandProduct->original_price; |
||||
|
$product->pictures = $demandProduct->pictures; |
||||
|
$product->stock = $demand->stock; |
||||
|
$product->know = $demandProduct->know; |
||||
|
$product->content = $demandProduct->content; |
||||
|
$product->pictures = $demandProduct->pictures; |
||||
|
$product->agent_id = $demandBidding->bidding_user_id; |
||||
|
$product->pictures = $demandProduct->pictures; |
||||
|
$product->save(); |
||||
|
DB::commit(); |
||||
|
} catch (\Exception $e) { |
||||
|
Log::error('选中竞标失败::'.$e->getTraceAsString()); |
||||
|
DB::rollBack(); |
||||
|
return $this->jsonFail(1001,'选中竞标失败,稍后重试或联系管理员!'.$e->getMessage()); |
||||
|
} |
||||
|
return back(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,139 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\AdminSupplier\Controllers; |
||||
|
|
||||
|
use App\AdminSupplier\Repositories\DemandProduct; |
||||
|
use App\Common\ProductStatus; |
||||
|
use App\Models\AgentProduct; |
||||
|
use App\Models\Category; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Form; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Repositories\EloquentRepository; |
||||
|
use Dcat\Admin\Show; |
||||
|
use Dcat\Admin\Http\Controllers\AdminController; |
||||
|
use Illuminate\Support\Facades\DB; |
||||
|
|
||||
|
class DemandProductController extends AdminController |
||||
|
{ |
||||
|
protected $title = '产品'; |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new DemandProduct(['category:id,name']), function (Grid $grid) { |
||||
|
$grid->model()->where('supplier_id', Admin::user()->id); |
||||
|
|
||||
|
$grid->column('id')->sortable(); |
||||
|
$grid->column('category.name', '产品分类'); |
||||
|
$grid->column('title'); |
||||
|
$grid->column('picture')->image('', 60, 60); |
||||
|
$grid->column('price'); |
||||
|
$grid->column('original_price'); |
||||
|
$grid->column('stock'); |
||||
|
$grid->column('sale'); |
||||
|
$grid->column('status')->using(ProductStatus::array()); |
||||
|
$grid->column('created_at'); |
||||
|
$grid->column('updated_at'); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->equal('id'); |
||||
|
|
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new DemandProduct(), function (Show $show) { |
||||
|
$show->field('id'); |
||||
|
$show->field('supplier_id'); |
||||
|
$show->field('category_id'); |
||||
|
$show->field('title'); |
||||
|
$show->field('price'); |
||||
|
$show->field('original_price'); |
||||
|
$show->field('pictures')->image('', 80, 80); |
||||
|
$show->field('stock'); |
||||
|
$show->field('sale'); |
||||
|
$show->field('status'); |
||||
|
$show->field('know')->unescape()->as(fn($v) => preg_replace('/<script.*?>.*?<\/script>/is', '', $v)); |
||||
|
$show->field('content')->unescape()->as(fn($v) => preg_replace('/<script.*?>.*?<\/script>/is', '', $v)); |
||||
|
$show->field('created_at'); |
||||
|
$show->field('updated_at'); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a form builder. |
||||
|
* |
||||
|
* @return Form |
||||
|
*/ |
||||
|
protected function form() |
||||
|
{ |
||||
|
return Form::make(new DemandProduct(), function (Form $form) { |
||||
|
//不允许编辑非自己数据
|
||||
|
if ($form->isEditing() && $form->model()->supplier_id != Admin::user()->id) { |
||||
|
return $form->response()->error('数据不存在'); |
||||
|
} |
||||
|
|
||||
|
$form->display('id'); |
||||
|
|
||||
|
$options = Category::selectOptions(fn($query) => $query->where('agent_id', 0)); |
||||
|
$form->select('category_id')->options(array_slice($options, 1, null, true))->required(); |
||||
|
$form->text('title')->required(); |
||||
|
$form->text('price')->required(); |
||||
|
$form->text('original_price')->required(); |
||||
|
$form->multipleImage('pictures')->required()->removable(false)->retainable()->uniqueName(); |
||||
|
$form->text('stock')->default(9999)->required(); |
||||
|
$form->editor('know'); |
||||
|
$form->editor('content')->required(); |
||||
|
|
||||
|
if ($form->isEditing()) { |
||||
|
$form->confirm('提示', '编辑产品需要重新审核,同时<span class="btn-danger">下架所有</span>关联的代理商产品,是否继续?'); |
||||
|
} |
||||
|
})->saving(function (Form $form) { |
||||
|
//不允许编辑非自己数据
|
||||
|
if ($form->isEditing() && $form->model()->supplier_id != Admin::user()->id) { |
||||
|
return $form->response()->error('数据不存在'); |
||||
|
} |
||||
|
|
||||
|
//不允许编辑的字段 TODO 忽略字段不起作用
|
||||
|
$form->ignore(['id', 'supplier_id', 'sale', 'status', 'created_at', 'updated_at', 'deleted_at']); |
||||
|
|
||||
|
//null字段转为''
|
||||
|
foreach ($form->input() as $k => $v) { |
||||
|
if (is_null($v)) { |
||||
|
$form->$k = ''; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
//特殊字段处理
|
||||
|
$form->hidden(['status', 'supplier_id']); //表单没有的字段,必须加上这句才能重置值
|
||||
|
$form->status = ProductStatus::UNAUDITED; |
||||
|
$form->supplier_id = Admin::user()->id; |
||||
|
})->saved(function (Form $form, $result) { |
||||
|
//下架代理商产品
|
||||
|
if ($result) { |
||||
|
$id = $form->getKey(); |
||||
|
AgentProduct::where('product_id', $id) |
||||
|
->orWhere(DB::raw('FIND_IN_SET(' . $id . ', product_ids)')) //TODO product_ids字段可能会去掉
|
||||
|
->update(['status' => ProductStatus::SOLD_OUT]); |
||||
|
} |
||||
|
})->deleting(function (Form $form) { |
||||
|
//不允许删除非自己的数据
|
||||
|
if (array_filter($form->model()->toArray(), fn($v) => $v['supplier_id'] != Admin::user()->id)) { |
||||
|
return $form->response()->error('数据不存在'); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,48 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\AdminSupplier\Renderable; |
||||
|
use App\Common\ProductStatus; |
||||
|
use App\AdminAgent\Repositories\Product; |
||||
|
use App\Models\DemandProduct; |
||||
|
use Dcat\Admin\Admin; |
||||
|
use Dcat\Admin\Grid; |
||||
|
use Dcat\Admin\Grid\LazyRenderable; |
||||
|
|
||||
|
/** |
||||
|
* 选择产品 |
||||
|
* Class SelectProduct |
||||
|
* @package App\AdminAgent\Renderable |
||||
|
*/ |
||||
|
class SelectProduct extends LazyRenderable |
||||
|
{ |
||||
|
public function grid(): Grid |
||||
|
{ |
||||
|
// 获取外部传递的参数
|
||||
|
// $id = $this->id;
|
||||
|
Admin::translation('product'); |
||||
|
return Grid::make(new DemandProduct(['supplier:id,name']), function (Grid $grid) { |
||||
|
$grid->disableActions(); |
||||
|
$grid->disableBatchDelete(); |
||||
|
$grid->disableBatchActions(); |
||||
|
|
||||
|
//$grid->model()->where('status', ProductStatus::ON_SALE);
|
||||
|
$grid->model()->where('supplier_id',Admin::user()->id)->where('agent_id',0); |
||||
|
$grid->quickSearch(['title', 'supplier.name'])->placeholder('搜索产品名称、供应商'); |
||||
|
|
||||
|
$grid->column('id'); |
||||
|
$grid->column('supplier.name', '供应商'); |
||||
|
$grid->column('title'); |
||||
|
$grid->column('picture')->image('',60, 60); |
||||
|
$grid->column('sale'); |
||||
|
$grid->column('stock'); |
||||
|
$grid->column('updated_at'); |
||||
|
|
||||
|
$grid->paginate(15); |
||||
|
|
||||
|
$grid->filter(function (Grid\Filter $filter) { |
||||
|
$filter->like('title')->width(4); |
||||
|
$filter->like('supplier.name', '供应商名称')->width(4); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\AdminSupplier\Repositories; |
||||
|
|
||||
|
use App\Models\Demand as Model; |
||||
|
use Dcat\Admin\Repositories\EloquentRepository; |
||||
|
|
||||
|
class Demand extends EloquentRepository |
||||
|
{ |
||||
|
/** |
||||
|
* Model. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $eloquentClass = Model::class; |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\AdminSupplier\Repositories; |
||||
|
|
||||
|
use App\Models\DemandBidding as Model; |
||||
|
use Dcat\Admin\Repositories\EloquentRepository; |
||||
|
|
||||
|
class DemandBidding extends EloquentRepository |
||||
|
{ |
||||
|
/** |
||||
|
* Model. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $eloquentClass = Model::class; |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\AdminSupplier\Repositories; |
||||
|
|
||||
|
use App\Models\DemandProduct as Model; |
||||
|
use Dcat\Admin\Repositories\EloquentRepository; |
||||
|
|
||||
|
class DemandProduct extends EloquentRepository |
||||
|
{ |
||||
|
/** |
||||
|
* Model. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $eloquentClass = Model::class; |
||||
|
} |
||||
@ -0,0 +1,52 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Models; |
||||
|
|
||||
|
use Dcat\Admin\Traits\HasDateTimeFormatter; |
||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
|
use Illuminate\Database\Eloquent\SoftDeletes; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
|
||||
|
class DemandProduct extends Model |
||||
|
{ |
||||
|
use HasDateTimeFormatter; |
||||
|
use SoftDeletes; |
||||
|
|
||||
|
protected $table = 'demand_products'; |
||||
|
use HasFactory, SoftDeletes; |
||||
|
|
||||
|
protected $guarded = ['id']; //不允许编辑的字段
|
||||
|
|
||||
|
// 获取所有产品图片
|
||||
|
public function getPicturesAttribute($value): array |
||||
|
{ |
||||
|
if (is_string($value)) { |
||||
|
$value = $value ? json_decode($value, true) : []; |
||||
|
} |
||||
|
$this->append('picture'); |
||||
|
return $value ?? []; |
||||
|
} |
||||
|
|
||||
|
// 获取第一张产品图片
|
||||
|
public function getPictureAttribute($value): string |
||||
|
{ |
||||
|
return $this->pictures[0] ?? ''; |
||||
|
} |
||||
|
|
||||
|
public function setPicturesAttribute($value) |
||||
|
{ |
||||
|
if (is_array($value)) { |
||||
|
$this->attributes['pictures'] = json_encode(array_filter($value)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public function supplier() |
||||
|
{ |
||||
|
return $this->belongsTo(Supplier::class); |
||||
|
} |
||||
|
|
||||
|
public function category() |
||||
|
{ |
||||
|
return $this->belongsTo(Category::class); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,23 @@ |
|||||
|
<?php |
||||
|
return [ |
||||
|
'labels' => [ |
||||
|
'DemandProduct' => 'DemandProduct', |
||||
|
'demand-product' => 'DemandProduct', |
||||
|
], |
||||
|
'fields' => [ |
||||
|
'agent_id' => '代理商id 竞标特供', |
||||
|
'category_id' => '产品分类ID', |
||||
|
'content' => '产品详情', |
||||
|
'know' => '旅客须知', |
||||
|
'original_price' => '原价', |
||||
|
'pictures' => '产品图片,可能有多张,JSON格式', |
||||
|
'price' => '价格', |
||||
|
'sale' => '销量', |
||||
|
'status' => '0:下架,1:在售', |
||||
|
'stock' => '库存量', |
||||
|
'supplier_id' => '供应商ID', |
||||
|
'title' => '标题', |
||||
|
], |
||||
|
'options' => [ |
||||
|
], |
||||
|
]; |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue