* @date 2017/03/27 14:43 */ class GoodsBrand extends BasicAdmin { /** * 定义当前操作表名 * @var string */ public $table = 'StoreGoodsBrand'; /** * 品牌列表 * @return array|string * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function index() { $this->title = '品牌管理'; $get = $this->request->get(); $db = Db::name($this->table)->where(['is_deleted' => '0']); if (isset($get['brand_title']) && $get['brand_title'] !== '') { $db->whereLike('brand_title', "%{$get['brand_title']}%"); } if (isset($get['create_at']) && $get['create_at'] !== '') { list($start, $end) = explode(' - ', $get['create_at']); $db->whereBetween('create_at', ["{$start} 00:00:00", "{$end} 23:59:59"]); } return parent::_list($db->order('sort asc,id desc')); } /** * 添加品牌 * @return array|string * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\Exception */ public function add() { $this->title = '添加品牌'; return $this->_form($this->table, 'form'); } /** * 编辑品牌 * @return array|string * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\Exception */ public function edit() { $this->title = '编辑品牌'; return $this->_form($this->table, 'form'); } /** * 表单提交数据处理 * @param array $data */ protected function _form_filter($data) { if ($this->request->isPost()) { empty($data['brand_logo']) && $this->error('请上传品牌Logo图片'); empty($data['brand_cover']) && $this->error('请上传品牌封面图片'); } } /** * 添加成功回跳处理 * @param bool $result */ protected function _form_result($result) { if ($result !== false) { list($base, $spm, $url) = [url('@admin'), $this->request->get('spm'), url('store/goods_brand/index')]; $this->success('数据保存成功!', "{$base}#{$url}?spm={$spm}"); } } /** * 删除品牌 * @throws \think\Exception * @throws \think\exception\PDOException */ public function del() { if (DataService::update($this->table)) { $this->success("品牌删除成功!", ''); } $this->error("品牌删除失败,请稍候再试!"); } /** * 品牌禁用 * @throws \think\Exception * @throws \think\exception\PDOException */ public function forbid() { if (DataService::update($this->table)) { $this->success("品牌禁用成功!", ''); } $this->error("品牌禁用失败,请稍候再试!"); } /** * 品牌签禁用 * @throws \think\Exception * @throws \think\exception\PDOException */ public function resume() { if (DataService::update($this->table)) { $this->success("品牌启用成功!", ''); } $this->error("品牌启用失败,请稍候再试!"); } }