Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
soss
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hooloo
ms
soss
Commits
770c75ff
Commit
770c75ff
authored
Feb 24, 2023
by
weijiguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
下单时校验订单中sku数量
parent
0e138be9
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
200 additions
and
25 deletions
+200
-25
soss-admin/src/main/java/com/soss/web/controller/coffee/WeixinController.java
+28
-0
soss-admin/src/main/test/JavaTest.java
+20
-4
soss-common/src/main/java/com/soss/common/utils/DateUtils.java
+33
-0
soss-system/src/main/java/com/soss/system/domain/Shop.java
+29
-21
soss-system/src/main/java/com/soss/system/mapper/ShopMapper.java
+2
-0
soss-system/src/main/java/com/soss/system/service/impl/AppServiceImpl.java
+84
-0
soss-system/src/main/resources/mapper/system/ShopMapper.xml
+4
-0
No files found.
soss-admin/src/main/java/com/soss/web/controller/coffee/WeixinController.java
View file @
770c75ff
...
...
@@ -19,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
java.text.ParseException
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -102,6 +103,33 @@ public class WeixinController {
return
weixinService
.
wxNotifyTest
(
orderNo
);
}
@RequestMapping
(
"/v2/getShop"
)
public
AjaxResult
getShopV2
(
HttpServletRequest
request
,
@RequestParam
(
required
=
false
)
String
lng
,
@RequestParam
(
required
=
false
)
String
lat
)
throws
ParseException
{
LoginUser
loginUser
=
tokenService
.
getLoginUser
(
request
);
boolean
testFlag
=
false
;
if
(
loginUser
!=
null
)
{
Customer
customer
=
customerService
.
selectCustById
(
loginUser
.
getOpenId
());
if
(
customer
!=
null
)
{
testFlag
=
customer
.
getTestFlag
();
}
}
Shop
shop
=
appService
.
getShop
(
loginUser
,
lng
,
lat
,
testFlag
);
return
AjaxResult
.
success
(
shop
);
}
@RequestMapping
(
"/v2/getLocationShops"
)
public
AjaxResult
getSameLocationShops
(
HttpServletRequest
request
,
@RequestParam
(
required
=
false
)
String
lng
,
@RequestParam
(
required
=
false
)
String
lat
)
throws
ParseException
{
LoginUser
loginUser
=
tokenService
.
getLoginUser
(
request
);
boolean
testFlag
=
false
;
if
(
loginUser
!=
null
)
{
Customer
customer
=
customerService
.
selectCustById
(
loginUser
.
getOpenId
());
if
(
customer
!=
null
)
{
testFlag
=
customer
.
getTestFlag
();
}
}
Shop
shop
=
appService
.
getShop
(
loginUser
,
lng
,
lat
,
testFlag
);
return
AjaxResult
.
success
(
shop
);
}
@RequestMapping
(
"/getShop"
)
public
AjaxResult
getShop
(
HttpServletRequest
request
,
@RequestParam
(
required
=
false
)
String
lng
,
@RequestParam
(
required
=
false
)
String
lat
)
{
...
...
soss-admin/src/main/test/JavaTest.java
View file @
770c75ff
import
java.util.Calendar
;
import
com.soss.common.utils.DateUtils
;
import
com.soss.system.domain.Shop
;
import
java.text.ParseException
;
public
class
JavaTest
{
public
static
void
main
(
String
[]
args
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
System
.
out
.
println
(
calendar
.
get
(
Calendar
.
DAY_OF_WEEK
)
-
1
);
public
static
void
main
(
String
[]
args
)
throws
ParseException
{
Shop
shop
=
new
Shop
();
shop
.
setStartTime
(
"14:21"
);
shop
.
setEndTime
(
"18:00"
);
System
.
out
.
println
(
DateUtils
.
isEffectiveDate
(
shop
.
getStartTime
(),
shop
.
getEndTime
()));
// Shop shop = new Shop();
// shop.setLat("39.91571");
// shop.setLng("116.463485");
// String lat = "39.789916";
// String lng = "116.531469";
// double realDistance = DistanceUtil.getRealDistance(Double.parseDouble(lng), Double.parseDouble(lat), Double.parseDouble(shop.getLng()), Double.parseDouble(shop.getLat()));
// System.out.println(realDistance);
// Calendar calendar = Calendar.getInstance();
// System.out.println(calendar.get(Calendar.DAY_OF_WEEK) - 1);
}
}
soss-common/src/main/java/com/soss/common/utils/DateUtils.java
View file @
770c75ff
...
...
@@ -6,6 +6,7 @@ import java.lang.management.ManagementFactory;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.time.*
;
import
java.util.Calendar
;
import
java.util.Date
;
/**
...
...
@@ -29,6 +30,38 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
"yyyy/MM/dd"
,
"yyyy/MM/dd HH:mm:ss"
,
"yyyy/MM/dd HH:mm"
,
"yyyy/MM"
,
"yyyy.MM.dd"
,
"yyyy.MM.dd HH:mm:ss"
,
"yyyy.MM.dd HH:mm"
,
"yyyy.MM"
};
public
static
boolean
isEffectiveDate
(
String
shopStartTime
,
String
shopEndTime
)
throws
ParseException
{
String
format
=
"HH:mm"
;
SimpleDateFormat
sf
=
new
SimpleDateFormat
(
"HH:mm"
);
String
now
=
sf
.
format
(
new
Date
());
Date
nowTime
=
new
SimpleDateFormat
(
format
).
parse
(
now
);
Date
startTime
=
new
SimpleDateFormat
(
format
).
parse
(
shopStartTime
);
Date
endTime
=
new
SimpleDateFormat
(
format
).
parse
(
shopEndTime
);
return
DateUtils
.
isEffectiveDate
(
nowTime
,
startTime
,
endTime
);
}
public
static
boolean
isEffectiveDate
(
Date
nowTime
,
Date
startTime
,
Date
endTime
)
{
if
(
nowTime
.
getTime
()
==
startTime
.
getTime
()
||
nowTime
.
getTime
()
==
endTime
.
getTime
())
{
return
true
;
}
Calendar
date
=
Calendar
.
getInstance
();
date
.
setTime
(
nowTime
);
Calendar
begin
=
Calendar
.
getInstance
();
begin
.
setTime
(
startTime
);
Calendar
end
=
Calendar
.
getInstance
();
end
.
setTime
(
endTime
);
if
(
date
.
after
(
begin
)
&&
date
.
before
(
end
))
{
return
true
;
}
else
{
return
false
;
}
}
/**
* 获取当前Date型日期
*
...
...
soss-system/src/main/java/com/soss/system/domain/Shop.java
View file @
770c75ff
...
...
@@ -14,13 +14,12 @@ import java.util.List;
/**
* 店铺对象 shop
*
*
* @author zxq
* @date 2022-04-28
*/
@Data
public
class
Shop
extends
BaseEntity
{
public
class
Shop
extends
BaseEntity
{
private
static
final
long
serialVersionUID
=
1L
;
/** 主键 */
...
...
@@ -135,6 +134,15 @@ public class Shop extends BaseEntity
private
Integer
salesVolume
;
/**
* 是否允许下单, 1-可以下单,0-不可以下单
*/
private
Integer
orderState
;
/**
* 不允许下单原因
*/
private
String
stateDesc
;
public
Shop
()
{
super
();
}
...
...
@@ -154,23 +162,23 @@ public class Shop extends BaseEntity
@Override
public
String
toString
()
{
return
new
ToStringBuilder
(
this
,
ToStringStyle
.
MULTI_LINE_STYLE
)
.
append
(
"id"
,
getId
())
.
append
(
"name"
,
getName
())
.
append
(
"code"
,
getCode
())
.
append
(
"lng"
,
getLng
())
.
append
(
"lat"
,
getLat
())
.
append
(
"remarks"
,
getRemarks
())
.
append
(
"startTime"
,
getStartTime
())
.
append
(
"endTime"
,
getEndTime
())
.
append
(
"address"
,
getAddress
())
.
append
(
"province"
,
getProvince
())
.
append
(
"city"
,
getCity
())
.
append
(
"zone"
,
getZone
())
.
append
(
"state"
,
getState
())
.
append
(
"createdAt"
,
getCreatedAt
())
.
append
(
"updatedAt"
,
getUpdatedAt
())
.
append
(
"isDefault"
,
getIsDefault
())
.
toString
();
return
new
ToStringBuilder
(
this
,
ToStringStyle
.
MULTI_LINE_STYLE
)
.
append
(
"id"
,
getId
())
.
append
(
"name"
,
getName
())
.
append
(
"code"
,
getCode
())
.
append
(
"lng"
,
getLng
())
.
append
(
"lat"
,
getLat
())
.
append
(
"remarks"
,
getRemarks
())
.
append
(
"startTime"
,
getStartTime
())
.
append
(
"endTime"
,
getEndTime
())
.
append
(
"address"
,
getAddress
())
.
append
(
"province"
,
getProvince
())
.
append
(
"city"
,
getCity
())
.
append
(
"zone"
,
getZone
())
.
append
(
"state"
,
getState
())
.
append
(
"createdAt"
,
getCreatedAt
())
.
append
(
"updatedAt"
,
getUpdatedAt
())
.
append
(
"isDefault"
,
getIsDefault
())
.
toString
();
}
}
soss-system/src/main/java/com/soss/system/mapper/ShopMapper.java
View file @
770c75ff
...
...
@@ -76,4 +76,6 @@ public interface ShopMapper {
public
int
deleteShopByIds
(
String
[]
ids
);
void
updateNoDefault
();
List
<
Shop
>
selectEnableShops
();
}
soss-system/src/main/java/com/soss/system/service/impl/AppServiceImpl.java
View file @
770c75ff
...
...
@@ -2,6 +2,8 @@ package com.soss.system.service.impl;
import
com.soss.common.core.domain.model.LoginUser
;
import
com.soss.common.enums.ShopState
;
import
com.soss.common.utils.DateUtils
;
import
com.soss.common.utils.StringUtils
;
import
com.soss.system.domain.Order
;
import
com.soss.system.domain.Shop
;
import
com.soss.system.mapper.ShopMapper
;
...
...
@@ -11,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
java.text.ParseException
;
import
java.util.Arrays
;
import
java.util.Comparator
;
import
java.util.List
;
...
...
@@ -24,6 +27,87 @@ public class AppServiceImpl {
@Autowired
private
OrderServiceImpl
orderService
;
public
Shop
getShop
(
LoginUser
loginUser
,
String
lng
,
String
lat
,
Boolean
testFlag
)
throws
ParseException
{
Shop
shop
=
null
;
if
(
StringUtils
.
isEmpty
(
lng
)
||
StringUtils
.
isEmpty
(
lat
))
{
// 未授权位置
if
(
loginUser
==
null
)
{
// 未登录,返回默认店铺
shop
=
getDefaultShop
();
}
else
{
// 已登录
List
<
Order
>
myOrder
=
orderService
.
getMyOrder
(
loginUser
.
getOpenId
());
if
(
CollectionUtils
.
isEmpty
(
myOrder
))
{
// 未下过单返回默认店铺
shop
=
getDefaultShop
();
}
else
{
// 返回最后下单店铺
Order
order
=
myOrder
.
get
(
0
);
shop
=
shopService
.
selectShopById
(
order
.
getShopId
());
}
}
}
else
{
// 授权了位置
List
<
Shop
>
shops
=
shopMapper
.
selectEnableShops
();
// 获取所有非关闭的店铺
if
(
CollectionUtils
.
isEmpty
(
shops
))
{
return
null
;
}
for
(
Shop
s
:
shops
)
{
// 获取所有店铺距离
double
realDistance
=
DistanceUtil
.
getRealDistance
(
Double
.
parseDouble
(
lng
),
Double
.
parseDouble
(
lat
),
Double
.
parseDouble
(
s
.
getLng
()),
Double
.
parseDouble
(
s
.
getLat
()));
s
.
setRealDistance
(
realDistance
);
}
shops
.
sort
(
Comparator
.
comparing
(
Shop:
:
getRealDistance
));
// 按距离排序
for
(
Shop
s
:
shops
)
{
if
(
perfectOrderState
(
s
,
lng
,
lat
))
{
// 是否能下单
shop
=
s
;
}
}
if
(
shop
==
null
)
{
// 没有能下单店铺选择最近的店铺
shop
=
shops
.
get
(
0
);
}
}
if
(
shop
.
getOrderState
()
==
null
)
{
perfectOrderState
(
shop
,
lng
,
lat
);
}
return
shop
;
}
private
boolean
perfectOrderState
(
Shop
shop
,
String
lng
,
String
lat
)
throws
ParseException
{
if
(
shop
==
null
)
{
return
false
;
}
// 状态已停止营业
if
(
shop
.
getState
()
!=
1
)
{
shop
.
setOrderState
(
0
);
shop
.
setStateDesc
(
"门店已暂停营业"
);
return
false
;
}
// 不在营业时间范围内
if
(!
DateUtils
.
isEffectiveDate
(
shop
.
getStartTime
(),
shop
.
getEndTime
()))
{
shop
.
setOrderState
(
0
);
shop
.
setStateDesc
(
"门店已休息"
);
return
false
;
}
// 超出最大配送距离10KM 或 超出店铺设置最大距离
double
realDistance
=
DistanceUtil
.
getRealDistance
(
Double
.
parseDouble
(
lng
),
Double
.
parseDouble
(
lat
),
Double
.
parseDouble
(
shop
.
getLng
()),
Double
.
parseDouble
(
shop
.
getLat
()));
double
realKm
=
realDistance
/
1000
;
double
shopLimit
=
shop
.
getDistanceLimit
()
==
null
?
0
:
shop
.
getDistanceLimit
();
if
(
realKm
>
10
||
realKm
>
shopLimit
)
{
shop
.
setOrderState
(
0
);
shop
.
setStateDesc
(
"距离较远,门店暂停接单"
);
return
false
;
}
shop
.
setOrderState
(
1
);
return
true
;
}
public
Shop
getShop
(
LoginUser
loginUser
)
{
if
(
loginUser
==
null
)
{
// 未登录,返回默认店铺
...
...
soss-system/src/main/resources/mapper/system/ShopMapper.xml
View file @
770c75ff
...
...
@@ -32,6 +32,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select id, name, code, province, city, zone from shop
</select>
<select
id=
"selectEnableShops"
resultMap=
"ShopResult"
>
select * from shop where `state` != 2
</select>
<select
id=
"selectShopList"
parameterType=
"Shop"
resultMap=
"ShopResult"
>
select * from shop s left join machine m on s.id =m.shop_id
<where>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment