Prize.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\admin\model\lottery;
  3. use think\Model;
  4. use traits\model\SoftDelete;
  5. class Prize extends Model
  6. {
  7. use SoftDelete;
  8. // 表名
  9. protected $name = 'luck_prize';
  10. // 自动写入时间戳字段
  11. protected $autoWriteTimestamp = 'integer';
  12. // 定义时间戳字段名
  13. protected $createTime = 'createtime';
  14. protected $updateTime = 'updatetime';
  15. protected $deleteTime = 'deletetime';
  16. // 追加属性
  17. protected $append = [
  18. 'type_text',
  19. 'image_full_url'
  20. ];
  21. public function getTypeList()
  22. {
  23. return ['1' => __('未中奖'), '4' => __('红包')];
  24. }
  25. public function getTypeTextAttr($value, $data)
  26. {
  27. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  28. $list = $this->getTypeList();
  29. return isset($list[$value]) ? $list[$value] : '';
  30. }
  31. public function getImageFullUrlAttr($value, $data)
  32. {
  33. $value = $value ?: (isset($data['image']) ? $data['image'] : '');
  34. return cdnurl($value, true);
  35. }
  36. public function lottery()
  37. {
  38. return $this->belongsTo(Info::class, 'lottery_id', 'id');
  39. }
  40. }