DrawRecord.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace app\admin\model\lottery;
  3. use think\Model;
  4. class DrawRecord extends Model
  5. {
  6. // 表名
  7. protected $table = 'shop_lottery_draw_record';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'integer';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = false;
  13. // 追加属性
  14. protected $append = [
  15. 'trigger_type_text',
  16. 'draw_time_text'
  17. ];
  18. /**
  19. * 触发类型列表
  20. */
  21. public function getTriggerTypeList()
  22. {
  23. return [
  24. '1' => __('购买商品'),
  25. '2' => __('订单消费'),
  26. '3' => __('充值'),
  27. '4' => __('累计消费')
  28. ];
  29. }
  30. // 获取器
  31. public function getTriggerTypeTextAttr($value, $data)
  32. {
  33. $value = $value ? $value : (isset($data['trigger_type']) ? $data['trigger_type'] : '');
  34. $list = $this->getTriggerTypeList();
  35. return isset($list[$value]) ? $list[$value] : '';
  36. }
  37. public function getDrawTimeTextAttr($value, $data)
  38. {
  39. $value = $value ? $value : (isset($data['draw_time']) ? $data['draw_time'] : '');
  40. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  41. }
  42. // 关联关系
  43. public function activity()
  44. {
  45. return $this->belongsTo('Activity', 'activity_id', 'id');
  46. }
  47. public function user()
  48. {
  49. return $this->belongsTo('app\\common\\model\\User', 'user_id', 'id');
  50. }
  51. public function prize()
  52. {
  53. return $this->belongsTo('LotteryPrize', 'prize_id', 'id');
  54. }
  55. public function winRecord()
  56. {
  57. return $this->hasOne('WinRecord', 'draw_record_id', 'id');
  58. }
  59. }