示例#1
0
        /// <summary>
        /// 拼享惠产品描述编辑
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult PinRichText(int id = 0)
        {
            string token = WxHelper.GetToken(webview_appid, webview_appsecret, false);

            ViewBag.appid     = AccessTokenContainer.GetFirstOrDefaultAppId();
            ViewBag.ticket    = JsApiTicketContainer.GetJsApiTicket(JsApiTicketContainer.GetFirstOrDefaultAppId());
            ViewBag.timestamp = JSSDKHelper.GetTimestamp();
            ViewBag.nonceStr  = JSSDKHelper.GetNoncestr();

            ViewBag.signature = JSSDKHelper.GetSignature(ViewBag.ticket, ViewBag.nonceStr, ViewBag.timestamp, Server.UrlDecode(GetPageUrl()));
            ViewBag.pageUrl   = GetPageUrl();

            if (id == 0)
            {
                //string temp = RedisUtil.Get<string>(PinGoodsBLL.key_new_pin_goods);
                ViewBag.description = ""; //temp ?? "";
            }
            else
            {
                PinGoods good = PinGoodsBLL.SingleModel.GetModel(id);
                if (good == null)
                {
                    ViewBag.description = "";
                    return(Content("产品不存在或已删除"));
                }
                ViewBag.description = good.description;
            }
            return(View("RichText"));
        }
示例#2
0
 public ActionResult Good(string act = "", int id = 0, int aId = 0, int storeId = 0, int pageIndex = 0, int pageSize = 20, string kw = "", int cateIdOne = 0, int cateId = 0, string sortData = "")
 {
     //显示
     if (string.IsNullOrEmpty(act))
     {
         ViewModel <PinGoods> vm = new ViewModel <PinGoods>();
         var tupleResult         = PinGoodsBLL.SingleModel.GetListFromTable(aId, storeId, pageIndex, pageSize, kw, cateIdOne, cateId);
         vm.DataList          = tupleResult.Item1;
         vm.TotalCount        = tupleResult.Item2;
         vm.PageIndex         = pageIndex;
         vm.PageSize          = pageSize;
         vm.aId               = aId;
         vm.storeId           = storeId;
         ViewBag.categoryList = PinCategoryBLL.SingleModel.GetList($"aid={aId} and storeid=0 and state=1");
         return(View(vm));
     }
     else
     {
         //删除
         if (act == "del")
         {
             if (id <= 0)
             {
                 result.msg = "参数错误";
             }
             else
             {
                 PinGoods updateModel = PinGoodsBLL.SingleModel.GetModel(id);
                 if (updateModel != null)
                 {
                     updateModel.state = -1;
                     bool updateResult = PinGoodsBLL.SingleModel.Update(updateModel);
                     if (updateResult)
                     {
                         result.code = 1;
                         result.msg  = "删除成功";
                     }
                     else
                     {
                         result.msg = "删除失败";
                     }
                 }
                 else
                 {
                     result.msg = "删除失败,菜品不存在";
                 }
             }
         }
         else if (act == "sort")
         {
             bool updateResult = PinGoodsBLL.SingleModel.UpdateSortBatch(sortData);
             result.code = updateResult ? 1 : 0;
             result.msg  = updateResult ? "排序成功" : "排序失败";
         }
     }
     return(Json(result, JsonRequestBehavior.AllowGet));
 }
示例#3
0
        public DeliveryFeeResult GetFreightInfo(PinGoods good, int buyCount, string province, string city)
        {
            PinStore store = PinStoreBLL.SingleModel.GetModelByAid_Id(good.aId, good.storeId);

            if (store == null)
            {
                return(new DeliveryFeeResult {
                    InRange = true, Message = "店铺不存在"
                });
            }
            if (!store.setting.freightSwitch)
            {
                return(new DeliveryFeeResult {
                    InRange = true, Message = "未开启运费模板功能,默认零元运费"
                });
            }

            DeliveryFeeSumMethond sumMethod;

            if (!Enum.TryParse(store.setting.freightSumRule.ToString(), out sumMethod))
            {
                return(new DeliveryFeeResult {
                    Message = "运费规则设置异常"
                });
            }

            DeliveryProduct product = new DeliveryProduct
            {
                Count      = buyCount,
                Id         = good.id,
                Name       = good.name,
                TemplateId = good.FreightTemplate,
                Weight     = good.GetAttrbute().Weight,
            };

            DeliveryFeeResult result = GetDeliveryFeeCommon(new List <DeliveryProduct> {
                product
            }, province, city, sumMethod);

            if (result.Fee > 0)
            {
                result.Message = $"[{sumMethod}]{result.Message}";
            }
            return(result);
        }
