ProductPresellSku.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace app\common\model\store\product;
  3. use app\common\model\BaseModel;
  4. class ProductPresellSku extends BaseModel
  5. {
  6. /**
  7. * TODO
  8. * @return string
  9. * @author Qinii
  10. * @day 2020-10-12
  11. */
  12. public static function tablePk(): string
  13. {
  14. return '';
  15. }
  16. /**
  17. * TODO
  18. * @return string
  19. * @author Qinii
  20. * @day 2020-10-12
  21. */
  22. public static function tableName(): string
  23. {
  24. return 'store_product_presell_sku';
  25. }
  26. public function sku()
  27. {
  28. return $this->hasOne(ProductAttrValue::class,'unique','unique');
  29. }
  30. public function presell()
  31. {
  32. return $this->hasOne(ProductPresell::class,'product_presell_id','product_presell_id');
  33. }
  34. public function searchUniqueAttr($query,$value)
  35. {
  36. $query->where('unique',$value);
  37. }
  38. public function searchProductIdAttr($query,$value)
  39. {
  40. $query->where('product_id',$value);
  41. }
  42. public function searchProductPresellIdAttr($query,$value)
  43. {
  44. $query->where('product_presell_id',$value);
  45. }
  46. public function getBcExtensionOneAttr()
  47. {
  48. if (!intval(systemConfig('extension_status'))) return 0;
  49. if ($this->sku->extension_one > 0) return $this->sku->extension_one;
  50. return floatval(round(bcmul(systemConfig('extension_one_rate'), $this->presell_price, 3), 2));
  51. }
  52. public function getBcExtensionTwoAttr()
  53. {
  54. if (!intval(systemConfig('extension_status'))) return 0;
  55. if ($this->sku->extension_two > 0) return $this->sku->extension_two;
  56. return floatval(round(bcmul(systemConfig('extension_two_rate'), $this->presell_price, 3), 2));
  57. }
  58. }