package com.czg.controller.admin;

import com.czg.annotation.SaAdminCheckPermission;
import com.czg.market.entity.MkShareBase;
import com.czg.market.service.MkShareBaseService;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;


/**
 * 分享奖励基础
 *
 * @author ww
 */
@RestController
@RequestMapping("/admin/shareBase")
public class AShareBaseController {

    @Resource
    private MkShareBaseService mkShareBaseService;

    /**
     * 分享奖励基础
     */
    @GetMapping
    @SaAdminCheckPermission(parentName = "分享奖励基础", value = "share:config", name = "分享-配置")
    public CzgResult<MkShareBase> getShareBase() {
        return CzgResult.success(mkShareBaseService.getShareBase(StpKit.USER.getShopId()));
    }

    /**
     * 分享奖励基础:新增/修改
     */
    @PostMapping
    @SaAdminCheckPermission(parentName = "分享奖励基础", value = "share:up", name = "分享-新增/修改")
    public CzgResult<Boolean> editShareBase(@RequestBody MkShareBase shareBase) {
        shareBase.setShopId(StpKit.USER.getShopId());
        MkShareBase share = mkShareBaseService.getById(shareBase.getShopId());
        if (share == null) {
            return CzgResult.success(mkShareBaseService.save(shareBase));
        } else {
            shareBase.setCreateTime(share.getCreateTime());
            return CzgResult.success(mkShareBaseService.updateById(shareBase, false));
        }
    }
}