LotteryUserChance.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace app\common\model\lottery;
  3. use think\Model;
  4. /**
  5. * 用户抽奖机会模型
  6. */
  7. class LotteryUserChance extends Model
  8. {
  9. // 表名
  10. protected $table = 'shop_lottery_user_chance';
  11. // 开启自动写入时间戳字段
  12. protected $autoWriteTimestamp = 'int';
  13. // 定义时间戳字段名
  14. protected $createTime = 'createtime';
  15. protected $updateTime = 'updatetime';
  16. protected $deleteTime = false;
  17. // 追加属性
  18. protected $append = [
  19. 'get_detail_data'
  20. ];
  21. /**
  22. * 关联活动
  23. */
  24. public function activity()
  25. {
  26. return $this->belongsTo('LotteryActivity', 'activity_id');
  27. }
  28. /**
  29. * 关联用户
  30. */
  31. public function user()
  32. {
  33. return $this->belongsTo('app\common\model\User', 'user_id');
  34. }
  35. /**
  36. * 获取获得详情数据
  37. */
  38. public function getGetDetailDataAttr($value, $data)
  39. {
  40. return !empty($data['get_detail']) ? json_decode($data['get_detail'], true) : [];
  41. }
  42. /**
  43. * 设置获得详情
  44. */
  45. public function setGetDetailAttr($value)
  46. {
  47. return is_array($value) ? json_encode($value) : $value;
  48. }
  49. }