示例#4
0
        public void CreateOrder(PinGoodsOrder order, C_UserInfo userInfo, PinGoods goods, SpecificationDetailModel specificationDetail)
        {
            if (order == null || userInfo == null || goods == null)
            {
                order = new PinGoodsOrder();
                return;
            }
            int price      = specificationDetail != null ? specificationDetail.price : goods.price;
            int groupPrice = specificationDetail != null ? specificationDetail.groupPrice : goods.groupPrice;

            order.price       = price * order.count;
            order.money       = order.price + order.freight;
            order.returnMoney = groupPrice * order.count;
            order.userId      = userInfo.Id;
            order.receivingNo = GetCount($" aid={order.aid} and storeId={order.storeId}") + 100001;
            order.outTradeNo  = $"{DateTime.Now.ToString("yyyyMMdd")}{order.receivingNo}";
            order.goodsPhoto  = JsonConvert.SerializeObject(goods);
            if (specificationDetail != null)
            {
                order.specificationPhoto = JsonConvert.SerializeObject(specificationDetail);
            }
            order.id = Convert.ToInt32(Add(order));
            if (order.id > 0)
            {
                switch (order.payway)
                {
                case (int)PayWay.微信支付:
                    order.payNo = CreateWxOrder(order, userInfo.NickName);
                    Update(order, "payno");
                    break;

                case (int)PayWay.余额支付:
                    PayOrderByAccount(order);    //未写
                    break;

                case (int)PayWay.线下支付:
                    order.state = (int)PinOrderState.交易成功;
                    Update(order, "state");
                    break;
                }
            }
        }
示例#5
0
        public ActionResult SavePinRichText(int id, string content)
        {
            if (id > 0)
            {
                PinGoods good = PinGoodsBLL.SingleModel.GetModel(id);
                if (good == null)
                {
                    return(Json(new { isok = false, msg = "产品不存在或已删除" }));
                }
                if (content.Trim() == "")
                {
                    return(Json(new { isok = false, msg = "产品详情不能为空" }));
                }

                good.description = content;
                if (PinGoodsBLL.SingleModel.Update(good, "description"))
                {
                    return(Json(new { isok = true, msg = "保存成功!" }));
                }
                else
                {
                    return(Json(new { isok = false, msg = "保存失败!" }));
                }
            }
            else
            {
                //如果是新增的产品 没有id用一个缓存来保存
                if (RedisUtil.Set(PinGoodsBLL.key_new_pin_goods, content))
                {
                    return(Json(new { isok = true, msg = "保存成功!" }));
                }
                else
                {
                    return(Json(new { isok = false, msg = "保存失败!" }));
                }
            }
        }
