<?php

namespace App\Http\Controllers\V1;
use App\Models\User;
use App\Models\UserMember;
use App\Models\UserMemberOrder;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

/**
 * 会员
 */
class MemberController extends Controller
{
    public function __construct()
    {
        $this->user = auth('api')->user();
        $this->userId = $this->user ? $this->user->id : 0;

        //如果用户被删除，会自动退出登录
        if (!empty($this->user->deleted_at)) {
            $this->user->online = 0;
            $this->user->save();
            auth('api')->logout();
        }
    }

    /**
     * @return void
     * 会员选项
     */
    public function memberList(Request $request){

        $list = UserMember::query()->get();

        return $this->success($list);

    }

    /**
     * @return void
     * 加入会员
     */
    public function joinMember(Request $request){
        $params = $request->all();
        DB::beginTransaction();
        try {
            $user = User::query()->where('id',$this->userId)->first();
            $user->update($params);
            DB::commit();
        } catch (\Exception $e){
            DB::rollBack();
           return $this->error("保存失败！");
        }
       return $this->success();
    }

    /**
     * @return void
     * 支付构建
     */
    public function payment(){



    }

}
