调整客户预付费
parent
ff4ae6fbf3
commit
c19dd234fc
|
|
@ -67,7 +67,7 @@ public abstract class BasePrepayCustomer<M extends BasePrepayCustomer<M>> extend
|
|||
/**
|
||||
* name: supermarket_id
|
||||
* type: INT(10)
|
||||
* isNullable: NO
|
||||
* isNullable: YES
|
||||
* isPrimaryKey: NO
|
||||
* defaultValue:
|
||||
* @param supermarketId 超市id
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ public abstract class BasePrepayDetail<M extends BasePrepayDetail<M>> extends Ba
|
|||
/**
|
||||
* name: supermarket_id
|
||||
* type: INT(10)
|
||||
* isNullable: NO
|
||||
* isNullable: YES
|
||||
* isPrimaryKey: NO
|
||||
* defaultValue:
|
||||
* @param supermarketId 超市id
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ public abstract class BaseRefundDetail<M extends BaseRefundDetail<M>> extends Ba
|
|||
/**
|
||||
* name: supermarket_id
|
||||
* type: INT(10)
|
||||
* isNullable: NO
|
||||
* isNullable: YES
|
||||
* isPrimaryKey: NO
|
||||
* defaultValue:
|
||||
* @param supermarketId 超市id
|
||||
|
|
|
|||
|
|
@ -22,8 +22,11 @@ public class CustomerService extends BaseService {
|
|||
public static final CustomerService me = new CustomerService();
|
||||
|
||||
public Page<Record> find(PageParam pp, String name, Integer del, Integer type) {
|
||||
String selectsql = "select t.*, a.name receiver_name, a.phone receiver_phone, a.address receiver_address ";
|
||||
String fromsql = "from customer t\n" +
|
||||
String selectsql = " select \n" +
|
||||
" t.*\n" +
|
||||
" , a.name receiver_name, a.phone receiver_phone, a.address receiver_address \n" +
|
||||
" , b.surplus, b.recharge_time, b.spend_time, b.first_recharge_time, b.threshold \n";
|
||||
String fromsql = "from customer t\n" +
|
||||
" left join (\n" +
|
||||
" select t.* from customer_receiver t\n" +
|
||||
" left join (\n" +
|
||||
|
|
@ -31,23 +34,33 @@ public class CustomerService extends BaseService {
|
|||
" group by t.customer_id\n" +
|
||||
" ) a on a.customer_receiver_id = t.id and t.customer_id = a.customer_id\n" +
|
||||
" where a.customer_receiver_id is not null\n" +
|
||||
" ) a on a.customer_id = t.id \n" +
|
||||
" where 1=1 \n";
|
||||
List<Object> paraList = new ArrayList<>();
|
||||
" ) a on a.customer_id = t.id\n" +
|
||||
" \n" +
|
||||
" left join (\n" +
|
||||
" select t.* from prepay_customer t\n" +
|
||||
" left join (\n" +
|
||||
" select max(t.id) prepay_customer_id, t.customer_id from prepay_customer t\n" +
|
||||
" group by t.customer_id\n" +
|
||||
" ) a on t.customer_id = a.customer_id\n" +
|
||||
" where a.prepay_customer_id is not null\n" +
|
||||
" ) b on b.customer_id = t.id \n" +
|
||||
" \n" +
|
||||
" where 1=1 \n";
|
||||
List<Object> paraList = new ArrayList<>();
|
||||
|
||||
if(del == null){
|
||||
if (del == null) {
|
||||
fromsql += " and t.del = 0 \n";
|
||||
}else if (del == Const.LOGIC_DEL_VALID || del == Const.LOGIC_DEL_INVALID) {
|
||||
} else if (del == Const.LOGIC_DEL_VALID || del == Const.LOGIC_DEL_INVALID) {
|
||||
fromsql += " and t.del = ? \n";
|
||||
paraList.add(del);
|
||||
}
|
||||
|
||||
if(StrKit.notBlank(name)){
|
||||
if (StrKit.notBlank(name)) {
|
||||
fromsql += " and t.name like ? \n";
|
||||
paraList.add("%" + name + "%");
|
||||
}
|
||||
|
||||
if(type != null){
|
||||
if (type != null) {
|
||||
fromsql += " and t.type = ? \n";
|
||||
paraList.add(type);
|
||||
}
|
||||
|
|
@ -66,38 +79,38 @@ public class CustomerService extends BaseService {
|
|||
}
|
||||
}
|
||||
|
||||
Page<Record> page = Db.paginateByFullSql(pp.getPage(), pp.getSize(), totalRowSql, findSql, paraList.toArray());
|
||||
List<Record> list = page.getList();
|
||||
// Page<Record> page = Db.paginateByFullSql(pp.getPage(), pp.getSize(), totalRowSql, findSql, paraList.toArray());
|
||||
// List<Record> list = page.getList();
|
||||
//
|
||||
// if (!list.isEmpty()) {
|
||||
// List<String> ids = new ArrayList<>();
|
||||
//
|
||||
// for (Record record : list) {
|
||||
// ids.add(record.getStr("id"));
|
||||
// }
|
||||
//
|
||||
// List<Record> prepaycustomers = Db.find(" select t.*, s.name supermarket_name from prepay_customer t \n" +
|
||||
// " left join supermarket s on s.id = t.supermarket_id \n" +
|
||||
// " where t.customer_id in(" + StrKit.join(ids, ",") + ")");
|
||||
//
|
||||
// for (Record record : list) {
|
||||
// int id = record.getInt("id");
|
||||
//
|
||||
// if (record.get("prepay_customer") == null) {
|
||||
// record.set("prepay_customer", new ArrayList<>());
|
||||
// }
|
||||
//
|
||||
// for (Record p : prepaycustomers) {
|
||||
// int customer_id = p.getInt("customer_id");
|
||||
//
|
||||
// if (id == customer_id) {
|
||||
// ((ArrayList) record.get("prepay_customer")).add(p);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
if(!list.isEmpty()) {
|
||||
List<String> ids = new ArrayList<>();
|
||||
|
||||
for (Record record : list) {
|
||||
ids.add(record.getStr("id"));
|
||||
}
|
||||
|
||||
List<Record> prepaycustomers = Db.find(" select t.*, s.name supermarket_name from prepay_customer t \n" +
|
||||
" left join supermarket s on s.id = t.supermarket_id \n" +
|
||||
" where t.customer_id in(" + StrKit.join(ids, ",") + ")");
|
||||
|
||||
for (Record record : list) {
|
||||
int id = record.getInt("id");
|
||||
|
||||
if (record.get("prepay_customer") == null) {
|
||||
record.set("prepay_customer", new ArrayList<>());
|
||||
}
|
||||
|
||||
for (Record p : prepaycustomers) {
|
||||
int customer_id = p.getInt("customer_id");
|
||||
|
||||
if (id == customer_id) {
|
||||
((ArrayList) record.get("prepay_customer")).add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return page;
|
||||
return Db.paginateByFullSql(pp.getPage(), pp.getSize(), totalRowSql, findSql, paraList.toArray());
|
||||
}
|
||||
|
||||
public List<Customer> list() {
|
||||
|
|
|
|||
|
|
@ -8,4 +8,8 @@ public class PrepayCustomerService {
|
|||
public PrepayCustomer getPrepayCustomer(int customer_id, int supermarket_id){
|
||||
return PrepayCustomer.dao.findFirst("select * from prepay_customer where customer_id = ? and supermarket_id = ? ", customer_id, supermarket_id);
|
||||
}
|
||||
|
||||
public PrepayCustomer getPrepayCustomer(int customer_id){
|
||||
return PrepayCustomer.dao.findFirst("select * from prepay_customer where customer_id = ? limit 1", customer_id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ public class PrepayDetailValidator extends CrudParamValidator {
|
|||
}
|
||||
|
||||
validateInteger("customer_id", 1, 2147483647, "customer_id", "customer_id 范围 1~2147483647");
|
||||
validateInteger("supermarket_id", 1, 2147483647, "supermarket_id", "supermarket_id 范围 1~2147483647");
|
||||
// validateInteger("supermarket_id", 1, 2147483647, "supermarket_id", "supermarket_id 范围 1~2147483647");
|
||||
validateBigDecimal("amount", new java.math.BigDecimal(0), new java.math.BigDecimal(9.9999999999E10), "amount", "amount 范围 0~9.9999999999E10");
|
||||
validateString("contact_name", 1, 100, "contact_name", "contact_name 长度 1~100");
|
||||
validateRegex("contact_phone", StrUtil.regphone, "contact_phone", "contact_phone 必须为手机号格式");
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ public class RefundDetailValidator extends CrudParamValidator {
|
|||
}
|
||||
|
||||
validateInteger("customer_id", 1, 2147483647, "customer_id", "customer_id 范围 1~2147483647");
|
||||
validateInteger("supermarket_id", 1, 2147483647, "supermarket_id", "supermarket_id 范围 1~2147483647");
|
||||
// validateInteger("supermarket_id", 1, 2147483647, "supermarket_id", "supermarket_id 范围 1~2147483647");
|
||||
validateBigDecimal("amount", new java.math.BigDecimal(0), new java.math.BigDecimal(9.9999999999E10), "amount", "amount 范围 -9.9999999999E10~9.9999999999E10");
|
||||
validateString("contact_name", 1, 100, "contact_name", "contact_name 长度 1~100");
|
||||
validateRegex("contact_phone", StrUtil.regphone, "contact_phone", "contact_phone 必须为手机号格式");
|
||||
|
|
|
|||
|
|
@ -28,12 +28,6 @@ public class PrepayDetailSyncService extends BaseSyncService {
|
|||
return Result.failed("按客户 id 未找到对应客户信息");
|
||||
}
|
||||
|
||||
Supermarket supermarket = Supermarket.dao.findById(model.getSupermarketId());
|
||||
|
||||
if (supermarket == null) {
|
||||
return Result.failed("按超市 id 未找到对应超市信息");
|
||||
}
|
||||
|
||||
model.setId(StrKit.getRandomUUID());
|
||||
model.setState(1);
|
||||
model.setType(1);
|
||||
|
|
@ -66,7 +60,7 @@ public class PrepayDetailSyncService extends BaseSyncService {
|
|||
synctask.addSaveData(model);
|
||||
synctask.addSaveData(his);
|
||||
|
||||
return SyncTaskService.me.save(synctask, model.getSupermarketId())
|
||||
return SyncTaskService.me.save(synctask)
|
||||
&& ModifyLogService.me.save(model, null, Enums.DataOpType.SAVE.getId(), user);
|
||||
}
|
||||
});
|
||||
|
|
@ -112,12 +106,6 @@ public class PrepayDetailSyncService extends BaseSyncService {
|
|||
return Result.failed("未找到有效的客户信息");
|
||||
}
|
||||
|
||||
Supermarket supermarket = Supermarket.dao.findById(model.getSupermarketId());
|
||||
|
||||
if (supermarket == null) {
|
||||
return Result.failed("按超市 id 未找到对应超市信息");
|
||||
}
|
||||
|
||||
try {
|
||||
PrepayDetail oldmodel = model.clone();
|
||||
boolean ret = Db.tx(new IAtom() {
|
||||
|
|
@ -142,11 +130,10 @@ public class PrepayDetailSyncService extends BaseSyncService {
|
|||
if (state == 2) {
|
||||
customer.setType(1); // 标记为预付费用户
|
||||
|
||||
PrepayCustomer prepayCustomer = PrepayCustomerService.me.getPrepayCustomer(customer.getId(), supermarket.getId());
|
||||
PrepayCustomer prepayCustomer = PrepayCustomerService.me.getPrepayCustomer(customer.getId());
|
||||
if (prepayCustomer == null) {
|
||||
prepayCustomer = new PrepayCustomer();
|
||||
prepayCustomer.setCustomerId(customer.getId());
|
||||
prepayCustomer.setSupermarketId(supermarket.getId());
|
||||
prepayCustomer.setSurplus(model.getAmount()); // 更新余额
|
||||
prepayCustomer.setRechargeTime(now); // 更新最后一次充值时间
|
||||
prepayCustomer.setFirstRechargeTime(now);
|
||||
|
|
@ -161,7 +148,6 @@ public class PrepayDetailSyncService extends BaseSyncService {
|
|||
ret = prepayCustomer.update();
|
||||
|
||||
synctask.addUpdateData(prepayCustomer);
|
||||
|
||||
}
|
||||
|
||||
if (!ret) {
|
||||
|
|
|
|||
|
|
@ -30,13 +30,7 @@ public class RefundDetailSyncService extends BaseSyncService {
|
|||
return Result.failed("按客户 id 未找到对应客户信息");
|
||||
}
|
||||
|
||||
Supermarket supermarket = Supermarket.dao.findById(model.getSupermarketId());
|
||||
|
||||
if (supermarket == null) {
|
||||
return Result.failed("按超市 id 未找到对应超市信息");
|
||||
}
|
||||
|
||||
PrepayCustomer prepayCustomer = PrepayCustomerService.me.getPrepayCustomer(customer.getId(), supermarket.getId());
|
||||
PrepayCustomer prepayCustomer = PrepayCustomerService.me.getPrepayCustomer(customer.getId());
|
||||
|
||||
if (prepayCustomer == null) {
|
||||
return Result.failed("未找到客户预付费信息");
|
||||
|
|
@ -86,7 +80,7 @@ public class RefundDetailSyncService extends BaseSyncService {
|
|||
synctask.addSaveData(model);
|
||||
synctask.addSaveData(his);
|
||||
|
||||
return SyncTaskService.me.save(synctask, model.getSupermarketId())
|
||||
return SyncTaskService.me.save(synctask)
|
||||
&& ModifyLogService.me.save(model, null, Enums.DataOpType.SAVE.getId(), user);
|
||||
}
|
||||
});
|
||||
|
|
@ -133,13 +127,7 @@ public class RefundDetailSyncService extends BaseSyncService {
|
|||
return Result.failed("未找到有效的客户信息");
|
||||
}
|
||||
|
||||
Supermarket supermarket = Supermarket.dao.findById(model.getSupermarketId());
|
||||
|
||||
if (supermarket == null) {
|
||||
return Result.failed("按超市 id 未找到对应超市信息");
|
||||
}
|
||||
|
||||
PrepayCustomer prepayCustomer = PrepayCustomerService.me.getPrepayCustomer(customer.getId(), supermarket.getId());
|
||||
PrepayCustomer prepayCustomer = PrepayCustomerService.me.getPrepayCustomer(customer.getId());
|
||||
|
||||
if (prepayCustomer == null) {
|
||||
return Result.failed("未找到客户预付费信息");
|
||||
|
|
@ -228,13 +216,7 @@ public class RefundDetailSyncService extends BaseSyncService {
|
|||
return Result.failed("未找到有效的客户信息");
|
||||
}
|
||||
|
||||
Supermarket supermarket = Supermarket.dao.findById(model.getSupermarketId());
|
||||
|
||||
if (supermarket == null) {
|
||||
return Result.failed("按超市 id 未找到对应超市信息");
|
||||
}
|
||||
|
||||
PrepayCustomer prepayCustomer = PrepayCustomerService.me.getPrepayCustomer(customer.getId(), supermarket.getId());
|
||||
PrepayCustomer prepayCustomer = PrepayCustomerService.me.getPrepayCustomer(customer.getId());
|
||||
|
||||
if (prepayCustomer == null) {
|
||||
return Result.failed("未找到客户预付费信息");
|
||||
|
|
|
|||
Loading…
Reference in New Issue