public List <CityUserMsg> getListByUserId(int aid, int userId, out int totalCount, int pageSize = 10, int pageIndex = 1, string appId = "") { string strWhere = $"aid={aid} and toUserId={userId}"; base.ExecuteNonQuery($"update CityUserMsg set state=1 where aid={aid} and toUserId={userId}");//将该用户未读消息全部标记为已读 totalCount = base.GetCount(strWhere); OpenAuthorizerConfig openAuthorizerConfig = OpenAuthorizerConfigBLL.SingleModel.GetModelByAppids(appId); List <CityUserMsg> list = base.GetList(strWhere, pageSize, pageIndex, "*", "addTime desc"); string userIds = string.Join(",", list?.Select(s => s.fromUserId).Distinct()); List <C_UserInfo> userInfoList = C_UserInfoBLL.SingleModel.GetListByIds(userIds); list.ForEach(x => { //获取用户头像 昵称 C_UserInfo c_UserInfo = userInfoList?.FirstOrDefault(f => f.Id == x.fromUserId); if (c_UserInfo != null) { x.fromUserName = c_UserInfo.NickName; x.fromUseImg = c_UserInfo.HeadImgUrl; } else { x.fromUserName = "******"; x.fromUseImg = openAuthorizerConfig.head_img; } x.addTimeStr = CommondHelper.GetTimeSpan(DateTime.Now - x.addTime); }); return(list); }
public bool JieBang(string userId) { List <string> sqllist = new List <string>(); OpenAuthorizerConfig openconfig = OpenAuthorizerConfigBLL.SingleModel.GetModel("user_name='" + userId + "'"); if (openconfig != null) { var xcxrelations = GetList($"AppId='{openconfig.appid}'"); if (xcxrelations != null && xcxrelations.Count > 0) { var ids = string.Join(",", xcxrelations.Select(s => s.Id).Distinct()); //log4net.LogHelper.WriteInfo(this.GetType(),ids); //log4net.LogHelper.WriteInfo(this.GetType(), $"Update XcxAppAccountRelation set appId='' where id in ({ids})"); if (base.ExecuteNonQuery($"Update XcxAppAccountRelation set appId='' where id in ({ids})") <= 0 && UserXcxTemplateBLL.SingleModel.UpdateUserTemplate(openconfig.appid, openconfig.minisnsid)) { return(false); } } if (OpenAuthorizerConfigBLL.SingleModel.Delete(openconfig.id) <= 0) { return(false); } } return(true); }
/// <summary> /// 关联客户端小程序 /// </summary> /// <returns></returns> public ActionResult LinkClient() { int appId = Context.GetRequestInt("appId", 0); if (appId <= 0) { return(View("PageError", new Return_Msg() { Msg = "系统繁忙appid_null!", code = "500" })); } XcxAppAccountRelation appAcountRelation = XcxAppAccountRelationBLL.SingleModel.GetModelByaccountidAndAppid(appId, dzaccount.Id.ToString()); if (appAcountRelation == null) { return(View("PageError", new Return_Msg() { Msg = "系统繁忙relation_null!", code = "500" })); } ViewBag.appId = appId; FootbathXcxRelation xcxRelation = FootbathXcxRelationBLL.SingleModel.GetModelByTechnicianAid(appId); List <XcxAppAccountRelation> clientAccountRelationList = XcxAppAccountRelationBLL.SingleModel.GetClientList(dzaccount.Id.ToString()); List <FootbathClientModel> clientModelList = new List <FootbathClientModel>(); if (clientAccountRelationList != null && clientAccountRelationList.Count > 0) { foreach (XcxAppAccountRelation client in clientAccountRelationList) { FootbathClientModel clientModel = new FootbathClientModel(); clientModel.aid = client.Id; OpenAuthorizerConfig authModel = OpenAuthorizerConfigBLL.SingleModel.GetListByaccoundidAndRid(dzaccount.Id.ToString(), client.Id).FirstOrDefault(); clientModel.xcxName = "未绑定"; if (authModel != null) { clientModel.xcxName = authModel.nick_name; } clientModel.relation = FootbathXcxRelationBLL.SingleModel.GetModelByClientAid(client.Id); clientModelList.Add(clientModel); } } if (xcxRelation != null) { xcxRelation.clientXcxName = "未绑定"; foreach (FootbathClientModel clienModel in clientModelList) { if (clienModel.aid == xcxRelation.clientAid) { xcxRelation.clientXcxName = clienModel.xcxName; } } } return(View(new { xcxRelation, clientModelList, appId })); }
public string GetStoreNameEnt(Store store) { //if (store == null) //{ // return string.Empty; //} if (!string.IsNullOrWhiteSpace(store.name)) { return(store.name); } OpenAuthorizerConfig XUserList = OpenAuthorizerConfigBLL.SingleModel.GetModelByAppids(string.Empty, store.appId); return(XUserList?.nick_name); }
public ReturnMsg getAppInfo(string appid = "") { if (string.IsNullOrEmpty(appid)) { result.msg = "非法请求"; } OpenAuthorizerConfig authModel = OpenAuthorizerConfigBLL.SingleModel.GetModelByAppids(appid); if (authModel != null) { result.code = 1; result.obj = authModel; } return(result); }
/// <summary> /// 第三方授权获取小程序token /// </summary> /// <param name="appId"></param> /// <returns></returns> public GetAccessTokenMsg GetThirthPlatToken(string appId) { GetAccessTokenMsg model = new GetAccessTokenMsg(); model.obj = new AccessTokenModel(); OpenAuthorizerConfig openConfig = OpenAuthorizerConfigBLL.SingleModel.GetModelByAppids(appId); if (openConfig == null) { model.msg = "第三方授权:模板还没授权"; model.isok = -1; return(model); } string url = GetOpenAuthodModel(openConfig.user_name); string resultStr = HttpHelper.GetData(url); if (string.IsNullOrEmpty(resultStr)) { model.isok = -1; model.msg = "第三方授权:获取token为空"; return(model); } model = JsonConvert.DeserializeObject <GetAccessTokenMsg>(resultStr); if (model == null || model.obj == null) { model.isok = -1; model.msg = "第三方授权:获取token失败"; return(model); } if (model.obj.errcode != 0 || string.IsNullOrEmpty(model.obj.access_token)) { model.isok = -1; model.msg = $"第三方授权:{model.obj.errmsg}"; return(model); } return(model); }
/// <summary> /// 专业版普通订单打印内容拼接 /// </summary> /// <param name="food"></param> /// <param name="foodGoodsOrder"></param> /// <param name="cars"></param> /// <param name="foodPrintList"></param> /// <returns></returns> public static string entPrintOrderContent(EntGoodsOrder goodsOrder) { //打印内容 string content = ""; List <EntGoodsCart> cars = EntGoodsCartBLL.SingleModel.GetList($" GoodsOrderId = {goodsOrder.Id} ") ?? new List <EntGoodsCart>(); string goodsIds = string.Join(",", cars.Select(s => s.FoodGoodsId).Distinct()); List <EntGoods> entGoodsList = EntGoodsBLL.SingleModel.GetListByIds(goodsIds); cars.ForEach(c => { c.goodsMsg = entGoodsList?.FirstOrDefault(f => f.id == c.FoodGoodsId) ?? new EntGoods(); }); XcxAppAccountRelation curXcx = XcxAppAccountRelationBLL.SingleModel.GetModel(goodsOrder.aId); if (curXcx == null) { log4net.LogHelper.WriteInfo(typeof(PrinterHelper), "专业版打印内容拼接失败 curXcx_null"); return(content); } //获取店铺名 OpenAuthorizerConfig XUserList = OpenAuthorizerConfigBLL.SingleModel.GetModelByAppids(curXcx.AppId); if (XUserList == null) { log4net.LogHelper.WriteInfo(typeof(PrinterHelper), "专业版打印内容获取不到小程序名,但仍旧打印 XUserList_null"); } string zqStoreInfo = "送货地址:无(到店自取)\r\n"; if (!string.IsNullOrEmpty(goodsOrder.attribute)) { goodsOrder.attrbuteModel = JsonConvert.DeserializeObject <EntGoodsOrderAttr>(goodsOrder.attribute); } PickPlace storeAddress = null; if (goodsOrder.attrbuteModel.zqStoreId > 0) { storeAddress = PickPlaceBLL.SingleModel.GetModel(goodsOrder.attrbuteModel.zqStoreId); } else if (!string.IsNullOrWhiteSpace(goodsOrder.attrbuteModel.zqStoreName)) { storeAddress = PickPlaceBLL.SingleModel.GetModelByAid_Name(goodsOrder.aId, goodsOrder.attrbuteModel.zqStoreName); } if (storeAddress != null) { zqStoreInfo = $"送货地址:【{storeAddress?.name}】{storeAddress?.address}\r\n"; } //拼接订单内容排版 content = $"<MC>0,00005,0</MC><FS>{XUserList?.nick_name ?? string.Empty}</FS>\r\n"; content += "<table><tr><td>商品</td><td>数量</td><td>金额(元)</td></tr>"; content += "<tr><td>@@2................................</td></tr>"; foreach (var car in cars) { //car.goodsMsg = foodGoodsBLL.GetModel($"Id={car.FoodGoodsId}"); content += $"<tr><td>{car.goodsMsg.name}</td><td>{car.Count}</td><td>{(car.Price * car.Count * 0.01).ToString("0.00")}</td></tr>"; if (!string.IsNullOrEmpty(car.SpecInfo)) { content += $"<tr><td>规格:{car.SpecInfo}</td></tr>"; } content += $"<tr><td></td></tr>"; } content += "<tr><td>┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄</td></tr>"; content += $"<tr><td>实收:</td><td>-</td><td>{(goodsOrder.BuyPrice * 0.01).ToString("0.00")}</td></tr>"; content += $"<tr><td></td><td></td><td>({Enum.GetName(typeof(miniAppBuyMode), goodsOrder.BuyMode)})</td></tr></table>"; content += "┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄\r\n"; content += $"订单号:{goodsOrder.OrderNum}\r\n"; content += $"下单时间:{goodsOrder.CreateDate}\r\n"; content += $"打印时间:{DateTime.Now}\r\n"; content += $"收货人:{goodsOrder.AccepterName}\r\n"; content += $"联系方式:{goodsOrder.AccepterTelePhone}\r\n"; switch (goodsOrder.GetWay) { case (int)miniAppOrderGetWay.商家配送: content += $"送货地址:{goodsOrder.Address}\r\n"; break; case (int)miniAppOrderGetWay.到店自取: case (int)miniAppOrderGetWay.到店消费: content += zqStoreInfo; break; } content += $"订单备注:{goodsOrder.Message}\r\n"; return(content); }
/// <summary> /// 获取首页轮播图以及推荐商家 /// </summary> /// <returns></returns> public ActionResult GetConfig() { returnObj = new Return_Msg_APP(); returnObj.code = "200"; string appId = Context.GetRequest("appId", string.Empty); if (string.IsNullOrEmpty(appId)) { returnObj.Msg = "参数错误"; return(Json(returnObj)); } int pageIndexAdImg = Context.GetRequestInt("pageIndexAdImg", 1); int pageSizeAdImg = Context.GetRequestInt("pageSizeAdImg", 10); int pageIndexTjStore = Context.GetRequestInt("pageIndexTjStore", 1); int pageSizeTjStore = Context.GetRequestInt("pageSizeTjStore", 20); XcxAppAccountRelation r = _xcxAppAccountRelationBLL.GetModelByAppid(appId); if (r == null) { returnObj.Msg = "小程序未授权"; return(Json(returnObj, JsonRequestBehavior.AllowGet)); } string appname = ""; OpenAuthorizerConfig openonfigmodel = OpenAuthorizerConfigBLL.SingleModel.GetModelByAppids(r.AppId); if (openonfigmodel != null) { appname = openonfigmodel.nick_name; } else { UserXcxTemplate userXcxModel = UserXcxTemplateBLL.SingleModel.GetModelByAppId(r.AppId); appname = userXcxModel?.Name; } int adImgCount, tjStoreCount = 0; List <PlatConfig> listADImg = PlatConfigBLL.SingleModel.getListByaid(r.Id, out adImgCount, 0, pageSizeAdImg, pageIndexAdImg); List <PlatConfig> listTjStore = PlatConfigBLL.SingleModel.getListByaid(r.Id, out tjStoreCount, 1, pageSizeTjStore, pageIndexTjStore); string lngStr = Context.GetRequest("lng", string.Empty); string latStr = Context.GetRequest("lat", string.Empty); double lng = 0.00; double lat = 0.00; string curLocation = "未知城市"; int curCityCode = 0; if (!double.TryParse(lngStr, out lng) || !double.TryParse(latStr, out lat)) { string IP = WebHelper.GetIP(); IPToPoint iPToPoint = CommondHelper.GetLoctionByIP(IP); if (iPToPoint != null) { lat = iPToPoint.result.location.lat; lng = iPToPoint.result.location.lng; lngStr = lng.ToString(); latStr = lat.ToString(); //log4net.LogHelper.WriteInfo(this.GetType(), $"IP={IP};{lat},{lng}"); } } AddressApi addressinfo = AddressHelper.GetAddressByApi(lngStr, latStr); // log4net.LogHelper.WriteInfo(this.GetType(), Newtonsoft.Json.JsonConvert.SerializeObject(addressinfo)); if (addressinfo != null && addressinfo.result != null && addressinfo.result.address_component != null) { curLocation = addressinfo.result.address_component.city; curCityCode = C_AreaBLL.SingleModel.GetCodeByName(curLocation); } listTjStore.ForEach(x => { x.ObjName = x.ObjName.Length > 6 ? (x.ObjName.Substring(0, 5) + "...") : x.ObjName; }); PlatConfig platConfigRemark = PlatConfigBLL.SingleModel.GetPlatConfig(r.Id, 3); var remarkObj = new { haveRemark = false, remark = string.Empty, remarkOpenFrm = false }; if (platConfigRemark != null && !string.IsNullOrEmpty(platConfigRemark.ADImg)) { remarkObj = new { haveRemark = true, remark = platConfigRemark.ADImg, remarkOpenFrm = platConfigRemark.ObjId == 0 }; } PlatConfig platOther = PlatConfigBLL.SingleModel.GetPlatConfig(r.Id, 5);//获取平台其它设置 if (platOther == null) { platOther = new PlatConfig() { Aid = r.Id, AddTime = DateTime.Now, ConfigType = 5 }; } PlatOtherConfig platOtherConfig = new PlatOtherConfig(); platOtherConfig.VirtualPV = platOther.ADImgType; platOtherConfig.VirtualPlatMsgCount = platOther.ObjId; platOtherConfig.PlatMsgCount = PlatMsgBLL.SingleModel.GetCountByAId(r.Id); platOtherConfig.PV = PlatStatisticalFlowBLL.SingleModel.GetPVCount(r.Id); int totalPV = platOtherConfig.VirtualPV + platOtherConfig.PV; int totalMsgCout = platOtherConfig.PlatMsgCount + platOtherConfig.VirtualPlatMsgCount; PlatConfig platOfficialAccount = PlatConfigBLL.SingleModel.GetPlatConfig(r.Id, 6);//获取关注公众号设置 if (platOfficialAccount == null) { platOfficialAccount = new PlatConfig() { Aid = r.Id, AddTime = DateTime.Now, ConfigType = 6 }; } returnObj.dataObj = new { appname = appname, ADImgs = new { totalCount = adImgCount, list = listADImg }, TjStores = new { totalCount = tjStoreCount, list = listTjStore }, Location = new { curLocation = curLocation, curCityCode = curCityCode }, platConfigRemark = remarkObj, platOtherConfig = new { TotalPV = totalPV > 100000?Convert.ToInt32(totalPV * 0.0001).ToString() + "万+": totalPV.ToString(), TotalMsgCount = totalMsgCout > 100000? Convert.ToInt32(totalMsgCout * 0.0001).ToString() + "万+": totalMsgCout.ToString() }, platOfficialAccount = platOfficialAccount }; returnObj.isok = true; returnObj.Msg = "获取成功"; return(Json(returnObj, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 授权页回调 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult OpenOAuthCallback(string id) { var reurl = "http://openapp.vzan.com/test/index"; var appid = "wx9a6ab00a752e10e8"; string auth_code = Request["auth_code"]; int areacode = int.Parse(Request["AreaCode"]?.ToString()); int expires_in = Convert.ToInt32(Request["expires_in"]); var currentmodel = opencomponentconfigBLL.SingleModel.getCurrentModel(); string token = currentmodel.component_access_token; //使用授权码获取小程序授权信息 var queryAuthResult = ComponentApi.QueryAuth(token, appid, auth_code); try { var authorizerInfoResult = ComponentApi.GetAuthorizerInfo(token, appid, queryAuthResult.authorization_info.authorizer_appid); StringBuilder str = new StringBuilder(); foreach (FuncscopeCategoryItem item in queryAuthResult.authorization_info.func_info) { str.Append(item.funcscope_category.id.ToString() + ","); } string func_info = str.ToString(); if (func_info.Length > 0) { func_info = func_info.Substring(0, func_info.Length - 1); } #region 公众号详细信息 OpenAuthorizerConfig openconfig = OpenAuthorizerConfigBLL.SingleModel.GetModel("user_name='" + authorizerInfoResult.authorizer_info.user_name + "'"); if (openconfig == null) { openconfig = new OpenAuthorizerConfig(); } openconfig.alias = authorizerInfoResult.authorizer_info.alias; openconfig.appid = queryAuthResult.authorization_info.authorizer_appid; openconfig.func_info = func_info; openconfig.head_img = authorizerInfoResult.authorizer_info.head_img; openconfig.nick_name = authorizerInfoResult.authorizer_info.nick_name; openconfig.qrcode_url = authorizerInfoResult.authorizer_info.qrcode_url; openconfig.service_type_info = (int)authorizerInfoResult.authorizer_info.service_type_info.id; openconfig.user_name = authorizerInfoResult.authorizer_info.user_name; openconfig.verify_type_info = (int)authorizerInfoResult.authorizer_info.verify_type_info.id; openconfig.state = 1; //openconfig.minisnsid = areacode; if (openconfig.id > 0) { OpenAuthorizerConfigBLL.SingleModel.Update(openconfig); } else { OpenAuthorizerConfigBLL.SingleModel.Add(openconfig); } OpenAuthorizerInfo info = OpenAuthorizerInfoBLL.SingleModel.GetModel(string.Format("user_name='{0}'", authorizerInfoResult.authorizer_info.user_name)); if (info == null) { info = new OpenAuthorizerInfo(); } info.addtime = DateTime.Now; info.authorizer_access_token = queryAuthResult.authorization_info.authorizer_access_token; info.authorizer_appid = authorizerInfoResult.authorization_info.authorizer_appid; info.authorizer_refresh_token = queryAuthResult.authorization_info.authorizer_refresh_token; info.refreshtime = DateTime.Now; info.status = 1; //info.minisnsid = areacode; info.user_name = authorizerInfoResult.authorizer_info.user_name; if (info.id > 0) { OpenAuthorizerInfoBLL.SingleModel.Update(info); } else { OpenAuthorizerInfoBLL.SingleModel.Add(info); } #endregion return(Redirect(reurl)); } catch (ErrorJsonResultException ex) { log4net.LogHelper.WriteError(this.GetType(), ex); return(Content(ex.Message)); } }
/// <summary> /// /// </summary> /// <param name="aid">平台小程序appId</param> /// <param name="totalCount"></param> /// <param name="storeName">店铺名称</param> /// <param name="appName">绑定的小程序名称</param> /// <param name="agentName">分销代理商名称</param> /// <param name="categoryName">原平台类别名称</param> /// <param name="storeState">店铺状态</param> /// <param name="haveAid">是否绑定了小程序0 未绑定 1绑定了</param> /// <param name="fromType">数据来源0 店铺入驻 1代理分销商同步</param> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <param name="orderWhere"></param> /// <returns></returns> public List <PlatStoreRelation> GetListStore(int aid, out int totalCount, string storeName = "", string appName = "", string agentName = "", string categoryName = "", int storeState = -1, int haveAid = -1, int fromType = -1, int pageSize = 10, int pageIndex = 1, string orderWhere = "AddTime desc", string storeOwnerPhone = "", int isFirstType = 0, int categoryId = 0, string appId = "") { List <PlatStore> list = new List <PlatStore>(); List <PlatStoreRelation> listPlatStoreRelation = new List <PlatStoreRelation>(); List <MySqlParameter> parameters = new List <MySqlParameter>(); string strWhere = $" psr.Aid={aid} and s.Id>0 and s.state<>-1 and s.MyCardId in({PlatMyCardBLL.SingleModel.GetCardIds(aid, appId)})"; if (storeState != -1) { strWhere += $" and psr.State={storeState}"; } if (haveAid != -1) { if (haveAid == 0) { strWhere += $" and s.Aid=0"; } else { strWhere += $" and s.Aid<>0"; //表示店铺已经绑定独立小程序 } } if (fromType != -1) { strWhere += $" and psr.FromType={fromType}"; } if (!string.IsNullOrEmpty(storeOwnerPhone)) { parameters.Add(new MySqlParameter("@storeOwnerPhone", $"%{storeOwnerPhone}%")); strWhere += " and c.Phone like @storeOwnerPhone"; } if (!string.IsNullOrEmpty(storeName)) { parameters.Add(new MySqlParameter("@storeName", $"%{storeName}%")); strWhere += " and s.Name like @storeName"; } if (!string.IsNullOrEmpty(appName))//根据店铺绑定的小程序名称模糊查询 { List <int> listRids = OpenAuthorizerConfigBLL.SingleModel.GetRidByAppName(appName); if (listRids == null || listRids.Count <= 0) { listRids.Add(0); } strWhere += $" and s.Aid in ({string.Join(",", listRids)})"; } if (!string.IsNullOrEmpty(agentName))//根据分销代理商名称模糊查询 { List <int> listAgentId = AgentinfoBLL.SingleModel.GetAgentIdByAgentName(agentName); if (listAgentId == null || listAgentId.Count <= 0) { listAgentId.Add(0); } strWhere += $" and psr.AgentId in ({string.Join(",", listAgentId)})"; } if (!string.IsNullOrEmpty(categoryName))//根据类别名称(小类 因为店铺最终属于某个小类)模糊查询 { List <int> listCategoryId = PlatStoreCategoryBLL.SingleModel.GetCategoryIdName(categoryName); if (listCategoryId == null || listCategoryId.Count <= 0) { listCategoryId.Add(0); } strWhere += $" and s.Category in ({string.Join(",", listCategoryId)})"; } if (isFirstType == 1 && categoryId > 0) { //表示传过来的是店铺大类 先查询出其下面的小类id strWhere += $" and s.Category in ({PlatStoreCategoryBLL.SingleModel.GetChildIds(aid, categoryId)})"; } if (isFirstType == 2 && categoryId > 0) { //表示传过来的是店铺大类 先查询出其下面的小类id strWhere += $" and s.Category in ({categoryId})"; } string sql = $"select psr.*,s.YearCount,s.CostPrice,s.Id as sId,s.Aid as sAid,s.Category as sCategory,s.MyCardId as sMyCardId,s.StorePV,s.StoreVirtualPV,s.Name,c.Phone as StoreOwnerPhone from PlatStoreRelation psr left join PlatStore s on psr.StoreId=s.Id left join PlatMyCard c on s.MyCardId=c.Id where {strWhere} order by {orderWhere} LIMIT {(pageIndex - 1) * pageSize},{pageSize}"; using (var dr = SqlMySql.ExecuteDataReader(Utility.dbEnum.MINIAPP.ToString(), CommandType.Text, sql, parameters.ToArray())) { listPlatStoreRelation = new List <PlatStoreRelation>(); while (dr.Read()) { PlatStoreRelation platStoreRelation = PlatStoreRelationBLL.SingleModel.GetModel(dr); if (platStoreRelation != null) { if (dr["sCategory"] != DBNull.Value) { PlatStoreCategory OwnerPlatStoreCategory = PlatStoreCategoryBLL.SingleModel.GetModel(Convert.ToInt32(dr["sCategory"])); if (OwnerPlatStoreCategory != null) { platStoreRelation.OwnerSecondCategoryName = OwnerPlatStoreCategory.Name; PlatStoreCategory firstplatStoreCategory = PlatStoreCategoryBLL.SingleModel.GetModel(OwnerPlatStoreCategory.ParentId); if (firstplatStoreCategory != null) { platStoreRelation.OwnerFirstCategoryName = firstplatStoreCategory.Name; } } } PlatStoreCategory CurPlatStoreCategory = PlatStoreCategoryBLL.SingleModel.GetModel(platStoreRelation.Category); if (CurPlatStoreCategory != null) { platStoreRelation.CurSecondCategoryName = CurPlatStoreCategory.Name; PlatStoreCategory firstplatStoreCategory = PlatStoreCategoryBLL.SingleModel.GetModel(CurPlatStoreCategory.ParentId); if (firstplatStoreCategory != null) { platStoreRelation.CurFirstCategoryName = firstplatStoreCategory.Name; platStoreRelation.FirstCategory = CurPlatStoreCategory.ParentId; } } platStoreRelation.StoreOwnerPhone = dr["StoreOwnerPhone"].ToString(); if (dr["sMyCardId"] != DBNull.Value) { platStoreRelation.MyCardId = Convert.ToInt32(dr["sMyCardId"]); } Agentinfo agentinfo = AgentinfoBLL.SingleModel.GetModel(platStoreRelation.AgentId); platStoreRelation.FromTypeStr = platStoreRelation.FromType == 0 ? "平台入驻" : (agentinfo != null ? agentinfo.name : "分销代理商"); if (dr["sAid"] != DBNull.Value) { XcxAppAccountRelation xcxAppAccountRelation = XcxAppAccountRelationBLL.SingleModel.GetModel(Convert.ToInt32(dr["sAid"])); if (xcxAppAccountRelation == null) { platStoreRelation.BindAppIdName = "无"; } else { OpenAuthorizerConfig openAuthorizerConfig = OpenAuthorizerConfigBLL.SingleModel.GetModelByAppids(xcxAppAccountRelation.AppId, xcxAppAccountRelation.Id); platStoreRelation.BindAppIdName = openAuthorizerConfig?.nick_name + "id:" + xcxAppAccountRelation.Id; } } platStoreRelation.StoreName = Convert.ToString(dr["Name"]); if (dr["StorePV"] != DBNull.Value) { platStoreRelation.StorePV = Convert.ToInt32(dr["StorePV"]); } if (dr["StoreVirtualPV"] != DBNull.Value) { platStoreRelation.StorePV += Convert.ToInt32(dr["StoreVirtualPV"]); } if (dr["sId"] != DBNull.Value) { platStoreRelation.StoreId = Convert.ToInt32(dr["sId"]); } if (dr["sAid"] != DBNull.Value) { platStoreRelation.StoreAid = Convert.ToInt32(dr["sAid"]); } platStoreRelation.YearCount = Convert.ToInt32(dr["YearCount"]); platStoreRelation.CostPrice = Convert.ToInt32(dr["CostPrice"]); listPlatStoreRelation.Add(platStoreRelation); } } } totalCount = 0; object obj = SqlMySql.ExecuteScalar(Utility.dbEnum.MINIAPP.ToString(), CommandType.Text, $"select Count(psr.Id) from PlatStoreRelation psr left join PlatStore s on psr.StoreId=s.Id left join PlatMyCard c on s.MyCardId=c.Id where {strWhere}", parameters.ToArray()); if (obj != null) { totalCount = Convert.ToInt32(obj); } ; return(listPlatStoreRelation); }
public CreateCardResult AddWxCoupons(Coupons coupons, XcxAppAccountRelation xcx, string accountId) { //默认专业版的 string center_app_brand_pass = "******"; //专业版 个人中心 string custom_app_brand_pass = "******"; //首页 专业版 string logo_url = string.Empty; string brand_name = string.Empty; string appOriginalId = string.Empty; CreateCardResult _createCardResult = new CreateCardResult(); XcxTemplate xcxTemplate = XcxTemplateBLL.SingleModel.GetModel($"id={xcx.TId}"); if (xcxTemplate == null) { _createCardResult.errcode = 1; _createCardResult.errmsg = "小程序模板不存在"; return(_createCardResult); } List <OpenAuthorizerConfig> listOpenAuthorizerConfig = OpenAuthorizerConfigBLL.SingleModel.GetListByaccoundidAndRid(accountId, xcx.Id, 4); if (listOpenAuthorizerConfig == null) { _createCardResult.errcode = 1; _createCardResult.errmsg = "请先绑定认证服务号才有生成卡券权限"; return(_createCardResult); } OpenAuthorizerConfig umodel = listOpenAuthorizerConfig[0]; switch (xcxTemplate.Type) { case (int)TmpType.小程序专业模板: EntSetting ent = EntSettingBLL.SingleModel.GetModel(coupons.appId); if (ent == null) { _createCardResult.errcode = 1; _createCardResult.errmsg = "该专业版信息找不到"; return(_createCardResult); } OpenAuthorizerConfig XUserList = OpenAuthorizerConfigBLL.SingleModel.GetModelByAppids(xcx.AppId); if (XUserList == null) { _createCardResult.errcode = 1; _createCardResult.errmsg = "请先授权给平台"; return(_createCardResult); } ConfParam imginfo = ConfParamBLL.SingleModel.GetModelByParamappid("logoimg", xcx.AppId); if (imginfo == null) { _createCardResult.errcode = 1; _createCardResult.errmsg = "请先到小程序管理配置底部Logo"; return(_createCardResult); } logo_url = imginfo.Value; brand_name = XUserList.nick_name; break; case (int)TmpType.小程序电商模板: center_app_brand_pass = "******"; //个人中心页面 Store store = StoreBLL.SingleModel.GetModelByAId(xcx.Id); if (store == null) { _createCardResult.errcode = 1; _createCardResult.errmsg = "电商版店铺不存在"; return(_createCardResult); } logo_url = store.logo; brand_name = store.name; break; case (int)TmpType.小程序餐饮模板: center_app_brand_pass = "******"; //个人中心页面 custom_app_brand_pass = "******"; //首页 Food miAppFood = FoodBLL.SingleModel.GetModel($"appId={xcx.Id}"); if (miAppFood == null) { _createCardResult.errcode = 1; _createCardResult.errmsg = "餐饮版店铺不存在"; return(_createCardResult); } logo_url = miAppFood.Logo; brand_name = miAppFood.FoodsName; break; case (int)TmpType.小程序足浴模板: case (int)TmpType.小程序多门店模板: int t = 0; if ((int)TmpType.小程序足浴模板 == xcxTemplate.Type) { center_app_brand_pass = "******"; //个人中心页面 custom_app_brand_pass = "******"; //首页 } else { center_app_brand_pass = "******"; //个人中心页面 t = 1; } FootBath storeModel = FootBathBLL.SingleModel.GetModel($"appId={xcx.Id}"); if (storeModel == null) { _createCardResult.errcode = 1; _createCardResult.errmsg = "找不到该足浴版"; return(_createCardResult); } brand_name = storeModel.StoreName; List <C_Attachment> LogoList = C_AttachmentBLL.SingleModel.GetListByCache(storeModel.Id, t == 0 ? (int)AttachmentItemType.小程序足浴版店铺logo : (int)AttachmentItemType.小程序多门店版门店logo); if (LogoList != null && LogoList.Count > 0) { logo_url = LogoList[0].filepath; } break; case (int)TmpType.小未平台子模版: center_app_brand_pass = "******"; //个人中心页面 custom_app_brand_pass = "******"; //首页 PlatStore platStore = PlatStoreBLL.SingleModel.GetPlatStore(xcx.Id, 2); if (platStore == null) { _createCardResult.errcode = 1; _createCardResult.errmsg = "平台版店铺不存在"; return(_createCardResult); } brand_name = platStore.Name; logo_url = platStore.StoreHeaderImg; break; } if (string.IsNullOrEmpty(logo_url) || string.IsNullOrEmpty(brand_name)) { _createCardResult.errcode = 1; _createCardResult.errmsg = "请先配置Logo以及名称"; return(_createCardResult); } //这里可能会出现token失效 个人发布的未授权给我们第三方平台的卡券会生成不了 string xcxapiurl = XcxApiBLL.SingleModel.GetOpenAuthodModel(umodel.user_name); string authorizer_access_token = CommondHelper.GetAuthorizer_Access_Token(xcxapiurl); string uploadImgResult = CommondHelper.WxUploadImg(authorizer_access_token, logo_url); if (!uploadImgResult.Contains("url")) { _createCardResult.errcode = 1; _createCardResult.errmsg = $"上传Logo到微信失败uploadImgResult={uploadImgResult}"; return(_createCardResult); } if (brand_name.Length >= 12) { brand_name = brand_name.Substring(0, 12); } WxUploadImgResult wxUploadImgResult = JsonConvert.DeserializeObject <WxUploadImgResult>(uploadImgResult); logo_url = wxUploadImgResult.url; base_info _base_info = new base_info(); _base_info.logo_url = logo_url; _base_info.code_type = "CODE_TYPE_TEXT"; _base_info.brand_name = brand_name; _base_info.title = coupons.CouponName.Length > 9 ? Utility.StringHelper.strSubstring(coupons.CouponName, 0, 8) : coupons.CouponName; _base_info.color = "Color010"; _base_info.center_title = "立即使用"; _base_info.center_app_brand_user_name = $"{appOriginalId}@app"; _base_info.center_app_brand_pass = center_app_brand_pass; _base_info.custom_url_name = "小程序"; _base_info.custom_app_brand_user_name = $"{appOriginalId}@app"; _base_info.custom_app_brand_pass = custom_app_brand_pass; _base_info.custom_url_sub_title = "点击进入"; _base_info.description = coupons.Desc.Length > 1024 ? Utility.StringHelper.strSubstring(coupons.Desc, 0, 1023) : coupons.Desc; _base_info.notice = "使用时向服务员出示此券"; _base_info.sku.quantity = coupons.CreateNum; if (coupons.LimitReceive > 0) { //大于0表示限制,0表示无限制 _base_info.get_limit = coupons.LimitReceive; } if (coupons.ValType == 0) { //表示固定日期 _base_info.date_info = new Firstdate_infoItem() { begin_timestamp = WxUtils.GetWeixinDateTime(coupons.StartUseTime), end_timestamp = WxUtils.GetWeixinDateTime(coupons.EndUseTime) }; } if (coupons.ValType == 2 || coupons.ValType == 1) { //fixed_begin_term=0表示领取后当天开始生效 1表示次日后开始生效 领取当日N天内有效 _base_info.date_info = new Seconddate_infoItem() { fixed_begin_term = coupons.ValType == 2?0:1, fixed_term = coupons.ValDay }; } string json = string.Empty; if (coupons.CouponWay == 0) { //表示是需要生成微信代金券 WxCashCoupons wxCashCoupons = new WxCashCoupons(); Cash cash = new Cash(); cash.base_info = _base_info;//基础字段信息 Use_condition use_condition = new Use_condition(); use_condition.accept_category = coupons.GoodsType == 0 ? "全部产品" : "部分产品"; if (coupons.LimitMoney > 0) { cash.least_cost = coupons.LimitMoney; //满减门槛 use_condition.least_cost = coupons.LimitMoney; } use_condition.can_use_with_other_discount = coupons.discountType == 0; cash.reduce_cost = coupons.Money; cash.advanced_info = new Advanced_info() { use_condition = use_condition }; wxCashCoupons.cash = cash; json = JsonConvert.SerializeObject(new { card = wxCashCoupons }); } else { //表示是需要生成微信折扣券 WxDiscountCoupons wxDiscountCoupons = new WxDiscountCoupons(); Discount discount = new Discount(); discount.base_info = _base_info; discount.discount = (int)(100 - coupons.Money * 0.1); wxDiscountCoupons.discount = discount; json = JsonConvert.SerializeObject(new { card = wxDiscountCoupons }); } string result = Utility.IO.Context.PostData($"https://api.weixin.qq.com/card/create?access_token={authorizer_access_token}", json); if (string.IsNullOrEmpty(result)) { return(_createCardResult); } _createCardResult = JsonConvert.DeserializeObject <CreateCardResult>(result); return(_createCardResult); }
public ActionResult GetUserTemplatesList() { int pageindex = Context.GetRequestInt("pageindex", 1); int pagesize = Context.GetRequestInt("pagesize", 20); try { Account account = AccountBLL.SingleModel.GetModel(dzuserId); List <XcxAppAccountRelation> miniapplist = new List <XcxAppAccountRelation>(); List <object> mytemplatelist = new List <object>(); if (account != null) { bool ismodel = _customerLoginId.Contains(account.LoginId); #region 小程序 //判断是否是代理登陆 if (agentaccount != null && agentinfo != null && agentinfo.id > 0 && dzuserId != agentuserId) { miniapplist = XcxAppAccountRelationBLL.SingleModel.GetListByaccountIdandAgentId(account.Id.ToString(), agentinfo.id, 0, pagesize, pageindex); } else { miniapplist = XcxAppAccountRelationBLL.SingleModel.GetListByaccountIdandAgentId(account.Id.ToString(), 0, 0, pagesize, pageindex); } if (miniapplist != null && miniapplist.Count > 0) { List <CustomModelRelation> customModelList = new List <CustomModelRelation>(); if (ismodel) { string aids = string.Join(",", miniapplist.Select(s => s.Id)); customModelList = CustomModelRelationBLL.SingleModel.GetListByAIds(aids); } string ids = string.Join(",", miniapplist.Select(s => s.TId).Distinct()); List <XcxTemplate> xcxtemplatelist = XcxTemplateBLL.SingleModel.GetList("id in (" + ids + ")"); if (xcxtemplatelist != null && xcxtemplatelist.Count > 0) { string appIds = $"'{string.Join("','", miniapplist.Where(w=>!string.IsNullOrEmpty(w.AppId))?.Select(s=>s.AppId))}'"; List <UserXcxTemplate> userXcxTemplateList = UserXcxTemplateBLL.SingleModel.GetListByAppIds(appIds); foreach (XcxAppAccountRelation item in miniapplist) { List <OpenAuthorizerConfig> authomodellist = OpenAuthorizerConfigBLL.SingleModel.GetListByaccoundidAndRid(item.AccountId.ToString(), item.Id); XcxTemplate xcxtempmodel = xcxtemplatelist.Where(w => w.Id == item.TId).FirstOrDefault(); if (item.AuthoAppType == 1) { if (!string.IsNullOrEmpty(item.AppId)) { OpenAuthorizerConfig authomodel = authomodellist != null && authomodellist.Count > 0 ? authomodellist[0] : null; if (authomodel != null) { item.XcxName = authomodel.nick_name; UserXcxTemplate uploadmodel = userXcxTemplateList?.FirstOrDefault(f => f.AppId == item.AppId); if (uploadmodel != null) { if (uploadmodel.AddTime.ToString("yyyy-MM-dd") == "0001-01-01") { uploadmodel.State = (int)XcxTypeEnum.未发布; UserXcxTemplateBLL.SingleModel.Update(uploadmodel, "state"); } item.UploadState = uploadmodel.State; item.UploadStateName = Enum.GetName(typeof(XcxTypeEnum), uploadmodel.State); } else { item.UploadState = (int)XcxTypeEnum.未发布; item.UploadStateName = XcxTypeEnum.未发布.ToString(); } } } else { item.XcxName = "未绑定"; item.UploadState = (int)XcxTypeEnum.未发布; item.UploadStateName = XcxTypeEnum.未发布.ToString(); } } else { UserXcxTemplate uploadmodel = userXcxTemplateList?.FirstOrDefault(f => f.AppId == item.AppId); item.XcxName = uploadmodel?.Name; } if (item.outtime <= DateTime.Now) { item.TimeLength = 0; } else { TimeSpan sp = item.outtime.Subtract(DateTime.Now); item.TimeLength = sp.Days <= 0?1:sp.Days; } if (xcxtempmodel != null) { string bangdinurl = "/Config/MiniAppConfig?appId=" + item.Id + "&id=" + item.Id + "&type=" + xcxtempmodel.Type; string TName = xcxtempmodel.TName.Replace("专业版", "专业"); if (xcxtempmodel.Type == 22) { TName += AgentdepositLogBLL.SingleModel.GetVerName(item.VersionId); } string modelname = ""; if (ismodel) { modelname = customModelList.Where(w => w.AId == item.Id).FirstOrDefault()?.Name; modelname = string.IsNullOrEmpty(modelname) ? TName : modelname; } mytemplatelist.Add(new { Id = item.Id, Title = TName, Url = "/" + item.Url + "?Id=" + item.Id + "&appId=" + item.Id + "&versionId=" + item.VersionId,//跳转管理路径 item.TimeLength, outtime = item.outtime.ToString("yyyy-MM-dd"), XcxName = item.XcxName, UploadState = item.UploadState, UploadStateName = item.UploadStateName, item.State, item.AppId, xcxtempmodel.Type, bangdinurl = bangdinurl, //绑定路径 yulang = $"/config/GettestQrcode?Id={item.Id}&tid={item.TId}&needpay=0", //预览路径 iosimg = "", logoimg = xcxtempmodel.TImgurl, //小图标 item.IsExperience, ismodel, modelstate = customModelList.Where(w => w.AId == item.Id).FirstOrDefault()?.State, modelname, modeldesc = customModelList.Where(w => w.AId == item.Id).FirstOrDefault()?.Desc, modelimgurl = customModelList.Where(w => w.AId == item.Id).FirstOrDefault()?.ImgUrl, }); } } } } return(Json(new { isok = 1, msg = "成功", obj = mytemplatelist, accountid = dzuserId }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { isok = -1, msg = "找不到用户信息", obj = new List <object>() }, JsonRequestBehavior.AllowGet)); } #endregion } catch (Exception ex) { log4net.LogHelper.WriteError(this.GetType(), ex); } return(Json(new { isok = -1, msg = "获取用户已开通模板数据出错", obj = new List <object>() }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 获取小程序名称 /// </summary> /// <param name="aid"></param> /// <param name="model"></param> /// <returns></returns> public string GetAppName(int aid, XcxAppAccountRelation model = null, UserXcxTemplate userxcxTmpelate = null, OpenAuthorizerConfig openModel = null) { if (model == null) { if (aid <= 0) { return(""); } model = base.GetModel(aid); } if (model == null) { return(""); } if (model.AuthoAppType == 0) { if (userxcxTmpelate == null) { userxcxTmpelate = UserXcxTemplateBLL.SingleModel.GetModelByAppId(model.AppId); } return(userxcxTmpelate?.Name); } else if (model.AuthoAppType == 1) { if (openModel == null) { openModel = OpenAuthorizerConfigBLL.SingleModel.GetModelByAppids(model.AppId); } return(openModel?.nick_name); } return(""); }
public JsonResult App(Account account) { List <XcxAppAccountRelation> apps = XcxAppAccountRelationBLL.SingleModel.GetListByTemplateType(account.Id.ToString(), TmpType.智慧餐厅); if (apps == null || apps.Count == 0) { return(ApiModel(message: "没有开通智慧餐厅")); } List <XcxTemplate> appTemplates = XcxTemplateBLL.SingleModel.GetListByIds(string.Join(",", apps.Select(s => s.TId).Distinct())); List <OpenAuthorizerConfig> appConfigs = OpenAuthorizerConfigBLL.SingleModel.GetListByaccoundidAndRid(account.Id.ToString(), string.Join(",", apps.Select(item => item.Id))); string appIds = $"'{string.Join("','", apps.FindAll(item => !string.IsNullOrEmpty(item.AppId)).Select(s => s.AppId))}'"; List <UserXcxTemplate> appPublish = UserXcxTemplateBLL.SingleModel.GetListByAppIds(appIds); object formatDTO = apps.Select(app => { XcxTemplate template = appTemplates.Where(thisItem => thisItem.Id == app.TId).FirstOrDefault(); if (app.AuthoAppType == 1) { OpenAuthorizerConfig config = appConfigs.FirstOrDefault(thisItem => thisItem.RId == app.Id); app.XcxName = config?.nick_name; app.UploadStateName = XcxTypeEnum.未发布.ToString(); if (config != null && !string.IsNullOrWhiteSpace(app.AppId)) { UserXcxTemplate publish = appPublish?.FirstOrDefault(item => item.AppId == app.AppId); if (publish != null) { if (publish.AddTime.ToString("yyyy-MM-dd") == "0001-01-01") { publish.State = (int)XcxTypeEnum.未发布; UserXcxTemplateBLL.SingleModel.Update(publish, "state"); } app.UploadStateName = Enum.GetName(typeof(XcxTypeEnum), publish.State); } } } else { app.XcxName = appPublish?.FirstOrDefault(f => f.AppId == app.AppId)?.Name; app.UploadStateName = "手动发布"; } if (string.IsNullOrWhiteSpace(app.XcxName)) { app.XcxName = "未绑定公众号小程序"; } string expireDay = string.Empty; if (app.outtime <= DateTime.Now) { expireDay = "0天"; } else { expireDay = Convert.ToInt32(Math.Round(app.outtime.Subtract(DateTime.Now).TotalDays)).ToString() + "天"; } return(new { app.Id, Template = template.TName, AppTitle = app.XcxName, Icon = template.TImgurl, ExpireDay = expireDay, StoreCount = app.SCount, PublishState = app.UploadStateName, }); }); return(ApiModel(isok: true, message: "获取成功", data: formatDTO)); }