Product.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace app\common\model\plus\seckill;
  3. use app\common\model\BaseModel;
  4. /**
  5. * 参与记录模型
  6. */
  7. class Product extends BaseModel
  8. {
  9. protected $name = 'seckill_product';
  10. protected $pk = 'seckill_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($seckill_product_id, $with = ['product.sku', 'seckillSku','active','product.image.file'])
  36. {
  37. return (new static())->with($with)->where('seckill_product_id', '=', $seckill_product_id)->find();
  38. }
  39. public function active()
  40. {
  41. return $this->belongsTo('app\\common\\model\\plus\\seckill\\Active', 'seckill_activity_id', 'seckill_activity_id');
  42. }
  43. public function product()
  44. {
  45. return $this->belongsTo('app\\common\\model\\product\\Product', 'product_id', 'product_id');
  46. }
  47. public function seckillSku()
  48. {
  49. return $this->hasMany('app\\common\\model\\plus\\seckill\\SeckillSku', 'seckill_product_id', 'seckill_product_id');
  50. }
  51. /**
  52. * 关联供应商
  53. */
  54. public function supplier()
  55. {
  56. return $this->hasMany('app\\common\\model\\supplier\\Supplier', 'shop_supplier_id', 'shop_supplier_id');
  57. }
  58. /**
  59. * 商品ID是否存在
  60. */
  61. public static function isExistProductId($productId)
  62. {
  63. return (new static)->where('product_id', '=', $productId)
  64. ->where('is_delete', '=', 0)
  65. ->value('seckill_product_id');
  66. }
  67. }