<?php 
namespace app\common\model;
use think\Model;
use think\facade\Db;
use app\common\model\Company as CompanyModel;
use app\common\model\CompanyView as CompanyViewModel;
class CompanyBrowse extends Model
{
	public static function saveBrowse($User,$id):void
	{
		$CompanyViewModel=CompanyViewModel::where(['company_id'=>$id])->whereDay('create_time')->find();
		if (!$CompanyViewModel) $CompanyViewModel=new CompanyViewModel;
        $view_rand=intval(config('basic.view_rand'));
        $view=1;
        if ($view_rand)
        $view=rand(1,$view_rand);
		$CompanyViewModel->company_id=$id;
		$CompanyViewModel->view=Db::raw('view+'.$view);
		if(!empty($User['uid'])){
			if (!empty($User['resume_id'])&&$id){
				if (!self::where(['resume_id'=>$User['resume_id'],'company_id'=>$id])->whereNull('delete_time')->count()) {
					$CompanyBrowseModel=new self;
					$CompanyBrowseModel->resume_id=$User['resume_id'];
					$CompanyBrowseModel->company_id=$id;
					$CompanyBrowseModel->save();
				}
			}
			$CompanyViewModel->user_view=Db::raw('user_view+1');
			if(!empty($User['role_type'])){
				$CompanyViewModel->company_view=Db::raw('company_view+1');
			}else{
				$CompanyViewModel->personal_view=Db::raw('personal_view+1');
			}
		}
		CompanyModel::where(['id'=>$id])->inc('view',$view)->update();
		$CompanyViewModel->save();
	}
}