field(true) ->where($where) ->order('sort', 'asc') ->paginate([ 'page' => $get['page'], 'list_rows' => $get['limit'], 'var_page' => 'page' ]) ->toArray(); $cates1 = Db::name("legal_cate")->where(['del'=>0,'is_show'=>1])->select()->toArray(); $cates = array_column($cates1,"name","id"); foreach ($lists['data'] as &$item) { $item['cate_name'] = $cates[$item['cate_id']] ?? "未知"; $item['is_show'] = $item['is_show'] ? '显示' : '隐藏'; $item['address'] = $item['province_id']?AreaServer::getAddress([ $item['province_id'], $item['city_id'], $item['district_id']]):''; } return ['count'=>$lists['total'], 'lists'=>$lists['data']]; } catch (Exception $e) { return ['error'=>$e->getMessage()]; } } /** * @Notes: 文章详细 * @Author: 张无忌 * @param $id * @return array */ public static function detail($id) { $model = new LegalCase(); $data= $model->field(true)->findOrEmpty($id)->toArray(); // $data['address'] = $data['province_id']?AreaServer::getAddress([ // $data['province_id'], // $data['city_id'], // $data['district_id']]):''; $data['images_arr'] = $data['images']? explode(",",$data['images']):[]; return $data; } /** * @Notes: 添加文章 * @Author: 张无忌 * @param $post * @return bool */ public static function add($post) { try { LegalCase::create([ 'title' => $post['title'], 'cate_id' => $post['cate_id'] ?? 0, 'content' => $post['content'] ?? '', 'image' => $post['image'] ?? '', 'images' => $post['images'] ?? '', 'contact' => $post['contact'] ?? '', 'is_show' => $post['is_show'], // 'province_id' => $post['province_id'] ?? 0, // 'city_id' => $post['city_id'] ?? 0, // 'district_id' => $post['district_id'] ?? 0, // 'address_detail' => $post['address_detail'] ?? '', ]); return true; } catch (\Exception $e) { static::$error = $e->getMessage(); return false; } } /** * @Notes: 编辑文章 * @Author: 张无忌 * @param $post * @return bool */ public static function edit($post) { try { LegalCase::update([ 'title' => $post['title'], 'cate_id' => $post['cate_id'] ?? 0, 'content' => $post['content'] ?? '', 'image' => $post['image'] ?? '', 'images' => $post['images'] ?? '', 'contact' => $post['contact'] ?? '', 'is_show' => $post['is_show'], ], ['id'=>$post['id']]); return true; } catch (\Exception $e) { static::$error = $e->getMessage(); return false; } } /** * @Notes: 删除 * @Author: 张无忌 * @param $id * @return bool */ public static function del($id) { try { LegalCase::update([ 'del' => 1, 'update_time' => time() ], ['id'=>$id]); return true; } catch (\Exception $e) { static::$error = $e->getMessage(); return false; } } /** * @Notes: 隐藏 * @Author: 张无忌 * @param $id * @return bool */ public static function hide($id) { try { $model = new LegalCase(); $article = $model->findOrEmpty($id)->toArray(); LegalCase::update([ 'is_show' => !$article['is_show'], 'update_time' => time() ], ['id'=>$id]); return true; } catch (\Exception $e) { static::$error = $e->getMessage(); return false; } } }