From 68663ed74dc2a94dd1f53cc003db728bbe4ff9b8 Mon Sep 17 00:00:00 2001 From: JerryYan <792602257@qq.com> Date: Sun, 16 Aug 2020 15:03:26 +0800 Subject: [PATCH] =?UTF-8?q?=E7=83=82=E7=AC=94=E5=A4=B4=E8=AE=B0=E8=B4=A6?= =?UTF-8?q?=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 | 68 ++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 3 deletions(-) diff --git a/hyhproject/app/controller/Note.php b/hyhproject/app/controller/Note.php index 531fd62..690b18d 100644 --- a/hyhproject/app/controller/Note.php +++ b/hyhproject/app/controller/Note.php @@ -64,6 +64,14 @@ class Note extends Base return WSTReturn("异常请求", 0); } + public function delete() { + $userId = (int)session('WST_USER.userId'); + $id = (int)input('post.id', -1); + Db::name('note') + ->where(["user_id" => $userId, "id" => $id])->delete(); + return WSTReturn("OK", 1); + } + public function creditIndex() { $userId = (int)session('WST_USER.userId'); @@ -177,11 +185,11 @@ class Note extends Base switch ($type) { case 1: //+ - $credit["amount"] += $amount; + $credit["cur_cash"] -= $amount; break; case 2: //- - $credit["amount"] -= $amount; + $credit["cur_cash"] += $amount; break; } Db::startTrans(); @@ -189,7 +197,7 @@ class Note extends Base Db::name('note_credit')->where([ "user_id" => $userId, "id" => $id, - ])->save($credit); + ])->update($credit); Db::name("note_credit_detail")->insert([ "credit_id" => $id, "user_id"=>$userId, @@ -205,4 +213,58 @@ class Note extends Base return WSTReturn('操作失败', -1); } } + + public function creditDelete() { + $userId = (int)session('WST_USER.userId'); + $id = (int)input('post.id', -1); + Db::name('note_credit') + ->where(["user_id" => $userId, "id" => $id])->delete(); + return WSTReturn("OK", 1); + } + + public function creditDeleteInfo () { + $userId = (int)session('WST_USER.userId'); + $id = (int)input('post.id', 0); + $cid = (int)input('post.credit_id', 0); + $credit = Db::name('note_credit')->where([ + "user_id" => $userId, + "id" => $cid, + ])->field(true)->find(); + $detail = Db::name("note_credit_detail")->where([ + "credit_id" => $cid, + "user_id"=>$userId, + "id" => $id, + ])->field(true)->find(); + if (empty($credit) || empty($detail)) { + return WSTReturn("数据不存在", 0); + } + switch ((int)$detail['type']) { + case 1: + //+ + $credit["cur_cash"] += $detail['amount']; + break; + case 2: + //- + $credit["cur_cash"] -= $detail['amount']; + break; + } + Db::startTrans(); + try { + Db::name('note_credit')->where([ + "user_id" => $userId, + "id" => $cid, + ])->update($credit); + Db::name("note_credit_detail")->where([ + "credit_id" => $cid, + "user_id"=>$userId, + "id" => $id, + ])->delete(); + Db::commit(); + return WSTReturn("OK", 1); + } catch (\Exception $e) { + Db::rollback(); + errLog($e); + return WSTReturn('操作失败', -1); + } + } } \ No newline at end of file