|
|
@@ -14,6 +14,9 @@ import common.utils.http.MyRet;
|
|
|
import modules.user.UserController;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
public class NfttController extends MyController {
|
|
|
@Inject
|
|
|
@@ -126,7 +129,7 @@ public class NfttController extends MyController {
|
|
|
System.out.println("Nftt Model 的内部数据 (for debug): " + nftt);
|
|
|
|
|
|
if (service.save(nftt)) {
|
|
|
- renderJson(MyRet.ok("创建成功").setData(service.findNfttById(nftt.getId())));
|
|
|
+ renderJson(MyRet.ok("创建成功").setData(service.findNfttById(nftt.getId().toString())));
|
|
|
} else {
|
|
|
renderJson(MyRet.fail("创建失败,原因未知,请将此日志提供给开发者" + nftt).setData(nftt));
|
|
|
}
|
|
|
@@ -139,4 +142,197 @@ public class NfttController extends MyController {
|
|
|
e.printStackTrace(); // 打印堆栈跟踪,便于调试
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新NFT模板的方法,传什么更新什么,不传就不更新,id必须传
|
|
|
+ */
|
|
|
+ @Before(LoginInterceptor.class)
|
|
|
+ @RequiredRoleInterface({UserController.ROLE_CHECK_ADMIN, UserController.ROLE_SUPER_ADMIN})
|
|
|
+ @EmptyInterface({"id"})
|
|
|
+ public void updateByAdmin() {
|
|
|
+ JSONObject requestBodyJson = MyController.getJsonModelByRequestAndType(getRequest(), JSONObject.class);
|
|
|
+ String id = requestBodyJson.getString("id");
|
|
|
+
|
|
|
+ Nftt nftt = service.findNfttById(id);
|
|
|
+
|
|
|
+ if (nftt == null) {
|
|
|
+ renderJson(MyRet.fail("nft模板获取不合法,该id对应的nftt不存在:" + id));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 名字
|
|
|
+ String name = requestBodyJson.getString("name");
|
|
|
+ if (StrKit.notBlank(name)) {
|
|
|
+ nftt.set("name", name);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 价格
|
|
|
+ try {
|
|
|
+ BigDecimal price = requestBodyJson.getBigDecimal("price");
|
|
|
+ if (price != null) {
|
|
|
+ // 可以添加额外的业务校验,例如 price 必须大于 0
|
|
|
+ if (price.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ renderJson(MyRet.fail("售价(price)不能为负数"));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ nftt.set("price", price);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ renderJson(MyRet.fail("你传入的 price 有些问题:" + e.getMessage()).setData(requestBodyJson));
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 预售开始时间
|
|
|
+ try {
|
|
|
+ Long presaleStartTime = requestBodyJson.getLong("presale_start_time");
|
|
|
+ if (presaleStartTime != null) {
|
|
|
+ // 业务校验:时间戳必须是正数或非负数
|
|
|
+ if (presaleStartTime <= 0) {
|
|
|
+ renderJson(MyRet.fail("预售开始时间(presale_start_time)必须是有效的Unix时间戳"));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ nftt.set("presale_start_time", presaleStartTime);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ renderJson(MyRet.fail("你传入的 presale_start_time 有些问题:" + e.getMessage()).setData(requestBodyJson));
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 预售结束时间
|
|
|
+ try {
|
|
|
+ Long presaleEndTime = requestBodyJson.getLong("presale_end_time");
|
|
|
+ if (presaleEndTime != null) {
|
|
|
+ if (presaleEndTime <= 0) {
|
|
|
+ renderJson(MyRet.fail("预售结束时间(presale_end_time)必须是有效的Unix时间戳"));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ nftt.set("presale_end_time", presaleEndTime);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ renderJson(MyRet.fail("你传入的 presale_end_time 有些问题:" + e.getMessage()).setData(requestBodyJson));
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 开始购买时间
|
|
|
+ try {
|
|
|
+ Long buyingStartTime = requestBodyJson.getLong("buying_start_time");
|
|
|
+ if (buyingStartTime != null) {
|
|
|
+ if (buyingStartTime <= 0) {
|
|
|
+ renderJson(MyRet.fail("开放购买时间(buying_start_time)必须是有效的Unix时间戳"));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ nftt.set("buying_start_time", buyingStartTime);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ renderJson(MyRet.fail("你传入的 buying_start_time 有些问题:" + e.getMessage()).setData(requestBodyJson));
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 已购入份数
|
|
|
+ try {
|
|
|
+ Integer purchasedQuantity = requestBodyJson.getInteger("purchased_quantity");
|
|
|
+ if (purchasedQuantity != null) {
|
|
|
+ if (purchasedQuantity <= 0) {
|
|
|
+ renderJson(MyRet.fail("已购入份数(purchased_quantity)必须是大于0的整数"));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ nftt.set("purchased_quantity", purchasedQuantity);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ renderJson(MyRet.fail("你传入的 purchased_quantity 有些问题:" + e.getMessage()).setData(requestBodyJson));
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 最大份数
|
|
|
+ try {
|
|
|
+ Integer maxQuantity = requestBodyJson.getInteger("max_quantity");
|
|
|
+ if (maxQuantity != null) {
|
|
|
+ if (maxQuantity <= 0) {
|
|
|
+ renderJson(MyRet.fail("最大份数(max_quantity)必须是大于0的整数"));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ nftt.set("max_quantity", maxQuantity);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ renderJson(MyRet.fail("你传入的 max_quantity 有些问题:" + e.getMessage()).setData(requestBodyJson));
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 作者修改
|
|
|
+ String author = requestBodyJson.getString("author");
|
|
|
+ if (StrKit.notBlank(author)) {
|
|
|
+ nftt.set("author", author);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 详情列表
|
|
|
+ JSONArray detailImageListArray = requestBodyJson.getJSONArray("detail_image_list");
|
|
|
+ if (detailImageListArray != null) {
|
|
|
+ nftt.set("detail_image_list", detailImageListArray.toJSONString());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 最后执行更新
|
|
|
+ if (nftt.update()) {
|
|
|
+ renderJson(MyRet.ok("更新成功").setData(nftt));
|
|
|
+ } else {
|
|
|
+ renderJson(MyRet.fail("更新失败,请将此日志复制给开发者" + nftt).setData(nftt));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Before(LoginInterceptor.class)
|
|
|
+ @RequiredRoleInterface({UserController.ROLE_CHECK_ADMIN, UserController.ROLE_SUPER_ADMIN})
|
|
|
+ @EmptyInterface({"page_size", "page_number"})
|
|
|
+ public void nftts() {
|
|
|
+ JSONObject requestBodyJson = MyController.getJsonModelByRequestAndType(getRequest(), JSONObject.class);
|
|
|
+
|
|
|
+ // 页面大小
|
|
|
+ String pageSizeStr = requestBodyJson.getString("page_size");
|
|
|
+ int pageSizeInt;
|
|
|
+ try {
|
|
|
+ pageSizeInt = Integer.parseInt(pageSizeStr);
|
|
|
+
|
|
|
+ if (pageSizeInt <= 0) {
|
|
|
+ renderJson(MyRet.fail("页面大小(page_size)期待是正整数,你传的是: " + pageSizeStr));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ renderJson(MyRet.fail("页面大小(page_size)格式不正确: " + e.getMessage()));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 页码
|
|
|
+ String pageNumberStr = requestBodyJson.getString("page_number");
|
|
|
+ int pageNumberInt;
|
|
|
+ try {
|
|
|
+ pageNumberInt = Integer.parseInt(pageNumberStr);
|
|
|
+
|
|
|
+ if (pageNumberInt <= 0) {
|
|
|
+ renderJson(MyRet.fail("页码(page_number)期待是正整数,你传的是: " + pageNumberStr));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ renderJson(MyRet.fail("页码(page_number)格式不正确: " + e.getMessage()));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 最终结果封装
|
|
|
+ List<Nftt> nftts = service.nftts(pageNumberInt, pageSizeInt);
|
|
|
+ Integer totalNftts = service.count();
|
|
|
+
|
|
|
+ Map<String, Object> response = new HashMap<>();
|
|
|
+ response.put("list", nftts);
|
|
|
+ response.put("total_row", nftts.toArray().length);
|
|
|
+ response.put("total_page", 1 + (nftts.toArray().length / pageSizeInt));
|
|
|
+ response.put("page_size", pageSizeInt);
|
|
|
+ response.put("page_number", pageNumberInt);
|
|
|
+ response.put("total_user_count", totalNftts);
|
|
|
+
|
|
|
+ renderJson(MyRet.ok("查询成功").setData(response));
|
|
|
+ }
|
|
|
}
|