示例#6
0
        public ActionResult GoodEdit(string act = "", int id = 0, int aId = 0, int storeId = 0, PinGoods model = null)
        {
            //参数验证
            if (id < 0 || aId <= 0 || storeId <= 0)
            {
                result.msg = "参数错误";
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            //显示
            if (string.IsNullOrEmpty(act))
            {
                if (id == 0)
                {
                    model = new PinGoods();
                }
                else
                {
                    model = PinGoodsBLL.SingleModel.GetModel(id);
                    if (model == null)
                    {
                        return(Content("菜品不存在"));
                    }
                }
                EditModel <PinGoods> em = new EditModel <PinGoods>();
                em.DataModel         = model;
                em.aId               = aId;
                em.storeId           = storeId;
                ViewBag.categoryList = PinCategoryBLL.SingleModel.GetList($"aid={aId} and storeid=0 and state=1");
                ViewBag.attrTypeList = PinAttrBLL.SingleModel.GetList($"aid={aId} and storeid={storeId} and state=1");
                ViewBag.labelList    = PinGoodsLabelBLL.SingleModel.GetList($"aid={aId} and storeid={storeId} and state=1");
                return(View(em));
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    result.code = 0;
                    result.msg  = this.ErrorMsg();
                    return(Json(result));
                }
                if (act == "edit")
                {
                    if (model.groupPrice > 0)
                    {
                        if (model.groupPrice < 1 * 100 || model.groupPrice > 20000 * 100 || model.groupPrice > model.price)
                        {
                            result.code = 0;
                            result.msg  = "返现金额不能小于1元,不能大于2万元,且不能高于产品价格";
                            return(Json(result));
                        }
                    }

                    if (id == 0)
                    {
                        //添加产品
                        int newid = Convert.ToInt32(PinGoodsBLL.SingleModel.Add(model));
                        result.msg  = newid > 0 ? "添加成功" : "添加失败";
                        result.code = newid > 0 ? 1 : 0;
                    }
                    else
                    {
                        if (model.state == 0)
                        {
                            model.auditState = (int)GoodsAuditState.待审核;
                        }

                        bool updateResult = PinGoodsBLL.SingleModel.Update(model);
                        result.msg  = updateResult ? "修改成功" : "修改失败";
                        result.code = updateResult ? 1 : 0;
                    }
                }
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }
示例#7
0
        public ActionResult Good(string act = "", int id = 0, int aId = 0, int storeId = 0, int pageIndex = 0, int pageSize = 20, string sortData = "", string name = "", string shopName = "", string shopTel = "", int cateIdOne = 0, int cateId = 0, int auditState = -10, string orderBy = "indexrank", string orderMode = "desc")
        {
            if (string.IsNullOrEmpty(act))
            {
                pageIndex -= 1;
                if (pageIndex < 0)
                {
                    pageIndex = 0;
                }


                StringBuilder         filterSql  = new StringBuilder();
                ViewModel <PinGoods>  vm         = new ViewModel <PinGoods>();
                List <MySqlParameter> parameters = new List <MySqlParameter>();
                filterSql.Append($" and g.aId = {aId} ");

                if (!string.IsNullOrEmpty(name))
                {
                    filterSql.Append(" and g.name like @name ");
                    parameters.Add(new MySqlParameter("@name", Utils.FuzzyQuery(name)));
                }
                if (!string.IsNullOrEmpty(shopName))
                {
                    filterSql.Append(" and s.storename like @shopName ");
                    parameters.Add(new MySqlParameter("@shopName", Utils.FuzzyQuery(shopName)));
                }
                if (!string.IsNullOrEmpty(shopTel))
                {
                    filterSql.Append(" and s.phone like @shopTel ");
                    parameters.Add(new MySqlParameter("@shopTel", Utils.FuzzyQuery(shopTel)));
                }
                if (cateIdOne > 0)
                {
                    filterSql.Append(" and g.cateIdOne = @cateIdOne ");
                    parameters.Add(new MySqlParameter("@cateIdOne", cateIdOne));
                }
                else if (cateIdOne == 0)
                {
                    filterSql.Append(" and g.cateIdOne not in(SELECT id from pincategory where state=-1 and fid=0) and g.cateId not in(select id from pincategory  where state=-1 and fid<>0) ");
                }
                if (cateId > 0)
                {
                    filterSql.Append(" and g.cateId = @cateId ");
                    parameters.Add(new MySqlParameter("@cateId", cateId));
                }
                if (auditState != -10)
                {
                    filterSql.Append(" and g.auditState = @auditState ");
                    parameters.Add(new MySqlParameter("@auditState", auditState));
                }

                string sql = $"SELECT g.* from pingoods g " +
                             $" inner JOIN pinstore s " +
                             $" on " +
                             $" g.storeid=s.id " +
                             filterSql +
                             $" and s.state=1 " +
                             $" and g.state<>-1 ";
                string orderSql = $" order by  g.{orderBy} {orderMode},g.id desc limit {pageIndex * pageSize},{pageSize}";

                vm.DataList   = PinGoodsBLL.SingleModel.GetListBySql(sql + orderSql, parameters.ToArray());
                vm.TotalCount = PinGoodsBLL.SingleModel.GetCountBySql(sql.Replace("g.*", "count(0)"), parameters.ToArray());
                vm.PageIndex  = pageIndex;
                vm.PageSize   = pageSize;
                vm.aId        = aId;
                vm.storeId    = storeId;
                return(View(vm));
            }
            else
            {
                bool updateResult = false;

                if (act == "updateIndexRank")
                {
                    PinGoods goodModel = PinGoodsBLL.SingleModel.GetModel(id);
                    if (goodModel == null)
                    {
                        result.msg = "产品不存在";
                        return(Json(result));
                    }
                    int rank = Utility.IO.Context.GetRequestInt("value", 0);
                    goodModel.IndexRank = rank;
                    updateResult        = PinGoodsBLL.SingleModel.Update(goodModel, "IndexRank");
                }
                else if (act == "updateAuditState")
                {
                    PinGoods goodModel = PinGoodsBLL.SingleModel.GetModel(id);
                    if (goodModel == null)
                    {
                        result.msg = "产品不存在";
                        return(Json(result));
                    }
                    int state = Utility.IO.Context.GetRequestInt("state", 0);
                    goodModel.auditState = state;
                    if (state == (int)PinEnums.GoodsAuditState.已拒绝)
                    {
                        goodModel.state = 0;
                    }
                    updateResult = PinGoodsBLL.SingleModel.Update(goodModel, "auditState");
                }
                else if (act == "sort")
                {
                    updateResult = PinGoodsBLL.SingleModel.UpdateRankBatch(sortData);
                }
                result.code = updateResult ? 1 : 0;
                result.msg  = updateResult ? "设置成功" : "设置失败";
                return(Json(result));
            }
        }
示例#8
0
        /// <summary>
        /// 完成交易
        /// </summary>
        /// <param name="orders"></param>
        /// <returns></returns>
        public int OrderSuccess(List <PinGoodsOrder> orders, TransactionModel tran = null, string remark = "商家确认交易完成")
        {
            int code = 0;

            if (orders == null || orders.Count <= 0)
            {
                return(code);
            }
            bool isTran = tran != null;

            if (!isTran)
            {
                tran = new TransactionModel();
            }
            string orderIds = string.Join(",", orders.Select(order => order.id));

            string sql = $"update PinGoodsOrder set state={(int)PinEnums.PinOrderState.交易成功},remark='商家确认交易完成',receivingtime='{DateTime.Now}' where id in ({orderIds})";

            tran.Add(sql);

            string groupIds = string.Join(",", orders.Select(order => order.groupId));

            List <PinGroup> groupList = PinGroupBLL.SingleModel.GetList($" id in ({groupIds})");

            if (groupList != null && groupList.Count > 0)
            {
                MySqlParameter[] pone = null;
                foreach (var item in groupList)
                {
                    item.successCount += orders.Where(order => order.groupId == item.id).Count();
                    item.state         = item.successCount >= item.groupCount ? (int)PinEnums.GroupState.拼团成功 : item.state;
                    tran.Add(PinGroupBLL.SingleModel.BuildUpdateSql(item, "successCount,state", out pone), pone);
                }
            }
            //添加销量

            string          goodsIds     = string.Join(",", orders.Select(s => s.goodsId).Distinct());
            List <PinGoods> pinGoodsList = PinGoodsBLL.SingleModel.GetListByIds(goodsIds);

            string          storeIds     = string.Join(",", orders.Select(s => s.storeId).Distinct());
            List <PinStore> pinStoreList = PinStoreBLL.SingleModel.GetListByIds(storeIds);

            foreach (var order in orders)
            {
                PinGoods goods = pinGoodsList?.FirstOrDefault(f => f.id == order.goodsId);
                if (goods == null)
                {
                    continue;
                }
                goods.sales += order.count;
                MySqlParameter[] pone = null;
                tran.Add(PinGoodsBLL.SingleModel.BuildUpdateSql(goods, "sales", out pone), pone);
                PinStore store = pinStoreList?.FirstOrDefault(f => f.id == order.storeId);
                if (store == null)
                {
                    log4net.LogHelper.WriteError(GetType(), new Exception($"找不到店铺信息 orderid:{order.id}"));
                }
                else
                {
                    PinStoreBLL.SingleModel.AddIncome(order, store, tran);//商家增加收入
                }
            }
            if (isTran)
            {
                code = 1;
                return(code);
            }
            code = ExecuteTransactionDataCorect(tran.sqlArray, tran.ParameterArray) ? 1 : 0;
            return(code);
        }