field(true) ->where($where) ->paginate([ 'page' => $get['page'], 'list_rows' => $get['limit'], 'var_page' => 'page' ]) ->toArray(); $cates1 = Db::name("contract_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['start_time_str'] = $item['start_time'] ? date("Y-m-d",$item['start_time']) : '-'; $item['end_time_str'] = $item['end_time'] ? date("Y-m-d",$item['end_time']) : '-'; $item['is_show'] = $item['is_show'] ? '显示' : '隐藏'; } 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 Contract(); $data = $model->field(true)->findOrEmpty($id)->toArray(); return $data; } /** * @Notes: 添加文章 * @Author: 张无忌 * @param $post * @return bool */ public static function add($post) { try { Contract::create([ 'title' => $post['title'], 'partA' => $post['partA'], 'partB' => $post['partB'], 'partC' => $post['partC'], 'cate_id' => $post['cate_id'] ?? 0, 'start_time' => $post['start_time'] ? strtotime($post['start_time']) : 0, 'end_time' => $post['end_time'] ? strtotime($post['start_time']." 23:59:59") : 0, 'term' => $post['term'] ?? 0, 'money' => $post['money'] ?? 0.00, 'path' => $post['path'] , ]); return true; } catch (\Exception $e) { static::$error = $e->getMessage(); return false; } } /** * @Notes: 编辑文章 * @Author: 张无忌 * @param $post * @return bool */ public static function edit($post) { try { Contract::update([ 'title' => $post['title'], 'partA' => $post['partA'], 'partB' => $post['partB'], 'partC' => $post['partC'], 'cate_id' => $post['cate_id'] ?? 0, 'start_time' => $post['start_time'] ? strtotime($post['start_time']) : 0, 'end_time' => $post['end_time'] ? strtotime($post['start_time']." 23:59:59") : 0, 'term' => $post['term'] ?? 0, 'money' => $post['money'] ?? 0.00, 'path' => $post['path'] , ], ['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 { Contract::update([ 'del' => 1, 'update_time' => time() ], ['id'=>$id]); return true; } catch (\Exception $e) { static::$error = $e->getMessage(); return false; } } }