| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 | <?php/** * Commonfunc.php UTF-8 * 公共函数 * * @date    : 2016年11月9日下午11:29:44 * * @license 这不是一个自由软件,未经授权不许任何使用和传播。 * @author  : wuyonghong <wyh@huosdk.com> * @version : HUOSDK 7.0 * @modified: 2016年11月9日下午11:29:44 */namespace huo\controller\common;use huo\controller\agent\AgentCache;use huo\controller\member\MemCache;use huolib\constant\GameConst;use wxapp\aes\ErrorCode;use wxapp\aes\WXBizDataCrypt;class CommonFunc {    /**     * 生成Order     *     * @param int    $mem_id     * @param string $agent_game     * @param int    $agent_id     * @param string $device_id     *     * @return int|string     */    public static function getAgentId($mem_id = 0, $agent_game = '', $agent_id = 0, $device_id = '') {        if (!empty($mem_id)) {            $_mem_data = MemCache::ins()->getInfoById($mem_id);            return $_mem_data['agent_id'];        }        if (empty($agent_id)) {            $agent_id = (new HuoSession($mem_id))->getAgentId();        }        if (!empty($agent_game)) {            /* 根据agentgame获得agent_id */            return AgentCache::ins()->getAgentIdByAg($agent_game);        }        /* 通过设备判定渠道归属 */        if (!empty($device_id)) {            // TODO: wuyonghong 2018/4/26 根据设备判定渠道归属            return $agent_id;        }        return $agent_id;    }    /**     * @return float 默认为1     */    public static function getPtbRmbRate() {        $_rate = config('ptb_rmb_rate');        if (empty($_rate)) {            $_rate = 1;        }        return $_rate;    }    /**     * @return float 默认为1     */    public static function getGmRmbRate() {        $_rate = config('gm_rmb_rate');        if (empty($_rate)) {            $_rate = 1;        }        return $_rate;    }    /**     * 获取金币与人民币比例     *     * @return float 默认为100     */    public static function getGoldRmbRate() {        $_rate = config('gold_rmb_rate');        if (empty($_rate)) {            $_rate = 100;        }        return $_rate;    }    /**     * 获取心跳时长     */    public static function getHeartbeatTime() {        $_g_heartbeat_time = config('G_HEARTBEAT_TIME');        if (empty($_g_heartbeat_time)) {            /* 默认时长300秒 */            return 300;        }        return $_g_heartbeat_time;    }    /**     * @param $classify     *     * @return array|int     */    public static function getAppAppId($classify = 0) {        $_and_app_id = config('app_app_id');        $_ios_app_id = config('ios_app_id');        switch ($classify) {            case GameConst::GAME_IOS:                return $_ios_app_id;            case GameConst::GAME_ANDROID:                return $_and_app_id;            default:                return [$_and_app_id, $_ios_app_id];        }    }    /**     * 从加密数据中获取unionid     *     * @param $app_key     * @param $session_key     *     * @return mixed|string     */    public static function getUnionIdByEncryptedData($app_key, $session_key) {        $_iv = request()->param('iv/s', '');        $_encrypted_data = request()->param('encrypted_data/s', '');        $_union_id = '';        if (!empty($_iv) && !empty($_encrypted_data)) {            $_wx_biz_data_crypt = new WXBizDataCrypt($app_key, $session_key);            $_err_code = $_wx_biz_data_crypt->decryptData($_encrypted_data, $_iv, $_wx_data);            if (ErrorCode::$OK == $_err_code) {                $_wx_data = json_decode($_wx_data, true);                $_union_id = get_val($_wx_data, 'unionId', '');            }        }        return $_union_id;    }    public static function safeDivMinValue($a, $b) {        $_div = $a - $b;        return ($_div < 0) ? 0 : $_div;    }}
 |