package cn.momia.mapi.api.v1;

import cn.momia.mapi.web.response.ResponseMessage;
import cn.momia.api.deal.DealServiceApi;
import cn.momia.api.user.UserServiceApi;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/v1/order")
public class OrderV1Api extends AbstractV1Api {
    @RequestMapping(method = RequestMethod.POST)
    public ResponseMessage placeOrder(@RequestParam String utoken, @RequestParam String order) {
        if (StringUtils.isBlank(utoken) || StringUtils.isBlank(order)) return ResponseMessage.BAD_REQUEST;

        JSONObject orderJson = JSON.parseObject(order);
        orderJson.put("customerId", UserServiceApi.USER.get(utoken).getId());

        return ResponseMessage.SUCCESS(processOrder(DealServiceApi.ORDER.add(orderJson)));
    }

    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public ResponseMessage deleteOrder(@RequestParam String utoken, @RequestParam long id) {
        if (StringUtils.isBlank(utoken) || id <= 0) return ResponseMessage.BAD_REQUEST;

        DealServiceApi.ORDER.delete(utoken, id);

        return ResponseMessage.SUCCESS;
    }
}

@@ -738,35 +738,177 @@
 ken,
- @RequestParam String order
+%0A                                      @RequestParam String order,%0A                                      @RequestParam(required = false, defaultValue = %22%22) String invite
 ) %7B%0A
@@ -1071,16 +1071,16 @@
 order);%0A
-
         
@@ -1148,16 +1148,95 @@
 etId());
+%0A        if (!StringUtils.isBlank(invite)) orderJson.put(%22inviteCode%22, invite);
 %0A%0A      

order 添加邀请码