xiaogang 4 سال پیش
والد
کامیت
14b745dc61

+ 1 - 1
app/Http/Controllers/Api/UploadConfigController.php

@@ -28,6 +28,6 @@ class UploadConfigController extends Controller
         $res['OSSAccessKeyId']=$config['access_id'];
         $res['OSSAccessKeyId']=$config['access_id'];
         $res['domain']="https://".$config['bucket'].'.'.$config['endpoint'];
         $res['domain']="https://".$config['bucket'].'.'.$config['endpoint'];
         $res['folder']="chengluApp";
         $res['folder']="chengluApp";
-        return response()->json($res)->setStatusCode(201);
+        return response()->json($res);
     }
     }
 }
 }

+ 27 - 0
app/Http/Controllers/Api/UserController.php

@@ -6,6 +6,7 @@ use App\Http\Params\ProblemParam;
 use App\Models\User;
 use App\Models\User;
 use App\Models\UserExtModel;
 use App\Models\UserExtModel;
 use App\Models\UserInfoModel;
 use App\Models\UserInfoModel;
+use App\Models\VipModel;
 use App\Services\UserService;
 use App\Services\UserService;
 use Illuminate\Http\Request;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\DB;
@@ -180,9 +181,35 @@ class UserController extends Controller
      * 获取VIP
      * 获取VIP
      */
      */
     public function get_vip(){
     public function get_vip(){
+        try {
+            $res = VipModel::query()->orderBy('id','asc')->get();
+            foreach ($res as $k=>$v){
+                $res[$k]['rights'] = json_decode($v['rights'],true);
+            }
+        }catch (\Exception $exception){
+            return $this->response->errorForbidden($exception->getMessage());
+        }
+        return response()->json($res);
+    }
 
 
+    /**
+     * 购买/续费vip
+     * @param Request $request
+     * @return \Illuminate\Http\JsonResponse|void
+     */
+    public function buy_vip(Request $request){
+        try {
+            $user = auth('api')->user();
+            $param['id'] = $request->id;
+            $param['user_id'] = $user->id;
+            $res = $this->userService->buy_vip($param);
+        }catch (\Exception $exception){
+            return $this->response->errorForbidden($exception->getMessage());
+        }
+        return response()->json($res);
     }
     }
 
 
+
     /**
     /**
      * 问题反馈
      * 问题反馈
      * @param Request $request
      * @param Request $request

+ 12 - 0
app/Models/PaymentLogModel.php

@@ -0,0 +1,12 @@
+<?php
+
+
+namespace App\Models;
+
+
+class PaymentLogModel extends BaseModel
+{
+    protected $table = 'payment_log';
+    protected $fillable = ['user_id', 'order_no','price','status','content','type','payment'];
+
+}

+ 12 - 0
app/Models/VipModel.php

@@ -0,0 +1,12 @@
+<?php
+
+
+namespace App\Models;
+
+
+class VipModel extends BaseModel
+{
+    protected $table = 'vip';
+
+    protected $fillable = ['title', 'price','day','day_price','rights'];
+}

+ 10 - 0
app/Services/PayService.php

@@ -0,0 +1,10 @@
+<?php
+
+
+namespace App\Services;
+
+
+class PayService
+{
+    //public function
+}

+ 25 - 0
app/Services/UserService.php

@@ -5,8 +5,10 @@ namespace App\Services;
 
 
 
 
 use App\Http\Params\ProblemParam;
 use App\Http\Params\ProblemParam;
+use App\Models\PaymentLogModel;
 use App\Models\UserLookModel;
 use App\Models\UserLookModel;
 use App\Models\UserProblemModel;
 use App\Models\UserProblemModel;
+use App\Models\VipModel;
 use PHPUnit\Util\Exception;
 use PHPUnit\Util\Exception;
 
 
 class UserService
 class UserService
@@ -39,4 +41,27 @@ class UserService
             ->paginate(request('perPage',20));
             ->paginate(request('perPage',20));
         return $res;
         return $res;
     }
     }
+
+    /**
+     * 购买vip
+     */
+    public function buy_vip($param){
+        if(empty($param['id'])){
+            throw new Exception("参数错误");
+        }
+        if(!$vip_info = VipModel::query()->where('id',$param['id'])->first()){
+            throw new Exception("VIP不存在");
+        }
+        $ins = array();
+        $ins['order_no'] = create_order_number();
+        $ins['user_id'] = $param['user_id'];
+        $ins['price'] = $vip_info['price'];
+        $ins['status'] = 0;
+        $ins['content'] = json_encode($vip_info);
+        $ins['type'] = 1;
+        if(!$order_id = PaymentLogModel::query()->insertGetId($ins)){
+            throw new Exception("插入订单失败");
+        }
+        return true;
+    }
 }
 }

+ 2 - 1
composer.json

