Commands.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace app\admin\model\auto;
  3. use think\Model;
  4. class Commands extends Model
  5. {
  6. protected $auto = ['full_text'];
  7. // 表名
  8. protected $name = 'auto_commands';
  9. // 自动写入时间戳字段
  10. protected $autoWriteTimestamp = 'integer';
  11. // 定义时间戳字段名
  12. protected $createTime = 'createtime';
  13. protected $updateTime = 'updatetime';
  14. protected $deleteTime = false;
  15. // 追加属性
  16. protected $append = [
  17. 'status_text'
  18. ];
  19. protected static function init()
  20. {
  21. self::afterInsert(function ($row) {
  22. if (!$row['weigh']) {
  23. $pk = $row->getPk();
  24. $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
  25. }
  26. });
  27. }
  28. public function getStatusList()
  29. {
  30. return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2')];
  31. }
  32. public function getStatusTextAttr($value, $data)
  33. {
  34. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  35. $list = $this->getStatusList();
  36. return isset($list[$value]) ? $list[$value] : '';
  37. }
  38. protected function setFullTextAttr()
  39. {
  40. // general:docker-compose restart #重启容器-docker,compose
  41. return sprintf('%s:%s #%s-%s', $this->type_id, $this->command, $this->note, $this->cmd_tags);
  42. }
  43. }