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);