@@ -19,7 +19,8 @@
         "spatie/laravel-activitylog": "^3.17",
         "spatie/laravel-activitylog": "^3.17",
         "tencent/tls-sig-api-v2": "1.0",
         "tencent/tls-sig-api-v2": "1.0",
         "tencentcloud/tencentcloud-sdk-php": "^3.0",
         "tencentcloud/tencentcloud-sdk-php": "^3.0",
-        "tymon/jwt-auth": "^1.0"
+        "tymon/jwt-auth": "^1.0",
+        "yansongda/pay": "^2.10"
     },
     },
     "require-dev": {
     "require-dev": {
         "facade/ignition": "^2.5",
         "facade/ignition": "^2.5",

+ 130 - 1
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
         "This file is @generated automatically"
     ],
     ],
-    "content-hash": "b7aeab616caaba4d1f629d1bc4c7f7f2",
+    "content-hash": "1cedd7f6b4a9a52ab91315cb7a09b0a2",
     "packages": [
     "packages": [
         {
         {
             "name": "asm89/stack-cors",
             "name": "asm89/stack-cors",
@@ -6603,6 +6603,135 @@
                 "source": "https://github.com/webmozarts/assert/tree/1.10.0"
                 "source": "https://github.com/webmozarts/assert/tree/1.10.0"
             },
             },
             "time": "2021-03-09T10:59:23+00:00"
             "time": "2021-03-09T10:59:23+00:00"
+        },
+        {
+            "name": "yansongda/pay",
+            "version": "v2.10.2",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/yansongda/pay.git",
+                "reference": "8c258853b142c6d7589629b047ca5cb21232b509"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/yansongda/pay/zipball/8c258853b142c6d7589629b047ca5cb21232b509",
+                "reference": "8c258853b142c6d7589629b047ca5cb21232b509",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "ext-bcmath": "*",
+                "ext-json": "*",
+                "ext-libxml": "*",
+                "ext-openssl": "*",
+                "ext-simplexml": "*",
+                "php": ">=7.1.3",
+                "symfony/event-dispatcher": "^4.0 || ^5.0",
+                "symfony/http-foundation": "^4.0 || ^5.0.7",
+                "yansongda/supports": "^2.0"
+            },
+            "require-dev": {
+                "friendsofphp/php-cs-fixer": "^2.15",
+                "mockery/mockery": "^1.2",
+                "phpunit/phpunit": "^7.5"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "Yansongda\\Pay\\": "src"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "yansongda",
+                    "email": "me@yansongda.cn"
+                }
+            ],
+            "description": "专注 Alipay 和 WeChat 的支付扩展包",
+            "keywords": [
+                "alipay",
+                "pay",
+                "wechat"
+            ],
+            "support": {
+                "issues": "https://github.com/yansongda/pay/issues",
+                "source": "https://github.com/yansongda/pay"
+            },
+            "time": "2021-01-18T01:48:43+00:00"
+        },
+        {
+            "name": "yansongda/supports",
+            "version": "v2.2.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/yansongda/supports.git",
+                "reference": "de9a8d38b0461ddf9c12f27390dad9a40c9b4e3b"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/yansongda/supports/zipball/de9a8d38b0461ddf9c12f27390dad9a40c9b4e3b",
+                "reference": "de9a8d38b0461ddf9c12f27390dad9a40c9b4e3b",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "guzzlehttp/guzzle": "^6.2 || ^7.0",
+                "monolog/monolog": "^1.23 || ^2.0",
+                "php": ">=7.1.3"
+            },
+            "require-dev": {
+                "friendsofphp/php-cs-fixer": "^2.15",
+                "phpunit/phpunit": "^7.5",
+                "predis/predis": "^1.1"
+            },
+            "suggest": {
+                "predis/predis": "Allows to use throttle feature"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "Yansongda\\Supports\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "yansongda",
+                    "email": "me@yansongda.cn"
+                }
+            ],
+            "description": "common components",
+            "keywords": [
+                "Guzzle",
+                "array",
+                "collection",
+                "config",
+                "http",
+                "support",
+                "throttle"
+            ],
+            "support": {
+                "issues": "https://github.com/yansongda/supports/issues",
+                "source": "https://github.com/yansongda/supports"
+            },
+            "time": "2020-10-14T08:17:18+00:00"
         }
         }
     ],
     ],
     "packages-dev": [
     "packages-dev": [

+ 1 - 0
routes/api.php

@@ -76,6 +76,7 @@ $api->version('v1', [
             $api->post('/updateext', 'UserController@updateext')->name('user.updateext');
             $api->post('/updateext', 'UserController@updateext')->name('user.updateext');
             $api->post('/problem', 'UserController@problem')->name('user.problem');
             $api->post('/problem', 'UserController@problem')->name('user.problem');
             $api->post('/looked_me', 'UserController@looked_me')->name('user.looked_me');
             $api->post('/looked_me', 'UserController@looked_me')->name('user.looked_me');
+            $api->get('/get_vip', 'UserController@get_vip')->name('user.get_vip');
 
 
         });
         });