ibrand_multi_groupon拼团表
CREATE TABLE `ibrand_multi_groupon` ( `id` int(10) NOT NULL AUTO_INCREMENT, `title` varchar(191) DEFAULT NULL COMMENT '拼团名称', `goods_id` int(10) DEFAULT NULL, `nums` int(10) DEFAULT NULL COMMENT '拼团人数', `price` decimal(10,2) DEFAULT NULL COMMENT '价格', `sort` bigint(4) DEFAULT NULL COMMENT '排序', `status` tinyint(4) DEFAULT '1' COMMENT '状态', `starts_at` datetime DEFAULT NULL COMMENT '开始时间', `ends_at` datetime DEFAULT NULL COMMENT '结束时间', `created_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `deleted_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4;商品表
CREATE TABLE `goods_db` ( `id` int(10) NOT NULL AUTO_INCREMENT, `goods_no` varchar(32) NOT NULL, `goods_name` varchar(100) DEFAULT NULL, `category_id` bigint(4) DEFAULT NULL, `sell_price` decimal(10,2) DEFAULT NULL, `img` varchar(100) DEFAULT NULL, `created_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, `deleted_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4;创建对应模型层
php artisan make:model ....创建admin控制器
php artisan admin:make Controller --model=App\Useradmin规格选择器 admin 数仓
php artisan make:provider RiakServiceProvider数仓绑定 [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-tHde3YAQ-1599135064387)(https://cdn.learnku.com/uploads/images/202009/03/58026/15USyiWTa0.png!large)]
public function register() { $this->app->bind( AsdInterfaces::class, AsdRepository::class ); }Repository文件夹 Interfaces Repositories Interfaces内的接口 [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-6bysUF4m-1599135064389)(https://cdn.learnku.com/uploads/images/202009/03/58026/3F7eYARppm.png!large)]
<?php namespace App\Repository\Interfaces; interface AsdInterfaces { public function Asdf($num); }Repositories 接口实现方法 [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-78Yih0nk-1599135064391)(https://cdn.learnku.com/uploads/images/202009/03/58026/b7YUn5ly9q.png!large)]
<?php namespace App\Repository\Repositories; use App\IbrandMultiGroupon; use App\Repository\Interfaces\AsdInterfaces; class AsdRepository implements AsdInterfaces { public function Asdf($num) {/* '0'=> '所有活动', 1=> '未开始', 2=>'进行中', 3=>'已结束', 4=>'已失效',*/ $times=date("Y-m-d H:i:s");//获取当前时间 if ($num==1){//未开始 $ids=IbrandMultiGroupon::where('starts_at','>',$times) ->where('status','=',1) ->get()->pluck('id'); return $ids; }elseif ($num==0){//所有活动 $ids=IbrandMultiGroupon::get()->pluck('id'); return $ids; }elseif ($num==2){//正在进行的 $ids=IbrandMultiGroupon::where('starts_at','<',$times) ->where('status','=',1) ->where('ends_at','>',$times) ->get()->pluck('id'); // dd(132); return $ids; }elseif ($num==3){//结束的 $ids=IbrandMultiGroupon::where('ends_at','<',$times) ->where('status','=',1) ->get()->pluck('id'); // dd(132); return $ids; }else{//失效的 $ids=IbrandMultiGroupon::where('status','=',0) ->get()->pluck('id'); // dd(132); return $ids; } } }团购控制器
<?php namespace App\Admin\Controllers; use App\DbGoods; use App\IbrandMultiGroupon; use App\Repository\Interfaces\AsdInterfaces; use Encore\Admin\Controllers\AdminController; use Encore\Admin\Form; use Encore\Admin\Grid; use Encore\Admin\Show; class IbrandMultiGrouponController extends AdminController { /** * Title for current resource. * * @var string */ protected $title = 'IbrandMultiGroupon'; /** * Make a grid builder. * * @return Grid */ protected $asd; public function __construct(AsdInterfaces $asdf) { $this->asd = $asdf; } protected function grid() { $grid = new Grid(new IbrandMultiGroupon()); $a = 1; $grid->selector(function (Grid\Tools\Selector $selector) { $selector->select('status', '拼团状态', [ '0' => '所有活动', 1 => '未开始', 2 => '进行中', 3 => '已结束', 4 => '已失效', ], function ($query, $value) { $num = $value[0]; $a = $this->asd->Asdf($num); //dd($value[0]); $query->wherein('id', $a); } ); }); $grid->column('id', __('Id')); $grid->column('title', __('标题')); $grid->column('goods_id', __('商品编号')); $grid->column('nums', __('拼团人数')); $grid->column('price', __('拼团价格')); $grid->column('sort', __('排序')); $grid->column('status', __('状态'))->editable('select',[ 0 => '下架', 1 => '上架', ]); $grid->column('starts_at', __('开始时间')); $grid->column('ends_at', __('结束时间')); $grid->column('created_at', __('Created at')); $grid->column('updated_at', __('Updated at')); $grid->column('deleted_at', __('Deleted at')); return $grid; } /** * Make a show builder. * * @param mixed $id * @return Show */ protected function detail($id) { $show = new Show(IbrandMultiGroupon::findOrFail($id)); $show->field('id', __('Id')); $show->field('title', __('Title')); $show->field('goods_id', __('商品编号')); $show->field('nums', __('拼团人数')); $show->field('price', __('拼团价格')); $show->field('sort', __('排序')); $show->field('status', __('状态')); $show->field('starts_at', __('开始时间')); $show->field('ends_at', __('结束时间')); $show->field('created_at', __('Created at')); $show->field('updated_at', __('Updated at')); $show->field('deleted_at', __('Deleted at')); return $show; } /** * Make a form builder. * * @return Form */ protected function form() { $form = new Form(new IbrandMultiGroupon()); $form->text('title', __('Title')); // $form->number('goods_id', __('商品编号')); // dd(DbGoods::get()->pluck('goods_name','id')); $form->radio('goods_id')->options(DbGoods::get()->pluck('goods_name', 'id'))->stacked(); $form->number('nums', __('拼团人数')); $form->decimal('price', __('拼团价格')); $form->number('sort', __('排序')); $form->select('status', __('状态'))->options([ 0 => '下架', 1 => '上架', ])->default(1); $form->datetime('starts_at', __('开始时间'));//->default(date('Y-m-d H:i:s')) $form->datetime('ends_at', __('结束时间')); return $form; } }回收站软删除 请点击
控制器 $grid->filter(function ($filter) { // 范围过滤器,调用模型的`onlyTrashed`方法,查询出被软删除的数据。 $filter->scope('trashed', '回收站')->onlyTrashed(); });回收站
模型层 use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; class IbrandMultiGroupon extends Model { protected $table = 'ibrand_multi_groupon'; use SoftDeletes; }