コード例 #1
0
ファイル: ProductsController.cs プロジェクト: Bobom/kuanmai
        public ApiMessage VerifyOrder()
        {
            ApiMessage message = new ApiMessage();
            HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"];
            HttpRequestBase request = context.Request;
            string user_id = User.Identity.Name;
            UserManager userMgr = new UserManager(int.Parse(user_id), null);
            BUser user = userMgr.CurrentUser;
            BuyManager buyManager = new BuyManager(userMgr.CurrentUser, userMgr.Shop, userMgr.CurrentUserPermission);
            try
            {
                int oid = 0;
                long comeDate = 0;
                string odetails = request["order_products"];
                string desc = request["description"];
                int.TryParse(request["oid"], out oid);

                if (!string.IsNullOrEmpty(request["comedate"]))
                {
                    comeDate = DateTimeUtil.ConvertDateTimeToInt(Convert.ToDateTime(request["comedate"]));
                }

                BBuy buy = new BBuy();
                buy.ID = 0;
                buy.Order = new BBuyOrder() { ID = oid };
                buy.ComeDate = comeDate;
                buy.Description = desc;
                buy.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                buy.Shop = new BShop() { ID = buyManager.Shop.Shop_ID };
                buy.User = new BUser() { ID = buyManager.CurrentUser.ID };

                if (!string.IsNullOrEmpty(odetails))
                {
                    odetails = HttpUtility.UrlDecode(odetails);
                    buy.Details = new List<BBuyDetail>();

                    JArray jsons = JArray.Parse(odetails);
                    if (jsons != null && jsons.Count > 0)
                    {

                        for (int i = 0; i < jsons.Count; i++)
                        {
                            JObject jOrder = (JObject)jsons[i];
                            int parent_product_id = (int)jOrder["product_id"];
                            JArray cjorders = (JArray)jOrder["orders"];

                            if (cjorders != null && cjorders.Count > 0)
                            {
                                for (int j = 0; j < cjorders.Count; j++)
                                {
                                    JObject json = (JObject)cjorders[j];
                                    BBuyDetail oDetail = new BBuyDetail();
                                    oDetail.Buy_Order_ID = oid;
                                    double price = 0;
                                    int quantity = 0;
                                    double.TryParse(json["price"].ToString(), out price);
                                    int.TryParse(json["quantity"].ToString(), out quantity);
                                    oDetail.Price = price;
                                    oDetail.Product = new BProduct() { ID = (int)json["child_id"] };
                                    oDetail.Quantity = quantity;

                                    if (quantity <= 0)
                                    {
                                        continue;
                                    }
                                    oDetail.Parent_Product_ID = parent_product_id;
                                    buy.Details.Add(oDetail);
                                }
                            }
                        }
                    }
                }

                bool result = buyManager.VerifyBuyOrder(buy);

                if (result)
                {
                    message.Status = "ok";
                }
                else
                {
                    message.Status = "failed";
                    message.Message = "验货单创建失败";
                }
            }
            catch (KM.JXC.Common.KMException.KMJXCException kex)
            {
                message.Status = "failed";
                message.Message = kex.Message;
            }
            catch (Exception ex)
            {
                message.Status = "failed";
                message.Message = ex.Message;
            }
            finally
            {

            }

            return message;
        }
コード例 #2
0
ファイル: BuyManager.cs プロジェクト: Bobom/kuanmai
        /// <summary>
        /// 
        /// </summary>
        /// <param name="buy"></param>
        /// <returns></returns>
        public bool VerifyBuyOrder(BBuy buy)
        {
            bool result = false;
            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                Buy dbBuy=(from dbbuy in db.Buy where dbbuy.Buy_Order_ID==buy.Order.ID select dbbuy).FirstOrDefault<Buy>();
                if (dbBuy == null)
                {
                    result = this.CreateNewBuy(buy, buy.Details);
                }
                else
                {
                    result = this.CreateNewBuyDetails(dbBuy.Buy_ID, buy.Details);
                }

                //update buy order status
                var notVerified = from od in db.Buy_Order_Detail where od.Buy_Order_ID==buy.Order.ID && od.Status == 0 select od;
                if (notVerified.ToList<Buy_Order_Detail>().Count == 0)
                {
                    Buy_Order order=(from o in db.Buy_Order where o.Buy_Order_ID==buy.Order.ID select o).FirstOrDefault<Buy_Order>();
                    if (order != null)
                    {
                        order.Status = 1;
                    }

                    db.SaveChanges();
                }

                result = true;
            }
            return result;
        }
コード例 #3
0
ファイル: BuyManager.cs プロジェクト: Bobom/kuanmai
 /// <summary>
 /// 
 /// </summary>
 /// <param name="buy"></param>
 /// <returns></returns>
 public bool CreateNewBuy(BBuy buy)
 {
     return this.CreateNewBuy(buy,buy.Details);
 }
コード例 #4
0
ファイル: BuyManager.cs プロジェクト: Bobom/kuanmai
        /// <summary>
        /// Create a buy which could contains details information 
        /// </summary>
        /// <param name="buy"></param>
        /// <param name="details">A list of Buy_Detail, it could be NULL</param>
        /// <returns>TRUE/FALSE</returns>
        public bool CreateNewBuy(BBuy buy, List<BBuyDetail> details)
        {
            bool result = false;

            if (this.CurrentUserPermission.ADD_BUY == 0)
            {
                throw new KMJXCException("没有权限创建验货单");
            }

            if (buy.Shop == null || buy.Shop.ID==0)
            {
                buy.Shop = new BShop() { ID = this.Shop.Shop_ID };
            }

            if (buy.User == null || buy.User.ID==0)
            {
                buy.User = new BUser() { ID = this.CurrentUser.ID };
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                Buy dbBuy = new Buy();
                dbBuy.Buy_Order_ID = buy.Order.ID;
                dbBuy.Come_Date = buy.ComeDate;
                dbBuy.Create_Date = buy.Created;
                dbBuy.Description = buy.Description;
                dbBuy.Shop_ID = buy.Shop.ID;
                dbBuy.User_ID = buy.User.ID;
                dbBuy.Status = 0;
                db.Buy.Add(dbBuy);
                db.SaveChanges();
                int buy_id = (int)dbBuy.Buy_ID;
                if (buy_id <= 0)
                {
                    throw new KMJXCException("验货单创建失败");
                }

                if (details != null && details.Count>0)
                {
                    result = true;
                    result = result & this.CreateNewBuyDetails(dbBuy.Buy_ID, details);
                    base.CreateActionLog(new BUserActionLog() { Shop = new BShop { ID = dbBuy.Shop_ID }, Action = new BUserAction() { Action_ID = UserLogAction.CREATE_BUY }, Description = "" });
                }
            }
            return result;
        }