<?php
/**
 *
 * @author: xaboy<365615158@qq.com>
 * @day: 2017/11/11
 */

namespace app\admin\model\order;

use crmeb\traits\ModelTrait;
use crmeb\basic\BaseModel;

/**
 * 订单操作纪律model
 * Class StoreOrderStatus
 * @package app\admin\model\store
 */
class StoreOrderRefund extends BaseModel
{

    /**
     * 模型名称
     * @var string
     */
    use ModelTrait;
    public static function refund($data)
    {
        $info = self::where('order_id',$data['order_id'])->where('product_id',$data['product_id'])->find();
        if($info && bcadd($info['refund_num'],$data['refund_num'],3)>bcadd($data['cart_num'],0,3))
        {
            return self::setErrorInfo('退货数量，不能超过订单数量');
        }
        if($info)
        {
            self::where('id',$info['id'])->inc('refund_num',$data['refund_num'])->update();
        }
        else
        {
            self::create($data);
        }

    }

}