fetch(); } public function lst(Request $request) { $where = UtilService::getMore([ ['page', 1], ['limit', 10], ['title', ''], ['is_show', ''], ], $request); $data = StoreActivityModel::setWherePage(new StoreActivityModel(), $where, ['is_show'], ['title'])->order('id desc')->where("is_del=0")->page($where['page'], $where['limit'])->select()->toArray(); $count = sizeof($data); return JsonService::successlayui(compact('data','count')); } public function create() { $field = [ Form::input('title', '活动名称'), Form::input('price_color', '价格颜色(比如:33aaff)'), Form::radio('is_new', '新人专享', 1)->options([['label' => '是', 'value' => 1], ['label' => '否', 'value' => 0]]), Form::frameImageOne('main_img', '活动主图', Url::buildUrl('admin/widget.images/index', array('fodder' => 'main_img')))->icon('image')->width('100%')->height('500px'), Form::frameImageOne('label_img', '商品标签图', Url::buildUrl('admin/widget.images/index', array('fodder' => 'label_img')))->icon('image')->width('100%')->height('500px'), Form::frameImageOne('border_img', '商品边框图', Url::buildUrl('admin/widget.images/index', array('fodder' => 'border_img')))->icon('image')->width('100%')->height('500px'), Form::radio('is_show', '启用', 1)->options([['label' => '是', 'value' => 1], ['label' => '否', 'value' => 0]]) ]; $form = Form::make_post_form('添加活动', $field, Url::buildUrl('save'), 2); $this->assign(compact('form')); return $this->fetch('public/form-builder'); } public function save(Request $request) { $data = UtilService::postMore([ 'title', 'price_color', 'is_new', 'is_show', 'price_color', ['main_img', []], ['label_img', []], ['border_img', []], ], $request); if (!$data['title']) return JsonService::fail('请输入活动名称'); if (!$data['price_color']) return JsonService::fail('请输入价格颜色'); if ($data['main_img'][0] == "") return JsonService::fail('请上传活动主图'); if ($data['label_img'][0] == "") return JsonService::fail('请上传商品标签图'); if ($data['border_img'][0] == "") return JsonService::fail('请上传商品边框图'); $data['main_img'] = $data['main_img'][0]; $data['label_img'] = $data['label_img'][0]; $data['border_img'] = $data['border_img'][0]; $data['add_time'] = time(); StoreActivityModel::create($data); return JsonService::successful('添加活动成功!'); } public function edit($id) { $c = StoreActivityModel::get($id); if (!$c) return JsonService::fail('数据不存在!'); $field = [ Form::input('title', '活动名称', $c['title']), Form::input('price_color', '价格颜色(比如:33aaff)', $c['price_color']), Form::radio('is_new', '新人专享', $c['is_new'])->options([['label' => '是', 'value' => 1], ['label' => '否', 'value' => 0]]), Form::frameImageOne('main_img', '活动主图', Url::buildUrl('admin/widget.images/index', array('fodder' => 'main_img')), $c['main_img'])->icon('image')->width('100%')->height('500px'), Form::frameImageOne('label_img', '商品标签图', Url::buildUrl('admin/widget.images/index', array('fodder' => 'label_img')), $c['label_img'])->icon('image')->width('100%')->height('500px'), Form::frameImageOne('border_img', '商品边框图', Url::buildUrl('admin/widget.images/index', array('fodder' => 'border_img')), $c['border_img'])->icon('image')->width('100%')->height('500px'), Form::radio('is_show', '启用', $c['is_show'])->options([['label' => '是', 'value' => 1], ['label' => '否', 'value' => 0]]) ]; $form = Form::make_post_form('添加活动', $field, Url::buildUrl('update', array('id' => $id)), 2); $this->assign(compact('form')); return $this->fetch('public/form-builder'); } public function update(Request $request, $id) { $data = UtilService::postMore([ 'title', 'price_color', 'is_new', 'is_show', 'price_color', ['main_img', []], ['label_img', []], ['border_img', []], ], $request); if (!$data['title']) return JsonService::fail('请输入活动名称'); if (!$data['price_color']) return JsonService::fail('请输入价格颜色'); if ($data['main_img'][0] == "") return JsonService::fail('请上传活动主图'); if ($data['label_img'][0] == "") return JsonService::fail('请上传商品标签图'); if ($data['border_img'][0] == "") return JsonService::fail('请上传商品边框图'); $data['main_img'] = $data['main_img'][0]; $data['label_img'] = $data['label_img'][0]; $data['border_img'] = $data['border_img'][0]; $data['add_time'] = time(); StoreActivityModel::edit($data, $id); return JsonService::successful('修改活动成功!'); } public function del(Request $request, $id) { //todo 判断活动下面是否有商品 if (StoreActivityProductModel::be(['aid' => $id, 'is_del=0'])) { return JsonService::fail("删除失败,活动下面还有商品"); } StoreActivityModel::update([ 'id' => $id, 'is_del' => 1 ]); return JsonService::success("删除成功"); } public function set_show(Request $request) { $param = UtilService::getMore([ 'id', 'is_show' ], $request); StoreActivityModel::update([ 'id' => $param['id'], 'is_show' => $param['is_show'] ]); if (!$param['is_show']) { // 活动停用后,下面的所有商品都要设置为停用 StoreActivityProductModel::where("aid={$param['id']}")->update([ 'is_show' => 0, ]); } JsonService::success("修改成功"); } public function set_new(Request $request) { $param = UtilService::getMore([ 'id', 'is_new' ], $request); StoreActivityModel::update([ 'id' => $param['id'], 'is_new' => $param['is_new'] ]); JsonService::success("修改成功"); } }