Ejemplo n.º 1
0
 private function delChildClassify($c_id)
 {
     $cus_id = Auth::id();
     $del_imgs = array();
     $child_ids = Classify::where('p_id', $c_id)->where('cus_id', $cus_id)->lists('id');
     if (count($child_ids)) {
         foreach ($child_ids as $id) {
             $classify = Classify::find($id);
             $c_del_img = $classify->img;
             $ids = Articles::where('c_id', $id)->lists('id');
             $a_del_imgs = Articles::where('c_id', $id)->lists('img');
             if (count($ids)) {
                 $m_del_imgs = MoreImg::whereIn('a_id', (array) $ids)->lists('img');
             } else {
                 $m_del_imgs = array();
             }
             $del_imgs = array_merge((array) $a_del_imgs, (array) $m_del_imgs);
             Classify::where('id', $id)->where('cus_id', $cus_id)->delete();
             Articles::where('c_id', $id)->where('cus_id', $cus_id)->delete();
             foreach ((array) $del_imgs as $val) {
                 $imgdel = new ImgDel();
                 $imgdel->mysave($val);
             }
             $imgdel = new ImgDel();
             $imgdel->mysave($c_del_img, 'category');
             $this->delMobileHomepage($id);
             $this->delChildClassify($id);
         }
     }
 }
Ejemplo n.º 2
0
 public function articleDelete()
 {
     $del_imgs = array();
     $cus_id = Auth::id();
     $ids = explode(',', Input::get('id'));
     if (count($ids) > 1) {
         //执行批量删除
         $failed = 0;
         foreach ($ids as $id) {
             $article = Articles::find($id);
             Classify::where('cus_id', $cus_id)->where('id', $article->c_id)->update(['pushed' => 1]);
             $data = MoreImg::where('a_id', $id)->get()->toArray();
             $result = Articles::where('id', '=', $id)->delete();
             if (!$result) {
                 $failed++;
             } else {
                 foreach ((array) $data as $v) {
                     $del_imgs[] = $v["img"];
                 }
                 $del_imgs[] = $article->img;
             }
         }
         foreach ((array) $del_imgs as $v) {
             $imgdel = new ImgDel();
             $imgdel->mysave($v, 'articles');
         }
         if ($failed) {
             $return_msg = array('err' => 3001, 'msg' => $failed . '条记录删除失败');
         } else {
             $return_msg = array('err' => 0, 'msg' => '');
         }
     } else {
         //单条删除
         $article = Articles::find($ids[0]);
         Classify::where('cus_id', $cus_id)->where('id', $article->c_id)->update(['pushed' => 1]);
         $data = MoreImg::where('a_id', $ids[0])->get()->toArray();
         $result = Articles::where('id', '=', $ids[0])->delete();
         if ($result) {
             foreach ((array) $data as $v) {
                 $del_imgs[] = $v["img"];
             }
             $del_imgs[] = $article->img;
             foreach ((array) $del_imgs as $v) {
                 $imgdel = new ImgDel();
                 $imgdel->mysave($v, 'articles');
             }
             $return_msg = array('err' => 0, 'msg' => '');
         } else {
             $return_msg = array('err' => 3001, 'msg' => '文章删除失败');
         }
     }
     return Response::json($return_msg);
 }
Ejemplo n.º 3
0
 public function articleAdd()
 {
     $id = Input::get('id');
     if ($id) {
         //修改操作
         $article = Articles::find($id);
     } else {
         //新增操作
         $article = new Articles();
     }
     $cus_id = Auth::id();
     $article->title = trim(Input::get('title'));
     $article->c_id = Input::get('c_id');
     $article->viewcount = Input::get('viewcount') ? Input::get('viewcount') : 0;
     $article->title_bold = Input::get('title_bold');
     $article->title_color = Input::get('title_color');
     $article->keywords = Input::get('keywords');
     $article->introduction = Input::get('introduction');
     $article->content = trim(Input::get('content'));
     if ($article->title == "" || $article->content == "") {
         return Response::json(array('err' => 3001, 'msg' => '标题或内容不能为空'));
     }
     $article->pushed = 1;
     $img_arr = explode(',', Input::get('src'));
     if (count($img_arr)) {
         $article->img = $img_arr[0];
         unset($img_arr[0]);
     }
     $is_show = empty(Input::get('is_show')) ? array() : explode(',', Input::get('is_show'));
     $article->pc_show = 0;
     $article->mobile_show = 0;
     $article->wechat_show = 0;
     if (count($is_show)) {
         foreach ($is_show as $val) {
             $article->{$val} = 1;
         }
     }
     $pubdate = Input::get('pubdate');
     if ($pubdate) {
         $article->created_at = date('Y-m-d H:i:s', strtotime($pubdate));
     }
     $article->cus_id = $cus_id;
     $result = $article->save();
     if ($result) {
         if ($id) {
             MoreImg::where('a_id', $id)->delete();
         }
         if (count($img_arr)) {
             foreach ($img_arr as $img) {
                 $moreimg = new Moreimg();
                 $moreimg->title = '';
                 $moreimg->img = $img;
                 $moreimg->url = '';
                 $moreimg->sort = '';
                 $moreimg->a_id = $article->id;
                 $moreimg->save();
             }
         }
         $return_msg = array('err' => 0, 'msg' => '', 'data' => array($article->id));
     } else {
         $return_msg = array('err' => 3001, 'msg' => '文章添加失败');
     }
     return Response::json($return_msg);
 }