ProductPresellSku.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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 ProductPresellSku extends BaseModel
  14. {
  15. /**
  16. * TODO
  17. * @return string
  18. * @author Qinii
  19. * @day 2020-10-12
  20. */
  21. public static function tablePk(): string
  22. {
  23. return '';
  24. }
  25. /**
  26. * TODO
  27. * @return string
  28. * @author Qinii
  29. * @day 2020-10-12
  30. */
  31. public static function tableName(): string
  32. {
  33. return 'store_product_presell_sku';
  34. }
  35. public function sku()
  36. {
  37. return $this->hasOne(ProductAttrValue::class,'unique','unique');
  38. }
  39. public function presell()
  40. {
  41. return $this->hasOne(ProductPresell::class,'product_presell_id','product_presell_id');
  42. }
  43. public function searchUniqueAttr($query,$value)
  44. {
  45. $query->where('unique',$value);
  46. }
  47. public function searchProductIdAttr($query,$value)
  48. {
  49. $query->where('product_id',$value);
  50. }
  51. public function searchProductPresellIdAttr($query,$value)
  52. {
  53. $query->where('product_presell_id',$value);
  54. }
  55. public function getBcExtensionOneAttr()
  56. {
  57. if (!intval(systemConfig('extension_status'))) return 0;
  58. if ($this->sku->extension_one > 0) return $this->sku->extension_one;
  59. return floatval(round(bcmul(systemConfig('extension_one_rate'), $this->presell_price, 3), 2));
  60. }
  61. public function getBcExtensionTwoAttr()
  62. {
  63. if (!intval(systemConfig('extension_status'))) return 0;
  64. if ($this->sku->extension_two > 0) return $this->sku->extension_two;
  65. return floatval(round(bcmul(systemConfig('extension_two_rate'), $this->presell_price, 3), 2));
  66. }
  67. }