<?php
/**
 * RoleController.php UTF-8
 * 角色上报
 *
 * @date    : 2018/1/16 16:51
 *
 * @license 这不是一个自由软件,未经授权不许任何使用和传播。
 * @author  : wuyonghong <wyh@huosdk.com>
 * @version : HUOSDK 8.0
 */

namespace mini\sdk\controller;

use huo\controller\member\MemCache;
use huo\controller\pay\PayShow;
use huo\controller\pay\PaySwitch;
use huolib\constant\CommonConst;
use huolib\constant\GameConst;
use huolib\constant\MemConst;
use huolib\constant\OrderConst;
use huolib\status\CommonStatus;
use huolib\status\MemberStatus;
use mini\common\controller\V2ApiBaseController;
use huo\controller\member\Role;
use think\Request;

class RoleController extends V2ApiBaseController {
    public function __construct(Request $request = null) {
        parent::__construct($request);
    }

    public function _initialize() {
        parent::_initialize();
    }

    /**
     * 上传角色信息
     * http://doc.1tsdk.com/159?page_id=4833
     * 【域名】/mp/user/uprole
     */
    public function save() {
        $this->checkLogin();
        $_game_rq = $this->setGameData();
        $_role_rq = $this->setRoleData();
        $_mem_rq = $this->setMemData();
        $_mem_rq->setMemId($this->mem_id);
        $_mem_data = MemCache::ins()->getInfoById($this->mem_id);
        if (isset($_mem_data['status']) && $_mem_data['status'] == MemConst::STATUS_FORBID) {
            $_code = MemberStatus::LOGIN_IS_OUT;
            $this->error(lang(MemberStatus::getMsg($_code)), [], $_code);
        }
        $_device_rq = $this->setDeviceData();
        $_role_class = new Role();
        $_rs = $_role_class->insertLog($_mem_rq, $_role_rq, $_game_rq, 0.00, $_device_rq);
        if (false !== $_rs) {
            $this->success(lang('SUCCESS'));
        }
        $this->error(lang('ERROR'));
    }

    /**
     * 获取角色充值控制
     * 【域名】/v8/user/checkpay
     * http://doc.1tsdk.com/159?page_id=9036
     */
    public function checkPay() {
        $this->checkLogin();
        $_game_rq = $this->setGameData();
        $_channel_rq = $this->setChannelData();
        $_mem_rq = $this->setMemData();
        $_role_rq = $this->setRoleData();
        $_order_rq = $this->setOrderData();
        $_device_rq = $this->setDeviceData();
        $_pay_check = OrderConst::PAY_SWITCH_NO;
        /* 判断支付切换 */
        if (GameConst::GAME_MP_GAME == $_game_rq->getPkgName()) {
            $_pay_switch = new PaySwitch();
            $_pay_check = $_pay_switch->getPaySwitch(
                $_order_rq, $_role_rq, $_mem_rq, $_game_rq, $_channel_rq, $_device_rq
            );
            $_pay_check = $_pay_switch->checkShowPay($_pay_check, $_device_rq);
            $_pay_show = new PayShow();
            $_show_status = $_pay_show->getPayShow(
                $_order_rq, $_role_rq, $_mem_rq, $_game_rq, $_channel_rq, $_device_rq
            );
            if (CommonConst::STATUS_NO == $_show_status) {
                $_pay_check = OrderConst::PAY_SWITCH_IOS_NO;
            }
        }
        $_r_data = [
            'check' => $_pay_check
        ];
        $_code = CommonStatus::NO_ERROR;
        $this->success(CommonStatus::getMsg($_code), $_r_data, $_code);
    }
}