コード例 #1
0
        public IHttpActionResult ExcelBugQuery()
        {
            int s   = 0;
            int sum = 0;

            try
            {
                var filelist = HttpContext.Current.Request.Files;
                var bad      = new List <ExcelBugQueryModel>();
                if (filelist.Count > 0)
                {
                    for (var i = 0; i < filelist.Count; i++)
                    {
                        var file      = filelist[i];
                        var dataTable = ExcelHelp.ExcelToTableForXLSX(file.InputStream);         //excel转成datatable
                        bad = dataTable.ToDataList <ExcelBugQueryModel>();                       //datatable转成list
                    }
                }
                sum = bad.Count();
                using (TransactionScope scope = new TransactionScope())
                {
                    foreach (var item in bad)
                    {
                        var bid = entities.BugQuery.Where(b => b.Id == item.编号).FirstOrDefault();
                        if (item.状态.Equals("0"))
                        {
                            if (bid != null)
                            {
                                bid.State = 4;
                                DbEntityEntry entry = entities.Entry(bid);
                                entry.State = System.Data.Entity.EntityState.Modified;
                                //entities.SaveChanges();

                                //退款
                                var customerFinance = entities.AroundUserFinance.Where(t => t.UserId == bid.UserId).FirstOrDefault();
                                customerFinance.AccountBalance         = customerFinance.AccountBalance + bid.Price;
                                customerFinance.AccumulatedExpenditure = customerFinance.AccumulatedExpenditure - bid.Price;
                                DbEntityEntry entryc = entities.Entry(customerFinance);
                                entryc.State = System.Data.Entity.EntityState.Modified;
                                //entities.SaveChanges();

                                //记录流水
                                TimeSpan             ts  = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
                                AroundUserFinanceLog log = new AroundUserFinanceLog
                                {
                                    BusinessNumber    = Convert.ToInt64(ts.TotalMilliseconds).ToString(),
                                    UserId            = bid.UserId,
                                    PaymentState      = 16,
                                    TransactionType   = 3,
                                    TransactionTime   = DateTime.Now,
                                    TransactionAmount = bid.Price,
                                    Remarks           = "任务:" + bid.Id + " 死因查询退款"
                                };
                                entities.AroundUserFinanceLog.Add(log);
                                //entities.SaveChanges();
                            }
                        }
                        else if (item.状态.Equals("1"))
                        {
                            if (bid != null)
                            {
                                bid.State = 3;
                                DbEntityEntry entry = entities.Entry(bid);
                                entry.State = System.Data.Entity.EntityState.Modified;
                                //entities.SaveChanges();
                            }
                        }
                        else
                        {
                            return(Ok(Respone.No("上传失败")));
                        }
                        s++;
                    }
                    entities.SaveChanges();
                    scope.Complete();
                }
                if (s == sum)
                {
                    return(Ok(Respone.Success("导入成功")));
                }
                else
                {
                    return(Ok(Respone.No("发生了点问题,请稍后再试")));
                }
            }
            catch (Exception ex)
            {
                return(Ok(ex.ToString()));
            }
        }
コード例 #2
0
 public IHttpActionResult ExcelLinkMailboxQuery()
 {
     try
     {
         string uid      = HttpContext.Current.Session["UserId"].ToString();
         int    s        = 0;
         int    sum      = 0;
         var    pric     = entities.NavBySubmeun.Where(e => e.ModularId == 12).Select(e => e.Price).FirstOrDefault();
         var    filelist = HttpContext.Current.Request.Files;
         var    bad      = new List <ExcelLinkMailboxQueryModel>();
         var    linkMail = new List <LinkMailboxQuery>();
         if (filelist.Count > 0)
         {
             for (var i = 0; i < filelist.Count; i++)
             {
                 var file      = filelist[i];
                 var dataTable = ExcelHelp.ExcelToTableForXLSX(file.InputStream);                 //excel转成datatable
                 bad = dataTable.ToDataList <ExcelLinkMailboxQueryModel>();                       //datatable转成list
             }
         }
         sum = bad.Count();
         foreach (var item in bad)
         {
             int cname = entities.Country.Where(e => e.CountryName == item.国家.Trim()).Select(e => e.Id).FirstOrDefault();
             if (cname > 0 && uid != null)
             {
                 var box = new LinkMailboxQuery
                 {
                     UserId     = Convert.ToInt32(uid),
                     State      = 1,
                     Price      = pric,
                     ReviewLink = item.Review,
                     CountryId  = cname,
                     SubTime    = DateTime.Now
                 };
                 linkMail.Add(box);
                 s++;
             }
             else
             {
                 return(Ok(Respone.No("EXCEL数据有误")));
             }
         }
         if (s == sum)
         {
             var dt = linkMail.ToDataTable();
             if (string.IsNullOrWhiteSpace(dt.TableName))
             {
                 dt.TableName = "LinkMailboxQuery";
             }
             SqlBulkCopyHelper.SaveTable(dt);                    //批量插入
             var list = new { succeed = linkMail.Take(100).ToList() };
             return(Ok(Respone.Success("导入成功")));
         }
         else
         {
             return(Ok(Respone.No("导入失败")));
         }
     }
     catch (Exception ex)
     {
         return(Ok(ex.ToString()));
     }
 }