From c74f56a43b30f99f384c1eb5312012fe38ddebb5 Mon Sep 17 00:00:00 2001 From: JerryYan <792602257@qq.com> Date: Sun, 16 Aug 2020 14:05:34 +0800 Subject: [PATCH] =?UTF-8?q?=E7=83=82=E7=AC=94=E5=A4=B4=E6=96=B0=E5=A2=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hyhproject/app/controller/Note.php | 57 +++++++++++++----------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/hyhproject/app/controller/Note.php b/hyhproject/app/controller/Note.php index 60ddb2e..531fd62 100644 --- a/hyhproject/app/controller/Note.php +++ b/hyhproject/app/controller/Note.php @@ -6,7 +6,6 @@ namespace wstmart\app\controller; use think\Db; use think\Exception; -use think\exception\PDOException; class Note extends Base { @@ -102,43 +101,37 @@ class Note extends Base return WSTReturn("异常请求", 0); } - public function creditCreate() - { - $userId = (int)session('WST_USER.userId'); - $title = input("post.title"); - $content = input("post.content"); - $cash = (float)input("post.cash"); - Db::startTrans(); - try { - $id = Db::name('note_credit')->save([ - "title" => $title, - "content" => $content, - "user_id" => $userId, - "cur_cash" => $cash, - ]); - Db::name("note_credit_detail")->save([ - "credit_id" => $id, - "type" => 0, - "cash" => $cash, - "content" => "新建时填写的值", - "create_time" => date("Y-m-d H:i:s"), - ]); - Db::commit(); - return WSTReturn("OK", 1); - } catch (\Exception $e) { - Db::rollback(); - errLog($e); - return WSTReturn('操作失败', -1); - } - } - public function creditSave() { $userId = (int)session('WST_USER.userId'); - $id = (int)input('post.id', 0); + $id = (int)input('post.id', -1); $name = input("post.name"); $cur_cash = input('post.cur_cash'); $credit_cash = input('post.credit_cash'); + if ($id == 0){ + Db::startTrans(); + try { + $id = Db::name('note_credit')->insertGetId([ + "user_id" => $userId, "id" => $id, + "cur_cash" => $cur_cash, + 'name' => $name, + 'credit_cash' => $credit_cash, + ]); + Db::name("note_credit_detail")->insert([ + "credit_id" => $id, + "user_id"=>$userId, + "type" => 0, + "amount" => $cur_cash, + "create_time" => date("Y-m-d H:i:s"), + ]); + Db::commit(); + return WSTReturn("OK", 1); + } catch (\Exception $e) { + Db::rollback(); + errLog($e); + return WSTReturn('操作失败', -1); + } + } $detail = Db::name('note_credit') ->where(["user_id" => $userId, "id" => $id])->find(); if (!$detail) return WSTReturn("该条内容已被删除", 0);