Пример #1
0
        public async Task <BaseApiResponse> AddGoods(AddGoodsRequest request)
        {
            request.CheckNotNull(nameof(request));
            TryInitUserModel();

            //创建商品
            var goodsId = GuidUtil.NewSequentialId();
            var command = new CreateGoodsCommand(
                goodsId,
                request.StoreId,
                request.CategoryIds,
                request.Name,
                request.Description,
                request.Pics,
                request.Price,
                request.OriginalPrice,
                request.Stock,
                request.IsPayOnDelivery,
                request.IsInvoice,
                request.Is7SalesReturn,
                request.Sort);
            var result = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }
            //初始化默认规格
            var thumb = "";

            if (request.Pics.Any())
            {
                thumb = request.Pics[0];
            }
            var command2 = new AddSpecificationCommand(
                goodsId,
                "默认规格",
                "默认规格",
                thumb,
                request.Price,
                request.Stock,
                request.OriginalPrice,
                request.OriginalPrice / 100M,
                "",
                "");
            var result2 = await ExecuteCommandAsync(command2);

            if (!result2.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }
            return(new AddGoodsResponse {
                GoodsId = goodsId
            });
        }
Пример #2
0
        public async Task <IActionResult> Add([FromBody] AddGoodsRequest request)
        {
            try
            {
                var response = await _serviceProvider.HandlerAsync(request);

                return(new JsonResult(response));
            }
            catch (Exception ex)
            {
                return(new JsonResult(new ResponseBase()
                {
                    Result = -1, ResultInfo = ex.Message
                }));
            }
        }
Пример #3
0
        public async Task <BaseApiResponse> StoreUpdateGoods(AddGoodsRequest request)
        {
            request.CheckNotNull(nameof(request));
            TryInitUserModel();

            var command = new StoreUpdateGoodsCommand(
                request.CategoryIds,
                request.Name,
                request.Description,
                request.Pics,
                request.Price,
                request.OriginalPrice,
                request.Stock,
                request.IsPayOnDelivery,
                request.IsInvoice,
                request.Is7SalesReturn,
                request.Sort)
            {
                AggregateRootId = request.Id
            };

            var result = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }
            //更新默认规格
            var specification = _goodsQueryService.GetGoodsDefaultSpecification(request.Id);

            if (specification != null)
            {
                var thumb = specification.Thumb;
                if (request.Pics.Any())
                {
                    thumb = request.Pics[0];
                }
                //更新默认规格
                var command2 = new UpdateSpecificationCommand(
                    request.Id,
                    specification.Id,
                    "默认规格",
                    "默认规格",
                    thumb,
                    request.Price,
                    request.OriginalPrice,
                    request.OriginalPrice / 100M,
                    "",
                    "",
                    request.Stock);
                var result2 = await ExecuteCommandAsync(command2);

                if (!result2.IsSuccess())
                {
                    return(new BaseApiResponse {
                        Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                    });
                }
            }
            return(new BaseApiResponse());
        }
Пример #4
0
 public Task <AddGoodsResponse> AddGoodsAsync(AddGoodsRequest request)
 {
     return(WeChatMiniProgramApiRequester.RequestAsync <AddGoodsResponse>(AddGoodsUrl,
                                                                          HttpMethod.Post,
                                                                          request));
 }
Пример #5
0
        /// <summary>
        /// 微盟-商品信息-添加商品(ec/goods/addGoods)
        /// </summary>
        public void AddGoodsToWm(DateTime startDate, DateTime endDate)
        {
            string preMsg = "微盟 添加商品 ";

            string sql = @"select a.F_GoodsID, a.F_SkuID, a.F_CategoryID, a.F_Name, a.F_ID, a.F_Stop, z.F_PosPrice, a.F_CostPrice, b.F_Qty
                            from v_Item_NoPic a 
                            left join (select F_ItemZID,F_PosPrice from t_ItemZonePriceOne where F_ZoneID = '01') z on a.F_ID = z.F_ItemZID 
                            left join t_StorageQty b on a.F_ID = b.F_ItemID and a.F_ColorID = b.F_ColorID and a.F_SizeID = b.F_SizeID 
                            where a.F_CreaterDate >= '" + startDate.ToString("yyyy-MM-dd HH:mm:ss") + @"'
                              and a.F_CreaterDate < '" + endDate.ToString("yyyy-MM-dd HH:mm:ss") + @"'
                              and a.F_GoodsID is null ";

            DataTable dtItem = sd.GetDataTable(sql);

            Log.WriteLog(preMsg + "取得的记录数:" + dtItem.Rows.Count + "行。", 1);
            if (dtItem.Rows.Count == 0)
            {
                return;
            }

            foreach (DataRow drItem in dtItem.Rows)
            {
                AddGoodsRequest   request = new AddGoodsRequest();
                PendingAddGoodsVo goods   = new PendingAddGoodsVo();
                goods.title         = drItem["F_Name"].ToString();
                goods.isMultiSku    = 0;
                goods.goodsImageUrl = new List <string> {
                    G_INI.ReadValue("Local", "goodsImageUrl")
                };
                goods.initialSales    = 0;
                goods.deductStockType = 1;
                goods.isPutAway       = NumUtil.ToInt(drItem["F_Stop"]);
                goods.Sort            = 0;
                goods.categoryId      = NumUtil.ToLong(drItem["F_CategoryID"]);
                goods.b2cGoods        = new PendingB2CGoodsVo
                {
                    freightTemplateId  = NumUtil.ToLong(G_INI.ReadValue("Local", "freightTemplateId")),
                    deliveryTypeIdList = new List <long> {
                        NumUtil.ToLong(G_INI.ReadValue("Local", "deliveryTypeId"))
                    },
                    b2cGoodsType = 0
                };
                goods.skuList = new List <PendingSkuVo>
                {
                    new PendingSkuVo {
                        outerSkuCode = drItem["F_ID"].ToString(),
                        salePrice    = NumUtil.ToDecimal(drItem["F_PosPrice"]),
                        costPrice    = NumUtil.ToDecimal(drItem["F_CostPrice"]),
                        editStockNum = NumUtil.ToInt(drItem["F_Qty"]),
                        b2cSku       = new PendingB2CSkuVo
                        {
                            weight = 0,
                            volume = 0
                        }
                    }
                };
                request.goods = goods;
                AddGoodsResponse response = HttpPostToWm <AddGoodsResponse>("ec/goods/addGoods", request, preMsg);
                sql = "update t_Item set F_GoodsID = " + response.data.goodsId +
                      " where F_ID = '" + StrUtil.ConvToStr(drItem["F_ID"]) + "';";
                if (response.data.skuList.Count > 0)
                {
                    sql += "update t_ItemDetail set F_SkuID = " + response.data.skuList[0].skuId +
                           " where F_ItemID = '" + StrUtil.ConvToStr(drItem["F_ID"]) + "';";
                }

                int cnt = sd.ExcuteNonQuery(sql);
            }
        }