public async Task <IActionResult> MchList([FromQuery] MchListQuery request) { var memberId = this.GetMemberId(); var activityNo = this.GetActivityNo(); if (memberId == 0) { return(BadRequest("未获取会员id")); } var(dataList, total) = await _activityApplication.GetMchListAsync(request); return(this.MyOK(new { dataList, total })); }
/// <summary> /// 获取门店列表 /// </summary> /// <param name="makeWishId"></param> /// <param name="lo"></param> /// <param name="la"></param> /// <returns></returns> public async Task <(IEnumerable <MchItem>, int)> GetMchListAsync(MchListQuery query) { var makeWish = await GetMakeWishAsync(0, query.wishId); if (makeWish == null) { return(new MchItem[0], 0); } var sql = "select max(max_user_count) from t_wish where wish_no=@wishNo AND is_deleted=0"; var maxUserCount = await _jiakeRepository.SQLQueryFirstOrDefaultAsync <int>(sql, new { makeWish.wishNo }); sql = @"SELECT DISTINCT c.id,c.mch_no mchNo,c.mch_name `name`,mch_tel tel,mch_pic pic, fake_wish_complated wishComplated,mch_latitude latitude,mch_longitude longitude FROM t_make_wish b INNER JOIN t_wish a on a.wish_no=b.wish_no AND a.is_deleted=0 INNER JOIN t_merchant c on c.mch_no=a.mch_no and c.is_deleted=0 WHERE (wish_stock>0 or wish_stock is null) AND b.id=@wishId and max_user_count>=@boosts;"; var data = await _jiakeRepository.SQLQueryAsync <MchItem>(sql, new { query.wishId, boosts = maxUserCount > 0 && makeWish.boosts > maxUserCount ? maxUserCount : makeWish.boosts }); if (!data.Any()) { return(data, 0); } foreach (var item in data) { if (query.lo > 0 && query.la > 0) { item.shopDistance = Math.Round(CoordDispose.GetDistance(new Degree(query.lo, query.la), new Degree(item.longitude, item.latitude)) / 1000, 1); } else { item.shopDistance = 999999; } } var total = data.Count(); // 只有第一个按最近距离,其余按次数 if (query.lo > 0 && query.la > 0) { var fistData = data.OrderBy(p => p.shopDistance).FirstOrDefault(); foreach (var i in data) { if (i.id == fistData.id) { i.shopDistance = 0; } else { i.shopDistance = 999999; } } } data = data.OrderBy(p => p.shopDistance).ThenByDescending(p => p.wishComplated).ThenBy(p => p.id) .Skip((query.pageIndex - 1) * query.pageSize).Take(query.pageSize); if (query.pageIndex == 1 && query.la > 0 && query.lo > 0) { data.FirstOrDefault().isShorted = true; } return(data, total); }