orderBy('sort','desc')->orderBy('status','desc')->orderBy('id','desc'); if ($isAll){ $list = $list->get(); }else{ $list = $list->paginate(getProp($param,'limit',15)); } if (!$list->isEmpty()){ $types = self::getMiniProgramType(); $types = array_column($types,null,'value'); foreach ($list as $value){ $value->miniprogram_type_text = $types[$value->miniprogram_type]['name'] ?? "-"; } } return $list; } public static function getMiniProgramType(){ return [ ['value' => 1,'name' =>"微信小程序"], ['value' => 2,'name' =>"抖音小程序"], ]; } /** * 查询构建 * name: getQuery * @param array $param * date 2023/06/07 14:41 */ private static function getQuerySql(array $param) { $sql = DuanJuBanner::query(); if (getProp($param,'title')){ $sql->where("title","like","%{$param['title']}%"); } return $sql; } /** * 添加轮播图 * name: addBanner * @param array $param * date 2023/06/07 15:53 */ public static function addBanner(array $param) { $res = DuanJuBanner::create($param); if ($res){ return "操作成功"; } self::throwErrMsg("添加失败"); } /** * 更新banner * name: updateBanner * @param $id * @param $param * date 2023/06/08 09:55 */ public static function updateBanner($id, $param) { // 禁用检测 if( $param['status'] != 1){ $type = getProp($param,'miniprogram_type'); if (empty($type)){ $type = DuanJuBanner::where('id',$id)->value('miniprogram_type'); } $other = DuanJuBanner::where('id','<>',$id)->where('miniprogram_type',$type)->where('status',1)->value('id'); if (empty($other)){ self::throwErrMsg("此类型小程序应最少保障一张可用轮播图"); } } $res = DuanJuBanner::where('id',$id)->update($param); if ($res){ return "操作成功"; } self::throwErrMsg("操作失败"); } /* * 删除 */ public static function delBannerById($id) { $info = DuanJuBanner::where('id',$id)->first(); if (is_empty($info)){ return "操作成功"; } $other = DuanJuBanner::where('id','<>',$id)->where('miniprogram_type',$info->miniprogram_type)->where('status',1)->value('id'); if (empty($other)){ self::throwErrMsg("此类型小程序应最少保障一张可用轮播图"); } DuanJuBanner::where('id',$id)->delete(); return "操作成功"; } }