微信小程序后端,用户签到积分,每月一轮回

需求:连续签到1-2天5分,3-4天7分,5-6天9分,7天以上每天10分,每月一轮回。
只放个controller吧,其余都跟用户登录差不多,建表points签到表,用户表新增3个字段points、sign_days、sign_time

public function signAdd(Request $request, Point $point)
    {
        $user = Auth::guard('api')->user();
        $sign_time = Carbon::create($user->sign_time)->toDateString();
        $startOfMonth = Carbon::now()->startOfMonth()->day();
        $today = Carbon::today()->toDateString();
        $yesterday = Carbon::yesterday()->toDateString();
        if ($today == $sign_time) {
            return response()->json([
                'status' => false,
                'msg' => '今天已签到',
            ], 501);
        }
        if ($user->sign_time && $startOfMonth != '1' && $yesterday == $sign_time) {
            if ($user->sign_days == '0' || $user->sign_days == '1') {
                $points = '5';
            } elseif ($user->sign_days == '2' || $user->sign_days == '3') {
                $points = '7';
            } elseif ($user->sign_days == '4' || $user->sign_days == '5') {
                $points = '9';
            } elseif ($user->sign_days >= '6') {
                $points = '10';
            } else {
                $points = '5';
            }
            $attributes['updated_at'] = Carbon::now()->toDateTimeString();
            $attributes['banned_at'] = Carbon::now()->toDateTimeString();
            $attributes['sign_days'] = ($user->sign_days + 1);
            $attributes['sign_time'] = Carbon::now()->toDateTimeString();
            $attributes['points'] = ($user->points + $points);
            $user->update($attributes);
            $point->user_id = $user->id;
            $point->location_id = $request->location_id;
            $point->counts = $points;
            $point->model = request('model', 'Sign');
            $point->reason = request('reason', '签到');
            $point->fill($request->all());
            $point->save();
            return response()->json([
                'msg' => '签到成功',
                'userData' => $user
            ], 200);
        }
        $point->user_id = $user->id;
        $point->location_id = $request->location_id;
        $point->counts = '5';
        $point->model = request('model', 'Sign');
        $point->reason = request('reason', '签到啦');
        $point->fill($request->all());
        $point->save();

        $attributes['updated_at'] = Carbon::now()->toDateTimeString();
        $attributes['banned_at'] = Carbon::now()->toDateTimeString();
        $attributes['sign_days'] = '0';
        $attributes['sign_time'] = Carbon::now()->toDateTimeString();
        $attributes['points'] = ($user->points + 5);
        $user->update($attributes);
        return response()->json([
            'msg' => '签到成功',
            'userData' => $user
        ], 200);
    }
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!