121 lines
3.7 KiB
PHP
121 lines
3.7 KiB
PHP
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\common\model\store\product;
|
|
|
|
use app\common\model\BaseModel;
|
|
use think\facade\Log;
|
|
|
|
class ProductAttrValue extends BaseModel
|
|
{
|
|
|
|
|
|
/**
|
|
* @Author:Qinii
|
|
* @Date: 2020/5/8
|
|
* @return string
|
|
*/
|
|
public static function tablePk(): string
|
|
{
|
|
return 'value_id';
|
|
}
|
|
|
|
|
|
/**
|
|
* @Author:Qinii
|
|
* @Date: 2020/5/8
|
|
* @return string
|
|
*/
|
|
public static function tableName(): string
|
|
{
|
|
return 'store_product_attr_value';
|
|
}
|
|
|
|
public function getDetailAttr($value)
|
|
{
|
|
return json_decode($value);
|
|
}
|
|
|
|
public function product()
|
|
{
|
|
return $this->hasOne(Product::class, 'product_id','product_id');
|
|
}
|
|
|
|
public function getSvipPriceAttr()
|
|
{
|
|
if (isset($this->product->product_type) && $this->product->product_type == 0 && $this->product->show_svip_price && $this->product->svip_price_type == 1) {
|
|
$rate = merchantConfig($this->product->mer_id,'svip_store_rate');
|
|
$svip_store_rate = $rate > 0 ? bcdiv($rate,100,2) : 0;
|
|
return bcmul($this->price, $svip_store_rate,2);
|
|
}
|
|
return $this->getData('svip_price');
|
|
}
|
|
|
|
public function getIsSvipPriceAttr()
|
|
{
|
|
if (isset($this->product->product_type) && $this->product->product_type == 0 && $this->product->svip_price_type == 1) {
|
|
$rate = merchantConfig($this->product->mer_id, 'svip_store_rate');
|
|
$svip_store_rate = $rate > 0 ? bcdiv($rate, 100, 2) : 0;
|
|
return bcmul($this->price, $svip_store_rate, 2);
|
|
}
|
|
return '未设置';
|
|
}
|
|
|
|
// 计算一级佣金
|
|
public function getBcExtensionOneAttr(){
|
|
$merId = (int)$this->product->mer_id;
|
|
// 判断:平台和商户是否开启分销
|
|
if(!intval(systemConfig('extension_status')) && !intval(merchantConfig((int)$merId,'extension_status'))) return 0;
|
|
// 商品设置固定金额 直接返回固定金额
|
|
if($this->product->extension_type == 1) return $this->extension_one;
|
|
// 计算佣金
|
|
$oneRate = (float)systemConfig('extension_one_rate');// 平台比例
|
|
$merOneRate = (float)merchantConfig((int)$merId,'extension_one_rate');// 商家比例
|
|
$rate = $merOneRate > 0 ? $merOneRate : $oneRate;
|
|
|
|
return floatval(round(bcmul($rate, isset($this->org_price) ? $this->org_price : $this->price, 3),2));
|
|
}
|
|
// 计算二级佣金
|
|
public function getBcExtensionTwoAttr(){
|
|
$merId = (int)$this->product->mer_id;
|
|
// 判断:平台和商户是否开启分销
|
|
if(!intval(systemConfig('extension_status')) && !intval(merchantConfig((int)$merId,'extension_status'))) return 0;
|
|
// 商品设置固定金额 直接返回固定金额
|
|
if($this->product->extension_type == 1) return $this->extension_two;
|
|
// 计算佣金
|
|
$twoRate = (float)systemConfig('extension_two_rate');// 平台比例
|
|
$merTwoRate = (float)merchantConfig((int)$merId,'extension_two_rate');// 商家比例
|
|
$rate = $merTwoRate > 0 ? $merTwoRate : $twoRate;
|
|
|
|
return floatval(round(bcmul($rate, isset($this->org_price) ? $this->org_price : $this->price, 3),2));
|
|
}
|
|
|
|
public function productSku()
|
|
{
|
|
return $this->hasOne(ProductSku::class, 'unique', 'unique');
|
|
}
|
|
public function productCdkey()
|
|
{
|
|
return $this->hasMany(ProductCdkey::class,'value_id','value_id');
|
|
}
|
|
|
|
public function searchUniqueAttr($query,$value)
|
|
{
|
|
$query->where('unique',$value);
|
|
}
|
|
|
|
public function searchSkuAttr($query,$value)
|
|
{
|
|
$query->where('sku',$value);
|
|
}
|
|
|
|
public function searchProductIdAttr($query,$value)
|
|
{
|
|
$query->where('product_id',$value);
|
|
}
|
|
|
|
|
|
}
|