123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
- namespace app\admin\model\lottery;
- use think\Model;
- use traits\model\SoftDelete;
- use app\common\Enum\LotteryEnum;
- class Activity extends Model
- {
- use SoftDelete;
- // 表名
- protected $table = 'shop_lottery_activity';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'integer';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = 'deletetime';
- // 追加属性
- protected $append = [
- 'type_text',
- 'status_text',
- 'lottery_type_text',
- 'user_limit_type_text',
- 'guide_style_text',
- 'start_time_text',
- 'end_time_text',
- 'lottery_time_text'
- ];
- // 获取器
- public function getTypeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
- $list = LotteryEnum::getActivityTypeMap();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getStatusTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
- $list = LotteryEnum::getActivityStatusMap();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getLotteryTypeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['lottery_type']) ? $data['lottery_type'] : '');
- $list = LotteryEnum::getLotteryTypeMap();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getUserLimitTypeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['user_limit_type']) ? $data['user_limit_type'] : '');
- $list = LotteryEnum::getUserLimitTypeMap();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getGuideStyleTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['guide_style']) ? $data['guide_style'] : '');
- $list = LotteryEnum::getGuideStyleMap();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getStartTimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['start_time']) ? $data['start_time'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- public function getEndTimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['end_time']) ? $data['end_time'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- public function getLotteryTimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['lottery_time']) ? $data['lottery_time'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- // 关联关系
- public function prize()
- {
- return $this->hasMany('LotteryPrize', 'activity_id', 'id');
- }
- public function condition()
- {
- return $this->hasMany('Condition', 'activity_id', 'id');
- }
- public function drawRecord()
- {
- return $this->hasMany('DrawRecord', 'activity_id', 'id');
- }
- public function winRecord()
- {
- return $this->hasMany('WinRecord', 'activity_id', 'id');
- }
- public function userChance()
- {
- return $this->hasMany('UserChance', 'activity_id', 'id');
- }
- public function statistics()
- {
- return $this->hasMany('Statistics', 'activity_id', 'id');
- }
- }
|