ClientSearchKeyword.php 992 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. class ClientSearchKeyword extends Model
  5. {
  6. // 表名
  7. protected $table = 'client_search_keyword';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. // 追加属性
  14. protected $append = [
  15. 'sex_text'
  16. ];
  17. protected static function init()
  18. {
  19. self::afterInsert(function ($row) {
  20. $pk = $row->getPk();
  21. $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
  22. });
  23. }
  24. public function getSexList()
  25. {
  26. return ['1' => '男频','2' => '女频'];
  27. }
  28. public function getSexTextAttr($value, $data)
  29. {
  30. $value = $value ? $value : $data['sex'];
  31. $list = $this->getSexList();
  32. return isset($list[$value]) ? $list[$value] : '';
  33. }
  34. }