<?php
declare(strict_types=1);

namespace app\common\model;

use think\Model;

class CustomerSpec Extends Model
{
      const NORMAL = 1;
      const DELETE = 0;

      //customer
      public function customer()
      {
            return $this->hasOne(Customer::class,'id','customer_id');
      }

      //获取客户规格
      public static function getBoxId(int $customer_id, int $type_id, int $spec_id): object
      {
            return self::alias('a')
            ->leftjoin('stock_config b', 'a.box_id = b.id')
            ->leftjoin('stock_config c', 'a.type_id = c.id')
            ->where('a.customer_id', $customer_id)->where('a.type_id', $type_id)->where('a.product_id', $spec_id)
            ->field('a.price,b.id,b.title as box_name,c.title as variety_name')
            ->findOrEmpty();
      }
}
