ActiveGoods.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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\active;
  12. use addon\mall\app\dict\active\ActiveDict;
  13. use addon\mall\app\model\goods\Goods;
  14. use addon\mall\app\model\goods\GoodsSku;
  15. use core\base\BaseModel;
  16. use think\db\Query;
  17. /**
  18. * 营销活动商品模型
  19. */
  20. class ActiveGoods extends BaseModel
  21. {
  22. /**
  23. * 数据表主键
  24. * @var string
  25. */
  26. protected $pk = 'active_goods_id';
  27. /**
  28. * 模型名称
  29. * @var string
  30. */
  31. protected $name = 'mall_active_goods';
  32. protected $type = [
  33. ];
  34. /**
  35. * 商品项
  36. * @return \think\model\relation\HasMany
  37. */
  38. public function goods()
  39. {
  40. return $this->hasOne(Goods::class, 'goods_id', 'goods_id');
  41. }
  42. /**
  43. * 关联默认商品规格
  44. * @return \think\model\relation\HasOne
  45. */
  46. public function goodsSku()
  47. {
  48. return $this->hasOne(GoodsSku::class, 'goods_id', 'goods_id');
  49. }
  50. /**
  51. * 优惠券商品项
  52. * @return \think\model\relation\HasMany
  53. */
  54. public function active()
  55. {
  56. return $this->hasOne(Active::class, 'active_id', 'active_id');
  57. }
  58. /**
  59. * 活动状态
  60. * @param $value
  61. * @param $data
  62. * @return mixed|string
  63. */
  64. public function getActiveGoodsStatusNameAttr($value, $data)
  65. {
  66. if (empty($data['active_goods_status']))
  67. {
  68. return '';
  69. }
  70. return ActiveDict::getStatus()[$data['active_goods_status']] ?? '';
  71. }
  72. }