| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 | 
							- <?php
 
- namespace App\Repositories;
 
- use App\Models\Member;
 
- use App\Models\MemberInfo;
 
- use App\Models\Resume;
 
- use App\Validators\Rules\MobileRule;
 
- use Illuminate\Support\Facades\DB;
 
- use Illuminate\Support\Facades\Hash;
 
- use Illuminate\Support\Facades\Schema;
 
- use Prettus\Repository\Eloquent\BaseRepository;
 
- use Prettus\Repository\Criteria\RequestCriteria;
 
- /**
 
-  * Class MemberRepositoryEloquent.
 
-  *
 
-  * @package namespace App\Repositories;
 
-  */
 
- class MemberRepository extends BaseRepository
 
- {
 
-     /**
 
-      * Specify Model class name
 
-      *
 
-      * @return string
 
-      */
 
-     public function model()
 
-     {
 
-         return Member::class;
 
-     }
 
-     
 
-     /**
 
-      * Boot up the repository, pushing criteria
 
-      */
 
-     public function boot()
 
-     {
 
-         $this->pushCriteria(app(RequestCriteria::class));
 
-     }
 
-     /**
 
-      * @param $account string
 
-      * @return null|Member
 
-      */
 
-     public function getMemberByAccount($account)
 
-     {
 
-         if (validator_check($account, 'email')) {
 
-             return $this->model->where('email', $account)->first();
 
-         }
 
-         if (validator_check($account, new MobileRule())) {
 
-             return $this->model->where('mobile', $account)->first();
 
-         }
 
-         if (isCreditNo($account)) {
 
-             $member_info = MemberInfo::where('id_card', $account)->first();
 
-             if (!$member_info) {
 
-                 return null;
 
-             }
 
-             return $member_info->members;
 
-         }
 
-         return $this->model->where('username', $account)->first();
 
-     }
 
-     /**
 
-      * @param $id
 
-      * @return object
 
-      */
 
-     public function getMemberById($id)
 
-     {
 
-         return $this->model->find($id);
 
-     }
 
-     public function updatePasswordById($password, $id)
 
-     {
 
-         return $this->model->where(['id'=>$id])->update(['password'=>$password]);
 
-     }
 
-     public function getFields($id, $field = ['*'])
 
-     {
 
-         return $this->model->where('id', $id)->select($field)->first();
 
-     }
 
-     public function updateInfo($id, $date)
 
-     {
 
-         return $this->model->where('id', $id)->update($date);
 
-     }
 
-     public function updateLoginStatus($member)
 
-     {
 
-         $member->last_login_ip=ip2long(request()->ip);
 
-         $member->last_login_time=time();
 
-         $member->save();
 
-     }
 
-     /**
 
-      * 检查字段惟一
 
-      * @param $key
 
-      * @param $value
 
-      * @param int $id 大于0表示排除自身
 
-      * @return bool
 
-      */
 
-     public function checkUniaue($key, $value, $id = 0)
 
-     {
 
-         if (!Schema::hasColumn($this->model->getTable(), $key)) {
 
-             return true;
 
-         }
 
-         if ($this->model->withTrashed()->where($key, $value)
 
-             ->when($id>0, function ($query) use ($id) {
 
-                 return $query->where('id', '<>', $id);
 
-             })->first()) {
 
-             return false;
 
-         }
 
-         return true;
 
-     }
 
-     /**
 
-      * 重置密码
 
-      * @param $type :mobile, email
 
-      * @param $value :对应type
 
-      * @param $password
 
-      */
 
-     public function resetPassword($type, $value, $password)
 
-     {
 
-         $this->model->where($type, $value)->update(['password'=>Hash::make($password)]);
 
-         return $this->model->where($type, $value)->first();
 
-     }
 
-     public function getLastPersonCount($where)
 
-     {
 
-         return $this->model->where($where)->where('created_at', '>=', date('Y-m-01 00:00:00', strtotime('-1 month')))->where('created_at', '<=', date("Y-m-d 23:59:59", strtotime(-date('d').'day')))->count();
 
-     }
 
-     public function getNextPersonCount($where)
 
-     {
 
-         return $this->model->where($where)->where('created_at', '>=', date('Y-m-01 00:00:00', strtotime(date("Y-m-d"))))->where('created_at', '<=', date('Y-m-d 23:59:59', strtotime(date('Y-m-01', strtotime(date("Y-m-d")))." +1 month -1 day")))->count();
 
-     }
 
-     public function getPersonCount($where)
 
-     {
 
-         return $this->model->where($where)->count();
 
-     }
 
-     public function getMemberNumByTime($where, $time_condition)
 
-     {
 
-         return $this->model->where($where)->where(function ($query) use ($time_condition) {
 
-             if ($time_condition) {
 
-                 $query->Where([['last_login_time', '>=',strtotime($time_condition[0])],['last_login_time', '<=',strtotime($time_condition[1])]])->orWhere([['updated_at', '>=',strtotime($time_condition[0])],['updated_at', '<=',strtotime($time_condition[1])]]);
 
-             }
 
-         })->count();
 
-     }
 
-     public function getJobSeekersByGroup($where, $where_str, $fields, $group_by)
 
-     {
 
-         return DB::table(Resume::getTableName().' as r')
 
-                     ->select(DB::raw($fields))
 
-                     ->leftjoin(MemberInfo::getTableName().' as mi', 'mi.uid', '=', 'r.uid')
 
-                     ->leftjoin(Member::getTableName().' as m', 'm.id', '=', 'mi.uid')
 
-                     ->where($where)
 
-                     ->whereRaw($where_str)
 
-                     ->groupBy($group_by)
 
-                     ->get();
 
-     }
 
- }
 
 
  |