123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- /**
- * Created by PhpStorm.
- * User: zilongs
- * Date: 20-9-23
- * Time: 上午11:04
- */
- namespace App\Models;
- class User extends BaseModel
- {
- protected $table = 'users';
- public function patients()
- {
- return $this->hasMany(Patient::class);
- }
- public function order()
- {
- return $this->hasMany(Order::class);
- }
- //通过token获取用户信息
- public static function getUserByToken()
- {
- $auth = request()->header('token');
- if (empty($auth)) {
- exit_out(null, 401, '认证失效,请重新登录');
- }
- $arr = aes_decrypt($auth);
- if (isset($arr['doctor_id'])){
- // 说明是医生登陆!
- if (empty($arr['doctor_id'])) {
- exit_out(null, 401, '认证失效,请重新登录');
- }
- $user = Docter::where('id', $arr['doctor_id'])->first();
- if (empty($user)){
- exit_out(null, 601, '该账号已被删除');
- }
- $user = $user->toArray();
- // if ($user['status'] == 0){
- // exit_out(null, 602, '该账号已被冻结');
- // }
- return $user;
- }else{
- if (empty($arr['id'])) {
- exit_out(null, 401, '认证失效,请重新登录');
- }
- $user = User::where('id', $arr['id'])->first();
- if (empty($user)){
- exit_out(null, 601, '该账号已被删除');
- }
- $user = $user->toArray();
- if ($user['status'] == 0){
- exit_out(null, 602, '该账号已被冻结');
- }
- return $user;
- }
- }
- /**
- * 用户医生关注表
- * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
- * @author Liu-Yh
- * Create By 2020/11/18 11:06
- */
- public function userDorter(){
- return $this->hasOne(UserDocter::class,'user_id','id')->select(['id', 'remark']);;
- }
- //改变用户余额
- public static function changeBalance($user_id, $change_balance, $type, $relation_id, $remark, $admin_user_id = 0)
- {
- $user = User::select(['balance'])->where('id', $user_id)->first();
- User::where('id', $user_id)->increment('balance', $change_balance);
- UserBalanceLog::create([
- 'user_id' => $user_id,
- 'admin_user_id' => $admin_user_id,
- 'type' => $type,
- 'relation_id' => $relation_id,
- 'before_balance' => $user['balance'],
- 'change_balance' => $change_balance,
- 'after_balance' => $user['balance'] + $change_balance,
- 'remark' => $remark,
- ]);
- return true;
- }
- }
|