123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- <?php
- namespace App\Repositories;
- use App\Exceptions\ResponseException;
- use App\Models\Category;
- use App\Models\Company;
- use App\Models\MembersLog;
- use App\Validators\Rules\MobileRule;
- use Illuminate\Container\Container as Application;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\Hash;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Schema;
- use Prettus\Repository\Eloquent\BaseRepository;
- use Prettus\Repository\Criteria\RequestCriteria;
- use Illuminate\Support\Facades\DB;
- class CompanyRepository extends BaseRepository
- {
- /**
- * Specify Model class name
- *
- * @return string
- */
- protected $membersSetmealLogRepository;
- public function __construct(Application $app,MembersSetmealLogRepository $membersSetmealLogRepository)
- {
- $this->membersSetmealLogRepository=$membersSetmealLogRepository;
- parent::__construct($app);
- }
- public function model()
- {
- return Company::class;
- }
- /**
- * Boot up the repository, pushing criteria
- */
- public function boot()
- {
- $this->pushCriteria(app(RequestCriteria::class));
- }
- /**
- * @param array $column
- * @return mixed
- */
- public function getCompanyColumn($id, $column = ['*'])
- {
- return $this->model->where('id', $id)->select($column)->first()->toArray();
- }
- public function auth()
- {
- return $this->find(auth('web-company')->user()->id, ['audit']);
- }
- public function getCompanyInfoByID($id)
- {
- $companyInfo = $this->model->find($id, ['*']);
- if (!$companyInfo) {
- throw new ResponseException('参数错误', '400');
- }
- $tag = Category::categoryType('AIX_jobtag');//这个要改
- $companyInfo->tag1 = implode(',', $companyInfo->tag);
- foreach ($companyInfo->tag as $val) {
- if ($val) {
- $companyInfo->tag_cn.=$tag[$val].',';
- }
- }
- $landline = $companyInfo->landline_tel?explode('-', $companyInfo->landline_tel):array();
- if (is_array($landline)) {
- $companyInfo->landline_first = isset($landline[0]) ? ($landline[0] == 0 ? '' : $landline[0]) : "";
- $companyInfo->landline_next = isset($landline[1]) ? ($landline[1] == 0 ? '' : $landline[1]) : "";
- $companyInfo->landline_last = isset($landline[2]) ? ($landline[2] == 0 ? '' : $landline[2]) : "";
- }
- return $companyInfo;
- }
- /**
- * 企业保存
- * @param $data
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function companySave($data, $id)
- {
- return $this->update($data, $id);
- }
- /**
- * @param array $data 需要修改的字段
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function save($data, $id)
- {
- return $this->update($data, $id);
- }
- public function modifyJobsNum($uid, $type, $count)
- {
- switch ($type) {
- case 1:
- $increment = 'increment';
- break;
- case 2:
- $increment = 'decrement';
- break;
- }
- return $this->model->where('id', $uid)->$increment('jobs', $count);
- }
- public function verifyCode($data, $id)
- {
- return $this->update($data, $id);
- }
- /**
- * @param $account string
- * @return null|Company
- */
- public function getCompanyByAccount($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();
- }
- return $this->model->where('username', $account)->orWhere('organization_code', $account)->first();
- }
- //获取企业信息
- public function getCompanyInfo($where)
- {
- return $this->model->where($where)->first();
- }
- //获取指定行业的企业
- public function getTradeCompanies($where, $trades = array(), $field = '*', $order = 'refresh_time desc', $limit = '10')
- {
- if ($trades) {
- return $this->model->select(DB::raw($field))->where($where)->whereIn('trade', $trades)->orderByRaw($order)->limit($limit)->get();
- } else {
- return $this->model->select(DB::raw($field))->where($where)->orderByRaw($order)->limit($limit)->get();
- }
- }
- public function updataSmsNum($uid, $type, $num)
- {
- if ($type == 1) {
- $action = 'increment';
- } else {
- $action = 'decrement';
- }
- return $this->model->where('id', $uid)->$action('sms_num', $num);
- }
- public function SetSmsNum($uid,$vaule)
- {
- return $this->model->where('id', $uid)->update(['sms_num'=> $vaule]);
- }
- public function updateLoginStatus($company)
- {
- $company->last_login_ip=ip2long(request()->ip);
- $company->last_login_time=time();
- $company->refresh_time=time();
- $company->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;
- }
- public function changeEmail($id, $email)
- {
- $this->model->where('id', $id)->update(['email'=>$email, 'email_audit'=>1]);
- }
- /**
- * 重置密码
- * @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 getLastCompanyCount($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 getNextCompanyCount($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 getCompanyCount($where)
- {
- return $this->model->where($where)->count();
- }
- public function getCompanyNumByTime($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([['refresh_time', '>=',strtotime($time_condition[0])],['refresh_time', '<=',strtotime($time_condition[1])]]);
- }
- })->count();
- }
- public function getAuditCount($where)
- {
- return $this->model->where($where)->count();
- }
- public function getCompanyies($where = array(), $whereIn = array(), $order = array())
- {
- $rst = $this->model->where($where);
- if ($whereIn) {
- foreach ($whereIn as $k => $v) {
- $rst->whereIn($k, $v);
- }
- }
- if ($order && is_array($order)) {
- foreach ($order as $k => $v) {
- $rst->orderBy($k, $v);
- }
- }
- return $rst->get();
- }
- public function getCompanyNumsByGroup($where, $fields, $group_by = '')
- {
- $rst = $this->model->select(DB::raw($fields))->where($where);
- if ($group_by) {
- $rst->groupBy($group_by);
- }
- return $rst->get();
- }
- //短信数量--
- public function SetSmsReduce($user_id){
- $user=$this->model->find($user_id);
- $isOk=$this->model->where('id',$user->id)->update(['sms_num'=>$user->sms_num-1]);
- $this->membersSetmealLogRepository->createLog($user,"扣除了短信",$user->sms_num-1);
- return $isOk;
- }
- //批量修改企业信息
- public function updateCompanies($where, $whereIn, $data)
- {
- $rst = $this->model->where($where);
- if ($whereIn) {
- foreach ($whereIn as $k => $v) {
- $rst->whereIn($k, $v);
- }
- }
- return $rst->update($data);
- }
- }
|