package com.sqx.modules.datacentre.controller;

import com.sqx.common.utils.Result;
import com.sqx.modules.app.entity.RechargeRecord;
import com.sqx.modules.app.entity.UserEntity;
import com.sqx.modules.app.service.RechargeRecordService;
import com.sqx.modules.app.service.UserMoneyService;
import com.sqx.modules.coupon.service.TbCouponUserService;
import com.sqx.modules.datacentre.query.DataCenterQuery;
import com.sqx.modules.datacentre.query.ShopCenterQuery;
import com.sqx.modules.datacentre.service.DataCentreService;
import com.sqx.modules.errand.service.ErrandComplaintService;
import com.sqx.modules.integral.service.UserIntegralDetailsService;
import com.sqx.modules.order.service.AppOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.math.BigDecimal;

@RestController
@Api(value = "数据中心-管理端", tags = {"数据中心-管理端"})
@RequestMapping(value = "/admin/dataCentre")
public class DataCentreController {

    @Autowired
    private DataCentreService dataCentreService;
    @Autowired
    private AppOrderService appOrderService;
    @Autowired
    private TbCouponUserService tbCouponUserService;
    @Autowired
    private UserIntegralDetailsService userIntegralDetailsService;
    @Autowired
    private UserMoneyService userMoneyService;
    @Autowired
    private ErrandComplaintService errandComplaintService;
    @Autowired
    private RechargeRecordService rechargeRecordService;

    @ApiOperation("数据中心")
    @GetMapping(value = "/dataCentre")
    public Result dataCentre() {
        return dataCentreService.dataCentre();
    }

    @ApiOperation("任务分析")
    @GetMapping(value = "selectOrderData")
    public Result selectOrderData(DataCenterQuery query) {
        return dataCentreService.selectOrderData(query);
    }

    @ApiOperation("任务详情分析")
    @GetMapping(value = "/selectOrderAnalyze")
    public Result selectPayOrderAnalyze(DataCenterQuery query) {
        return dataCentreService.selectPayOrderAnalyze(query);
    }

    @ApiOperation("条件筛选所有用户")
    @GetMapping(value = "selectAllUser")
    public Result selectAllUser(Integer page, Integer limit, String userName, String phone) {
        return dataCentreService.selectAllUser(page, limit, userName, phone);
    }

    @ApiOperation("根据userId查询")
    @GetMapping(value = "selectUserById")
    public Result selectUserById(Long userId) {
        return dataCentreService.selectUserById(userId);
    }

    @ApiOperation("给用户账户修改余额")
    @GetMapping(value = "addUserMoney")
    public Result addUserMoney(Long userId, BigDecimal money, Integer type, String account, String remark) {
        return userMoneyService.addUserMoney(userId, money, type, account, remark);
    }

    //修改充值记录备注
    @ApiOperation("修改充值记录备注")
    @GetMapping(value = "updateRecordById")
    public Result updateRecordById(Integer id, String remark) {
        RechargeRecord rr = rechargeRecordService.selectRechargeRecordById(id);
        if (rr == null) {
            return Result.error("记录无效，备注添加失败");
        }
        rr.setRemark(remark);

        return rechargeRecordService.updateRechargeRecord(rr);
    }

    //分页数据
    @ApiOperation("充值记录分页数据")
    @GetMapping("getRecordList")
    public Result getRecordList(Integer page, Integer limit, String orderNo, String phone) {
        return rechargeRecordService.selectRechargeRecordList(page, limit, orderNo, phone);
    }

    @ApiOperation("修改用户保证金")
    @GetMapping(value = "updateCashDeposit")
    public Result updateCashDeposit(Long userId, BigDecimal money, Integer type) {
        return userMoneyService.updateCashDeposit(userId, money, type);
    }

    @ApiOperation("给骑手修改余额")
    @GetMapping(value = "updateUserBalance")
    public Result updateUserBalance(Long userId, BigDecimal money, Integer type) {
        return userMoneyService.updateUserBalance(userId, money, type);
    }


    @ApiOperation("查看该用户下单信息(下单数、下单金额)")
    @GetMapping(value = "selectOrderByUserId")
    public Result selectOrderByUserId(Long userId, String date, String dateType) {

        return appOrderService.selectOrderByUserId(userId, date, dateType);
    }

    @ApiOperation("查看该用户下单详情")
    @GetMapping(value = "selectOrderDetails")
    public Result selectOrderDetails(Integer page, Integer limit, Long userId) {

        return appOrderService.selectOrderDetails(page, limit, userId);
    }

    @ApiOperation("查看用户拥有的优惠券")
    @GetMapping(value = "selectCouponByUserId")
    public Result selectCouponByUserId(Integer page, Integer limit, Long userId, Integer status, String phone, String shopName, Long shopId, Integer shopFlag/*是否平台券 1是 2否 0 全部 */) {

        return tbCouponUserService.selectCouponByUserId(page, limit, userId, status, phone, shopName, shopId, shopFlag);
    }

    @ApiOperation("查看积分明细")
    @GetMapping(value = "/selectSignIn")
    public Result selectSignIn(Integer page, Integer limit, Long userId) {

        return userIntegralDetailsService.selectSignIn(page, limit, userId);
    }

