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.
209 lines
6.9 KiB
209 lines
6.9 KiB
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Admin\Repositories\ImsCjdcMarket;
|
|
use App\Models\LanzuMmInfo;
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Controllers\AdminController;
|
|
use App\Models\LanzuMpInfo;
|
|
|
|
class ImsCjdcMarketController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
return Grid::make(new ImsCjdcMarket(), function (Grid $grid) {
|
|
$adu = Admin::user();
|
|
if ($adu->isRole('lanzu_mp')){
|
|
$mp = LanzuMpInfo::where('admin_user_id',$adu->id)->first();
|
|
$grid->model()->where('mp_id',$mp->id);
|
|
$grid->disableCreateButton();
|
|
$grid->disableActions();
|
|
}
|
|
$grid->id->sortable();
|
|
$grid->logo->image('', 50, 50);
|
|
$grid->name;
|
|
$grid->column('mp_id', '服务商')->display(function ($mid) {
|
|
if ($mid == 0) return '懒族自营';
|
|
$mp = LanzuMpInfo::find($mid);
|
|
if (!$mp) {
|
|
return '<span style="color: #ff0000">数据错误</span>';
|
|
}
|
|
return $mp->name;
|
|
});
|
|
$grid->column('status', '状态')->filter(
|
|
Grid\Column\Filter\In::make([
|
|
0 => '禁用',
|
|
1 => '正常',
|
|
])
|
|
)->display(function ($status) {
|
|
if ($status == 0) {
|
|
return '禁用';
|
|
} else {
|
|
return '正常';
|
|
}
|
|
});
|
|
$grid->address;
|
|
$grid->column('addtime', '创建时间');
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->equal('id');
|
|
});
|
|
$grid->disableFilterButton();
|
|
$grid->quickSearch(['name'])->placeholder('输入市场名称');
|
|
|
|
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
|
|
|
if (!\Admin::user()->isAdministrator() && $actions->row->mp_id == 0) {
|
|
$actions->disableDelete();
|
|
$actions->disableEdit();
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, new ImsCjdcMarket(), function (Show $show) {
|
|
|
|
if (!\Admin::user()->isAdministrator() && $show->model()->mp_id == 0) {
|
|
$show->panel()
|
|
->tools(function ($tools) {
|
|
$tools->disableEdit();
|
|
$tools->disableList();
|
|
$tools->disableDelete();
|
|
// 显示快捷编辑按钮
|
|
$tools->showQuickEdit();
|
|
});
|
|
}
|
|
|
|
$show->name;
|
|
$show->logo->image();
|
|
$show->introduce;
|
|
$show->imgs->image();
|
|
$show->addtime('创建时间');
|
|
$show->sort;
|
|
$show->status()->using([0=>'禁用',1=>'正常']);
|
|
$show->coordinates;
|
|
$show->remark;
|
|
$show->address;
|
|
$show->poundage;
|
|
$show->dn_poundage;
|
|
$show->dm_poundage;
|
|
$show->yd_poundage;
|
|
$show->loudspeaker_imei;
|
|
$show->dishes_menu_intro;
|
|
$show->create_time->as(function ($time){
|
|
if ($time){
|
|
return date('Y-m-d H:i',$time);
|
|
}else{
|
|
return '-';
|
|
}
|
|
|
|
});
|
|
$show->created_at->as(function ($time){
|
|
if ($time){
|
|
return date('Y-m-d H:i',$time);
|
|
}else{
|
|
return '-';
|
|
}
|
|
|
|
});
|
|
$show->updated_at->as(function ($time){
|
|
if ($time){
|
|
return date('Y-m-d H:i',$time);
|
|
}else{
|
|
return '-';
|
|
}
|
|
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new ImsCjdcMarket(), function (Form $form) {
|
|
$form->display('id');
|
|
$form->text('name')->required();
|
|
$form->select('mp_id', '服务商')->options('/api/getMpInfo')->required();
|
|
$form->mobile('tel','电话')->required();
|
|
$form->text('address')->required();
|
|
$form->text('coordinates')
|
|
->required()
|
|
->placeholder('输入 经纬度,如: 108.281552,22.83731')
|
|
->help("通过网址 <a href='https://lbs.amap.com/console/show/picker' target='_blank'>https://lbs.amap.com/console/show/picker</a> 获取经纬度");
|
|
$form->text('poundage');
|
|
$form->text('dn_poundage');
|
|
$form->text('dm_poundage');
|
|
$form->text('yd_poundage');
|
|
$form->text('loudspeaker_imei')->value(0);
|
|
$form->number('sort', '排序');
|
|
$form->switch('status', '状态');
|
|
$form->image('logo');
|
|
$form->multipleImage('imgs', '市场图片');
|
|
$form->textarea('introduce');
|
|
$form->textarea('remark');
|
|
$form->textarea('dishes_menu_intro')->value('菜谱简介');
|
|
|
|
$form->saving(function (Form $form){
|
|
if ($form->isCreating()){
|
|
$coordinates = explode(',',$form->coordinates);
|
|
$form->coordinates = implode(',',[$coordinates[1],$coordinates[0]]);
|
|
$form->addtime = date('Y-m-d H:i:s',time());
|
|
}else{
|
|
if ($form->coordinates&&$form->coordinates!=$form->model()->coordinates){
|
|
$coordinates = explode(',',$form->coordinates);
|
|
$form->coordinates = implode(',',[$coordinates[1],$coordinates[0]]);
|
|
}
|
|
}
|
|
});
|
|
|
|
$form->deleting(function (Form $form){
|
|
//删除市场前,校验该市场下是否存在市场经理
|
|
$mids = array_column($form->model()->toArray(), 'id');
|
|
$count = LanzuMmInfo::whereIn('market_id',$mids)->count();
|
|
if ($count){
|
|
return $form->error('该市场下关联有市场经理, 无法删除');
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 服务商信息
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
protected function getMpInfo()
|
|
{
|
|
$mps = LanzuMpInfo::all();
|
|
$ret = [];
|
|
foreach ($mps as $key => $value) {
|
|
$item = [];
|
|
$item['id'] = $value->id;
|
|
$item['text'] = $value->name;
|
|
$ret[] = $item;
|
|
}
|
|
return response()->json($ret);
|
|
}
|
|
}
|