Ejemplo n.º 1
0
        public Result UpdatePurchase([FromQuery] string ids, string pIds)
        {
            try
            {
                var    purchases = new List <int>();
                var    idList    = ids.IsNullOrEmpty() ? new List <int>() : ids.Split(",").Select(int.Parse);
                var    pIdList   = pIds.IsNullOrEmpty() ? new List <int>() : pIds.Split(",").Select(int.Parse);
                string sql;
                if (idList.Any())
                {
                    sql = "SELECT PurchaseId FROM `material_purchase_item` WHERE ErpId IN @idList AND `MarkedDelete` = 0";
                    purchases.AddRange(ServerConfig.ApiDb.Query <int>(sql, new { idList }));
                }

                if (pIdList.Any())
                {
                    sql = "SELECT Id FROM `material_purchase` WHERE ErpId IN @pIdList AND `MarkedDelete` = 0";
                    purchases.AddRange(ServerConfig.ApiDb.Query <int>(sql, new { pIdList }));
                }
                if (purchases.Any())
                {
                    HMaterialHelper.ErpPurchaseFunc(purchases);
                }
            }
            catch (Exception e)
            {
                Log.Error($"{ids?.Join() ?? ""}|{pIds?.Join() ?? ""}, {e}");
                return(Result.GenError <Result>(Error.Fail));
            }
            return(Result.GenError <Result>(Error.Success));
        }
Ejemplo n.º 2
0
        public Result PutMaterialPurchase([FromBody] IEnumerable <MaterialPurchase> materialPurchases)
        {
            if (materialPurchases == null || !materialPurchases.Any())
            {
                return(Result.GenError <Result>(Error.MaterialPurchaseNotExist));
            }

            var ids = materialPurchases.Select(x => x.Id);
            var oldMaterialPurchases = MaterialPurchaseHelper.Instance.GetByIds <MaterialPurchase>(ids);

            if (oldMaterialPurchases == null || !oldMaterialPurchases.Any() || oldMaterialPurchases.Count() != materialPurchases.Count())
            {
                return(Result.GenError <Result>(Error.MaterialPurchaseNotExist));
            }
            if (oldMaterialPurchases.Any(x => x.State != MaterialPurchaseStateEnum.订单完成))
            {
                return(Result.GenError <Result>(Error.MaterialPurchaseSateError));
            }

            var markedDateTime = DateTime.Now;

            foreach (var purchase in oldMaterialPurchases)
            {
                purchase.MarkedDateTime = markedDateTime;
                purchase.State          = MaterialPurchaseStateEnum.开始采购;
            }

            MaterialPurchaseHelper.Instance.Update(oldMaterialPurchases);

            HMaterialHelper.ErpPurchaseFunc(ids);
            return(Result.GenError <Result>(Error.Success));
        }