package com.pj.tb_order_after_sale;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.pj.current.dto.APPLoginUserInfo;
import com.pj.current.satoken.StpAPPUserUtil;
import com.pj.project4sp.SP;
import com.pj.tb_order.TbOrder;
import com.pj.tb_order.TbOrderMapper;
import com.pj.tb_order_after_sale.param.AfterSaleParam;
import com.pj.tb_order_after_sale.param.TbOrderAfterSaleParam;
import com.pj.utils.sg.AjaxJson;
import com.pj.utils.so.SoMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * Controller: tb_order_after_sale -- 售后申请表，并关联一级市场订单
 * @author qzy 
 */
@RestController
@RequestMapping("/app/TbOrderAfterSale/")
public class OrderAfterSaleAPPController {

	/** 底层 Service 对象 */
	@Autowired
	TbOrderAfterSaleService tbOrderAfterSaleService;



	/** 获取当前登陆人的订单号 */
	@RequestMapping("selectSelfOrders")
//		@SaCheckPermission(TbOrderAfterSale.PERMISSION_CODE)
	public AjaxJson selectSelfOrders() {
		SoMap so = SoMap.getRequestSoMap();
		List<TbOrder> list = tbOrderAfterSaleService.selectSelfOrders(so.startPage());
		return AjaxJson.getPageData(so.getDataCount(), list);
	}


	/** 发起售后 */
	@RequestMapping("afterSale")
//		@SaCheckPermission(TbOrderAfterSale.PERMISSION_CODE)
	public AjaxJson afterSale(@Validated @RequestBody AfterSaleParam afterSaleParam) {
		boolean afteredSale = tbOrderAfterSaleService.afterSale(afterSaleParam);
		if(afteredSale)return AjaxJson.getSuccess("售后发起成功!");
		return AjaxJson.getError("售后发起失败!");
	}

	/** 商户处理售后订单 */
	@RequestMapping("disposeOrders")
	public AjaxJson disposeOrders(@Validated @RequestBody TbOrderAfterSaleParam tbOrderAfterSaleParam){
		boolean b = tbOrderAfterSaleService.disposeOrders(tbOrderAfterSaleParam);
		if(!b)return AjaxJson.getError("处理售后结果失败!");
		return AjaxJson.getSuccess("处理售后结果成功!");
	}



	/** 查集合 - 根据条件（参数为空时代表忽略指定条件） */
	@RequestMapping("getAppList")
//		@SaCheckPermission(TbOrderAfterSale.PERMISSION_CODE)
	public AjaxJson getAppList(@RequestParam("afterSaleStatus") Integer afterSaleStatus,@RequestParam("keyword")String keyword) {
		SoMap so = SoMap.getRequestSoMap();
		List<TbOrderAfterSale> list = tbOrderAfterSaleService.getAppList(so.startPage(),afterSaleStatus,keyword);
		return AjaxJson.getPageData(so.getDataCount(), list);
	}









}
