Commit f64f7d12 authored by Junling Bu's avatar Junling Bu
Browse files

feat[litemall-db]: 数据库添加售后表 litemall_aftersale

parent ed7cb85e
......@@ -179,5 +179,10 @@
<table tableName="litemall_notice_admin">
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
</table>
<table tableName="litemall_aftersale">
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
<columnOverride column="pictures" javaType="java.lang.String[]"
typeHandler="org.linlinjava.litemall.db.mybatis.JsonStringArrayTypeHandler"/>
</table>
</context>
</generatorConfiguration>
\ No newline at end of file
......@@ -89,6 +89,32 @@ CREATE TABLE `litemall_admin` (
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COMMENT='管理员表';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `litemall_aftersale`
--
DROP TABLE IF EXISTS `litemall_aftersale`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `litemall_aftersale` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`aftersale_sn` varchar(63) DEFAULT NULL COMMENT '售后编号',
`order_id` int(11) NOT NULL COMMENT '订单ID',
`user_id` int(11) NOT NULL COMMENT '用户ID',
`type` smallint(6) DEFAULT '0' COMMENT '售后类型,0是未收货退款,1是已收货(无需退货)退款,2用户退货退款',
`reason` varchar(31) DEFAULT '' COMMENT '退款原因',
`amount` decimal(10,2) DEFAULT '0.00' COMMENT '退款金额',
`pictures` varchar(1023) DEFAULT '[]' COMMENT '退款凭证图片链接数组',
`comment` varchar(511) DEFAULT '' COMMENT '退款说明',
`status` smallint(6) DEFAULT '0' COMMENT '状态,0是用户初始申请,1是管理员接收申请处理中,2是管理员处理成功完成申请,3是管理员拒绝申请',
`handle_time` datetime DEFAULT NULL COMMENT '管理员操作时间',
`add_time` datetime DEFAULT NULL COMMENT '添加时间',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
`deleted` tinyint(1) DEFAULT '0' COMMENT '售后编号',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COMMENT='售后表';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `litemall_brand`
--
......
package org.linlinjava.litemall.db.dao;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.linlinjava.litemall.db.domain.LitemallAftersale;
import org.linlinjava.litemall.db.domain.LitemallAftersaleExample;
public interface LitemallAftersaleMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_aftersale
*
* @mbg.generated
*/
long countByExample(LitemallAftersaleExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_aftersale
*
* @mbg.generated
*/
int deleteByExample(LitemallAftersaleExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_aftersale
*
* @mbg.generated
*/
int deleteByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_aftersale
*
* @mbg.generated
*/
int insert(LitemallAftersale record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_aftersale
*
* @mbg.generated
*/
int insertSelective(LitemallAftersale record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_aftersale
*
* @mbg.generated
*/
LitemallAftersale selectOneByExample(LitemallAftersaleExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_aftersale
*
* @mbg.generated
*/
LitemallAftersale selectOneByExampleSelective(@Param("example") LitemallAftersaleExample example, @Param("selective") LitemallAftersale.Column ... selective);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_aftersale
*
* @mbg.generated
*/
List<LitemallAftersale> selectByExampleSelective(@Param("example") LitemallAftersaleExample example, @Param("selective") LitemallAftersale.Column ... selective);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_aftersale
*
* @mbg.generated
*/
List<LitemallAftersale> selectByExample(LitemallAftersaleExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_aftersale
*
* @mbg.generated
*/
LitemallAftersale selectByPrimaryKeySelective(@Param("id") Integer id, @Param("selective") LitemallAftersale.Column ... selective);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_aftersale
*
* @mbg.generated
*/
LitemallAftersale selectByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_aftersale
*
* @mbg.generated
*/
LitemallAftersale selectByPrimaryKeyWithLogicalDelete(@Param("id") Integer id, @Param("andLogicalDeleted") boolean andLogicalDeleted);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_aftersale
*
* @mbg.generated
*/
int updateByExampleSelective(@Param("record") LitemallAftersale record, @Param("example") LitemallAftersaleExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_aftersale
*
* @mbg.generated
*/
int updateByExample(@Param("record") LitemallAftersale record, @Param("example") LitemallAftersaleExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_aftersale
*
* @mbg.generated
*/
int updateByPrimaryKeySelective(LitemallAftersale record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_aftersale
*
* @mbg.generated
*/
int updateByPrimaryKey(LitemallAftersale record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_aftersale
*
* @mbg.generated
*/
int logicalDeleteByExample(@Param("example") LitemallAftersaleExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table litemall_aftersale
*
* @mbg.generated
*/
int logicalDeleteByPrimaryKey(Integer id);
}
\ No newline at end of file
package org.linlinjava.litemall.db.service;
import com.github.pagehelper.PageHelper;
import org.linlinjava.litemall.db.dao.LitemallAftersaleMapper;
import org.linlinjava.litemall.db.domain.*;
import org.linlinjava.litemall.db.util.AftersaleConstant;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Random;
@Service
public class LitemallAftersaleService {
@Resource
private LitemallAftersaleMapper aftersaleMapper;
public LitemallAftersale findById(Integer id) {
return aftersaleMapper.selectByPrimaryKey(id);
}
public List<LitemallAftersale> queryList(Integer userId, Short status, Integer page, Integer limit, String sort, String order) {
LitemallAftersaleExample example = new LitemallAftersaleExample();
LitemallAftersaleExample.Criteria criteria = example.or();
criteria.andUserIdEqualTo(userId);
if (status != null) {
criteria.andStatusEqualTo(status);
}
criteria.andDeletedEqualTo(false);
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
example.setOrderByClause(sort + " " + order);
}
else{
example.setOrderByClause(LitemallAftersale.Column.addTime.desc());
}
PageHelper.startPage(page, limit);
return aftersaleMapper.selectByExample(example);
}
public List<LitemallAftersale> querySelective(Integer orderId, String aftersaleSn, Integer page, Integer limit, String sort, String order) {
LitemallAftersaleExample example = new LitemallAftersaleExample();
LitemallAftersaleExample.Criteria criteria = example.or();
if (orderId != null) {
criteria.andOrderIdEqualTo(orderId);
}
if (!StringUtils.isEmpty(aftersaleSn)) {
criteria.andAftersaleSnEqualTo(aftersaleSn);
}
criteria.andDeletedEqualTo(false);
if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
example.setOrderByClause(sort + " " + order);
}
else{
example.setOrderByClause(LitemallAftersale.Column.addTime.desc());
}
PageHelper.startPage(page, limit);
return aftersaleMapper.selectByExample(example);
}
private String getRandomNum(Integer num) {
String base = "0123456789";
Random random = new Random();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < num; i++) {
int number = random.nextInt(base.length());
sb.append(base.charAt(number));
}
return sb.toString();
}
public int countByAftersaleSn(Integer userId, String aftersaleSn) {
LitemallAftersaleExample example = new LitemallAftersaleExample();
example.or().andUserIdEqualTo(userId).andAftersaleSnEqualTo(aftersaleSn).andDeletedEqualTo(false);
return (int) aftersaleMapper.countByExample(example);
}
public int countByOrderIdWithoutReject(Integer userId, Integer orderId) {
LitemallAftersaleExample example = new LitemallAftersaleExample();
example.or().andUserIdEqualTo(userId).andOrderIdEqualTo(orderId).andStatusNotEqualTo(AftersaleConstant.STATUS_REJECT).andDeletedEqualTo(false);
return (int) aftersaleMapper.countByExample(example);
}
// TODO 这里应该产生一个唯一的编号,但是实际上这里仍然存在两个售后编号相同的可能性
public String generateAftersaleSn(Integer userId) {
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMdd");
String now = df.format(LocalDate.now());
String aftersaleSn = now + getRandomNum(6);
while (countByAftersaleSn(userId, aftersaleSn) != 0) {
aftersaleSn = now + getRandomNum(6);
}
return aftersaleSn;
}
public void add(LitemallAftersale aftersale) {
aftersale.setAddTime(LocalDateTime.now());
aftersale.setUpdateTime(LocalDateTime.now());
aftersaleMapper.insertSelective(aftersale);
}
public void deleteByIds(List<Integer> ids) {
LitemallAftersaleExample example = new LitemallAftersaleExample();
example.or().andIdIn(ids).andDeletedEqualTo(false);
LitemallAftersale aftersale = new LitemallAftersale();
aftersale.setUpdateTime(LocalDateTime.now());
aftersale.setDeleted(true);
aftersaleMapper.updateByExampleSelective(aftersale, example);
}
public void deleteById(Integer id) {
aftersaleMapper.logicalDeleteByPrimaryKey(id);
}
}
package org.linlinjava.litemall.db.util;
public class AftersaleConstant {
public static final Short STATUS_REQUEST = 0;
public static final Short STATUS_HANDLE = 1;
public static final Short STATUS_FINISH = 2;
public static final Short STATUS_REJECT = 3;
}
......@@ -8,6 +8,7 @@ public class OrderHandleOption {
private boolean confirm = false; // 确认收货操作
private boolean refund = false; // 取消订单并退款操作
private boolean rebuy = false; // 再次购买
private boolean aftersale = false; // 售后操作
public boolean isCancel() {
return cancel;
......@@ -65,4 +66,11 @@ public class OrderHandleOption {
this.rebuy = rebuy;
}
public boolean isAftersale() {
return aftersale;
}
public void setAftersale(boolean aftersale) {
this.aftersale = aftersale;
}
}
......@@ -31,9 +31,6 @@ public class OrderUtil {
public static final Short STATUS_REFUND = 202;
public static final Short STATUS_REFUND_CONFIRM = 203;
public static final Short STATUS_AUTO_CONFIRM = 402;
public static final Short STATUS_PAY_GROUPON = 200;
public static final Short STATUS_TIMEOUT_GROUPON = 204;
public static String orderStatusText(LitemallOrder order) {
int status = order.getOrderStatus().intValue();
......@@ -50,10 +47,6 @@ public class OrderUtil {
return "已取消(系统)";
}
if (status == 200) {
return "已付款团购";
}
if (status == 201) {
return "已付款";
}
......@@ -97,7 +90,7 @@ public class OrderUtil {
} else if (status == 102 || status == 103) {
// 如果订单已经取消或是已完成,则可删除
handleOption.setDelete(true);
} else if (status == 200 || status == 201) {
} else if (status == 201) {
// 如果订单已付款,没有发货,则可退款
handleOption.setRefund(true);
} else if (status == 202 || status == 204) {
......@@ -110,10 +103,11 @@ public class OrderUtil {
// 此时不能取消订单
handleOption.setConfirm(true);
} else if (status == 401 || status == 402) {
// 如果订单已经支付,且已经收货,则可删除、去评论和再次购买
// 如果订单已经支付,且已经收货,则可删除、去评论、申请售后和再次购买
handleOption.setDelete(true);
handleOption.setComment(true);
handleOption.setRebuy(true);
handleOption.setAftersale(true);
} else {
throw new IllegalStateException("status不支持");
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment