StoreCoupon.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\model\store\coupon;
  12. use app\common\model\BaseModel;
  13. use app\common\model\system\merchant\Merchant;
  14. use app\common\repositories\store\coupon\StoreCouponUserRepository;
  15. class StoreCoupon extends BaseModel
  16. {
  17. /**
  18. * @return string
  19. * @author xaboy
  20. * @day 2020-03-30
  21. */
  22. public static function tablePk(): string
  23. {
  24. return 'coupon_id';
  25. }
  26. /**
  27. * @return string
  28. * @author xaboy
  29. * @day 2020-03-30
  30. */
  31. public static function tableName(): string
  32. {
  33. return 'store_coupon';
  34. }
  35. public function product()
  36. {
  37. return $this->hasMany(StoreCouponProduct::class, 'coupon_id', 'coupon_id');
  38. }
  39. public function issue()
  40. {
  41. return $this->hasOne(StoreCouponIssueUser::class, 'coupon_id', 'coupon_id');
  42. }
  43. public function merchant()
  44. {
  45. return $this->hasOne(Merchant::class, 'mer_id', 'mer_id');
  46. }
  47. public function getUsedNumAttr()
  48. {
  49. return app()->make(StoreCouponUserRepository::class)->usedNum($this->coupon_id);
  50. }
  51. public function getSendNumAttr()
  52. {
  53. return app()->make(StoreCouponUserRepository::class)->sendNum($this->coupon_id);
  54. }
  55. }