package com.fdkankan.ucenter.controller;


import com.fdkankan.common.util.JwtUtil;
import com.fdkankan.ucenter.common.BaseController;
import com.fdkankan.ucenter.common.Result;
import com.fdkankan.ucenter.service.IOrderService;
import com.fdkankan.ucenter.util.DateUserUtil;
import com.fdkankan.ucenter.vo.request.DownNumParam;
import com.fdkankan.ucenter.vo.request.OrderParam;
import com.fdkankan.ucenter.vo.request.PlaceOrderParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 订单
 *
 */
@RestController
@RequestMapping("/ucenter/user/order")
@Slf4j
public class OrderController extends BaseController {

    @Autowired
    IOrderService orderService;

    /**
     * 获取用户订单
     */
    @PostMapping("/list")
    public Result list(@RequestBody OrderParam param){
        param.setUserName(getUserName());
        return Result.success(orderService.pageList(param));
    }

    /**
     * 取消订单
     */
    @PostMapping("/cancel")
    public Result cancel(@RequestBody OrderParam param){
        orderService.cancel(param.getOrderId());
        return Result.success();
    }

    /**
     * 确认收货
     */
    @PostMapping("/receipt")
    public Result receipt(@RequestBody OrderParam param){
        orderService.receipt(param.getOrderId());
        return Result.success();
    }

    /**
     * 确认订单
     */
    @PostMapping("/placeOrder")
    public Result placeOrder(@RequestBody PlaceOrderParam param){
        param.setLang(getLang());
        param.setUserName(getUserName());
        return Result.success(orderService.placeOrder(param));
    }

    /**
     * 交易查询 (轮询)
     */
    @PostMapping("/queryOrderStatus")
    public Result queryOrderStatus(@RequestBody OrderParam param) throws Exception {
        return Result.success(orderService.queryOrderStatus(param));
    }

    /**
     * 获取增值权益或场景下载价格
     */
    @PostMapping("/getIncrementOrDownloadPrice")
    public Result getIncrementOrDownloadPrice(@RequestBody OrderParam param){
        param.setUserName(getUserName());
        return Result.success(orderService.getIncrementOrDownloadPrice(param));
    }

    /**
     * 下载场景提交订单
     */
    @PostMapping("/downloadOrder")
    public Result downloadOrder(@RequestBody DownNumParam param){
        param.setUserName(getUserName());
        param.setTimeZoneOff(getTimeZone());
        param.setAgentKey(getAgentKey());
        return Result.success(orderService.downloadOrder(param));
    }

    /**
     * 增值权益提交订单
     */
    @PostMapping("/incrementOrder")
    public Result incrementOrder(@RequestBody DownNumParam param){
        param.setUserName(getUserName());
        param.setTimeZoneOff(getTimeZone());
        param.setAgentKey(getAgentKey());
        return Result.success(orderService.incrementOrder(param));
    }

}

