123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- <?php
- namespace app\admin\model\lottery;
- use think\Model;
- use traits\model\SoftDelete;
- 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 getTypeList()
- {
- return ['1' => __('消费抽奖')];
- }
- /**
- * 活动状态列表
- */
- public function getStatusList()
- {
- return [
- '0' => __('草稿'),
- '1' => __('进行中'),
- '2' => __('已结束'),
- '3' => __('已暂停')
- ];
- }
- /**
- * 开奖方式列表
- */
- public function getLotteryTypeList()
- {
- return [
- '1' => __('即抽即中'),
- '2' => __('按时间开奖'),
- '3' => __('按人数开奖')
- ];
- }
- /**
- * 适用人群类型列表
- */
- public function getUserLimitTypeList()
- {
- return [
- '1' => __('全部会员'),
- '2' => __('会员等级'),
- '3' => __('会员标签')
- ];
- }
- /**
- * 引导样式列表
- */
- public function getGuideStyleList()
- {
- return [
- '1' => __('默认样式'),
- '2' => __('自定义')
- ];
- }
- // 获取器
- public function getTypeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
- $list = $this->getTypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getStatusTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
- $list = $this->getStatusList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getLotteryTypeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['lottery_type']) ? $data['lottery_type'] : '');
- $list = $this->getLotteryTypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getUserLimitTypeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['user_limit_type']) ? $data['user_limit_type'] : '');
- $list = $this->getUserLimitTypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getGuideStyleTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['guide_style']) ? $data['guide_style'] : '');
- $list = $this->getGuideStyleList();
- 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;
- }
- // 修改器
- protected function setStartTimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- protected function setEndTimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- protected function setLotteryTimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($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');
- }
- }
|