Product.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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', 'status_text'];
  12. /**
  13. * 计算显示销量 (初始销量 + 实际销量)
  14. */
  15. public function getProductSalesAttr($value, $data)
  16. {
  17. return $data['sales_initial'] + $data['total_sales'];
  18. }
  19. /**
  20. * 状态
  21. */
  22. public function getStatusTextAttr($value, $data)
  23. {
  24. if($data['status'] == 0){
  25. return '待审核';
  26. }
  27. if($data['status'] == 10){
  28. return '通过';
  29. }
  30. if($data['status'] == 20){
  31. return '未通过';
  32. }
  33. return '';
  34. }
  35. public static function detail($assemble_product_id, $with = ['product.sku', 'assembleSku'])
  36. {
  37. return (new static())->with($with)->where('assemble_product_id', '=', $assemble_product_id)->find();
  38. }
  39. public function active()
  40. {
  41. return $this->belongsTo('app\\common\\model\\plus\\assemble\\Active', 'assemble_activity_id', 'assemble_activity_id');
  42. }
  43. public function product()
  44. {
  45. return $this->belongsTo('app\\common\\model\\product\\Product', 'product_id', 'product_id');
  46. }
  47. /**
  48. *关联商品规格表
  49. */
  50. public function assembleSku()
  51. {
  52. return $this->hasMany('app\\common\\model\\plus\\assemble\\AssembleSku', 'assemble_product_id', 'assemble_product_id');
  53. }
  54. /**
  55. * 关联供应商
  56. */
  57. public function supplier()
  58. {
  59. return $this->hasMany('app\\common\\model\\supplier\\Supplier', 'shop_supplier_id', 'shop_supplier_id');
  60. }
  61. /**
  62. * 商品ID是否存在
  63. */
  64. public static function isExistProductId($productId)
  65. {
  66. return (new static)->where('product_id', '=', $productId)
  67. ->where('is_delete', '=', 0)
  68. ->value('assemble_product_id');
  69. }
  70. }