Răsfoiți Sursa

账单编辑删除

afa 5 luni în urmă
părinte
comite
946bd71316
3 a modificat fișierele cu 56 adăugiri și 2 ștergeri
  1. 50 1
      app/api/controller/MoneyLog.php
  2. 5 0
      app/api/route/route.php
  3. 1 1
      app/api/validate/Money.php

+ 50 - 1
app/api/controller/MoneyLog.php

@@ -52,7 +52,6 @@ class MoneyLog extends Base
       //添加记账
       public function money(MonuyModel $monuyModel)
       {     
-
             $data = $this->request->post();
             $result = false;
             Db::startTrans();
@@ -77,6 +76,56 @@ class MoneyLog extends Base
             $this->success();
       }
 
+      //账单编辑
+      public function moneyedit(MonuyModel $monuyModel)
+      {
+            $data = $this->request->post();
+            $result = false;
+            Db::startTrans();
+            try {
+                  validate(MoneyValidate::class)->scene('edit')->check($data);
+                  
+                  $rows = $monuyModel->where('id', $data['id'])->where('user_id', $this->userinfo['id'])->find();
+                  if(!$rows) $this->error('数据不存在');
+                  //发货数据
+                  $result = $rows->save($data);
+
+                  Db::commit();
+            }catch (ValidateException $e) {
+                  Db::rollback();
+                  return $this->error($e->getError());
+            } catch (\Exception $e) {
+                  Db::rollback();
+                  $this->error($e->getMessage());
+            }
+            if ($result === false) {
+                  $this->error(__('没有更新任何数据'));
+            }
+            $this->success();
+      }
+
+      //删除账单
+      public function moneydel(MonuyModel $monuyModel)
+      {
+            $id = $this->request->post('id/d');
+            $result = false;
+            Db::startTrans();
+            try {
+                  $rows = $monuyModel->where('id', $id)->where('user_id', $this->userinfo['id'])->find();
+                  if(!$rows) $this->error('数据不存在');
+                  //发货数据
+                  $result = $rows->delete();
+
+                  Db::commit();
+            } catch (\Exception $e) {
+                  Db::rollback();
+                  $this->error($e->getMessage());
+            }
+            if ($result === false) {
+                  $this->error(__('没有删除任何数据'));
+            }
+            $this->success();
+      }
 
       /**
      * @return void 全部类型图标

+ 5 - 0
app/api/route/route.php

@@ -44,6 +44,11 @@ Route::group('user', function () {
 
     //记账
     Route::rule('money','MoneyLog/money','POST');
+    //账单编辑
+    Route::rule('moneyedit','MoneyLog/moneyedit','POST');
+    //删除
+    Route::rule('moneydel','MoneyLog/moneydel','POST');
+    
     //记账记录
     Route::rule('moneylog','MoneyLog/moneylog','POST');
     //记账类型配置

+ 1 - 1
app/api/validate/Money.php

@@ -24,6 +24,6 @@ class Money extends Validate
  
     protected $scene = [
         'add'  =>  ['type_name','type','bank_account', 'change'],
-      
+        'edit' => ['id','type_name','type','bank_account', 'change'],
     ]; 
 }