Exemplo n.º 1
0
        /// <summary>
        /// 对任务进行开单
        /// </summary>
        /// <param name="processTask"></param>
        /// <returns></returns>
        public virtual async Task KaiDan(ProcessTask processTask)
        {
            //更改状态至待上机
            if (processTask.ProcessTaskStatus == ProcessTaskStatus.Inputed)
            {
                processTask.ProcessTaskStatus = ProcessTaskStatus.WaitForProcess;
            }
            //add 20190429 设置审核人为当前人员
            if (string.IsNullOrEmpty(processTask.Verifier))
            {
                processTask.Verifier = AbpSession.Name();
            }
            await SaveAsync(processTask);

            await CurrentUnitOfWork.SaveChangesAsync();

            processTask.KaiDate = DateTime.Now;
            //生成加工单号
            GenerateProcessSN(processTask);
            #region 20190506 Tiansfather 如果是外协的单,则开单后提醒发送人
            if (!processTask.Inner && processTask.SupplierId != null)
            {
                //获取所有有发送权限的人
                var users = await Resolve <UserManager>().FindByPermission("Module.JGKD.Button.SendToUnit");

                //提醒接收发送提醒的人
                foreach (var user in users.Where(o => o.Id != AbpSession.UserId && o.HasStatus("ReceiveSendRemind")))
                {
                    var openId = user.GetWechatOpenId();
                    if (!string.IsNullOrEmpty(openId))
                    {
                        //先产生一条提醒记录
                        var remindLog = new RemindLog()
                        {
                            RemindType = "开单待发送提醒",
                            Name       = user.Name,
                            TenantId   = processTask.TenantId,
                            Message    = processTask.ProcessSN
                        };
                        var remindLogId = await Resolve <RemindLogManager>().InsertAndGetIdAsync(remindLog);

                        var arg = new SendWeiXinMessageJobArgs()
                        {
                            OpenId      = openId,
                            DataId      = processTask.Id,
                            RemindLogId = remindLogId
                        };
                        Resolve <IBackgroundJobManager>().Enqueue <TaskToSendMessageJob, SendWeiXinMessageJobArgs>(arg);
                    }
                }
            }
            #endregion
        }
Exemplo n.º 2
0
        public virtual async Task AddFeePoint(DateTime dateTime)
        {
            List <FeePointSetting> feePointSettings = new List <FeePointSetting>();
            var setting = await SettingManager.GetSettingValueForApplicationAsync(SettingNames.FeePointSetting);

            if (!string.IsNullOrEmpty(setting))
            {
                feePointSettings = Newtonsoft.Json.JsonConvert.DeserializeObject <List <FeePointSetting> >(setting);
            }
            feePointSettings.Add(new FeePointSetting()
            {
                FeeDate      = dateTime,
                CreationTime = DateTime.Now,
                Creator      = AbpSession.Name()
            });
            await SettingManager.ChangeSettingForApplicationAsync(SettingNames.FeePointSetting, Newtonsoft.Json.JsonConvert.SerializeObject(feePointSettings));
        }
