瀏覽代碼

自动更新

moonsflyer 9 月之前
父節點
當前提交
9a096e54b9
共有 2 個文件被更改,包括 34 次插入0 次删除
  1. 6 0
      app/adminapi/controller/asset/AssetLeaseController.php
  2. 28 0
      app/adminapi/lists/asset/AssetLeaseLists.php

+ 6 - 0
app/adminapi/controller/asset/AssetLeaseController.php

@@ -32,6 +32,7 @@ use app\common\logic\PaymentLogic;
  */
 class AssetLeaseController extends BaseAdminController
 {
+    public array $notNeedLogin = ['autoUpdataLeaseStatus'];
     /**
      * @notes 查看资产列表
      * @return \think\response\Json
@@ -122,4 +123,9 @@ class AssetLeaseController extends BaseAdminController
         }
         return $this->fail(AssetLeaseLists::getError());
     }
+
+    public function autoUpdataLeaseStatus(){
+        $result = AssetLeaseLists::autoUpdateStatus();
+        return $this->success('更新成功',[], 1, 1);
+    }
 }

+ 28 - 0
app/adminapi/lists/asset/AssetLeaseLists.php

@@ -399,4 +399,32 @@ class AssetLeaseLists extends BaseAdminDataLists implements ListsSearchInterface
             return false;
         }
     }
+
+    public static function autoUpdateStatus():bool{
+        $where = [] ;
+        $where[] = ['auto_status','=',0] ;
+        $where[]= ['approval_status','=',5];
+        $assetLeaseList = AssetLeaseInfo::where($where)->select()->toArray();
+        $nowTime = time();
+        foreach($assetLeaseList as &$v){
+            $assetInfo = AssetInfo::find($v['a_id']);
+            $a_lease_expiration_time = $assetInfo['lease_expiration_time'];
+            if($nowTime >= strtotime($v['lease_end_time'])){
+                $updateLeaseData['id']=$v['id'];
+                $updateLeaseData['auto_status']=1;
+                AssetLeaseInfo::update($updateLeaseData);
+                if(strtotime($v['lease_end_time']) >= strtotime($a_lease_expiration_time)) {
+                    $updateAssetData['id'] = $assetInfo['id'];
+                    $updateAssetData['lease_status'] = 3;
+                    AssetInfo::update($updateAssetData);
+                }else{
+                    continue;
+                }
+            }else{
+                continue;
+            }
+        }
+       
+        return true;
+    }
 }