/**
 * [OElove] (C)2010-2099 oelove.com Inc.biz
 * Email: service@phpcoo.com ,phpcoo@qq.com
 * $ Last update 2020/11/30 by CL $
*/
var inst_oerpzy = null;
$(function(){
    //开放平台
    function OERpzy () {
        //this.init();     
        this.clickTips();
    }
    
    OERpzy.prototype = {
        
        //初始化
        init:function() {
            var _this = this;
            setTimeout(function(){
                _this.getBalance();
            }, 100);
            
            setTimeout(function(){
                _this.getSmsNums();
            }, 200);
        },
        
        //关闭提示
        clickTips:function() {
            var _this = this;
            
            //关闭
            $(document).on("click", "[f='but_close_rpzy_tips']", function(){
                $("#rpzy_tips_dialog").hide();
            });
        },
        
        //获取帐户余额
        getBalance:function(){
            $.ajax({
                type: "POST",
                url: _ROOT_PATH+"index.php",
                cache: false,
                data: {
                    c:'rpzy', a:'balance'
                },
                dataType: "json",
                success: function(data) {
                    var response = data.response;
                    var result = data.result;
                    if (response == "1") {
                        //返回余额
                        result = parseFloat(result);
                        if (result < 20) {
                            $("#rpzy_balance_nums").html(result);
                            $("#rpzy_balance_tips").show();
                            $("#rpzy_tips_dialog").show();
                        }
                    }
                },
                error: function() {
                    
                }
            });
        },
        
        //获取短信余额
        getSmsNums:function() {
            $.ajax({
                type: "POST",
                url: _ROOT_PATH+"index.php",
                cache: false,
                data: {
                    m:'admin', c:'setting', a:'checkSmsBalance', type:'4'
                },
                dataType: "json",
                success: function(data) {
                    var response = data.response;
                    var result = data.result;
                    if (response == "1") {
                        //返回条数
                        
                        var yzm_nums = result.yzm_nums; //验证码短信
                        if (typeof(yzm_nums) == "undefined") {
                            yzm_nums = 0;
                        }
                        var yx_nums = result.yx_nums; //营销短信
                        if (typeof(yx_nums) == "undefined") {
                            yx_nums = 0;
                        }
                        
                        yzm_nums = parseInt(yzm_nums);
                        if (yzm_nums < 100) {
                            $("#rpzy_sms_nums").html(yzm_nums);
                            $("#rpzy_sms_tips").show();
                            $("#rpzy_tips_dialog").show();
                        }
                    }
                },
                error: function() {
                    
                }
            });
        }
        
        
    }
    inst_oerpzy = new OERpzy();
});
