ComplianceServer/oldcode/Core.Web/Controllers/ProductGiftController.cs

208 lines
7.3 KiB
C#

using Core.Web.App_Start;
using Core.Web.WebHelper;
using CRM.Core.BLL.Util;
using CRM.Core.BLL.Wx;
using CRM.Core.Common.Layui;
using CRM.Core.DTO;
using CRM.Core.Model.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using WX.CRM.Common;
namespace Core.Web.Controllers
{
public class ProductGiftController : BaseController
{
private readonly WX_PRODUCT_BL _product = new WX_PRODUCT_BL();
private readonly WX_PRODUCTGIFT_BL _productGift = new WX_PRODUCTGIFT_BL();
private readonly WX_OrderActive_BL _active = new WX_OrderActive_BL();
private readonly CACHE_BL cache_BL = new CACHE_BL();
[HttpGet]
public ActionResult Index()
{
ViewBag.rightCode = RightsConfig.CONST_赠送产品;
ViewBag.companyList = cache_BL.GetCompanyVirtual();
return View();
}
[HttpPost]
[AuthorizeRedirect(RightsConfig.CONST_赠送产品, ToolBarConfig.CONST_NotButton, false)]
public JsonResult Index(Laypage pager, string channel, string subProductName)
{
var list = _productGift.GetList(ref pager, channel, subProductName);
var data = new LayuiData<WX_SZZYSUBPRODUCT_GIFT>()
{
msg = "数据加载成功!",
count = pager.count,
code = 0,
data = list
};
return Json(data, JsonRequestBehavior.AllowGet);
}
[HttpGet]
public ActionResult List(string productCode, int channel)
{
var companyList = cache_BL.GetCompanyCode();
var company = companyList.FirstOrDefault(p => p.Min <= channel && p.Max >= channel);
var companyCode = company.CompanyCode;
var activeList = _active.GetList(productCode, companyCode, DateTime.Now);
ViewBag.activeList = activeList;
return View();
}
[HttpPost]
public JsonResult List(string productCode, int channel, string act)
{
var productList = _product.GetSubProductListByProductId(0, 0, null);
var product = productList.Find(p => p.PRODUCTCODE == productCode);
if (product == null)
{
return Json(new { result = false }, JsonRequestBehavior.AllowGet);
}
LogHelper.Error("1");
var companyList = cache_BL.GetCompanyCode();
var company = companyList.FirstOrDefault(p => p.Min <= channel && p.Max >= channel);
LogHelper.Error("2");
var companyCode = company.CompanyCode;
var activeList = _active.GetList(productCode, companyCode, DateTime.Now);
LogHelper.Error("3" + product.SUBPRODUCTID + ",channel:" + channel);
var list = _productGift.GetList(p => p.SubProductId == product.SUBPRODUCTID && p.Channel == channel).OrderBy(m => m.Sort).ThenBy(m => m.Id);
LogHelper.Error("4");
List<ProductGifList> giflist = new List<ProductGifList>();
foreach (var ac in activeList)
{
giflist.Add(new ProductGifList() { activeid = ac.Id, json = list.Where(m => m.activeid == ac.Id).ToList() });
}
LogHelper.Error("5");
return Json(new { result = true, data = giflist }, JsonRequestBehavior.AllowGet);
}
[HttpGet]
public ActionResult Add(string productCode, int activeid)
{
//var list = product_bl.GetProductList().Where(p => p.parentid == 0);
//List<SelectListItem> productList = new List<SelectListItem>();
//foreach (var item in list)
//{
// productList.Add(new SelectListItem { Text = item.PRODUCTNAME, Value = item.PRODUCTID.ToString() });
//}
//ViewBag.productList = productList;
////var lableName = _softProductService.GetLableName();
////ViewBag.LableName = lableName;
var entry = _active.Get(m => m.Id == activeid);
ViewBag.ActiveName = entry.activename;
var product = _product.GetSubProduct(productCode);
return View(product ?? new WX_SZZYSUBPRODUCT());
}
[HttpPost]
public JsonResult Add(SZZYSUBPRODUCT_GIFT_DTO dto)
{
var result = _productGift.Add(dto);
return Json(new { result }, JsonRequestBehavior.AllowGet);
}
[HttpGet]
public ActionResult Edit(int id)
{
var model = _productGift.Get(p => p.Id == id);
return View(model);
}
[HttpPost]
public JsonResult Edit(WX_SZZYSUBPRODUCT_GIFT dto)
{
try
{
var result = _productGift.UpdateGift(dto);
return Json(new { result }, JsonRequestBehavior.AllowGet);
}
catch (Exception e)
{
LogHelper.Error(e);
return Json(new { result = false }, JsonRequestBehavior.AllowGet);
}
}
[HttpPost]
public JsonResult Delete(int id)
{
try
{
var result = _productGift.Delete(id);
return Json(new { result }, JsonRequestBehavior.AllowGet);
}
catch (Exception e)
{
LogHelper.Error(e);
return Json(new { result = false }, JsonRequestBehavior.AllowGet);
}
}
[HttpPost]
public JsonResult AddActive(string productCode, int channel, string activeCode, int isfolloworder, string gifType, string editoradd, int? id)
{
try
{
if (editoradd == "edit")
{
if (!id.HasValue)
{
return Json(new retMsg() { result = false, retcode = 102, retmsg = "参数错误!" }, JsonRequestBehavior.AllowGet);
}
activeCode = activeCode.Trim();
var result = _active.Update(id.Value, isfolloworder, gifType);
return Json(result, JsonRequestBehavior.AllowGet);
}
else
{
activeCode = activeCode.Trim();
var result = _active.Add(productCode, channel, activeCode, isfolloworder, gifType);
return Json(result, JsonRequestBehavior.AllowGet);
}
}
catch (Exception e)
{
LogHelper.Error(e);
return Json(new { result = false }, JsonRequestBehavior.AllowGet);
}
}
[HttpPost]
public JsonResult DeleteActive(string productCode, int channel, string activeCode)
{
try
{
var result = _active.Delete(productCode, channel, activeCode);
return Json(result, JsonRequestBehavior.AllowGet);
}
catch (Exception e)
{
LogHelper.Error(e);
return Json(new { result = false }, JsonRequestBehavior.AllowGet);
}
}
}
public class ProductGifList
{
public int activeid { get; set; }
public List<WX_SZZYSUBPRODUCT_GIFT> json { get; set; }
}
}