链街Dcat后台
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.
 
 
 
 

228 lines
8.7 KiB

<?php
namespace App\Admin\Controllers\v3;
use App\Admin\Repositories\v3\Store;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Controllers\AdminController;
use App\Models\LanzuMmInfo as MminfoModel;
use App\Models\v3\Market as MarketModel;
use App\Admin\Common\StoreQRCode;
use App\Models\v3\Store as StoreModel;
use App\Models\v3\User as UserModel;
use App\Models\v3\Category as CategoryModel;
use App\Models\LanzuUserBalance as UserBalanceModel;
class StoreController extends AdminController
{
/**
* Make a grid builder.
*
* @return Grid
*/
protected function grid()
{
return Grid::make(new Store(), function (Grid $grid) {
$grid->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->row(function (Show\Row $show) {
$show->width(6)->id;
$show->width(6)->mm_user_id->as(function ($mmUserId){
$item = MminfoModel::getMmInfo($mmUserId,'name');
return empty($item) ? '' : $item->name;
});
$show->width(6)->market_id->as(function ($marketId){
$item = MarketModel::getMarketInfo($marketId,'name');
return empty($item) ? '' : $item->name;
});
$show->width(6)->category_id->as(function ($categoryId){
$item = CategoryModel::getCategoryInfo($categoryId,'title');
return empty($item) ? '' : $item->title;
});
$show->width(6)->name;
$show->width(6)->logo->image();
$show->width(6)->user_id->as(function ($userId){
$item = UserModel::getUserInfo($userId,'nick_name');
return empty($item) ? '' : $item->nick_name;
});
$show->width(6)->admin_id->as(function ($userId){
$item = UserModel::getUserInfo($userId,'nick_name');
return empty($item) ? '' : $item->nick_name;
});
$show->width(6)->business_license->image();
$show->width(6)->zm_img->image();
$show->width(6)->fm_img->image();
$show->width(6)->tel;
$show->width(6)->link_name;
$show->width(6)->link_tel;
$show->width(6)->time1;
$show->width(6)->time2;
$show->width(6)->time3;
$show->width(6)->time4;
});
$show->row(function (Show\Row $show) {
$show->width(6)->announcement;
$show->width(6)->address;
$show->width(6)->coordinates;
$show->width(6)->is_rest_text;
$show->width(6)->is_open_text;
$show->width(6)->sort;
// $show->width(6)->environment;
$show->width(6)->expire_time;
$show->width(6)->loudspeaker_imei;
});
// $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) use($userList){
$form->image('business_license')->required();
$form->image('zm_img')->required();
$form->image('fm_img')->required();
$form->select('admin_id')->options($userList)->required();/*需要优化 一个用户只能绑定一家店铺*/
$form->select('user_id')->options($userList)->required();/*需要优化 一个用户只能绑定一家店铺*/
$form->timeRange('time1','time2','营业时间段一')->required();
$form->timeRange('time3','time4','营业时间段二')
->rules('after:time2',['after'=>'选择的时间必须比时间段一结束时间大']);
});
$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("通过网址 <a href='https://lbs.amap.com/console/show/picker' target='_blank'>https://lbs.amap.com/console/show/picker</a> 获取经纬度");
$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();
});
}
}