Topicdongtai.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. 'auditstatus_text',
  18. 'audittime_text'
  19. ];
  20. protected static function init()
  21. {
  22. self::afterUpdate(function ($row) {
  23. $changed = $row->getChangedData();
  24. //如果有修改密码
  25. if (isset($changed['auditstatus'])) {
  26. //如果强制审核,默认不通过
  27. $dongtai_audit_switch = config('site.dongtai_audit_switch');
  28. if($dongtai_audit_switch == 1){
  29. //暂时不影响
  30. }
  31. if ($changed['auditstatus'] == 2) {
  32. //驳回
  33. $msg_id = \app\common\model\Message::addMessage($row['user_id'],'动态审核','动态审核不通过:'.$row['auditremark']);
  34. } elseif($changed['auditstatus'] == 1) {
  35. //通过
  36. //$msg_id = \app\common\model\Message::addMessage($row['user_id'],'动态审核','动态审核通过');
  37. $task_rs = \app\common\model\TaskLog::tofinish($row['user_id'],10);
  38. }
  39. }
  40. });
  41. }
  42. public function getTypeList()
  43. {
  44. return ['1' => __('Type 1'), '2' => __('Type 2'), '3' => __('Type 3')];
  45. }
  46. public function getAuditstatusList()
  47. {
  48. return ['0' => __('Auditstatus 0'), '1' => __('Auditstatus 1'), '2' => __('Auditstatus 2')];
  49. }
  50. public function getTypeTextAttr($value, $data)
  51. {
  52. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  53. $list = $this->getTypeList();
  54. return isset($list[$value]) ? $list[$value] : '';
  55. }
  56. public function getAuditstatusTextAttr($value, $data)
  57. {
  58. $value = $value ? $value : (isset($data['auditstatus']) ? $data['auditstatus'] : '');
  59. $list = $this->getAuditstatusList();
  60. return isset($list[$value]) ? $list[$value] : '';
  61. }
  62. public function getAudittimeTextAttr($value, $data)
  63. {
  64. $value = $value ? $value : (isset($data['audittime']) ? $data['audittime'] : '');
  65. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  66. }
  67. protected function setAudittimeAttr($value)
  68. {
  69. return $value === '' ? 0 : ($value && !is_numeric($value) ? strtotime($value) : $value);
  70. }
  71. public function user()
  72. {
  73. return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  74. }
  75. }