<?php

/**
 * Created by PhpStorm.
 * User: z-yang
 * Date: 2018/7/16
 * Time: 13:44
 */
namespace App\Modules\Welfare\Services;

use App\Modules\Welfare\Models\WelfarePrize;

class WelfarePriceSerivce
{
    /**
     * 商户可不可以抽奖
     * @param int $channel_user_id
     * @param $date
     * @return int
     */
     public static function isCanPrize(int $channel_user_id,$date):int{
         $info = WelfarePrize::where('channel_user_id',$channel_user_id)->where('date',$date)->select('left','num')->first();
         if($info){
             return $info->left;
         }
         return -1;
     }


     public static function create(array $data){
         if( WelfarePrize::where('channel_user_id',$data['channel_user_id'])->where('date',$data['date'])->count()){
             return null;
         }
         return WelfarePrize::create($data);
     }

    public static function getByToday(int $channel_user_id){
        $info = WelfarePrize::where('channel_user_id',$channel_user_id)->where('date',date('Y-m-d'))->select('id','left','num')->first();
        return $info;
    }

    public static function decrementLeft($id){
        WelfarePrize::where('id', $id)->decrement('left');
    }
}