wesmiler 4 лет назад
Родитель
Сommit
1f49934329

+ 7 - 7
app/Helpers/Jwt.php

@@ -29,10 +29,10 @@ class Jwt
     // 使用HMAC生成信息摘要时所使用的密钥
     private static $key = '34c68cdccb5b6feb4f7f0a5ede9f5932';
 
-    private static $iss = 'jwt_yh';
+    private static $scene = 'jwt';
 
     public function __construct($scene=''){
-        self::$iss = $scene? $scene : self::$iss;
+        self::$scene = $scene? $scene : self::$scene;
     }
 
     /**
@@ -54,11 +54,11 @@ class Jwt
      * @author wesmiler
      * @since 2020/11/14
      */
-    public function getPayload($uid, $expire)
+    public function getPayload($uid, $expire=0)
     {
         $payload = [
-            'iss' => self::$iss, //签发人
-            'exp' => $expire? time() + $expire * 60 * 60 * 24 : time() + 60 * 60 * 24 * 7, //过期时间
+            'iss' => 'jwt_yh', //签发人
+            'exp' => $expire>0? time() + $expire * 60 * 60 * 24 : time() + 60 * 60 * 24 * 7, //过期时间
             'sub' => 'YH', //主题
             'aud' => 'every', //受众
             'nbf' => time(), //生效时间,该时间之前不接收处理该Token
@@ -94,7 +94,7 @@ class Jwt
         // JWT头拼接JWT有效载荷
         $raw = $header . '.' . $payload;
         // Token字符串
-        $token = $raw . '.' . self::signature($raw, self::$key, self::$header['alg']);
+        $token = $raw . '.' . self::signature($raw, md5(self::$key.self::$scene), self::$header['alg']);
         // 返回Token
         return $token;
     }
@@ -125,7 +125,7 @@ class Jwt
         }
 
         //签名验证
-        if (self::signature($base64header . '.' . $base64payload, self::$key, $base64decodeheader['alg']) !== $sign) {
+        if (self::signature($base64header . '.' . $base64payload, md5(self::$key.self::$scene), $base64decodeheader['alg']) !== $sign) {
             return false;
         }
 

+ 17 - 1
app/Helpers/common.php

@@ -686,7 +686,7 @@ if (!function_exists('get_order_num')) {
     function get_order_num($prefix = '')
     {
         $micro = substr(microtime(), 2, 3);
-        return $prefix . date("YmdHis") . $micro . rand(100000, 999999);
+        return $prefix . date("YmdHis") . $micro . rand(100, 999);
     }
 
 }
@@ -1210,6 +1210,22 @@ if (!function_exists('getValidatorError')) {
     }
 }
 
