<?php

namespace app\common\model\unishop;

use think\Model;
use traits\model\SoftDelete;

class Product extends Model
{

    use SoftDelete;



    // 表名
    protected $name = 'unishop_product';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [

    ];

    /**
     * 计算订单商品总价
     * @param $goods_id  商品ID
     * @param $num  数量
     * @return int|mixed|string
     */
    public function computePrice($goods_id,$num){

        $price = self::where('id',$goods_id)->value('sales_price');

        return bcmul((string)$price,(string)$num,2);

    }

}
