package com.sqx.modules.goods.controller;

import com.sqx.common.utils.Result;
import com.sqx.modules.goods.entity.GoodsShop;
import com.sqx.modules.goods.entity.GoodsShopRelevancy;
import com.sqx.modules.goods.service.GoodsShopService;
import com.sqx.modules.goods.vo.GoodsShopVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RestController
@Api(value="商户端-商铺",tags={"商户端-商铺"})
@RequestMapping(value = "/admin/goodsShop")
public class GoodsShopController {

    @Autowired
    private GoodsShopService goodsShopService;

    @ApiOperation("查看该商铺所有商品")
    @GetMapping(value = "/selectGoodsByShopId")
    public Result selectGoodsByShopId(Long shopId, Integer page, Integer limit, String goodsName, Integer classifyId, Integer status){

        return goodsShopService.selectGoodsByShopId(shopId, page, limit, goodsName, classifyId, status);
    }

    @ApiOperation("修改商铺上下线")
    @GetMapping("/updateGoodsShopPutawayFlag")
    public Result updateGoodsShopPutawayFlag(Long shopId,Integer putawayFlag){
        GoodsShop goodsShop = goodsShopService.getById(shopId);
        goodsShop.setPutawayFlag(putawayFlag);
        goodsShopService.updateById(goodsShop);
        return Result.success();
    }

    @ApiOperation("修改商铺佣金")
    @GetMapping("/updateGoodsShopRate")
    public Result updateGoodsShopRate(Long shopId, BigDecimal shopRate){
        GoodsShop goodsShop = goodsShopService.getById(shopId);
        goodsShop.setShopRate(shopRate);
        goodsShopService.updateById(goodsShop);
        return Result.success();
    }

    @ApiOperation("修改商铺排序")
    @GetMapping("/updateGoodsShopSort")
    public Result updateGoodsShopRate(Long shopId, Integer sort){
        GoodsShop goodsShop = goodsShopService.getById(shopId);
        goodsShop.setSort(sort);
        goodsShopService.updateById(goodsShop);
        return Result.success();
    }


    //查看该商铺所有未选择商品
    @ApiOperation("查看该商铺所有未选择商品")
    @GetMapping(value = "/selectGoodsByNotShopId")
    public Result selectGoodsByNotShopId(Long shopId, Integer page, Integer limit, String goodsName){

        return goodsShopService.selectGoodsByNotShopId(shopId, page, limit, goodsName);
    }

    @ApiOperation("批量添加商品到该商铺")
    @PostMapping(value = "/addGoodsByShopId")
    public Result addGoodsByShopId(@RequestBody List<GoodsShopRelevancy> goodsShopRelevancyList){
        if(goodsShopRelevancyList.size()<=0){
            return Result.error("请选择商品");
        }
        return goodsShopService.addGoodsByShopId(goodsShopRelevancyList);
    }

    @ApiOperation("修改该商铺商品信息（主要是库存）")
    @PostMapping(value = "updateGoodsByShopId")
    public Result updateGoodsByShopId(@RequestBody GoodsShopRelevancy goodsShopRelevancy){

        return goodsShopService.updateGoodsByShopId(goodsShopRelevancy);
    }

    @ApiOperation("删除该商铺的商品")
    @PostMapping(value = "/deleteGoodsByShopId")
    public Result deleteGoodsByShopId(Long shopId, Long goodsId){

        return goodsShopService.deleteGoodsByShopId(shopId, goodsId);
    }

    @ApiOperation("下架该商铺的商品")
    @PostMapping(value = "/soldOutOrPutaway")
    public Result soldOutOrPutaway(Long shopId, Long goodsId, Integer status){

        return goodsShopService.soldOutOrPutaway(shopId, goodsId, status);
    }

    @ApiOperation("统计门店收入")
    @GetMapping(value = "selectStoreData")
    public Result selectStoreData(Long shopId, String date, String dateType){

        return goodsShopService.selectStoreData(shopId, date, dateType);
    }

    @ApiOperation("统计门店订单详情")
    @GetMapping(value = "selectStoreMessage")
    public Result selectStoreMessage(Long shopId, String startTime, String endTime, Integer page, Integer limit, String orderNumber){

        return goodsShopService.selectStoreMessage(shopId, startTime, endTime, page, limit, orderNumber);
    }

    @ApiOperation("商户快捷入驻")
    @PostMapping("quickGoodsShop")
    public Result quickGoodsShop(@RequestBody GoodsShopVo goodsShopVo){
        return goodsShopService.quickGoodsShop(goodsShopVo);
    }

    @ApiOperation("查询商户")
    @GetMapping("/selectGoodsShop")
    public Result selectGoodsShop(String phone,String msg){
        return goodsShopService.selectGoodsShop(phone,msg);
    }

    @ApiOperation("修改商户信息")
    @PostMapping("/updateGoodsShop")
    public Result updateGoodsShop(@RequestBody GoodsShop goodsShop){
        goodsShop.setStatus(0);
        goodsShopService.updateById(goodsShop);
        return Result.success();
    }




}
