External.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php namespace App\Models\WeiBan;
  2. use Illuminate\Database\Eloquent\Factories\HasFactory;
  3. use Illuminate\Database\Eloquent\Model;
  4. use App\Models\Traits\MultipUpdate;
  5. /**
  6. * 微伴用户模型
  7. *
  8. */
  9. class External extends Model
  10. {
  11. use HasFactory,MultipUpdate;
  12. // 与模型关联的表名
  13. protected $table = 'weiban_external';
  14. // 主键不是一个整数
  15. protected $keyType = 'string';
  16. // 主键不自增
  17. public $incrementing = false;
  18. // 是否主动维护时间戳
  19. public $timestamps = false;
  20. // 定义时间戳字段名
  21. // const CREATED_AT = 'insert_time';
  22. // const UPDATED_AT = 'update_time';
  23. /**
  24. * 添加数据
  25. *
  26. */
  27. public function edit($id,$data)
  28. {
  29. // 更新时间
  30. $data['update_time'] = time();
  31. // 写入数据表
  32. $result = $this->query()->where(['id'=>$id])->update($data);
  33. // 失败返回0
  34. if( !$result ) return '';
  35. // 返回结果
  36. return $id;
  37. }
  38. /**
  39. * 添加数据
  40. *
  41. */
  42. public function getOne($id)
  43. {
  44. // 返回结果
  45. $custom = $this->query()->where([['id','=',$id]])->first(['id','custom_uid','avatar','name','gender','status','type','corp_name','corp_full_name']);
  46. // 返回结果
  47. if( !$custom ) return [];
  48. // 数据结构
  49. return $custom->toArray();
  50. }
  51. /**
  52. * 添加数据
  53. *
  54. * @param int $id 客户ID
  55. * @param string $field 字段
  56. */
  57. public function getValue($id,$field)
  58. {
  59. // 返回结果
  60. $result = $this->query()->where([['id','=',$id]])->value($field);
  61. // 数据结构
  62. return $result;
  63. }
  64. }