query('set SESSION sql_mode =\'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION \';'); //修改sql_mode only_full_group_by } /** * 初始化处理 * * @author liuns@dianzhong.com * @date 2018-08-22 11:28:46 * @access protected * @return void */ protected static function init() { } /** * 关联短链接域名表 * * @author liues@dianzhong.com * @date 2018-08-16 11:20:57 * @return $this */ public function domain(){ return $this->hasOne(ShortDomain::class, 'id', 'domain_id', [], 'LEFT'); } /** * 关联 渠道商/代理商信息 * * @author liues@dianzhong.com * @date 2018-08-16 13:07:55 * @return \think\model\relation\HasOne */ public function admin(){ return $this->hasOne(Admin::class, 'id', 'admin_id', [], 'LEFT'); } /** * 检测是渠道否有关联 * @param $channel_id * @return bool * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function checkChannelRelation($channel_id){ if($relation = $this->where(['admin_id'=>$channel_id])->find()){ return true; }else{ return false; } } /** * 随机读取渠道商绑定的短链域名 * * @param $admin_id * @return mixed|string */ public function getRandShort($admin_id){ $ids = $this->alias('sr')->field('sd.*') ->join('admin_config ac', 'ac.admin_id=sr.admin_id') ->join('short_domain sd', 'sd.id=sr.domain_id') ->where(['ac.guide_domain'=>'1', 'sr.admin_id'=>$admin_id, 'sd.status'=>'1']) ->select(); return $ids ? $ids[array_rand($ids)] : ''; } /** * 获取渠道/代理商关联的域名数量 * @param int $admin_id * @return int|string */ public function getRelationCount($admin_id){ return $this->alias('sr') ->join('short_domain sd','sd.id=sr.domain_id', 'LEFT') ->where(['sd.status'=>'1','sr.admin_id'=>$admin_id]) ->count(); } }