| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- <?php defined('BASEPATH') OR exit('No direct script access allowed');
- class Goodimglibrary extends Start_Controller {
- public function __construct(){
- parent::__construct();
- $this->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){
- $this->db->like('g.title', $title);
- }
- if($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){
- $this->db->like('title', $title);
- }
- if($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.= '<video controls="true" width="100" src="'.$this->show_url.$v.'" alt="video image" style="margin-right:3px;"></video>';
- }else{
- $str .= '<img width="100px" src="'.$this->show_url.$v.'" alt="image" style="margin-right:3px;">';
- }
- }
-
- }
- 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)))){
- 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)),$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->show_url.$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";
- }
-
- }
|