瀏覽代碼

编辑删除

afa 5 月之前
父節點
當前提交
b496d39482
共有 2 個文件被更改,包括 14 次插入9 次删除
  1. 5 5
      app/api/controller/MoneyLog.php
  2. 9 4
      app/common/model/MoneyLog.php

+ 5 - 5
app/api/controller/MoneyLog.php

@@ -21,6 +21,7 @@ class MoneyLog extends Base
             $time = $this->request->post('time/s', date('Y-m'));
             $result['count'] = $monuyModel::getCountMonthBalance($this->userinfo['id'], $time);
             $result['list']  = $monuyModel->where('user_id', $this->userinfo['id'])
+                              ->where('status', MonuyModel::STATUS_NORMAL)
                               ->whereMonth('create_date', $time)
                               ->order('id desc')
                               ->paginate(10);
@@ -57,7 +58,6 @@ class MoneyLog extends Base
             Db::startTrans();
             try {
                   validate(MoneyValidate::class)->scene('add')->check($data);
-            
                   //发货数据
                   $data['user_id'] = $this->userinfo['id'];
                   $result = $monuyModel::create($data);
@@ -85,7 +85,7 @@ class MoneyLog extends Base
             try {
                   validate(MoneyValidate::class)->scene('edit')->check($data);
                   
-                  $rows = $monuyModel->where('id', $data['id'])->where('user_id', $this->userinfo['id'])->find();
+                  $rows = $monuyModel->where('id', $data['id'])->where('user_id', $this->userinfo['id'])->where('status', $monuyModel::STATUS_NORMAL)->find();
                   if(!$rows) $this->error('数据不存在');
                   //发货数据
                   $result = $rows->save($data);
@@ -111,11 +111,11 @@ class MoneyLog extends Base
             $result = false;
             Db::startTrans();
             try {
-                  $rows = $monuyModel->where('id', $id)->where('user_id', $this->userinfo['id'])->find();
+                  $rows = $monuyModel->where('id', $id)->where('user_id', $this->userinfo['id'])->where('status', $monuyModel::STATUS_NORMAL)->find();
                   if(!$rows) $this->error('数据不存在');
                   //发货数据
-                  $result = $rows->delete();
-
+                  $rows->status = $monuyModel::STATUS_HIDDEN;
+                  $result = $rows->save();
                   Db::commit();
             } catch (\Exception $e) {
                   Db::rollback();

+ 9 - 4
app/common/model/MoneyLog.php

@@ -20,6 +20,11 @@ class MoneyLog Extends Model
     const TYPE_INCOME = 1;
     const TYPE_EXPENDITURE = 2;
 
+    const STATUS_HIDDEN= 0;  //隐藏
+    const STATUS_NORMAL = 1; //正常
+
+
+
     //
     public function users()
     {
@@ -36,13 +41,13 @@ class MoneyLog Extends Model
     //按照类型月统计 收入- 支出
     public static function getCountMonthBalance(int $user_id = 0, string $time = '')
     {
-        $income = self::where('type', self::TYPE_INCOME);
+        $income = self::where('type', self::TYPE_INCOME)->where('status', self::STATUS_NORMAL);
         if(!empty($user_id) && !empty($time)){
             $income = $income->where('user_id', $user_id)->whereMonth('create_date', $time);
         }
         $income = $income->sum('change');
         //支出
-        $expenditure = self::where('type', self::TYPE_EXPENDITURE);
+        $expenditure = self::where('type', self::TYPE_EXPENDITURE)->where('status', self::STATUS_NORMAL);
         if(!empty($user_id) && !empty($time)){
             $expenditure = $expenditure->where('user_id', $user_id)->whereMonth('create_date', $time);
         }
@@ -60,13 +65,13 @@ class MoneyLog Extends Model
     public static function getCountYearBalance(int $user_id = 0, string $time = '')
 
     {
-        $income = self::where('type', self::TYPE_INCOME);
+        $income = self::where('type', self::TYPE_INCOME)->where('status', self::STATUS_NORMAL);
         if(!empty($user_id) && !empty($time)){
             $income = $income->where('user_id', $user_id)->whereYear('create_date', $time);
         }
         $income = $income->sum('change');
         //支出
-        $expenditure = self::where('type', self::TYPE_EXPENDITURE);
+        $expenditure = self::where('type', self::TYPE_EXPENDITURE)->where('status', self::STATUS_NORMAL);
         if(!empty($user_id) && !empty($time)){
             $expenditure = $expenditure->where('user_id', $user_id)->whereYear('create_date', $time);
         }