Useridconfirm.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. ];
  19. protected static function init()
  20. {
  21. self::beforeDelete(function ($row){
  22. $update = [
  23. 'idcard_status'=> '-1',
  24. ];
  25. Db::name('user')->where('id',$row['user_id'])->update($update);
  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. public function user()
  39. {
  40. return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  41. }
  42. }