コード例 #1
0
        public IHttpActionResult CollectSupplier(JObject request)
        {
            Logger.WriterLogger("Supplier.CollectSupplier, Params: " + request.ToString(), LoggerType.Info);

            ParamCollectSupplier param = new ParamCollectSupplier();

            try
            {
                param = request.ToObject <ParamCollectSupplier>();
            }
            catch
            {
                // 参数无效
                return(base.JsonFaultResult(new CommonException(40100).GetMessage(), request.ToString()));
            }

            string accessToken = param.accessToken;

            // 验证令牌
            int accessTookenCode = VerifyAccessToken(accessToken);

            if (accessTookenCode > 0)
            {
                return(base.JsonFaultResult(new CommonException(accessTookenCode).GetMessage(), request.ToString()));
            }


            string userId = param.UserId;

            int    channel  = param.channel;
            int    platform = param.platform;
            string ver      = param.ver;

            // 保存访问信息
            base.SaveVisitInfo(userId, channel, platform, ver);

            Member member = GetMember(userId.ToSeesionId());

            if (member != null)
            {
                if (SupplierHelper.GetSupplier(param.SupplierId) == null)
                {
                    StandardResult <string> result = new StandardResult <string>()
                    {
                        code = 1,
                        msg  = "供应商不存在",
                        data = ""
                    };

                    return(base.JsonActionResult(result));
                }
                if (SupplierHelper.SupplierIsCollect(member.UserId, param.SupplierId))
                {
                    StandardResult <string> result = new StandardResult <string>()
                    {
                        code = 1,
                        msg  = "不可重复收藏",
                        data = ""
                    };

                    return(base.JsonActionResult(result));
                }

                SupplierCollectInfo info = new SupplierCollectInfo();

                info.Remark     = "";
                info.SupplierId = param.SupplierId;
                info.UserId     = member.UserId;
                int id = SupplierHelper.CollectSupplier(info);
                if (id > 0)
                {
                    StandardResult <string> result = new StandardResult <string>()
                    {
                        code = 0,
                        msg  = "店铺收藏成功",
                        data = ""
                    };

                    return(base.JsonActionResult(result));
                }

                else
                {
                    StandardResult <string> result = new StandardResult <string>()
                    {
                        code = 1,
                        msg  = "店铺收藏失败",
                        data = ""
                    };

                    return(base.JsonActionResult(result));
                }
            }

            else
            {
                return(base.JsonFaultResult(new CommonException(40201).GetMessage(), request.ToString()));
            }
        }
コード例 #2
0
        /// <summary>
        /// 收藏店铺
        /// </summary>
        /// <param name="context"></param>
        public void CollectSupplier(System.Web.HttpContext context)
        {
            StringBuilder stringBuilder = new StringBuilder();

            context.Response.ContentType = "application/json";
            int supplierId;

            if (!int.TryParse(context.Request["supplierId"], out supplierId))
            {
                stringBuilder.Append("{");
                stringBuilder.Append("\"Success\":0,");
                stringBuilder.Append("\"msg\":\"supplierid错误\"");
                stringBuilder.Append("}");
                this.message = stringBuilder.ToString();
                return;
            }
            Member member = HiContext.Current.User as Member;

            if (member != null)
            {
                if (SupplierHelper.GetSupplier(supplierId) == null)
                {
                    stringBuilder.Append("{");
                    stringBuilder.Append("\"Success\":-1,");
                    stringBuilder.Append("\"msg\":\"店铺不存在\"");
                    stringBuilder.Append("}");
                    this.message = stringBuilder.ToString();
                    return;
                }
                if (SupplierHelper.SupplierIsCollect(member.UserId, supplierId))
                {
                    stringBuilder.Append("{");
                    stringBuilder.Append("\"Success\":-2,");
                    stringBuilder.Append("\"msg\":\"店铺已收藏\"");
                    stringBuilder.Append("}");
                    this.message = stringBuilder.ToString();
                    return;
                }

                SupplierCollectInfo info = new SupplierCollectInfo();

                info.Remark     = "";
                info.SupplierId = supplierId;
                info.UserId     = member.UserId;
                int id = SupplierHelper.CollectSupplier(info);
                if (id > 0)
                {
                    stringBuilder.Append("{");
                    stringBuilder.Append("\"Success\":1,");
                    stringBuilder.Append("\"msg\":\"店铺收藏成功\"");
                    stringBuilder.Append("}");
                    this.message = stringBuilder.ToString();
                    return;
                }

                else
                {
                    stringBuilder.Append("{");
                    stringBuilder.Append("\"Success\":-3,");
                    stringBuilder.Append("\"msg\":\"店铺收藏失败\"");
                    stringBuilder.Append("}");
                    this.message = stringBuilder.ToString();
                    return;
                }
            }

            else
            {
                stringBuilder.Append("{");
                stringBuilder.Append("\"Success\":-4,");
                stringBuilder.Append("\"msg\":\"您还未登陆\"");
                stringBuilder.Append("}");
                this.message = stringBuilder.ToString();
                return;
            }
        }