Useridconfirm.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. use think\Db;
  5. class Useridconfirm extends Model
  6. {
  7. // 表名
  8. protected $table = 'user_idconfirm';
  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. self::afterUpdate(function ($row) {
  21. $changed = $row->getChangedData();
  22. if (isset($changed['status'])) {
  23. $update = ['idcard_status'=>$changed['status']];
  24. if($changed['status'] == 1){
  25. $update['nickname'] = $row['truename'];
  26. }
  27. Db::name('user')->where('id',$row['user_id'])->update($update);
  28. }
  29. });
  30. }
  31. public function getStatusList()
  32. {
  33. return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2')];
  34. }
  35. public function getStatusTextAttr($value, $data)
  36. {
  37. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  38. $list = $this->getStatusList();
  39. return isset($list[$value]) ? $list[$value] : '';
  40. }
  41. public function user()
  42. {
  43. return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  44. }
  45. }