    @ApiOperation("财务中心-充值统计")
    @GetMapping(value = "selectTopUpStatistics")
    public Result selectTopUpStatistics(String date, String dateType) {

        return dataCentreService.selectTopUpStatistics(date, dateType);
    }

    @ApiOperation("查看所有实名认证待审核用户")
    @GetMapping(value = "findAllCertification")
    public Result findAllCertification(Integer page, Integer limit, String userName, String phone, String checkCertification,Integer riderStationId) {
        return dataCentreService.findAllCertification(page, limit, userName, phone, checkCertification,riderStationId);
    }

    @ApiOperation("实名认证审核")
    @PostMapping("checkCertification")
    public Result checkCertification(Long userId, String checkCertification, String checkCertificationMessage) {

        return dataCentreService.checkCertification(userId, checkCertification, checkCertificationMessage);
    }

    @ApiOperation("查看用户实名认证信息")
    @GetMapping(value = "findCertification")
    public Result findCertification(Long userId) {

        return dataCentreService.findCertification(userId);
    }

    @ApiOperation("接单排行榜")
    @GetMapping(value = "rankingList")
    public Result rankingList(Integer page, Integer limit, String address, String date, String dateType,Integer riderStationId) {

        return dataCentreService.rankingList(page, limit, address, date, dateType,riderStationId);
    }

    @ApiOperation("门店统计")
    @GetMapping(value = "selectShopCenter")
    public Result selectShopCenter(@Valid ShopCenterQuery query) {

        return dataCentreService.selectShopCenter(query);
    }

    @ApiOperation("用户统计")
    @GetMapping(value = "selectUserCenter")
    public Result selectUserCenter(DataCenterQuery query) {

        return dataCentreService.selectUserCenter(query);
    }

    @GetMapping(value = "selectUserFeedback")
    @ApiOperation("查看意见反馈")
    public Result selectUserFeedback(String userEmail, Integer page, Integer limit) {

        return dataCentreService.selectUserFeedback(userEmail, page, limit);
    }

    @ApiOperation("获取该用户所有派单任务")
    @GetMapping(value = "findUserAddIndent")
    public Result findUserAddIndent(Long userId, Integer page, Integer limit) {

        return dataCentreService.findUserAddIndent(userId, page, limit);
    }

    @ApiOperation("获取该用户所有接单任务")
    @GetMapping(value = "findUserReceivingIndent")
    public Result findUserReceivingIndent(Long userId, Integer page, Integer limit) {

        return dataCentreService.findUserReceivingIndent(userId, page, limit);
    }

    @ApiOperation("查看充值明细")
    @GetMapping(value = "findTopUpMoney")
    public Result findTopUpMoney(Long userId, Integer page, Integer limit, String startTime, String endTime) {

        return dataCentreService.findTopUpMoney(userId, page, limit, startTime, endTime);
    }


    @ApiOperation("查看提现记录")
    @GetMapping(value = "findWithdrawMoney")
    public Result findWithdrawMoney(Long userId, Integer page, Integer limit) {

        return dataCentreService.findWithdrawMoney(userId, page, limit);
    }

    //查看全部骑手申诉（条件查询）
    @ApiOperation("查看全部骑手申诉")
    @GetMapping(value = "findAllAppeal")
    public Result findAllAppeal(Integer page, Integer limit, Long userId, Integer illegalId, Integer complaintState, String indentNumber) {

        return errandComplaintService.findAllAppeal(page, limit, userId, illegalId, complaintState, indentNumber);
    }

    @ApiOperation("同城跑腿收入统计")
    @GetMapping(value = "findplatformMoney")
    public Result findplatformMoney(String dateType, String date) {

        return dataCentreService.findplatformMoney(dateType, date);
    }

    @ApiOperation("外卖点餐收入统计")
    @GetMapping(value = "tcwmplatformMoney")
    private Result tcwmplatformMoney(String date, String dateType) {

        return dataCentreService.tcwmplatformMoney(date, dateType);
    }


    @ApiOperation("保证金管理")
    @GetMapping(value = "selectCashDeposit")
    public Result selectCashDeposit(String phone, Integer type, Integer page, Integer limit, Long userId) {

        return dataCentreService.selectCashDeposit(phone, type, page, limit, userId);
    }

   /* @ApiOperation("用户中心 用户列表")
    @GetMapping(value = "findAllUser")
    public Result findAllUser(Integer page, Integer limit, String phone, Integer userType, String platform, String nickName, String invitationCode){

        return dataCentreService.findAllUser(page, limit, phone, userType, platform, nickName, invitationCode);
    }*/

    @ApiOperation("查看反馈列表")
    @GetMapping(value = "selectFeedbackList")
    public Result selectFeedbackList(Integer page, Integer limit, Integer feedbackType) {

        return dataCentreService.selectFeedbackList(page, limit, feedbackType);
    }

    /*==========================================================*/

    @ApiOperation("管理端赠送用户会员")
    @PostMapping(value = "presenterVip")
    public Result presenterVip(Long userId) {

        return dataCentreService.presenterVip(userId);
    }


    @ApiOperation("编辑实名认证待审核用户")
    @PostMapping(value = "updateCertification")
    public Result updateCertification(@RequestBody UserEntity userEntity) {
        return dataCentreService.updateCertification(userEntity);
    }

}
