page($page, $limit)->append($append)->order('id desc')->select()->toArray(); $count = ShopAd::where($where)->count(); return [ 'count' => $count, 'lists' => $lists ]; } static function add($params, $shop_id) { if (empty($params['terminal']) || ! isset(ShopAdEnum::getTerminal()[$params['terminal']])) { static::$error = '终端必须选择'; return false; } if (empty($params['image'])) { static::$error = '广告图片必须'; return false; } $params['shop_id'] = $shop_id; ShopAd::create($params, [ 'shop_id', 'title', 'place', 'terminal', 'image', 'sort', 'link', 'status', ]); return true; } static function edit($params, $shop_id) { if (empty($params['terminal']) || ! isset(ShopAdEnum::getTerminal()[$params['terminal']])) { static::$error = '终端必须选择'; return false; } if (empty($params['image'])) { static::$error = '广告图片必须'; return false; } $where = [ [ 'id', '=', $params['id'] ], [ 'shop_id', '=', $shop_id ], ]; ShopAd::update($params, $where, [ 'shop_id', 'title', 'place', 'terminal', 'image', 'sort', 'link', 'status', ]); return true; } static function status($params, $shop_id) { $where = [ [ 'id', '=', $params['id'] ], [ 'shop_id', '=', $shop_id ], ]; ShopAd::update($params, $where, [ 'status' ]); return true; } static function delete($params, $shop_id) { ShopAd::destroy(function ($query) use ($params, $shop_id) { $query->where('shop_id', $shop_id)->where('id', $params['id']); }); return true; } }