Commands.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. return implode(',', [$this->type_id, $this->command, $this->note, $this->cmd_tags]);
  41. }
  42. }