xiansin 4 лет назад
Родитель
Сommit
0e55fed150

+ 11 - 1
app/Http/Controllers/Api/SettingController.php

xqd
@@ -4,12 +4,22 @@ namespace App\Http\Controllers\Api;
 
 use App\Http\Controllers\Controller;
 use App\Models\Setting;
+use App\Models\ShareConfig;
 use Illuminate\Http\Request;
 
 class SettingController extends Controller
 {
     public function get()
     {
-        return out(Setting::orderBy('id','desc')->first());
+        $shareConfig = ShareConfig::orderBy('id','asc')->first()->toArray();
+        $setting = Setting::orderBy('id','asc')->first()->toArray();
+        $data = [
+            'origin_member_price' => $setting['origin_member_price'],
+            'member_price' => $setting['member_price'],
+            'service_wechat' => $setting['service_wechat'],
+            'service_qrcode' => $setting['service_qrcode'],
+            'open_share' => $shareConfig['is_open'],
+        ];
+        return out($data);
     }
 }

+ 32 - 5
app/Http/Controllers/Api/UserController.php

xqd xqd xqd xqd xqd
@@ -13,7 +13,10 @@ class UserController extends Controller
 {
     public function get()
     {
-        return out();
+        $user = auth('api')->user();
+
+        $user = User::with(['parent'])->where('id',$user['id'])->first()->toArray();
+        return out($user);
     }
 
 
@@ -22,14 +25,17 @@ class UserController extends Controller
     {
         $user = auth('api')->user();
 
-        $record = UserVip::where('user_id',$user['id'])->first()->toArray();
+        $record = UserVip::where('user_id',$user['id'])
+            ->where('status',1)
+            ->first()
+            ->toArray();
         if(empty($record)){
             return out();
         }
 
         return out([
             'order_fee' => $record['order_fee'],
-            'buy_time' => $record['created_at'],
+            'buy_time' => $record['pay_at'],
         ]);
     }
 
@@ -38,7 +44,7 @@ class UserController extends Controller
     {
         $user = auth('api')->user();
 
-        $user = User::where('user_id',$user['id'])->first()->toArray();
+        $user = User::where('id',$user['id'])->first()->toArray();
 
         return out([
             'overage' => $user['overage'],
@@ -102,7 +108,7 @@ class UserController extends Controller
             if($order->status == 0){
                 $data = $jssdk->bridgeConfig($order->prepay_id,false);
             }else{
-                throw new \Exception('您已经是会员了');
+                return out([],10013,'您已经是会员了!');
             }
 
             \DB::commit();
@@ -113,4 +119,25 @@ class UserController extends Controller
 
         return out($data);
     }
+
+    // 查询购买订单
+    public function query()
+    {
+        $user = auth('api')->user();
+        $order = UserVip::where('user_id', $user['id'])->first()->toArray();
+        return out($order);
+    }
+
+    public function shares()
+    {
+        $user = auth('api')->user();
+        $builder = User::where('parent_id', $user['id'])->orderBy('become_child_at','desc');
+        $data = $builder->paginate($req['per_page'] ?? 15);
+        $total_num = $builder->sum('id');
+        $custom = collect([
+            'total_num'   => $total_num,
+        ]);
+        $data = $custom->merge($data);
+        return out($data);
+    }
 }

+ 7 - 6
app/Http/Controllers/Api/Withdraws.php → app/Http/Controllers/Api/WithdrawController.php

xqd xqd
@@ -7,7 +7,7 @@ use App\Models\User;
 use App\Models\UserWithdraw;
 use Illuminate\Http\Request;
 
-class Withdraws extends Controller
+class WithdrawController extends Controller
 {
     public function apply()
     {
@@ -22,16 +22,17 @@ class Withdraws extends Controller
         {
             $user = auth('api')->user();
 
-            $user = User::where('user_id',$user['id'])->first()->toArray();
-
-            $userWithdraw = new UserWithdraw();
+            $user = User::where('id',$user['id'])->first()->toArray();
+            if($user['overage'] == 0){
+                throw new \Exception('暂无可提现金额');
+            }
             UserWithdraw::create([
+                'user_id' => $user['id'],
                 'name' => $req['name'],
                 'account' => $req['account'],
                 'price' => $user['overage'],
-                'desc' => $req['desc'],
+                'desc' => $req['remark'] ?? '',
             ]);
-            $userWithdraw->save();
 
 
             $user = User::find($user['id']);

+ 8 - 0
app/Http/Controllers/PaymentController.php

xqd xqd
@@ -8,6 +8,7 @@
 
 namespace App\Http\Controllers;
 
+use App\Models\User;
 use App\Models\UserVip;
 use EasyWeChat\Factory;
 use EasyWeChat\Kernel\Exceptions\Exception;
@@ -35,6 +36,13 @@ class PaymentController extends Controller
                 return $fail('通信失败,请稍后再通知我');
             }
 
+            if($order->status == 1){
+                $user = User::find($order->user_id);
+                $user->is_vip = 1;
+                $user->become_vip_at = time();
+                $user->save();
+            }
+
             $order->save();
             return true;
         });

+ 5 - 0
app/Models/User.php

xqd
@@ -106,4 +106,9 @@ class User extends Authenticatable implements JWTSubject
     {
         return [];
     }
+
+    public function parent()
+    {
+        return $this->belongsTo(User::class,'parent_id');
+    }
 }

+ 11 - 1
app/Models/UserWithdraw.php

xqd
@@ -38,5 +38,15 @@ class UserWithdraw extends Model
 {
 	use HasDateTimeFormatter;
     protected $table = 'user_withdraws';
-    
+
+    protected $fillable = [
+        'name',
+        'user_id',
+        'account',
+        'price',
+        'status',
+        'desc',
+        'check_at'
+    ];
+
 }

+ 3 - 2
routes/api.php

xqd xqd xqd
@@ -20,7 +20,7 @@ $api->version('v1', [
     //'middleware' => ['serializer:array', 'bindings']
 ], function($api) {
     // 上传不验证
-    $api->post('Common/uploadFile', 'CommonController@uploadFile');
+    // $api->post('Common/uploadFile', 'CommonController@uploadFile');
 
     // 限制登录和验证码接口请求频率
     $api->group([
@@ -28,7 +28,6 @@ $api->version('v1', [
         'limit'   => config('api.rate_limits.sign.limit'),
         'expires' => config('api.rate_limits.sign.expires'),
     ], function($api) {
-        // 短信验证码
         $api->any('passport/login', 'PassportController@login');
     });
 
@@ -40,6 +39,8 @@ $api->version('v1', [
     ], function($api) {
         $api->get('setting/get', 'SettingController@get');
         $api->get('user/get', 'UserController@get');
+        $api->get('user/query', 'UserController@query');
+        $api->get('user/shares', 'UserController@shares');
         $api->get('user/memberRecord', 'UserController@memberRecord');
         $api->get('user/overage', 'UserController@overage');
         $api->get('user/income', 'UserController@income');