Beispiel #1
0
 public function delete($id)
 {
     if (!$id) {
         echo json_encode(array('code' => '1003', 'msg' => '参数错误'));
         exit;
     }
     if ($this->product->delete($id)) {
         $data = array('code' => '1000', 'msg' => '删除成功', 'data' => array('id' => $id));
         @unlink(upload_folder('product') . DIRECTORY_SEPARATOR . file_save_dir($id) . DIRECTORY_SEPARATOR . file_save_name($id) . '.png');
         @unlink(upload_folder('product') . DIRECTORY_SEPARATOR . file_save_dir($id) . DIRECTORY_SEPARATOR . file_save_name($id) . '_thumb.png');
     } else {
         $data = array('code' => '1001', 'msg' => '删除失败');
     }
     echo json_encode($data);
 }
Beispiel #2
0
 /**
  *   取商品图片
  *   @param int id 商品ID
  *   @param var type 类型
  */
 public function pic($id = '', $sort = 1, $type = 'big')
 {
     $filePath = $file_save_dir = $file_save_name = '';
     $folder = upload_folder('product');
     if ($id) {
         $file_save_dir = file_save_dir($id);
         $file_save_name = file_save_name($id);
     }
     switch ($type) {
         case 'small':
         case 'thumb':
             $filePath = $folder . '/' . $file_save_dir . '/' . $file_save_name . '_' . $sort . '_thumb.png';
             $default = base_url() . 'assets/img/product/p-default_thumb.png';
             break;
         case 'big':
         case 'default':
         default:
             $filePath = $folder . '/' . $file_save_dir . '/' . $file_save_name . '_' . $sort . '.png';
             $default = base_url() . 'assets/img/product/p-default.png';
             break;
     }
     if (file_exists($filePath)) {
         return base_url() . $filePath . '?' . rand();
     } else {
         return $default;
     }
     return false;
 }
Beispiel #3
0
 public function pic($id)
 {
     $this->config->load('upload');
     $folder = $this->config->item('ad_folder');
     $file_save_dir = file_save_dir($id);
     $file_save_name = file_save_name($id);
     if (is_file($folder . DIRECTORY_SEPARATOR . $file_save_dir . DIRECTORY_SEPARATOR . $file_save_name . '.png')) {
         return base_url() . $folder . '/' . $file_save_dir . '/' . $file_save_name . '.png';
     }
     return base_url() . 'assets/img/ad.jpg';
 }
Beispiel #4
0
 public function update()
 {
     $post = $this->input->post();
     if (empty($post)) {
         show_error('参数错误');
     }
     $data = array('code' => '1000', 'msg' => '');
     $this->load->library('form_validation');
     $this->form_validation->set_rules('name', ' ', 'required|max_length[50]');
     $this->form_validation->set_rules('info', ' ', 'max_length[100]');
     if ($this->form_validation->run() == FALSE) {
         $this->form_validation->set_error_delimiters('', '');
         $data['code'] = '1010';
         $error['name'] = form_error('name');
         $error['info'] = form_error('info');
         $data['msg'] = $this->lang->line('error_msg');
         $data['error'] = $error;
         echo json_encode($data);
         exit;
     }
     $error = array();
     if ($post['id']) {
         $where = array('name' => trim($post['name']), 'id !=' => $post['id']);
         if ($this->product_brand->exist($where)) {
             $error['name'] = '名称已存在';
         }
     } else {
         $where = array('name' => trim($post['name']));
         if ($this->product_brand->exist($where)) {
             $error['name'] = '名称已存在';
         }
     }
     if (!empty($error)) {
         echo json_encode(array('code' => '1010', 'msg' => $this->lang->line('error_msg'), 'error' => $error));
         exit;
     }
     $row = array('name' => trim($post['name']), 'info' => trim($post['info']), 'product_cate_id' => trim($post['product_cate_id']));
     if ($post['id']) {
         if (!$this->product_brand->update($row, $post['id'])) {
             $data = array('code' => '1001', 'msg' => $this->lang->line('update_fail'));
         }
         $id = $post['id'];
     } else {
         if (!($id = $this->product_brand->insert($row))) {
             $data = array('code' => '1001', 'msg' => $this->lang->line('add_fail'));
         }
     }
     if ($data['code'] == '1000') {
         $data['goto'] = 'admin/product_brands';
         //处理图片
         if ($post['link_pic_path'] && is_file(upload_folder('temp') . DIRECTORY_SEPARATOR . $post['link_pic_path'])) {
             $target = upload_folder('product_brand') . DIRECTORY_SEPARATOR . file_save_dir($id);
             create_folder($target);
             $config['image_library'] = 'gd2';
             $config['source_image'] = upload_folder('temp') . DIRECTORY_SEPARATOR . $post['link_pic_path'];
             $config['create_thumb'] = false;
             $config['maintain_ratio'] = TRUE;
             $config['new_image'] = $target . DIRECTORY_SEPARATOR . file_save_name($id) . '.png';
             $config['width'] = 120;
             $config['height'] = 80;
             $this->load->library('image_lib', $config);
             $this->image_lib->resize();
             @unlink($config['source_image']);
         }
     }
     echo json_encode($data);
 }
