CouponRules.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\common\model\coupon;
  15. use app\common\model\BaseModel;
  16. use app\common\model\goods\Goods;
  17. use app\common\model\goods_category\GoodsCategory;
  18. /**
  19. * CouponRules模型
  20. * Class CouponRules
  21. * @package app\common\model\coupon
  22. */
  23. class CouponRules extends BaseModel
  24. {
  25. protected $name = 'coupon_rules';
  26. public function couponWithCategory()
  27. {
  28. return $this->belongsToMany(GoodsCategory::class,CouponCategory::class,'goods_category_id','coupon_id');
  29. }
  30. public function couponWithGoods()
  31. {
  32. return $this->belongsToMany(Goods::class,CouponGoods::class,'goods_id','coupon_id');
  33. }
  34. public function couponCategory()
  35. {
  36. return $this->hasMany(CouponCategory::class, 'coupon_id', 'goods_category_id');
  37. }
  38. public function getDiscountRatioTextAttr($value,$data)
  39. {
  40. return !empty($data['discount_ratio'])?$data['discount_ratio']*10:'';
  41. }
  42. public function couponCategoryOne()
  43. {
  44. return $this->hasOne(CouponCategory::class, 'coupon_id', 'id');
  45. }
  46. public function getLabelsAttr($value)
  47. {
  48. return $value?array_map(function($item){ return (int)$item; },explode(',',$value)):[];
  49. }
  50. }