烂笔头记账新增
This commit is contained in:
parent
c74f56a43b
commit
68663ed74d
@ -64,6 +64,14 @@ class Note extends Base
|
|||||||
return WSTReturn("异常请求", 0);
|
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()
|
public function creditIndex()
|
||||||
{
|
{
|
||||||
$userId = (int)session('WST_USER.userId');
|
$userId = (int)session('WST_USER.userId');
|
||||||
@ -177,11 +185,11 @@ class Note extends Base
|
|||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 1:
|
case 1:
|
||||||
//+
|
//+
|
||||||
$credit["amount"] += $amount;
|
$credit["cur_cash"] -= $amount;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
//-
|
//-
|
||||||
$credit["amount"] -= $amount;
|
$credit["cur_cash"] += $amount;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
@ -189,7 +197,7 @@ class Note extends Base
|
|||||||
Db::name('note_credit')->where([
|
Db::name('note_credit')->where([
|
||||||
"user_id" => $userId,
|
"user_id" => $userId,
|
||||||
"id" => $id,
|
"id" => $id,
|
||||||
])->save($credit);
|
])->update($credit);
|
||||||
Db::name("note_credit_detail")->insert([
|
Db::name("note_credit_detail")->insert([
|
||||||
"credit_id" => $id,
|
"credit_id" => $id,
|
||||||
"user_id"=>$userId,
|
"user_id"=>$userId,
|
||||||
@ -205,4 +213,58 @@ class Note extends Base
|
|||||||
return WSTReturn('操作失败', -1);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user