<?php
/**
 * 小游戏相关业务
 */
use \GatewayWorker\Lib\Gateway;
require_once "./GatewayWorker/Function/Init.php";
class GameCrazyWorker extends Init{
    public function subCD($client_id,$data){
        $reqId = isset($data['httpIdentifier']) ? $data['httpIdentifier'] : '';
        $uid = oo::functions()->uint($data['uid']);
        $putNum = oo::functions()->uint($data['putNum']);
        $dropNum = oo::functions()->uint($data['dropNum']);
        $lostPidsStr = $data['lostPids'];
        $getPidsStr = $data['getPids'];
        if(empty($uid)){
            $return =  oo::response(errorCode::REQUEST_PARAM_ERROR);
        }else{
            $ts1 = oo::getMsectime();
            $return =oo::commonOprModel('coindozer')->sub($uid,$putNum,$dropNum,$lostPidsStr,$getPidsStr);
            $ts2 = oo::getMsectime();
            if(($ts2-$ts1)>1500){
                oo::logs()->debug3(['time'=>date("Y-m-d H:i:s"),"uid"=>$data['uid'],"expend_ts"=>($ts2-$ts1),"type"=>"subCD"],'expend_ts_ws.log');
            }
        }
        $return = json_encode(['cmd'=>ocmd::$send['Game_subCD'],'data'=>json_decode($return,true), 'httpIdentifier' => $reqId],JSON_NUMERIC_CHECK);
        Gateway::sendToClient($client_id,$this->encryp($return));
    }

    public function useCDGameProp($client_id,$data){
        $uid = oo::functions()->uint($data['uid']);
        $type =oo::functions()->uint($data['type']);
        $reqId = isset($data['httpIdentifier']) ? $data['httpIdentifier'] : '';
        if(empty($uid)){
            $return =  oo::response(errorCode::REQUEST_PARAM_ERROR);
        }else{
            $return =json_encode(oo::commonOprModel('coindozer')->useProp($uid,$type));
        }
        $return = json_encode(['cmd'=>ocmd::$send['Game_useCDGameProp'],'data'=>json_decode($return,true), 'httpIdentifier' => $reqId],JSON_NUMERIC_CHECK);
        Gateway::sendToClient($client_id,$this->encryp($return));
    }

}
