コード例 #1
0
        public ServiceResult Save(object model, AutoBaseModel autoModel)
        {
            var view = model.MapTo <TestShareOrderView>();
            var user = Resolve <IUserService>().GetSingle(view.UserName);

            if (user == null)
            {
                return(ServiceResult.FailedWithMessage("用户不存在"));
            }

            if (view.Amount <= 0)
            {
                return(ServiceResult.FailedWithMessage("分润金额不能小于0"));
            }

            var shareOrder = new ShareOrder
            {
                UserId      = user.Id,
                EntityId    = user.Id,
                Amount      = view.Amount,
                TriggerType = TriggerType.Other
            };

            if (!Resolve <IShareOrderService>().Add(shareOrder))
            {
                return(ServiceResult.FailedWithMessage("添加失败"));
            }

            return(ServiceResult.Success);
        }
コード例 #2
0
 public ShareRewardInput(ShareOrder shareOrder, Account beforeAccount, Account afterAccount, long shareUserId,
                         decimal shareAmount, long moduleConfigId, long orderUserId)
 {
     ShareOrder     = shareOrder;
     BeforeAccount  = beforeAccount;
     ModuleConfigId = moduleConfigId;
     AfterAccount   = afterAccount;
     ShareAmount    = shareAmount;
     ShareUserId    = shareUserId;
     OrderUserId    = orderUserId;
 }
コード例 #3
0
        /// <summary>
        ///     添加会员注册类型的分润订单
        ///     分润基数为1
        /// </summary>
        /// <param name="user">用户</param>
        protected ShareOrder UserRegShareOrder(User user)
        {
            var shareOrder = new ShareOrder
            {
                EntityId    = user.Id,
                UserId      = user.Id,
                Amount      = 1,
                TriggerType = TriggerType.UserReg
            };

            Resolve <IShareOrderService>().Add(shareOrder);
            return(shareOrder);
        }
コード例 #4
0
        /// <summary>
        ///     获取商城订单
        /// </summary>
        /// <param name="user">用户</param>
        /// <param name="address"></param>
        protected Tuple <ShareOrder, Order> GetShopOrder(User user, UserAddress address = null)
        {
            // 复制id=465的订单
            var order = Resolve <IOrderService>().GetSingle(r => r.Id == 7);

            if (order == null)
            {
                throw new InvalidExpressionException("基础订单不存在,请重新复制订单");
            }

            // 添加订单
            var newOrder = AutoMapping.SetValue <Order>(order);

            newOrder.Id     = 0;
            newOrder.UserId = user.Id;
            newOrder.OrderExtension.User = user;

            if (address != null)
            {
                newOrder.AddressId = address.Id.ToString();
                newOrder.OrderExtension.UserAddress = address;
            }

            newOrder.Extension = newOrder.OrderExtension.ToJson();
            Resolve <IOrderService>().Add(newOrder);

            // 添加订单商品
            var orderProductList = Resolve <IOrderProductService>().GetList(r => r.OrderId == order.Id);

            foreach (var item in orderProductList)
            {
                var orderProduct = AutoMapping.SetValue <OrderProduct>(item);
                orderProduct.Id      = 0;
                orderProduct.OrderId = newOrder.Id;
                Resolve <IOrderProductService>().Add(orderProduct);
            }

            var shareOrder = new ShareOrder
            {
                EntityId    = newOrder.Id,
                UserId      = user.Id,
                Amount      = newOrder.PaymentAmount,
                TriggerType = TriggerType.Order
            };

            Resolve <IShareOrderService>().Add(shareOrder);

            return(Tuple.Create(shareOrder, order));
        }
コード例 #5
0
ファイル: TaskActuator.cs プロジェクト: 2644783865/alabo
        /// <summary>
        ///     开始执行task任务,包括会员升级,分润等
        ///     Executes the task.
        /// </summary>
        /// <typeparam name="TParameter">The type of the t parameter.</typeparam>
        /// <param name="moduleType">The type.</param>
        /// <param name="parameter">参数</param>
        /// <param name="shareOrder"></param>
        /// <returns>ServiceResult.</returns>
        public void ExecuteTask <TParameter>(Type moduleType, ShareOrder shareOrder, TParameter parameter)
            where TParameter : class
        {
            if (parameter == null)
            {
                throw new ArgumentNullException(nameof(parameter));
            }

            if (moduleType == null)
            {
                throw new ArgumentNullException(nameof(moduleType));
            }

            var taskModuleAttribute = moduleType.GetTypeInfo().GetAttribute <TaskModuleAttribute>();

            if (taskModuleAttribute == null)
            {
                throw new ArgumentNullException(nameof(moduleType));
            }

            //从数据库中获取所有分润模块
            var modules = _taskModuleFactory.CreateModules(moduleType);

            if (modules.Count() <= 0)
            {
                return;
            }

            // 参数处理
            var taskParameter = new TaskParameter();
            var propertyList  = GetOrCreatePropertyCache <TParameter>();

            foreach (var item in propertyList)
            {
                taskParameter.AddValue(item.Key.Name, item.Value(parameter));
            }

            var taskMessage = new TaskMessage
            {
                Type       = moduleType.FullName,
                ModuleId   = taskModuleAttribute.Id,
                ModuleName = taskModuleAttribute.Name
            };
            IList <ITaskResult> resultList = new List <ITaskResult>();

            foreach (var item in modules)
            {
                // 通过动态类型获取配置属性
                var configuration = ((dynamic)item).Configuration;
                var triggerType   = (TriggerType)configuration.TriggerType;
                if (triggerType != shareOrder.TriggerType)
                {
                    continue;
                }

                taskMessage.ConfigName = (string)configuration.Name;
                taskParameter.TryGetValue("ShareOrderId", out long ShareOrderId);
                try
                {
                    var result = item.Execute(taskParameter);
                    if (result != null)
                    {
                        if (result.Status == ResultStatus.Success && result.Result.Count() > 0)
                        {
                            resultList.AddRange(result.Result);
                        }
                        else
                        {
                            // 将操作记录更新到数据
                            taskMessage.Message = result.Message;
                            Ioc.Resolve <IShareOrderService>()
                            .AddTaskMessage(ShareOrderId, taskMessage);
                            _logger.LogWarning(result.Message);
                        }
                    }
                }
                catch (Exception ex)
                {
                    //执行出错,将错误写入到数据库中
                    taskMessage.Message = $"DefaultTaskActuator.Execute执行出错{moduleType}:{ex.Message}";
                    Ioc.Resolve <IShareOrderService>().AddTaskMessage(ShareOrderId, taskMessage);
                }
            }

            //更新执行次数
            var repositoryContext = Ioc.Resolve <IShareOrderRepository>();

            repositoryContext.UpdateExcuteCount(shareOrder.Id, modules.Count());

            if (resultList.Count > 0)
            {
                var shareOrderNative = Ioc.Resolve <IShareOrderService>()
                                       .GetSingleNative(shareOrder.Id);
                if (shareOrderNative.Status == ShareOrderStatus.Pending)
                {
                    UpdateTaskPriceResult(resultList);
                }
            }
        }
コード例 #6
0
 protected void AssertReward(ShareOrder shareOrder, long shareUserId, Account beforeAccount,
                             Account afterAccount,
                             decimal shareAmount, long moduleConfigId, Type type)
 {
 }