Commit 8452a6b9 by DuJunLi
parents 35c2a785 941f334a
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="物品场景case"> <!-- 起一个好听且唯一的名字-->
<test name="物品设置模块测试" preserve-order="true" verbose="3"> <!-- 再起一个听且唯一的名字 -->
<packages>
<package name="com.xiaomai.cases.polar.goods.*"></package> <!-- 添加自己想要集成测试的case 范围自己定 -->
</packages>
</test>
<listeners>
<listener class-name="com.xiaomai.client.RetryListener" />
<listener class-name="com.xiaomai.client.TestListener" />
<listener class-name="com.xiaomai.client.ExtentTestNGIReporterListener"/>
</listeners>
</suite>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
......@@ -4,7 +4,7 @@
<test name="通用设置模块测试" preserve-order="true" verbose="3"> <!-- 再起一个听且唯一的名字 -->
<packages>
<package name="com.xiaomai.cases.polar.setting.*"></package> <!-- 添加自己想要集成测试的case 范围自己定 -->
<package name="com.xiaomai.cases.polar.setting.*"></package> <!-- 添加自己想要集成测试的范围自己定 -->
</packages>
</test>
<listeners>
......
package com.xiaomai.cases.lunar.goods;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xiaomai.client.DataUserInfo;
import com.xiaomai.enums.ApiModule;
import com.xiaomai.enums.RequestType;
import com.xiaomai.enums.Terminal;
import com.xiaomai.utils.RandomStringUtil;
import com.xiaomai.utils.XMBaseTest;
import java.math.BigDecimal;
public class GoodCTools extends XMBaseTest {
/**
* @param
* @description:C端获取物品列表
* @author: yff
**/
public JSONObject pageXcxHomeGoodsC(DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Lunar_Goods)
.setApiName("API_pageXcxHomeGoodsC")
.setTerminal(Terminal.minApp);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("current", 0);
jsonObject.put("size",20);
jsonObject.put("studioId",dataApi.getLoginInfo().getStudioId());
JSONArray ids=new JSONArray();
jsonObject.put("ids",ids);
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:获取C端的物品详情
* @param id:物品ID
* @author: yff
**/
public JSONObject getDetail_goods_C(String id, DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Lunar_Goods)
.setApiName("API_getDetail_goods_C")
.setTerminal(Terminal.minApp);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("id",id);
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:拉取C端小程序物品组列表
* @author: yff
**/
public JSONObject listXcxGoodsGroup(DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Lunar_Goods)
.setApiName("API_listXcxGoodsGroup")
.setTerminal(Terminal.minApp);
super.beforeDataRequest(userInfos);
JSONObject listXcxGoodsGroup=new JSONObject();
listXcxGoodsGroup.put("studioId",dataApi.getLoginInfo().getStudioId());
JSONArray ids=new JSONArray();
listXcxGoodsGroup.put("ids",ids);
dataApi.doRequest(RequestType.JSON,dataparams,listXcxGoodsGroup.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:C端购买物品前校验是否通过
* @author: yff
**/
public JSONObject checkAllowPurchase(String goodsSpecId, String memberId, BigDecimal price,int quantity, DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Lunar_Goods)
.setApiName("API_checkAllowPurchase")
.setTerminal(Terminal.minApp);
super.beforeDataRequest(userInfos);
JSONObject checkAllowPurchase=new JSONObject();
checkAllowPurchase.put("goodsSpecId",goodsSpecId);
checkAllowPurchase.put("memberId",memberId);
checkAllowPurchase.put("price",price);
checkAllowPurchase.put("quantity",quantity);
checkAllowPurchase.put("studioId",dataApi.getLoginInfo().getStudioId());
dataApi.doRequest(RequestType.JSON,dataparams,checkAllowPurchase.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:C端购买物品
* @author: yff
**/
public JSONObject purchaseGoods(String depositAmount, String depositCardId, String memberId,String memo, String receivableAmount,String id, BigDecimal price, int quantity, DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Lunar_Goods)
.setApiName("API_purchaseGoods")
.setTerminal(Terminal.minApp);
super.beforeDataRequest(userInfos);
JSONObject purchaseGoods=new JSONObject();
purchaseGoods.put("depositAmount",depositAmount);
purchaseGoods.put("depositCardId",depositCardId);
purchaseGoods.put("memberId",memberId);
purchaseGoods.put("memo",memo);
purchaseGoods.put("objectId", RandomStringUtil.randomString(16));
purchaseGoods.put("receivableAmount",receivableAmount);
purchaseGoods.put("goodsSpecId",id);
purchaseGoods.put("price",price);
purchaseGoods.put("quantity",quantity);
purchaseGoods.put("studioId",dataApi.getLoginInfo().getStudioId());
dataApi.doRequest(RequestType.JSON,dataparams,purchaseGoods.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
}
package com.xiaomai.cases.lunar.goods;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xiaomai.basetest.BaseTestImpl;
import com.xiaomai.cases.polar.goods.Tools.GoodTools;
import com.xiaomai.client.DataUserInfo;
import com.xiaomai.enums.ApiModule;
import com.xiaomai.enums.LoginAccount;
import com.xiaomai.enums.Terminal;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class TestListXcxGoodsGroup extends BaseTestImpl {
GoodCTools goodCTools=new GoodCTools();
GoodTools goodTools=new GoodTools();
String createGoodsId;
DataUserInfo info = new DataUserInfo();
@BeforeMethod
@Override
public void beforeTest(){
setTestInfo(ApiModule.Lunar_Goods,"API_listXcxGoodsGroup", LoginAccount.GYM_MINIAPPC, Terminal.minApp,"yff");
super.beforeTest();
}
@Test(description = "拉取C端小程序物品组列表")
public void testListXcxGoodsGroup() {
//切换端位
info.setTerminal(Terminal.B);
info.setLoginUser(LoginAccount.GYM_PROD);
//存量分组:"id": "1873903771989471234","name": "自动化分组勿动勿用"
String id="1873903771989471234";
//case1:获取小程序物品分组列表:没有这个分组数据,因为没任何物品
JSONObject listXcxGoodsGroup=goodCTools.listXcxGoodsGroup();
JSONArray result=listXcxGoodsGroup.getJSONArray("result");
boolean success=false;
for(int i=0;i<result.size();i++){
if( ! result.getJSONObject(1).getString("id").equals(id)){
success=true;
break;
}
}
Assert.assertEquals(success,true,"分组里没有一个物品,这个分组不应该在小程序物品组列表展示");
//case2:获取小程序物品分组列表:有这个分组数据,因为创建了一个单规格&启用&开启小程序售卖的物品
//新建物品
//创建了一个单规格&启用&开启小程序售卖
JSONObject createGoods=goodTools.createGoods_single("YES","0.01",10,info);
createGoodsId=createGoods.getString("result");
//移动至这个分组
JSONObject batchModifyGoodsBelongGroup=goodTools.batchModifyGoodsBelongGroup("1873903771989471234",createGoodsId,info);
String batchModifyGoodsBelongGroupSuccess=batchModifyGoodsBelongGroup.getJSONObject("result").getString("success");
Assert.assertEquals(batchModifyGoodsBelongGroupSuccess,"1","移动一个物品至该分组失败");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//获取小程序物品分组列表:有该分组
JSONObject listXcxGoodsGroup1=goodCTools.listXcxGoodsGroup();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
JSONArray result1=listXcxGoodsGroup1.getJSONArray("result");
JSONObject result0= result1.getJSONObject(0);
System.out.println("result1"+result1);
System.out.println("result11"+result0);
boolean success1=false;
for(int i=0;i < result1.size();i++){
if(result1.getJSONObject(i).getString("id").equals(id)){
success1=true;
break;
}
}
Assert.assertEquals(success1,true,"分组的物品是启用且开启小程序售卖的,这个分组应该在小程序物品组列表展示");
//case3:获取小程序物品分组列表:没有这个分组数据,因为分组内的物品为启用&关闭小程序售卖
//修改上个物品为启用&关闭小程序售卖
JSONObject modifyGoodsXcxSaleState=goodTools.modifyGoodsXcxSaleState(createGoodsId,"NO",info);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//修改校验1:获取B端物品详情
JSONObject getDetail=goodTools.getDetail_goods(createGoodsId,info);
String xcxSaleState=getDetail.getJSONObject("result").getString("xcxSaleState");
Assert.assertEquals(xcxSaleState,"NO","修改物品的小程序售卖为关闭失败");
//获取小程序物品分组列表:没有该分组
JSONObject listXcxGoodsGroup2=goodCTools.listXcxGoodsGroup();
JSONArray result2=listXcxGoodsGroup2.getJSONArray("result");
boolean success2=false;
for(int i=0;i<result2.size();i++){
if( ! result2.getJSONObject(1).getString("id").equals(id)){
success2=true;
break;
}
}
Assert.assertEquals(success2,true,"分组的物品是启用且关闭小程序售卖的,这个分组应该不在小程序物品组列表展示");
//case4:获取小程序物品分组列表:没有这个分组数据,因为分组内的物品为停用&关闭小程序售卖
//修改上个物品为停用&关闭小程序售卖
JSONObject modifyGoodsState=goodTools.modifyGoodsState(createGoodsId,"NO",info);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//修改校验1:获取B端物品详情
JSONObject getDetail1=goodTools.getDetail_goods(createGoodsId,info);
String state=getDetail1.getJSONObject("result").getString("state");
Assert.assertEquals(state,"NO","修改物品的状态为停用失败");
//获取小程序物品分组列表:没有该分组
JSONObject listXcxGoodsGroup3=goodCTools.listXcxGoodsGroup();
JSONArray result3=listXcxGoodsGroup3.getJSONArray("result");
boolean success3=false;
for(int i=0;i<result3.size();i++){
if( ! result3.getJSONObject(1).getString("id").equals(id)){
success3=true;
break;
}
}
Assert.assertEquals(success3,true,"分组的物品是停用且关闭小程序售卖的,这个分组应该不在小程序物品组列表展示");
}
@Test(description = "清理物品数据",priority = 1)
public void delete() {
goodTools.deleteGoods(createGoodsId,info);
}
}
package com.xiaomai.cases.lunar.goods;
import com.alibaba.fastjson.JSONObject;
import com.xiaomai.basetest.BaseTestImpl;
import com.xiaomai.cases.lunar.order.OrderCTools;
import com.xiaomai.cases.lunar.user.UserTools;
import com.xiaomai.cases.polar.data.financeData.FinanceDataTools;
import com.xiaomai.cases.polar.finance.order.OrderTools;
import com.xiaomai.cases.polar.goods.Tools.GoodTools;
import com.xiaomai.client.DataUserInfo;
import com.xiaomai.enums.ApiModule;
import com.xiaomai.enums.LoginAccount;
import com.xiaomai.enums.RequestType;
import com.xiaomai.enums.Terminal;
import com.xiaomai.utils.RandomStringUtil;
import com.xiaomai.utils.TimeUtils;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.math.BigDecimal;
import java.math.RoundingMode;
public class TestPurchaseGoods extends BaseTestImpl {
GoodCTools goodCTools=new GoodCTools();
GoodTools goodTools=new GoodTools();
String memberId;
UserTools userTools=new UserTools();
DataUserInfo info = new DataUserInfo();
OrderCTools orderCTools=new OrderCTools();
OrderTools orderTools=new OrderTools();
FinanceDataTools financeDataTools=new FinanceDataTools();
String orderId1;
String orderId2;
String orderId3;
@BeforeMethod
@Override
public void beforeTest(){
setTestInfo(ApiModule.Lunar_Goods,"API_purchaseGoods", LoginAccount.GYM_MINIAPPC, Terminal.minApp,"yff");
super.beforeTest();
}
@Test(description = "购买非0元多规格物品")
public void testPurchaseGoods_WAITING() {
//涉及到订单的都使用存量物品数据,因为购买过物品就不能被删除了,所以不会买一次新建一个
// "id": "1874413681302990849",
// "name": "自动化禁用-购买订单单规格1元",
// "id": "1874413587237335042",
// "name": "自动化禁用-购买订单多规格1元",
// "id": "1874413193018896386",
// "name": "自动化禁用-购买订单多规格0元",
// "id": "1874411064376061954",
// "name": "自动化禁用-购买订单单规格0元",
//case1:购买多规格非0元物品生成待支付订单
//获取会员信息
memberId = userTools.getMemberInfo().getString("memberId");
//切换端位
info.setTerminal(Terminal.B);
info.setLoginUser(LoginAccount.GYM_PROD);
String goodsId1="1874413587237335042";
//获取C端商品详情
JSONObject getDetail_goods_C=goodCTools.getDetail_goods_C(goodsId1);
String id=getDetail_goods_C.getJSONObject("result").getJSONObject("multiSpecInfo").getJSONArray("specCombinationList").getJSONObject(0).getString("id");
BigDecimal price=new BigDecimal(getDetail_goods_C.getJSONObject("result").getJSONObject("multiSpecInfo").getJSONArray("specCombinationList").getJSONObject(0).getString("price"));
int beforeInventory=Integer.parseInt(getDetail_goods_C.getJSONObject("result").getJSONObject("multiSpecInfo").getJSONArray("specCombinationList").getJSONObject(0).getString("inventory"));
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//获取数据中心-财务中心-营收明细-物品的确认收入
JSONObject beforeGetCostData_type=financeDataTools.getCostData_type("DAY","GOODS", TimeUtils.getTodayTime(),TimeUtils.getTodayEndTime(),info);
BigDecimal beforeConfirmedAmount=new BigDecimal(beforeGetCostData_type.getJSONObject("result").getString("confirmedAmount"));//确认收入
boolean checkAllowPurchase=Boolean.parseBoolean(goodCTools.checkAllowPurchase(id,memberId,price,beforeInventory).getJSONObject("result").getString("success"));
//校验一下物品购买是否可以通过,为true才可以
if(checkAllowPurchase==true){
//购买非0元多规格物品
JSONObject purchaseGoods=new JSONObject();
purchaseGoods.put("depositAmount","0.00");
purchaseGoods.put("depositCardId",null);
purchaseGoods.put("memberId",memberId);
purchaseGoods.put("memo","");
purchaseGoods.put("objectId", RandomStringUtil.randomString(16));
purchaseGoods.put("receivableAmount",price);
purchaseGoods.put("goodsSpecId",id);
purchaseGoods.put("price",price);
purchaseGoods.put("quantity",1);
purchaseGoods.put("studioId",dataApi.getLoginInfo().getStudioId());
xmAppApi.doRequest(RequestType.JSON, params, purchaseGoods.toString(), headers).assetsSuccess(true);
JSONObject purchaseGoodsResponse = xmAppApi.getBodyInJSON();
orderId1=purchaseGoodsResponse.getJSONObject("result").getString("id");
//校验1:获取B端订单详情:待支付状态
JSONObject getDetailResult = orderTools.getDetail(orderId1,info);
String businessNo= getDetailResult.getJSONObject("result").getString("businessNo");//订单号
String state=getDetailResult.getJSONObject("result").getString("state");
Assert.assertEquals(state,"WAITING","未生成待支付物品订单");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验2:C端商品详情库存数-1
JSONObject afterGetDetail_goods_C=goodCTools.getDetail_goods_C(goodsId1);
int afterInventory=Integer.parseInt(afterGetDetail_goods_C.getJSONObject("result").getJSONObject("multiSpecInfo").getJSONArray("specCombinationList").getJSONObject(0).getString("inventory"));
Assert.assertEquals(afterInventory,beforeInventory-1,"购买1个物品生成待支付订单后,应扣除1个库存数");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验3:权益未到,数据中心的确认收入没有增加
//获取数据中心-财务中心-营收明细-物品的确认收入
JSONObject afterGetCostData_type=financeDataTools.getCostData_type("DAY","GOODS", TimeUtils.getTodayTime(),TimeUtils.getTodayEndTime(),info);
BigDecimal afterConfirmedAmount=new BigDecimal(afterGetCostData_type.getJSONObject("result").getString("confirmedAmount"));//确认收入
Assert.assertEquals(afterConfirmedAmount,beforeConfirmedAmount,"购买1个物品生成待支付订单后,财务中心-营收明细-物品的确认收入应无变化");
//case2:C端取消订单
JSONObject cancel=orderCTools.cancel(orderId1);
//校验1:获取B端订单详情:已取消状态
JSONObject getDetailResult_cancel = orderTools.getDetail(orderId1,info);
String businessNo_cancel= getDetailResult_cancel.getJSONObject("result").getString("businessNo");//订单号
String state_cancel=getDetailResult_cancel.getJSONObject("result").getString("state");
Assert.assertEquals(state_cancel,"CANCEL","C端取消物品订单后,订单状态未从待支付变更为已取消");
//校验2:C端商品详情库存数+1
JSONObject lastGetDetail_goods_C=goodCTools.getDetail_goods_C(goodsId1);
int lastInventory=Integer.parseInt(lastGetDetail_goods_C.getJSONObject("result").getJSONObject("multiSpecInfo").getJSONArray("specCombinationList").getJSONObject(0).getString("inventory"));
Assert.assertEquals(lastInventory,afterInventory+1,"取消购买1个物品的待支付订单后,应返回1个库存数");
//校验3:权益未涉及,数据中心的确认收入没有变化
//获取数据中心-财务中心-营收明细-物品的确认收入
JSONObject lastGetCostData_type=financeDataTools.getCostData_type("DAY","GOODS", TimeUtils.getTodayTime(),TimeUtils.getTodayEndTime(),info);
BigDecimal lastConfirmedAmount=new BigDecimal(lastGetCostData_type.getJSONObject("result").getString("confirmedAmount"));//确认收入
Assert.assertEquals(lastConfirmedAmount,afterConfirmedAmount,"取消购买1个物品的待支付订单后,财务中心-营收明细-物品的确认收入应无变化");
}
else {
System.out.println("物品购买校验未通过,不能下单");
}
}
@Test(description = "购买0元多规格物品")
public void testPurchaseGoods_PAID() {
//获取会员信息
memberId = userTools.getMemberInfo().getString("memberId");
//切换端位
info.setTerminal(Terminal.B);
info.setLoginUser(LoginAccount.GYM_PROD);
String goodsId2="1874413193018896386";
//获取C端商品详情
JSONObject getDetail_goods_C=goodCTools.getDetail_goods_C(goodsId2);
String id=getDetail_goods_C.getJSONObject("result").getJSONObject("multiSpecInfo").getJSONArray("specCombinationList").getJSONObject(0).getString("id");
BigDecimal price=new BigDecimal(getDetail_goods_C.getJSONObject("result").getJSONObject("multiSpecInfo").getJSONArray("specCombinationList").getJSONObject(0).getString("price"));
int beforeInventory=Integer.parseInt(getDetail_goods_C.getJSONObject("result").getJSONObject("multiSpecInfo").getJSONArray("specCombinationList").getJSONObject(0).getString("inventory"));
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//获取数据中心-财务中心-营收明细-物品的确认收入
JSONObject beforeGetCostData_type=financeDataTools.getCostData_type("DAY","GOODS", TimeUtils.getTodayTime(),TimeUtils.getTodayEndTime(),info);
BigDecimal beforeConfirmedAmount=new BigDecimal(beforeGetCostData_type.getJSONObject("result").getString("confirmedAmount"));//确认收入
boolean checkAllowPurchase=Boolean.parseBoolean(goodCTools.checkAllowPurchase(id,memberId,price,beforeInventory).getJSONObject("result").getString("success"));
//校验一下物品购买是否可以通过,为true才可以
if(checkAllowPurchase==true){
//购买非0元多规格物品
JSONObject purchaseGoods=new JSONObject();
purchaseGoods.put("depositAmount","0.00");
purchaseGoods.put("depositCardId",null);
purchaseGoods.put("memberId",memberId);
purchaseGoods.put("memo","");
purchaseGoods.put("objectId", RandomStringUtil.randomString(16));
purchaseGoods.put("receivableAmount",price);
purchaseGoods.put("goodsSpecId",id);
purchaseGoods.put("price",price);
purchaseGoods.put("quantity",1);
purchaseGoods.put("studioId",dataApi.getLoginInfo().getStudioId());
xmAppApi.doRequest(RequestType.JSON, params, purchaseGoods.toString(), headers).assetsSuccess(true);
JSONObject purchaseGoodsResponse = xmAppApi.getBodyInJSON();
orderId2=purchaseGoodsResponse.getJSONObject("result").getString("id");
//校验1:获取B端订单详情:待支付状态
JSONObject getDetailResult = orderTools.getDetail(orderId2,info);
String businessNo= getDetailResult.getJSONObject("result").getString("businessNo");//订单号
String state=getDetailResult.getJSONObject("result").getString("state");
Assert.assertEquals(state,"PAID","未生成已完成物品订单");
//校验2:C端商品详情库存数-1
JSONObject afterGetDetail_goods_C=goodCTools.getDetail_goods_C(goodsId2);
int afterInventory=Integer.parseInt(afterGetDetail_goods_C.getJSONObject("result").getJSONObject("multiSpecInfo").getJSONArray("specCombinationList").getJSONObject(0).getString("inventory"));
Assert.assertEquals(afterInventory,beforeInventory-1,"购买1个物品生成已完成订单后,应扣除1个库存数");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验3:权益到,数据中心的确认收入增加
//获取数据中心-财务中心-营收明细-物品的确认收入
JSONObject afterGetCostData_type=financeDataTools.getCostData_type("DAY","GOODS", TimeUtils.getTodayTime(),TimeUtils.getTodayEndTime(),info);
BigDecimal afterConfirmedAmount=new BigDecimal(afterGetCostData_type.getJSONObject("result").getString("confirmedAmount"));//确认收入
Assert.assertEquals(afterConfirmedAmount,beforeConfirmedAmount.add(price.setScale(2, RoundingMode.HALF_UP)),"购买1个物品生成待支付订单后,财务中心-营收明细-物品的确认收入应增加对应物品的价格");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
else {
System.out.println("物品购买校验未通过,不能下单");
}
}
@Test(description = "购买0元单规格物品")
public void testPurchaseGoods_PAID_single() {
//获取会员信息
memberId = userTools.getMemberInfo().getString("memberId");
//切换端位
info.setTerminal(Terminal.B);
info.setLoginUser(LoginAccount.GYM_PROD);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
String goodsId3="1874411064376061954";
//获取C端商品详情
JSONObject getDetail_goods_C=goodCTools.getDetail_goods_C(goodsId3);
String id=getDetail_goods_C.getJSONObject("result").getString("id");
BigDecimal price=new BigDecimal(getDetail_goods_C.getJSONObject("result").getJSONObject("singleSpecInfo").getString("price"));
int beforeInventory=Integer.parseInt(getDetail_goods_C.getJSONObject("result").getJSONObject("singleSpecInfo").getString("inventory"));
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//获取数据中心-财务中心-营收明细-物品的确认收入
JSONObject beforeGetCostData_type=financeDataTools.getCostData_type("DAY","GOODS", TimeUtils.getTodayTime(),TimeUtils.getTodayEndTime(),info);
BigDecimal beforeConfirmedAmount=new BigDecimal(beforeGetCostData_type.getJSONObject("result").getString("confirmedAmount"));//确认收入
//购买0元单规格物品
JSONObject purchaseGoods=new JSONObject();
purchaseGoods.put("depositAmount","0.00");
purchaseGoods.put("depositCardId",null);
purchaseGoods.put("memberId",memberId);
purchaseGoods.put("memo","");
purchaseGoods.put("objectId", RandomStringUtil.randomString(16));
purchaseGoods.put("receivableAmount",price);
purchaseGoods.put("goodsSpecId",goodsId3);
purchaseGoods.put("price",price);
purchaseGoods.put("quantity",1);
purchaseGoods.put("studioId",dataApi.getLoginInfo().getStudioId());
xmAppApi.doRequest(RequestType.JSON, params, purchaseGoods.toString(), headers).assetsSuccess(true);
JSONObject purchaseGoodsResponse = xmAppApi.getBodyInJSON();
orderId3=purchaseGoodsResponse.getJSONObject("result").getString("id");
//校验1:获取B端订单详情:已完成状态
JSONObject getDetailResult = orderTools.getDetail(orderId3,info);
String businessNo= getDetailResult.getJSONObject("result").getString("businessNo");//订单号
String state=getDetailResult.getJSONObject("result").getString("state");
Assert.assertEquals(state,"PAID","未生成已完成物品订单");
//校验2:C端商品详情库存数-1
JSONObject afterGetDetail_goods_C=goodCTools.getDetail_goods_C(goodsId3,info);
int afterInventory=Integer.parseInt(afterGetDetail_goods_C.getJSONObject("result").getJSONObject("singleSpecInfo").getString("inventory"));
Assert.assertEquals(afterInventory,beforeInventory-1,"购买1个物品生成已完成订单后,应扣除1个库存数");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验3:权益到,数据中心的确认收入增加
//获取数据中心-财务中心-营收明细-物品的确认收入
JSONObject afterGetCostData_type=financeDataTools.getCostData_type("DAY","GOODS", TimeUtils.getTodayTime(),TimeUtils.getTodayEndTime(),info);
BigDecimal afterConfirmedAmount=new BigDecimal(afterGetCostData_type.getJSONObject("result").getString("confirmedAmount"));//确认收入
Assert.assertEquals(afterConfirmedAmount,beforeConfirmedAmount.add(price.setScale(2, RoundingMode.HALF_UP)),"购买1个物品生成待支付订单后,财务中心-营收明细-物品的确认收入应增加对应物品的价格");
}
@Test(description ="作废签单订单",priority = 1)
public void discard(){
//作废签单订单
orderTools.discard(orderId2, "重复录入", "已作废签单订单" + RandomStringUtil.randomString(10),info);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
orderTools.discard(orderId3, "重复录入", "已作废签单订单" + RandomStringUtil.randomString(10),info);
}
}
......@@ -9,7 +9,6 @@ import com.xiaomai.enums.LoginAccount;
import com.xiaomai.enums.RequestType;
import com.xiaomai.enums.Terminal;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
......@@ -57,7 +56,7 @@ public class TestStudioRoleCreate extends BaseTestImpl {
xmAppApi.doRequest(RequestType.JSON,params,body,headers).assetsSuccess(true);
try {
Thread.sleep(3000);
Thread.sleep(6000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
......@@ -84,7 +83,7 @@ public class TestStudioRoleCreate extends BaseTestImpl {
Assert.assertEquals(flag,true,"创建角色失败");
try {
Thread.sleep(3000);
Thread.sleep(10000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
......
package com.xiaomai.cases.polar.finance.cashier;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xiaomai.cases.polar.finance.order.OrderTools;
import com.xiaomai.cases.polar.member.Tools;
import com.xiaomai.cases.polar.memberCard.CardTools;
import com.xiaomai.enums.ApiModule;
import com.xiaomai.enums.LoginAccount;
import com.xiaomai.enums.RequestType;
import com.xiaomai.enums.Terminal;
import com.xiaomai.utils.RandomStringUtil;
import com.xiaomai.utils.TimeUtils;
import com.xiaomai.utils.XMBaseTest;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.math.BigDecimal;
public class TestOfflinePay extends XMBaseTest {
String memberId;
String cardId;
String getDetailId;
Tools tools=new Tools();
OrderTools orderTools=new OrderTools();
CardTools cardTools=new CardTools();
@BeforeMethod
public void beforeTest(){
xmAppApi.setApiModule(ApiModule.Polar_Finance)
.setApiName("API_offlinePay")
.setLoginUser(LoginAccount.YFF_PROD)
.setTerminal(Terminal.B);
dal.setCase_owner("yff")
.setCase_name(Thread.currentThread().getStackTrace()[1].getFileName().split("\\.")[0]);
super.beforeTest();
}
@Test(description = "线下支付订单(实际是操作关联流水调用)")
public void testOfflinePay(){
//10020060066--固定流水,换场馆需要按照这个手机支付0.01元 "flowIds": ["1808757176611880962"]
//
// String name = "创建订单潜在会员"+ RandomStringUtil.randomString(3);
// String phone = RandomStringUtil.randomMobile("666");
//
// //获取会员ID,没有则新建一个
// int memberTotal = Integer.parseInt(tools.search("NORMAL","NORMAL").getJSONObject("result").getString("total"));
// if (memberTotal == 0) {
// memberId = tools.create(name,phone).getString("result");
// }
// memberId=tools.search("NORMAL","NORMAL").getJSONObject("result").getJSONArray("records").getJSONObject(0).getString("id");
//
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// throw new RuntimeException(e);
// }
//
// //获取会员卡信息
// //获取会员卡列表,没有则新建一个
// int cardTotal = Integer.parseInt(orderTools.fetchPageOfMemberCard("次卡","MEMBER_CARD").getJSONObject("result").getString("total"));
// if (cardTotal == 0) {
// cardId = cardTools.memberCardCreate("次卡-创建订单会员卡"+ TimeUtils.getCurrentTime()).getString("result");
// }
// JSONObject memberCard=orderTools.fetchPageOfMemberCard("次卡","MEMBER_CARD");
// cardId=memberCard.getJSONObject("result").getJSONArray("records").getJSONObject(0).getString("id");
// BigDecimal quantity= new BigDecimal(memberCard.getJSONObject("result").getJSONArray("records").getJSONObject(0).getString("balance"));
// float price= Float.parseFloat(memberCard.getJSONObject("result").getJSONArray("records").getJSONObject(0).getString("price"));
// int validPeriod= Integer.parseInt(memberCard.getJSONObject("result").getJSONArray("records").getJSONObject(0).getString("validPeriod"));
//
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// throw new RuntimeException(e);
// }
//
// //获取签单要用的卡快照id
// String latestSnapshotId=orderTools.fetchDetailById(cardId,xmAppApi.getLoginInfo().getBrandId(),xmAppApi.getLoginInfo().getStudioId(),xmAppApi.getLoginInfo().getAdminId()).getJSONObject("result").getString("latestSnapshotId");
//
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// throw new RuntimeException(e);
// }
//
// //检查会员对该卡是否超出购买上限
// boolean limitResult=orderTools.checkAllowPurchase("MEMBER_CARD",cardId,memberId,"1",xmAppApi.getLoginInfo().getBrandId(),xmAppApi.getLoginInfo().getStudioId(),xmAppApi.getLoginInfo().getAdminId()).getBoolean("success");
//
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// throw new RuntimeException(e);
// }
//
//
// if(limitResult == true) {
//
// //创建待支付订单
//
// //创建待支付订单
// JSONObject orderResult=orderTools.signOrder(cardId,latestSnapshotId,quantity,price,validPeriod,latestSnapshotId, price/2,"PURCHASE",
// "MEMBER_CARD",memberId,price-price/2,0,"1",false);
// String getDetailId=orderResult.getString("result");//订单ID
//
//// JSONObject orderResult = orderTools.signOrder(cardId, latestSnapshotId, quantity, price, validPeriod, latestSnapshotId, price / 2, "PURCHASE",
//// "MEMBER_CARD", memberId, price - price / 2, 0, "6");
//// getDetailId = orderResult.getString("result");//订单ID
//
//
// try {
// Thread.sleep(3000);
// } catch (InterruptedException e) {
// throw new RuntimeException(e);
// }
//
//
//
// //关联流水
// JSONObject jsonObject=new JSONObject();
//
// JSONArray flowIds=new JSONArray();
// flowIds.add("1808757176611880962");
// jsonObject.put("flowIds",flowIds);
// jsonObject.put("voucherId",getDetailId);
// jsonObject.put("brandId",xmAppApi.getLoginInfo().getBrandId());
// jsonObject.put("studioId",xmAppApi.getLoginInfo().getStudioId());
// jsonObject.put("operatorId",xmAppApi.getLoginInfo().getAdminId());
//
// xmAppApi.doRequest(RequestType.JSON,params,jsonObject.toJSONString(),headers).assetsSuccess(true);
// String result=xmAppApi.getBodyInJSON().getString("result");
// Assert.assertEquals(result,"true","关联流水失败");
//
// try {
// Thread.sleep(3000);
// } catch (InterruptedException e) {
// throw new RuntimeException(e);
// }
//
// //校验关联流水之后,订单状态变成已完成
// //获取订单详情
//
// //校验获取订单详情
// JSONObject getDetailResult=orderTools.getDetail(getDetailId);
// String state=getDetailResult.getJSONObject("result").getString("state");
// Assert.assertEquals(state,"PAID","关联流水成功,但订单状态未是已完成");
//
//
//
// //关联之后一定要把签单订单作废!!否则下次流水就不能关联了
// //校验是否可以作废签单订单
// boolean checkDiscardSignVoucherResult = orderTools.checkDiscardVoucher(getDetailId).getBoolean("success");
//
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// throw new RuntimeException(e);
// }
//
// if (checkDiscardSignVoucherResult == true) {
// JSONObject discardResult = orderTools.discard(getDetailId, "重复录入", "已作废签单订单" + RandomStringUtil.randomString(10));
// Assert.assertEquals(discardResult.getString("success"), "true", "签单订单作废失败");
// }
//
// }
}
}
......@@ -926,6 +926,48 @@ public class OrderTools extends XMBaseTest {
return response;
}
/**
* @param
* @description:继续收款
* @param unpaidAmount:欠费金额
* @param getDetailId:订单ID
* @param paymentWay:支付方式 1-线下微信 2 3
* @param directReceive:true待补交 false待支付
* @author: yangfangfang
**/
public JSONObject pay_unpaid(BigDecimal unpaidAmount,String paymentWay,String getDetailId,boolean directReceive, DataUserInfo...dataUserInfos){
dataApi.setApiModule(ApiModule.Polar_Finance)
.setApiName("API_pay")
.setTerminal(Terminal.B);
super.beforeDataRequest(dataUserInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("operationTime", TimeUtils.getCurrentTime());
jsonObject.put("operatorId", dataApi.getLoginInfo().getAdminId());
JSONArray paymentWays = new JSONArray();
JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("amount", unpaidAmount);
jsonObject1.put("paymentWay",paymentWay);
JSONArray voucherResourceIds = new JSONArray();
voucherResourceIds.add("");
jsonObject1.put("voucherResourceIds", voucherResourceIds);
paymentWays.add(jsonObject1);
jsonObject.put("paymentWays", paymentWays);
jsonObject.put("voucherId", getDetailId);
jsonObject.put("directReceive",directReceive);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
dataApi.doRequest(RequestType.JSON, dataparams, jsonObject.toJSONString(), dataheadrs).assetsSuccess(true);
JSONObject response=dataApi.getBodyInJSON();
return response;
}
/**
......
package com.xiaomai.cases.polar.goods;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xiaomai.cases.lunar.goods.GoodCTools;
import com.xiaomai.cases.polar.goods.Tools.GoodTools;
import com.xiaomai.client.DataUserInfo;
import com.xiaomai.enums.ApiModule;
import com.xiaomai.enums.LoginAccount;
import com.xiaomai.enums.RequestType;
import com.xiaomai.enums.Terminal;
import com.xiaomai.utils.RandomStringUtil;
import com.xiaomai.utils.XMBaseTest;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class TestCreateGoods extends XMBaseTest {
GoodTools goodTools=new GoodTools();
GoodCTools goodCTools=new GoodCTools();
String studioResult1;
String studioResult2;
DataUserInfo info = new DataUserInfo();
@BeforeMethod
public void beforeTest() {
xmAppApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_createGoods")
.setLoginUser(LoginAccount.GYM_PROD)
.setTerminal(Terminal.B);
dal.setCase_owner("yff")
.setCase_name(Thread.currentThread().getStackTrace()[1].getFileName().split("\\.")[0]);
super.beforeTest();
}
@Test(description = "创建物品-多规格")
public void testCreateGoods_multiple() {
//分组是存量的: "id": "1873912725360504834","name": "自动化分组多规格",因为只能创建10个,超了的话影响后续流程还所以还是用存量的
//获取B端物品列表
JSONObject beforeTotalStudioGoods= goodTools.studioGoods("");
int beforeTotal=Integer.parseInt(beforeTotalStudioGoods.getJSONObject("result").getString("total"));
//切换端位
//切换端位
info.setTerminal(Terminal.minApp);
info.setLoginUser(LoginAccount.GYM_MINIAPPC);
try {
Thread.sleep(6000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
JSONObject beforePageXcxHomeGoods_C = goodCTools.pageXcxHomeGoodsC(info);
int beforeTotal_C = Integer.parseInt(beforePageXcxHomeGoods_C.getJSONObject("result").getString("total"));
String name="自动化创建三个规格" + RandomStringUtil.randomString(2);
//物品名称重名校验:为false才是不重名
boolean checkRepeatNameForStudio=Boolean.parseBoolean(goodTools.checkRepeatNameForStudio(name).getString("result"));
if(checkRepeatNameForStudio==false) {
String color1 = "黑色";
String color2 = "白色";
String size1 = "大的";
String size2 = "小的";
String skin1 = "貂蝉";
String skin2 = "王昭君";
JSONObject jsonObject = new JSONObject();
//商品介绍为空
// JSONObject description=new JSONObject();
// jsonObject.put("description",description.toString());
//商品介绍不为空,纯文本
JSONObject description = new JSONObject();
JSONArray items = new JSONArray();
JSONObject item1 = new JSONObject();
item1.put("type", "TEXT");
item1.put("content", "自动化创建的多规格三个规格,每个规格都有两个规格值");
item1.put("aspect", "");
items.add(item1);
description.put("items", items);
jsonObject.put("description", description.toString());
jsonObject.put("groupId", "1873912725360504834");
jsonObject.put("multiSpec", true);
jsonObject.put("name", name);
jsonObject.put("xcxSaleState", "YES");
JSONObject multiSpecInfo = new JSONObject();
//设置三个规格和每个都有两个规格值
JSONArray specList = new JSONArray();
JSONObject specList1 = new JSONObject();
specList1.put("name", "颜色");
JSONArray specList1SpecValues = new JSONArray();
JSONObject specList1SpecValues1 = new JSONObject();
specList1SpecValues1.put("name", color1);
JSONObject specList1SpecValues2 = new JSONObject();
specList1SpecValues2.put("name", color2);
specList1SpecValues.add(specList1SpecValues1);
specList1SpecValues.add(specList1SpecValues2);
specList1.put("specValues", specList1SpecValues);
JSONObject specList2 = new JSONObject();
specList2.put("name", "尺码");
JSONArray specList2SpecValues = new JSONArray();
JSONObject specList2SpecValues1 = new JSONObject();
specList2SpecValues1.put("name", size1);
JSONObject specList2SpecValues2 = new JSONObject();
specList2SpecValues2.put("name", size2);
specList2SpecValues.add(specList2SpecValues1);
specList2SpecValues.add(specList2SpecValues2);
specList2.put("specValues", specList2SpecValues);
JSONObject specList3 = new JSONObject();
specList3.put("name", "限定皮肤");
JSONArray specList3SpecValues = new JSONArray();
JSONObject specList3SpecValues1 = new JSONObject();
specList3SpecValues1.put("name", skin1);
JSONObject specList3SpecValues2 = new JSONObject();
specList3SpecValues2.put("name", skin2);
specList3SpecValues.add(specList3SpecValues1);
specList3SpecValues.add(specList3SpecValues2);
specList3.put("specValues", specList3SpecValues);
specList.add(specList1);
specList.add(specList2);
specList.add(specList3);
multiSpecInfo.put("specList", specList);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//排列出来的组合2*2*2
JSONArray specCombinationList = new JSONArray();
JSONObject specCombinationList1 = new JSONObject();
JSONArray specCombinationList1Specs = new JSONArray();
specCombinationList1Specs.add(color1);
specCombinationList1Specs.add(size1);
specCombinationList1Specs.add(skin1);
specCombinationList1.put("specs", specCombinationList1Specs);
specCombinationList1.put("price", "0.01");
specCombinationList1.put("inventory", 10);
specCombinationList.add(specCombinationList1);
JSONObject specCombinationList2 = new JSONObject();
JSONArray specCombinationList2Specs = new JSONArray();
specCombinationList2Specs.add(color1);
specCombinationList2Specs.add(size1);
specCombinationList2Specs.add(skin2);
specCombinationList2.put("specs", specCombinationList2Specs);
specCombinationList2.put("price", "0.01");
specCombinationList2.put("inventory", 10);
specCombinationList.add(specCombinationList2);
JSONObject specCombinationList3 = new JSONObject();
JSONArray specCombinationList3Specs = new JSONArray();
specCombinationList3Specs.add(color1);
specCombinationList3Specs.add(size2);
specCombinationList3Specs.add(skin1);
specCombinationList3.put("specs", specCombinationList3Specs);
specCombinationList3.put("price", "0.01");
specCombinationList3.put("inventory", 10);
specCombinationList.add(specCombinationList3);
JSONObject specCombinationList4 = new JSONObject();
JSONArray specCombinationList4Specs = new JSONArray();
specCombinationList4Specs.add(color1);
specCombinationList4Specs.add(size2);
specCombinationList4Specs.add(skin2);
specCombinationList4.put("specs", specCombinationList4Specs);
specCombinationList4.put("price", "0.01");
specCombinationList4.put("inventory", 10);
specCombinationList.add(specCombinationList4);
JSONObject specCombinationList5 = new JSONObject();
JSONArray specCombinationList5Specs = new JSONArray();
specCombinationList5Specs.add(color2);
specCombinationList5Specs.add(size1);
specCombinationList5Specs.add(skin1);
specCombinationList5.put("specs", specCombinationList5Specs);
specCombinationList5.put("price", "0.01");
specCombinationList5.put("inventory", 10);
specCombinationList.add(specCombinationList5);
JSONObject specCombinationList6 = new JSONObject();
JSONArray specCombinationList6Specs = new JSONArray();
specCombinationList6Specs.add(color2);
specCombinationList6Specs.add(size1);
specCombinationList6Specs.add(skin2);
specCombinationList6.put("specs", specCombinationList6Specs);
specCombinationList6.put("price", "0.01");
specCombinationList6.put("inventory", 10);
specCombinationList.add(specCombinationList6);
JSONObject specCombinationList7 = new JSONObject();
JSONArray specCombinationList7Specs = new JSONArray();
specCombinationList7Specs.add(color2);
specCombinationList7Specs.add(size2);
specCombinationList7Specs.add(skin1);
specCombinationList7.put("specs", specCombinationList7Specs);
specCombinationList7.put("price", "0.01");
specCombinationList7.put("inventory", 10);
specCombinationList.add(specCombinationList7);
JSONObject specCombinationList8 = new JSONObject();
JSONArray specCombinationList8Specs = new JSONArray();
specCombinationList8Specs.add(color2);
specCombinationList8Specs.add(size2);
specCombinationList8Specs.add(skin2);
specCombinationList8.put("specs", specCombinationList8Specs);
specCombinationList8.put("price", "0.01");
specCombinationList8.put("inventory", 10);
specCombinationList.add(specCombinationList8);
multiSpecInfo.put("specCombinationList", specCombinationList);
jsonObject.put("multiSpecInfo", multiSpecInfo);
jsonObject.put("brandId", xmAppApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", xmAppApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId", xmAppApi.getLoginInfo().getAdminId());
xmAppApi.doRequest(RequestType.JSON, params, jsonObject.toJSONString(), headers).assetsSuccess(true);
JSONObject response = xmAppApi.getBodyInJSON();
studioResult1 = response.getString("result");
//校验:
//校验1:获取B端物品列表
//①统计值增加1
//②有对应的商品id
JSONObject afterStudioGoods = goodTools.studioGoods("");
int afterTotal = Integer.parseInt(afterStudioGoods.getJSONObject("result").getString("total"));
JSONArray records = afterStudioGoods.getJSONObject("result").getJSONArray("records");
boolean success=false;
for (int i = 0; i < records.size(); i++) {
if (records.getJSONObject(i).getString("id").equals(studioResult1)) {
success=true;
break;
}
}
Assert.assertEquals(success, true, "新建三个规格的物品成功,但物品列表未找到对应增加的物品ID");
Assert.assertEquals(afterTotal, beforeTotal + 1, "新建三个规格的物品成功,但物品列表的统计值未增加");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验:
//校验2:获取C端物品列表
//①统计值增加1
//②有对应的商品id
JSONObject afterPageXcxHomeGoods_C = goodCTools.pageXcxHomeGoodsC(info);
int afterTotal_C = Integer.parseInt(afterPageXcxHomeGoods_C.getJSONObject("result").getString("total"));
JSONArray records_C = afterPageXcxHomeGoods_C.getJSONObject("result").getJSONArray("records");
boolean success_C=false;
for (int i = 0; i < records_C.size(); i++) {
if (records_C.getJSONObject(i).getString("id").equals(studioResult1)) {
success_C=true;
break;
}
}
Assert.assertEquals(success_C, true, "新建三个规格的物品成功,但C端的物品列表未找到对应增加的物品ID");
Assert.assertEquals(afterTotal_C, beforeTotal_C + 1, "新建三个规格的物品成功,但C端物品列表的统计值未增加");
//校验3:获取B端物品详情,状态是开启,小程序售卖也是开启
JSONObject getDetail_goods=goodTools.getDetail_goods(studioResult1);
String state=getDetail_goods.getJSONObject("result").getString("state");
String xcxSaleState=getDetail_goods.getJSONObject("result").getString("xcxSaleState");
//规格1ID
String getDetailSpecListId1=getDetail_goods.getJSONObject("result").getJSONObject("multiSpecInfo").getJSONArray("specList").getJSONObject(0).getString("id");
//规格2ID
String getDetailSpecListId2=getDetail_goods.getJSONObject("result").getJSONObject("multiSpecInfo").getJSONArray("specList").getJSONObject(1).getString("id");
//规格3ID
String getDetailSpecListId3=getDetail_goods.getJSONObject("result").getJSONObject("multiSpecInfo").getJSONArray("specList").getJSONObject(2).getString("id");
Assert.assertEquals(state,"YES","新建物品是启用,但物品详情展示非启用");
Assert.assertEquals(xcxSaleState,"YES","新建物品是开启小程序售卖,但物品详情展示非开启小程序售卖");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验4:获取C端物品详情,状态是开启,小程序售卖也是开启
JSONObject getDetail_goods_C=goodCTools.getDetail_goods_C(studioResult1,info);
String state_C=getDetail_goods_C.getJSONObject("result").getString("state");
String xcxSaleState_C=getDetail_goods_C.getJSONObject("result").getString("xcxSaleState");
Assert.assertEquals(state_C,"YES","新建物品是启用,但C端物品详情展示非启用");
Assert.assertEquals(xcxSaleState_C,"YES","新建物品是开启小程序售卖,但C端物品详情展示非开启小程序售卖");
//校验5:获取B端查看多规格的库存详情,和物品详情的规格id都一致
JSONObject listMultiSpecInventorRecords=goodTools.listMultiSpecInventorRecords(studioResult1);
//规格1ID
String listMultiSpecInventorRecordsSpecListId1=listMultiSpecInventorRecords.getJSONObject("result").getJSONArray("specList").getJSONObject(0).getString("id");
//规格2ID
String listMultiSpecInventorRecordsSpecListId2=listMultiSpecInventorRecords.getJSONObject("result").getJSONArray("specList").getJSONObject(1).getString("id");
//规格3ID
String listMultiSpecInventorRecordsSpecListId3=listMultiSpecInventorRecords.getJSONObject("result").getJSONArray("specList").getJSONObject(2).getString("id");
Assert.assertTrue(listMultiSpecInventorRecordsSpecListId1.equals(getDetailSpecListId1),"新建物品的库存详情的规格1的规格ID和物品详情的规格1的规格ID不一致");
Assert.assertTrue(listMultiSpecInventorRecordsSpecListId2.equals(getDetailSpecListId2),"新建物品的库存详情的规格2的规格ID和物品详情的规格2的规格ID不一致");
Assert.assertTrue(listMultiSpecInventorRecordsSpecListId3.equals(getDetailSpecListId3),"新建物品的库存详情的规格3的规格ID和物品详情的规格3的规格ID不一致");
//校验6:生成一条编辑记录,类型为新建物品
JSONObject pageGoodsModifyRecord=goodTools.pageGoodsModifyRecord(studioResult1);
String pageGoodsModifyRecordResult=pageGoodsModifyRecord.getJSONObject("result").getJSONArray("records").getJSONObject(0).getString("type");
Assert.assertEquals(pageGoodsModifyRecordResult,"CREATE","创建多规格物品后,未生成类型为新建的编辑记录");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
@Test(description = "创建物品-单规格")
public void testCreateGoods_single() {
//单规格:"id": "1873903328974499841", "name": "自动化分组单规格",
//获取物品列表
JSONObject beforeTotalStudioGoods= goodTools.studioGoods("");
int beforeTotal=Integer.parseInt(beforeTotalStudioGoods.getJSONObject("result").getString("total"));
//切换端位
info.setTerminal(Terminal.minApp);
info.setLoginUser(LoginAccount.GYM_MINIAPPC);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
JSONObject beforePageXcxHomeGoods_C = goodCTools.pageXcxHomeGoodsC(info);
int beforeTotal_C = Integer.parseInt(beforePageXcxHomeGoods_C.getJSONObject("result").getString("total"));
String name = "自动化创建单规格" + RandomStringUtil.randomString(2);
//物品名称重名校验:为false才是不重名
boolean checkRepeatNameForStudio = Boolean.parseBoolean(goodTools.checkRepeatNameForStudio(name).getString("result"));
if (checkRepeatNameForStudio == false) {
//单规格
JSONObject jsonObject = new JSONObject();
//商品介绍不为空,纯文本
JSONObject description = new JSONObject();
JSONArray items = new JSONArray();
JSONObject item1 = new JSONObject();
item1.put("type", "TEXT");
item1.put("content", "自动化创建的");
item1.put("aspect", "");
items.add(item1);
description.put("items", items);
jsonObject.put("description", description.toString());
jsonObject.put("groupId", "1873903328974499841");
jsonObject.put("multiSpec", false);
jsonObject.put("name", "自动化创建单规格" + RandomStringUtil.randomString(2));
jsonObject.put("xcxSaleState", "YES");
JSONObject jsonObject2 = new JSONObject();
jsonObject2.put("inventory", "10");
jsonObject2.put("price", "0.01");
jsonObject.put("singleSpecInfo", jsonObject2);
jsonObject.put("brandId", xmAppApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", xmAppApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId", xmAppApi.getLoginInfo().getAdminId());
xmAppApi.doRequest(RequestType.JSON, params, jsonObject.toJSONString(), headers).assetsSuccess(true);
JSONObject response = xmAppApi.getBodyInJSON();
studioResult2=response.getString("result");
//校验:
//校验1:获取B端物品列表
//①统计值增加1
//②有对应的商品id
JSONObject afterStudioGoods = goodTools.studioGoods("");
int afterTotal = Integer.parseInt(afterStudioGoods.getJSONObject("result").getString("total"));
JSONArray records = afterStudioGoods.getJSONObject("result").getJSONArray("records");
boolean success=false;
for (int i = 0; i < records.size(); i++) {
if (records.getJSONObject(i).getString("id").equals(studioResult2)) {
success=true;
break;
}
}
Assert.assertEquals(success, true, "新建三个规格的物品成功,但物品列表未找到对应增加的物品ID");
Assert.assertEquals(afterTotal, beforeTotal + 1, "新建三个规格的物品成功,但物品列表的统计值未增加");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验:
//校验2:获取C端物品列表
//①统计值增加1
//②有对应的商品id
JSONObject afterPageXcxHomeGoods_C = goodCTools.pageXcxHomeGoodsC(info);
int afterTotal_C = Integer.parseInt(afterPageXcxHomeGoods_C.getJSONObject("result").getString("total"));
JSONArray records_C = afterPageXcxHomeGoods_C.getJSONObject("result").getJSONArray("records");
boolean success_C=false;
for (int i = 0; i < records_C.size(); i++) {
if (records_C.getJSONObject(i).getString("id").equals(studioResult2)) {
success_C=true;
break;
}
}
Assert.assertEquals(success_C, true, "新建三个规格的物品成功,但C端的物品列表未找到对应增加的物品ID");
Assert.assertEquals(afterTotal_C, beforeTotal_C + 1, "新建三个规格的物品成功,但C端物品列表的统计值未增加");
//校验3:获取B端物品详情,状态是开启,小程序售卖也是开启
JSONObject getDetail_goods=goodTools.getDetail_goods(studioResult2);
String state=getDetail_goods.getJSONObject("result").getString("state");
String xcxSaleState=getDetail_goods.getJSONObject("result").getString("xcxSaleState");
Assert.assertEquals(state,"YES","新建物品是启用,但物品详情展示非启用");
Assert.assertEquals(xcxSaleState,"YES","新建物品是开启小程序售卖,但物品详情展示非开启小程序售卖");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验4:获取C端物品详情,状态是开启,小程序售卖也是开启
JSONObject getDetail_goods_C=goodCTools.getDetail_goods_C(studioResult2,info);
String state_C=getDetail_goods_C.getJSONObject("result").getString("state");
String xcxSaleState_C=getDetail_goods_C.getJSONObject("result").getString("xcxSaleState");
Assert.assertEquals(state_C,"YES","新建物品是启用,但C端物品详情展示非启用");
Assert.assertEquals(xcxSaleState_C,"YES","新建物品是开启小程序售卖,但C端物品详情展示非开启小程序售卖");
//校验5:生成一条编辑记录,类型为新建物品
JSONObject pageGoodsModifyRecord=goodTools.pageGoodsModifyRecord(studioResult2);
String pageGoodsModifyRecordResult=pageGoodsModifyRecord.getJSONObject("result").getJSONArray("records").getJSONObject(0).getString("type");
Assert.assertEquals(pageGoodsModifyRecordResult,"CREATE","创建多规格物品后,未生成类型为新建的编辑记录");
}
}
@Test(description = "数据清理",priority = 1)
public void deleteGood(){
goodTools.deleteGoods(studioResult1);//删除新建的多规格物品
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
goodTools.deleteGoods(studioResult2);//删除新建的单规格物品
}
// @Test(description ="循环")
// public void xun(){
// for (int i = 0; i < 20; i++) {
// testCreateGoods();
// }
// }
}
package com.xiaomai.cases.polar.goods;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xiaomai.cases.polar.goods.Tools.GoodTools;
import com.xiaomai.enums.ApiModule;
import com.xiaomai.enums.LoginAccount;
import com.xiaomai.enums.Terminal;
import com.xiaomai.utils.XMBaseTest;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class TestCreateGoodsGroup extends XMBaseTest {
GoodTools goodTools=new GoodTools();
String name1="自动化创建分组";
String name2="自动化编辑分组";
String createId;
String groupId;
@BeforeMethod
public void beforeTest() {
xmAppApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_createGoodsGroup")
.setLoginUser(LoginAccount.GYM_PROD)
.setTerminal(Terminal.B);
dal.setCase_owner("yff")
.setCase_name(Thread.currentThread().getStackTrace()[1].getFileName().split("\\.")[0]);
super.beforeTest();
}
@Test(description = "创建分组")
public void testCreateGoodsGroup() {
name1="自动化创建分组";
//创建之前先看下列表的分组是不是10个,大于等于10就不走新建分组这个case了
JSONObject listPageGoodsGroup=goodTools.listPageGoodsGroup();
JSONArray listPageGoodsGroup_result=listPageGoodsGroup.getJSONArray("result");
if(listPageGoodsGroup_result.size()<10){
//创建之前先校验重名不重名
Boolean checkNameRepeatGoodsGroup=Boolean.parseBoolean(goodTools.checkNameRepeatGoodsGroup(name1).getString("result"));
if (checkNameRepeatGoodsGroup==false){
//创建分组
JSONObject createGoodsGroup=goodTools.createGoodsGroup(name1);
groupId=createGoodsGroup.getString("result");
//校验分组是否创建成功
//校验1:B端分组列表中是否有这个分组
JSONObject afterListPageGoodsGroup=goodTools.listPageGoodsGroup();
JSONArray afterListPageGoodsGroup_result=afterListPageGoodsGroup.getJSONArray("result");
boolean success=false;
for(int i=0; i < afterListPageGoodsGroup_result.size(); i++){
if(afterListPageGoodsGroup_result.getJSONObject(i).getString("id").equals(groupId)){
success=true;
break;
}
}
Assert.assertEquals(success,true,"新建分组成功,但是分组中未找到对应的分组ID");
//校验2:新建物品拉取分组名称的时候也有此条数据
JSONObject listGoodsGroup=goodTools.listGoodsGroup();
JSONArray listGoodsGroupResult=listGoodsGroup.getJSONArray("result");
boolean success_listGoodsGroup=false;
for(int i=0;i < listGoodsGroupResult.size();i++){
if(listGoodsGroupResult.getJSONObject(i).getString("id").equals(groupId)){
success_listGoodsGroup=true;
break;
}
}
Assert.assertEquals(success_listGoodsGroup,true,"新建分组成功,但分组中未找到对应的分组ID");
//新建一个物品
JSONObject create=goodTools.createGoods_multiple("YES","0.01",10);
createId=create.getString("result");
//新建分组成功后,批量移动物品至其分组
JSONObject jsonObject=goodTools.batchModifyGoodsBelongGroup(groupId,createId);
//移动至其分组校验
//校验1:该分组物品数量为1
JSONObject afterListPageGoodsGroup_count=goodTools.listPageGoodsGroup();
JSONArray afterListPageGoodsGroup_result_count=afterListPageGoodsGroup_count.getJSONArray("result");
for(int i=0; i < afterListPageGoodsGroup_result_count.size(); i++){
if(afterListPageGoodsGroup_result_count.getJSONObject(i).getString("id").equals(groupId)){
String goodsCount=afterListPageGoodsGroup_result_count.getJSONObject(0).getString("goodsCount");
Assert.assertEquals(goodsCount,"1","批量移动1个数据至该分组之后,该分组下物品数不为1");
}
}
Boolean checkNameRepeatGoodsGroup_modify=Boolean.parseBoolean(goodTools.checkNameRepeatGoodsGroup(name2).getString("result"));
if (checkNameRepeatGoodsGroup_modify==false) {
//编辑分组
JSONObject modifyGoodsGroup=goodTools.modifyGoodsGroup(groupId,name2);
//编辑之后校验编辑是否成功
//校验1:分组列表中有这个修改后的分组名称
JSONObject afterListPageGoodsGroup_modify=goodTools.listPageGoodsGroup();
JSONArray afterListPageGoodsGroup_result_modify=afterListPageGoodsGroup_modify.getJSONArray("result");
boolean success_modify=false;
for(int i=0; i < afterListPageGoodsGroup_result_modify.size(); i++){
if(afterListPageGoodsGroup_result_modify.getJSONObject(i).getString("name").equals(name2)){
success_modify=true;
break;
}
}
Assert.assertEquals(success_modify,true,"编辑分组成功,但列表中没有编辑成功后的分组");
//校验2:新建物品拉取分组名称的时候也有此条编辑后的数据
JSONObject listGoodsGroup_modify=goodTools.listGoodsGroup();
JSONArray listGoodsGroupResult_modify=listGoodsGroup_modify.getJSONArray("result");
boolean success_listGoodsGroup_modify=false;
for(int i=0;i < listGoodsGroupResult_modify.size();i++){
if(listGoodsGroupResult_modify.getJSONObject(i).getString("id").equals(groupId)){
success_listGoodsGroup_modify=true;
break;
}
}
Assert.assertEquals(success_listGoodsGroup_modify,true,"编辑分组成功,但在新建物品时拉取分组未找到对应的分组ID");
}
else {
System.out.println("场馆已存在相同名称分组");
}
}
else {
System.out.println("场馆已存在相同名称分组");
}
}
else{
System.out.println("分组列表已经超过10个");
}
}
@Test(description = "删除数据:物品和分组",priority = 1)
public void testDeleteGoodsGroup() {
//先删除物品
JSONObject deleteGoods=goodTools.deleteGoods(createId);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//再删除分组
//先校验分组下有没有物品,没有物品才可以删除
Boolean checkAllowDeleteSuccess=Boolean.parseBoolean(goodTools.checkAllowDelete(groupId).getJSONObject("result").getString("success"));
if(checkAllowDeleteSuccess==true) {
JSONObject deleteGoodsGroup = goodTools.deleteGoodsGroup(groupId);
//删除分组校验
//校验1:分组列表中没有这个物品
JSONObject afterListPageGoodsGroup=goodTools.listPageGoodsGroup();
JSONArray afterListPageGoodsGroup_result=afterListPageGoodsGroup.getJSONArray("result");
boolean success=false;
for(int i=0; i < afterListPageGoodsGroup_result.size(); i++){
if( ! afterListPageGoodsGroup_result.getJSONObject(i).getString("id").equals(groupId)){
success=true;
break;
}
}
Assert.assertEquals(success,true,"删除分组成功,但列表中还有此条数据");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验2:新建物品拉取分组名称的时候没有此条编辑后的数据
JSONObject listGoodsGroup=goodTools.listGoodsGroup();
JSONArray listGoodsGroupResult=listGoodsGroup.getJSONArray("result");
boolean success_listGoodsGroup=false;
for(int i=0;i < listGoodsGroupResult.size();i++){
if( ! listGoodsGroupResult.getJSONObject(i).getString("id").equals(groupId)){
success_listGoodsGroup=true;
break;
}
}
Assert.assertEquals(success_listGoodsGroup,true,"删除分组成功,但在新建物品时拉取分组还有此条数据");
}
else {
System.out.println("该分组下有物品,不可删除");
}
}
}
package com.xiaomai.cases.polar.goods;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xiaomai.cases.polar.goods.Tools.GoodTools;
import com.xiaomai.enums.ApiModule;
import com.xiaomai.enums.LoginAccount;
import com.xiaomai.enums.RequestType;
import com.xiaomai.enums.Terminal;
import com.xiaomai.utils.XMBaseTest;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class TestDeleteGood extends XMBaseTest {
GoodTools goodTools=new GoodTools();
@BeforeMethod
public void beforeTest() {
xmAppApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_delete")
.setLoginUser(LoginAccount.GYM_PROD)
.setTerminal(Terminal.B);
dal.setCase_owner("yff")
.setCase_name(Thread.currentThread().getStackTrace()[1].getFileName().split("\\.")[0]);
super.beforeTest();
}
@Test(description = "删除物品")
public void testCreateGoods() {
//新建物品
JSONObject createGoods=goodTools.createGoods_multiple("YES","0.01",10);
String id=createGoods.getString("result");
//获取物品列表
JSONObject studioGoods= goodTools.studioGoods("");
JSONArray records=studioGoods.getJSONObject("result").getJSONArray("records");
boolean success=false;
for (int i=0;i<records.size();i++){
if(records.getJSONObject(i).getString("id").equals(id)){
success=true;
break;
}
}
Assert.assertEquals(success,true,"新建物品成功,但物品列表没有新增此条数据");
//删除物品
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", id);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId", dataApi.getLoginInfo().getAdminId());
xmAppApi.doRequest(RequestType.JSON, params, jsonObject.toJSONString(), headers).assetsSuccess(true);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验1:物品列表中没有此数据
JSONObject afterStudioGoods= goodTools.studioGoods("");
JSONArray afterRecords=afterStudioGoods.getJSONObject("result").getJSONArray("records");
boolean afterSuccess=false;
for (int i=0;i<afterRecords.size();i++){
if( ! afterRecords.getJSONObject(i).getString("id").equals(id)){
afterSuccess=true;
break;
}
}
Assert.assertEquals(afterSuccess,true,"删除物品成功,但物品列表还有此条数据");
}
// @Test
// public void xun(){
// for(int i=0;i<20;i++){
// testCreateGoods();
// }
// }
}
\ No newline at end of file
package com.xiaomai.cases.polar.goods;
import com.alibaba.fastjson.JSONObject;
import com.xiaomai.cases.lunar.goods.GoodCTools;
import com.xiaomai.cases.lunar.user.UserTools;
import com.xiaomai.cases.polar.data.financeData.FinanceDataTools;
import com.xiaomai.cases.polar.finance.order.OrderTools;
import com.xiaomai.cases.polar.goods.Tools.GoodTools;
import com.xiaomai.client.DataUserInfo;
import com.xiaomai.enums.ApiModule;
import com.xiaomai.enums.LoginAccount;
import com.xiaomai.enums.Terminal;
import com.xiaomai.utils.RandomStringUtil;
import com.xiaomai.utils.TimeUtils;
import com.xiaomai.utils.XMBaseTest;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.math.BigDecimal;
import java.math.RoundingMode;
public class TestGoodsOrder extends XMBaseTest {
GoodTools goodTools=new GoodTools();
GoodCTools goodCTools=new GoodCTools();
DataUserInfo info =new DataUserInfo();
UserTools userTools=new UserTools();
OrderTools orderTools=new OrderTools();
FinanceDataTools financeDataTools=new FinanceDataTools();
String memberId;
@BeforeMethod
public void beforeTest() {
xmAppApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_refundGoods")
.setLoginUser(LoginAccount.GYM_PROD)
.setTerminal(Terminal.B);
dal.setCase_owner("yff")
.setCase_name(Thread.currentThread().getStackTrace()[1].getFileName().split("\\.")[0]);
super.beforeTest();
}
@Test(description = "签单单规格:待支付->取消订单")
public void testSignGoods_single() {
//涉及到订单的都使用存量物品数据,因为购买过物品就不能被删除了,所以不会买一次新建一个
// "id": "1874413681302990849",
// "name": "自动化禁用-购买订单单规格1元",
// "id": "1874413587237335042",
// "name": "自动化禁用-购买订单多规格1元",
//case1:购买非0订单->待支付->取消订单
//切换端位
info.setTerminal(Terminal.minApp);
info.setLoginUser(LoginAccount.GYM_MINIAPPC);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//获取会员信息
//获取用户
memberId = userTools.getMemberInfo(info).getString("memberId");
String goodsId1="1874413681302990849";
//获取B端商品详情
JSONObject getDetail_goods=goodTools.getDetail_goods(goodsId1);
String id=getDetail_goods.getJSONObject("result").getString("id");
BigDecimal price=new BigDecimal(getDetail_goods.getJSONObject("result").getJSONObject("singleSpecInfo").getString("price"));
int beforeInventory=Integer.parseInt(getDetail_goods.getJSONObject("result").getJSONObject("singleSpecInfo").getString("inventory"));
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//获取数据中心-财务中心-营收明细-物品的确认收入
JSONObject beforeGetCostData_type=financeDataTools.getCostData_type("DAY","GOODS", TimeUtils.getTodayTime(),TimeUtils.getTodayEndTime());
BigDecimal beforeConfirmedAmount=new BigDecimal(beforeGetCostData_type.getJSONObject("result").getString("confirmedAmount"));//确认收入
JSONObject purchaseGoods = goodCTools.purchaseGoods("0.00", null,memberId,"",price.toString(),id,price,1,info);
String orderId1=purchaseGoods.getJSONObject("result").getString("id");
//生成待支付订单后,去B端继续收款
//获取B端订单详情:待支付状态
JSONObject getDetailResult = orderTools.getDetail(orderId1,info);
String state=getDetailResult.getJSONObject("result").getString("state");
Assert.assertEquals(state,"WAITING","未生成待支付物品订单");
//校验1:B端商品详情库存数-1
JSONObject afterGetDetail_goods=goodTools.getDetail_goods(goodsId1);
int afterInventory=Integer.parseInt(afterGetDetail_goods.getJSONObject("result").getJSONObject("singleSpecInfo").getString("inventory"));
Assert.assertEquals(afterInventory,beforeInventory-1,"购买1个物品生成待支付订单后,应扣除1个库存数");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验2:权益未到,数据中心的确认收入没有增加
//获取数据中心-财务中心-营收明细-物品的确认收入
JSONObject afterGetCostData_type=financeDataTools.getCostData_type("DAY","GOODS", TimeUtils.getTodayTime(),TimeUtils.getTodayEndTime());
BigDecimal afterConfirmedAmount=new BigDecimal(afterGetCostData_type.getJSONObject("result").getString("confirmedAmount"));//确认收入
Assert.assertEquals(afterConfirmedAmount,beforeConfirmedAmount,"购买1个物品生成待支付订单后,财务中心-营收明细-物品的确认收入应无变化");
//B端取消物品订单
JSONObject cancel=orderTools.cancel(orderId1);
//校验1:获取B端订单详情:已取消状态
JSONObject getDetailResult_cancel = orderTools.getDetail(orderId1);
String state_cancel=getDetailResult_cancel.getJSONObject("result").getString("state");
Assert.assertEquals(state_cancel,"CANCEL","B端取消物品订单后,订单状态未从待支付变更为已取消");
//校验2:B端商品详情库存数+1
JSONObject lastGetDetail_goods=goodTools.getDetail_goods(goodsId1);
int lastInventory=Integer.parseInt(lastGetDetail_goods.getJSONObject("result").getJSONObject("singleSpecInfo").getString("inventory"));
Assert.assertEquals(lastInventory,afterInventory+1,"取消购买1个物品的待支付订单后,应返回1个库存数");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验3:权益未涉及,数据中心的确认收入没有变化
//获取数据中心-财务中心-营收明细-物品的确认收入
JSONObject lastGetCostData_type=financeDataTools.getCostData_type("DAY","GOODS", TimeUtils.getTodayTime(),TimeUtils.getTodayEndTime());
BigDecimal lastConfirmedAmount=new BigDecimal(lastGetCostData_type.getJSONObject("result").getString("confirmedAmount"));//确认收入
Assert.assertEquals(lastConfirmedAmount,afterConfirmedAmount,"取消购买1个物品的待支付订单后,财务中心-营收明细-物品的确认收入应无变化");
}
@Test(description = "签单单规格:待支付->待补交->作废订单")
public void testSignGoods_single1() {
//case1:购买非0订单->待支付->带补交->作废订单
//切换端位
info.setTerminal(Terminal.minApp);
info.setLoginUser(LoginAccount.GYM_MINIAPPC);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//获取会员信息
//获取用户
memberId = userTools.getMemberInfo(info).getString("memberId");
String goodsId1="1874413681302990849";
//获取B端商品详情
JSONObject getDetail_goods=goodTools.getDetail_goods(goodsId1);
String id=getDetail_goods.getJSONObject("result").getString("id");
BigDecimal price=new BigDecimal(getDetail_goods.getJSONObject("result").getJSONObject("singleSpecInfo").getString("price"));
int beforeInventory=Integer.parseInt(getDetail_goods.getJSONObject("result").getJSONObject("singleSpecInfo").getString("inventory"));
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//获取数据中心-财务中心-营收明细-物品的确认收入
JSONObject beforeGetCostData_type=financeDataTools.getCostData_type("DAY","GOODS", TimeUtils.getTodayTime(),TimeUtils.getTodayEndTime());
BigDecimal beforeConfirmedAmount=new BigDecimal(beforeGetCostData_type.getJSONObject("result").getString("confirmedAmount"));//确认收入
JSONObject purchaseGoods = goodCTools.purchaseGoods("0.00", null,memberId,"",price.toString(),id,price,1,info);
String orderId2=purchaseGoods.getJSONObject("result").getString("id");
//生成待支付订单后,去B端继续收款
//获取B端订单详情:待支付状态
JSONObject getDetailResult = orderTools.getDetail(orderId2,info);
String state=getDetailResult.getJSONObject("result").getString("state");
BigDecimal unpaidAmount=new BigDecimal(getDetailResult.getJSONObject("result").getString("unpaidAmount"));
Assert.assertEquals(state,"WAITING","未生成待支付物品订单");
//校验1:B端商品详情库存数-1
JSONObject afterGetDetail_goods=goodTools.getDetail_goods(goodsId1);
int afterInventory=Integer.parseInt(afterGetDetail_goods.getJSONObject("result").getJSONObject("singleSpecInfo").getString("inventory"));
Assert.assertEquals(afterInventory,beforeInventory-1,"购买1个物品生成待支付订单后,应扣除1个库存数");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验2:权益未到,数据中心的确认收入没有增加
//获取数据中心-财务中心-营收明细-物品的确认收入
JSONObject afterGetCostData_type=financeDataTools.getCostData_type("DAY","GOODS", TimeUtils.getTodayTime(),TimeUtils.getTodayEndTime());
BigDecimal afterConfirmedAmount=new BigDecimal(afterGetCostData_type.getJSONObject("result").getString("confirmedAmount"));//确认收入
Assert.assertEquals(afterConfirmedAmount,beforeConfirmedAmount,"购买1个物品生成待支付订单后,财务中心-营收明细-物品的确认收入应无变化");
//B端变更为待补交物品订单
BigDecimal num=new BigDecimal(2);
//继续收款为待补交
JSONObject pay_unpaid=orderTools.pay_unpaid(unpaidAmount.divide(num),"1",orderId2,true);
//校验1:获取B端订单详情:待补交状态
JSONObject getDetailResult_delinquent = orderTools.getDetail(orderId2);
String state_delinquent=getDetailResult_delinquent.getJSONObject("result").getString("state");
Assert.assertEquals(state_delinquent,"DELINQUENT","B端继续收款后订单状态由待支付变为待补交");
//校验2:B端商品详情库存数不变
JSONObject lastGetDetail_goods=goodTools.getDetail_goods(goodsId1);
int lastInventory=Integer.parseInt(lastGetDetail_goods.getJSONObject("result").getJSONObject("singleSpecInfo").getString("inventory"));
Assert.assertEquals(lastInventory,afterInventory,"B端继续收款后订单状态由待支付变为待补交,库存数应不变");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验3:权益到,数据中心的确认收入应增加
//获取数据中心-财务中心-营收明细-物品的确认收入
JSONObject lastGetCostData_type=financeDataTools.getCostData_type("DAY","GOODS", TimeUtils.getTodayTime(),TimeUtils.getTodayEndTime());
BigDecimal lastConfirmedAmount=new BigDecimal(lastGetCostData_type.getJSONObject("result").getString("confirmedAmount"));//确认收入
Assert.assertEquals(lastConfirmedAmount,afterConfirmedAmount.add(unpaidAmount.setScale(2, RoundingMode.HALF_UP)),"B端继续收款后订单状态由待支付变为待补交,财务中心-营收明细-物品的确认收入应增加");
//作废待补交订单
JSONObject discard=orderTools.discard(orderId2, "重复录入", "已作废签单订单" + RandomStringUtil.randomString(10));
//校验1:获取B端订单详情:已作废状态
JSONObject getDetailResult_discard = orderTools.getDetail(orderId2);
String state_discard=getDetailResult_discard.getJSONObject("result").getString("state");
Assert.assertEquals(state_discard,"DISCARD","B端作废订单后状态由待补交变为已作废");
//校验2:B端商品详情库存数+1
JSONObject discardGetDetail_goods=goodTools.getDetail_goods(goodsId1);
int discardInventory=Integer.parseInt(discardGetDetail_goods.getJSONObject("result").getJSONObject("singleSpecInfo").getString("inventory"));
Assert.assertEquals(discardInventory,lastInventory+1,"B端作废订单后,应增加1个库存数");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验3:权益退回,数据中心的确认收入应减少
//获取数据中心-财务中心-营收明细-物品的确认收入
JSONObject discardGetCostData_type=financeDataTools.getCostData_type("DAY","GOODS", TimeUtils.getTodayTime(),TimeUtils.getTodayEndTime());
BigDecimal discardConfirmedAmount=new BigDecimal(discardGetCostData_type.getJSONObject("result").getString("confirmedAmount"));//确认收入
Assert.assertEquals(discardConfirmedAmount,lastConfirmedAmount.subtract(unpaidAmount.setScale(2, RoundingMode.HALF_UP)),"B端作废订单后,财务中心-营收明细-物品的确认收入应减少");
}
}
package com.xiaomai.cases.polar.goods;
import com.alibaba.fastjson.JSONObject;
import com.xiaomai.cases.lunar.goods.GoodCTools;
import com.xiaomai.cases.lunar.user.UserTools;
import com.xiaomai.cases.polar.data.financeData.FinanceDataTools;
import com.xiaomai.cases.polar.finance.order.OrderTools;
import com.xiaomai.cases.polar.goods.Tools.GoodTools;
import com.xiaomai.cases.polar.memberCard.CardTools;
import com.xiaomai.client.DataUserInfo;
import com.xiaomai.enums.ApiModule;
import com.xiaomai.enums.LoginAccount;
import com.xiaomai.enums.Terminal;
import com.xiaomai.utils.RandomStringUtil;
import com.xiaomai.utils.TimeUtils;
import com.xiaomai.utils.XMBaseTest;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.math.BigDecimal;
import java.math.RoundingMode;
public class TestGoodsOrderByDeposit extends XMBaseTest {
GoodTools goodTools=new GoodTools();
GoodCTools goodCTools=new GoodCTools();
DataUserInfo info =new DataUserInfo();
UserTools userTools=new UserTools();
OrderTools orderTools=new OrderTools();
CardTools cardTools=new CardTools();
FinanceDataTools financeDataTools=new FinanceDataTools();
String memberId;
@BeforeMethod
public void beforeTest() {
xmAppApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_refundGoods")
.setLoginUser(LoginAccount.GYM_PROD)
.setTerminal(Terminal.B);
dal.setCase_owner("yff")
.setCase_name(Thread.currentThread().getStackTrace()[1].getFileName().split("\\.")[0]);
super.beforeTest();
}
@Test(description = "使用储值卡购买单规格&退货退款->作废退&作废购买")
public void TestGoodsOrderByDeposit() {
//涉及到订单的都使用存量物品数据,因为购买过物品就不能被删除了,所以不会买一次新建一个
// "id": "1874413681302990849",
// "name": "自动化禁用-购买订单单规格1元",
// "id": "1874413587237335042",
// "name": "自动化禁用-购买订单多规格1元",
//存量储值卡:自动化用于物品储值卡1元禁用
//case1:使用储值卡购买非0订单,储值卡全额抵扣->已完成,物品权益到账,储值卡额度减少
//切换端位
info.setTerminal(Terminal.minApp);
info.setLoginUser(LoginAccount.GYM_MINIAPPC);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//获取会员信息
//获取用户
memberId = userTools.getMemberInfo(info).getString("memberId");
String goodsId1="1874413681302990849";
//获取储值卡
JSONObject tenantMemberCardCommonSearch=cardTools.tenantMemberCardCommonSearch("DEPOSIT_CARD","自动化用于物品储值卡1元禁用");
String cardId=tenantMemberCardCommonSearch.getJSONArray("result").getJSONObject(0).getString("id");
//获取储值卡详情
JSONObject fetchDetailById=cardTools.fetchDetailById(cardId);
String latestSnapshotId=fetchDetailById.getJSONObject("result").getString("latestSnapshotId");
BigDecimal cardPrice=new BigDecimal(fetchDetailById.getJSONObject("result").getJSONArray("benefitList").getJSONObject(0).getString("price"));
BigDecimal cardBalance=new BigDecimal(fetchDetailById.getJSONObject("result").getJSONArray("benefitList").getJSONObject(0).getString("balance"));
//1.购储值卡,获取购卡订单id
String voucherId = cardTools.signOrderDeposit(cardId,latestSnapshotId,memberId,String.valueOf(cardPrice),String.valueOf(cardBalance));
//获取已售储值卡ID,使用储值卡抵扣的时候需要的ID
JSONObject listUserUsableDepositCardB=cardTools.listUserUsableDepositCardB(memberId,"GOODS").getJSONObject("result").getJSONArray("applicableList").getJSONObject(0);
String cardId1=listUserUsableDepositCardB.getString("id");
//获取B端商品详情
JSONObject getDetail_goods=goodTools.getDetail_goods(goodsId1);
String id=getDetail_goods.getJSONObject("result").getString("id");
BigDecimal price=new BigDecimal(getDetail_goods.getJSONObject("result").getJSONObject("singleSpecInfo").getString("price"));
int beforeInventory=Integer.parseInt(getDetail_goods.getJSONObject("result").getJSONObject("singleSpecInfo").getString("inventory"));
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//获取数据中心-财务中心-营收明细-物品的确认收入
JSONObject beforeGetCostData_type=financeDataTools.getCostData_type("DAY","GOODS", TimeUtils.getTodayTime(),TimeUtils.getTodayEndTime());
BigDecimal beforeConfirmedAmount=new BigDecimal(beforeGetCostData_type.getJSONObject("result").getString("confirmedAmount"));//确认收入
JSONObject purchaseGoods = goodCTools.purchaseGoods(String.valueOf(cardPrice.add(cardBalance.setScale(2, RoundingMode.HALF_UP))), cardId1, memberId, "", "0.00", id, price, 1, info);
String signOrderId1 = purchaseGoods.getJSONObject("result").getString("id");
//校验1:获取B端订单详情:已完成状态
JSONObject getDetailResult_delinquent = orderTools.getDetail(signOrderId1);
String state_delinquent = getDetailResult_delinquent.getJSONObject("result").getString("state");
Assert.assertEquals(state_delinquent, "PAID", "使用储值卡购买订单,全部抵扣完之后生成已完成的物品订单");
//校验2:购买后库存数减少
//获取B端商品详情
JSONObject signGetDetail_goods=goodTools.getDetail_goods(goodsId1);
int signInventory=Integer.parseInt(signGetDetail_goods.getJSONObject("result").getJSONObject("singleSpecInfo").getString("inventory"));
Assert.assertEquals(signInventory,beforeInventory-1,"使用储值卡全额抵扣购买物品成功后,物品库存数应减少1个");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验3:数据中心-财务中心-营收明细-物品的确认收入增加对应的充值金额
JSONObject afterGetCostData_type = financeDataTools.getCostData_type("DAY", "GOODS", TimeUtils.getTodayTime(), TimeUtils.getTodayEndTime());
BigDecimal afterConfirmedAmount = new BigDecimal(afterGetCostData_type.getJSONObject("result").getString("confirmedAmount"));//确认收入
Assert.assertEquals(afterConfirmedAmount,beforeConfirmedAmount.add(cardPrice.setScale(2,RoundingMode.HALF_UP)),"使用储值卡全额抵扣购买物品,确认收入增加储值卡充值金额");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验4:储值卡额度减少,剩余充值金额+赠送金额为0
//获取储值卡详情
JSONObject fetchDetailById1=cardTools.memberCardFindDetailById(cardId1);
BigDecimal leftDepositPurchaseBenefitAmount1=new BigDecimal(fetchDetailById1.getJSONObject("result").getJSONObject("depositBenefit").getString("leftPurchaseBalance"));
BigDecimal leftDepositGiveBenefitAmount1=new BigDecimal(fetchDetailById1.getJSONObject("result").getJSONObject("depositBenefit").getString("leftGiveBalance"));
BigDecimal num=new BigDecimal("0.00");
Assert.assertEquals(leftDepositPurchaseBenefitAmount1,num,"使用储值卡全额抵扣购买物品,所使用的储值卡充值剩余金额应为0");
Assert.assertEquals(leftDepositGiveBenefitAmount1,num,"使用储值卡全额抵扣购买物品,所使用的储值卡赠送剩余金额应为0");
//case2:退掉使用储值卡购买非0订单,物品权益退回,储值卡额度返还
//拉取这个会员的物品列表
JSONObject listLeftGoodsItem=goodTools.listLeftGoodsItem(memberId);
String refundId=listLeftGoodsItem.getJSONArray("result").getJSONObject(0).getString("id");
//B端退单时获取订单可退物品(退单界面)
JSONObject getLeftGoodsItem=goodTools.getLeftGoodsItem(refundId);
int quantity=Integer.parseInt(getLeftGoodsItem.getJSONObject("result").getString("leftQuantity"));
BigDecimal refundAmount=new BigDecimal(getLeftGoodsItem.getJSONObject("result").getString("leftPaidAmount"));
String voucherItemId=getLeftGoodsItem.getJSONObject("result").getString("id");
BigDecimal receivableAmount=new BigDecimal(getLeftGoodsItem.getJSONObject("result").getString("leftPaidAmount"));
BigDecimal amount=new BigDecimal(getLeftGoodsItem.getJSONObject("result").getString("leftConsumeAmount"));
//退货退款物品
JSONObject refundGoods=goodTools.refundGoods(quantity,refundAmount,true,voucherItemId,memberId,receivableAmount,amount,"1",cardPrice,cardBalance,cardId1);
String refundOrderId1=refundGoods.getString("result");
//校验:
//校验1:获取B端订单详情:退单已完成状态
JSONObject getDetailResult_refund = orderTools.getDetail(refundOrderId1);
String state_refund = getDetailResult_refund.getJSONObject("result").getString("state");
Assert.assertEquals(state_refund, "PAID", "B端退货退款成功后退单物品订单状态变为已完成");
//校验2:退货退款后库存数减少
//获取B端商品详情
JSONObject refundGetDetail_goods=goodTools.getDetail_goods(goodsId1);
int refundInventory=Integer.parseInt(refundGetDetail_goods.getJSONObject("result").getJSONObject("singleSpecInfo").getString("inventory"));
Assert.assertEquals(refundInventory,signInventory+1,"使用储值卡全额抵扣购买物品退货退款成功后,物品库存数应增加1个");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验3:数据中心-财务中心-营收明细-物品的确认收入应减少充值金额
JSONObject refundAfterGetCostData_type = financeDataTools.getCostData_type("DAY", "GOODS", TimeUtils.getTodayTime(), TimeUtils.getTodayEndTime());
BigDecimal refundAfterConfirmedAmount = new BigDecimal(refundAfterGetCostData_type.getJSONObject("result").getString("confirmedAmount"));//确认收入
Assert.assertEquals(refundAfterConfirmedAmount,afterConfirmedAmount.subtract(cardPrice.setScale(2,RoundingMode.HALF_UP)),"退掉使用储值卡全额抵扣购买的物品,确认收入减少储值卡充值金额");
//校验4:储值卡额度增加,剩余充值金额+赠送金额增加
//获取储值卡详情
JSONObject fetchDetailById2=cardTools.memberCardFindDetailById(cardId1);
BigDecimal leftDepositPurchaseBenefitAmount2=new BigDecimal(fetchDetailById2.getJSONObject("result").getJSONObject("depositBenefit").getString("leftPurchaseBalance"));
BigDecimal leftDepositGiveBenefitAmount2=new BigDecimal(fetchDetailById2.getJSONObject("result").getJSONObject("depositBenefit").getString("leftGiveBalance"));
Assert.assertEquals(leftDepositPurchaseBenefitAmount2,cardPrice,"退掉使用储值卡全额抵扣购买的物品,所使用的储值卡充值剩余金额应返回对应的金额");
Assert.assertEquals(leftDepositGiveBenefitAmount2,cardBalance,"使用储值卡全额抵扣购买物品,所使用的储值卡赠送剩余金额应返回对应的金额");
//case3:作废退掉使用储值卡购买非0订单,物品权益返还,储值卡额度减少
JSONObject discardRefundOrder=orderTools.discard(refundOrderId1, "重复录入", "已作废物品退货退款订单" + RandomStringUtil.randomString(10));
//校验:
//校验1:获取B端订单详情:退单已作废状态
JSONObject getDetailResult_discardRefund = orderTools.getDetail(refundOrderId1);
String state_discardRefund = getDetailResult_discardRefund.getJSONObject("result").getString("state");
Assert.assertEquals(state_discardRefund, "DISCARD", "B端作废退货退款订单后,订单状态应由已完成变为已作废");
//校验2:退货退款后库存数减少
//获取B端商品详情
JSONObject disRefundGetDetail_goods=goodTools.getDetail_goods(goodsId1);
int disRefundInventory=Integer.parseInt(disRefundGetDetail_goods.getJSONObject("result").getJSONObject("singleSpecInfo").getString("inventory"));
Assert.assertEquals(disRefundInventory,refundInventory-1,"B端作废退货退款订单后,物品库存数应减少1个");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验3:数据中心-财务中心-营收明细-物品的确认收入应增加充值金额
JSONObject disRefundAfterGetCostData_type = financeDataTools.getCostData_type("DAY", "GOODS", TimeUtils.getTodayTime(), TimeUtils.getTodayEndTime());
BigDecimal disRefundAfterConfirmedAmount = new BigDecimal(disRefundAfterGetCostData_type.getJSONObject("result").getString("confirmedAmount"));//确认收入
Assert.assertEquals(disRefundAfterConfirmedAmount,refundAfterConfirmedAmount.add(cardPrice.setScale(2,RoundingMode.HALF_UP)),"作废退掉使用储值卡全额抵扣购买的物品,确认收入增加储值卡充值金额");
//校验4:储值卡额度增加,剩余充值金额+赠送金额增加
//获取储值卡详情
JSONObject fetchDetailById3=cardTools.memberCardFindDetailById(cardId1);
BigDecimal leftDepositPurchaseBenefitAmount3=new BigDecimal(fetchDetailById3.getJSONObject("result").getJSONObject("depositBenefit").getString("leftPurchaseBalance"));
BigDecimal leftDepositGiveBenefitAmount3=new BigDecimal(fetchDetailById3.getJSONObject("result").getJSONObject("depositBenefit").getString("leftGiveBalance"));
BigDecimal num1=new BigDecimal("0.00");
Assert.assertEquals(leftDepositPurchaseBenefitAmount3,num1,"作废退掉使用储值卡全额抵扣购买的物品,所使用的储值卡充值剩余金额应为0");
Assert.assertEquals(leftDepositGiveBenefitAmount3,num1,"作废退掉使用储值卡全额抵扣购买物品,所使用的储值卡赠送剩余金额应为0");
//case4:作废购买订单,物品权益退回,储值卡额度返还
JSONObject discardSignOrder=orderTools.discard(signOrderId1, "重复录入", "已作废物品购买订单" + RandomStringUtil.randomString(10));
//校验:
//校验1:获取B端订单详情:购买订单已作废状态
JSONObject getDetailResult_discardSign = orderTools.getDetail(signOrderId1);
String state_discardRefund_discardSign = getDetailResult_discardSign.getJSONObject("result").getString("state");
Assert.assertEquals(state_discardRefund_discardSign, "DISCARD", "B端作废购买订单后,签单订单状态由已完成变为已作废");
//校验2:退货退款后库存数减少
//获取B端商品详情
JSONObject disSignGetDetail_goods=goodTools.getDetail_goods(goodsId1);
int disSignInventory=Integer.parseInt(disSignGetDetail_goods.getJSONObject("result").getJSONObject("singleSpecInfo").getString("inventory"));
Assert.assertEquals(disSignInventory,disRefundInventory+1,"B端作废购买订单后,物品库存数应增加1个");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验3:数据中心-财务中心-营收明细-物品的确认收入应减少充值金额
JSONObject disSignAfterGetCostData_type = financeDataTools.getCostData_type("DAY", "GOODS", TimeUtils.getTodayTime(), TimeUtils.getTodayEndTime());
BigDecimal disSignAfterConfirmedAmount = new BigDecimal(disSignAfterGetCostData_type.getJSONObject("result").getString("confirmedAmount"));//确认收入
Assert.assertEquals(disSignAfterConfirmedAmount,disRefundAfterConfirmedAmount.subtract(cardPrice.setScale(2,RoundingMode.HALF_UP)),"作废使用储值卡全额抵扣购买的物品,确认收入减少储值卡充值金额");
//校验4:储值卡额度增加,剩余充值金额+赠送金额增加
//获取储值卡详情
JSONObject fetchDetailById4=cardTools.memberCardFindDetailById(cardId1);
BigDecimal leftDepositPurchaseBenefitAmount4=new BigDecimal(fetchDetailById4.getJSONObject("result").getJSONObject("depositBenefit").getString("leftPurchaseBalance"));
BigDecimal leftDepositGiveBenefitAmount4=new BigDecimal(fetchDetailById4.getJSONObject("result").getJSONObject("depositBenefit").getString("leftGiveBalance"));
Assert.assertEquals(leftDepositPurchaseBenefitAmount4,cardPrice,"作废使用储值卡全额抵扣购买的物品,所使用的储值卡充值剩余金额应返回对应的金额");
Assert.assertEquals(leftDepositGiveBenefitAmount4,cardPrice,"作废使用储值卡全额抵扣购买物品,所使用的储值卡赠送剩余金额应返回对应的金额");
}
}
package com.xiaomai.cases.polar.goods;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xiaomai.cases.lunar.goods.GoodCTools;
import com.xiaomai.cases.polar.goods.Tools.GoodTools;
import com.xiaomai.client.DataUserInfo;
import com.xiaomai.enums.ApiModule;
import com.xiaomai.enums.LoginAccount;
import com.xiaomai.enums.RequestType;
import com.xiaomai.enums.Terminal;
import com.xiaomai.utils.XMBaseTest;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.math.RoundingMode;
public class TestModifyGoods extends XMBaseTest {
GoodTools goodTools=new GoodTools();
GoodCTools goodCTools=new GoodCTools();
String createGoodsId;
DataUserInfo info =new DataUserInfo();
@BeforeMethod
public void beforeTest() {
xmAppApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_modifyGoods")
.setLoginUser(LoginAccount.GYM_PROD)
.setTerminal(Terminal.B);
dal.setCase_owner("yff")
.setCase_name(Thread.currentThread().getStackTrace()[1].getFileName().split("\\.")[0]);
super.beforeTest();
}
@Test(description = "编辑物品")
public void testModifyGoods() {
//切换端位
info.setTerminal(Terminal.minApp);
info.setLoginUser(LoginAccount.GYM_MINIAPPC);
String name="自动化编辑后单规格";
//case1:单规格改单规格
//创建了一个单规格&启用&开启小程序售卖
JSONObject createGoods=goodTools.createGoods_single("YES","0.01",10);
createGoodsId=createGoods.getString("result");
//修改物品状态为关闭
JSONObject modifyGoodsState=goodTools.modifyGoodsState(createGoodsId,"NO");
//单规格修改成单规格
//物品名称重名校验:为false才是不重名
boolean checkRepeatNameForStudio=Boolean.parseBoolean(goodTools.checkRepeatNameForStudio(name).getString("result"));
if(checkRepeatNameForStudio==false) {
JSONObject jsonObject = new JSONObject();
//商品介绍不为空,纯文本
JSONObject description = new JSONObject();
JSONArray items = new JSONArray();
JSONObject item1 = new JSONObject();
item1.put("type", "TEXT");
item1.put("content", "自动化编辑后单规格");
item1.put("aspect", "");
items.add(item1);
description.put("items", items);
jsonObject.put("description", description.toString());
jsonObject.put("groupId", "1873903328974499841");
JSONArray images=new JSONArray();
jsonObject.put("images",images);
jsonObject.put("multiSpec", false);
jsonObject.put("name", name);
jsonObject.put("xcxSaleState", "YES");
JSONObject jsonObject2 = new JSONObject();
jsonObject2.put("inventory", "100");
jsonObject2.put("price", "0.09");
jsonObject.put("singleSpecInfo", jsonObject2);
jsonObject.put("id",createGoodsId);
jsonObject.put("brandId", xmAppApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", xmAppApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId", xmAppApi.getLoginInfo().getAdminId());
xmAppApi.doRequest(RequestType.JSON, params, jsonObject.toJSONString(), headers).assetsSuccess(true);
//校验1:修改后字段:获取B端物品详情
JSONObject getDetail_goods=goodTools.getDetail_goods(createGoodsId).getJSONObject("result");
Assert.assertEquals(getDetail_goods.getString("name"),"自动化编辑后单规格","编辑物品名称但详情非编辑后的物品名称");
Assert.assertEquals(getDetail_goods.getJSONObject("group").getString("id"),"1873903328974499841","编辑物品分组但详情非编辑后的分组");
Assert.assertEquals(getDetail_goods.getBoolean("multiSpec").booleanValue(),false,"编辑成单规格但详情非编辑后的单规格");
Assert.assertEquals(getDetail_goods.getString("state"),"YES","编辑成单规格成功后但详情非编辑后的启用状态");
Assert.assertEquals(getDetail_goods.getString("xcxSaleState"),"YES","编辑成单规格成功后但详情非编辑后的开启小程序售卖");
Assert.assertEquals(getDetail_goods.getString("inventory"),"100","编辑成单规格成功后但详情总库存非编辑后的100");
Assert.assertEquals(getDetail_goods.getJSONObject("singleSpecInfo").getString("inventory"),"100","编辑成单规格成功后但详情库存非编辑后的100");
Assert.assertEquals(getDetail_goods.getJSONObject("singleSpecInfo").getBigDecimal("price").setScale(2, RoundingMode.HALF_UP).toString(),"0.09","编辑成单规格成功后但详情价格非编辑后的0.09");
//校验2:修改后字段:获取C端物品详情
JSONObject getDetail_goodsC=goodCTools.getDetail_goods_C(createGoodsId,info).getJSONObject("result");
Assert.assertEquals(getDetail_goodsC.getString("name"),"自动化编辑后单规格","编辑物品名称但详情非编辑后的物品名称");
Assert.assertEquals(getDetail_goodsC.getJSONObject("group").getString("id"),"1873903328974499841","编辑物品分组但详情非编辑后的分组");
Assert.assertEquals(getDetail_goodsC.getBoolean("multiSpec").booleanValue(),false,"编辑成单规格但详情非编辑后的单规格");
Assert.assertEquals(getDetail_goodsC.getString("state"),"YES","编辑成单规格成功后但详情非编辑后的启用状态");
Assert.assertEquals(getDetail_goodsC.getString("xcxSaleState"),"YES","编辑成单规格成功后但详情非编辑后的开启小程序售卖");
Assert.assertEquals(getDetail_goodsC.getString("inventory"),"100","编辑成单规格成功后但详情总库存非编辑后的100");
Assert.assertEquals(getDetail_goodsC.getJSONObject("singleSpecInfo").getString("inventory"),"100","编辑成单规格成功后但详情库存非编辑后的100");
Assert.assertEquals(getDetail_goodsC.getJSONObject("singleSpecInfo").getBigDecimal("price").setScale(2, RoundingMode.HALF_UP).toString(),"0.09","编辑成单规格成功后但详情价格非编辑后的0.09");
//校验3:获取B端物品列表
JSONObject afterStudioGoods = goodTools.studioGoods("");
JSONArray records = afterStudioGoods.getJSONObject("result").getJSONArray("records");
boolean success=false;
for (int i = 0; i < records.size(); i++) {
if (records.getJSONObject(i).getString("name").equals(name)) {
success=true;
break;
}
}
Assert.assertEquals(success, true, "物品列表中有此编辑后的物品名称");
//校验4:获取C端物品列表
JSONObject afterStudioGoodsC = goodCTools.pageXcxHomeGoodsC(info);
JSONArray recordsC = afterStudioGoodsC.getJSONObject("result").getJSONArray("records");
boolean successC=false;
for (int i = 0; i < recordsC.size(); i++) {
if (recordsC.getJSONObject(i).getString("name").equals(name)) {
successC=true;
break;
}
}
Assert.assertEquals(successC, true, "C端物品列表中有此编辑后的物品名称");
//校验5:生成一条编辑记录,类型为编辑物品
JSONObject pageGoodsModifyRecord=goodTools.pageGoodsModifyRecord(createGoodsId);
String pageGoodsModifyRecordResult=pageGoodsModifyRecord.getJSONObject("result").getJSONArray("records").getJSONObject(0).getString("type");
Assert.assertEquals(pageGoodsModifyRecordResult,"MODIFY","创建多规格物品后,未生成类型为编辑物品的编辑记录");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//case2:单规格改多规格
String name1="自动化编辑后多规格";
//校验5:获取编辑记录
JSONObject beforePageGoodsModifyRecord1=goodTools.pageGoodsModifyRecord(createGoodsId);
int beforeTotal1=Integer.parseInt(beforePageGoodsModifyRecord1.getJSONObject("result").getString("total"));
//修改物品状态为关闭
JSONObject modifyGoodsState1=goodTools.modifyGoodsState(createGoodsId,"NO");
//单规格修改成单规格
//物品名称重名校验:为false才是不重名
boolean checkRepeatNameForStudio1=Boolean.parseBoolean(goodTools.checkRepeatNameForStudio(name1).getString("result"));
if(checkRepeatNameForStudio1==false) {
String color1 = "黑色";
String color2 = "白色";
String size1 = "大的";
String size2 = "小的";
String skin1 = "貂蝉";
String skin2 = "王昭君";
JSONObject jsonObject1 = new JSONObject();
//商品介绍为空
// JSONObject description=new JSONObject();
// jsonObject.put("description",description.toString());
//商品介绍不为空,纯文本
JSONObject description1 = new JSONObject();
JSONArray items1 = new JSONArray();
JSONObject item11 = new JSONObject();
item11.put("type", "TEXT");
item11.put("content", "自动化编辑后的多规格三个规格,每个规格都有两个规格值");
item11.put("aspect", "");
items1.add(item11);
description1.put("items", items1);
jsonObject1.put("description", description1.toString());
JSONArray images1=new JSONArray();
jsonObject1.put("images",images1);
jsonObject1.put("groupId", "1873912725360504834");
jsonObject1.put("multiSpec", true);
jsonObject1.put("name", name1);
jsonObject1.put("xcxSaleState", "YES");
JSONObject multiSpecInfo = new JSONObject();
//设置三个规格和每个都有两个规格值
JSONArray specList = new JSONArray();
JSONObject specList1 = new JSONObject();
specList1.put("name", "颜色");
JSONArray specList1SpecValues = new JSONArray();
JSONObject specList1SpecValues1 = new JSONObject();
specList1SpecValues1.put("name", color1);
JSONObject specList1SpecValues2 = new JSONObject();
specList1SpecValues2.put("name", color2);
specList1SpecValues.add(specList1SpecValues1);
specList1SpecValues.add(specList1SpecValues2);
specList1.put("specValues", specList1SpecValues);
JSONObject specList2 = new JSONObject();
specList2.put("name", "尺码");
JSONArray specList2SpecValues = new JSONArray();
JSONObject specList2SpecValues1 = new JSONObject();
specList2SpecValues1.put("name", size1);
JSONObject specList2SpecValues2 = new JSONObject();
specList2SpecValues2.put("name", size2);
specList2SpecValues.add(specList2SpecValues1);
specList2SpecValues.add(specList2SpecValues2);
specList2.put("specValues", specList2SpecValues);
JSONObject specList3 = new JSONObject();
specList3.put("name", "限定皮肤");
JSONArray specList3SpecValues = new JSONArray();
JSONObject specList3SpecValues1 = new JSONObject();
specList3SpecValues1.put("name", skin1);
JSONObject specList3SpecValues2 = new JSONObject();
specList3SpecValues2.put("name", skin2);
specList3SpecValues.add(specList3SpecValues1);
specList3SpecValues.add(specList3SpecValues2);
specList3.put("specValues", specList3SpecValues);
specList.add(specList1);
specList.add(specList2);
specList.add(specList3);
multiSpecInfo.put("specList", specList);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//排列出来的组合2*2*2
JSONArray specCombinationList = new JSONArray();
JSONObject specCombinationList1 = new JSONObject();
JSONArray specCombinationList1Specs = new JSONArray();
specCombinationList1Specs.add(color1);
specCombinationList1Specs.add(size1);
specCombinationList1Specs.add(skin1);
specCombinationList1.put("specs", specCombinationList1Specs);
specCombinationList1.put("price", "0.01");
specCombinationList1.put("inventory", 10);
specCombinationList.add(specCombinationList1);
JSONObject specCombinationList2 = new JSONObject();
JSONArray specCombinationList2Specs = new JSONArray();
specCombinationList2Specs.add(color1);
specCombinationList2Specs.add(size1);
specCombinationList2Specs.add(skin2);
specCombinationList2.put("specs", specCombinationList2Specs);
specCombinationList2.put("price", "0.01");
specCombinationList2.put("inventory", 10);
specCombinationList.add(specCombinationList2);
JSONObject specCombinationList3 = new JSONObject();
JSONArray specCombinationList3Specs = new JSONArray();
specCombinationList3Specs.add(color1);
specCombinationList3Specs.add(size2);
specCombinationList3Specs.add(skin1);
specCombinationList3.put("specs", specCombinationList3Specs);
specCombinationList3.put("price", "0.01");
specCombinationList3.put("inventory", 10);
specCombinationList.add(specCombinationList3);
JSONObject specCombinationList4 = new JSONObject();
JSONArray specCombinationList4Specs = new JSONArray();
specCombinationList4Specs.add(color1);
specCombinationList4Specs.add(size2);
specCombinationList4Specs.add(skin2);
specCombinationList4.put("specs", specCombinationList4Specs);
specCombinationList4.put("price", "0.01");
specCombinationList4.put("inventory", 10);
specCombinationList.add(specCombinationList4);
JSONObject specCombinationList5 = new JSONObject();
JSONArray specCombinationList5Specs = new JSONArray();
specCombinationList5Specs.add(color2);
specCombinationList5Specs.add(size1);
specCombinationList5Specs.add(skin1);
specCombinationList5.put("specs", specCombinationList5Specs);
specCombinationList5.put("price", "0.01");
specCombinationList5.put("inventory", 10);
specCombinationList.add(specCombinationList5);
JSONObject specCombinationList6 = new JSONObject();
JSONArray specCombinationList6Specs = new JSONArray();
specCombinationList6Specs.add(color2);
specCombinationList6Specs.add(size1);
specCombinationList6Specs.add(skin2);
specCombinationList6.put("specs", specCombinationList6Specs);
specCombinationList6.put("price", "0.01");
specCombinationList6.put("inventory", 10);
specCombinationList.add(specCombinationList6);
JSONObject specCombinationList7 = new JSONObject();
JSONArray specCombinationList7Specs = new JSONArray();
specCombinationList7Specs.add(color2);
specCombinationList7Specs.add(size2);
specCombinationList7Specs.add(skin1);
specCombinationList7.put("specs", specCombinationList7Specs);
specCombinationList7.put("price", "0.01");
specCombinationList7.put("inventory", 10);
specCombinationList.add(specCombinationList7);
JSONObject specCombinationList8 = new JSONObject();
JSONArray specCombinationList8Specs = new JSONArray();
specCombinationList8Specs.add(color2);
specCombinationList8Specs.add(size2);
specCombinationList8Specs.add(skin2);
specCombinationList8.put("specs", specCombinationList8Specs);
specCombinationList8.put("price", "0.01");
specCombinationList8.put("inventory", 10);
specCombinationList.add(specCombinationList8);
multiSpecInfo.put("specCombinationList", specCombinationList);
jsonObject1.put("multiSpecInfo", multiSpecInfo);
jsonObject1.put("id",createGoodsId);
jsonObject1.put("brandId", xmAppApi.getLoginInfo().getBrandId());
jsonObject1.put("studioId", xmAppApi.getLoginInfo().getStudioId());
jsonObject1.put("operatorId", xmAppApi.getLoginInfo().getAdminId());
xmAppApi.doRequest(RequestType.JSON, params, jsonObject1.toJSONString(), headers).assetsSuccess(true);
//校验1:修改后字段:获取B端物品详情
JSONObject getDetail_goods1=goodTools.getDetail_goods(createGoodsId).getJSONObject("result");
Assert.assertEquals(getDetail_goods1.getString("name"),"自动化编辑后多规格","编辑物品名称但详情非编辑后的物品名称");
Assert.assertEquals(getDetail_goods1.getJSONObject("group").getString("id"),"1873912725360504834","编辑物品分组但详情非编辑后的分组");
Assert.assertEquals(getDetail_goods1.getBoolean("multiSpec").booleanValue(),true,"编辑成多规格但详情非编辑后的多规格");
Assert.assertEquals(getDetail_goods1.getString("state"),"YES","编辑成多规格成功后但详情非编辑后的启用状态");
Assert.assertEquals(getDetail_goods1.getString("xcxSaleState"),"YES","编辑成多规格成功后但详情非编辑后的开启小程序售卖");
Assert.assertEquals(getDetail_goods1.getString("inventory"),"80","编辑成多规格成功后但详情总库存非编辑后的80");
//校验2:修改后字段:获取C端物品详情
JSONObject getDetail_goodsC1=goodCTools.getDetail_goods_C(createGoodsId,info).getJSONObject("result");
Assert.assertEquals(getDetail_goodsC1.getString("name"),"自动化编辑后多规格","编辑物品名称但详情非编辑后的物品名称");
Assert.assertEquals(getDetail_goodsC1.getJSONObject("group").getString("id"),"1873912725360504834","编辑物品分组但详情非编辑后的分组");
Assert.assertEquals(getDetail_goodsC1.getBoolean("multiSpec").booleanValue(),true,"编辑成多规格但详情非编辑后的多规格");
Assert.assertEquals(getDetail_goodsC1.getString("state"),"YES","编辑成多规格成功后但详情非编辑后的启用状态");
Assert.assertEquals(getDetail_goodsC1.getString("xcxSaleState"),"YES","编辑成多规格成功后但详情非编辑后的开启小程序售卖");
Assert.assertEquals(getDetail_goodsC1.getString("inventory"),"80","编辑成多规格成功后但详情总库存非编辑后的80");
//校验3:获取B端物品列表
JSONObject afterStudioGoods1 = goodTools.studioGoods("");
JSONArray records1 = afterStudioGoods1.getJSONObject("result").getJSONArray("records");
boolean success1=false;
for (int i = 0; i < records1.size(); i++) {
if (records1.getJSONObject(i).getString("name").equals(name1)) {
success1=true;
break;
}
}
Assert.assertEquals(success1, true, "物品列表中有此编辑后的物品名称");
//校验4:获取C端物品列表
JSONObject afterStudioGoodsC1 = goodCTools.pageXcxHomeGoodsC(info);
JSONArray recordsC1 = afterStudioGoodsC1.getJSONObject("result").getJSONArray("records");
boolean successC1=false;
for (int i = 0; i < recordsC1.size(); i++) {
if (recordsC1.getJSONObject(i).getString("name").equals(name1)) {
successC1=true;
break;
}
}
Assert.assertEquals(successC1, true, "C端物品列表中有此编辑后的物品名称");
//校验5:生成一条编辑记录,类型为编辑物品
JSONObject pageGoodsModifyRecord1=goodTools.pageGoodsModifyRecord(createGoodsId);
int afterTotal1=Integer.parseInt(pageGoodsModifyRecord1.getJSONObject("result").getString("total"));
String pageGoodsModifyRecordResult1=pageGoodsModifyRecord1.getJSONObject("result").getJSONArray("records").getJSONObject(0).getString("type");
Assert.assertEquals(pageGoodsModifyRecordResult1,"MODIFY","创建多规格物品后,未生成类型为编辑物品的编辑记录");
Assert.assertEquals(afterTotal1,beforeTotal1+1,"编辑成功后未生成编辑记录");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//case3:多规格改多规格
String name2="自动化编辑后一个规格";
//校验5:获取编辑记录
JSONObject beforePageGoodsModifyRecord2=goodTools.pageGoodsModifyRecord(createGoodsId);
int beforeTotal2=Integer.parseInt(beforePageGoodsModifyRecord2.getJSONObject("result").getString("total"));
//修改物品状态为关闭
JSONObject modifyGoodsState2=goodTools.modifyGoodsState(createGoodsId,"NO");
String color11 = "黑色";
String color22 = "白色";
String name66="颜色";
//获取规格名/规格值修改后的物品规格列表
JSONObject listModifiedSpecCombinations=goodTools.listModifiedSpecCombinations(createGoodsId,"",name66,"",color11,"",color22);
String specs1=listModifiedSpecCombinations.getJSONArray("result").getJSONObject(0).getJSONArray("specs").getString(0);
String specs2=listModifiedSpecCombinations.getJSONArray("result").getJSONObject(1).getJSONArray("specs").getString(0);
Assert.assertEquals(specs1,color11,"修改后的物品规格列表和修改的规格值不一致");
Assert.assertEquals(specs2,color22,"修改后的物品规格列表和修改的规格值不一致");
//物品名称重名校验:为false才是不重名
boolean checkRepeatNameForStudio2=Boolean.parseBoolean(goodTools.checkRepeatNameForStudio(name2).getString("result"));
if(checkRepeatNameForStudio2==false) {
JSONObject jsonObject3 = new JSONObject();
//商品介绍为空
// JSONObject description=new JSONObject();
// jsonObject.put("description",description.toString());
//商品介绍不为空,纯文本
JSONObject description2 = new JSONObject();
JSONArray items2 = new JSONArray();
JSONObject item22 = new JSONObject();
item22.put("type", "TEXT");
item22.put("content", "自动化编辑后的多规格一个规格,每个规格有两个规格值");
item22.put("aspect", "");
items2.add(item22);
description2.put("items", items2);
jsonObject3.put("description", description2.toString());
JSONArray images2 = new JSONArray();
jsonObject3.put("images", images2);
jsonObject3.put("groupId", "1873912725360504834");
jsonObject3.put("multiSpec", true);
jsonObject3.put("name", name2);
jsonObject3.put("xcxSaleState", "YES");
JSONObject multiSpecInfo1 = new JSONObject();
//设置一个规格有两个规格值
JSONArray specList6 = new JSONArray();
JSONObject specList66 = new JSONObject();
specList66.put("name", name66);
JSONArray specList6SpecValues = new JSONArray();
JSONObject specList6SpecValues1 = new JSONObject();
specList6SpecValues1.put("name", color11);
JSONObject specList6SpecValues2 = new JSONObject();
specList6SpecValues2.put("name", color22);
specList6SpecValues.add(specList6SpecValues1);
specList6SpecValues.add(specList6SpecValues2);
specList66.put("specValues", specList6SpecValues);
specList6.add(specList66);
multiSpecInfo1.put("specList", specList6);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//排列出来的组合1*2
JSONArray specCombinationList9 = new JSONArray();
JSONObject specCombinationList99 = new JSONObject();
JSONArray specCombinationList9Specs = new JSONArray();
specCombinationList9Specs.add(color11);
specCombinationList99.put("specs", specCombinationList9Specs);
specCombinationList99.put("price", "0.02");
specCombinationList99.put("inventory", 10);
specCombinationList9.add(specCombinationList99);
JSONObject specCombinationList1010 = new JSONObject();
JSONArray specCombinationList10Specs = new JSONArray();
specCombinationList10Specs.add(color22);
specCombinationList1010.put("specs", specCombinationList10Specs);
specCombinationList1010.put("price", "0.02");
specCombinationList1010.put("inventory", 10);
specCombinationList9.add(specCombinationList1010);
multiSpecInfo1.put("specCombinationList", specCombinationList9);
jsonObject3.put("multiSpecInfo", multiSpecInfo1);
jsonObject3.put("id", createGoodsId);
jsonObject3.put("brandId", xmAppApi.getLoginInfo().getBrandId());
jsonObject3.put("studioId", xmAppApi.getLoginInfo().getStudioId());
jsonObject3.put("operatorId", xmAppApi.getLoginInfo().getAdminId());
xmAppApi.doRequest(RequestType.JSON, params, jsonObject3.toJSONString(), headers).assetsSuccess(true);
//校验1:修改后字段:获取B端物品详情
JSONObject getDetail_goods2 = goodTools.getDetail_goods(createGoodsId).getJSONObject("result");
Assert.assertEquals(getDetail_goods2.getString("name"), "自动化编辑后一个规格", "编辑物品名称但详情非编辑后的物品名称");
Assert.assertEquals(getDetail_goods2.getJSONObject("group").getString("id"), "1873912725360504834", "编辑物品分组但详情非编辑后的分组");
Assert.assertEquals(getDetail_goods2.getBoolean("multiSpec").booleanValue(), true, "编辑成多规格但详情非编辑后的多规格");
Assert.assertEquals(getDetail_goods2.getString("state"), "YES", "编辑成多规格成功后但详情非编辑后的启用状态");
Assert.assertEquals(getDetail_goods2.getString("xcxSaleState"), "YES", "编辑成多规格成功后但详情非编辑后的开启小程序售卖");
Assert.assertEquals(getDetail_goods2.getString("inventory"), "20", "编辑成多规格成功后但详情总库存非编辑后的20");
//校验2:修改后字段:获取C端物品详情
JSONObject getDetail_goodsC2 = goodCTools.getDetail_goods_C(createGoodsId, info).getJSONObject("result");
Assert.assertEquals(getDetail_goodsC2.getString("name"), "自动化编辑后一个规格", "编辑物品名称但详情非编辑后的物品名称");
Assert.assertEquals(getDetail_goodsC2.getJSONObject("group").getString("id"), "1873912725360504834", "编辑物品分组但详情非编辑后的分组");
Assert.assertEquals(getDetail_goodsC2.getBoolean("multiSpec").booleanValue(), true, "编辑成多规格但详情非编辑后的多规格");
Assert.assertEquals(getDetail_goodsC2.getString("state"), "YES", "编辑成多规格成功后但详情非编辑后的启用状态");
Assert.assertEquals(getDetail_goodsC2.getString("xcxSaleState"), "YES", "编辑成多规格成功后但详情非编辑后的开启小程序售卖");
Assert.assertEquals(getDetail_goodsC2.getString("inventory"), "20", "编辑成多规格成功后但详情总库存非编辑后的20");
//校验3:获取B端物品列表
JSONObject afterStudioGoods2 = goodTools.studioGoods("");
JSONArray records2 = afterStudioGoods2.getJSONObject("result").getJSONArray("records");
boolean success2 = false;
for (int i = 0; i < records2.size(); i++) {
if (records2.getJSONObject(i).getString("name").equals(name2)) {
success2 = true;
break;
}
}
Assert.assertEquals(success2, true, "物品列表中有此编辑后的物品名称");
//校验4:获取C端物品列表
JSONObject afterStudioGoodsC2 = goodCTools.pageXcxHomeGoodsC(info);
JSONArray recordsC2 = afterStudioGoodsC2.getJSONObject("result").getJSONArray("records");
boolean successC2 = false;
for (int i = 0; i < recordsC2.size(); i++) {
if (recordsC2.getJSONObject(i).getString("name").equals(name2)) {
successC2 = true;
break;
}
}
Assert.assertEquals(successC2, true, "C端物品列表中有此编辑后的物品名称");
//校验5:生成一条编辑记录,类型为编辑物品
JSONObject pageGoodsModifyRecord2 = goodTools.pageGoodsModifyRecord(createGoodsId);
int afterTotal2 = Integer.parseInt(pageGoodsModifyRecord2.getJSONObject("result").getString("total"));
String pageGoodsModifyRecordResult2 = pageGoodsModifyRecord2.getJSONObject("result").getJSONArray("records").getJSONObject(0).getString("type");
Assert.assertEquals(pageGoodsModifyRecordResult2, "MODIFY", "创建多规格物品后,未生成类型为编辑物品的编辑记录");
Assert.assertEquals(afterTotal2, beforeTotal2 + 1, "编辑成功后未生成编辑记录");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
String name3="自动化多规格编辑为单";
//case4:多规格改单规格
//校验5:获取编辑记录
JSONObject beforePageGoodsModifyRecord3=goodTools.pageGoodsModifyRecord(createGoodsId);
int beforeTotal3=Integer.parseInt(beforePageGoodsModifyRecord3.getJSONObject("result").getString("total"));
//修改物品状态为关闭
JSONObject modifyGoodsState3=goodTools.modifyGoodsState(createGoodsId,"NO");
//物品名称重名校验:为false才是不重名
boolean checkRepeatNameForStudio3=Boolean.parseBoolean(goodTools.checkRepeatNameForStudio(name3).getString("result"));
if(checkRepeatNameForStudio3==false) {
JSONObject jsonObject4= new JSONObject();
//商品介绍不为空,纯文本
JSONObject description3 = new JSONObject();
JSONArray items3 = new JSONArray();
JSONObject item33 = new JSONObject();
item33.put("type", "TEXT");
item33.put("content", "自动化多规格编辑成单规格");
item33.put("aspect", "");
items3.add(item33);
description3.put("items", items3);
jsonObject4.put("description", description3.toString());
jsonObject4.put("groupId", "1873903328974499841");
JSONArray images3 = new JSONArray();
jsonObject4.put("images", images3);
jsonObject4.put("multiSpec", false);
jsonObject4.put("name", name3);
jsonObject4.put("xcxSaleState", "YES");
JSONObject jsonObject5 = new JSONObject();
jsonObject5.put("inventory", "100");
jsonObject5.put("price", "0.09");
jsonObject4.put("singleSpecInfo", jsonObject5);
jsonObject4.put("id", createGoodsId);
jsonObject4.put("brandId", xmAppApi.getLoginInfo().getBrandId());
jsonObject4.put("studioId", xmAppApi.getLoginInfo().getStudioId());
jsonObject4.put("operatorId", xmAppApi.getLoginInfo().getAdminId());
xmAppApi.doRequest(RequestType.JSON, params, jsonObject4.toJSONString(), headers).assetsSuccess(true);
//校验1:修改后字段:获取B端物品详情
JSONObject getDetail_goods3 = goodTools.getDetail_goods(createGoodsId).getJSONObject("result");
Assert.assertEquals(getDetail_goods3.getString("name"), "自动化多规格编辑为单", "编辑物品名称但详情非编辑后的物品名称");
Assert.assertEquals(getDetail_goods3.getJSONObject("group").getString("id"), "1873903328974499841", "编辑物品分组但详情非编辑后的分组");
Assert.assertEquals(getDetail_goods3.getBoolean("multiSpec").booleanValue(), false, "编辑成单规格但详情非编辑后的单规格");
Assert.assertEquals(getDetail_goods3.getString("state"), "YES", "编辑成单规格成功后但详情非编辑后的启用状态");
Assert.assertEquals(getDetail_goods3.getString("xcxSaleState"), "YES", "编辑成单规格成功后但详情非编辑后的开启小程序售卖");
Assert.assertEquals(getDetail_goods3.getString("inventory"), "100", "编辑成单规格成功后但详情总库存非编辑后的100");
Assert.assertEquals(getDetail_goods3.getJSONObject("singleSpecInfo").getString("inventory"), "100", "编辑成单规格成功后但详情库存非编辑后的100");
Assert.assertEquals(getDetail_goods3.getJSONObject("singleSpecInfo").getBigDecimal("price").setScale(2, RoundingMode.HALF_UP).toString(), "0.09", "编辑成单规格成功后但详情价格非编辑后的0.09");
//校验2:修改后字段:获取C端物品详情
JSONObject getDetail_goodsC3 = goodCTools.getDetail_goods_C(createGoodsId, info).getJSONObject("result");
Assert.assertEquals(getDetail_goodsC3.getString("name"), "自动化多规格编辑为单", "编辑物品名称但详情非编辑后的物品名称");
Assert.assertEquals(getDetail_goodsC3.getJSONObject("group").getString("id"), "1873903328974499841", "编辑物品分组但详情非编辑后的分组");
Assert.assertEquals(getDetail_goodsC3.getBoolean("multiSpec").booleanValue(), false, "编辑成单规格但详情非编辑后的单规格");
Assert.assertEquals(getDetail_goodsC3.getString("state"), "YES", "编辑成单规格成功后但详情非编辑后的启用状态");
Assert.assertEquals(getDetail_goodsC3.getString("xcxSaleState"), "YES", "编辑成单规格成功后但详情非编辑后的开启小程序售卖");
Assert.assertEquals(getDetail_goodsC3.getString("inventory"), "100", "编辑成单规格成功后但详情总库存非编辑后的100");
Assert.assertEquals(getDetail_goodsC3.getJSONObject("singleSpecInfo").getString("inventory"), "100", "编辑成单规格成功后但详情库存非编辑后的100");
Assert.assertEquals(getDetail_goodsC3.getJSONObject("singleSpecInfo").getBigDecimal("price").setScale(2, RoundingMode.HALF_UP).toString(), "0.09", "编辑成单规格成功后但详情价格非编辑后的0.09");
//校验3:获取B端物品列表
JSONObject afterStudioGoods3 = goodTools.studioGoods("");
JSONArray records3 = afterStudioGoods3.getJSONObject("result").getJSONArray("records");
boolean success3 = false;
for (int i = 0; i < records3.size(); i++) {
if (records3.getJSONObject(i).getString("name").equals(name3)) {
success3 = true;
break;
}
}
Assert.assertEquals(success3, true, "物品列表中有此编辑后的物品名称");
//校验4:获取C端物品列表
JSONObject afterStudioGoodsC3 = goodCTools.pageXcxHomeGoodsC(info);
JSONArray recordsC3 = afterStudioGoodsC3.getJSONObject("result").getJSONArray("records");
boolean successC3 = false;
for (int i = 0; i < recordsC3.size(); i++) {
if (recordsC3.getJSONObject(i).getString("name").equals(name3)) {
successC3 = true;
break;
}
}
Assert.assertEquals(successC3, true, "C端物品列表中有此编辑后的物品名称");
//校验5:生成一条编辑记录,类型为编辑物品
JSONObject pageGoodsModifyRecord3 = goodTools.pageGoodsModifyRecord(createGoodsId);
int afterTotal3 = Integer.parseInt(pageGoodsModifyRecord3.getJSONObject("result").getString("total"));
String pageGoodsModifyRecordResult3 = pageGoodsModifyRecord3.getJSONObject("result").getJSONArray("records").getJSONObject(0).getString("type");
Assert.assertEquals(pageGoodsModifyRecordResult3, "MODIFY", "创建多规格物品后,未生成类型为编辑物品的编辑记录");
Assert.assertEquals(afterTotal3, beforeTotal3 + 1, "编辑成功后未生成编辑记录");
}
else {
System.out.println("编辑物品时,物品名称重复");
}
}
else {
System.out.println("编辑物品时,物品名称重复");
}
}
else {
System.out.println("编辑物品时,物品名称重复");
}
}
else {
System.out.println("编辑物品时,物品名称重复");
}
}
@Test(description = "删除物品",priority = 1)
public void delete(){
goodTools.deleteGoods(createGoodsId);
}
}
package com.xiaomai.cases.polar.goods;
import com.alibaba.fastjson.JSONObject;
import com.xiaomai.cases.lunar.goods.GoodCTools;
import com.xiaomai.cases.lunar.user.UserTools;
import com.xiaomai.cases.polar.data.financeData.FinanceDataTools;
import com.xiaomai.cases.polar.finance.order.OrderTools;
import com.xiaomai.cases.polar.goods.Tools.GoodTools;
import com.xiaomai.client.DataUserInfo;
import com.xiaomai.enums.ApiModule;
import com.xiaomai.enums.LoginAccount;
import com.xiaomai.enums.Terminal;
import com.xiaomai.utils.RandomStringUtil;
import com.xiaomai.utils.TimeUtils;
import com.xiaomai.utils.XMBaseTest;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.math.BigDecimal;
import java.math.RoundingMode;
public class TestRefundGoods extends XMBaseTest {
GoodTools goodTools=new GoodTools();
GoodCTools goodCTools=new GoodCTools();
DataUserInfo info =new DataUserInfo();
UserTools userTools=new UserTools();
OrderTools orderTools=new OrderTools();
FinanceDataTools financeDataTools=new FinanceDataTools();
String memberId;
@BeforeMethod
public void beforeTest() {
xmAppApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_refundGoods")
.setLoginUser(LoginAccount.GYM_PROD)
.setTerminal(Terminal.B);
dal.setCase_owner("yff")
.setCase_name(Thread.currentThread().getStackTrace()[1].getFileName().split("\\.")[0]);
super.beforeTest();
}
@Test(description = "退物品:购买多规格&退货退款->作废退&仅退款->作废退&作废购买")
public void testRefundGoods() {
//涉及到订单的都使用存量物品数据,因为购买过物品就不能被删除了,所以不会买一次新建一个
// "id": "1874413681302990849",
// "name": "自动化禁用-购买订单单规格1元",
// "id": "1874413587237335042",
// "name": "自动化禁用-购买订单多规格1元",
//case1:购买非0订单->待支付->已完成
//切换端位
info.setTerminal(Terminal.minApp);
info.setLoginUser(LoginAccount.GYM_MINIAPPC);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//获取会员信息
//获取用户
memberId = userTools.getMemberInfo(info).getString("memberId");
String goodsId1="1874413587237335042";
//获取B端商品详情
JSONObject getDetail_goods=goodTools.getDetail_goods(goodsId1);
String id=getDetail_goods.getJSONObject("result").getJSONObject("multiSpecInfo").getJSONArray("specCombinationList").getJSONObject(0).getString("id");
BigDecimal price=new BigDecimal(getDetail_goods.getJSONObject("result").getJSONObject("multiSpecInfo").getJSONArray("specCombinationList").getJSONObject(0).getString("price"));
int beforeInventory=Integer.parseInt(getDetail_goods.getJSONObject("result").getJSONObject("multiSpecInfo").getJSONArray("specCombinationList").getJSONObject(0).getString("inventory"));
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//获取数据中心-财务中心-营收明细-物品的确认收入
JSONObject beforeGetCostData_type=financeDataTools.getCostData_type("DAY","GOODS", TimeUtils.getTodayTime(),TimeUtils.getTodayEndTime());
BigDecimal beforeConfirmedAmount=new BigDecimal(beforeGetCostData_type.getJSONObject("result").getString("confirmedAmount"));//确认收入
boolean checkAllowPurchase=Boolean.parseBoolean(goodCTools.checkAllowPurchase(id,memberId,price,beforeInventory,info).getJSONObject("result").getString("success"));
//校验一下物品购买是否可以通过,为true才可以
if(checkAllowPurchase==true) {
JSONObject purchaseGoods = goodCTools.purchaseGoods("0.00", null, memberId, "", price.toString(), id, price, 1, info);
String signOrderId1 = purchaseGoods.getJSONObject("result").getString("id");
//生成待支付订单后,去B端继续收款
//获取B端订单详情:待支付状态
JSONObject getDetailResult = orderTools.getDetail(signOrderId1, info);
String state = getDetailResult.getJSONObject("result").getString("state");
BigDecimal unpaidAmount = new BigDecimal(getDetailResult.getJSONObject("result").getString("unpaidAmount"));
Assert.assertEquals(state, "WAITING", "未生成待支付物品订单");
//B端变更为已完成物品订单
//继续收款为已完成
JSONObject pay = orderTools.pay(unpaidAmount, "1", signOrderId1);
//校验1:获取B端订单详情:已完成状态
JSONObject getDetailResult_delinquent = orderTools.getDetail(signOrderId1);
String state_delinquent = getDetailResult_delinquent.getJSONObject("result").getString("state");
Assert.assertEquals(state_delinquent, "PAID", "B端继续收款后订单状态由待支付变为已完成");
//获取B端商品详情库存数
JSONObject lastGetDetail_goods = goodTools.getDetail_goods(goodsId1);
int refundBeforeInventory = Integer.parseInt(lastGetDetail_goods.getJSONObject("result").getJSONObject("multiSpecInfo").getJSONArray("specCombinationList").getJSONObject(0).getString("inventory"));
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//获取数据中心-财务中心-营收明细-物品的确认收入
JSONObject refundBeforeGetCostData_type = financeDataTools.getCostData_type("DAY", "GOODS", TimeUtils.getTodayTime(), TimeUtils.getTodayEndTime());
BigDecimal refundBeforeConfirmedAmount = new BigDecimal(refundBeforeGetCostData_type.getJSONObject("result").getString("confirmedAmount"));//确认收入
//case2:已完成->退货退款
//拉取这个会员的物品列表
JSONObject listLeftGoodsItem=goodTools.listLeftGoodsItem(memberId);
String refundId=listLeftGoodsItem.getJSONArray("result").getJSONObject(0).getString("id");
//B端退单时获取订单可退物品(退单界面)
JSONObject getLeftGoodsItem=goodTools.getLeftGoodsItem(refundId);
int quantity=Integer.parseInt(getLeftGoodsItem.getJSONObject("result").getString("leftQuantity"));
BigDecimal refundAmount=new BigDecimal(getLeftGoodsItem.getJSONObject("result").getString("leftConsumeAmount"));
String voucherItemId=getLeftGoodsItem.getJSONObject("result").getString("id");
BigDecimal receivableAmount=new BigDecimal(getLeftGoodsItem.getJSONObject("result").getString("leftConsumeAmount"));
BigDecimal amount=new BigDecimal(getLeftGoodsItem.getJSONObject("result").getString("leftConsumeAmount"));
//退货退款物品
JSONObject refundGoods=goodTools.refundGoods(quantity,refundAmount,true,voucherItemId,memberId,receivableAmount,amount,"1",new BigDecimal("0.00"),new BigDecimal("0.00"),"");
String refundOrderId1=refundGoods.getString("result");
//校验:
//校验1:获取B端订单详情:退单已完成状态
JSONObject getDetailResult_refund = orderTools.getDetail(refundOrderId1);
String state_refund = getDetailResult_refund.getJSONObject("result").getString("state");
Assert.assertEquals(state_refund, "PAID", "B端退货退款成功后退单订单状态变为已完成");
//校验2:商品详情库存数+1
JSONObject refundAfterGetDetail_goods = goodTools.getDetail_goods(goodsId1);
int refundAfterInventory = Integer.parseInt(refundAfterGetDetail_goods.getJSONObject("result").getJSONObject("multiSpecInfo").getJSONArray("specCombinationList").getJSONObject(0).getString("inventory"));
Assert.assertEquals(refundAfterInventory,refundBeforeInventory+1,"退货退款成功后,库存数应+1");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验3:数据中心-财务中心-营收明细-物品的确认收入应减少
JSONObject refundAfterGetCostData_type = financeDataTools.getCostData_type("DAY", "GOODS", TimeUtils.getTodayTime(), TimeUtils.getTodayEndTime());
BigDecimal refundAfterConfirmedAmount = new BigDecimal(refundAfterGetCostData_type.getJSONObject("result").getString("confirmedAmount"));//确认收入
Assert.assertEquals(refundAfterConfirmedAmount,refundBeforeConfirmedAmount.subtract(refundAmount.setScale(2, RoundingMode.HALF_UP)),"退货退款成功后,数据中心-财务中心-营收明细-物品的确认收入应减少对应的金额");
//case3:作废退货退款订单
JSONObject discardRefundOrder=orderTools.discard(refundOrderId1, "重复录入", "已作废物品退货退款订单" + RandomStringUtil.randomString(10));
//校验:
//校验1:获取B端订单详情:退单已作废状态
JSONObject getDetailResult_discardRefund = orderTools.getDetail(refundOrderId1);
String state_discardRefund = getDetailResult_discardRefund.getJSONObject("result").getString("state");
Assert.assertEquals(state_discardRefund, "DISCARD", "B端作废退货退款订单后,订单状态由已完成变为已作废");
//校验2:商品详情库存数-1
JSONObject discardRefundAfterGetDetail_goods = goodTools.getDetail_goods(goodsId1);
int discardRefundAfterInventory = Integer.parseInt(discardRefundAfterGetDetail_goods.getJSONObject("result").getJSONObject("multiSpecInfo").getJSONArray("specCombinationList").getJSONObject(0).getString("inventory"));
Assert.assertEquals(discardRefundAfterInventory,refundAfterInventory-1,"作废退货退款订单成功后,库存数应-1");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验3:数据中心-财务中心-营收明细-物品的确认收入应增加
JSONObject discardRefundAfterGetCostData_type = financeDataTools.getCostData_type("DAY", "GOODS", TimeUtils.getTodayTime(), TimeUtils.getTodayEndTime());
BigDecimal discardRefundAfterConfirmedAmount = new BigDecimal(discardRefundAfterGetCostData_type.getJSONObject("result").getString("confirmedAmount"));//确认收入
Assert.assertEquals(discardRefundAfterConfirmedAmount,refundAfterConfirmedAmount.add(refundAmount.setScale(2, RoundingMode.HALF_UP)),"作废退货退款订单成功后,数据中心-财务中心-营收明细-物品的确认收入应增加对应的金额");
//case4:仅退款物品
//拉取这个会员的物品列表
JSONObject listLeftGoodsItem_onlyAmount=goodTools.listLeftGoodsItem(memberId);
String refundId_onlyAmount=listLeftGoodsItem_onlyAmount.getJSONArray("result").getJSONObject(0).getString("id");
//B端退单时获取订单可退物品(退单界面)
JSONObject getLeftGoodsItem_onlyAmount=goodTools.getLeftGoodsItem(refundId_onlyAmount);
int quantity_onlyAmount=Integer.parseInt(getLeftGoodsItem.getJSONObject("result").getString("leftQuantity"));
BigDecimal refundAmount_onlyAmount=new BigDecimal(getLeftGoodsItem_onlyAmount.getJSONObject("result").getString("leftConsumeAmount"));
String voucherItemId_onlyAmount=getLeftGoodsItem_onlyAmount.getJSONObject("result").getString("id");
BigDecimal receivableAmount_onlyAmount=new BigDecimal(getLeftGoodsItem_onlyAmount.getJSONObject("result").getString("leftConsumeAmount"));
BigDecimal amount_onlyAmount=new BigDecimal(getLeftGoodsItem_onlyAmount.getJSONObject("result").getString("leftConsumeAmount"));
//仅退款物品
JSONObject refundGoods_onlyAmount=goodTools.refundGoods(quantity_onlyAmount,refundAmount_onlyAmount,false,voucherItemId_onlyAmount,memberId,receivableAmount_onlyAmount,amount_onlyAmount,"1",new BigDecimal("0.00"),new BigDecimal("0.00"),"");
String refundOrderId2_onlyAmount=refundGoods_onlyAmount.getString("result");
//校验:
//校验1:获取B端订单详情:退单已完成状态
JSONObject getDetailResult_refund_onlyAmount = orderTools.getDetail(refundOrderId2_onlyAmount);
String state_refund_onlyAmount = getDetailResult_refund_onlyAmount.getJSONObject("result").getString("state");
Assert.assertEquals(state_refund_onlyAmount, "PAID", "B端退货退款成功后退单订单状态变为已完成");
//校验2:商品详情库存数不变
JSONObject refundAfterGetDetail_goods_onlyAmount = goodTools.getDetail_goods(goodsId1);
int refundAfterInventory_onlyAmount = Integer.parseInt(refundAfterGetDetail_goods_onlyAmount.getJSONObject("result").getJSONObject("multiSpecInfo").getJSONArray("specCombinationList").getJSONObject(0).getString("inventory"));
Assert.assertEquals(refundAfterInventory_onlyAmount,discardRefundAfterInventory,"仅退款成功后,库存数应不变");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验3:数据中心-财务中心-营收明细-物品的确认收入应减少
JSONObject refundAfterGetCostData_type_onlyAmount = financeDataTools.getCostData_type("DAY", "GOODS", TimeUtils.getTodayTime(), TimeUtils.getTodayEndTime());
BigDecimal refundAfterConfirmedAmount_onlyAmount = new BigDecimal(refundAfterGetCostData_type_onlyAmount.getJSONObject("result").getString("confirmedAmount"));//确认收入
Assert.assertEquals(refundAfterConfirmedAmount_onlyAmount,discardRefundAfterConfirmedAmount.subtract(refundAmount_onlyAmount.setScale(2, RoundingMode.HALF_UP)),"仅退款成功后,数据中心-财务中心-营收明细-物品的确认收入应减少对应的金额");
//case5:作废仅退款订单
JSONObject discardRefundOrder_onlyAmount=orderTools.discard(refundOrderId2_onlyAmount, "重复录入", "已作废物品仅退款订单" + RandomStringUtil.randomString(10));
//校验:
//校验1:获取B端订单详情:退单已作废状态
JSONObject getDetailResult_discardRefund_onlyAmount = orderTools.getDetail(refundOrderId2_onlyAmount);
String state_discardRefund_onlyAmount = getDetailResult_discardRefund_onlyAmount.getJSONObject("result").getString("state");
Assert.assertEquals(state_discardRefund_onlyAmount, "DISCARD", "B端作废仅退款订单后,订单状态由已完成变为已作废");
//校验2:商品详情库存数不变
JSONObject discardRefundAfterGetDetail_goods_onlyAmount = goodTools.getDetail_goods(goodsId1);
int discardRefundAfterInventory_onlyAmount = Integer.parseInt(discardRefundAfterGetDetail_goods_onlyAmount.getJSONObject("result").getJSONObject("multiSpecInfo").getJSONArray("specCombinationList").getJSONObject(0).getString("inventory"));
Assert.assertEquals(discardRefundAfterInventory_onlyAmount,refundAfterInventory_onlyAmount,"作废仅退款订单成功后,库存数应不变");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验3:数据中心-财务中心-营收明细-物品的确认收入应增加
JSONObject discardRefundAfterGetCostData_type_onlyAmount = financeDataTools.getCostData_type("DAY", "GOODS", TimeUtils.getTodayTime(), TimeUtils.getTodayEndTime());
BigDecimal discardRefundAfterConfirmedAmount_onlyAmount = new BigDecimal(discardRefundAfterGetCostData_type_onlyAmount.getJSONObject("result").getString("confirmedAmount"));//确认收入
Assert.assertEquals(discardRefundAfterConfirmedAmount_onlyAmount,refundAfterConfirmedAmount_onlyAmount.add(refundAmount_onlyAmount.setScale(2, RoundingMode.HALF_UP)),"作废仅退款订单成功后,数据中心-财务中心-营收明细-物品的确认收入应增加对应的金额");
//case6:作废购买订单
JSONObject discardSignOrder=orderTools.discard(signOrderId1, "重复录入", "已作废物品购买订单" + RandomStringUtil.randomString(10));
//校验:
//校验1:获取B端订单详情:购买订单已作废状态
JSONObject getDetailResult_discardSign = orderTools.getDetail(signOrderId1);
String state_discardRefund_discardSign = getDetailResult_discardSign.getJSONObject("result").getString("state");
Assert.assertEquals(state_discardRefund_discardSign, "DISCARD", "B端作废购买订单后,签单订单状态由已完成变为已作废");
//校验2:商品详情库存数+1
JSONObject discardSignAfterGetDetail_goods = goodTools.getDetail_goods(goodsId1);
int discardSignAfterInventory = Integer.parseInt(discardSignAfterGetDetail_goods.getJSONObject("result").getJSONObject("multiSpecInfo").getJSONArray("specCombinationList").getJSONObject(0).getString("inventory"));
Assert.assertEquals(discardSignAfterInventory,discardRefundAfterInventory_onlyAmount+1,"作废购买订单成功后,库存数应+1");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//校验3:数据中心-财务中心-营收明细-物品的确认收入应减少
JSONObject discardSignAfterGetCostData_type = financeDataTools.getCostData_type("DAY", "GOODS", TimeUtils.getTodayTime(), TimeUtils.getTodayEndTime());
BigDecimal discardSignAfterConfirmedAmount = new BigDecimal(discardSignAfterGetCostData_type.getJSONObject("result").getString("confirmedAmount"));//确认收入
Assert.assertEquals(discardSignAfterConfirmedAmount,discardRefundAfterConfirmedAmount_onlyAmount.subtract(unpaidAmount.setScale(2, RoundingMode.HALF_UP)),"作废购买订单成功后,数据中心-财务中心-营收明细-物品的确认收入应减少对应的金额");
}
}
}
package com.xiaomai.cases.polar.goods.Tools;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xiaomai.client.DataUserInfo;
import com.xiaomai.enums.ApiModule;
import com.xiaomai.enums.RequestType;
import com.xiaomai.enums.Terminal;
import com.xiaomai.utils.RandomStringUtil;
import com.xiaomai.utils.TimeUtils;
import com.xiaomai.utils.XMBaseTest;
import java.math.BigDecimal;
public class GoodTools extends XMBaseTest {
//
// /**
// * @param
// * @description:新建物品
// * @param multiSpec:是否是多规格;true:多规格;false:单规格
// * @author: yff
// **/
//
// public JSONObject testCreateGoods(boolean multiSpec,DataUserInfo...userInfos) {
// dataApi.setApiModule(ApiModule.Polar_Goods)
// .setApiName("API_createGoods")
// .setTerminal(Terminal.B);
//
// super.beforeDataRequest(userInfos);
//
// String color1 = "黑色";
// String color2 = "白色";
// String size1 = "大的";
// String size2 = "小的";
// String skin1 = "貂蝉";
// String skin2 = "王昭君";
//
// JSONObject jsonObject = new JSONObject();
//
// //多规格
// if (multiSpec==true) {
//
// //商品介绍不为空,纯文本的写法
// JSONObject description = new JSONObject();
// JSONArray items = new JSONArray();
// JSONObject item1 = new JSONObject();
// item1.put("type", "TEXT");
// item1.put("content", "自动化创建的多规格三个规格,每个规格都有两个规格值");
// item1.put("aspect", "");
//
// items.add(item1);
//
// description.put("items", items);
// jsonObject.put("description", description.toString());
//
//
// jsonObject.put("groupId", "1873903328974499841");
// jsonObject.put("multiSpec", true);
// jsonObject.put("name", "自动化创建三个规格" + RandomStringUtil.randomString(2));
// jsonObject.put("xcxSaleState", "YES");
//
//
// JSONObject multiSpecInfo = new JSONObject();
//
// //设置三个规格和每个都有两个规格值
// JSONArray specList = new JSONArray();
// JSONObject specList1 = new JSONObject();
// specList1.put("name", "颜色");
//
// JSONArray specList1SpecValues = new JSONArray();
// JSONObject specList1SpecValues1 = new JSONObject();
// specList1SpecValues1.put("name", color1);
// JSONObject specList1SpecValues2 = new JSONObject();
// specList1SpecValues2.put("name", color2);
// specList1SpecValues.add(specList1SpecValues1);
// specList1SpecValues.add(specList1SpecValues2);
// specList1.put("specValues", specList1SpecValues);
//
// JSONObject specList2 = new JSONObject();
// specList2.put("name", "尺码");
//
// JSONArray specList2SpecValues = new JSONArray();
// JSONObject specList2SpecValues1 = new JSONObject();
// specList2SpecValues1.put("name", size1);
// JSONObject specList2SpecValues2 = new JSONObject();
// specList2SpecValues2.put("name", size2);
// specList2SpecValues.add(specList2SpecValues1);
// specList2SpecValues.add(specList2SpecValues2);
// specList2.put("specValues", specList2SpecValues);
//
//
// JSONObject specList3 = new JSONObject();
// specList3.put("name", "限定皮肤");
//
// JSONArray specList3SpecValues = new JSONArray();
// JSONObject specList3SpecValues1 = new JSONObject();
// specList3SpecValues1.put("name", skin1);
// JSONObject specList3SpecValues2 = new JSONObject();
// specList3SpecValues2.put("name", skin2);
// specList3SpecValues.add(specList3SpecValues1);
// specList3SpecValues.add(specList3SpecValues2);
// specList3.put("specValues", specList3SpecValues);
//
// specList.add(specList1);
// specList.add(specList2);
// specList.add(specList3);
//
// multiSpecInfo.put("specList", specList);
//
//
// try {
// Thread.sleep(3000);
// } catch (InterruptedException e) {
// throw new RuntimeException(e);
// }
//
// //排列出来的组合2*2*2
// JSONArray specCombinationList = new JSONArray();
//
// JSONObject specCombinationList1 = new JSONObject();
//
// JSONArray specCombinationList1Specs = new JSONArray();
// specCombinationList1Specs.add(color1);
// specCombinationList1Specs.add(size1);
// specCombinationList1Specs.add(skin1);
// specCombinationList1.put("specs", specCombinationList1Specs);
// specCombinationList1.put("price", "0.01");
// specCombinationList1.put("inventory", 10);
//
// specCombinationList.add(specCombinationList1);
//
// JSONObject specCombinationList2 = new JSONObject();
// JSONArray specCombinationList2Specs = new JSONArray();
// specCombinationList2Specs.add(color1);
// specCombinationList2Specs.add(size1);
// specCombinationList2Specs.add(skin2);
// specCombinationList2.put("specs", specCombinationList2Specs);
// specCombinationList2.put("price", "0.01");
// specCombinationList2.put("inventory", 10);
//
// specCombinationList.add(specCombinationList2);
//
//
// JSONObject specCombinationList3 = new JSONObject();
// JSONArray specCombinationList3Specs = new JSONArray();
// specCombinationList3Specs.add(color1);
// specCombinationList3Specs.add(size2);
// specCombinationList3Specs.add(skin1);
// specCombinationList3.put("specs", specCombinationList3Specs);
// specCombinationList3.put("price", "0.01");
// specCombinationList3.put("inventory", 10);
//
// specCombinationList.add(specCombinationList3);
//
//
// JSONObject specCombinationList4 = new JSONObject();
// JSONArray specCombinationList4Specs = new JSONArray();
// specCombinationList4Specs.add(color1);
// specCombinationList4Specs.add(size2);
// specCombinationList4Specs.add(skin2);
// specCombinationList4.put("specs", specCombinationList4Specs);
// specCombinationList4.put("price", "0.01");
// specCombinationList4.put("inventory", 10);
//
// specCombinationList.add(specCombinationList4);
//
//
// JSONObject specCombinationList5 = new JSONObject();
// JSONArray specCombinationList5Specs = new JSONArray();
// specCombinationList5Specs.add(color2);
// specCombinationList5Specs.add(size1);
// specCombinationList5Specs.add(skin1);
// specCombinationList5.put("specs", specCombinationList5Specs);
// specCombinationList5.put("price", "0.01");
// specCombinationList5.put("inventory", 10);
//
// specCombinationList.add(specCombinationList5);
//
//
// JSONObject specCombinationList6 = new JSONObject();
// JSONArray specCombinationList6Specs = new JSONArray();
// specCombinationList6Specs.add(color2);
// specCombinationList6Specs.add(size1);
// specCombinationList6Specs.add(skin2);
// specCombinationList6.put("specs", specCombinationList6Specs);
// specCombinationList6.put("price", "0.01");
// specCombinationList6.put("inventory", 10);
//
// specCombinationList.add(specCombinationList6);
//
// JSONObject specCombinationList7 = new JSONObject();
// JSONArray specCombinationList7Specs = new JSONArray();
// specCombinationList7Specs.add(color2);
// specCombinationList7Specs.add(size2);
// specCombinationList7Specs.add(skin1);
// specCombinationList7.put("specs", specCombinationList7Specs);
// specCombinationList7.put("price", "0.01");
// specCombinationList7.put("inventory", 10);
//
// specCombinationList.add(specCombinationList7);
//
//
// JSONObject specCombinationList8 = new JSONObject();
// JSONArray specCombinationList8Specs = new JSONArray();
// specCombinationList8Specs.add(color2);
// specCombinationList8Specs.add(size2);
// specCombinationList8Specs.add(skin2);
// specCombinationList8.put("specs", specCombinationList8Specs);
// specCombinationList8.put("price", "0.01");
// specCombinationList8.put("inventory", 10);
//
// specCombinationList.add(specCombinationList8);
//
// multiSpecInfo.put("specCombinationList", specCombinationList);
// jsonObject.put("multiSpecInfo", multiSpecInfo);
// jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
// jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
// jsonObject.put("operatorId", dataApi.getLoginInfo().getAdminId());
// }
//
// //单规格
// else if (multiSpec==false){
//
// //商品介绍不为空,纯文本的写法
// JSONObject description = new JSONObject();
// JSONArray items = new JSONArray();
// JSONObject item1 = new JSONObject();
// item1.put("type", "TEXT");
// item1.put("content", "自动化创建的");
// item1.put("aspect", "");
//
// items.add(item1);
//
// description.put("items", items);
// jsonObject.put("description", description.toString());
//
// jsonObject.put("groupId", "1873903328974499841");
// jsonObject.put("multiSpec", false);
// jsonObject.put("name", "自动化创建单规格" + RandomStringUtil.randomString(2));
// jsonObject.put("xcxSaleState", "YES");
// JSONObject jsonObject2 = new JSONObject();
//
// jsonObject2.put("inventory", "10");
// jsonObject2.put("price", "0.01");
//
// jsonObject.put("singleSpecInfo", jsonObject2);
// jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
// jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
// jsonObject.put("operatorId", dataApi.getLoginInfo().getAdminId());
//
// }
//
// dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
// return dataApi.getBodyInJSON();
//
// }
/**
* @param
* @description:新建物品_多规格(三个规格,每个规格都是三个规格值)
* @param xcxSaleState:是否开启小程序售卖 YES:开启 NO:关闭;
* @param price:每个规格值的售价
* @param inventory 库存
* @author: yff
**/
public JSONObject createGoods_multiple(String xcxSaleState, String price,int inventory,DataUserInfo...userInfos) {
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_createGoods")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
// 存量的分组:"id": "1873912725360504834","name": "自动化分组多规格",因为分组不能超过10个,所以很多地方用存量就够了
String color1 = "黑色";
String color2 = "白色";
String size1 = "大的";
String size2 = "小的";
String skin1 = "貂蝉";
String skin2 = "王昭君";
JSONObject jsonObject = new JSONObject();
//商品介绍不为空,纯文本的写法
JSONObject description = new JSONObject();
JSONArray items = new JSONArray();
JSONObject item1 = new JSONObject();
item1.put("type", "TEXT");
item1.put("content", "自动化创建的多规格三个规格,每个规格都有两个规格值");
item1.put("aspect", "");
items.add(item1);
description.put("items", items);
jsonObject.put("description", description.toString());
jsonObject.put("groupId", "1873912725360504834");
jsonObject.put("multiSpec", true);
jsonObject.put("name", "自动化创建三规格" + RandomStringUtil.randomString(6));
jsonObject.put("xcxSaleState",xcxSaleState);
JSONObject multiSpecInfo = new JSONObject();
//设置三个规格和每个都有两个规格值
JSONArray specList = new JSONArray();
JSONObject specList1 = new JSONObject();
specList1.put("name", "颜色");
JSONArray specList1SpecValues = new JSONArray();
JSONObject specList1SpecValues1 = new JSONObject();
specList1SpecValues1.put("name", color1);
JSONObject specList1SpecValues2 = new JSONObject();
specList1SpecValues2.put("name", color2);
specList1SpecValues.add(specList1SpecValues1);
specList1SpecValues.add(specList1SpecValues2);
specList1.put("specValues", specList1SpecValues);
JSONObject specList2 = new JSONObject();
specList2.put("name", "尺码");
JSONArray specList2SpecValues = new JSONArray();
JSONObject specList2SpecValues1 = new JSONObject();
specList2SpecValues1.put("name", size1);
JSONObject specList2SpecValues2 = new JSONObject();
specList2SpecValues2.put("name", size2);
specList2SpecValues.add(specList2SpecValues1);
specList2SpecValues.add(specList2SpecValues2);
specList2.put("specValues", specList2SpecValues);
JSONObject specList3 = new JSONObject();
specList3.put("name", "限定皮肤");
JSONArray specList3SpecValues = new JSONArray();
JSONObject specList3SpecValues1 = new JSONObject();
specList3SpecValues1.put("name", skin1);
JSONObject specList3SpecValues2 = new JSONObject();
specList3SpecValues2.put("name", skin2);
specList3SpecValues.add(specList3SpecValues1);
specList3SpecValues.add(specList3SpecValues2);
specList3.put("specValues", specList3SpecValues);
specList.add(specList1);
specList.add(specList2);
specList.add(specList3);
multiSpecInfo.put("specList", specList);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
//排列出来的组合2*2*2
JSONArray specCombinationList = new JSONArray();
JSONObject specCombinationList1 = new JSONObject();
JSONArray specCombinationList1Specs = new JSONArray();
specCombinationList1Specs.add(color1);
specCombinationList1Specs.add(size1);
specCombinationList1Specs.add(skin1);
specCombinationList1.put("specs", specCombinationList1Specs);
specCombinationList1.put("price", price);
specCombinationList1.put("inventory", inventory);
specCombinationList.add(specCombinationList1);
JSONObject specCombinationList2 = new JSONObject();
JSONArray specCombinationList2Specs = new JSONArray();
specCombinationList2Specs.add(color1);
specCombinationList2Specs.add(size1);
specCombinationList2Specs.add(skin2);
specCombinationList2.put("specs", specCombinationList2Specs);
specCombinationList2.put("price", price);
specCombinationList2.put("inventory", inventory);
specCombinationList.add(specCombinationList2);
JSONObject specCombinationList3 = new JSONObject();
JSONArray specCombinationList3Specs = new JSONArray();
specCombinationList3Specs.add(color1);
specCombinationList3Specs.add(size2);
specCombinationList3Specs.add(skin1);
specCombinationList3.put("specs", specCombinationList3Specs);
specCombinationList3.put("price", price);
specCombinationList3.put("inventory", inventory);
specCombinationList.add(specCombinationList3);
JSONObject specCombinationList4 = new JSONObject();
JSONArray specCombinationList4Specs = new JSONArray();
specCombinationList4Specs.add(color1);
specCombinationList4Specs.add(size2);
specCombinationList4Specs.add(skin2);
specCombinationList4.put("specs", specCombinationList4Specs);
specCombinationList4.put("price", price);
specCombinationList4.put("inventory", inventory);
specCombinationList.add(specCombinationList4);
JSONObject specCombinationList5 = new JSONObject();
JSONArray specCombinationList5Specs = new JSONArray();
specCombinationList5Specs.add(color2);
specCombinationList5Specs.add(size1);
specCombinationList5Specs.add(skin1);
specCombinationList5.put("specs", specCombinationList5Specs);
specCombinationList5.put("price", price);
specCombinationList5.put("inventory",inventory);
specCombinationList.add(specCombinationList5);
JSONObject specCombinationList6 = new JSONObject();
JSONArray specCombinationList6Specs = new JSONArray();
specCombinationList6Specs.add(color2);
specCombinationList6Specs.add(size1);
specCombinationList6Specs.add(skin2);
specCombinationList6.put("specs", specCombinationList6Specs);
specCombinationList6.put("price",price);
specCombinationList6.put("inventory",inventory);
specCombinationList.add(specCombinationList6);
JSONObject specCombinationList7 = new JSONObject();
JSONArray specCombinationList7Specs = new JSONArray();
specCombinationList7Specs.add(color2);
specCombinationList7Specs.add(size2);
specCombinationList7Specs.add(skin1);
specCombinationList7.put("specs", specCombinationList7Specs);
specCombinationList7.put("price", price);
specCombinationList7.put("inventory", inventory);
specCombinationList.add(specCombinationList7);
JSONObject specCombinationList8 = new JSONObject();
JSONArray specCombinationList8Specs = new JSONArray();
specCombinationList8Specs.add(color2);
specCombinationList8Specs.add(size2);
specCombinationList8Specs.add(skin2);
specCombinationList8.put("specs", specCombinationList8Specs);
specCombinationList8.put("price", price);
specCombinationList8.put("inventory", inventory);
specCombinationList.add(specCombinationList8);
multiSpecInfo.put("specCombinationList", specCombinationList);
jsonObject.put("multiSpecInfo", multiSpecInfo);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId", dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:新建物品_单规格
* @param xcxSaleState:是否开启小程序售卖 YES:开启 NO:关闭
* @param price:每个规格值的售价
* @param inventory 库存
* @author: yff
**/
public JSONObject createGoods_single(String xcxSaleState, String price,int inventory,DataUserInfo...userInfos) {
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_createGoods")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
// 存量的分组: "id": "1873903328974499841","name": "自动化分组单规格",因为分组不能超过10个,所以很多地方用存量就够了
JSONObject jsonObject = new JSONObject();
//商品介绍不为空,纯文本的写法
JSONObject description = new JSONObject();
JSONArray items = new JSONArray();
JSONObject item1 = new JSONObject();
item1.put("type", "TEXT");
item1.put("content", "自动化创建的单规格");
item1.put("aspect", "");
items.add(item1);
description.put("items", items);
jsonObject.put("description", description.toString());
jsonObject.put("groupId", "1873903328974499841");
jsonObject.put("multiSpec", false);
jsonObject.put("name", "自动化创建单规格" + RandomStringUtil.randomString(6));
jsonObject.put("xcxSaleState",xcxSaleState);
JSONObject jsonObject2 = new JSONObject();
jsonObject2.put("inventory",inventory);
jsonObject2.put("price",price);
jsonObject.put("singleSpecInfo", jsonObject2);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId", dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:获取物品列表
* @author: yff
**/
public JSONObject studioGoods( String nameLike,DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_pageStudioGoods")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("current", 0);
jsonObject.put("size", 20);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:删除物品
* @author: yff
**/
public JSONObject deleteGoods(String id, DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_delete")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", id);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:新建物品的重名校验
* @param name:物品名称
* @author: yff
**/
public JSONObject checkRepeatNameForStudio(String name, DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_checkRepeatNameForStudio")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("name", name);
jsonObject.put("id","");
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:获取B端的物品详情
* @param id:物品ID
* @author: yff
**/
public JSONObject getDetail_goods(String id, DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_getDetail_goods")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("id",id);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:获取多规格物品的库存详情;注意仅多规格,单规格没有这个接口
* @param id:物品ID
* @author: yff
**/
public JSONObject listMultiSpecInventorRecords(String id, DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_listMultiSpecInventorRecords")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("id",id);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:新建分組
* @param name:分組名称
* @author: yff
**/
public JSONObject createGoodsGroup(String name, DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_createGoodsGroup")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("name",name);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:获取分组列表
* @author: yff
**/
public JSONObject listPageGoodsGroup( DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_listPageGoodsGroup")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:分组重名校验
* @author: yff
**/
public JSONObject checkNameRepeatGoodsGroup(String name, DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_checkNameRepeatGoodsGroup")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("name",name);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:删除分组
* @param id:分组ID
* @author: yff
**/
public JSONObject deleteGoodsGroup(String id, DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_deleteGoodsGroup")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("id",id);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:删除分组前是否存在物品的校验
* @param id:分组ID
* @author: yff
**/
public JSONObject checkAllowDelete(String id, DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_checkAllowDelete")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("id",id);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:编辑分组
* @param id:分组ID
* @param name:修改后的分组名称
* @author: yff
**/
public JSONObject modifyGoodsGroup(String id,String name, DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_modifyGoodsGroup")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("id",id);
jsonObject.put("name",name);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:新建物品时拉取物品分组
* @author: yff
**/
public JSONObject listGoodsGroup(DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_listGoodsGroup")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:批量修改物品的分组
* @param groupId:分组ID
* @param id:物品ID
* @author: yff
**/
public JSONObject batchModifyGoodsBelongGroup(String groupId,String id,DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_batchModifyGoodsBelongGroup")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("groupId",groupId);
JSONArray ids=new JSONArray();
ids.add(id);
jsonObject.put("ids",ids);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:B端修改物品的小程序售卖是否开启
* @param id:物品ID
* @param xcxSaleState:小程序是否开启 YES开启小程序售卖 NO关闭小程序售卖
* @author: yff
**/
public JSONObject modifyGoodsXcxSaleState(String id,String xcxSaleState,DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_modifyGoodsXcxSaleState")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("id",id);
jsonObject.put("xcxSaleState",xcxSaleState);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:B端修改物品状态是否为开启
* @param id:物品ID
* @param state:物品状态 YES启用 NO停用
* @author: yff
**/
public JSONObject modifyGoodsState(String id,String state,DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_modifyGoodsState")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("id",id);
jsonObject.put("state",state);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:查看物品的编辑记录
* @param goodsId:物品ID
* @author: yff
**/
public JSONObject pageGoodsModifyRecord(String goodsId,DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_pageGoodsModifyRecord")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("goodsId",goodsId);
jsonObject.put("current",0);
jsonObject.put("size",20);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:B端退单时拉取可退物品
* @param receiverId:会员ID
* @author: yff
**/
public JSONObject listLeftGoodsItem(String receiverId,DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_listLeftGoodsItem")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("receiverId",receiverId);
jsonObject.put("content","");
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:B端退单时获取订单可退物品(退单界面)
* @param id: 是listLeftGoodsItem拉取可退的物品列表接口中:"result":{ [{"id": "1874695209647783938",}]}
* @author: yff
**/
public JSONObject getLeftGoodsItem(String id,DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_getLeftGoodsItem")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject jsonObject = new JSONObject();
jsonObject.put("id",id);
jsonObject.put("brandId", dataApi.getLoginInfo().getBrandId());
jsonObject.put("studioId", dataApi.getLoginInfo().getStudioId());
jsonObject.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,jsonObject.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:B端退单物品
* @param quantity:退出数量
* @param refundAmount:退出金额
* @param refundInventory:退货退款:true 仅退款:false
* @param voucherItemId:是listLeftGoodsItem拉取可退的物品列表接口中:"result":{ [{"id": "1874695209647783938",}]}
* @param memberId:会员ID
* @param receivableAmount:应退金额
* @param amount:支付金额
* @param paymentWay:支付方式 1 2 ...
* @param depositRechargeAmount:退回储值卡充值金额 没有的话就是new BigDecimal("0.00")
* @param depositGiveAmount:退回储值卡赠送金额 没有的话就是new BigDecimal("0.00")
* @param depositCardId:退回储值卡 没有的话就是""
* @author: yff
**/
public JSONObject refundGoods(int quantity, BigDecimal refundAmount,boolean refundInventory,String voucherItemId,String memberId,BigDecimal receivableAmount,
BigDecimal amount,String paymentWay,BigDecimal depositRechargeAmount,BigDecimal depositGiveAmount,String depositCardId,DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_refundGoods")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject refundGoods=new JSONObject();
refundGoods.put("operationTime", TimeUtils.getTodayTime());
JSONObject goods=new JSONObject();
goods.put("quantity",quantity);
goods.put("refundAmount",refundAmount);
goods.put("refundInventory",refundInventory);
goods.put("voucherItemId",voucherItemId);
refundGoods.put("goods",goods);
refundGoods.put("objectId", RandomStringUtil.randomString(32));
refundGoods.put("studioId",xmAppApi.getLoginInfo().getStudioId());
refundGoods.put("memberId",memberId);
refundGoods.put("receivableAmount",receivableAmount);
refundGoods.put("operatorId",xmAppApi.getLoginInfo().getAdminId());
JSONArray paymentWays=new JSONArray();
JSONObject object=new JSONObject();
object.put("amount",amount);
object.put("paymentWay",paymentWay);
JSONArray voucherResourceIds=new JSONArray();
object.put("voucherResourceIds",voucherResourceIds);
paymentWays.add(object);
refundGoods.put("paymentWays",paymentWays);
refundGoods.put("brandId",xmAppApi.getLoginInfo().getBrandId());
refundGoods.put("depositRechargeAmount",depositRechargeAmount);
refundGoods.put("depositGiveAmount",depositGiveAmount);
refundGoods.put("depositCardId",depositCardId);
dataApi.doRequest(RequestType.JSON,dataparams,refundGoods.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
/**
* @param
* @description:获取规格名/规格值修改后的物品规格列表(这里是修改为1个规格,两个规格值)
* @param id:物品ID
* @param specListObjectId:第一个规格的规格ID
* @param specListObjectName:第一个规格的规格名称
* @param specValuesObject1Id:第一个规格值的规格值ID
* @param specValuesObject1Name:第一个规格值的规格值名称
* @param specValuesObject2Id:第二个规格值的规格值ID
* @param specValuesObject2Name:第二个规格值的规格值名称
* @author: yff
**/
public JSONObject listModifiedSpecCombinations(String id,String specListObjectId, String specListObjectName,String specValuesObject1Id,String specValuesObject1Name,
String specValuesObject2Id,String specValuesObject2Name,DataUserInfo...userInfos){
dataApi.setApiModule(ApiModule.Polar_Goods)
.setApiName("API_listModifiedSpecCombinations")
.setTerminal(Terminal.B);
super.beforeDataRequest(userInfos);
JSONObject listModifiedSpecCombinations=new JSONObject();
listModifiedSpecCombinations.put("id", id);
JSONArray specList=new JSONArray();
JSONObject specListObject=new JSONObject();
specListObject.put("id",specListObjectId);
specListObject.put("name",specListObjectName);
JSONArray specValues=new JSONArray();
JSONObject specValuesObject1=new JSONObject();
specValuesObject1.put("id",specValuesObject1Id);
specValuesObject1.put("name",specValuesObject1Name);
JSONObject specValuesObject2=new JSONObject();
specValuesObject2.put("id",specValuesObject2Id);
specValuesObject2.put("name",specValuesObject2Name);
specValues.add(specValuesObject1);
specValues.add(specValuesObject2);
specListObject.put("specValues",specValues);
specList.add(specListObject);
listModifiedSpecCombinations.put("specList",specList);
listModifiedSpecCombinations.put("brandId", dataApi.getLoginInfo().getBrandId());
listModifiedSpecCombinations.put("studioId", dataApi.getLoginInfo().getStudioId());
listModifiedSpecCombinations.put("operatorId",dataApi.getLoginInfo().getAdminId());
dataApi.doRequest(RequestType.JSON,dataparams,listModifiedSpecCombinations.toString(),dataheadrs).assetsSuccess(true);
return dataApi.getBodyInJSON();
}
}
......@@ -36,6 +36,8 @@ public class ApiModule {
public static String Polar_MemberEntry="polar_memberEntry";//入场
public static String Polar_Export="polar_export";//导出
public static String Polar_Goods="polar_goods";//物品
//小程序模块
......@@ -48,6 +50,9 @@ public class ApiModule {
public static String Lunar_Training="lunar_training";//训练
public static String Lunar_Share="lunar_share";//分享
public static String Lunar_VenueArea="lunar_venueArea";//场地
public static String Lunar_Goods="lunar_goods";//物品
public static String Lunar_Invitation = "lunar_invitation";
}
\ No newline at end of file
......@@ -20,5 +20,10 @@ public class LoginAccount {
public static String XYY_PROD = "xyy_prod";
public static String DZHT_PROD = "dzht_prod"; // 电子合同账户
public static String YFF_PROD="yff_prod";
public static String YFF_RC="yff_rc";
public static String YFF_GRAY="yff_gray";//芳芳场馆
}
Markdown is supported
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