wesmiler 6 月之前
父節點
當前提交
7c993363aa
共有 4 個文件被更改,包括 73 次插入24 次删除
  1. 29 12
      app/Helpers/common.php
  2. 9 6
      app/Http/Controllers/Api/v1/MemberController.php
  3. 34 5
      app/Services/Api/MemberService.php
  4. 1 1
      routes/api.php

+ 29 - 12
app/Helpers/common.php

@@ -381,7 +381,7 @@ if (!function_exists('dateFormat')) {
 if (!function_exists('formatHour')) {
     /**
      * 格式化时间
-     * @param $time 时间/秒
+     * @param mixed $time 时间/秒
      * @return false|string
      */
     function formatHour($time)
@@ -609,14 +609,34 @@ if (!function_exists('format_cent')) {
 
     /**
      * 以元为单位的金额转化成分
-     * @param $money 金额
+     * @param mixed $money 金额
+     * @return string
+     */
+    function format_cent($money)
+    {
+        return ($money * 100).'';
+    }
+
+}
+
+if (!function_exists('format_day')) {
+
+    /**
+     * 格式化时间/年或月
+     * @param int $money 金额
      * @return string 返回格式化的金额
      * @author laravel开发员
      * @date 2019/5/23
      */
-    function format_cent($money)
+    function format_day($day = 0)
     {
-        return (string) ($money * 100);
+        if ($day >= 365) {
+            return '一年';
+        }else if($day>=30){
+            return intval($day/30).'个月';
+        }else{
+            return intval($day).'天';
+        }
     }
 
 }
@@ -762,13 +782,13 @@ if (!function_exists('get_zodiac_sign')) {
 
     /**
      * 根据月、日获取星座
-     * @param $month 月份
-     * @param $day 日期
+     * @param int $month 月份
+     * @param int $day 日期
      * @return string 返回结果
      * @author laravel开发员
      * @date 2019/5/23
      */
-    function get_zodiac_sign($month, $day)
+    function get_zodiac_sign(int $month, int $day)
     {
         // 检查参数有效性
         if ($month < 1 || $month > 12 || $day < 1 || $day > 31) {
@@ -790,9 +810,9 @@ if (!function_exists('get_zodiac_sign')) {
             array("22" => "射手座"),
             array("22" => "摩羯座")
         );
-        list($sign_start, $sign_name) = each($signs[(int) $month - 1]);
+        list($sign_start, $sign_name) = each($signs[$month - 1]);
         if ($day < $sign_start) {
-            list($sign_start, $sign_name) = each($signs[($month - 2 < 0) ? $month = 11 : $month -= 2]);
+            list($sign_start, $sign_name) = each($signs[($month - 2 < 0) ? $month = 11 : ($month -= 2)]);
         }
         return $sign_name;
     }
@@ -2317,7 +2337,6 @@ if (!function_exists('api_decrypt')) {
     }
 }
 
-
 if (!function_exists('format_message')) {
     /**
      * 格式化消息内容
@@ -2335,8 +2354,6 @@ if (!function_exists('format_message')) {
     }
 }
 
-
-
 if (!function_exists('format_image_field')) {
 
     /**

+ 9 - 6
app/Http/Controllers/Api/v1/MemberController.php

@@ -45,15 +45,18 @@ class MemberController extends webApp
     }
 
     /**
-     * 用户账号列表
+     * VIP列表
      * @return array
      */
-    public function index()
+    public function vipList()
     {
-        $params =request()->post();
-        $pageSize = request()->post('pageSize', 12);
-        $datas = MemberService::make()->getDataList($params, $pageSize);
-        return message(1010, true, $datas);
+        $type = request()->post('type', 1);
+        $datas = MemberService::make()->getVipList($type);
+        if ($datas) {
+            return showJson(1010, true, $datas);
+        } else {
+            return showJson(1004, false);
+        }
     }
 
     /**

+ 34 - 5
app/Services/Api/MemberService.php

@@ -14,6 +14,7 @@ namespace App\Services\Api;
 use App\Helpers\Jwt;
 use App\Models\ActionLogModel;
 use App\Models\MemberModel;
+use App\Models\VipModel;
 use App\Services\BaseService;
 use App\Services\MpService;
 use App\Services\RedisService;
@@ -206,6 +207,7 @@ class MemberService extends BaseService
                 'nickname'=> $phone? '微信用户'.substr($phone,-6,6) : '微信用户'.$userId,
                 'openid'=> $openid,
                 'mobile'=> $phone,
+                'password'=> $phone? get_password(substr($phone,-6,6)) : get_password('123456'),
                 'login_ip'=> get_client_ip(),
                 'create_time'=> time(),
                 'login_time'=> time(),
@@ -307,7 +309,7 @@ class MemberService extends BaseService
             return $info;
         }
 
-        $defaultField = ['id', 'user_type', 'realname', 'mobile', 'nickname','is_zg_vip','zg_vip_expired','is_zsb_vip','is_zsb_vip','zsb_vip_expired','is_video','video_vip_expired','balance', 'code', 'openid', 'status', 'avatar'];
+        $defaultField = ['id', 'user_type', 'realname', 'mobile', 'nickname','is_zg_vip','zg_vip_expired','is_zsb_vip','is_zsb_vip','zsb_vip_expired','is_video_vip','video_vip_expired','balance', 'code', 'openid', 'status', 'avatar'];
         $field = $field ? $field : $defaultField;
         if (is_array($where)) {
             $info = $this->model->where(['mark' => 1])->where($where)->select($field)->first();
@@ -332,21 +334,24 @@ class MemberService extends BaseService
             $idVip = 0;
             $vipExpired = '';
             $isZgVip = isset($info['is_zg_vip'])? $info['is_zg_vip'] : 0;
-            $zgVipExpired = isset($info['zg_vip_expired']) && $info['zg_vip_expired']? $info['zg_vip_expired'] : '';
+            $zgVipExpired = isset($info['zg_vip_expired']) && !empty($info['zg_vip_expired'])? $info['zg_vip_expired'] : '';
             if($isZgVip && $zgVipExpired && $zgVipExpired>date('Y-m-d H:i:s')){
                 $idVip = 1;
                 $vipExpired = $zgVipExpired;
             }
 
             $isZsbVip = isset($info['is_zsb_vip'])? $info['is_zsb_vip'] : 0;
-            $zsbVipExpired = isset($info['zsb_vip_expired']) && $info['zsb_vip_expired']? $info['zsb_vip_expired'] : '';
+            $zsbVipExpired = isset($info['zsb_vip_expired']) && !empty($info['zsb_vip_expired'])? $info['zsb_vip_expired'] : '';
             if($isZsbVip && $zsbVipExpired && $zgVipExpired>date('Y-m-d H:i:s')){
                 $idVip = 1;
                 $vipExpired = $zsbVipExpired>$vipExpired? $zsbVipExpired : $vipExpired;
             }
             $info['is_vip'] = $idVip;
             $info['vip_expired'] = $vipExpired;
-            RedisService::set($cacheKey, $info, rand(10, 20));
+            $info['zg_vip_expired'] = $zgVipExpired;
+            $info['zsb_vip_expired'] = $zsbVipExpired;
+            $info['video_vip_expired'] = isset($info['video_vip_expired']) && !empty($info['video_vip_expired'])? $info['video_vip_expired'] : '';
+            RedisService::set($cacheKey, $info, rand(5, 10));
         }
 
         return $info;
@@ -478,7 +483,6 @@ class MemberService extends BaseService
         return true;
     }
 
-
     /**
      * 设置入口类型
      * @param $userId
@@ -521,4 +525,29 @@ class MemberService extends BaseService
         RedisService::clear($cacheLockKey);
         return true;
     }
+
+    /**
+     * 获取VIP类别
+     * @param int $type
+     * @return array|mixed
+     */
+    public function getVipList($type=1)
+    {
+        $cacheKey = "caches:members:vipList:{$type}";
+        $datas = RedisService::get($cacheKey);
+        if($datas){
+            return $datas;
+        }
+
+        $datas = VipModel::where(['type'=> $type,'status'=>1,'mark'=>1])
+            ->select(['id','name','type','price','day','remark','status'])
+            ->orderBy('id','asc')
+            ->get();
+        $datas = $datas? $datas->toArray() : [];
+        if($datas){
+            RedisService::set($cacheKey, $datas, rand(3600, 7200));
+        }
+
+        return $datas;
+    }
 }

+ 1 - 1
routes/api.php

@@ -53,6 +53,7 @@ Route::prefix('v1')->middleware('web.login')->group(function() {
 
     // 用户信息
     Route::get('/user/info', [\App\Http\Controllers\Api\v1\MemberController::class, 'info']);
+    Route::get('/user/vipList', [\App\Http\Controllers\Api\v1\MemberController::class, 'vipList']);
     Route::post('/user/setEntry', [\App\Http\Controllers\Api\v1\MemberController::class, 'setEntry']);
     Route::post('/user/modify', [\App\Http\Controllers\Api\v1\MemberController::class, 'modify']);
 
@@ -74,7 +75,6 @@ Route::prefix('v1')->middleware('web.login')->group(function() {
 
 // 回调处理
 Route::match(['get','post'],'/notify/refund/{payType}', [\App\Http\Controllers\Api\v1\NotifyController::class, 'refund']);
-Route::match(['get','post'],'/notify/depositRefund/{payType}', [\App\Http\Controllers\Api\v1\NotifyController::class, 'depositRefund']);
 Route::match(['get','post'],'/notify/{scene}/{payType}', [\App\Http\Controllers\Api\v1\NotifyController::class, 'callback']);
 Route::match(['get','post'],'/notify/kf', [\App\Http\Controllers\Api\v1\NotifyController::class, 'kf']);