记账,新增修改
This commit is contained in:
parent
6fa32ec4d0
commit
de9d4a1fc4
@ -5,146 +5,211 @@ namespace wstmart\app\controller;
|
|||||||
|
|
||||||
|
|
||||||
use think\Db;
|
use think\Db;
|
||||||
|
use think\Exception;
|
||||||
|
use think\exception\PDOException;
|
||||||
|
|
||||||
class Note extends Base
|
class Note extends Base
|
||||||
{
|
{
|
||||||
public function index(){
|
public function index()
|
||||||
|
{
|
||||||
$userId = (int)session('WST_USER.userId');
|
$userId = (int)session('WST_USER.userId');
|
||||||
$model = Db::name('note')->field(true)
|
$model = Db::name('note')->field(true)
|
||||||
->where(["user_id"=>$userId])->order("update_time", "desc")
|
->where(["user_id" => $userId])->order("update_time", "desc")
|
||||||
->select();
|
->select();
|
||||||
return WSTReturn("OK", 1, $model);
|
return WSTReturn("OK", 1, $model);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function detail(){
|
public function detail()
|
||||||
|
{
|
||||||
$userId = (int)session('WST_USER.userId');
|
$userId = (int)session('WST_USER.userId');
|
||||||
if(($id = (int)input( 'id', 0)) > 0){
|
if (($id = (int)input('id', 0)) > 0) {
|
||||||
$detail = Db::name('note')
|
$detail = Db::name('note')
|
||||||
->where(["user_id"=>$userId, "id"=>$id])->find();
|
->where(["user_id" => $userId, "id" => $id])->find();
|
||||||
if(!$detail) return WSTReturn("该条内容已被删除",0);
|
if (!$detail) return WSTReturn("该条内容已被删除", 0);
|
||||||
$detail['content'] = htmlspecialchars_decode($detail['content']);
|
$detail['content'] = htmlspecialchars_decode($detail['content']);
|
||||||
return WSTReturn("OK", 1, $detail);
|
return WSTReturn("OK", 1, $detail);
|
||||||
}
|
}
|
||||||
return WSTReturn("异常请求",0);
|
return WSTReturn("异常请求", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function save(){
|
public function save()
|
||||||
|
{
|
||||||
$userId = (int)session('WST_USER.userId');
|
$userId = (int)session('WST_USER.userId');
|
||||||
$id = (int)input( 'post.id', 0);
|
$id = (int)input('post.id', 0);
|
||||||
$title = input("post.title");
|
$title = input("post.title");
|
||||||
$content = request()->post("content");
|
$content = request()->post("content");
|
||||||
$content = htmlspecialchars_decode($content);
|
$content = htmlspecialchars_decode($content);
|
||||||
if(empty($title)) return WSTReturn("请填写标题",0);
|
if (empty($title)) return WSTReturn("请填写标题", 0);
|
||||||
if(empty($content)) return WSTReturn("请填写内容",0);
|
if (empty($content)) return WSTReturn("请填写内容", 0);
|
||||||
if($id > 0){
|
if ($id > 0) {
|
||||||
$detail = Db::name('note')->field(true)
|
$detail = Db::name('note')->field(true)
|
||||||
->where(["user_id"=>$userId, "id"=>$id])->select();
|
->where(["user_id" => $userId, "id" => $id])->select();
|
||||||
if(!$detail) return WSTReturn("该条内容已被删除",0);
|
if (!$detail) return WSTReturn("该条内容已被删除", 0);
|
||||||
Db::name('note')->where(["user_id"=>$userId, "id"=>$id])
|
Db::name('note')->where(["user_id" => $userId, "id" => $id])
|
||||||
->update([
|
->update([
|
||||||
"title"=>$title,
|
"title" => $title,
|
||||||
"content"=>$content,
|
"content" => $content,
|
||||||
"update_time"=>date("Y-m-d H:i:s"),
|
"update_time" => date("Y-m-d H:i:s"),
|
||||||
]);
|
]);
|
||||||
return WSTReturn("成功", 1);
|
return WSTReturn("成功", 1);
|
||||||
}elseif($id == 0){
|
} elseif ($id == 0) {
|
||||||
Db::name('note')->insert([
|
Db::name('note')->insert([
|
||||||
"title"=>$title,
|
"title" => $title,
|
||||||
"content"=>$content,
|
"content" => $content,
|
||||||
"user_id"=>$userId,
|
"user_id" => $userId,
|
||||||
"create_time"=>date("Y-m-d H:i:s"),
|
"create_time" => date("Y-m-d H:i:s"),
|
||||||
"update_time"=>date("Y-m-d H:i:s"),
|
"update_time" => date("Y-m-d H:i:s"),
|
||||||
]);
|
]);
|
||||||
return WSTReturn("成功", 1);
|
return WSTReturn("成功", 1);
|
||||||
}
|
}
|
||||||
return WSTReturn("异常请求",0);
|
return WSTReturn("异常请求", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function creditIndex(){
|
public function creditIndex()
|
||||||
|
{
|
||||||
$userId = (int)session('WST_USER.userId');
|
$userId = (int)session('WST_USER.userId');
|
||||||
$model = Db::name('note_credit')->field(true)
|
$model = Db::name('note_credit')->field(true)
|
||||||
->where(["user_id"=>$userId])->order("update_time", "desc")
|
->where(["user_id" => $userId])->order("update_time", "desc")
|
||||||
->select();
|
->select();
|
||||||
return WSTReturn("OK", 1, $model);
|
return WSTReturn("OK", 1, $model);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function creditDetail(){
|
public function creditDetail()
|
||||||
|
{
|
||||||
|
$userId = (int)session('WST_USER.userId');
|
||||||
|
if (($id = (int)input('id', 0)) > 0) {
|
||||||
|
$detail = Db::name('note_credit')
|
||||||
|
->where(["user_id" => $userId, "id" => $id])->find();
|
||||||
|
if (!$detail) return WSTReturn("该条内容已被删除", 0);
|
||||||
|
$detail['content'] = htmlspecialchars_decode($detail['content']);
|
||||||
|
return WSTReturn("OK", 1, $detail);
|
||||||
|
}
|
||||||
|
return WSTReturn("异常请求", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function creditCreate(){
|
public function creditDetailInfo()
|
||||||
|
{
|
||||||
|
$userId = (int)session('WST_USER.userId');
|
||||||
|
if (($id = (int)input('id', 0)) > 0) {
|
||||||
|
$detail = Db::name('note_credit_detail')
|
||||||
|
->order('create_time', 'desc')
|
||||||
|
->where(["user_id" => $userId, "credit_id" => $id])->select();
|
||||||
|
foreach ($detail as &$item) {
|
||||||
|
$item['create_date'] = date('Y-m-d', strtotime($item['create_time']));
|
||||||
|
}
|
||||||
|
return WSTReturn("OK", 1, $detail);
|
||||||
|
}
|
||||||
|
return WSTReturn("异常请求", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function creditCreate()
|
||||||
|
{
|
||||||
$userId = (int)session('WST_USER.userId');
|
$userId = (int)session('WST_USER.userId');
|
||||||
$title = input("post.title");
|
$title = input("post.title");
|
||||||
$content = input("post.content");
|
$content = input("post.content");
|
||||||
$cash = (float)input("post.cash");
|
$cash = (float)input("post.cash");
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try{
|
try {
|
||||||
$id = Db::name('note_credit')->save([
|
$id = Db::name('note_credit')->save([
|
||||||
"title"=>$title,
|
"title" => $title,
|
||||||
"content"=>$content,
|
"content" => $content,
|
||||||
"user_id"=>$userId,
|
"user_id" => $userId,
|
||||||
"cur_cash"=>$cash,
|
"cur_cash" => $cash,
|
||||||
]);
|
]);
|
||||||
model("note_credit_detail")->save([
|
Db::name("note_credit_detail")->save([
|
||||||
"credit_id"=>$id,
|
"credit_id" => $id,
|
||||||
"type"=>0,
|
"type" => 0,
|
||||||
"cash"=>$cash,
|
"cash" => $cash,
|
||||||
"content"=>"新建时填写的值",
|
"content" => "新建时填写的值",
|
||||||
"create_time"=>date("Y-m-d H:i:s"),
|
"create_time" => date("Y-m-d H:i:s"),
|
||||||
]);
|
]);
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return WSTReturn("OK", 1);
|
return WSTReturn("OK", 1);
|
||||||
}catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Db::rollback();errLog($e);
|
Db::rollback();
|
||||||
return WSTReturn('操作失败',-1);
|
errLog($e);
|
||||||
|
return WSTReturn('操作失败', -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function creditAdd(){
|
public function creditSave()
|
||||||
|
{
|
||||||
$userId = (int)session('WST_USER.userId');
|
$userId = (int)session('WST_USER.userId');
|
||||||
$id = (int)input( 'post.id', 0);
|
$id = (int)input('post.id', 0);
|
||||||
$type = (int)input("post.type", 1);
|
$name = input("post.name");
|
||||||
$content = input("post.content");
|
$cur_cash = input('post.cur_cash');
|
||||||
$cash = (float)input("post.cash");
|
$credit_cash = input('post.credit_cash');
|
||||||
$credit = Db::name('note_credit')->where([
|
$detail = Db::name('note_credit')
|
||||||
"user_id"=>$userId,
|
->where(["user_id" => $userId, "id" => $id])->find();
|
||||||
"id"=>$id,
|
if (!$detail) return WSTReturn("该条内容已被删除", 0);
|
||||||
])->field(true)->find();
|
Db::startTrans();
|
||||||
if(empty($credit)){
|
try {
|
||||||
return WSTReturn("数据不存在",0);
|
if ($detail['cur_cash'] != $cur_cash) {
|
||||||
|
Db::name('note_credit')
|
||||||
|
->where(["user_id" => $userId, "id" => $id])
|
||||||
|
->update(compact('cur_cash'));
|
||||||
|
Db::name("note_credit_detail")->insert([
|
||||||
|
"credit_id" => $id,
|
||||||
|
"user_id"=>$userId,
|
||||||
|
"type" => 9,
|
||||||
|
"amount" => $cur_cash,
|
||||||
|
"create_time" => date("Y-m-d H:i:s"),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
Db::name('note_credit')
|
||||||
|
->where(["user_id" => $userId, "id" => $id])
|
||||||
|
->update(compact('name', 'credit_cash'));
|
||||||
|
Db::commit();
|
||||||
|
return WSTReturn("OK", 1);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Db::rollback();
|
||||||
|
errLog($e);
|
||||||
|
return WSTReturn('操作失败', -1);
|
||||||
}
|
}
|
||||||
switch ($type){
|
}
|
||||||
|
|
||||||
|
public function creditAdd()
|
||||||
|
{
|
||||||
|
$userId = (int)session('WST_USER.userId');
|
||||||
|
$id = (int)input('post.id', 0);
|
||||||
|
$type = (int)input("post.type", 1);
|
||||||
|
$amount = (float)input("post.amount");
|
||||||
|
$credit = Db::name('note_credit')->where([
|
||||||
|
"user_id" => $userId,
|
||||||
|
"id" => $id,
|
||||||
|
])->field(true)->find();
|
||||||
|
if (empty($credit)) {
|
||||||
|
return WSTReturn("数据不存在", 0);
|
||||||
|
}
|
||||||
|
switch ($type) {
|
||||||
case 1:
|
case 1:
|
||||||
//+
|
//+
|
||||||
$credit["cash"] += $cash;
|
$credit["amount"] += $amount;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
//-
|
//-
|
||||||
$credit["cash"] -= $cash;
|
$credit["amount"] -= $amount;
|
||||||
break;
|
|
||||||
case 9:
|
|
||||||
//-
|
|
||||||
$credit["cash"] = $cash;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try{
|
try {
|
||||||
Db::name('note_credit')->where([
|
Db::name('note_credit')->where([
|
||||||
"user_id"=>$userId,
|
"user_id" => $userId,
|
||||||
"id"=>$id,
|
"id" => $id,
|
||||||
])->save($credit);
|
])->save($credit);
|
||||||
model("note_credit_detail")->save([
|
Db::name("note_credit_detail")->insert([
|
||||||
"credit_id"=>$id,
|
"credit_id" => $id,
|
||||||
"type"=>$type,
|
"user_id"=>$userId,
|
||||||
"cash"=>$cash,
|
"type" => $type,
|
||||||
"content"=>$content,
|
"amount" => $amount,
|
||||||
"create_time"=>date("Y-m-d H:i:s"),
|
"create_time" => date("Y-m-d H:i:s"),
|
||||||
]);
|
]);
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return WSTReturn("OK", 1);
|
return WSTReturn("OK", 1);
|
||||||
}catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Db::rollback();errLog($e);
|
Db::rollback();
|
||||||
return WSTReturn('操作失败',-1);
|
errLog($e);
|
||||||
|
return WSTReturn('操作失败', -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user