| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- using System;
- using System.Collections.Generic;
- using System.Common;
- using System.IRepositories;
- using System.Linq;
- using System.Model;
- using System.Security.Claims;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Mvc;
- using TVShoppingCallCenter_ZLJ.Models.Inputs;
- using SqlSugar;
- namespace TVShoppingCallCenter_ZLJ.Controllers.Customer
- {
- //[Authorize]
- [Produces("application/json")]
- [Route("api/[controller]")]
- public class VipInfoController : BaseController
- {
- private readonly ICus_VipInfoRepository _cus_vip_infoRepository;
- private readonly ISys_UserAccountRepository _sys_user_accountRepository;
- public VipInfoController(ICus_VipInfoRepository cus_vip_infoRepository, ISys_UserAccountRepository sys_user_accountRepository)
- {
- _cus_vip_infoRepository = cus_vip_infoRepository;
- _sys_user_accountRepository = sys_user_accountRepository;
- }
- [HttpGet]
- public IActionResult Index()
- {
- return Success("成功");
- }
- /// <summary>
- /// 获取会员列表分页
- /// </summary>
- /// <param name="keyword"></param>
- /// <param name="pageindex"></param>
- /// <param name="pagesize"></param>
- /// <returns></returns>
- [HttpGet("getlistbypage")]
- public async Task<IActionResult> GetListsByPageAsync(string keyword, int pageindex = 1, int pagesize = 20)
- {
- List<IConditionalModel> conModels = new List<IConditionalModel>();
- #region 条件筛选
- conModels.Add(new ConditionalModel() { FieldName = "F_State", ConditionalType = ConditionalType.Equal, FieldValue = ((int)EnumDelState.Enabled).ToString() });
- if (!string.IsNullOrEmpty(keyword))
- conModels.Add(new ConditionalCollections()
- {
- ConditionalList = new List<KeyValuePair<WhereType, ConditionalModel>>()
- {
- new KeyValuePair<WhereType, ConditionalModel>(WhereType.And, new ConditionalModel() { FieldName = "F_Name", ConditionalType = ConditionalType.Like, FieldValue = keyword }),
- new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or , new ConditionalModel() { FieldName = "F_Phone", ConditionalType = ConditionalType.Like, FieldValue = keyword }),
- new KeyValuePair<WhereType, ConditionalModel>( WhereType.Or, new ConditionalModel() { FieldName = "F_VIPCode", ConditionalType = ConditionalType.Like, FieldValue = keyword })
-
- }
- });
- #endregion
- int recordCount = 0;
- var list = await _cus_vip_infoRepository.GetListByPage(conModels, new MyPageModel() { PageIndex = pageindex, PageSize = pagesize, PageCount = recordCount });
- var obj = new
- {
- state = "success",
- message = "成功",
- rows = list,
- total = recordCount,
- };
- return Content(obj.ToJson());
- }
- /// <summary>
- /// 获取会员信息详情
- /// </summary>
- /// <param name="id">id</param>
- /// <returns></returns>
- [HttpGet("getdetailes")]
- public async Task<IActionResult> GetDetailsAsync(int id)
- {
- if (id <= 0)
- return Error("参数错误");
- var model = await _cus_vip_infoRepository.GetSingle(x => x.F_ID == id);
- if (model == null)
- {
- return Error("获取失败");
- }
- return Success("获取成功!", model);
- }
- /// <summary>
- /// 添加会员
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [HttpPost("add")]
- public async Task<IActionResult> AddAsync(VipInfoInput input)
- {
- if (string.IsNullOrEmpty(input.name ))
- return Error("请输入名字");
- if (string.IsNullOrEmpty(input.phone ))
- return Error("请输入手机号");
- var model = new T_Cus_VipInfo();
- model.F_VIPCode = input .vipcode ;//会员卡号
- model.F_Name = input.name;
- model.F_Birthday = input.birthday ;
- model.F_Phone = input.phone;
- model.F_Recommender = input.recommender;
- model.F_Sex = input.sex;
- model.F_Label = input.label;
- model.F_State = input.state;
- model.F_Note = input.note;
- model.F_City = input.city;
- model.F_Nickname = input.nickname;
- model.F_Address = input.address;
- model.F_Address1 = input.address1;
- model.F_RegTime = DateTime.Now;
- model.F_CreateBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
- model.F_CreateOn = DateTime.Now;
- if (await _cus_vip_infoRepository.GetCount(x => x.F_VIPCode == model.F_VIPCode && x.F_Name == input.name) > 0)
- {
- return Error("添加失败,存在相同会员信息");
- }
- var res = await _cus_vip_infoRepository.Add(model);
- if (res > 0)
- {
- return Success("添加成功");
- }
- else
- {
- return Error("添加失败");
- }
- }
- /// <summary>
- /// 修改会员信息
- /// </summary>
- [HttpPost("update")]
- public async Task<IActionResult> UpdateAsync(VipInfoInput input)
- {
- if (string.IsNullOrEmpty(input.name))
- return Error("请输入名字");
- if (string.IsNullOrEmpty(input.phone))
- return Error("请输入手机号");
- var model = await _cus_vip_infoRepository.GetSingle(x => x.F_ID == input.id);
- if (model == null)
- return Error("操作失败");
- //model.F_VIPCode = input.vipcode;//会员卡号
- model.F_Name = input.name;
- model.F_Birthday = input.birthday;
- model.F_Phone = input.phone;
- model.F_Recommender = input.recommender;
- model.F_Sex = input.sex;
- model.F_Label = input.label;
- model.F_State = input.state;
- model.F_Note = input.note;
- model.F_City = input.city;
- model.F_Nickname = input.nickname;
- model.F_Address = input.address;
- model.F_Address1 = input.address1;
- model.F_RegTime = DateTime.Now;
- model.F_LastModifyOn = DateTime.Now.ToLocalTime();
- model.F_LastModifyBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
- bool b = await _cus_vip_infoRepository.Update(model);
- if (b)
- return Success("修改成功");
- return Error("修改失败");
- }
- /// <summary>
- /// 删除会员信息 by ids
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- [HttpPost("delete")]
- public async Task<IActionResult> Remove(int[] ids)
- {
- var res = 0;
- if (ids != null && ids.Length > 0)
- {
- foreach (var item in ids)
- {
- var ml = await _cus_vip_infoRepository.GetSingle(x => x.F_ID == item);
- ml.F_State = (int)EnumDelState.Delete;
- ml.F_DeleteOn = DateTime.Now.ToLocalTime();
- ml.F_DeleteBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
- if (_cus_vip_infoRepository.Update(ml).Result)
- res += 1;
- }
- if (res == ids.Length)
- return Success("删除成功");
- else if (res > 0 && res < ids.Length)
- return Error("部分删除失败,请查看后重新操作");
- else
- return Error("删除失败,请查看后重新操作");
- }
- else
- return Error("请选择要删除的记录");
- }
- }
- }
|