Useridconfirm.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. use think\Db;
  5. class Useridconfirm extends Model
  6. {
  7. // 表名
  8. protected $name = 'user_idconfirm';
  9. // 自动写入时间戳字段
  10. protected $autoWriteTimestamp = 'int';
  11. // 定义时间戳字段名
  12. protected $createTime = 'createtime';
  13. protected $updateTime = 'updatetime';
  14. protected $deleteTime = false;
  15. // 追加属性
  16. protected $append = [
  17. 'status_text',
  18. 'audittime_text'
  19. ];
  20. /*protected static function init()
  21. {
  22. self::afterUpdate(function ($row){
  23. $changed = $row->getChangedData();
  24. if (isset($changed['status'])) {
  25. $update = [
  26. 'idcard_status'=>$changed['status'],
  27. ];
  28. Db::name('user')->where('id',$row['user_id'])->update($update);
  29. }
  30. });
  31. }*/
  32. public function getStatusList()
  33. {
  34. return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3')];
  35. }
  36. public function getStatusTextAttr($value, $data)
  37. {
  38. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  39. $list = $this->getStatusList();
  40. return isset($list[$value]) ? $list[$value] : '';
  41. }
  42. public function getAudittimeTextAttr($value, $data)
  43. {
  44. $value = $value ? $value : (isset($data['audittime']) ? $data['audittime'] : '');
  45. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  46. }
  47. protected function setAudittimeAttr($value)
  48. {
  49. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  50. }
  51. public function user()
  52. {
  53. return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  54. }
  55. }