|
|
@@ -1,11 +1,65 @@
|
|
|
package modules.order;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.jfinal.aop.Before;
|
|
|
import com.jfinal.aop.Inject;
|
|
|
+import com.jfinal.kit.StrKit;
|
|
|
+import common.interceptor.LoginInterceptor;
|
|
|
+import common.model.Nftt;
|
|
|
+import common.model.User;
|
|
|
import common.utils.http.MyController;
|
|
|
+import common.utils.http.MyRet;
|
|
|
+import modules.user.UserService;
|
|
|
|
|
|
public class OrderController extends MyController {
|
|
|
@Inject
|
|
|
private OrderService service;
|
|
|
+ @Inject
|
|
|
+ private UserService userService;
|
|
|
+
|
|
|
+ @Before(LoginInterceptor.class)
|
|
|
+ public void create() {
|
|
|
+ // --- 从 JSON 请求体中获取参数 ---
|
|
|
+ JSONObject requestBodyJson = MyController.getJsonModelByRequestAndType(getRequest(), JSONObject.class);
|
|
|
+ Integer nfttId;
|
|
|
+ // nfttId
|
|
|
+ try {
|
|
|
+ nfttId = requestBodyJson.getInteger("nftt_id");
|
|
|
+ } catch (Exception e) {
|
|
|
+ renderJson(MyRet.fail("你传入的 nftt_id 有些问题:" + e.getMessage()).setData(requestBodyJson));
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (nfttId == null) {
|
|
|
+ renderJson(MyRet.fail("id(nftt_id) 有问题"));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 先判断实名认证过没过
|
|
|
+ User user = userService.findUserByMobileNumber(this.<String>getSessionAttr("mobile_number"));
|
|
|
+ if (user == null || StrKit.isBlank(user.getHygWorkerId())) {
|
|
|
+ renderJson(MyRet.fail("请先进行实名认证"));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取nftt
|
|
|
+ Nftt nftt = Nftt.dao.findById(nfttId);
|
|
|
+ if (nftt == null) {
|
|
|
+ renderJson(MyRet.fail("nftt不存在"));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 过了之后判断当前是预售阶段还是正式开售阶段
|
|
|
+ // 判断是否到了预售阶段
|
|
|
+ long now = System.currentTimeMillis();
|
|
|
+ if (now < nftt.getPresaleStartTime()) {
|
|
|
+ renderJson(MyRet.fail("预售未开始,请勿非法请求!"));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int orderType = now > nftt.getBuyingStartTime() ? 1 : 0;
|
|
|
+ // 执行抢购操作
|
|
|
+ renderJson(service.create(nfttId.longValue(), user.getId(), orderType));
|
|
|
+ }
|
|
|
|
|
|
// 订单状态枚举 (建议定义在单独的类或枚举中)
|
|
|
public enum OrderStatus {
|