ProductGroupBuying.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace app\common\model\store\product;
  3. use app\common\model\BaseModel;
  4. use app\common\model\system\merchant\Merchant;
  5. class ProductGroupBuying extends BaseModel
  6. {
  7. /**
  8. * TODO
  9. * @return string
  10. * @author Qinii
  11. * @day 1/7/21
  12. */
  13. public static function tablePk(): string
  14. {
  15. return 'group_buying_id';
  16. }
  17. /**
  18. * TODO
  19. * @return string
  20. * @author Qinii
  21. * @day 1/7/21
  22. */
  23. public static function tableName(): string
  24. {
  25. return 'store_product_group_buying';
  26. }
  27. public function getStopTimeAttr()
  28. {
  29. return date('Y-m-d H:i:s',$this->end_time);
  30. }
  31. public function groupUser()
  32. {
  33. return $this->hasMany(ProductGroupUser::class,'group_buying_id','group_buying_id');
  34. }
  35. public function initiator()
  36. {
  37. return $this->hasOne(ProductGroupUser::class,'group_buying_id','group_buying_id')->where('is_initiator',1);
  38. }
  39. public function productGroup()
  40. {
  41. return $this->hasOne(ProductGroup::class,'product_group_id','product_group_id');
  42. }
  43. public function merchant()
  44. {
  45. return $this->hasOne(Merchant::class,'mer_id','mer_id');
  46. }
  47. public function searchEndTimeAttr($query,$value)
  48. {
  49. $query->where('end_time','<=',$value);
  50. }
  51. public function searchStatusAttr($query,$value)
  52. {
  53. $query->where('status',$value);
  54. }
  55. public function searchIsDelAttr($query,$value)
  56. {
  57. $query->where('is_del',$value);
  58. }
  59. public function searchProductGroupIdAttr($query,$value)
  60. {
  61. $query->where('product_group_id',$value);
  62. }
  63. public function searchGroupBuyingIdAttr($query,$value)
  64. {
  65. $query->where('group_buying_id',$value);
  66. }
  67. }