Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
O
on-site-service
Project
Project
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
external
on-site-service
Commits
494a8cee
Commit
494a8cee
authored
Jul 11, 2022
by
kretee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 估价,订单取消,订单退款接口
parent
0de5834e
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
296 additions
and
32 deletions
+296
-32
BizCodeEnum.java
...in/java/com/onsiteservice/constant/enums/BizCodeEnum.java
+14
-2
ServiceOrderStatusEnum.java
.../onsiteservice/constant/enums/ServiceOrderStatusEnum.java
+14
-9
ServiceOrder.java
...ain/java/com/onsiteservice/entity/order/ServiceOrder.java
+4
-0
ServiceOrderController.java
...vice/miniapp/controller/order/ServiceOrderController.java
+46
-8
CancelServiceOrderDTO.java
...e/miniapp/controller/order/dto/CancelServiceOrderDTO.java
+24
-0
FinishServiceOrderDTO.java
...e/miniapp/controller/order/dto/FinishServiceOrderDTO.java
+24
-0
RefundServiceOrderDTO.java
...e/miniapp/controller/order/dto/RefundServiceOrderDTO.java
+24
-0
ServiceOrderService.java
...iteservice/miniapp/service/order/ServiceOrderService.java
+146
-13
No files found.
constant/src/main/java/com/onsiteservice/constant/enums/BizCodeEnum.java
View file @
494a8cee
...
...
@@ -16,6 +16,11 @@ public enum BizCodeEnum {
* 订单分组
*/
SERVICE_ORDER_NOT_EXIST
(
"订单不存在"
),
SERVICE_ORDER_NOT_VALUATION
(
"订单未估价,不能发送给客户"
),
SERVICE_ORDER_CANNOT_CANCEL
(
"订单不能取消"
),
SERVICE_ORDER_CANNOT_REFUND
(
"订单不能申请退款"
),
SERVICE_ORDER_CANNOT_DISPATCH
(
"订单未支付,不能派单"
),
SERVICE_ORDER_CANNOT_FINISH
(
"订单未派单,不能完成本次服务"
),
/**
...
...
@@ -31,9 +36,16 @@ public enum BizCodeEnum {
/**
*
*
服务子类
*/
SERVICE_SUBCLASS_NOT_EXIST
(
"服务项目不存在"
);
SERVICE_SUBCLASS_NOT_EXIST
(
"服务项目不存在"
),
/**
* 权限相关
*/
NO_AUTH_SEND_ORDER_TO_USER
(
"您不能发送订单"
),
NO_AUTH_DISPATCH_ORDER_TO_USER
(
"您不能派单"
);
@Getter
...
...
constant/src/main/java/com/onsiteservice/constant/enums/ServiceOrderStatusEnum.java
View file @
494a8cee
...
...
@@ -20,35 +20,40 @@ public enum ServiceOrderStatusEnum {
/**
* 已受理:估价+发送客户
*/
ACCEPT
(
2
,
"已受理"
),
VALUATION
(
2
,
"已估价"
),
/**
*
*/
SEND
(
3
,
"已发送"
),
/**
* 已支付
*/
PAY
(
3
,
"已支付"
),
PAY
(
4
,
"已支付"
),
/**
* 已派单
*/
DISPATCH
(
4
,
"已派单"
),
DISPATCH
(
5
,
"已派单"
),
/**
* 已确认
*/
CONFIRM
(
5
,
"已确认
"
),
FINISH
(
6
,
"已完成
"
),
/**
*
*/
CANCEL
(
6
,
"已取消"
),
CANCEL
(
7
,
"已取消"
),
/**
* 退款状态
*/
REFUND_APPLY
(
4
,
"申请退款"
),
REFUND_HANDLING
(
4
,
"退款处理中"
),
REFUND_FAIL
(
4
,
"退款失败"
),
REFUND_FINISH
(
4
,
"退款完成"
);
REFUND_APPLY
(
8
,
"申请退款"
),
REFUND_HANDLING
(
9
,
"退款处理中"
),
REFUND_FAIL
(
10
,
"退款失败"
),
REFUND_FINISH
(
11
,
"退款完成"
);
@Getter
...
...
entity/src/main/java/com/onsiteservice/entity/order/ServiceOrder.java
View file @
494a8cee
...
...
@@ -52,6 +52,10 @@ public class ServiceOrder implements Serializable {
@ApiModelProperty
(
"服务地址id"
)
private
Long
addressId
;
@Column
(
name
=
"phone"
)
@ApiModelProperty
(
"客户服务手机号"
)
private
String
phone
;
/**
* 期望上门时间
*/
...
...
mini-app/src/main/java/com/onsiteservice/miniapp/controller/order/ServiceOrderController.java
View file @
494a8cee
...
...
@@ -4,10 +4,7 @@ import com.onsiteservice.common.annotation.user.CurrentUserId;
import
com.onsiteservice.core.result.Result
;
import
com.onsiteservice.dao.common.page.PageInfoVO
;
import
com.onsiteservice.entity.order.ServiceOrder
;
import
com.onsiteservice.miniapp.controller.order.dto.PageServiceOrderDTO
;
import
com.onsiteservice.miniapp.controller.order.dto.SaveServiceOrderDTO
;
import
com.onsiteservice.miniapp.controller.order.dto.SendServiceOrderDTO
;
import
com.onsiteservice.miniapp.controller.order.dto.ValuationServiceOrderDTO
;
import
com.onsiteservice.miniapp.controller.order.dto.*
;
import
com.onsiteservice.miniapp.controller.order.vo.ServiceOrderVO
;
import
com.onsiteservice.miniapp.service.order.ServiceOrderService
;
import
io.swagger.annotations.Api
;
...
...
@@ -62,17 +59,58 @@ public class ServiceOrderController {
return
serviceOrderService
.
save
(
dto
,
userId
)
==
1
?
success
()
:
fail
(
"已预约"
);
}
@ApiOperation
(
value
=
"订单估
计
"
)
@P
u
tMapping
(
"valuation"
)
@ApiOperation
(
value
=
"订单估
价
"
)
@P
os
tMapping
(
"valuation"
)
public
Result
valuation
(
@RequestBody
@NonNull
@Validated
ValuationServiceOrderDTO
dto
,
@CurrentUserId
Long
userId
)
{
return
serviceOrderService
.
valuation
(
dto
,
userId
)
==
1
?
success
()
:
fail
(
"估价失败"
);
}
/**
* 发送订单 已估价订单才能发送 <link>ServiceOrderStatusEnum</link>
*/
@ApiOperation
(
value
=
"发送订单"
)
@P
u
tMapping
(
"send"
)
@P
os
tMapping
(
"send"
)
public
Result
valuation
(
@RequestBody
@NonNull
@Validated
SendServiceOrderDTO
dto
,
@CurrentUserId
Long
userId
)
{
return
serviceOrderService
.
sendOrder
(
dto
,
userId
)
==
1
?
success
()
:
fail
(
"
估价
失败"
);
return
serviceOrderService
.
sendOrder
(
dto
,
userId
)
==
1
?
success
()
:
fail
(
"
发送
失败"
);
}
@ApiOperation
(
value
=
"派单"
)
@PostMapping
(
"dispatch"
)
public
Result
dispatch
(
@RequestBody
@NonNull
@Validated
SendServiceOrderDTO
dto
,
@CurrentUserId
Long
userId
)
{
return
serviceOrderService
.
dispatch
(
dto
,
userId
)
==
1
?
success
()
:
fail
(
"派单失败"
);
}
/**
* 未派单之前不能完成,已申请退款的也可以点击完成
*/
@ApiOperation
(
value
=
"完成订单"
)
@PostMapping
(
"finish"
)
public
Result
finish
(
@RequestBody
@NonNull
@Validated
FinishServiceOrderDTO
dto
,
@CurrentUserId
Long
userId
)
{
return
serviceOrderService
.
finishOrder
(
dto
,
userId
)
==
1
?
success
()
:
fail
(
"取消失败"
);
}
/**
* 订单退款 订单已付款,未派单之前可以取消 <link>ServiceOrderStatusEnum</link>
*/
@ApiOperation
(
value
=
"订单退款"
)
@PostMapping
(
"refund"
)
public
Result
refund
(
@RequestBody
@NonNull
@Validated
RefundServiceOrderDTO
dto
,
@CurrentUserId
Long
userId
)
{
return
serviceOrderService
.
refundOrder
(
dto
,
userId
)
==
1
?
success
()
:
fail
(
"退款失败"
);
}
/**
* 取消订单: 未支付之前可取消订单 <link>ServiceOrderStatusEnum</link>
*/
@ApiOperation
(
value
=
"取消订单"
)
@PostMapping
(
"cancel"
)
public
Result
cancel
(
@RequestBody
@NonNull
@Validated
CancelServiceOrderDTO
dto
,
@CurrentUserId
Long
userId
)
{
return
serviceOrderService
.
cancelOrder
(
dto
,
userId
)
==
1
?
success
()
:
fail
(
"取消失败"
);
}
}
mini-app/src/main/java/com/onsiteservice/miniapp/controller/order/dto/CancelServiceOrderDTO.java
0 → 100644
View file @
494a8cee
package
com
.
onsiteservice
.
miniapp
.
controller
.
order
.
dto
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
javax.validation.constraints.NotNull
;
/**
* <P></P>
*
* @author 李宁
* @version v1.0
* @since 2022/7/7 15:20
*/
@Data
@ApiModel
(
"取消订单请求模型"
)
public
class
CancelServiceOrderDTO
{
@ApiModelProperty
(
value
=
"订单id"
,
required
=
true
)
@NotNull
(
message
=
"请选择要取消的订单"
)
private
Long
id
;
}
mini-app/src/main/java/com/onsiteservice/miniapp/controller/order/dto/FinishServiceOrderDTO.java
0 → 100644
View file @
494a8cee
package
com
.
onsiteservice
.
miniapp
.
controller
.
order
.
dto
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
javax.validation.constraints.NotNull
;
/**
* <P></P>
*
* @author 李宁
* @version v1.0
* @since 2022/7/7 15:20
*/
@Data
@ApiModel
(
"订单完成请求模型"
)
public
class
FinishServiceOrderDTO
{
@ApiModelProperty
(
value
=
"订单id"
,
required
=
true
)
@NotNull
(
message
=
"请选择订单"
)
private
Long
id
;
}
mini-app/src/main/java/com/onsiteservice/miniapp/controller/order/dto/RefundServiceOrderDTO.java
0 → 100644
View file @
494a8cee
package
com
.
onsiteservice
.
miniapp
.
controller
.
order
.
dto
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
javax.validation.constraints.NotNull
;
/**
* <P></P>
*
* @author 李宁
* @version v1.0
* @since 2022/7/7 15:20
*/
@Data
@ApiModel
(
"订单退款请求模型"
)
public
class
RefundServiceOrderDTO
{
@ApiModelProperty
(
value
=
"订单id"
,
required
=
true
)
@NotNull
(
message
=
"请选择您要退款的订单"
)
private
Long
id
;
}
mini-app/src/main/java/com/onsiteservice/miniapp/service/order/ServiceOrderService.java
View file @
494a8cee
...
...
@@ -10,6 +10,7 @@ import com.onsiteservice.core.result.ResultGenerator;
import
com.onsiteservice.dao.common.AbstractMapper
;
import
com.onsiteservice.dao.common.page.PageInfoVO
;
import
com.onsiteservice.dao.mapper.service.ServiceAddressMapper
;
import
com.onsiteservice.dao.mapper.service.ServiceOrderMapper
;
import
com.onsiteservice.dao.mapper.service.ServiceSubclassMapper
;
import
com.onsiteservice.dao.mapper.user.UserMapper
;
import
com.onsiteservice.entity.address.ServiceAddress
;
...
...
@@ -17,16 +18,16 @@ import com.onsiteservice.entity.category.ServiceSubclass;
import
com.onsiteservice.entity.order.ServiceOrder
;
import
com.onsiteservice.entity.user.User
;
import
com.onsiteservice.miniapp.controller.address.vo.ServiceAddressVO
;
import
com.onsiteservice.miniapp.controller.order.dto.PageServiceOrderDTO
;
import
com.onsiteservice.miniapp.controller.order.dto.SaveServiceOrderDTO
;
import
com.onsiteservice.miniapp.controller.order.dto.SendServiceOrderDTO
;
import
com.onsiteservice.miniapp.controller.order.dto.ValuationServiceOrderDTO
;
import
com.onsiteservice.miniapp.controller.order.dto.*
;
import
com.onsiteservice.miniapp.controller.order.vo.ServiceOrderVO
;
import
com.onsiteservice.miniapp.mapper.order.ServiceOrderBizMapper
;
import
com.onsiteservice.miniapp.service.address.ServiceAddressService
;
import
com.onsiteservice.util.AttrCopyUtils
;
import
com.onsiteservice.util.RandomUtils
;
import
com.onsiteservice.util.aliyun.SmsUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.CollectionUtils
;
...
...
@@ -42,6 +43,13 @@ import java.util.stream.Collectors;
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
class
ServiceOrderService
extends
AbstractMapper
<
ServiceOrder
>
{
@Value
(
"${aliyun.sms.sign}"
)
private
String
sign
;
@Autowired
private
SmsUtils
smsUtils
;
@Resource
private
ServiceOrderBizMapper
serviceOrderBizMapper
;
...
...
@@ -57,6 +65,9 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
@Resource
private
UserMapper
userMapper
;
@Resource
private
ServiceOrderMapper
serviceOrderMapper
;
public
ServiceOrderVO
selectById
(
Long
id
,
Long
userId
)
{
// 订单信息
...
...
@@ -112,6 +123,8 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
serviceOrder
.
setAccountNo
(
userId
);
// 订单号
serviceOrder
.
setOrderNo
(
RandomUtils
.
orderNum
());
// 手机号
serviceOrder
.
setPhone
(
serviceAddress
.
getPhone
());
return
this
.
insertSelective
(
serviceOrder
);
}
...
...
@@ -133,25 +146,145 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
// 估价价格
serviceOrder
.
setPrice
(
dto
.
getPrice
());
serviceOrder
.
setOrderStatus
(
ServiceOrderStatusEnum
.
ACCEPT
.
getStatus
());
serviceOrder
.
setOrderStatus
(
ServiceOrderStatusEnum
.
VALUATION
.
getStatus
());
return
this
.
updateByPrimaryKeySelective
(
serviceOrder
);
}
public
int
sendOrder
(
SendServiceOrderDTO
dto
,
Long
userId
)
{
log
.
info
(
"sendOrder dto: {}, userId: {}"
,
dto
,
userId
);
// 判断发送者权限
User
user
=
userMapper
.
selectByPrimaryKey
(
userId
);
if
(
Objects
.
isNull
(
user
)
||
!
user
.
getAdmin
())
{
throw
new
ServiceException
(
BizCodeEnum
.
NO_AUTH_SEND_ORDER_TO_USER
);
}
// 判断能发送的状态
ServiceOrder
serviceOrder
=
serviceOrderMapper
.
selectByPrimaryKey
(
dto
.
getId
());
if
(
Objects
.
isNull
(
serviceOrder
))
{
throw
new
ServiceException
(
BizCodeEnum
.
SERVICE_ORDER_NOT_EXIST
);
}
if
(!
serviceOrder
.
getOrderStatus
().
equals
(
ServiceOrderStatusEnum
.
VALUATION
.
getStatus
()))
{
throw
new
ServiceException
(
BizCodeEnum
.
SERVICE_ORDER_NOT_VALUATION
);
}
serviceOrder
.
setOrderStatus
(
ServiceOrderStatusEnum
.
SEND
.
getStatus
());
int
result
=
serviceOrderMapper
.
updateByPrimaryKeySelective
(
serviceOrder
);
try
{
// 发短信
log
.
info
(
"sendOrder send msg to phone: {}"
,
serviceOrder
.
getPhone
());
// TODO
smsUtils
.
send
(
sign
,
""
,
""
,
serviceOrder
.
getPhone
());
}
catch
(
Exception
e
)
{
log
.
error
(
"sendOrder error, "
,
e
);
}
// TODO 小程序通知客户完成支付
return
result
;
}
public
int
refundOrder
(
RefundServiceOrderDTO
dto
,
Long
userId
)
{
log
.
info
(
"refundOrder dto: {}, userId: {}"
,
dto
,
userId
);
ServiceOrder
serviceOrder
=
checkOrder
(
dto
.
getId
(),
userId
);
if
(!
serviceOrder
.
getOrderStatus
().
equals
(
ServiceOrderStatusEnum
.
PAY
.
getStatus
()))
{
throw
new
ServiceException
(
BizCodeEnum
.
SERVICE_ORDER_CANNOT_REFUND
);
}
// 已申请退款
serviceOrder
.
setOrderStatus
(
ServiceOrderStatusEnum
.
REFUND_APPLY
.
getStatus
());
int
result
=
serviceOrderMapper
.
updateByPrimaryKeySelective
(
serviceOrder
);
try
{
// TODO 调用微信接口退款 ??
// TODO 通知web
}
catch
(
Exception
e
)
{
}
return
result
;
}
public
int
cancelOrder
(
CancelServiceOrderDTO
dto
,
Long
userId
)
{
log
.
info
(
"cancelOrder dto: {}, userId: {}"
,
dto
,
userId
);
ServiceOrder
serviceOrder
=
checkOrder
(
dto
.
getId
(),
userId
);
if
(
serviceOrder
.
getOrderStatus
()
>=
ServiceOrderStatusEnum
.
PAY
.
getStatus
())
{
throw
new
ServiceException
(
BizCodeEnum
.
SERVICE_ORDER_CANNOT_CANCEL
);
}
serviceOrder
.
setOrderStatus
(
ServiceOrderStatusEnum
.
CANCEL
.
getStatus
());
return
serviceOrderMapper
.
updateByPrimaryKeySelective
(
serviceOrder
);
}
public
int
dispatch
(
SendServiceOrderDTO
dto
,
Long
userId
)
{
log
.
info
(
"dispatch dto: {}, userId: {}"
,
dto
,
userId
);
User
user
=
userMapper
.
selectByPrimaryKey
(
userId
);
if
(
Objects
.
isNull
(
user
)
||
!
user
.
getAdmin
())
{
throw
new
ServiceException
(
BizCodeEnum
.
NO_AUTH_DISPATCH_ORDER_TO_USER
);
}
ServiceOrder
serviceOrder
=
serviceOrderMapper
.
selectByPrimaryKey
(
dto
.
getId
());
if
(
Objects
.
isNull
(
serviceOrder
))
{
throw
new
ServiceException
(
BizCodeEnum
.
SERVICE_ORDER_NOT_EXIST
);
}
if
(!
serviceOrder
.
getOrderStatus
().
equals
(
ServiceOrderStatusEnum
.
PAY
.
getStatus
()))
{
throw
new
ServiceException
(
BizCodeEnum
.
SERVICE_ORDER_CANNOT_DISPATCH
);
}
serviceOrder
.
setOrderStatus
(
ServiceOrderStatusEnum
.
PAY
.
getStatus
());
int
result
=
serviceOrderMapper
.
updateByPrimaryKeySelective
(
serviceOrder
);
// TODO 小程序通知 您的订单已为您指派维修工~~~
return
result
;
}
public
int
finishOrder
(
FinishServiceOrderDTO
dto
,
Long
userId
)
{
log
.
info
(
"finishOrder dto: {}, userId: {}"
,
dto
,
userId
);
ServiceOrder
serviceOrder
=
checkOrder
(
dto
.
getId
(),
userId
);
if
(!
serviceOrder
.
getOrderStatus
().
equals
(
ServiceOrderStatusEnum
.
DISPATCH
.
getStatus
()))
{
throw
new
ServiceException
(
BizCodeEnum
.
SERVICE_ORDER_CANNOT_FINISH
);
}
serviceOrder
.
setOrderStatus
(
ServiceOrderStatusEnum
.
FINISH
.
getStatus
());
int
result
=
serviceOrderMapper
.
updateByPrimaryKeySelective
(
serviceOrder
);
// TODO 调用微信接口付款
return
result
;
}
private
ServiceOrder
checkOrder
(
Long
id
,
Long
userId
)
{
Condition
c
=
new
Condition
(
ServiceOrder
.
class
);
c
.
createCriteria
().
andEqualTo
(
"id"
,
id
).
andEqualTo
(
BizConstants
.
UserConstants
.
ACCOUNT_NO
,
userId
);
List
<
ServiceOrder
>
serviceOrderList
=
serviceOrderMapper
.
selectByCondition
(
c
);
if
(
CollectionUtils
.
isEmpty
(
serviceOrderList
))
{
throw
new
ServiceException
(
BizCodeEnum
.
SERVICE_ORDER_NOT_EXIST
);
}
/**
* 判断发送者权限
* 判断能发送的状态
* 发短信
* 小程序通知
*
*/
return
1
;
return
serviceOrderList
.
get
(
0
);
}
...
...
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