コード例 #1
0
        public override async Task Handle(FlowSheet flowSheet)
        {
            await base.Handle(flowSheet);

            //数据处理
            var formObj     = Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(flowSheet.FlowInstance.FormData);
            var sheetData   = formObj["sheetData"];
            var sheetHeader = sheetData["header"];

            flowSheet.SheetDate = sheetHeader["sheetDate"].ToObjectWithDefault <DateTime>();
            flowSheet.Remarks   = sheetHeader["remarks"].ToObjectWithDefault <string>();
            var unitId = sheetHeader["unitId"].ToObject <int>();//代理商id

            flowSheet.UnitId = unitId;
            //flowSheet.OrderStatus=CurrentUser.IsCenterUser?"待出库": "待审核";
            //todo:暂不做票劵订单的审核 20200227
            flowSheet.OrderStatus = "待出库";
            flowSheet.SetPropertyValue("OrderType", CurrentUser.IsCenterUser?"中心代为下单": "代理商自助下单");
            //清空对应代理商的票劵购物车
            await CartRepository.DeleteAsync(o => o.CreatorUserId == AbpSession.UserId && o.UnitId == unitId && o.Material.MaterialNature == MaterialNature.票券);

            foreach (var sheetItem in sheetData["body"])
            {
                var materialId = Convert.ToInt32(sheetItem["id"]);                //对应的物料Id
                var number     = sheetItem["number"].ToObjectWithDefault <int>(); //订购数量
                //检测库存
                //var material = await MaterialManager.GetByIdAsync(materialId);
                //var sellMode = await MaterialManager.GetMaterialUnitSellMode(material, unitId);
                //var storeNumber = await StoreMaterialManager.GetMaterialNumber(materialId);
                //if (sellMode==UnitSellMode.售完为止 && number > storeNumber)
                //{
                //    throw new UserFriendlyException($"产品\"{material.Name}\"库存数量不足,无法下单");
                //}
                //记录销售
                var materialSell = new MaterialSell()
                {
                    MaterialId  = materialId,
                    FlowSheetId = flowSheet.Id,
                    SellNumber  = number,
                    Discount    = sheetItem["discount"].ToObjectWithDefault <decimal>(),//折扣
                    UnitId      = unitId
                };
                await MaterialSellManager.InsertAsync(materialSell);
            }
        }
コード例 #2
0
        public override async Task Handle(FlowSheet flowSheet)
        {
            await base.Handle(flowSheet);

            //数据处理
            var formObj     = Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(flowSheet.FlowInstance.FormData);
            var sheetData   = formObj["sheetData"];
            var sheetHeader = sheetData["header"];

            flowSheet.SheetDate = sheetHeader["sheetDate"].ToObjectWithDefault <DateTime>();
            flowSheet.Remarks   = sheetHeader["remarks"].ToObjectWithDefault <string>();
            flowSheet.Fee       = sheetHeader["totalFee"].ToObjectWithDefault <decimal>();
            var unitId = sheetHeader["unitId"].ToObject <int>();//代理商id

            flowSheet.UnitId      = unitId;
            flowSheet.OrderStatus = "待审核";
            flowSheet.SetPropertyValue("OrderType", CurrentUser.IsCenterUser?"中心代为下单": "代理商自助下单");
            //清空对应代理商的实物购物车
            await CartRepository.DeleteAsync(o => o.CreatorUserId == AbpSession.UserId && o.UnitId == unitId && o.Material.MaterialNature == MaterialNature.实物);

            foreach (var sheetItem in sheetData["body"])
            {
                var materialId = Convert.ToInt32(sheetItem["id"]);            //对应的物料Id

                var number = sheetItem["number"].ToObjectWithDefault <int>(); //订购数量
                //记录销售
                var materialSell = new MaterialSell()
                {
                    MaterialId  = materialId,
                    FlowSheetId = flowSheet.Id,
                    SellNumber  = number,
                    UnitId      = unitId
                };
                await MaterialSellManager.InsertAsync(materialSell);
            }
        }