黄宗昌 2 gadi atpakaļ
vecāks
revīzija
e553eb73f1
1 mainītis faili ar 29 papildinājumiem un 4 dzēšanām
  1. 29 4
      app/Http/Controllers/V1/UserController.php

+ 29 - 4
app/Http/Controllers/V1/UserController.php

xqd
@@ -51,21 +51,46 @@ class UserController extends Controller
         }
         $info->follow_count = UserFollow::query()->where('user_id',$id)->count();
         $info->is_follow = UserFollow::query()->where('user_id',$this->userId)->where('to_user_id',$id)->count();
-        $info->remaining_time = "0 天";
+        $info->ko_remaining_time = "0 일";
+        $info->zh_remaining_time = "0 天";
         // 计算剩余时间
         if(strtotime($info->end_time) > time() && $info->member_type == 2){
-            $info->remaining_time = $this->timeCalculation(time(),strtotime($info->end_time));
+            $info->ko_remaining_time = $this->koTimeCalculation(time(),strtotime($info->end_time));
+            $info->zh_remaining_time = $this->zhTimeCalculation(time(),strtotime($info->end_time));
         }
         return $this->success($info);
     }
-
+    /**
+     * @param $beginDate  开始日期 2020-08-06 11:00:00
+     * @param $endDate    结束日期 2020-08-10 12:10:01
+     * @return string
+     */
+    public function koTimeCalculation($beginDate, $endDate)
+    {
+        $common = $endDate - $beginDate;
+        $a = floor($common/86400/360); //整数年
+        $b = floor($common/86400/30) - $a*12; //整数月
+        $c = floor($common/86400) - $a*360 - $b*30; //整数日
+        $d = floor($common/86400); //总的天数
+        $str = '';
+        if($a){
+            $str = $a."년";
+        }
+        if($b){
+            $str = $str.$b."월";
+        }
+        if($c){
+            $str = $str.$c."일";
+        }
+        return $str;
+    }
 
     /**
      * @param $beginDate  开始日期 2020-08-06 11:00:00
      * @param $endDate    结束日期 2020-08-10 12:10:01
      * @return string
      */
-   public function timeCalculation($beginDate, $endDate)
+   public function zhTimeCalculation($beginDate, $endDate)
     {
         $common = $endDate - $beginDate;
         $a = floor($common/86400/360); //整数年