Exemplo n.º 3
0
        public override async Task Action(FlowSheet flowSheet, string action, DateTime?lastModifyTime)
        {
            //数据处理
            var formObj     = Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(flowSheet.FlowInstance.FormData);
            var sheetData   = formObj["sheetData"];
            var sheetHeader = sheetData["header"];

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

            if (action == "backToCart")
            {
                foreach (var sheetItem in sheetData["body"])
                {
                    var materialId = Convert.ToInt32(sheetItem["id"]);                //对应的物料Id
                    var number     = sheetItem["number"].ToObjectWithDefault <int>(); //订购数量

                    var materialCart = await CartRepository.GetAll().Where(o => o.UnitId == unitId && o.CreatorUserId == AbpSession.UserId && o.MaterialId == materialId).FirstOrDefaultAsync();

                    if (materialCart != null)
                    {
                        materialCart.Number += number;
                        await CartRepository.UpdateAsync(materialCart);
                    }
                    else
                    {
                        materialCart = new MaterialSellCart()
                        {
                            MaterialId = materialId,
                            Number     = number,
                            UnitId     = unitId
                        };
                        await CartRepository.InsertAsync(materialCart);
                    }
                }
                //删除订单
                await FlowSheetManager.DeleteAsync(flowSheet);
            }
            else if (action == "modify")
            {
                if (flowSheet.OrderStatus != "待审核")
                {
                    throw new UserFriendlyException("本单据已被审核,当前操作无效,请重新查看");
                }
            }
            else if (action == "verify")
            {
                if (flowSheet.FlowInstance.LastModificationTime != null && (!lastModifyTime.HasValue || (flowSheet.FlowInstance.LastModificationTime.Value - lastModifyTime.Value).TotalSeconds > 1))
                {
                    throw new UserFriendlyException($"本单据已在{flowSheet.FlowInstance.LastModificationTime?.ToString("yyyy-MM-dd HH:mm:ss")}被{flowSheet.FlowInstance.LastModifierUser?.Name}修改,当前操作无效,请重新查看后再提交");
                }
                flowSheet.OrderStatus = "待发货";
            }
            else if (action == "cancel")
            {
                flowSheet.OrderStatus = "已取消";
            }
            else if (action == "send")
            {
                flowSheet.OrderStatus = "已发货";
                //‘收货时间’‘收货人姓名’‘联系方式’‘收货地址’
                flowSheet.SetPropertyValue("Receiver", sheetHeader["receiver"].ToObjectWithDefault <string>());
                flowSheet.SetPropertyValue("DeliverDate", sheetHeader["deliverDate"].ToObjectWithDefault <DateTime>());
                flowSheet.SetPropertyValue("ReceiverMobile", sheetHeader["receiverMobile"].ToObjectWithDefault <string>());
                flowSheet.SetPropertyValue("ReceiverAddress", sheetHeader["receiverAddress"].ToObjectWithDefault <string>());
                var totalFee = sheetHeader["totalFee"].ToObjectWithDefault <decimal>();
                //更改往来单位金额
                await UnitManager.ChangeFee(unitId, null, -totalFee, flowSheet);

                var materialSellIds = new List <int>();
                var toOutMaterials  = new Dictionary <int, int>();
                var outStoreId      = sheetHeader["storeId"].ToObjectWithDefault <int?>();
                if (outStoreId == null)
                {
                    throw new UserFriendlyException("请选择发货仓库");
                }

                var logs = new List <string>();

                foreach (var sheetItem in sheetData["body"])
                {
                    var materialId   = sheetItem["materialId"].ToObjectWithDefault <int>(); //商品Id
                    var number       = sheetItem["number"].ToObjectWithDefault <int>();     //出货数量
                    var materialSell = await MaterialSellManager.GetAll().Include(o => o.Material)
                                       .Where(o => o.FlowSheetId == flowSheet.Id && o.MaterialId == materialId).FirstOrDefaultAsync();

                    if (materialSell != null)
                    {
                        if (materialSell.SellNumber != number)
                        {
                            //发生订购数量更改需要进行记录
                            logs.Add($"商品\"{materialSell.Material.Name}\"订购数量从{materialSell.SellNumber}调整为{number}");
                        }
                        materialSell.SellNumber = number;
                        materialSell.OutNumber  = materialSell.SellNumber;//设置销售记录的出货数量等于订货数量
                    }
                    //建立销售出库记录
                    var materialSellOut = new MaterialSellOut()
                    {
                        UnitId      = unitId,
                        FlowSheetId = flowSheet.Id,
                        MaterialId  = materialId,
                        OutNumber   = number,
                        Price       = sheetItem["price"].ToObjectWithDefault <decimal>(),
                        Discount    = sheetItem["discount"].ToObjectWithDefault <decimal>()
                    };
                    await MaterialSellOutManager.InsertAsync(materialSellOut);

                    //检测库存是否足够
                    if (!StoreMaterialManager.IsSatisfied(materialId, outStoreId.Value, unitId, number, out var message))
                    {
                        throw new UserFriendlyException(message);
                    }
                    //库存变化
                    await StoreMaterialManager.CountMaterial(outStoreId.Value, materialId, -number, flowSheet);
                }
                if (logs.Count > 0)
                {
                    flowSheet.SetPropertyValue("Log", $"{AbpSession.Name()}于{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}将{string.Join(';', logs)}");
                }
            }
            else if (action == "back")
            {
                var totalFee = sheetHeader["totalFee"].ToObjectWithDefault <decimal>();
                flowSheet.OrderStatus = "已退货";
                //更改往来单位金额
                await UnitManager.ChangeFee(unitId, null, totalFee, flowSheet);

                var materialSellIds = new List <int>();
                var toOutMaterials  = new Dictionary <int, int>();
                var backStoreId     = sheetHeader["backStoreId"].ToObjectWithDefault <int?>();
                if (backStoreId == null)
                {
                    throw new UserFriendlyException("请选择退入仓库");
                }

                foreach (var sheetItem in sheetData["body"])
                {
                    var materialId = sheetItem["materialId"].ToObjectWithDefault <int>(); //商品Id
                    var number     = sheetItem["number"].ToObjectWithDefault <int>();     //出货数量
                    //库存变化
                    await StoreMaterialManager.CountMaterial(backStoreId.Value, materialId, number, flowSheet);

                    //产生退货数据
                    var materialSellBack = new MaterialSellBack()
                    {
                        UnitId      = unitId,
                        MaterialId  = materialId,
                        BackNumber  = number,
                        FlowSheetId = flowSheet.Id,
                        Discount    = sheetItem["discount"].ToObjectWithDefault <decimal>(),
                        Price       = sheetItem["price"].ToObjectWithDefault <decimal>(),
                    };
                    await MaterialSellBackManager.InsertAsync(materialSellBack);
                }
            }
        }