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.
210 lines
7.0 KiB
210 lines
7.0 KiB
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Admin\Repositories\ImsCjdcMarket;
|
|
use App\Models\LanzuArea;
|
|
use App\Models\LanzuMmInfo;
|
|
use App\Models\v3\Market;
|
|
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;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class ImsCjdcMarketController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
return Grid::make(new Market(), 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('status')->switch();
|
|
$grid->created_at->display(function ($time){
|
|
return date('Y-m-d H:i:s',$time);
|
|
});
|
|
$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 Market(), 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->remark;
|
|
$show->address;
|
|
$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 Market(), function (Form $form) {
|
|
$form->display('id');
|
|
$form->text('name')->required();
|
|
$form->select('mp_id', '服务商')->options('/api/getMpInfo');
|
|
$form->mobile('tel','电话')->required();
|
|
$form->select('province_id','省')
|
|
->options('/api/area')->required()
|
|
->load('city_id','/api/area');
|
|
$form->select('city_id','市')->required()->load('region_id','/api/area');
|
|
$form->select('region_id','区')->required();
|
|
$form->text('address')->required();
|
|
if ($form->isEditing()){
|
|
$form->text('coordinates')
|
|
->value(implode(',',[$form->model()->lng,$form->model()->lat]))
|
|
->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> 获取经纬度");
|
|
if (!($form->mp_id)){
|
|
$form->mp_id = '0';
|
|
}
|
|
}else{
|
|
$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->number('sort', '排序');
|
|
$form->switch('status', '状态');
|
|
$form->image('logo')->required();
|
|
$form->multipleImage('imgs', '市场图片');
|
|
$form->textarea('remark')->required();
|
|
$form->hidden('lng');
|
|
$form->hidden('lat');
|
|
|
|
$form->saving(function (Form $form){
|
|
if($form->coordinates){
|
|
$coordinates = explode(',',$form->coordinates);
|
|
$form->lng = $coordinates[0];
|
|
$form->lat = $coordinates[1];
|
|
$form->deleteInput('coordinates');
|
|
}
|
|
});
|
|
|
|
$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 = [['id'=>'0','text'=>'懒族自营']];
|
|
foreach ($mps as $key => $value) {
|
|
$item = [];
|
|
$item['id'] = $value->id;
|
|
$item['text'] = $value->name;
|
|
$ret[] = $item;
|
|
}
|
|
return response()->json($ret);
|
|
}
|
|
|
|
|
|
}
|