96 lines
3.0 KiB
PHP
96 lines
3.0 KiB
PHP
<?php
|
|
|
|
|
|
|
|
namespace app\common\model\store\product;
|
|
|
|
use app\common\model\BaseModel;
|
|
use app\common\repositories\store\product\ProductRepository;
|
|
use think\facade\Log;
|
|
|
|
class ProductPresellSku extends BaseModel
|
|
{
|
|
/**
|
|
* TODO
|
|
* @return string
|
|
* @author Qinii
|
|
* @day 2020-10-12
|
|
*/
|
|
public static function tablePk(): string
|
|
{
|
|
return '';
|
|
}
|
|
|
|
|
|
/**
|
|
* TODO
|
|
* @return string
|
|
* @author Qinii
|
|
* @day 2020-10-12
|
|
*/
|
|
public static function tableName(): string
|
|
{
|
|
return 'store_product_presell_sku';
|
|
}
|
|
|
|
public function sku()
|
|
{
|
|
return $this->hasOne(ProductAttrValue::class,'unique','unique');
|
|
}
|
|
|
|
public function presell()
|
|
{
|
|
return $this->hasOne(ProductPresell::class,'product_presell_id','product_presell_id');
|
|
}
|
|
|
|
public function searchUniqueAttr($query,$value)
|
|
{
|
|
$query->where('unique',$value);
|
|
}
|
|
public function searchProductIdAttr($query,$value)
|
|
{
|
|
$query->where('product_id',$value);
|
|
}
|
|
public function searchProductPresellIdAttr($query,$value)
|
|
{
|
|
$query->where('product_presell_id',$value);
|
|
}
|
|
|
|
// 计算一级佣金
|
|
public function getBcExtensionOneAttr(){
|
|
// 获取当前商品关联的商户id
|
|
$merId = app()->make(ProductRepository::class)
|
|
->getSearch([])
|
|
->where('product_id',$this->product_id)
|
|
->value('mer_id');
|
|
// 判断:平台和商户是否开启分销
|
|
if(!intval(systemConfig('extension_status')) && !intval(merchantConfig((int)$merId,'extension_status'))) return 0;
|
|
// 商品设置固定金额 直接返回固定金额
|
|
if($this->sku->extension_type == 1) return $this->sku->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, $this->presell_price, 3), 2));
|
|
}
|
|
// 计算二级佣金
|
|
public function getBcExtensionTwoAttr(){
|
|
// 获取当前商品关联的商户id
|
|
$merId = app()->make(ProductRepository::class)
|
|
->getSearch([])
|
|
->where('product_id',$this->product_id)
|
|
->value('mer_id');
|
|
// 判断:平台和商户是否开启分销
|
|
if(!intval(systemConfig('extension_status')) && !intval(merchantConfig((int)$merId,'extension_status'))) return 0;
|
|
// 商品设置固定金额 直接返回固定金额
|
|
if($this->sku->extension_type == 1) return $this->sku->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, $this->presell_price, 3), 2));
|
|
}
|
|
}
|