StoreCoupon.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020-05-13
  7. *
  8. *
  9. */
  10. namespace app\common\model\store\coupon;
  11. use app\common\model\BaseModel;
  12. use app\common\model\system\merchant\Merchant;
  13. use app\common\repositories\store\coupon\StoreCouponUserRepository;
  14. class StoreCoupon extends BaseModel
  15. {
  16. /**
  17. * @return string
  18. * @author xaboy
  19. * @day 2020-03-30
  20. */
  21. public static function tablePk(): string
  22. {
  23. return 'coupon_id';
  24. }
  25. /**
  26. * @return string
  27. * @author xaboy
  28. * @day 2020-03-30
  29. */
  30. public static function tableName(): string
  31. {
  32. return 'store_coupon';
  33. }
  34. public function product()
  35. {
  36. return $this->hasMany(StoreCouponProduct::class, 'coupon_id', 'coupon_id');
  37. }
  38. public function issue()
  39. {
  40. return $this->hasOne(StoreCouponIssueUser::class, 'coupon_id', 'coupon_id');
  41. }
  42. public function merchant()
  43. {
  44. return $this->hasOne(Merchant::class, 'mer_id', 'mer_id');
  45. }
  46. public function getUsedNumAttr()
  47. {
  48. return app()->make(StoreCouponUserRepository::class)->usedNum($this->coupon_id);
  49. }
  50. public function getSendNumAttr()
  51. {
  52. return app()->make(StoreCouponUserRepository::class)->sendNum($this->coupon_id);
  53. }
  54. }