package com.sqx.modules.shopping.controller.app;


import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.shopping.entity.SelfOrders;
import com.sqx.modules.shopping.service.OrdersService;
import com.sqx.modules.shopping.utils.Result;
import com.sqx.modules.shopping.utils.excel.ExcelData;
import com.sqx.modules.shopping.utils.excel.ExportExcelUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@RestController
@Api(value="自营商城订单",tags={"自营商城订单管理"})
@RequestMapping(value = "/app/orders")
public class AppOrdersController {
    @Autowired
    private OrdersService service;

    @Login
    @GetMapping("/list")
    @ApiOperation("后台管理列表")
    public Result findAll(Integer page, Integer size,
                          @ApiParam("订单号")@RequestParam(required = false) String orderNum,
                          @ApiParam("订单状态：1待付款 2已付款 3已发货 4已收货 5已取消 6退款中 7已退款 8拒绝退款")@RequestParam String status,
                          @ApiParam("商品名称")@RequestParam(required = false) String title,
                          String startTime, String endTime,
                          @ApiParam("手机号")@RequestParam(required = false) String mobile,String sendWay) {
        return service.findAll(page, size, orderNum, status, title, mobile,startTime,endTime,sendWay);
    }


    @Login
    @GetMapping("/findMyList")
    @ApiOperation("我的订单列表")
    public Result findMyList(Integer page, Integer size,
                             @ApiParam("用户id")@RequestParam String userId,
                             @ApiParam("订单状态：1待付款 2已付款 3已发货 4已收货 5已取消 6退款中 7已退款 8拒绝退款")@RequestParam String status) {
        return service.findMyList(page, size, userId, status);
    }


    @GetMapping("/find")
    @ApiOperation("查询")
    public Result findOne(Long id) {
        return service.findOne(id);
    }

    @Login
    @PostMapping("/save")
    @ApiOperation("保存订单")
    public Result saveBody(@RequestBody SelfOrders entity) {
        return service.saveBody(entity);
    }

    @Login
    @PostMapping("/update")
    @ApiOperation("修改")
    public Result updateBody(@RequestBody SelfOrders entity) {
        return service.updateBody(entity);
    }


    @Login
    @GetMapping("/delete")
    @ApiOperation("删除")
    public Result delete(Long id) {
        return service.delete(id);
    }

    @Login
    @ApiOperation(value="取消订单，orderStatus=1时可取消")
    @GetMapping("/cancel")
    public Result orderCancel(@ApiParam("id") @RequestParam Long id){
        return service.orderCancel(id);
    }

    @Login
    @ApiOperation(value="确认收货，orderStatus=3时收货")
    @GetMapping("/confirm")
    public Result orderConfirm(@ApiParam("id") @RequestParam Long id){
        return service.orderConfirm(id);
    }

    @Login
    @ApiOperation("零钱支付")
    @GetMapping("/changePay")
    public Result changePay(String ordersId){
        return service.changePay(ordersId);
    }

    @Login
    @ApiOperation("盛安豆支付")
    @GetMapping("/changeSadPay")
    public Result changeSadPay(String ordersId){
        return service.changeSadPay(ordersId);
    }

    @ApiOperation("检测是否完成支付")
    @GetMapping("/wxPay")
    public Result wxPayWeb(Long ordersId){
        return service.checkPay(ordersId);
    }

    @Login
    @ApiOperation("申请退款")
    @GetMapping("/refund")
    public Result refund(Long ordersId, String refund){
        return service.refund(ordersId, refund);
    }

    @Login
    @ApiOperation("用户端提醒发货")
    @GetMapping("/remind")
    public Result remind(Long ordersId){
        return service.remind(ordersId);
    }

    @Login
    @ApiOperation("用户端 订单统计")
    @GetMapping("/count")
    public Result count(@RequestAttribute Long userId){
        return service.count(userId);
    }

    @Login
    @ApiOperation("查快递")
    @GetMapping("/findExpress")
    public Result findExpress(String expressNumber){
        return service.findExpress(expressNumber);
    }
}
