CouponMember.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的多应用管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace addon\mall\app\model\coupon;
  12. use addon\mall\app\dict\coupon\CouponDict;
  13. use addon\mall\app\dict\coupon\CouponMemberDict;
  14. use app\model\member\Member;
  15. use core\base\BaseModel;
  16. use think\model\relation\HasMany;
  17. /**
  18. * 优惠券会员领取记录模型
  19. */
  20. class CouponMember extends BaseModel
  21. {
  22. /**
  23. * 数据表主键
  24. * @var string
  25. */
  26. protected $pk = 'id';
  27. /**
  28. * 模型名称
  29. * @var string
  30. */
  31. protected $name = 'mall_coupon_member';
  32. protected $type = [
  33. 'expire_time' => 'timestamp',
  34. 'use_time' => 'timestamp',
  35. ];
  36. public function coupon()
  37. {
  38. return $this->hasOne(Coupon::class, 'id', 'coupon_id')->joinType('left')
  39. ->withField('id, title, price, min_condition_money, type, join_site_ids, is_all_site_join');
  40. }
  41. public function member()
  42. {
  43. return $this->hasOne(Member::class, 'member_id', 'member_id')->joinType('left')
  44. ->withField('member_id,member_no, username, mobile, nickname');
  45. }
  46. /**
  47. * 优惠券商品项
  48. * @return HasMany
  49. */
  50. public function goods()
  51. {
  52. return $this->hasMany(CouponGoods::class, 'coupon_id', 'coupon_id');
  53. }
  54. public function getStatusNameAttr($value, $data)
  55. {
  56. if (empty($data[ 'status' ]))
  57. return '';
  58. $temp = CouponMemberDict::getStatus()[ $data[ 'status' ] ] ?? [];
  59. return $temp ?? '';
  60. }
  61. public function getReceiveTypeNameAttr($value, $data)
  62. {
  63. if (empty($data[ 'receive_type' ]))
  64. return '';
  65. $receive_type = event('CouponReceiveType', []);
  66. if (empty($receive_type)) {
  67. return [];
  68. }
  69. foreach ($receive_type as $value) {
  70. foreach ($value as $v) {
  71. $type[] = $v[ 'name' ];
  72. $info[] = $v;
  73. }
  74. }
  75. $key = array_search($data[ 'receive_type' ], $type);
  76. $temp = $info[ $key ][ 'title' ] ?? [];
  77. return $temp ?? '';
  78. }
  79. public function getCouponPriceAttr($value, $data)
  80. {
  81. if (empty($data[ 'price' ])) {
  82. return 0;
  83. }
  84. return rtrim(rtrim($data[ 'price' ], '0'), '.');
  85. }
  86. public function getCouponMinPriceAttr($value, $data)
  87. {
  88. if (empty($data[ 'min_condition_money' ])) {
  89. return 0;
  90. }
  91. return rtrim(rtrim($data[ 'min_condition_money' ], '0'), '.');
  92. }
  93. public function getTypeNameAttr($value, $data)
  94. {
  95. if (empty($data[ 'type' ]))
  96. return '';
  97. return CouponDict::getType()[ $data[ 'type' ] ] ?? '';
  98. }
  99. }