ProductAttrValue.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\model\store\product;
  12. use app\common\model\BaseModel;
  13. class ProductAttrValue extends BaseModel
  14. {
  15. /**
  16. * @Author:Qinii
  17. * @Date: 2020/5/8
  18. * @return string
  19. */
  20. public static function tablePk(): string
  21. {
  22. return 'value_id';
  23. }
  24. /**
  25. * @Author:Qinii
  26. * @Date: 2020/5/8
  27. * @return string
  28. */
  29. public static function tableName(): string
  30. {
  31. return 'store_product_attr_value';
  32. }
  33. public function getDetailAttr($value)
  34. {
  35. return json_decode($value);
  36. }
  37. public function product()
  38. {
  39. return $this->hasOne(Product::class, 'product_id','product_id');
  40. }
  41. public function reservation()
  42. {
  43. return $this->hasMany(ProductAttrValueReservation::class, 'attr_value_id','value_id');
  44. }
  45. public function getSvipPriceAttr()
  46. {
  47. if (isset($this->product->product_type) && $this->product->product_type == 0 && $this->product->show_svip_price && $this->product->svip_price_type == 1) {
  48. $rate = merchantConfig($this->product->mer_id,'svip_store_rate');
  49. $svip_store_rate = $rate > 0 ? bcdiv($rate,100,2) : 0;
  50. return bcmul($this->price, $svip_store_rate,2);
  51. }
  52. return $this->getData('svip_price');
  53. }
  54. public function getIsSvipPriceAttr()
  55. {
  56. if (isset($this->product->product_type) && $this->product->product_type == 0 && $this->product->svip_price_type == 1) {
  57. $rate = merchantConfig($this->product->mer_id, 'svip_store_rate');
  58. $svip_store_rate = $rate > 0 ? bcdiv($rate, 100, 2) : 0;
  59. return bcmul($this->price, $svip_store_rate, 2);
  60. }
  61. return '未设置';
  62. }
  63. public function getBcExtensionOneAttr()
  64. {
  65. if(!intval(systemConfig('extension_status'))) return 0;
  66. if($this->product && $this->product->extension_type == 1) return $this->extension_one;
  67. return floatval(round(bcmul(systemConfig('extension_one_rate'), isset($this->org_price) ? $this->org_price : $this->price, 3),2));
  68. }
  69. public function getBcExtensionTwoAttr()
  70. {
  71. if(!intval(systemConfig('extension_status'))) return 0;
  72. if($this->product && $this->product->extension_type == 1) return $this->extension_two;
  73. return floatval(round(bcmul(systemConfig('extension_two_rate'), isset($this->org_price) ? $this->org_price : $this->price, 3),2));
  74. }
  75. public function productSku()
  76. {
  77. return $this->hasOne(ProductSku::class, 'unique', 'unique');
  78. }
  79. public function productCdkey()
  80. {
  81. return $this->hasMany(ProductCdkey::class,'value_id','value_id');
  82. }
  83. public function cdkeyLibrary()
  84. {
  85. return $this->hasOne(CdkeyLibrary::class,'id','library_id');
  86. }
  87. public function searchUniqueAttr($query,$value)
  88. {
  89. $query->where('unique',$value);
  90. }
  91. public function searchSkuAttr($query,$value)
  92. {
  93. $query->where('sku',$value);
  94. }
  95. public function searchProductIdAttr($query,$value)
  96. {
  97. $query->where('product_id',$value);
  98. }
  99. // public function getOldStockAttr($value,$data)
  100. // {
  101. // $value = self::where(['sku' => $data['sku'], 'product_id' => $data['old_product_id']])->find();
  102. // if ($value){
  103. // return $value;
  104. // }
  105. // }
  106. }