+if (!function_exists('getDateText')) {
+    /**
+     * 获取实际日期格式
+     * @param $error
+     * @return mixed
+     */
+    function getDateText($date, $format='Y-m-d')
+    {
+        $dateText = str_replace(['年','月','日'],['-','-',''], $date);
+        if(!preg_match("/年/", $date)){
+            $dateText = date('Y-').$dateText;
+        }
+        return date($format, strtotime($dateText));
+    }
+}
+
 if (!function_exists('lang')) {
     /**
      * 语言转换

+ 7 - 0
app/Http/Controllers/Api/BaseController.php

@@ -165,6 +165,13 @@ class BaseController extends Controller
         define('NICK_NAME', env('NICK_NAME'));
         // 系统版本号
         define('VERSION', env('VERSION'));
+
+        // 请求参数
+        $this->param = \request()->input();
+
+        // 分页基础默认值
+        defined('PERPAGE') or define('PERPAGE', isset($this->param['limit']) ? $this->param['limit'] : 20);
+        defined('PAGE') or define('PAGE', isset($this->param['page']) ? $this->param['page'] : 1);
     }
 
     /**

+ 5 - 2
app/Http/Controllers/Api/TestController.php

@@ -30,8 +30,11 @@ class TestController extends BaseController
     }
 
     public function index(){
-        $jwt = new Jwt('jwt_wx');
-
+        $jwt = new Jwt();
+        $token = request()->headers->get('Authorization');
+        $token = str_replace("Bearer ", null, $token);
+        $userId = $jwt->verifyToken($token);
+        var_dump($userId.'+');
 
 
         return message(1005,'true',['ddd'=> []]);

+ 1 - 1
app/Http/Controllers/Backend.php

@@ -56,7 +56,7 @@ class Backend extends BaseController
             $token = $request->headers->get('Authorization');
             $token = str_replace("Bearer ", null, $token);
             // JWT解密token
-            $jwt = new Jwt();
+            $jwt = new Jwt('jwt_yh');
             $userId = $jwt->verifyToken($token);
 
             // 登录验证

+ 1 - 1
app/Http/Middleware/UserLogin.php

@@ -31,7 +31,7 @@ class UserLogin extends Middleware
         if (strpos($token, 'Bearer ') !== false) {
             $token = str_replace("Bearer ", null, $token);
             // JWT解密token
-            $jwt = new Jwt();
+            $jwt = new Jwt('jwt_yh');
             $userId = $jwt->verifyToken($token);
         } else {
             $userId = 0;

+ 5 - 0
app/Models/ActivityModel.php

@@ -39,6 +39,11 @@ class ActivityModel extends BaseModel
                 $info['thumb'] = get_image_url($info['thumb']);
             }
 
+            $publishStart = isset($info['publish_start']) && $info['publish_start']? date('m月d日', strtotime($info['publish_start'])) : '';
+            $publishEnd = isset($info['publish_end']) && $info['publish_end']? date('m月d日', strtotime($info['publish_end'])) : '';
+            $info['publish_at'] = $publishStart==$publishEnd? $publishStart : ($publishStart && $publishEnd>$publishStart? $publishStart.'-'.$publishEnd : '');
+            $info['publish_at_text'] = $info['publish_start'] && $info['publish_end']? $info['publish_start'].'至'.$info['publish_end'] : '';
+
         }
         return $info;
     }

+ 13 - 9
app/Services/ActivityService.php

@@ -88,6 +88,12 @@ class ActivityService extends BaseService
             $data['thumb'] = str_replace(IMG_URL, "", $data['thumb']);
         }
 
+        if(isset($data['publish_at_text']) && $data['publish_at_text']){
+            $times = $data['publish_at_text'];
+            $data['publish_start'] = isset($times[0])? $times[0] : '';
+            $data['publish_end'] = isset($times[1])? $times[1] : '';
+        }
+
         $data['update_time'] = time();
         return parent::edit($data); // TODO: Change the autogenerated stub
     }
@@ -107,7 +113,7 @@ class ActivityService extends BaseService
         // 验证活动
         $aid = isset($params['id'])? intval($params['id']) : 0;
         $activityInfo = $this->model::where(['id'=> $aid, 'status'=> 1, 'mark'=> 1])
-            ->select(['id','type','price','status','publish_at'])
+            ->select(['id','type','price','status','publish_start','publish_end'])
             ->first();
 
         $activityInfo = $activityInfo? $activityInfo->toArray() : [];
@@ -116,13 +122,11 @@ class ActivityService extends BaseService
         }
 
         $coupon = isset($activityInfo['price'])? $activityInfo['price'] : 0;
-        $publishAt = isset($activityInfo['publish_at'])? $activityInfo['publish_at'] : '';
+        $publishStart = isset($activityInfo['publish_start'])? $activityInfo['publish_start'] : '';
+        $publishEnd = isset($activityInfo['publish_end'])? $activityInfo['publish_end'] : '';
         $type = isset($activityInfo['type'])? $activityInfo['type'] : 1;
-        $times = $publishAt? explode('-', $publishAt) : [];
-        $timeStart = isset($times[0])? $times[0] : '';
-        $timeEnd = isset($times[1])? $times[1] : '';
-        $curDate = date('m-d');
-        if($timeStart && $timeEnd && ($curDate< $timeStart || $curDate > $timeEnd)){
+        $curDate = date('Y-m-d');
+        if($publishStart && $publishEnd && ($curDate< $publishStart || $curDate > $publishEnd)){
             return message('活动已结束', false);
         }
 
@@ -176,12 +180,12 @@ class ActivityService extends BaseService
         }
 
         // 报名记录
-        if(!$bid = $this->bookModel::insert($data)){
+        if(!$bid = $this->bookModel::insertGetId($data)){
             DB::rollBack();
             return message('报名处理失败', false);
         }
 
         DB::commit();
-        return message('请上传活动图片', true, ['id'=> $bid]);
+        return message('活动报名成功', true, ['id'=> $bid]);
     }
 }

+ 1 - 1
app/Services/LoginService.php

@@ -145,7 +145,7 @@ class LoginService extends BaseService
         ActionLogModel::record();
 
         // JWT生成token
-        $jwt = new Jwt();
+        $jwt = new Jwt('jwt_yh');
         $token = $jwt->getToken($info['id']);
 
         // 结果返回