/***********************************************************************
|
* Project: baifenBinfa
|
* ProjectName: 百分兵法管理系统
|
* Web: http://chuanyin.com
|
* Author:
|
* Email:
|
* CreateTime: 202403/02
|
* Description: 暂无
|
***********************************************************************/
|
|
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Threading.Tasks;
|
using CoreCms.Net.Auth.HttpContextUser;
|
using CoreCms.Net.Configuration;
|
using CoreCms.Net.IServices;
|
using CoreCms.Net.Model.Entities;
|
using CoreCms.Net.Model.Entities.Expression;
|
using CoreCms.Net.Model.FromBody;
|
using CoreCms.Net.Model.ViewModels.DTO;
|
using CoreCms.Net.Model.ViewModels.UI;
|
using CoreCms.Net.Utility.Extensions;
|
using CoreCms.Net.Utility.Helper;
|
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Mvc;
|
using SqlSugar;
|
|
namespace CoreCms.Net.Web.WebApi.Controllers
|
{
|
/// <summary>
|
/// 门店调用接口数据
|
/// </summary>
|
[Route("api/[controller]/[action]")]
|
[ApiController]
|
public class StoreController : ControllerBase
|
{
|
private readonly IHttpContextUser _user;
|
private readonly ICoreCmsStoreServices _storeServices;
|
private readonly ICoreCmsClerkServices _clerkServices;
|
private readonly ICoreCmsSettingServices _settingServices;
|
private readonly ICoreCmsBillLadingServices _billLadingServices;
|
private readonly ICoreCmsOrderServices _orderServices;
|
private readonly ICoreCmsUserServices _userServices;
|
|
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
public StoreController(IHttpContextUser user
|
, ICoreCmsStoreServices storeServices
|
, ICoreCmsClerkServices clerkServices
|
, ICoreCmsSettingServices settingServices
|
, ICoreCmsBillLadingServices billLadingServices, ICoreCmsOrderServices orderServices, ICoreCmsUserServices userServices)
|
{
|
_user = user;
|
_storeServices = storeServices;
|
_clerkServices = clerkServices;
|
_settingServices = settingServices;
|
_billLadingServices = billLadingServices;
|
_orderServices = orderServices;
|
_userServices = userServices;
|
}
|
|
//公共接口======================================================================================================
|
|
#region 获取默认的门店
|
/// <summary>
|
/// 获取默认的门店
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
public async Task<WebApiCallBack> GetDefaultStore()
|
{
|
var jm = new WebApiCallBack();
|
|
var ship = await _storeServices.QueryByClauseAsync(p => p.isDefault == true, true, true);
|
jm.status = true;
|
jm.data = ship;
|
|
return jm;
|
}
|
#endregion
|
|
#region 获取门店列表数据
|
/// <summary>
|
/// 获取门店列表数据
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
public async Task<WebApiCallBack> GetStoreList([FromBody] FMGetStoreQueryPageByCoordinate entity)
|
{
|
var jm = new WebApiCallBack();
|
try
|
{
|
var where = PredicateBuilder.True<CoreCmsStore>();
|
|
if (!string.IsNullOrEmpty(entity.key))
|
{
|
where = where.And(p => p.storeName.Contains(entity.key));
|
}
|
|
jm.status = true;
|
|
var data = await _storeServices.QueryPageAsyncByCoordinate(where, p => p.distance, OrderByType.Asc, entity.page, entity.limit, entity.latitude, entity.longitude);
|
|
foreach (var item in data)
|
{
|
if (item.distance > 0)
|
{
|
if (item.distance > 1000)
|
{
|
item.distanceStr = Math.Round(item.distance / 1000, 2) + "km";
|
}
|
else
|
{
|
item.distanceStr = Math.Round(item.distance, 2) + "m";
|
}
|
}
|
else
|
{
|
item.distanceStr = "";
|
}
|
}
|
jm.data = data;
|
jm.otherData = new
|
{
|
totalCount = data.TotalCount,
|
totalPages = data.TotalPages,
|
};
|
}
|
catch (Exception e)
|
{
|
|
jm.msg = GlobalConstVars.DataHandleEx;
|
jm.data = e.ToString();
|
}
|
return jm;
|
}
|
#endregion
|
|
#region 获取推荐关键词
|
/// <summary>
|
/// 获取推荐关键词
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
public async Task<WebApiCallBack> GetRecommendKeys()
|
{
|
var jm = new WebApiCallBack();
|
|
var allConfigs = await _settingServices.GetConfigDictionaries();
|
var recommendKeysStr = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.RecommendKeys);
|
jm.status = true;
|
jm.msg = "获取成功";
|
jm.data = !string.IsNullOrEmpty(recommendKeysStr) ? recommendKeysStr.Split("|") : new string[] { };
|
|
return jm;
|
}
|
#endregion
|
|
#region 判断是否开启门店自提
|
/// <summary>
|
/// 判断是否开启门店自提
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
public async Task<WebApiCallBack> GetStoreSwitch()
|
{
|
var jm = new WebApiCallBack { status = true, msg = "获取成功" };
|
|
var allConfigs = await _settingServices.GetConfigDictionaries();
|
jm.data = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.StoreSwitch).ObjectToInt(2); ;
|
return jm;
|
}
|
#endregion
|
|
#region 根据序列获取门店数据
|
/// <summary>
|
/// 根据序列获取门店数据
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
public async Task<WebApiCallBack> GetStoreById([FromBody] FMIntId entity)
|
{
|
var jm = new WebApiCallBack
|
{
|
status = true,
|
msg = "获取成功",
|
data = await _storeServices.QueryByClauseAsync(p => p.id == entity.id)
|
};
|
return jm;
|
}
|
#endregion
|
|
//验证接口======================================================================================================
|
|
#region 判断是否是商家,店员,开启商家中心
|
/// <summary>
|
/// 判断是否是商家,店员,开启商家中心
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
[Authorize]
|
public async Task<WebApiCallBack> IsClerk()
|
{
|
var jm = await _clerkServices.IsClerk(_user.ID);
|
return jm;
|
}
|
#endregion
|
|
#region 根据用户序列获取门店数据
|
/// <summary>
|
/// 根据用户序列获取门店数据
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
[Authorize]
|
public async Task<WebApiCallBack> GetStoreByUserId([FromBody] FMIntId entity)
|
{
|
var jm = new WebApiCallBack();
|
|
var allConfigs = await _settingServices.GetConfigDictionaries();
|
var shopManagerMobile = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShopManagerMobile);
|
|
var user = await _userServices.QueryByClauseAsync(p => p.id == _user.ID);
|
if (user == null)
|
{
|
jm.status = false;
|
jm.msg = "用户获取失败";
|
return jm;
|
}
|
|
var isManager = !string.IsNullOrEmpty(shopManagerMobile) && shopManagerMobile.Contains(user.mobile);
|
|
if (entity.id == 0 && isManager)
|
{
|
var latlong = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ReshipCoordinate);
|
var latLongArray = !string.IsNullOrEmpty(latlong) ? latlong.Split(",") : new string[2];
|
jm.status = true;
|
jm.data = new CoreCmsStore
|
{
|
id = 0,
|
storeName = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShopName),
|
//mobile = p.mobile,
|
//linkMan = p.linkMan,
|
//logoImage = p.logoImage,
|
//areaId = p.areaId,
|
address = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ReshipAddress),
|
//coordinate = p.coordinate,
|
latitude = latLongArray[0],
|
longitude = latLongArray[1],
|
//isDefault = p.isDefault,
|
//createTime = p.createTime,
|
//updateTime = p.updateTime,
|
|
};
|
}
|
else if (entity.id > 0 && isManager)
|
{
|
jm.status = true;
|
jm.data = await _storeServices.QueryByClauseAsync(p => p.id == entity.id);
|
}
|
else
|
{
|
jm.status = true;
|
jm.data = await _storeServices.GetStoreByUserId(_user.ID, entity.id);
|
}
|
return jm;
|
}
|
#endregion
|
|
#region 获取单个用户能管理的门店列表
|
/// <summary>
|
/// 获取单个用户能管理的门店列表
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
[Authorize]
|
public async Task<WebApiCallBack> GetStoreListForUser([FromBody] FMGetStoreQueryPageByCoordinate entity)
|
{
|
var jm = new WebApiCallBack();
|
try
|
{
|
var where = PredicateBuilder.True<CoreCmsStore>();
|
|
var allConfigs = await _settingServices.GetConfigDictionaries();
|
var shopManagerMobile = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShopManagerMobile);
|
|
var user = await _userServices.QueryByClauseAsync(p => p.id == _user.ID);
|
if (user == null)
|
{
|
jm.status = false;
|
jm.msg = "用户获取失败";
|
return jm;
|
}
|
|
var isManager = !string.IsNullOrEmpty(shopManagerMobile) && shopManagerMobile.Contains(user.mobile);
|
if (!isManager)
|
{
|
var stroes = await _clerkServices.QueryListByClauseAsync(p => p.userId == _user.ID);
|
var stroeIds = stroes.Select(p => p.storeId).ToList();
|
where = where.And(p => stroeIds.Contains(p.id));
|
}
|
|
jm.status = true;
|
|
var data = await _storeServices.QueryPageAsyncByCoordinate(where, p => p.distance, OrderByType.Asc, entity.page, entity.limit, entity.latitude, entity.longitude);
|
|
foreach (var item in data)
|
{
|
if (item.distance > 0)
|
{
|
if (item.distance > 1000)
|
{
|
item.distanceStr = Math.Round(item.distance / 1000, 2) + "km";
|
}
|
else
|
{
|
item.distanceStr = Math.Round(item.distance, 2) + "m";
|
}
|
}
|
else
|
{
|
item.distanceStr = "";
|
}
|
}
|
|
jm.data = data;
|
jm.otherData = new
|
{
|
totalCount = data.TotalCount,
|
totalPages = data.TotalPages,
|
};
|
}
|
catch (Exception e)
|
{
|
|
jm.msg = GlobalConstVars.DataHandleEx;
|
jm.data = e.ToString();
|
}
|
return jm;
|
}
|
#endregion
|
|
#region 获取个人订单列表
|
|
/// <summary>
|
/// 获取个人订单列表
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
[Authorize]
|
public async Task<WebApiCallBack> GetOrderPageByMerchant([FromBody] GetOrderPageByMerchantPost entity)
|
{
|
var jm = new WebApiCallBack();
|
|
var store = await _clerkServices.IsClerk(_user.ID);
|
if (store != null && store.otherData.ObjectToBool())
|
{
|
jm = await _orderServices.GetOrderPageByMerchant(entity.dateType, entity.date, entity.status, entity.receiptType, entity.storeId, entity.page, entity.limit);
|
}
|
else
|
{
|
jm.status = false;
|
jm.msg = "你不是店员";
|
}
|
|
return jm;
|
}
|
|
#endregion
|
|
#region 搜索订单
|
|
/// <summary>
|
/// 搜索订单
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
[Authorize]
|
public async Task<WebApiCallBack> GetOrderPageByMerchantSearch([FromBody] GetOrderPageByMerchantSearcgPost entity)
|
{
|
var jm = new WebApiCallBack();
|
|
var store = await _clerkServices.IsClerk(_user.ID);
|
if (store != null && store.otherData.ObjectToBool())
|
{
|
jm = await _orderServices.GetOrderPageByMerchantSearch(entity.keyword, entity.status, entity.receiptType, entity.storeId, entity.page, entity.limit);
|
}
|
else
|
{
|
jm.status = false;
|
jm.msg = "你不是店员";
|
}
|
|
return jm;
|
}
|
|
#endregion
|
|
|
#region 店铺提货单列表
|
/// <summary>
|
/// 店铺提货单列表
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
[Authorize]
|
public async Task<WebApiCallBack> StoreLadingList([FromBody] FMPageByIntId entity)
|
{
|
var jm = await _billLadingServices.GetStoreLadingList(_user.ID, entity.id, entity.page, entity.limit);
|
return jm;
|
}
|
#endregion
|
|
#region 删除提货单数据
|
/// <summary>
|
/// 删除提货单数据
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
[Authorize]
|
public async Task<WebApiCallBack> LadingDelete([FromBody] FMStringId entity)
|
{
|
var jm = await _billLadingServices.LadingDelete(entity.id, _user.ID);
|
return jm;
|
}
|
#endregion
|
|
#region 获取单个提货单详情
|
/// <summary>
|
/// 获取单个提货单详情
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
[Authorize]
|
public async Task<WebApiCallBack> LadingInfo([FromBody] FMStringId entity)
|
{
|
var jm = new WebApiCallBack();
|
|
if (string.IsNullOrEmpty(entity.id))
|
{
|
jm.msg = "请提交查询数据关键词";
|
return jm;
|
}
|
jm = await _billLadingServices.GetInfo(entity.id, _user.ID);
|
|
return jm;
|
}
|
#endregion
|
|
#region 核销订单
|
/// <summary>
|
/// 核销订单
|
/// </summary>
|
/// <returns></returns>
|
[HttpPost]
|
[Authorize]
|
public async Task<WebApiCallBack> Lading([FromBody] FMStringId entity)
|
{
|
var jm = new WebApiCallBack();
|
|
if (string.IsNullOrEmpty(entity.id))
|
{
|
jm.msg = "请提交查询数据关键词";
|
return jm;
|
}
|
var array = entity.id.Split(",");
|
var result = await _billLadingServices.LadingOperating(array, _user.ID);
|
jm.status = result.code == 0;
|
jm.msg = result.msg;
|
|
return jm;
|
}
|
#endregion
|
|
|
}
|
}
|