package cn.ysk.cashier.mybatis.mapper;

import cn.ysk.cashier.pojo.order.TbFullOrderDetail;
import cn.ysk.cashier.pojo.order.TbOrderDetail;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

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

public interface TbOrderDetailMapper extends BaseMapper<TbOrderDetail> {

    /**
     * 更新购物车数量以及金额
     * @param id id
     * @param status 状态
     * @param changeNum 修改数量 正数增加 负数减少
     * @return 影响行数
     */
    @Update("update tb_order_detail set status=#{status}, price_amount=(num+#{changeNum})*price,num=num+#{changeNum} " +
            "where id=#{id}")
    int updateNumAmountStatus(Integer id, String status, BigDecimal changeNum);

    /**
     * 查询包含打包费和是否赠送的订单详情信息
     * @param orderId 订单id
     */
    @Select("select a.*, b.is_gift, b.is_pack from tb_order_detail as a left join tb_cashier_cart as b on a.cart_id=b.id where a.order_id=#{orderId}")
    List<TbFullOrderDetail> selectFullInfoByOrderId(Integer orderId);
}