Beispiel #5
0
 /**
  * 上传用户头像
  * 
  */
 public function upload_pic()
 {
     $post = $this->input->post();
     $id = $this->auth->user_id();
     $data = array('code' => '1000', 'msg' => '');
     if (empty($post) && !$id) {
         show_error('参数错误');
     }
     //处理图片
     if ($post['user_pic_path'] && is_file(upload_folder('temp') . DIRECTORY_SEPARATOR . $post['user_pic_path'])) {
         $target = upload_folder('user') . DIRECTORY_SEPARATOR . file_save_dir($id);
         create_folder($target);
         $config['image_library'] = 'gd2';
         $config['source_image'] = upload_folder('temp') . DIRECTORY_SEPARATOR . $post['user_pic_path'];
         $config['create_thumb'] = false;
         $config['maintain_ratio'] = TRUE;
         $config['new_image'] = $target . DIRECTORY_SEPARATOR . file_save_name($id) . '.png';
         $config['width'] = 100;
         $config['height'] = 100;
         $this->load->library('image_lib', $config);
         $this->image_lib->resize();
         // $config['new_image'] = $target.DIRECTORY_SEPARATOR.file_save_name($id).'_small.png';
         // $config['width'] = 50;
         // $config['height'] = 50;
         // $this->load->library('image_lib', $config);
         // $this->image_lib->resize();
         @unlink($config['source_image']);
     } else {
         $data['code'] = '1001';
         $data['msg'] = '上传图片失败';
     }
     echo json_encode($data);
 }
