User.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Created by PhpStorm
  4. * User:林志杰
  5. * Email:[email protected]
  6. * Motto:纵有疾风起,人生不言弃!
  7. * Time:2020/1/3 0:29
  8. */
  9. namespace app\common\model\mysql;
  10. use think\Model;
  11. class User extends Model
  12. {
  13. /**
  14. * 自动生成写入时间
  15. * @var bool
  16. */
  17. protected $autoWriteTimestamp = true;
  18. /**
  19. * 根据手机号获取用户信息
  20. * @param $phoneNumber
  21. * @return array|bool|Model|null
  22. * @throws \think\db\exception\DataNotFoundException
  23. * @throws \think\db\exception\DbException
  24. * @throws \think\db\exception\ModelNotFoundException
  25. */
  26. public function getUserByPhoneNumber($phoneNumber)
  27. {
  28. if (empty($phoneNumber)) {
  29. return false;
  30. }
  31. $where = [
  32. 'phone_number' => $phoneNumber
  33. ];
  34. return $this->where($where)->find();
  35. }
  36. /**
  37. * 根据主键id更新数据表中的数据
  38. * @param $id
  39. * @param $data
  40. * @return bool
  41. */
  42. public function updateById($id, $data)
  43. {
  44. $id = (int)$id;
  45. if (empty($id) || empty($data) || !is_array($data)) {
  46. return false;
  47. }
  48. $where = [
  49. 'id' => $id,
  50. ];
  51. return $this->where($where)->save($data);
  52. }
  53. }