Topicdongtai.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Topicdongtai extends Model
  5. {
  6. // 表名
  7. protected $name = 'topic_dongtai';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'type_text',
  17. 'is_public_text',
  18. 'toptime_text',
  19. 'auditstatus_text',
  20. 'audittime_text'
  21. ];
  22. protected static function init()
  23. {
  24. self::afterUpdate(function ($row) {
  25. $changed = $row->getChangedData();
  26. //如果有修改密码
  27. if (isset($changed['auditstatus'])) {
  28. //如果强制审核,默认不通过
  29. $dongtai_audit_switch = config('site.dongtai_audit_switch');
  30. if($dongtai_audit_switch == 1){
  31. //暂时不影响
  32. }
  33. if ($changed['auditstatus'] == 2) {
  34. //驳回
  35. $msg_id = \app\common\model\Message::addMessage($row['user_id'],'动态审核','动态审核不通过:'.$row['auditremark']);
  36. } elseif($changed['auditstatus'] == 1) {
  37. //通过
  38. //$msg_id = \app\common\model\Message::addMessage($row['user_id'],'动态审核','动态审核通过');
  39. }
  40. }
  41. });
  42. }
  43. public function getTypeList()
  44. {
  45. return ['1' => __('Type 1'), '2' => __('Type 2')];
  46. }
  47. public function getIsPublicList()
  48. {
  49. return ['1' => __('Is_public 1'), '2' => __('Is_public 2')];
  50. }
  51. public function getAuditstatusList()
  52. {
  53. return ['0' => __('Auditstatus 0'), '1' => __('Auditstatus 1'), '2' => __('Auditstatus 2')];
  54. }
  55. public function getTypeTextAttr($value, $data)
  56. {
  57. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  58. $list = $this->getTypeList();
  59. return isset($list[$value]) ? $list[$value] : '';
  60. }
  61. public function getIsPublicTextAttr($value, $data)
  62. {
  63. $value = $value ? $value : (isset($data['is_public']) ? $data['is_public'] : '');
  64. $list = $this->getIsPublicList();
  65. return isset($list[$value]) ? $list[$value] : '';
  66. }
  67. public function getToptimeTextAttr($value, $data)
  68. {
  69. $value = $value ? $value : (isset($data['toptime']) ? $data['toptime'] : '');
  70. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  71. }
  72. public function getAuditstatusTextAttr($value, $data)
  73. {
  74. $value = $value ? $value : (isset($data['auditstatus']) ? $data['auditstatus'] : '');
  75. $list = $this->getAuditstatusList();
  76. return isset($list[$value]) ? $list[$value] : '';
  77. }
  78. public function getAudittimeTextAttr($value, $data)
  79. {
  80. $value = $value ? $value : (isset($data['audittime']) ? $data['audittime'] : '');
  81. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  82. }
  83. protected function setToptimeAttr($value)
  84. {
  85. return $value === '' ? 0 : ($value && !is_numeric($value) ? strtotime($value) : $value);
  86. }
  87. protected function setAudittimeAttr($value)
  88. {
  89. return $value === '' ? 0 : ($value && !is_numeric($value) ? strtotime($value) : $value);
  90. }
  91. public function user()
  92. {
  93. return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  94. }
  95. }