Beispiel #6
0
 public function update()
 {
     $this->auth->check_login_json();
     $post = $this->input->post();
     if (empty($post)) {
         show_error('参数错误');
     }
     $data = array('code' => '1000', 'msg' => '');
     $this->load->library('form_validation');
     $this->form_validation->set_rules('pcode', ' ', 'max_length[20]');
     $this->form_validation->set_rules('name', ' ', 'required|max_length[50]');
     $this->form_validation->set_rules('price', ' ', 'numeric|max_length[8]');
     $this->form_validation->set_rules('best_price', ' ', 'numeric|max_length[8]');
     $this->form_validation->set_rules('amount', ' ', 'integer|max_length[8]');
     $this->form_validation->set_rules('unit', ' ', 'max_length[30]');
     $this->form_validation->set_rules('weight', ' ', 'numeric|max_length[8]');
     $this->form_validation->set_rules('min_num', ' ', 'integer|max_length[11]');
     $this->form_validation->set_rules('score', ' ', 'integer|max_length[11]');
     $this->form_validation->set_rules('status', ' ', 'integer');
     $this->form_validation->set_rules('recommend', ' ', 'integer');
     $this->form_validation->set_rules('specials', ' ', 'integer');
     $this->form_validation->set_rules('hot', ' ', 'integer');
     $this->form_validation->set_rules('allow_comment', ' ', 'integer');
     $this->form_validation->set_rules('show_home', ' ', 'integer');
     $this->form_validation->set_rules('handpick', ' ', 'integer');
     if ($this->form_validation->run() == FALSE) {
         $this->form_validation->set_error_delimiters('', '');
         $data['code'] = '1010';
         $error['pcode'] = form_error('pcode');
         $error['name'] = form_error('name');
         $error['price'] = form_error('price');
         $error['best_price'] = form_error('best_price');
         $error['amount'] = form_error('amount');
         $error['unit'] = form_error('unit');
         $error['weight'] = form_error('weight');
         $error['min_num'] = form_error('min_num');
         $error['score'] = form_error('score');
         $error['status'] = form_error('status');
         $error['recommend'] = form_error('recommend');
         $error['specials'] = form_error('specials');
         $error['hot'] = form_error('hot');
         $error['allow_comment'] = form_error('allow_comment');
         $error['show_home'] = form_error('show_home');
         $error['handpick'] = form_error('handpick');
         $data['msg'] = $this->lang->line('error_msg');
         $data['error'] = $error;
         echo json_encode($data);
         exit;
     }
     $error = array();
     if ($post['id']) {
         if ($post['pcode']) {
             $where = array('code' => $post['pcode'], 'id !=' => $post['id']);
             if ($this->product->exist($where)) {
                 $error['pcode'] = '编码已存在';
             }
         }
         $where = array('name' => $post['name'], 'id !=' => $post['id']);
         if ($this->product->exist($where)) {
             $error['name'] = '名称已存在';
         }
     } else {
         if ($post['pcode']) {
             $where = array('code' => $post['pcode']);
             if ($this->product->exist($where)) {
                 $error['pcode'] = '编码已存在';
             }
         }
         $where = array('name' => $post['name']);
         if ($this->product->exist($where)) {
             $error['name'] = '名称已存在';
         }
     }
     if (!empty($error)) {
         echo json_encode(array('code' => '1010', 'msg' => $this->lang->line('error_msg'), 'error' => $error));
         exit;
     }
     $row = array('code' => $post['pcode'], 'name' => $post['name'], 'price' => $post['price'] ? $post['price'] : 0, 'best_price' => $post['best_price'] ? $post['best_price'] : 0, 'amount' => $post['amount'] ? $post['amount'] : 0, 'type_id' => $post['type_id'], 'cate_id' => $post['cate'], 'brand_id' => $post['brand_id'], 'unit' => $post['unit'], 'weight' => isset($post['weight']) ? floor($post['weight']) : 0, 'min_num' => isset($post['min_num']) ? intval($post['min_num']) : 0, 'score' => isset($post['score']) ? intval($post['score']) : 0, 'info' => $post['info'], 'promise' => $post['promise'], 'status' => isset($post['status']) ? round($post['status'], 2) : 0, 'recommend' => isset($post['recommend']) ? intval($post['recommend']) : 0, 'specials' => isset($post['specials']) ? $post['specials'] : 0, 'hot' => isset($post['hot']) ? intval($post['hot']) : 0, 'allow_comment' => isset($post['allow_comment']) ? intval($post['allow_comment']) : 0, 'show_home' => isset($post['show_home']) ? intval($post['show_home']) : 0, 'handpick' => isset($post['handpick']) ? intval($post['handpick']) : 0);
     if ($post['id']) {
         if (!$this->product->update($row, $post['id'])) {
             $data = array('code' => '1001', 'msg' => $this->lang->line('update_fail'));
         }
         $id = $post['id'];
         $this->product_category_map->delete_by_product($id);
     } else {
         if (!($id = $this->product->insert($row))) {
             $data = array('code' => '1001', 'msg' => $this->lang->line('add_fail'));
         }
     }
     if ($data['code'] == '1000') {
         if (isset($post['cate_id']) && $post['cate_id'] && is_array($post['cate_id']) && !empty($post['cate_id'])) {
             foreach ($post['cate_id'] as $key => $value) {
                 $this->product_category_map->insert(array('product_id' => $id, 'category_id' => $value));
             }
         }
         $data['goto'] = 'admin/products';
         //处理图片
         $this->load->library('image_lib');
         $target = upload_folder('product') . DIRECTORY_SEPARATOR . file_save_dir($id);
         create_folder($target);
         $tmp_folder = upload_folder('temp');
         $target_name = file_save_name($id);
         $unlink = array();
         for ($i = 1; $i <= 5; $i++) {
             if ($post['pro_pic_path_' . $i] && is_file($tmp_folder . DIRECTORY_SEPARATOR . $post['pro_pic_path_' . $i])) {
                 $config['image_library'] = 'gd2';
                 $config['source_image'] = $tmp_folder . DIRECTORY_SEPARATOR . $post['pro_pic_path_' . $i];
                 $config['create_thumb'] = false;
                 $config['maintain_ratio'] = TRUE;
                 $config['new_image'] = $target . DIRECTORY_SEPARATOR . $target_name . '_' . $i . '.png';
                 $config['width'] = 800;
                 $config['height'] = 600;
                 $this->image_lib->initialize($config);
                 $this->image_lib->resize();
                 $config['new_image'] = $target . DIRECTORY_SEPARATOR . $target_name . '_' . $i . '_thumb.png';
                 $config['width'] = 200;
                 $config['height'] = 150;
                 $this->image_lib->initialize($config);
                 $this->image_lib->resize();
                 $unlink[] = $config['source_image'];
             }
         }
         if (!empty($unlink)) {
             foreach ($unlink as $key => $value) {
                 @unlink($value);
             }
         }
     }
     echo json_encode($data);
 }
Beispiel #7
0
 public function pic($id, $size = 'normal')
 {
     if (!$id) {
         return base_url() . 'assets/img/avatar.jpg';
     }
     $this->config->load('upload');
     $folder = $this->config->item('user_folder');
     $file_save_dir = file_save_dir($id);
     $file_save_name = file_save_name($id);
     if (is_file($folder . DIRECTORY_SEPARATOR . $file_save_dir . DIRECTORY_SEPARATOR . $file_save_name . '.png')) {
         return base_url() . $folder . '/' . $file_save_dir . '/' . $file_save_name . '.png';
     }
     return base_url() . 'assets/img/avatar.jpg';
 }