Exemple #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Init();
            if (Request.QueryString["cmd"] != null)
            {
                string result = string.Empty;
                string objId = Request.QueryString["cmd"].ToString();
                string postData = GetPostData();

                //  记录传入的参数日志
                //Tools.Log.SaveNoteInterface("接口调入:" + objId + "  " + postData);

                //  登陆时候自动绑定安汇通
                if (objId == "getUserLogin")
                {

                    new getUserLoginBLL().getUserLogin(postData);
                }

                //  线下交易订单验证通过,完成商家到账环节功能
                //
                if (objId == "setVerifyZeroSerial")
                {
                    bool outRes = new setVerifyZeroSerialBLL().setVerifyZeroSerial(postData);
                    if (!outRes)
                    {
                        Response.Write("{ \"status\": \"0\", \"statusMsg\": \"验证失败 \", \"returnData\": \"\"}");
                        Response.End();
                    }
                }

                //  上传
                if (objId == "setUploadImage")
                {
                    string jsonArray = postData;
                    JavaScriptSerializer ser = new JavaScriptSerializer();
                    UploadModel upmodel = ser.Deserialize<UploadModel>(jsonArray);
                    byte[] fs = Convert.FromBase64String(upmodel.Data);
                    UploadService.UploadService UpSer = new UploadService.UploadService();
                    UpSer.Url = System.Configuration.ConfigurationSettings.AppSettings["UploadService"].ToString();
                    string filepath = UpSer.UploadFile(fs);
                    result = "{ \"status\": \"1\", \"statusMsg\": \"\", \"returnData\": { \"url\": \"" + System.Configuration.ConfigurationSettings.AppSettings["StreetDomain"].ToString() + filepath + "\"  }}";
                }

                //  发短信
                else if (objId == "setTextToMobile")
                {
                    string jsonArray = postData;
                    JavaScriptSerializer ser = new JavaScriptSerializer();
                    SendMessageModel MessageModel = ser.Deserialize<SendMessageModel>(jsonArray);
                    string Phones = MessageModel.userMobile;
                    string Message = MessageModel.text;
                    MessageService.WebService ms = new MessageService.WebService();
                    ms.Url = System.Configuration.ConfigurationSettings.AppSettings["Message"].ToString();
                    ms.SendMessage2(Phones, Message);

                    //result = obj.QHGetStorageJson(userId, objId, postData);

                    result = "{ \"status\": \"1\", \"statusMsg\": \"\", \"returnData\": \"\"}";
                }
                else if (objId == "getSmsCaptcha")
                {
                    result = obj.QHGetStorageJson(userId, objId, postData).Replace("999999", "");
                    JavaScriptSerializer ser = new JavaScriptSerializer();
                    getSmsCaptchaReturnModel getSmsCaptchaModel = ser.Deserialize<getSmsCaptchaReturnModel>(result);

                    mobileModel mobileModel = ser.Deserialize<mobileModel>(postData);
                    string Phones = mobileModel.mobile;
                    string Message = "验证码:" + getSmsCaptchaModel.returnData.captcha;
                    MessageService.WebService ms = new MessageService.WebService();
                    ms.Url = System.Configuration.ConfigurationSettings.AppSettings["Message"].ToString();
                    ms.SendMessage2(Phones, Message);
                }

                //  获取用户的余额
                else if (objId == "getUserMoney")
                {
                    Log.SaveNote(postData);
                    result = new PayBLL().getUserMoney(postData);

                    //JavaScriptSerializer ser = new JavaScriptSerializer();
                    //getUserMoneyModel getUserMoneyModel = ser.Deserialize<getUserMoneyModel>(postData);

                    //string anhuitongUserid = "";

                    //string _result = "";

                    //string UserName = getUserMoneyModel.userId;

                    //object[] objs = new object[1];
                    //objs[0] = UserName;
                    //DataSet ds = obj.QHGetDataSet("                              ", "ZY_CRM_getAnhuitongIdByUserName", objs, out _result);
                    //if (ds != null)
                    //{
                    //    if (ds.Tables[0].Rows.Count > 0)
                    //        anhuitongUserid = ds.Tables[0].Rows[0]["anHuiTongId"].ToString();
                    //}

                    //if (string.IsNullOrEmpty(anhuitongUserid))
                    //{
                    //    result = "{ \"status\": \"1\", \"statusMsg\": \"\", \"returnData\": {\"money\":\"\"}}";
                    //}
                    //else
                    //{
                    //    //获取用户余额 和 冻结资金
                    //    //decimal BalanceMoney = PayServiceFun.GetPayBalance(anhuitongUserid)[0];
                    //    //decimal FreezeMoney = PayServiceFun.GetPayBalance(anhuitongUserid)[1];
                    //    decimal BalanceMoney = ZYPayClient.ZYPayClient.zyPayClient.GetPayBalance(anhuitongUserid)[0];
                    //    decimal FreezeMoney = ZYPayClient.ZYPayClient.zyPayClient.GetPayBalance(anhuitongUserid)[1];
                    //    //ZY.Pay.Model.ModelPayUser modelPayUser = PayServiceFun.GetPayUserByUserId(anhuitongUserid);
                    //    result = "{ \"status\": \"1\", \"statusMsg\": \"\", \"returnData\": {\"money\":\"" + BalanceMoney + "\"}}";
                    //}

                }
                //  获得安卓手机的版本信息
                else if (objId == "getVersionInfor")
                {
                    result = System.Configuration.ConfigurationSettings.AppSettings["AndroidGetNewVersion"].ToString();

                }
                //  获得安卓手机的 商户版的版本信息
                else if (objId == "getSellerVersionInfor")
                {
                    result = System.Configuration.ConfigurationSettings.AppSettings["AndroidGetNewVersion_Seller"].ToString();

                }
                //  获得苹果手机的版本信息
                else if (objId == "verifyVersion")
                {
                    decimal NowVersion = decimal.Parse(System.Configuration.ConfigurationSettings.AppSettings["AppVersion"].ToString());

                    JavaScriptSerializer ser = new JavaScriptSerializer();
                    verifyVersionModel verifyVersionModel = ser.Deserialize<verifyVersionModel>(postData);

                    if (decimal.Parse(verifyVersionModel.version) < NowVersion)
                    {
                        //result =  "{ \"status\": \"1\", \"statusMsg\": \"\", \"returnData\": {\"title\":\"有新的版本2.0\",\"statusMsg\":\"1:添加了付款功能,2:修复了bug\",\"content\":\"http://www.6618.com\",\"bUpdate\":\"0\"}}";
                        if (verifyVersionModel.type == "1")
                            result = System.Configuration.ConfigurationSettings.AppSettings["AppGetNewVersion1"].ToString();
                        if (verifyVersionModel.type == "0")
                            result = System.Configuration.ConfigurationSettings.AppSettings["AppGetNewVersion0"].ToString();
                    }
                    else
                    {
                        result = System.Configuration.ConfigurationSettings.AppSettings["AppVersionOK"].ToString();
                    }

                }

                //  获得苹果手机的版本信息 新版本接口
                else if (objId == "verifyVersionNew")
                {
                    decimal NowVersion = decimal.Parse(System.Configuration.ConfigurationSettings.AppSettings["IosVersion"].ToString());

                    JavaScriptSerializer ser = new JavaScriptSerializer();
                    verifyVersionModel verifyVersionModel = ser.Deserialize<verifyVersionModel>(postData);

                    if (decimal.Parse(verifyVersionModel.version) < NowVersion)
                    {
                        string title = System.Configuration.ConfigurationSettings.AppSettings["IosVersionTitle"].ToString();
                        string content = System.Configuration.ConfigurationSettings.AppSettings["IosVersionContent"].ToString();
                        string loadURL = "";
                        string bUpdate = "";

                        //  获取必须更新的版本号,这个号之前的版本都必须强制更新
                        decimal MustUpdateVersion = decimal.Parse(System.Configuration.ConfigurationSettings.AppSettings["IosMustUpdateVersion"].ToString());
                        if (decimal.Parse(verifyVersionModel.version) < MustUpdateVersion)
                        {
                            bUpdate = "1";
                        }
                        else
                        {
                            bUpdate = "0";
                        }

                        //  6618服务器下载地址
                        if (verifyVersionModel.type == "1")
                            loadURL = System.Configuration.ConfigurationSettings.AppSettings["IosVersionloadURL1"].ToString();
                        //  苹果服务器下载地址
                        if (verifyVersionModel.type == "0")
                            loadURL = System.Configuration.ConfigurationSettings.AppSettings["IosVersionLoadURL0"].ToString();

                        result = "{ \"status\": \"1\", \"statusMsg\": \"\", \"returnData\": {\"title\":\"" + title + "\",\"content\":\"" + content + "\",\"loadURL\":\"" + loadURL + "\",\"bUpdate\":\"" + bUpdate + "\"}}";

                    }
                    else
                    {
                        result = System.Configuration.ConfigurationSettings.AppSettings["AppVersionOK"].ToString();
                    }

                }

                else if (objId == "getWXAppSign")
                {

                    JavaScriptSerializer ser = new JavaScriptSerializer();
                    getWXAppSignModel getWXAppSignModel = ser.Deserialize<getWXAppSignModel>(postData);
                    string appid = "wxd98660017636f881";
                    string appkey = "ZTpqaqaJAbf8a4uzprzIhuTUhdvmdGid4YFotwf7aetmnIDrTf23FRGDO4mE6FyJtqu1dH3FxKzRyoeLP4kiIBgOmSUhKLlkb9rvx8dsJNkUmuBh1ALYObuILWGPwFgj";
                    string sss = "appid=" + appid + "&appkey=" + appkey + "&" + getWXAppSignModel.appinfo;

                    string keyval = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sss, "SHA1").ToLower();

                    result = "{ \"status\": \"1\", \"statusMsg\": \"\", \"returnData\": \"" + keyval + "\"}";
                }
                else if (objId == "getWXPackageSign")
                {
                    JavaScriptSerializer ser = new JavaScriptSerializer();
                    getWXPackageSignModel getWXPackageSignModel = ser.Deserialize<getWXPackageSignModel>(postData);
                    string partnerKey = "dc7fe2c701cb2aac39f59fd960db23f2";
                    string sss = getWXPackageSignModel.package + "key=" + partnerKey;

                    string keyval = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sss, "MD5");

                    result = "{ \"status\": \"1\", \"statusMsg\": \"\", \"returnData\": \"" + keyval + "\"}";
                }
                //  获取现金列表
                else if (objId == "getUserMoneyHistory")
                {
                    JavaScriptSerializer ser = new JavaScriptSerializer();
                    getUserMoneyHistoryModel getUserMoneyHistoryModel = ser.Deserialize<getUserMoneyHistoryModel>(postData);

                    string anhuitongUserid = "";
                    string _result = "";
                    string UserName = getUserMoneyHistoryModel.userId;
                    int pageIndex = int.Parse(getUserMoneyHistoryModel.pageIndex);
                    int pageSize = int.Parse(getUserMoneyHistoryModel.pageSize);

                    object[] objs = new object[1];
                    objs[0] = UserName;
                    DataSet ds = obj.QHGetDataSet("                              ", "ZY_CRM_getAnhuitongIdByUserName", objs, out _result);
                    if (ds != null)
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                            anhuitongUserid = ds.Tables[0].Rows[0]["anHuiTongId"].ToString();
                    }

                    DataSet dsMoneyHistory = ZYPayClient.ZYPayClient.zyPayClient.GetPayUserBalanceList(anhuitongUserid, "", pageSize, pageIndex);
                    DataTable dtMoneyHistory = dsMoneyHistory.Tables[0];
                    string toltal = dsMoneyHistory.Tables[1].Rows[0][0].ToString();

                    result = "{ \"status\": \"1\", \"statusMsg\": \"\", \"returnData\": {\"dataCount\":\"" + toltal + "\",\"moneyList\":[";
                    for (int i = 0; i < dtMoneyHistory.Rows.Count; i++)
                    {
                        string value11111 = "";
                        if (decimal.Parse(dtMoneyHistory.Rows[i]["InAmount"].ToString()) > 0)
                        {
                            value11111 = "+" + dtMoneyHistory.Rows[i]["InAmount"].ToString();
                        }
                        else
                        {
                            value11111 = "-" + dtMoneyHistory.Rows[i]["OutAmount"].ToString();
                        }
                        string _remark12312 = dtMoneyHistory.Rows[i]["Remark"].ToString();
                        if (_remark12312.IndexOf("<a href=http://passport.6618.com/member/User/OrderDetail.aspx") > -1)
                        {
                            _remark12312 = "支付商城订单[" + _remark12312.Substring(_remark12312.IndexOf("orderid=") + 9, (_remark12312.IndexOf('>') - _remark12312.IndexOf("orderid=") - 9)) + "]";
                        }
                        result += "{\"time\":\"" + dtMoneyHistory.Rows[i]["ActionTime"] + "\",\"type\":\""
                            + _remark12312 + "\",\"value\":\"" + value11111 + "\"},";
                    }
                    result = result.TrimEnd(',');
                    result += "]}}";

                }
                //  订单支付支付
                else if (objId == "setPayProduct")
                {
                    #region 支付
                    try
                    {
                        JavaScriptSerializer ser = new JavaScriptSerializer();
                        setPayProductModel setPayProductModel = ser.Deserialize<setPayProductModel>(postData);

                        //  获取订单编号
                        long orderId = Convert.ToInt64(setPayProductModel.orderId);
                        Log.SaveNote("余额支付订单:" + postData);
                        //获取支付密码
                        string password = setPayProductModel.payPwd;

                        //  0:左右商城  1:左右币抢购 2:限时抢购 3:店铺商品;
                        string orderType = setPayProductModel.orderType;

                        //  支付类型 1、余额支付   2、微信支付
                        string payType = setPayProductModel.payType;

                        //  左右币支付结果
                        string payStatus = "";

                        //MD5加密
                        //password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5");

                        //  获取安汇通账户
                        //
                        string anhuitongUserid = "";
                        string UserName = setPayProductModel.userId;
                        string UserId = "";

                        //  买家手机号
                        string buyerPhoneNumber = "";
                        //  卖家手机号
                        string sellerPhoneNumber = "";
                        //  验证码序列号
                        string VerificationCode = "";
                        //  店铺名称
                        string shopName = "";
                        //  购买数量
                        string buyNums = "";
                        //  产品名称
                        string productName = "";
                        //  收货地址
                        string ReceiveAddress = "";
                        //  收货人
                        string ReceiveName = "";
                        //  收货人手机号
                        string ReceivePhone = "";

                        object[] objs = new object[1];
                        objs[0] = UserName;
                        string _result111 = "";
                        DataTable dtUser = QHDBGetDataTable("                              ", "ZY_CRM_getUserDataByUserName", out _result111, objs);

                        if (dtUser.Rows.Count > 0)
                        {
                            anhuitongUserid = dtUser.Rows[0]["anHuiTongId"].ToString();
                            UserId = dtUser.Rows[0]["UserId"].ToString();
                        }

                        //  通过安汇通编号获取安汇通实体类数据
                        //
                        ZYPayUserCommon.PayUserClass PayUserModel = ZYPayClient.ZYPayClient.zyPayClient.GetPayUserByUserId(anhuitongUserid);

                        if (PayUserModel == null)
                        {
                            Response.Write("{ \"status\": \"0\", \"statusMsg\": \"您未绑定/未激活安汇通。\", \"returnData\": \"\"}");
                            Response.End();
                            //return alertFun("支付抢购订单", "您未绑定/未激活安汇通。");
                        }
                        //验证支付密码是否一致
                        if (PayUserModel.tradePassword != password)
                        {
                            Response.Write("{ \"status\": \"0\", \"statusMsg\": \"支付密码失败\", \"returnData\": \"\"}");
                            Response.End();
                            //return alertFun("支付抢购订单", "支付密码失败");
                        }

                        //  订单对应的商品编号
                        long goodsid__ = 0;
                        //  消费方式。1:到付 2:现付 3:线下消费
                        string Consumotion = "";
                        //  需要支付的左右币,商品类型【1:店铺商品。2:0元抢购商品。3:优惠券,4:限时抢购】
                        int zyCoin = 0, goodstype = 0;
                        //  需要支付的现金+运费
                        decimal Payment = 0, Freight = 0;
                        string result1212121212 = "";

                        //  抢购订单支付
                        if (orderType == "1" || orderType == "2" || orderType == "3")
                        {

                            //获取当前订单的所有信息
                            DataTable orderTable1 = QHDBGetDataTable("", "ZY_Street_GetZYCoinByOrderId", out result1212121212, orderId, UserId);
                            if (orderTable1 != null)
                            {
                                if (orderTable1.Rows.Count > 0)
                                {
                                    //订单需要支付的左右币数量
                                    zyCoin = DataConverter.ToInt32(ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable1.Rows[0], "ZYCoin"));
                                    //
                                    Payment = DataConverter.ToDecimal(ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable1.Rows[0], "Payment"));
                                    //
                                    Freight = DataConverter.ToDecimal(ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable1.Rows[0], "Freight"));
                                    //消费方式。1:到付 2:现付 3:线下消费
                                    Consumotion = orderTable1.Rows[0]["Consumotion"].ToString();

                                    //商品类型【1:店铺商品。2:0元抢购商品。3:优惠券,4:限时抢购】
                                    goodstype = DataConverter.ToInt32(ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable1.Rows[0], "goodstype"));
                                    //商品编号
                                    goodsid__ = DataConverter.ToLong(ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable1.Rows[0], "goodsid"));
                                }
                            }

                            //  重新获取下订单验证码
                            //
                            string result3333312 = "";
                            DataTable orderTable222212 = QHDBGetDataTable("", "ZY_Street_GetGoodsOrder", out result3333312, orderId);
                            if (orderTable222212 != null)
                            {
                                if (orderTable222212.Rows.Count > 0)
                                {
                                    //订单需要支付的左右币数量
                                    UserId = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable222212.Rows[0], "BuyerUserId");
                                    Log.SaveNote("userid=" + UserId);
                                    //  买家手机号
                                    buyerPhoneNumber = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable222212.Rows[0], "buyerPhoneNumber");
                                    //  卖家手机号
                                    sellerPhoneNumber = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable222212.Rows[0], "sellerPhoneNumber");
                                    //  验证码序列号
                                    VerificationCode = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable222212.Rows[0], "VerificationCode");
                                    //  店铺名称
                                    shopName = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable222212.Rows[0], "shopname");
                                    //  购买数量
                                    buyNums = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable222212.Rows[0], "buyNums");
                                    //  产品名称
                                    productName = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable222212.Rows[0], "Title");
                                    //  收货人手机号
                                    ReceivePhone = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable222212.Rows[0], "CellPhone");
                                    //  收货地址
                                    ReceiveAddress = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable222212.Rows[0], "Address");
                                    //  收货人
                                    ReceiveName = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable222212.Rows[0], "BuyerUserName");

                                }
                                else
                                {
                                    Log.SaveNote("未获取到该有效订单,可能订单状态存在问题");
                                    Response.Write("{ \"status\": \"0\", \"statusMsg\": \"未获取到该有效订单,可能订单状态存在问题!\", \"returnData\": \"\"}");
                                    //Response.Write("fail");
                                    Response.End();
                                }
                            }

                            //商品类型【1:店铺商品。2:0元抢购商品。3:优惠券,4:限时抢购】
                            if (goodstype == 2)
                            {
                                //现金是不需要的
                                Payment = 0;
                            }
                            //消费方式。1:到付 2:现付 3:线下消费
                            switch (DataConverter.ToInt32(Consumotion))
                            {
                                case 1:
                                    //需要支付现金跟左右币,不支付邮费
                                    Freight = 0;
                                    break;
                                case 2:
                                    //需要支付左右币跟现金跟邮费
                                    Payment += Freight;
                                    break;
                                case 3:
                                    //需要支付现金跟左右币,邮费强制为零
                                    Freight = 0;
                                    break;
                            }

                            if (Payment > 0)
                            {
                                //可用余额
                                decimal BalanceAmount = ZYPayClient.ZYPayClient.zyPayClient.GetBalanceDetail(anhuitongUserid).BalanceAmount;

                                //余额是否够支付
                                if (BalanceAmount < Payment && payType != "2")
                                {
                                    Response.Write("{ \"status\": \"0\", \"statusMsg\": \"您的可用现金不足\", \"returnData\": \"\"}");
                                    Response.End();
                                    //return alertFun("支付抢购订单", "您的可用现金不足");
                                }
                            }

                            //  如果支付类型是 微信全额支付,验证通过后就回复成功
                            //
                            if (payType == "2")
                            {
                                Response.Write("{ \"status\": \"1\", \"statusMsg\": \"验证成功\", \"returnData\": \"\"}");
                                Response.End();
                            }

                            //支付接口
                            //
                            //goodstype     商品类型【1:店铺商品。2:0元抢购商品。3:优惠券,4:限时抢购】
                            if (goodstype == 1)
                            {
                                payStatus = ZY.Street.BLL.PublicFun.BaseConn.QHRunTranObjToStr("", "ZY_Street_payshopgoodsOrder", orderId, UserId);
                            }
                            if (goodstype == 2)
                            {
                                //支付接口
                                payStatus = ZY.Street.BLL.PublicFun.BaseConn.QHRunTranObjToStr("", "ZY_Street_payordergoodsDetail", orderId, UserId, password);
                            }
                            if (goodstype == 3) { }
                            if (goodstype == 4)
                            {
                                payStatus = ZY.Street.BLL.PublicFun.BaseConn.QHRunTranObjToStr("", "ZY_Street_payFlashGoodsOrder", orderId, UserId);
                            }

                            //  重新获取下订单验证码
                            //
                            string result3333322321 = "";
                            DataTable orderTable22222231 = QHDBGetDataTable("", "ZY_Street_GetOrderVerificationCode", out result3333322321, orderId);
                            if (orderTable22222231 != null)
                            {
                                if (orderTable22222231.Rows.Count > 0)
                                {
                                    //  验证码序列号
                                    VerificationCode = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable22222231.Rows[0], "VerificationCode");
                                }
                            }

                        }
                        //  左右商城订单支付
                        else if (orderType == "0")
                        {
                            //获取当前订单的所有信息
                            DataTable orderTable1 = QHDBGetDataTable("", "ZY_Street_GetOrder", out result1212121212, orderId);
                            if (orderTable1 != null)
                            {
                                if (orderTable1.Rows.Count > 0)
                                {
                                    //订单需要支付的左右币数量
                                    zyCoin = DataConverter.ToInt32(ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable1.Rows[0], "Interal"));
                                    //
                                    Payment = DataConverter.ToDecimal(ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable1.Rows[0], "Payment"));
                                    //
                                    Freight = DataConverter.ToDecimal(ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable1.Rows[0], "Freight"));

                                    //商品编号
                                    goodsid__ = DataConverter.ToLong(ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable1.Rows[0], "goodsid"));
                                }
                                else
                                {
                                    Response.Write("{ \"status\": \"0\", \"statusMsg\": \"未获取到该有效订单,可能订单状态存在问题!\", \"returnData\": \"\"}");
                                    Response.End();
                                }
                            }
                            else
                            {
                                Response.Write("{ \"status\": \"0\", \"statusMsg\": \"未获取到该有效订单,可能订单状态存在问题!\", \"returnData\": \"\"}");
                                Response.End();
                            }
                            //  支付总金额=订单金额+邮费
                            Payment += Freight;
                            if (Payment > 0)
                            {
                                //可用余额
                                decimal BalanceAmount = ZYPayClient.ZYPayClient.zyPayClient.GetBalanceDetail(anhuitongUserid).BalanceAmount;

                                //余额是否够支付
                                if (BalanceAmount < Payment && payType != "2")
                                {
                                    Response.Write("{ \"status\": \"0\", \"statusMsg\": \"您的可用现金不足\", \"returnData\": \"\"}");
                                    Response.End();
                                    //return alertFun("支付抢购订单", "您的可用现金不足");
                                }
                            }

                            //  如果支付类型是 微信全额支付,验证通过后就回复成功
                            //
                            if (payType == "2")
                            {
                                Response.Write("{ \"status\": \"1\", \"statusMsg\": \"验证成功\", \"returnData\": \"\"}");
                                Response.End();
                            }

                            //  支付左右币和修改订单状态
                            //payStatus = ZY.Street.BLL.PublicFun.BaseConn.QHRunTranObjToStr("", "ZY_Street_payorder", orderId, UserId);

                            //  调用mallapi接口
                            MallApi.OrderApi bllMallOrderApi = new MallApi.OrderApi();
                            bllMallOrderApi.Url = System.Configuration.ConfigurationSettings.AppSettings["MallApi"].ToString();
                            payStatus = bllMallOrderApi.webPayOrder(orderId)[0];
                            if (payStatus == "支付成功")
                            {
                                Log.SaveNote("支付成功");
                                Response.Write("{ \"status\": \"1\", \"statusMsg\": \"支付成功\", \"returnData\": \"\"}");
                                Response.End();
                            }

                            //  调用CRM支付接口
                            if (payStatus == "" || payStatus == "true")
                                new OrderService.OrderService().PaymentOrder(orderId);
                            else
                            {
                                Log.SaveNote(payStatus);
                                Response.Write("{ \"status\": \"0\", \"statusMsg\": \"" + payStatus + "\", \"returnData\": \"\"}");
                                Response.End();
                            }

                        }

                        payStatus = payStatus.ToLower().Trim();

                        Log.SaveNote(payStatus);

                        //支付成功
                        if (payStatus == "" || payStatus == "true")
                        {
                            //goodstype     商品类型【1:店铺商品。2:0元抢购商品。3:优惠券,4:限时抢购】
                            if (Payment > 0)
                            {
                                //可用余额
                                decimal BalanceAmount = ZYPayClient.ZYPayClient.zyPayClient.GetBalanceDetail(anhuitongUserid).BalanceAmount;

                                //余额是否够支付
                                if (BalanceAmount >= Payment)
                                {
                                    //扣除费用
                                    if (orderType == "1" || orderType == "2" || orderType == "3")//抢购
                                    {
                                        long result1 = ZYPayClient.ZYPayClient.zyPayClient.PayByUserBalance(anhuitongUserid, orderId,
                                            6, "支付订单现金", Payment, "支付了[" + orderId + "]订单", "内部方法名:PayByUserBalance调用");

                                    }
                                    if (orderType == "0")//商城
                                    {
                                        long result1 = ZYPayClient.ZYPayClient.zyPayClient.PayByUserBalance(anhuitongUserid, orderId,
                                                                                   10000, "支付商城订单现金", Payment, "支付了[" + orderId + "]订单", "内部方法名:PayByUserBalance调用");
                                    }

                                    ////现金支付失败
                                    //if (result1 <= 0)
                                    //{
                                    //    //返回左右币
                                    //    string Status = ZY.Street.BLL.PublicFun.BaseConn.QHRunTranObjToStr("", "ZY_Street_payFlashGoodsZYCoin", orderId, UserId);
                                    //    Status = Status.ToLower().Trim();
                                    //    if (Status == "true")
                                    //    {
                                    //        Response.Write("{ \"status\": \"0\", \"statusMsg\": \"现金支付失败,请重新再试\", \"returnData\": \"\"}");
                                    //        Response.End();
                                    //    }
                                    //    else
                                    //    {
                                    //        Response.Write("{ \"status\": \"0\", \"statusMsg\": \"—支付失败,请重新再试2—\", \"returnData\": \"\"}");
                                    //        Response.End();
                                    //    }

                                    //}

                                    try
                                    {
                                        //  发送短信
                                        QHJsonDemo.cs.SendMsgTool.SendMsg(int.Parse(Consumotion), buyerPhoneNumber, sellerPhoneNumber, VerificationCode, shopName, buyNums, productName, ReceivePhone, ReceiveName, ReceiveAddress);
                                    }
                                    catch (Exception ex) { Log.SaveNote(ex.Message); }

                                    Response.Write("{ \"status\": \"1\", \"statusMsg\": \"支付成功\", \"returnData\": \"\"}");
                                    Response.End();
                                }
                                else
                                {
                                    //ZY.Street.BLL.PublicFun.BaseConn.ZY_Street_addRechargeStatus(Payment, "支付了[" + orderId + "]订单", "支付了[" + orderId + "]订单", 6, orderId, UserId);
                                    //Response.Write("{ \"status\": \"1\", \"statusMsg\": \"支付成功\", \"returnData\": \"\"}");
                                    //Response.End();
                                }
                            }
                            //  如果不需要支付现金则直接返回成功
                            if (Payment == 0)
                            {
                                try
                                {
                                    //  发送短信
                                    QHJsonDemo.cs.SendMsgTool.SendMsg(int.Parse(Consumotion), buyerPhoneNumber, sellerPhoneNumber, VerificationCode, shopName, buyNums, productName, ReceivePhone, ReceiveName, ReceiveAddress);
                                }
                                catch (Exception ex) { Log.SaveNote(ex.Message); }

                                Response.Write("{ \"status\": \"1\", \"statusMsg\": \"支付成功\", \"returnData\": \"\"}");
                                Response.End();
                            }
                            ////直接跳转到下一个web
                            //return "/NewHtml/aspx/PayStatus.aspx?orderId=" + orderId;
                        }
                        else
                        {
                            payStatus = payStatus.Replace("999999", "");
                            if (payStatus.ToLower() == "false")
                                payStatus = "订单支付失败,可能已支付或订单被关闭。";

                            Response.Write("{ \"status\": \"0\", \"statusMsg\": \"—订单支付失败,可能已支付或订单被关闭。—\", \"returnData\": \"\"}");
                            Response.End();
                            //return alertFun("支付抢购订单", "—" + payStatus + "—");
                        }
                    }
                    catch (Exception ex)
                    {
                        if (!(ex is System.Threading.ThreadAbortException))
                        {
                            Log.SaveNote(ex.ToString());
                        }
                    }

                    Response.Write("{ \"status\": \"0\", \"statusMsg\": \"—支付失败,请重新再试—\", \"returnData\": \"\"}");
                    Response.End();

                    #endregion

                }
                else if (objId == "setMallOrderClose")
                {
                    JavaScriptSerializer ser = new JavaScriptSerializer();
                    setMallOrderCloseModel setMallOrderCloseModel = ser.Deserialize<setMallOrderCloseModel>(postData);

                    string _result232 = ZY.Street.BLL.PublicFun.BaseConn.QHRunTranObjToStr("", "setScoreOrderClose", setMallOrderCloseModel.userId, setMallOrderCloseModel.userPwd, setMallOrderCloseModel.orderId, setMallOrderCloseModel.causeClose);
                    if (_result232 == "" || _result232 == "true")
                    {
                        new OrderService.OrderService().CloseOrder(long.Parse(setMallOrderCloseModel.orderId));
                        result = "{ \"status\": \"1\", \"statusMsg\": \"关闭成功\", \"returnData\": \"\"}";
                    }
                    else
                    {
                        result = "{ \"status\": \"0\", \"statusMsg\": \"关闭失败\", \"returnData\": \"\"}";
                    }
                }
                //  发送验证码短信
                else if (objId == "SendVerificationMsg")
                {
                    #region 发送验证码
                    JavaScriptSerializer ser = new JavaScriptSerializer();
                    SendVerificationMsgModel SendVerificationMsgModel = ser.Deserialize<SendVerificationMsgModel>(postData);

                    //  订单编号
                    long orderId = long.Parse(SendVerificationMsgModel.orderId);
                    //  买家手机号
                    string buyerPhoneNumber = "";
                    //  卖家手机号
                    string sellerPhoneNumber = "";
                    //  验证码序列号
                    string VerificationCode = "";
                    //  店铺名称
                    string shopName = "";
                    //  购买数量
                    string buyNums = "";
                    //  产品名称
                    string productName = "";
                    //  收货地址
                    string ReceiveAddress = "";
                    //  收货人
                    string ReceiveName = "";
                    //  收货人手机号
                    string ReceivePhone = "";
                    //  消费方式。1:到付 2:现付 3:线下消费
                    string Consumotion = "";

                    //  重新获取下订单验证码
                    //
                    string result3333312 = "";
                    DataTable orderTable222212 = QHDBGetDataTable("", "ZY_Street_GetGoodsOrder1", out result3333312, orderId);
                    if (orderTable222212 != null)
                    {
                        if (orderTable222212.Rows.Count > 0)
                        {
                            //  买家手机号
                            buyerPhoneNumber = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable222212.Rows[0], "buyerPhoneNumber");
                            //  卖家手机号
                            sellerPhoneNumber = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable222212.Rows[0], "sellerPhoneNumber");
                            //  验证码序列号
                            VerificationCode = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable222212.Rows[0], "VerificationCode");
                            //  店铺名称
                            shopName = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable222212.Rows[0], "shopname");
                            //  购买数量
                            buyNums = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable222212.Rows[0], "buyNums");
                            //  产品名称
                            productName = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable222212.Rows[0], "Title");
                            //  收货人手机号
                            ReceivePhone = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable222212.Rows[0], "CellPhone");
                            //  收货地址
                            ReceiveAddress = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable222212.Rows[0], "Address");
                            //  收货人
                            ReceiveName = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable222212.Rows[0], "BuyerUserName");
                            //消费方式。1:到付 2:现付 3:线下消费
                            Consumotion = orderTable222212.Rows[0]["Consumotion"].ToString();

                        }
                        else
                        {
                            Log.SaveNote("未获取到该有效订单,可能订单状态存在问题");
                            Response.Write("{ \"status\": \"0\", \"statusMsg\": \"未获取到该有效订单,可能订单状态存在问题!\", \"returnData\": \"\"}");
                            //Response.Write("fail");
                            Response.End();
                        }
                    }

                    try
                    {
                        //  发送短信
                        QHJsonDemo.cs.SendMsgTool.SendMsg(int.Parse(Consumotion), buyerPhoneNumber, sellerPhoneNumber, VerificationCode, shopName, buyNums, productName, ReceivePhone, ReceiveName, ReceiveAddress);
                    }
                    catch (Exception ex)
                    {
                        Log.SaveNote(ex.Message);
                        Response.Write("{ \"status\": \"1\", \"statusMsg\": \"发送出错 \", \"returnData\": \"\"}");
                    }

                    Response.Write("{ \"status\": \"1\", \"statusMsg\": \"发送成功 \", \"returnData\": \"\"}");

                    #endregion

                }
                //  提交商城订单
                else if (objId == "setScoreOrderConfirm")
                {
                    string _res = new setScoreOrderConfirmBLL().setScoreOrderConfirm(postData);
                    Response.Write(_res);
                    Response.End();
                }
                //  添加商品到购物车 逛逛去
                else if (objId == "setMyShoppingCartAdd")
                {
                    string _res = new ShoppingCartBLL().setMyShoppingCartAdd(postData);
                    Response.Write(_res);
                    Response.End();
                }
                //  删除购物车 逛逛去
                else if (objId == "delMyGoodsShopCart")
                {
                    string _res = new ShoppingCartBLL().delMyGoodsShopCart(postData);
                    Response.Write(_res);
                    Response.End();
                }
                //  修改左右商城商品购物车中某商品购买属性
                else if (objId == "setMyGoodsShopCartAttrib")
                {
                    string _res = new ShoppingCartBLL().setMyGoodsShopCartAttrib(postData);
                    Response.Write(_res);
                    Response.End();
                }

                //  查询商品物流费
                else if (objId == "getGoodsTransitMoney")
                {
                    string _res = new ShoppingCartBLL().getGoodsTransitMoney(postData);
                    Response.Write(_res);
                    Response.End();
                }
                //  提交逛逛去购物车
                else if (objId == "setMyShopCartOrder")
                {
                    string _res = new ShoppingCartBLL().setMyShopCartOrder(postData);
                    Response.Write(_res);
                    Response.End();
                }
                //  直接提交订单
                else if (objId == "setUserBuyGoods")
                {
                    Log.SaveNote(postData);
                    string _res = new ShoppingCartBLL().setUserBuyGoods(postData);
                    Response.Write(_res);
                    Response.End();
                }

                //  用户订单在线支付
                else if (objId == "setUserOrderOnlinePay")
                {
                    string _res = new PayBLL().addPayRecharge(postData);
                    Response.Write(_res);
                    Response.End();
                }

                //  用户订单余额支付
                else if (objId == "setUserOrderLeavePay")
                {
                    string _res = new PayBLL().setUserOrderLeavePay(postData);
                    Response.Write(_res);
                    Response.End();
                }

                //  获取订单支付状态
                else if (objId == "getUserOrderPayStatus")
                {
                    string _res = new PayBLL().getUserOrderPayStatus(postData);
                    Response.Write(_res);
                    Response.End();
                }
                //  获取服务器时间
                else if (objId == "getServerTime")
                {
                    string ServerDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                    result = "{ \"status\": \"1\", \"statusMsg\": \"\", \"returnData\": {\"time\":\"" + ServerDate + "\"}}";
                }
                //  获取服务器时间
                else if (objId == "getSqlServerTime")
                {
                    StreetOrderService.GoodsOrderService _sqlServiceTime = new StreetOrderService.GoodsOrderService();
                    _sqlServiceTime.Url = System.Configuration.ConfigurationSettings.AppSettings["StreetOrderService"].ToString();

                    result = "{ \"status\": \"1\", \"statusMsg\": \"\", \"returnData\": {\"time\":\"" + _sqlServiceTime.GetSqlServerTime() + "\"}}";
                }

                //  去火拼下单
                else if (objId == "setUserBuyCloud")
                {
                    string _res = new QHPBLL().setUserBuyCloud(postData);
                    Response.Write(_res);
                    Response.End();
                }

                //   伙拼商品确认收货
                else if (objId == "setUserCloudReceive")
                {
                    string _res = new QHPBLL().setUserCloudReceive(postData);
                    Response.Write(_res);
                    Response.End();
                }

                //   店铺订单确认收货
                else if (objId == "setUserOrderReceive")
                {
                    string _res = new GoodsOrderBLL().setUserOrderReceive(postData);
                    Response.Write(_res);
                    Response.End();
                }

                //  执行应用服务的操作 以上都是特殊接口
                else if (!string.IsNullOrEmpty(objId))
                {
                    //DateTime dtStart = System.DateTime.Now;

                    result = obj.QHGetStorageJson(userId, objId, postData).Replace("999999", "");

                    //System.TimeSpan ts1 = System.DateTime.Now - dtStart;
                    //string totalSecond = ts1.TotalMilliseconds.ToString();
                    //lbSpandTime.Text = totalSecond;
                }

                //  记录传入的参数日志
                //Tools.Log.SaveNoteInterface("接口名:" + objId + " " + "返回结果:" + result);

                Response.Write(result);
                Response.End();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //Tools.Log.SaveNote("in");
            Tools.Log.SaveNote(Request.Url.ToString());
            string sign_type = Request.QueryString["sign_type"];
            string service_version = Request.QueryString["service_version"];
            string input_charset = Request.QueryString["input_charset"];
            string sign = Request.QueryString["sign"];
            string sign_key_index = Request.QueryString["sign_key_index"];
            string trade_mode = Request.QueryString["trade_mode"];
            string trade_state = Request.QueryString["trade_state"];
            string pay_info = Request.QueryString["pay_info"];
            string partner = Request.QueryString["partner"];
            string bank_type = Request.QueryString["bank_type"];
            string bank_billno = Request.QueryString["bank_billno"];
            string total_fee = Request.QueryString["total_fee"];
            string fee_type = Request.QueryString["fee_type"];
            string notify_id = Request.QueryString["notify_id"];
            string transaction_id = Request.QueryString["transaction_id"];
            string out_trade_no = Request.QueryString["out_trade_no"];
            string attach = Request.QueryString["attach"];
            string time_end = Request.QueryString["time_end"];
            string transport_fee = Request.QueryString["transport_fee"];
            string product_fee = Request.QueryString["product_fee"];
            string discount = Request.QueryString["discount"];
            string buyer_alias = Request.QueryString["buyer_alias"];

            string res = "";
            res += "sign_type=" + sign_type + " ";
            res += "service_version=" + service_version + " ";
            res += "input_charset=" + input_charset + " ";
            res += "sign=" + sign + " ";
            res += "sign_key_index=" + sign_key_index + " ";
            res += "trade_mode=" + trade_mode + " ";
            res += "trade_state=" + trade_state + " ";
            res += "pay_info=" + pay_info + " ";
            res += "partner=" + partner + " ";
            res += "bank_type=" + bank_type + " ";
            res += "bank_billno=" + bank_billno + " ";
            res += "total_fee=" + (decimal.Parse(total_fee) / 100) + " ";
            res += "fee_type=" + fee_type + " ";
            res += "notify_id=" + notify_id + " ";
            res += "transaction_id=" + transaction_id + " ";
            res += "out_trade_no=" + out_trade_no + " ";
            res += "attach=" + attach + " ";
            res += "time_end=" + time_end + " ";
            res += "transport_fee=" + transport_fee + " ";
            res += "product_fee=" + product_fee + " ";
            res += "discount=" + discount + " ";
            res += "buyer_alias=" + buyer_alias + " ";

            Tools.Log.SaveNote(res);

            try
            {

                //  获取订单编号
                long orderId = Convert.ToInt64(out_trade_no.Split('_')[1]);
                Log.SaveNote(orderId.ToString());
                //获取支付密码
                string password = "";

                //  0:左右商城  1:左右币抢购 2:限时抢购 3:店铺商品
                string orderType = out_trade_no.Split('_')[0];
                Log.SaveNote(orderType);
                //  支付类型
                //string payType = setPayProductModel.payType;

                //  左右币支付结果
                string payStatus = "";

                //MD5加密
                //password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5");

                //  获取安汇通账户
                //
                string anhuitongUserid = "";
                string UserName = "";
                string UserId = "";

                //  买家手机号
                string buyerPhoneNumber = "";
                //  卖家手机号
                string sellerPhoneNumber = "";
                //  验证码序列号
                string VerificationCode = "";
                //  店铺名称
                string shopName = "";
                //  购买数量
                string buyNums = "";
                //  产品名称
                string productName = "";
                //  收货地址
                string ReceiveAddress = "";
                //  收货人
                string ReceiveName = "";
                //  收货人手机号
                string ReceivePhone = "";

                //  获取用户编号  UserId
                if (orderType == "0")
                {
                    string result33333 = "";
                    DataTable orderTable2222 = QHDBGetDataTable("", "ZY_Street_GetOrder", out result33333, orderId);
                    if (orderTable2222 != null)
                    {
                        if (orderTable2222.Rows.Count > 0)
                        {
                            //订单需要支付的左右币数量
                            UserId = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable2222.Rows[0], "BuyerUserId");
                            Log.SaveNote(UserId);
                        }
                        else
                        {
                            Log.SaveNote("未获取到该有效订单,可能订单状态存在问题");
                            //Response.Write("{ \"status\": \"0\", \"statusMsg\": \"未获取到该有效订单,可能订单状态存在问题!\", \"returnData\": \"\"}");
                            Response.Write("fail");
                            Response.End();
                        }
                    }
                }
                if (orderType == "1" || orderType == "2" || orderType == "3")
                {
                    string result33333 = "";
                    DataTable orderTable2222 = QHDBGetDataTable("", "ZY_Street_GetGoodsOrder", out result33333, orderId);
                    if (orderTable2222 != null)
                    {
                        if (orderTable2222.Rows.Count > 0)
                        {
                            //订单需要支付的左右币数量
                            UserId = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable2222.Rows[0], "BuyerUserId");
                            Log.SaveNote("userid=" + UserId);
                            //  买家手机号
                            buyerPhoneNumber = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable2222.Rows[0], "buyerPhoneNumber");
                            //  卖家手机号
                            sellerPhoneNumber = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable2222.Rows[0], "sellerPhoneNumber");
                            //  验证码序列号
                            VerificationCode = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable2222.Rows[0], "VerificationCode");
                            //  店铺名称
                            shopName = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable2222.Rows[0], "shopname");
                            //  购买数量
                            buyNums = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable2222.Rows[0], "buyNums");
                            //  产品名称
                            productName = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable2222.Rows[0], "Title");
                            //  收货人手机号
                            ReceivePhone = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable2222.Rows[0], "CellPhone");
                            //  收货地址
                            ReceiveAddress = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable2222.Rows[0], "Address");
                            //  收货人
                            ReceiveName = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable2222.Rows[0], "BuyerUserName");

                        }
                        else
                        {
                            Log.SaveNote("未获取到该有效订单,可能订单状态存在问题");
                            //Response.Write("{ \"status\": \"0\", \"statusMsg\": \"未获取到该有效订单,可能订单状态存在问题!\", \"returnData\": \"\"}");
                            Response.Write("fail");
                            Response.End();
                        }
                    }
                }

                if (string.IsNullOrEmpty(UserId))
                {
                    Log.SaveNote("订单账户不存在");
                    //Response.Write("{ \"status\": \"0\", \"statusMsg\": \"订单账户不存在!\", \"returnData\": \"\"}");
                    Response.Write("fail");
                    Response.End();
                }

                object[] objs = new object[1];
                objs[0] = UserId;
                string _result111 = "";
                DataTable dtUser = QHDBGetDataTable("                              ", "ZY_CRM_getUserData", out _result111, objs);

                if (dtUser.Rows.Count > 0)
                {
                    anhuitongUserid = dtUser.Rows[0]["anHuiTongId"].ToString();
                    UserName = dtUser.Rows[0]["UserName"].ToString();
                    password = dtUser.Rows[0]["Password"].ToString();
                }

                //  通过安汇通编号获取安汇通实体类数据
                //

                ZYPayUserCommon.PayUserClass PayUserModel = ZYPayClient.ZYPayClient.zyPayClient.GetPayUserByUserId(anhuitongUserid);

                if (PayUserModel == null)
                {
                    Log.SaveNote("您未绑定/未激活安汇通。");
                    //Response.Write("{ \"status\": \"0\", \"statusMsg\": \"您未绑定/未激活安汇通。\", \"returnData\": \"\"}");
                    Response.Write("fail");
                    Response.End();
                    //return alertFun("支付抢购订单", "您未绑定/未激活安汇通。");
                }

                //  给安汇通先充值
                //
                decimal income = (decimal.Parse(total_fee) / 100);

                //  添加充值记录
                int isPayedWeixinRecharge = int.Parse(QHDBGetDataTable("                              ", "ZY_Street_IsWeixinRecharged", out _result111, orderId, orderType).Rows[0][0].ToString());

                if (isPayedWeixinRecharge == 0)
                {
                    string rrerer = ZY.Street.BLL.PublicFun.BaseConn.QHRunTranObjToStr("", "ZY_Street_addWeixinRecharge", orderId, income, orderType);
                    Log.SaveNote("微信充值记录:" + rrerer + " orderid:" + orderId + " income:" + income + " ordertype:" + orderType);

                    //  给安汇通先充值
                    //  如果充值记录里面这个订单没有充值过
                    ZYPayClient.ZYPayClient.zyPayClient.RechargeByWeixin(anhuitongUserid, orderId, "", income);
                }

                //验证支付密码是否一致
                //if (PayUserModel.tradePassword != password)
                //{
                //    Response.Write("{ \"status\": \"0\", \"statusMsg\": \"支付密码失败\", \"returnData\": \"\"}");
                //    Response.End();
                //}

                //  订单对应的商品编号
                long goodsid__ = 0;
                //  消费方式。1:到付 2:现付 3:线下消费
                string Consumotion = "";
                //  需要支付的左右币,商品类型【1:店铺商品。2:0元抢购商品。3:优惠券,4:限时抢购】
                int zyCoin = 0, goodstype = 0;
                //  需要支付的现金+运费
                decimal Payment = 0, Freight = 0;
                string result1212121212 = "";

                //  抢购订单支付
                if (orderType == "1" || orderType == "2" || orderType == "3")
                {
                    //获取当前订单的所有信息
                    DataTable orderTable1 = QHDBGetDataTable("", "ZY_Street_GetZYCoinByOrderId", out result1212121212, orderId, UserId);
                    if (orderTable1 != null)
                    {
                        if (orderTable1.Rows.Count > 0)
                        {
                            //订单需要支付的左右币数量
                            zyCoin = DataConverter.ToInt32(ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable1.Rows[0], "ZYCoin"));
                            //
                            Payment = DataConverter.ToDecimal(ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable1.Rows[0], "Payment"));
                            //
                            Freight = DataConverter.ToDecimal(ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable1.Rows[0], "Freight"));
                            //消费方式。1:到付 2:现付 3:线下消费
                            Consumotion = orderTable1.Rows[0]["Consumotion"].ToString();

                            //商品类型【1:店铺商品。2:0元抢购商品。3:优惠券,4:限时抢购】
                            goodstype = DataConverter.ToInt32(ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable1.Rows[0], "goodstype"));
                            //商品编号
                            goodsid__ = DataConverter.ToLong(ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable1.Rows[0], "goodsid"));
                        }
                    }
                    //商品类型【1:店铺商品。2:0元抢购商品。3:优惠券,4:限时抢购】
                    if (goodstype == 2)
                    {
                        //现金是不需要的
                        Payment = 0;
                    }
                    //消费方式。1:到付 2:现付 3:线下消费
                    switch (DataConverter.ToInt32(Consumotion))
                    {
                        case 1:
                            //需要支付现金跟左右币,不支付邮费
                            Freight = 0;
                            break;
                        case 2:
                            //需要支付左右币跟现金跟邮费
                            Payment += Freight;
                            break;
                        case 3:
                            //需要支付现金跟左右币,邮费强制为零
                            Freight = 0;
                            break;
                    }

                    if (Payment > 0)
                    {
                        //可用余额
                        decimal BalanceAmount = ZYPayClient.ZYPayClient.zyPayClient.GetBalanceDetail(anhuitongUserid).BalanceAmount;

                        //余额是否够支付
                        if (BalanceAmount < Payment)
                        {
                            Log.SaveNote("您的可用现金不足");
                            //Response.Write("{ \"status\": \"0\", \"statusMsg\": \"您的可用现金不足\", \"returnData\": \"\"}");
                            Response.Write("fail");
                            Response.End();
                            //return alertFun("支付抢购订单", "您的可用现金不足");
                        }
                    }

                    //支付接口
                    //
                    //goodstype     商品类型【1:店铺商品。2:0元抢购商品。3:优惠券,4:限时抢购】
                    if (goodstype == 1)
                    {
                        payStatus = ZY.Street.BLL.PublicFun.BaseConn.QHRunTranObjToStr("", "ZY_Street_payshopgoodsOrder", orderId, UserId);
                    }
                    if (goodstype == 2)
                    {
                        //支付接口
                        payStatus = ZY.Street.BLL.PublicFun.BaseConn.QHRunTranObjToStr("", "ZY_Street_payordergoodsDetail", orderId, UserId, password);
                    }
                    if (goodstype == 3) { }
                    if (goodstype == 4)
                    {
                        payStatus = ZY.Street.BLL.PublicFun.BaseConn.QHRunTranObjToStr("", "ZY_Street_payFlashGoodsOrder", orderId, UserId);
                    }

                    //  重新获取下订单验证码
                    //
                    string result3333322321 = "";
                    DataTable orderTable22222231 = QHDBGetDataTable("", "ZY_Street_GetOrderVerificationCode", out result3333322321, orderId);
                    if (orderTable22222231 != null)
                    {
                        if (orderTable22222231.Rows.Count > 0)
                        {
                            //  验证码序列号
                            VerificationCode = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable22222231.Rows[0], "VerificationCode");
                        }
                    }

                }
                //  左右商城订单支付
                else if (orderType == "0")
                {

                    //获取当前订单的所有信息
                    DataTable orderTable1 = QHDBGetDataTable("", "ZY_Street_GetOrder", out result1212121212, orderId);
                    if (orderTable1 != null)
                    {
                        if (orderTable1.Rows.Count > 0)
                        {
                            //订单需要支付的左右币数量
                            zyCoin = DataConverter.ToInt32(ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable1.Rows[0], "Interal"));
                            //
                            Payment = DataConverter.ToDecimal(ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable1.Rows[0], "Payment"));
                            //
                            Freight = DataConverter.ToDecimal(ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable1.Rows[0], "Freight"));

                            //商品编号
                            goodsid__ = DataConverter.ToLong(ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable1.Rows[0], "goodsid"));

                            //  如果是到付邮费的,则不计算邮费
                            string CashOnDelivery = ZY.Street.BLL.PublicFun.PublicFun.GetDrVal(orderTable1.Rows[0], "CashOnDelivery");
                            if (CashOnDelivery == "1")
                                Freight = 0;

                        }
                        else
                        {
                            Log.SaveNote("未获取到该有效订单,可能订单状态存在问题");
                            //Response.Write("{ \"status\": \"0\", \"statusMsg\": \"未获取到该有效订单,可能订单状态存在问题!\", \"returnData\": \"\"}");
                            Response.Write("fail");
                            Response.End();
                        }
                    }
                    else
                    {
                        Log.SaveNote("未获取到该有效订单,可能订单状态存在问题");
                        //Response.Write("{ \"status\": \"0\", \"statusMsg\": \"未获取到该有效订单,可能订单状态存在问题!\", \"returnData\": \"\"}");
                        Response.Write("fail");
                        Response.End();
                    }
                    //  支付总金额=订单金额+邮费
                    Payment += Freight;
                    if (Payment > 0)
                    {
                        //可用余额
                        decimal BalanceAmount = ZYPayClient.ZYPayClient.zyPayClient.GetBalanceDetail(anhuitongUserid).BalanceAmount;

                        //余额是否够支付
                        if (BalanceAmount < Payment)
                        {
                            Log.SaveNote("您的可用现金不足 BalanceAmount:" + BalanceAmount + " Payment:" + Payment);
                            //Response.Write("{ \"status\": \"0\", \"statusMsg\": \"您的可用现金不足\", \"returnData\": \"\"}");
                            Response.Write("fail");
                            Response.End();
                            //return alertFun("支付抢购订单", "您的可用现金不足");
                        }
                    }

                    //  调用mallapi接口
                    //  支付左右币和修改订单状态
                    //payStatus = ZY.Street.BLL.PublicFun.BaseConn.QHRunTranObjToStr("", "ZY_Street_payorder", orderId, UserId);

                    MallApi.OrderApi bllMallOrderApi = new MallApi.OrderApi();
                    bllMallOrderApi.Url = System.Configuration.ConfigurationSettings.AppSettings["MallApi"].ToString();
                    payStatus = bllMallOrderApi.webPayOrder(orderId)[0];

                    if (payStatus == "支付成功")
                    {
                        Log.SaveNote("支付成功");
                        Response.Write("success");
                        Response.End();
                    }

                    //  调用CRM支付接口
                    if (payStatus == "" || payStatus == "true")
                        new OrderService.OrderService().PaymentOrder(orderId);
                    else
                    {
                        Log.SaveNote(payStatus);
                        Response.Write("{ \"status\": \"0\", \"statusMsg\": \"" + payStatus + "\", \"returnData\": \"\"}");
                        Response.End();
                    }

                }

                payStatus = payStatus.ToLower().Trim();
                //支付成功
                if (payStatus == "" || payStatus == "true")
                {
                    //goodstype     商品类型【1:店铺商品。2:0元抢购商品。3:优惠券,4:限时抢购】
                    if (Payment > 0)
                    {
                        //可用余额
                        decimal BalanceAmount = ZYPayClient.ZYPayClient.zyPayClient.GetBalanceDetail(anhuitongUserid).BalanceAmount;

                        //余额是否够支付
                        if (BalanceAmount >= Payment)
                        {
                            //扣除费用
                            if (orderType == "1" || orderType == "2" || orderType == "3")//抢购
                            {
                                long result1 = ZYPayClient.ZYPayClient.zyPayClient.PayByUserBalance(anhuitongUserid, orderId,
                                    6, "支付订单现金", Payment, "支付了[" + orderId + "]订单", "内部方法名:PayByUserBalance调用");

                            }
                            if (orderType == "0")//商城
                            {
                                long result1 = ZYPayClient.ZYPayClient.zyPayClient.PayByUserBalance(anhuitongUserid, orderId,
                                                                           10000, "支付商城订单现金", Payment, "支付了[" + orderId + "]订单", "内部方法名:PayByUserBalance调用");
                            }

                            ////现金支付失败
                            //if (result1 <= 0)
                            //{
                            //    //返回左右币
                            //    string Status = ZY.Street.BLL.PublicFun.BaseConn.QHRunTranObjToStr("", "ZY_Street_payFlashGoodsZYCoin", orderId, UserId);
                            //    Status = Status.ToLower().Trim();
                            //    if (Status == "true")
                            //    {
                            //        Response.Write("{ \"status\": \"0\", \"statusMsg\": \"现金支付失败,请重新再试\", \"returnData\": \"\"}");
                            //        Response.End();
                            //    }
                            //    else
                            //    {
                            //        Response.Write("{ \"status\": \"0\", \"statusMsg\": \"—支付失败,请重新再试2—\", \"returnData\": \"\"}");
                            //        Response.End();
                            //    }

                            //}

                            Log.SaveNote("支付成功");

                            Response.Write("success");
                            try
                            {
                                //  发送短信
                                QHJsonDemo.cs.SendMsgTool.SendMsg(int.Parse(Consumotion), buyerPhoneNumber, sellerPhoneNumber, VerificationCode, shopName, buyNums, productName, ReceivePhone, ReceiveName, ReceiveAddress);
                            }
                            catch (Exception ex) { Log.SaveNote(ex.Message); }
                            Response.End();
                        }
                        else
                        {
                            //ZY.Street.BLL.PublicFun.BaseConn.ZY_Street_addRechargeStatus(Payment, "支付了[" + orderId + "]订单", "支付了[" + orderId + "]订单", 6, orderId, UserId);
                            //Response.Write("{ \"status\": \"1\", \"statusMsg\": \"支付成功\", \"returnData\": \"\"}");
                            //Response.End();
                        }
                    }
                    //  如果不需要支付现金则直接返回成功
                    if (Payment == 0)
                    {
                        //Response.Write("{ \"status\": \"1\", \"statusMsg\": \"支付成功\", \"returnData\": \"\"}");

                        //SendMsg(PhoneNumber, int.Parse(Consumotion));

                        Log.SaveNote("支付成功1");

                        Response.Write("success");
                        try
                        {
                            //  发送短信
                            QHJsonDemo.cs.SendMsgTool.SendMsg(int.Parse(Consumotion), buyerPhoneNumber, sellerPhoneNumber, VerificationCode, shopName, buyNums, productName, ReceivePhone, ReceiveName, ReceiveAddress);
                        }
                        catch (Exception ex) { Log.SaveNote(ex.Message); }

                        Response.End();
                    }
                    ////直接跳转到下一个web
                    //return "/NewHtml/aspx/PayStatus.aspx?orderId=" + orderId;
                }
                else
                {
                    payStatus = payStatus.Replace("999999", "");
                    if (payStatus.ToLower() == "false")
                        payStatus = "订单支付失败,可能已支付或订单被关闭。";

                    Log.SaveNote("订单支付失败,可能已支付或订单被关闭");
                    //Response.Write("{ \"status\": \"0\", \"statusMsg\": \"—订单支付失败,可能已支付或订单被关闭。—\", \"returnData\": \"\"}");
                    Response.Write("fail");
                    Response.End();
                    //return alertFun("支付抢购订单", "—" + payStatus + "—");
                }
            }
            catch (Exception ex)
            {
                if (!(ex is System.Threading.ThreadAbortException))
                {
                    Log.SaveNote(ex.ToString());
                }
            }

            Log.SaveNote("支付失败,请重新再试3");
            //Response.Write("{ \"status\": \"0\", \"statusMsg\": \"—支付失败,请重新再试3—\", \"returnData\": \"\"}");
            Response.Write("fail");
            Response.End();
        }