<?php
/*
 * description：
 * author：wh
 * email：
 * createTime：{2024/6/2} {10:51} 
 */

namespace app\api\logic;


use app\common\model\TabConf;
use think\Db;
use wanghua\general_utility_tools_php\Mmodel;

/**
 * 用户离线奖品表（用户上线时写入，领取后删除）
 * Class UserOfflinePrizeLogic
 * @package app\api\logic
 */
class UserOfflinePrizeLogic
{

    /**
     * desc：查询最早的一条奖品数据
     * author：wh
     * @param $openid
     */
    static function getFirstPrizeRecord($openid){
        return Db::table(TabConf::$fa_user_offline_prize)
            ->where('openid',$openid)
            ->order('id asc')
            ->find();
    }
    /**
     * desc：用户上线时写入奖品(存在则num加1)
     * author：wh
     */
    static function insertPrize($openid,$gameprop_id,$num){
        //
        $prize = Db::table(TabConf::$fa_user_offline_prize)
            ->where('openid',$openid)
            ->where('gameprop_id',$gameprop_id)
            ->find();
        if($prize){
            Db::table(TabConf::$fa_user_offline_prize)
                ->where('id',$prize['id'])
                ->setInc('num',$num);
        }else{
            Db::table(TabConf::$fa_user_offline_prize)
                ->insert([
                    'openid'=>$openid,
                    'gameprop_id'=>$gameprop_id,
                    'num'=>$num
                ]);
        }
    }

    /**
     * desc：领取后删除
     * author：wh
     * @param $openid
     */
    static function deletedPrize($openid){
        Db::table(TabConf::$fa_user_offline_prize)
            ->where('openid',$openid)
            ->delete();
    }
}