123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- /**
- * Created by PhpStorm
- * User:林志杰
- * Email:[email protected]
- * Motto:纵有疾风起,人生不言弃!
- * Time:2020/1/3 0:29
- */
- namespace app\common\model\mysql;
- use think\Model;
- class User extends Model
- {
- /**
- * 自动生成写入时间
- * @var bool
- */
- protected $autoWriteTimestamp = true;
- /**
- * 根据手机号获取用户信息
- * @param $phoneNumber
- * @return array|bool|Model|null
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getUserByPhoneNumber($phoneNumber)
- {
- if (empty($phoneNumber)) {
- return false;
- }
- $where = [
- 'phone_number' => $phoneNumber
- ];
- return $this->where($where)->find();
- }
- /**
- * 通过id获取用户数据
- * @param int $id
- * @return array|bool|Model|null
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getUserById(int $id)
- {
- if (!$id) {
- return false;
- }
- return $this->find($id);
- }
- /**
- * 根据主键id更新数据表中的数据
- * @param $id
- * @param $data
- * @return bool
- */
- public function updateById($id, $data)
- {
- $id = (int)$id;
- if (empty($id) || empty($data) || !is_array($data)) {
- return false;
- }
- $where = [
- 'id' => $id,
- ];
- return $this->where($where)->save($data);
- }
- }
|