Ejemplo n.º 1
0
        public string AddOrderTemp(RequestOrderInfo orderInfo)
        {
            try
            {
                #region  单判断库存部分
                if (orderInfo.OrderType != 2)
                {
                    foreach (var item in orderInfo.OrderDetaile)
                    {
                        var sql = string.Format("Select Stock from SKU Where SkuId = {0}", item.SkuId);
                        var q   = dataContext.ExecuteScalar(CommandType.Text, sql);

                        if ((int)q < item.Count)
                        {
                            return("Stock is not enough");
                        }
                    }
                }
                #endregion

                //操作订单积分
                string integralSql = string.Format("update RegistMember Set LeaveIntegral = LeaveIntegral - {0} where MemberId = {1}", orderInfo.OrderPrice, orderInfo.MemberId);
                int    nums        = dataContext.ExecuteNonQuery(CommandType.Text, integralSql);

                if (nums > 0)
                {
                    #region 订单新增部分
                    MemberOrder order = new MemberOrder();
                    order.MemberId       = orderInfo.MemberId;
                    order.OrderName      = orderInfo.OrderName;
                    order.OrderTelephone = orderInfo.OrderTelephone;
                    order.OrderState     = orderInfo.OrderState;
                    order.OrderAddress   = orderInfo.OrderAddress;
                    order.OrderPrice     = orderInfo.OrderPrice;
                    order.OrderType      = orderInfo.OrderType;
                    order.InventedType   = orderInfo.InventedType;
                    order.LogisticsNo    = "";
                    order.LogisticsType  = "";
                    order.OrderFrom      = orderInfo.OrderFrom;
                    order.OrderRemark    = orderInfo.OrderRemark;
                    order.AddDate        = DateTime.Now;

                    db.Order.Add(order);
                    db.SaveChanges();
                    #endregion

                    string date   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    string remark = "积分商城:" + order.OrderId;
                    //记录积分操作日志
                    string logsql = string.Format("insert into MemberIntegralDetail values({0},{1},'{2}',2,'积分商城','{2}','{3}','','');", order.MemberId, order.OrderPrice, date, remark);
                    dataContext.ExecuteNonQuery(CommandType.Text, logsql);

                    #region 新增订单商品
                    //新增完订单获取到订单ID然后录入订单商品
                    foreach (var item in orderInfo.OrderDetaile)
                    {
                        string sql = string.Format("Insert into OrderDetaile Values({0},{1},'{2}',{3},{4})", order.OrderId, item.SkuId, item.SkuName, item.ProductId, item.Count);

                        var count = dataContext.ExecuteNonQuery(CommandType.Text, sql);

                        string stockSql = string.Format("Update SKU Set Stock = Stock - {0} Where SkuId = {1}", item.Count, item.SkuId);
                        dataContext.ExecuteNonQuery(CommandType.Text, stockSql);
                    }
                    #endregion

                    //虚拟商品订单-欧飞充值
                    //if (order.OrderType == 2)
                    //{
                    //    int id = orderInfo.OrderDetaile[0].SkuId;
                    //    int skuNum = orderInfo.OrderDetaile[0].Count;
                    //    SKU sku = (from s in db.SKU
                    //               where s.SkuId == id
                    //               select s).FirstOrDefault();
                    //    int price = Convert.ToInt32(sku.MarketPrice);

                    //    if (!string.IsNullOrEmpty(order.OrderTelephone))
                    //    {
                    //        for (int i = 0; i < skuNum; i++)
                    //        {
                    //            LogHelper.WriteLog("共" + skuNum + "件商品,充值电话:" + order.OrderTelephone + ",充值的面值:" + price);
                    //            InventedManage(order.InventedType, order.OrderTelephone, i.ToString(), order.OrderId.ToString(), price);
                    //        }
                    //    }
                    //}
                    return("succ");
                }
                else
                {
                    Common.LogHelper.WriteLog("CreateOrderFromTemp-AddOrder-error" + orderInfo.MemberId.ToString() + orderInfo.OrderName + "Integral is not enough");
                    return("Integral is not enough");
                }
            }
            catch (Exception ex)
            {
                Common.LogHelper.WriteLog("CreateOrderFromTemp-AddOrder-error" + orderInfo.MemberId.ToString() + ex.ToString());
                return("error");
            }
        }
