黄宗昌 2 роки тому
батько
коміт
8749d4523c
1 змінених файлів з 42 додано та 1 видалено
  1. 42 1
      app/Http/Controllers/V1/UserController.php

+ 42 - 1
app/Http/Controllers/V1/UserController.php

xqd xqd
@@ -71,8 +71,40 @@ 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 天";
+        // 计算剩余时间
+        if(strtotime($info->end_time) > time() && $info->member_type == 2){
+            $info->remaining_time = $this->timeCalculation(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 timeCalculation($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;
+    }
+
     /**
      * 新增用户
      */
@@ -136,12 +168,21 @@ class UserController extends Controller
     /**
      * 删除用户
      */
-    public function destroy()
+    public function destroy(Request $request)
     {
         $user = User::query()->where('id',$this->userId)->first();
         if(!$user){
             return $this->error("用户不存在!");
         }
+        if(empty($request->email)){
+            return $this->error("邮箱不能为空!"); // 邮箱不能为空
+        }
+        if(empty($request->code)){
+            return $this->error("验证码不能为空!"); // 邮箱不能为空
+        }
+        if(!EmailController::isEmailCodeRight($request->email,$request->code)){
+            return $this->error("验证码验证失败!");
+        }
         $user->delete();
         return $this->success();
     }