You've already forked qlg.tsgz.moe
Merge branch 'test' of ssh://git.qgmzbxs.com:23333/q792602257/qlg.backend into test
This commit is contained in:
147
hyhproject/app/controller/Note.php
Normal file
147
hyhproject/app/controller/Note.php
Normal file
@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace wstmart\app\controller;
|
||||
|
||||
|
||||
use think\Db;
|
||||
|
||||
class Note extends Base
|
||||
{
|
||||
public function index(){
|
||||
$userId = (int)session('WST_USER.userId');
|
||||
$model = model("note")->field(true)
|
||||
->where(["user_id"=>$userId])->order("update_time", "desc")
|
||||
->select();
|
||||
return WSTReturn("OK", 1, $model);
|
||||
}
|
||||
|
||||
public function detail(){
|
||||
$userId = (int)session('WST_USER.userId');
|
||||
if(($id = (int)input( 'id', 0)) > 0){
|
||||
$detail = model("note")->field(true)
|
||||
->where(["user_id"=>$userId, "id"=>$id])->find();
|
||||
if(!$detail) return WSTReturn("该条内容已被删除",0);
|
||||
return WSTReturn("OK", 1, $detail);
|
||||
}
|
||||
return WSTReturn("异常请求",0);
|
||||
}
|
||||
|
||||
public function save(){
|
||||
$userId = (int)session('WST_USER.userId');
|
||||
$id = (int)input( 'post.id', 0);
|
||||
$title = input("post.title");
|
||||
$content = input("post.content");
|
||||
if(empty($title)) return WSTReturn("请填写标题",0);
|
||||
if(empty($content)) return WSTReturn("请填写内容",0);
|
||||
if($id > 0){
|
||||
$detail = model("note")->field(true)
|
||||
->where(["user_id"=>$userId, "id"=>$id])->select();
|
||||
if(!$detail) return WSTReturn("该条内容已被删除",0);
|
||||
model("note")->where(["user_id"=>$userId, "id"=>$id])
|
||||
->save([
|
||||
"title"=>$title,
|
||||
"content"=>$content,
|
||||
"update_time"=>date("Y-m-d H:i:s"),
|
||||
]);
|
||||
return WSTReturn("成功", 1);
|
||||
}elseif($id == 0){
|
||||
model("note")->save([
|
||||
"title"=>$title,
|
||||
"content"=>$content,
|
||||
"user_id"=>$userId,
|
||||
"update_time"=>date("Y-m-d H:i:s"),
|
||||
]);
|
||||
return WSTReturn("成功", 1);
|
||||
}
|
||||
return WSTReturn("异常请求",0);
|
||||
}
|
||||
|
||||
public function creditIndex(){
|
||||
$userId = (int)session('WST_USER.userId');
|
||||
$model = model("note_credit")->field(true)
|
||||
->where(["user_id"=>$userId])->order("update_time", "desc")
|
||||
->select();
|
||||
return WSTReturn("OK", 1, $model);
|
||||
}
|
||||
|
||||
public function creditDetail(){
|
||||
|
||||
}
|
||||
|
||||
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(){
|
||||
$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);
|
||||
}
|
||||
}
|
||||
}
|
27
hyhproject/app/controller/TradeRule.php
Normal file
27
hyhproject/app/controller/TradeRule.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace wstmart\app\controller;
|
||||
|
||||
|
||||
class TradeRule extends Base
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$model = model("trade_rule")->field(true)
|
||||
->order("create_time", "desc")
|
||||
->select();
|
||||
return WSTReturn("OK", 1, $model);
|
||||
}
|
||||
|
||||
public function detail()
|
||||
{
|
||||
if(($id = (int)input( 'id', 0)) > 0){
|
||||
$detail = model("trade_rule")->field(true)
|
||||
->where(["id"=>$id])->find();
|
||||
if(!$detail) return WSTReturn("该条内容已被删除",0);
|
||||
return WSTReturn("OK", 1, $detail);
|
||||
}
|
||||
return WSTReturn("异常请求",0);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user