123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace app\admin\model\lottery;
- use think\Model;
- use traits\model\SoftDelete;
- class LotteryPrize extends Model
- {
- use SoftDelete;
- // 表名
- protected $table = 'shop_lottery_prize';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'integer';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = 'deletetime';
- // 追加属性
- protected $append = [
- 'type_text',
- 'deliver_type_text',
- 'status_text'
- ];
- /**
- * 奖品类型列表
- */
- public function getTypeList()
- {
- return [
- '1' => __('未中奖'),
- '2' => __('实物奖品'),
- '3' => __('优惠券'),
- '4' => __('红包'),
- '5' => __('兑换码'),
- '6' => __('商城奖品')
- ];
- }
- /**
- * 发放方式列表
- */
- public function getDeliverTypeList()
- {
- return [
- '1' => __('自动发放'),
- '2' => __('手动发放')
- ];
- }
- /**
- * 状态列表
- */
- public function getStatusList()
- {
- return [
- '0' => __('禁用'),
- '1' => __('启用')
- ];
- }
- // 获取器
- public function getTypeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
- $list = $this->getTypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getDeliverTypeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['deliver_type']) ? $data['deliver_type'] : '');
- $list = $this->getDeliverTypeList();
- 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 activity()
- {
- return $this->belongsTo('Activity', 'activity_id', 'id');
- }
- public function winRecord()
- {
- return $this->hasMany('WinRecord', 'prize_id', 'id');
- }
- public function goods()
- {
- return $this->belongsTo('app\\common\\model\\shop\\Goods', 'goods_id', 'id');
- }
- public function goodsSku()
- {
- return $this->belongsTo('app\\common\\model\\shop\\GoodsSku', 'goods_sku_id', 'id');
- }
- public function coupon()
- {
- return $this->belongsTo('app\\common\\model\\shop\\Coupon', 'coupon_id', 'id');
- }
- }
|