Lottery.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace app\common\model\plus\lottery;
  3. use app\common\model\BaseModel;
  4. /**
  5. * Class GiftPackage
  6. * 转盘模型
  7. * @package
  8. */
  9. class Lottery extends BaseModel
  10. {
  11. protected $name = 'lottery';
  12. protected $pk = 'lottery_id';
  13. /**
  14. * 追加字段
  15. * @var string[]
  16. */
  17. protected $append = ['status_text'];
  18. /**
  19. * 转盘详情
  20. */
  21. public static function detail()
  22. {
  23. return (new static())->with(['image'])->find();
  24. }
  25. /**
  26. * 状态
  27. */
  28. public function getStatusTextAttr($value, $data)
  29. {
  30. $text = '';
  31. if ($value == 1) {
  32. $text = '开启';
  33. } else {
  34. $text = '关闭';
  35. }
  36. return $text;
  37. }
  38. /**
  39. * 关联奖项
  40. */
  41. public function prize()
  42. {
  43. return $this->hasMany('app\\common\\model\\plus\\lottery\\LotteryPrize', 'lottery_id', 'lottery_id');
  44. }
  45. /**
  46. * 关联文件库
  47. */
  48. public function image()
  49. {
  50. return $this->belongsTo('app\\common\\model\\file\\UploadFile', 'image_id', 'file_id')
  51. ->bind(['file_path']);
  52. }
  53. }