$word] */ public function formatQuery($query = []) { $format_query = [ 'query' => [], ]; foreach ($query as $k => $val) { $format_query['query'] = [$k, $val]; } return $format_query; } /** * 修改字段值 * @param $update * @return \think\response\Json */ public static function editField($update) { $data = self::where('id', $update['id'])->update([$update['field'] => $update['value']]); if ($data == 1) { return __success('修改成功!'); } else { return __error('数据没有修改!'); } } /** * 新增 * @param $post * @return \think\response\Json * @throws \think\exception\PDOException */ public static function addData($post) { try { self::insert($post); } catch (\Exception $e) { return __error($e->getMessage()); } return __success('添加成功'); } /** * 修改 * @param $post * @return \think\response\Json */ public static function editData($post) { try { self::where('id', $post['id'])->update($post); } catch (\Exception $e) { return __error($e->getMessage()); } return __success('修改成功'); } /** * 软删除操作 * @param $id 列ID * @param bool $type 删除类型 (false:软删除,true:真实删除) * @return bool|ModelService * @throws \Exception */ public function delData($id, $type = false) { is_array($id) ? $model = self::whereIn('id', $id) : $model = self::where('id', $id); $del = $model->delete(); if ($del >= 1) return __success('删除成功'); return __error('删除失败,请检查!'); } }