123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace app\admin\model\lottery;
- use think\Model;
- class DrawRecord extends Model
- {
- // 表名
- protected $table = 'shop_lottery_draw_record';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'integer';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = false;
- // 追加属性
- protected $append = [
- 'trigger_type_text',
- 'draw_time_text'
- ];
- /**
- * 触发类型列表
- */
- public function getTriggerTypeList()
- {
- return [
- '1' => __('购买商品'),
- '2' => __('订单消费'),
- '3' => __('充值'),
- '4' => __('累计消费')
- ];
- }
- // 获取器
- public function getTriggerTypeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['trigger_type']) ? $data['trigger_type'] : '');
- $list = $this->getTriggerTypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getDrawTimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['draw_time']) ? $data['draw_time'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- // 关联关系
- public function activity()
- {
- return $this->belongsTo('Activity', 'activity_id', 'id');
- }
- public function user()
- {
- return $this->belongsTo('app\\common\\model\\User', 'user_id', 'id');
- }
- public function prize()
- {
- return $this->belongsTo('LotteryPrize', 'prize_id', 'id');
- }
- public function winRecord()
- {
- return $this->hasOne('WinRecord', 'draw_record_id', 'id');
- }
- }
|