Exemple #1
0
        /// <summary>
        /// 保存商户信息
        /// </summary>
        public void SaveMerchant()
        {
            string data_save = GetString("data_save");

            if (string.IsNullOrEmpty(data_save))
            {
                ReturnErrorMsg("商户信息为空");
                return;
            }

            var json         = new JavaScriptSerializer();
            var merchantinfo = json.Deserialize <SaveMerchantInfo>(data_save);

            if (merchantinfo == null)
            {
                ReturnErrorMsg("商户信息为空");
                return;
            }

            var user = new Account();

            if (MerchantHelper.JudgeMerchant(merchantinfo.Name, merchantinfo.Id))
            {
                ReturnErrorMsg(string.Format("已存在名称为【{0}】的商户", merchantinfo.Name));
                return;
            }
            var id = merchantinfo.Id;

            if (id == 0)
            {
                user.UserName = merchantinfo.UserName;
                user.Pwd      = "111111";
                user.RoleType = RoleType.Merchant;
                user.Phone    = merchantinfo.Phone;
                user.Address  = merchantinfo.Address;



                merchantinfo.Id = AccountHelper.SaveAccount(user);
            }
            else
            {
                user = AccountHelper.GetUser(merchantinfo.Id);
            }
            if (user == null)
            {
                ReturnErrorMsg("不存在该商户");
                return;
            }
            var merchant        = MerchantHelper.GetMerchant(merchantinfo.Id);
            var isadd           = 0;
            var changeCountList = new List <GoodsHandler.ChangeCountItem>();

            if (merchant == null)
            {
                merchant    = new Merchant();
                merchant.Id = merchantinfo.Id;
                isadd       = 1;

                changeCountList.Add(new GoodsHandler.ChangeCountItem()
                {
                    Id = merchantinfo.Mid, Change = 1
                });
            }

            user.UserName = merchantinfo.UserName;

            merchant.Name    = merchantinfo.Name;
            merchant.LogoUrl = merchantinfo.LogoUrl;
            if (id > 0 && merchantinfo.Mid != merchant.Mid)
            {
                if (merchant.Mid > 0)
                {
                    changeCountList.Add(new GoodsHandler.ChangeCountItem()
                    {
                        Id = merchant.Mid, Change = -1
                    });
                }
                changeCountList.Add(new GoodsHandler.ChangeCountItem()
                {
                    Id = merchantinfo.Mid, Change = 1
                });
            }
            merchant.Mid = merchantinfo.Mid;

            merchant.Tid = merchantinfo.Tid;
            //merchant.ServerEndTime = merchantinfo.ServerEndTime;
            merchant.HasWifi        = merchantinfo.HasWifi;
            merchant.HasPrint       = merchantinfo.HasPrint;
            merchant.HasDelivery    = merchantinfo.HasDelivery;
            merchant.Sid            = merchantinfo.Sid;
            merchant.Phone          = merchantinfo.Phone;
            merchant.ManagerPhone   = merchantinfo.ManagerPhone;
            merchant.Address        = merchantinfo.Address;
            merchant.WinXinAccount  = merchantinfo.WinXinAccount;
            merchant.Qq             = merchantinfo.Qq;
            merchant.Remark         = merchantinfo.Note;
            merchant.IosUrl         = merchantinfo.IosUrl;
            merchant.IosVersion     = merchantinfo.IosVer;
            merchant.AndroidUrl     = merchantinfo.AndroidUrl;
            merchant.AndroidVersion = merchantinfo.AndroidVer;
            merchant.MachineCode    = merchantinfo.MachineCode;
            merchant.MachineKey     = merchantinfo.MachineKey;
            if (string.IsNullOrEmpty(merchantinfo.CnameList[0]))
            {
                merchantinfo.CnameList[0] = "活动咨询";
            }
            if (string.IsNullOrEmpty(merchantinfo.CnameList[1]))
            {
                merchantinfo.CnameList[1] = "商品展示";
            }
            if (string.IsNullOrEmpty(merchantinfo.CnameList[2]))
            {
                merchantinfo.CnameList[2] = "快速预约";
            }
            if (string.IsNullOrEmpty(merchantinfo.CnameList[3]))
            {
                merchantinfo.CnameList[3] = "图片墙";
            }
            if (string.IsNullOrEmpty(merchantinfo.CnameList[4]))
            {
                merchantinfo.CnameList[4] = "包厢";
            }
            merchant.CnameList   = merchantinfo.CnameList;
            merchant.DevName     = merchantinfo.DevName;
            merchant.WifiAccount = merchantinfo.WifiAccount;

            AccountHelper.SaveAccount(user);
            if (MerchantHelper.SaveMerchant(merchant, isadd))
            {
                MerchantTypeHelper.UpdateMerchantCount(changeCountList);
                if (id == 0)
                {
                    if (Utility._msg_opensend == "1")
                    {
                        //发送短信给商户
                        SendMsgClass5 jsobject = new SendMsgClass5();
                        jsobject.param1 = string.IsNullOrEmpty(merchant.Name) ? "商户名称为空" : merchant.Name;
                        jsobject.param2 = Utility._domainurl + "/view/dev/Index.aspx";
                        jsobject.param3 = string.IsNullOrEmpty(user.UserName)
                            ? string.IsNullOrEmpty(user.Phone) ? "用户名为空" : user.Phone
                            : user.UserName;
                        jsobject.param4 = user.Pwd;
                        jsobject.param5 = Utility._3vurl;

                        if (Utility.SendMsg(merchant.Phone, MsgTempleId.AddMerchant, jsobject) != "发送成功")
                        {
                            logger.InfoFormat("短信模板:{0},Phone:{3},发送失败merchantId:{1},Name:{2}",
                                              (int)MsgTempleId.AddMerchant, merchant.Id, merchant.Name, merchant.Phone);
                        }
                    }
                    ReturnCorrectMsg("添加成功");
                }
                else
                {
                    ReturnCorrectMsg("更新成功");
                }
            }
            else
            if (id == 0)
            {
                ReturnErrorMsg("添加失败");
            }
            else
            {
                ReturnErrorMsg("更新失败");
            }
        }