StoreCouponSend.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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\repositories\store\coupon\StoreCouponUserRepository;
  14. class StoreCouponSend extends BaseModel
  15. {
  16. public static function tablePk(): ?string
  17. {
  18. return 'coupon_send_id';
  19. }
  20. public static function tableName(): string
  21. {
  22. return 'store_coupon_send';
  23. }
  24. public function setMarkAttr(array $val)
  25. {
  26. return json_encode($val);
  27. }
  28. public function getMarkAttr($val)
  29. {
  30. return json_decode($val, true) ?: [];
  31. }
  32. public function getUseCountAttr()
  33. {
  34. return app()->make(StoreCouponUserRepository::class)->sendNum($this->coupon_id, $this->coupon_send_id, 1);
  35. }
  36. public function getUsedNumAttr()
  37. {
  38. return app()->make(StoreCouponUserRepository::class)->usedNum($this->coupon_id);
  39. }
  40. public function getSendNumAttr()
  41. {
  42. return app()->make(StoreCouponUserRepository::class)->sendNum($this->coupon_id);
  43. }
  44. }