Topicdongtai.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. if ($changed['auditstatus'] == 2) {
  27. //驳回
  28. $msg_id = \app\common\model\Message::addMessage($row['user_id'],'动态审核','动态审核不通过:'.$row['auditremark']);
  29. } elseif($changed['auditstatus'] == 1) {
  30. //通过
  31. //$msg_id = \app\common\model\Message::addMessage($row['user_id'],'动态审核','动态审核通过');
  32. $task_rs = \app\common\model\TaskLog::tofinish($row['user_id'],10);
  33. }
  34. }
  35. });
  36. }
  37. public function getTypeList()
  38. {
  39. return ['1' => __('Type 1'), '2' => __('Type 2'), '3' => __('Type 3')];
  40. }
  41. public function getAuditstatusList()
  42. {
  43. return ['0' => __('Auditstatus 0'), '1' => __('Auditstatus 1'), '2' => __('Auditstatus 2')];
  44. }
  45. public function getTypeTextAttr($value, $data)
  46. {
  47. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  48. $list = $this->getTypeList();
  49. return isset($list[$value]) ? $list[$value] : '';
  50. }
  51. public function getAuditstatusTextAttr($value, $data)
  52. {
  53. $value = $value ? $value : (isset($data['auditstatus']) ? $data['auditstatus'] : '');
  54. $list = $this->getAuditstatusList();
  55. return isset($list[$value]) ? $list[$value] : '';
  56. }
  57. public function getAudittimeTextAttr($value, $data)
  58. {
  59. $value = $value ? $value : (isset($data['audittime']) ? $data['audittime'] : '');
  60. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  61. }
  62. protected function setAudittimeAttr($value)
  63. {
  64. return $value === '' ? 0 : ($value && !is_numeric($value) ? strtotime($value) : $value);
  65. }
  66. public function user()
  67. {
  68. return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  69. }
  70. }