model()->orderBy('id','desc'); $grid->id->sortable(); $grid->logo_url->image('',50); $grid->name; $grid->market_id->display(function ($marketId){ $market = MarketModel::getMarketInfo($marketId,'name'); return empty($market) ? '' : $market->name; }); $grid->mm_user_id->display(function ($mmUserId){ $mmUser = MminfoModel::getMmInfo($mmUserId,'name'); return empty($mmUser) ? '' : $mmUser->name; }); $grid->store_applet_img->image('',50); $grid->cash_code_img->image('',50); $grid->sort->sortable(); $grid->is_rest->switch(); $grid->is_open->switch(); // 搜索 $grid->filter(function (Grid\Filter $filter) { $filter->equal('id'); }); // 每页10条 $grid->paginate(10); }); } /** * Make a show builder. * * @param mixed $id * * @return Show */ protected function detail($id) { return Show::make($id, new Store(), function (Show $show) { $show->id; $show->mm_user_id; $show->market_id; $show->name; $show->address; $show->tel; $show->announcement; $show->is_rest; $show->logo; $show->details; $show->coordinates; $show->business_license; $show->store_type_id; $show->is_open; $show->sort; $show->user_id; $show->environment; $show->expire_time; $show->zm_img; $show->fm_img; $show->link_name; $show->link_tel; $show->admin_id; $show->loudspeaker_imei; $show->time; $show->time2; $show->time3; $show->time4; $show->created_at; $show->updated_at; }); } /** * Make a form builder. * * @return Form */ protected function form() { return Form::make(new Store(), function (Form $form) { // 查询市场经理 $mmList = MminfoModel::getMmInfoArray(); // 查询市场 $marketList = MarketModel::getMarket(); // 查询一级分类 $categoryList = CategoryModel::getCategoryArray([['parent_id','=',0]]); // 用户 $userList = UserModel::getUserArray(); $form->column(6, function (Form $form) use($mmList,$marketList,$categoryList){ $form->hidden('id'); $form->select('mm_user_id')->options($mmList); $form->select('market_id')->required()->options($marketList); $form->select('category_id')->options($categoryList); $form->text('name')->required()->maxLength(50); $form->image('logo')->required(); $form->mobile('tel'); $form->text('link_name')->required(); $form->mobile('link_tel')->required(); $form->number('sort'); $form->switch('is_rest') ->customFormat(function ($v) { return $v == '休息' ? 1 : 0; }) ->saving(function ($v) { return $v; }); $form->switch('is_open') ->customFormat(function ($v) { return $v == '开启' ? 1 : 0; }) ->saving(function ($v) { return $v; })->default(1); $form->text('address'); }); $form->column(6, function (Form $form) { $form->image('business_license')->required(); $form->image('zm_img')->required(); $form->image('fm_img')->required(); $form->text('admin_id')->required();/*需要优化 一个用户只能绑定一家店铺*/ $form->text('user_id')->required();/*需要优化 一个用户只能绑定一家店铺*/ $form->timeRange('time1','time2','营业时间段一')->required(); $form->timeRange('time3','time4','营业时间段二'); }); $form->column(12, function (Form $form) { $form->map('lat','lng','地址'); $form->textarea('introduction')->required(); $form->textarea('announcement'); $form->multipleImage('environment'); }); // $form->text('coordinates')->width(4) // ->placeholder('输入 经纬度,如: 108.281552,22.83731') // ->help("通过网址 https://lbs.amap.com/console/show/picker 获取经纬度"); $form->saved(function (Form $form){ $id = $form->getKey(); $store = StoreModel::find($id); // 添加商户钱包 $userBalance = UserBalanceModel::where([ ['user_type','=',5], ['source_id','=',$id] ])->first(); if(empty($userBalance)){ $userBalance = new UserBalanceModel(); $userBalance->user_type = 5; $userBalance->source_id = $id; $userBalance->save(); } if($form->isCreating() && !empty($id)){ $qrCode = new StoreQRCode(); // 生成小程序码 店铺 $sRes = $qrCode->SetStoreWeChatCode($id); // 生产小程序码 收银 $pRes = $qrCode->SetPayWeChatCode($id); // 保存图片 $store->store_applet_img = $sRes['status'] ? $sRes['path'] : ''; $store->cash_code_img = $pRes['status'] ? $pRes['path'] : ''; $store->save(); // 剪裁图片 // $form->image('cash_code_img')->crop(270, 270, [5, 5]); } }); $form->disableResetButton(); $form->disableViewCheck(); $form->disableEditingCheck(); $form->disableCreatingCheck(); }); } }