Ejemplo n.º 2
0
        public string CreateOrderFromTemp()
        {
            string    sql = string.Format(@"SELECT  a.Id,a.OpenId ,a.Name,a.Phone,a.PrizeName,c.MemberId,s.SkuId,s.Price,
                                        u.Province+u.City+u.Area+u.Address Address,p.ProductType ,p.ProductId
                                        FROM dbo.TempOrder a 
                                        JOIN dbo.TempUsers u ON u.OpenId = a.OpenId
                                        JOIN dbo.OpenIdAssociated b ON b.OpenId = a.OpenId AND b.UserType =2
                                        JOIN dbo.RegistMember c ON c.MemberId = b.UserId 
                                        JOIN dbo.SKU s ON a.PrizeName = s.SkuName
                                        JOIN dbo.Product p ON p.ProductId = s.ProductId
                                        WHERE (a.Status IS NULL  or LEN(a.Status) =0 ) 
                                            AND a.CreateDate >'2018-09-26 17:50:39.040'  
                                            AND (u.City IS NOT NULL AND LEN(u.City)>0) order by  Id");
            DataTable dt  = dataContext.ExecuteDataTable(CommandType.Text, sql);

            RequestOrderInfo    or           = new RequestOrderInfo();
            List <OrderDetaile> orDetailList = new List <OrderDetaile>();
            OrderDetaile        orDetail     = new OrderDetaile();

            foreach (DataRow dr in dt.Rows)
            {
                or           = new RequestOrderInfo();
                orDetailList = new List <OrderDetaile>();
                orDetail     = new OrderDetaile();
                try
                {
                    if (string.IsNullOrEmpty(dr["Phone"].ToString()))
                    {
                        sql = string.Format(@"UPDATE dbo.TempOrder SET Status = 'fail',Remark='手机号为空' WHERE Id = {0}", dr["Id"].ToString());
                        dataContext.ExecuteNonQuery(CommandType.Text, sql);
                    }
                    else
                    {
                        //orderitem
                        orDetail.OrderDetaileId = 0;
                        orDetail.OrderId        = 0;
                        orDetail.SkuId          = Convert.ToInt32(dr["SkuId"]);
                        orDetail.SkuName        = dr["PrizeName"].ToString();
                        orDetail.ProductId      = Convert.ToInt32(dr["ProductId"]);
                        orDetail.Count          = 1;
                        orDetailList.Add(orDetail);

                        //order基本信息
                        or.MemberId       = Convert.ToInt32(dr["MemberId"]);
                        or.OrderName      = dr["Name"].ToString();
                        or.OrderTelephone = dr["Phone"].ToString();
                        or.OrderState     = "备货中";
                        or.OrderAddress   = dr["Address"].ToString();
                        or.OrderPrice     = 0;//Convert.ToInt32(dr["Price"]);
                        or.OrderType      = Convert.ToInt32(dr["ProductType"]);
                        or.InventedType   = Convert.ToInt32(dr["ProductType"]) == 1 ? 0 : 1;
                        or.OrderFrom      = "匠心寻百味抽奖";
                        or.OrderRemark    = "";

                        or.OrderDetaile = orDetailList;

                        if (AddOrderTemp(or) == "succ")
                        {
                            sql = string.Format("UPDATE TempOrder SET Status = 'succ' WHERE Id = {0}", dr["Id"].ToString());
                            dataContext.ExecuteNonQuery(CommandType.Text, sql);
                        }
                    }
                }
                catch (Exception ex)
                {
                    sql = string.Format("UPDATE TempOrder SET Status = 'fail',Remark='{1}' WHERE Id = {0}", dr["Id"].ToString(), ex.ToString());
                    dataContext.ExecuteNonQuery(CommandType.Text, sql);
                    Common.LogHelper.WriteLog("CreateOrderFromTemp-error" + Convert.ToInt32(dr["OpenId"]) + ex.ToString());
                }
            }
            return("");
        }