Product.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace app\common\model\plus\assemble;
  3. use app\common\model\BaseModel;
  4. /**
  5. * 参与记录模型
  6. */
  7. class Product extends BaseModel
  8. {
  9. protected $name = 'assemble_product';
  10. protected $pk = 'assemble_product_id';
  11. protected $append = ['product_sales'];
  12. /**
  13. * 计算显示销量 (初始销量 + 实际销量)
  14. */
  15. public function getProductSalesAttr($value, $data)
  16. {
  17. return $data['sales_initial'] + $data['total_sales'];
  18. }
  19. public static function detail($assemble_product_id, $with = ['product.sku', 'assembleSku'])
  20. {
  21. return (new static())->with($with)->where('assemble_product_id', '=', $assemble_product_id)->find();
  22. }
  23. public function active()
  24. {
  25. return $this->belongsTo('app\\common\\model\\plus\\assemble\\Active', 'assemble_activity_id', 'assemble_activity_id');
  26. }
  27. public function product()
  28. {
  29. return $this->belongsTo('app\\common\\model\\product\\Product', 'product_id', 'product_id');
  30. }
  31. public function assembleSku()
  32. {
  33. return $this->hasMany('AssembleSku', 'assemble_product_id', 'assemble_product_id');
  34. }
  35. }