ClientManageBlockResource.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class ClientManageBlockResource extends Model
  5. {
  6. // 表名
  7. protected $table = 'client_manage_block_resource';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. // 字段类型或者格式转换
  14. protected $type = [
  15. 'free_stime' => 'timestamp',
  16. 'free_etime' => 'timestamp'
  17. ];
  18. // 追加属性
  19. protected $append = [
  20. 'type_text'
  21. ];
  22. protected static function init()
  23. {
  24. self::afterInsert(function ($row) {
  25. $pk = $row->getPk();
  26. $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
  27. });
  28. }
  29. public function getTypeList()
  30. {
  31. return ['1' => '书籍', '2' => '跳转URL', '3' => 'VIP充值', '4' => '活动'];
  32. }
  33. public function getTypeTextAttr($value, $data)
  34. {
  35. $value = $value ? $value : $data['type'];
  36. $list = $this->getTypeList();
  37. return isset($list[$value]) ? $list[$value] : '';
  38. }
  39. public function manageblock()
  40. {
  41. return $this->belongsTo('ClientManageBlock', 'block_id', 'id', [], 'LEFT')->setEagerlyType(0);
  42. }
  43. public function book()
  44. {
  45. return $this->belongsTo('Book', 'book_id', 'id', [], 'LEFT')->setEagerlyType(0);
  46. }
  47. }