记账创建新增过程
This commit is contained in:
parent
9627c2b9b4
commit
d5f22242de
@ -4,6 +4,8 @@
|
|||||||
namespace wstmart\app\controller;
|
namespace wstmart\app\controller;
|
||||||
|
|
||||||
|
|
||||||
|
use think\Db;
|
||||||
|
|
||||||
class Note extends Base
|
class Note extends Base
|
||||||
{
|
{
|
||||||
public function index(){
|
public function index(){
|
||||||
@ -40,6 +42,7 @@ class Note extends Base
|
|||||||
->save([
|
->save([
|
||||||
"title"=>$title,
|
"title"=>$title,
|
||||||
"content"=>$content,
|
"content"=>$content,
|
||||||
|
"update_time"=>date("Y-m-d H:i:s"),
|
||||||
]);
|
]);
|
||||||
return WSTReturn("成功", 1);
|
return WSTReturn("成功", 1);
|
||||||
}elseif($id == 0){
|
}elseif($id == 0){
|
||||||
@ -47,7 +50,7 @@ class Note extends Base
|
|||||||
"title"=>$title,
|
"title"=>$title,
|
||||||
"content"=>$content,
|
"content"=>$content,
|
||||||
"user_id"=>$userId,
|
"user_id"=>$userId,
|
||||||
"id"=>$id
|
"update_time"=>date("Y-m-d H:i:s"),
|
||||||
]);
|
]);
|
||||||
return WSTReturn("成功", 1);
|
return WSTReturn("成功", 1);
|
||||||
}
|
}
|
||||||
@ -67,10 +70,78 @@ class Note extends Base
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function creditCreate(){
|
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 = model("note_credit")->save([
|
||||||
|
"title"=>$title,
|
||||||
|
"content"=>$content,
|
||||||
|
"user_id"=>$userId,
|
||||||
|
"cur_cash"=>$cash,
|
||||||
|
]);
|
||||||
|
model("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 creditAdd(){
|
public function creditAdd(){
|
||||||
|
$userId = (int)session('WST_USER.userId');
|
||||||
|
$id = (int)input( 'post.id', 0);
|
||||||
|
$type = (int)input("post.type", 1);
|
||||||
|
$content = input("post.content");
|
||||||
|
$cash = (float)input("post.cash");
|
||||||
|
$credit = model("note_credit")->where([
|
||||||
|
"user_id"=>$userId,
|
||||||
|
"id"=>$id,
|
||||||
|
])->field(true)->find();
|
||||||
|
if(empty($credit)){
|
||||||
|
return WSTReturn("数据不存在",0);
|
||||||
|
}
|
||||||
|
switch ($type){
|
||||||
|
case 1:
|
||||||
|
//+
|
||||||
|
$credit["cash"] += $cash;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
//-
|
||||||
|
$credit["cash"] -= $cash;
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
//-
|
||||||
|
$credit["cash"] = $cash;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Db::startTrans();
|
||||||
|
try{
|
||||||
|
model("note_credit")->where([
|
||||||
|
"user_id"=>$userId,
|
||||||
|
"id"=>$id,
|
||||||
|
])->save($credit);
|
||||||
|
model("note_credit_detail")->save([
|
||||||
|
"credit_id"=>$id,
|
||||||
|
"type"=>$type,
|
||||||
|
"cash"=>$cash,
|
||||||
|
"content"=>$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user