public function insert_data($app, $file, $file_info) { //先判断APP 是否存在,不存在新建APP $conditions = " app_name = :app_name: "; $parameters = array("app_name" => $app); $db_app = MeiuiApp::findFirst(array($conditions, "bind" => $parameters)); if (!$db_app) { $db_app = new MeiuiApp(); $db_app->app_name = $app; $db_app->create_user = $_SESSION['auth']['id']; $db_app->create_time = time(); $db_app->save(); } //再判断PIC 是否存在,不存在新建PIC $tags = explode('.', $file); $pic_url = 'http://img.meiui.me' . $_POST['img_url']; $conditions = " pic_url = :pic_url: "; $parameters = array("pic_url" => $pic_url); $db_pic = MeiuiPic::findFirst(array($conditions, "bind" => $parameters)); if (!$db_pic) { $db_pic = new MeiuiPic(); $db_pic->app_id = $db_app->id; $db_pic->app_name = $db_app->app_name; $db_pic->pic_url = $pic_url; $db_pic->pic_w = $file_info[0]; $db_pic->pic_h = $file_info[1]; $db_pic->brief = 'brief default tag ' . $app . ',' . $tags[0]; $db_pic->create_user = $_SESSION['auth']['id']; $db_pic->create_time = time(); $db_pic->save(); } // 判断标签 不存在则插入 $all_tag = explode(',', $tags[0]); $all_tag[] = $app; foreach ($all_tag as $one_tag) { $this->insert_tag_link_pic($one_tag, $db_pic->id); } $alert_message = "添加成功 <br/>APP:" . $app . '<br/>标签:' . $tags[0] . '<br/>url:' . $pic_url; $this->flash->notice($alert_message); }
public function insert_data($app, $file, $file_info) { //先判断APP 是否存在,不存在新建APP $conditions = " app_name = :app_name: "; $parameters = array("app_name" => $app); $db_app = MeiuiApp::findFirst(array($conditions, "bind" => $parameters)); if (!$db_app) { $db_app = new MeiuiApp(); $db_app->app_name = $app; $db_app->create_user = $_SESSION['auth']['id']; $db_app->create_time = time(); $db_app->save(); } //再判断PIC 是否存在,不存在新建PIC $tags = explode('.', $file); $pic_url = '52.68.155.92/load/init_data/APP/' . $app . '/' . $file; $conditions = " pic_url = :pic_url: "; $parameters = array("pic_url" => $pic_url); $db_pic = MeiuiPic::findFirst(array($conditions, "bind" => $parameters)); if (!$db_pic) { $db_pic = new MeiuiPic(); $db_pic->app_id = $db_app->id; $db_pic->app_name = $db_app->app_name; $db_pic->pic_url = $pic_url; $db_pic->pic_w = $file_info[0]; $db_pic->pic_h = $file_info[1]; $db_pic->brief = 'brief default tag ' . $app . ',' . $tags[0]; $db_pic->create_user = $_SESSION['auth']['id']; $db_pic->create_time = time(); $db_pic->save(); } // 判断标签 不存在则插入 $all_tag = explode(',', $tags[0]); $all_tag[] = $app; foreach ($all_tag as $one_tag) { $this->insert_tag_link_pic($one_tag, $db_pic->id); } }