where(['game_id'=>$game_id,'channel_id'=>$channel_id,'package_type'=>$package_type, 'type' => $type])->find()){ $this->insert(['game_id'=> $game_id,'channel_id'=> $channel_id,'package_type'=>$package_type,'create_time'=>time(),'short_link'=>$this->createShortLink(), 'type' => $type]); return true; } else{ return false; } } /** * 生成推广落地页短链接参数字段值 */ private function createShortLink() { $shortLink = strtolower(random(7)); while ($this->field('id')->where(['short_link' => $shortLink])->find()) { $shortLink = strtolower(random(7)); if (preg_match('/^\d+$/', $shortLink)) { $shortLink = strtolower(random(7)); } } return $shortLink; } }