External.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 add($data)
  28. {
  29. if( empty($data['id']) ) return '';
  30. // 更新时间
  31. $data['insert_time'] = time();
  32. $data['update_time'] = time();
  33. // 写入数据表
  34. $result = $this->query()->insert($data);
  35. // 失败返回0
  36. if( !$result ) return '';
  37. // 返回结果
  38. return $data['id'];
  39. }
  40. /**
  41. * 添加数据
  42. *
  43. */
  44. public function edit($id,$data)
  45. {
  46. // 更新时间
  47. $data['update_time'] = time();
  48. // 写入数据表
  49. $result = $this->query()->where(['id'=>$id])->update($data);
  50. // 失败返回0
  51. if( !$result ) return '';
  52. // 返回结果
  53. return $id;
  54. }
  55. /**
  56. * 添加数据
  57. *
  58. */
  59. public function getOne($id)
  60. {
  61. // 返回结果
  62. $custom = $this->query()->where([['id','=',$id]])->first(['id','custom_uid','avatar','name','gender','status','type','corp_name','corp_full_name']);
  63. // 返回结果
  64. if( !$custom ) return [];
  65. // 数据结构
  66. return $custom->toArray();
  67. }
  68. /**
  69. * 添加数据
  70. *
  71. * @param int $id 客户ID
  72. * @param string $field 字段
  73. */
  74. public function getValue($id,$field)
  75. {
  76. // 返回结果
  77. $result = $this->query()->where([['id','=',$id]])->value($field);
  78. // 数据结构
  79. return $result;
  80. }
  81. }