public ActionResult Save(SE_ShareMakeMoneyConfig model)
        {
            ShareMakeMoneyManager manager = new ShareMakeMoneyManager();

            if (manager.Save(model, User.Identity.Name))
            {
                return(Json(1));
            }
            else
            {
                return(Json(0));
            }
        }
        public ActionResult SelectProducts(string datetime, string pid, string displayName, string times, string status, int id)
        {
            ShareMakeMoneyManager manager = new ShareMakeMoneyManager();

            return(Content(JsonConvert.SerializeObject(manager.GetProductEntities(datetime, pid, displayName, times, status, id).OrderByDescending(p => p.CreateDate).Select(o => new
            {
                BatchGuid = o.BatchGuid,
                CreateDate = string.Format("{0:yyyy-MM-dd}", o.CreateDate),
                DisplayName = o.DisplayName,
                ID = o.ID,
                IsMakeMoney = o.IsMakeMoney == true ? "启用" : "禁用",
                IsShare = o.IsShare == true ? "显示" : "不显示",
                Orderby = o.Orderby,
                PID = o.PID,
                Times = o.Times
            }))));
        }
        /// <summary>
        /// 上传 xlsx
        /// </summary>
        /// <returns></returns>
        public ActionResult AddProduct(int id)
        {
            try
            {
                //var file = Request.Files[0];

                // if (!file.FileName.Contains(".xlsx") || !file.FileName.Contains(".xls"))
                //     return Json(new { Status = -1, Error = "请上传.xlsx文件或者.xls文件" }, "text/html");

                // var excel = new Tuhu.Provisioning.Controls.ExcelHelper(file.InputStream, file.FileName);
                // var dt = excel.ExcelToDataTable("分享赚钱活动产品", true);
                ShareMakeMoneyManager manager = new ShareMakeMoneyManager();
                var dt = manager.GetFenxiangzhuanqianProduct();
                if (dt == null || dt.Rows.Count == 0)
                {
                    return(Content(JsonConvert.SerializeObject(new { Status = -1, Error = "没有要同步的数据" })));
                }
                List <SE_ShareMakeImportProducts> list = new List <SE_ShareMakeImportProducts>();
                Guid BatchGuid = Guid.NewGuid();
                int  i         = 1;
                foreach (DataRow dr in dt.Rows)
                {
                    if (string.IsNullOrWhiteSpace(dr["PID"].ToString()))
                    {
                        continue;
                    }

                    double times = Convert.ToDouble(dr["multiple"].ToString());
                    if (times < 0.1 || times > 10)
                    {
                        return(Json(new { Status = -1, Error = "积分奖励倍数不符合,配置的PID:" + dr["PID"].ToString() + "积分奖励倍数:" + dr[2].ToString() }, "text/html"));
                    }
                    list.Add(new SE_ShareMakeImportProducts()
                    {
                        BatchGuid   = BatchGuid.ToString(),
                        IsMakeMoney = true,
                        IsShare     = false,
                        Orderby     = i++,
                        PID         = dr["PID"].ToString(),
                        Times       = dr["multiple"].ToString()
                    });
                }

                using (var client = new Tuhu.Service.Product.ProductClient())
                {
                    int baseNumber = 1000;
                    int number     = (list.Count / baseNumber);
                    for (int j = 0; j <= number; j++)
                    {
                        var temp   = list.GetRange(j * baseNumber, list.Count < baseNumber ? list.Count : ((j + 1) * baseNumber - list.Count) > 0 ? (list.Count - (j * baseNumber)) : baseNumber);
                        var result = client.SelectSkuProductListByPids(temp.Select(o => o.PID).ToList());
                        result.ThrowIfException(true);

                        if (result.Success)
                        {
                            var pids = result.Result.Select(o => o.Pid);
                            foreach (var item in temp)
                            {
                                if (!pids.Contains(item.PID))
                                {
                                    return(Content(JsonConvert.SerializeObject((new { Status = -1, Error = "PID配置有误:PID:" + item.PID }))));
                                }
                                else
                                {
                                    if (temp.Where(o => o.PID == item.PID).Count() > 1)
                                    {
                                        return(Content(JsonConvert.SerializeObject(new { Status = -1, Error = "PID配置有误,同一批次不能有相同的:PID:" + item.PID })));
                                    }
                                    var product = result.Result.Where(o => o.Pid == item.PID).FirstOrDefault();
                                    if (product == null)
                                    {
                                        return(Content(JsonConvert.SerializeObject(new { Status = -1, Error = "PID未查询出来误:PID:" + item.PID })));
                                    }
                                    else
                                    {
                                        item.DisplayName = product.DisplayName;
                                    }
                                }
                            }
                        }
                        else
                        {
                            return(Content(JsonConvert.SerializeObject(new { Status = -1, Error = "调用服务验证产品信息失败" + result.ErrorMessage })));
                        }
                    }
                }


                int resultID = manager.AddProducts(list, id);
                if (resultID > 0)
                {
                    return(Content(JsonConvert.SerializeObject(new { Status = 0, ID = resultID })));
                }
                else
                {
                    return(Content(JsonConvert.SerializeObject(new { Status = -1, Error = "保存失败" })));
                }
            }
            catch (Exception em)
            {
                return(Content(JsonConvert.SerializeObject(new { Status = -1, Error = "请检查文件内容格式是否正确", ErrorMsg = em.Message })));
            }
        }