package com.bjtdba.order.controller;

import com.bjtdba.order.service.OrderService;
import com.bjtdba.utils.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("order_service/orderService")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 1、以支付数量  带支付数量   待发货  已通过   待评价   以完成
     *
     * 2、实际支付金额
     *
     * 3、已退金额
     */
    @PostMapping("/getOrderStstusAmount")
     public Object orderStstusAmount(@RequestBody Map<String,String> map){
         return orderService.orderStstusAmount(map.get("mer_id"));
     }
    /**
     * 订单列表
     * 1、用户的订单列表
     * 2、商户的订单列表
     * 3、时间倒序
     * @param
     * @param
     * @param
     * @param
     * @param
     * 订单状态（0：待发货；1：待收货；2：待评价；3：已完成；4已申请退款；-1：已退款）5未支付
     * @return
     */
    @PostMapping("/orderList")
    public Object orderList(@RequestBody Map<String,String> map){
        return orderService.orderList(Integer.parseInt(map.get("pageNum")),Integer.parseInt(map.get("pageSize")),map.get("uid"),map.get("mer_id"),map.get("status"));

    }
    /**
     * 订单详情页面
     */
    /**
     *入参order_id
     * @param
     * @return
     */
    @PostMapping("/getOrderDetails")
    public Object orderDetails(@RequestBody Map<String,String> map){
        return orderService.getOrderDetails(map.get("order_id"));
    }

    /**
     * 逆向订单状态数量
     *
     * 状态 0:待审核 -1:审核未通过 1:待退货 2:待收货 3:已退款
     */
    @PostMapping("/getRefundOrderStstusAmount")
    public Object refundOrderStstusAmount(@RequestBody Map<String,String> map){
        return orderService.refundOrderStstusAmount(map.get("mer_id"));
    }

    /**
     * 人数   mer_id    and ctime  between #{start_time} and #{end_time}
     */
    @PostMapping("/onLineOrdeSun")
    public Object onLineOrdeSun(@RequestBody Map<String,String> map){
        return orderService.onLineOrdeSun(map.get("mer_id"),map.get("start_time"),map.get("end_time"));
    }

    /**
     * 通过商户id查询当前门店锁定的用户信息
     * @param map
     * @return
     */
    @PostMapping("/queryOrderUser")
    public  Object queryOrderUser(@RequestBody Map<String,Object> map ){
        int merId=Integer.parseInt(map.get("merId")+"");
        int pageNum=Integer.parseInt(map.get("pageNum")+"");
        int pageSize=Integer.parseInt(map.get("pageSize")+"");

        if(merId>0){
            return  orderService.queryMerchantUserOrder(merId,pageNum,pageSize);
        }else{
            return ResponseUtil.fail();
        }
    }

}
