load->library('session'); $this->load->_model('Model_goodimgs','goodimgs'); } private $show_url = "https://lyerposs.wepolicy.cn"; public function _remap($arg,$arg_array) { if($arg=="detail"){ //$this->_detial($arg_array); }elseif($arg=="edit"){ $this->_editData($arg_array); }else{ $this->_index(); } } private function _index(){ if($this->input->method() == 'post'){ $page = $this->input->post('page',true); $perpage = $this->input->post('perpage',true); $title = $this->input->post('title',true); $zh= $this->input->post('zh',true); if(empty($page)) { $start = 0; $perpage = 1; } else { $start = ($page - 1)*$perpage; } $this->db->select('g.id, g.features, g.title, g.sku, g.zh, g.jm, gi.id as img_id, gi.source_cont'); $this->db->from('crowd_goods as g'); $this->db->join('crowd_goodimgs as gi', 'g.id = gi.goods_id', 'left'); if($title){ $title = trim($title); $this->db->like('g.title', $title); } if($zh){ $zh = trim($zh); $this->db->like('g.zh', $zh); } $this->db->order_by('g.id', 'asc'); // 分页 (limit, offset) $this->db->limit($perpage, $start); $query = $this->db->get(); $list = $query->result_array(); $info_list = []; foreach($list as $k => $v){ $info_list[$k]['id'] = $v['id']; $info_list[$k]['sku'] = $v['sku']; $info_list[$k]['title'] = $v['title']; $info_list[$k]['zh'] = $v['zh']; //$info_list[$k]['jm'] = $v['jm']; $info_list[$k]['imgs'] = $this->transimg($v['source_cont']); } $this->db->from('crowd_goods'); if($title){ $title = trim($title); $this->db->like('title', $title); } if($zh){ $zh = trim($zh); $this->db->like('zh', $zh); } $total = $this->db->count_all_results(); $pagenum = ceil($total/$perpage); $over = $total-($start+$perpage); $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list)); echo json_encode($rows);exit; }else{ $this->_Template('goodimglibrary',$this->data); } } private function transimg($source_cont){ $str = ' '; if(!empty($source_cont)){ $imgs = json_decode($source_cont,true); foreach($imgs as $k => $v){ $type = $this->_checkVideo($v); if($type == "video"){ $str.= ''; }else{ $str .= 'image'; } } } return$str; } private function _editData($arg_array){ if($this->input->method() == 'post'){ $id = $this->input->post('id',true); $img = $this->input->post('img',true); if(empty($img)){ $img = []; } foreach($img as $k => $v){ $img[$k] = str_replace($this->show_url, '', $v); } $info = $this->db->get_where('crowd_goods',array('id'=>$id))->row_array(); $images = $this->goodimgs->find("goods_id = ".$id); if(empty($images)){ if($this->goodimgs->insert(array('goods_id'=>$id,'features'=>$info['features'],'source_cont'=>json_encode($img,JSON_UNESCAPED_SLASHES)))){ echo json_encode(array('msg'=>'修改成功','success'=>true));exit; }else{ echo json_encode(array('msg'=>'修改失败,请重试1','success'=>false));exit; } }else{ if($this->goodimgs->save(array('features'=>$info['features'],'source_cont'=>json_encode($img,JSON_UNESCAPED_SLASHES)),$images['id'])){ echo json_encode(array('msg'=>'修改成功','success'=>true));exit; }else{ echo json_encode(array('msg'=>'修改失败,请重试2','success'=>false));exit; } } } if($this->input->method() == 'get'){ $id = $arg_array[0]; $goods = $this->db->get_where('crowd_goods',array('id'=>$id))->row_array(); $this->db->where('goods_id',$id); $images = $this->db->get('crowd_goodimgs')->result_array(); if(empty($images)){ $goods['images'] = []; }else{ $imgs = json_decode($images[0]['source_cont'],true); $final_imgs = []; foreach($imgs as $k => $v){ $final_imgs[$k]['url'] = $this->_transingurl($v); $final_imgs[$k]['type'] = $this->_checkVideo($v); } $goods['images'] = $final_imgs; } $this->data['goods'] = $goods; $this->_Template('goodimglibrary_edit',$this->data); } } //根据后缀判断是否是视频 private function _checkVideo($str){ $hz_arr = explode(".",$str); $hz = end($hz_arr); if(in_array($hz,['mp4','flv','rmvb','avi','wmv','mov','rm','mkv'])){ return "video"; } return "img"; } private function _transingurl($url){ $url_arr = explode('/', $url); $filename = array_pop($url_arr); $filename = rawurlencode($filename); $url_arr[] = $filename; $final_url = implode('/', $url_arr); $final_url = $this->show_url.$final_url; return $final_url; } }