예제 #1
0
 /**
  * @brief 商品添加和修改视图
  */
 public function goods_edit()
 {
     $goods_id = IFilter::act(IReq::get('id'), 'int');
     //初始化数据
     $goods_class = new goods_class($this->seller['seller_id']);
     //获取所有商品扩展相关数据
     $data = $goods_class->edit($goods_id);
     if ($goods_id && !$data) {
         die("没有找到相关商品!");
     }
     $this->setRenderData($data);
     $this->redirect('goods_edit');
 }
예제 #2
0
 /**
  * @brief 商品添加和修改视图
  */
 public function goods_edit()
 {
     $goods_id = IFilter::act(IReq::get('id'), 'int');
     //初始化数据
     $goods_class = new goods_class($this->seller['seller_id']);
     //获取商品分类列表
     $tb_category = new IModel('category');
     $this->category = $goods_class->sortdata($tb_category->query(false, '*', 'sort', 'asc'), 0, '--');
     //获取所有商品扩展相关数据
     $data = $goods_class->edit($goods_id);
     if ($goods_id && !$data) {
         die("没有找到相关商品!");
     }
     $this->setRenderData($data);
     $this->redirect('goods_edit');
 }
예제 #3
0
 /**
  * @brief 保存修改商品信息
  */
 function goods_update()
 {
     //获得post的数据
     $goods_id = IFilter::act(IReq::get('goods_id'), 'int');
     $goods_name = IFilter::act(IReq::get('goods_name'));
     $goods_category = IReq::get('goods_category');
     $goods_model = IFilter::act(IReq::get('goods_model'), 'int');
     $goods_brand = IFilter::act(IReq::get('goods_brand'), 'int');
     $goods_status = IFilter::act(IReq::get('goods_status'), 'int');
     $goods_notes = IFilter::act(IReq::get('goods_notes'));
     $goods_from = IFilter::act(IReq::get('goods_from'));
     $goods_sellernick = IFilter::act(IReq::get('goods_sellernick'));
     $goods_commission = IFilter::act(IReq::get('goods_commission'), 'float');
     $goods_url = IFilter::act(IReq::get('goods_url'));
     $goods_img = IFilter::act(IReq::get('goods_img'));
     $list_img = IFilter::act(IReq::get('list_img'));
     $show_img = IFilter::act(IReq::get('small_img'));
     $sell_price = IFilter::act(IReq::get('sell_price'), 'float');
     $market_price = IFilter::act(IReq::get('market_price'), 'float');
     $discount = IFilter::act(IReq::get('discount'), 'float');
     $store_nums = IFilter::act(IReq::get('store_nums'), 'int');
     $weight = IFilter::act(IReq::get('weight'), 'float');
     $store_unit = IFilter::act(IReq::get('store_unit'));
     $content = IFilter::act(IReq::get('content'), 'text');
     $seo_keywords = IReq::get('seo_keywords');
     $seo_description = IReq::get('seo_description');
     $point = IFilter::act(IReq::get('point'), 'int');
     $exp = IFilter::act(IReq::get('exp'), 'int');
     $sort = IFilter::act(IReq::get('sort'));
     $focus_photo = IFilter::act(IReq::get('focus_photo'));
     $goods_no = IFilter::act(IReq::get('goods_no'));
     $keywords_for_search = IFilter::act(IReq::get('keywords_for_search'));
     $tb_goods = new IModel('goods');
     if (!$goods_no) {
         //如用户没有输入商品货号,则默认货号
         $goods_no = Block::goods_no($goods_id);
     } else {
         $goods_info = $tb_goods->query("goods_no='" . $goods_no . "'");
         $flag = 2;
         if (count($goods_info) > 0) {
             if (count($goods_info) == 1) {
                 if ($goods_info[0]['id'] != $goods_id) {
                     $flag = 1;
                 }
             } else {
                 $flag = 1;
             }
         }
         if ($flag == 1) {
             $type = array('gid' => $goods_id, 'admin_name' => $this->admin['admin_name'], 'admin_pwd' => $this->admin['admin_pwd']);
             $goods_in_fo = $tb_goods->getObj('id=' . $goods_id);
             $goods = new goods_class();
             $data = $goods->edit($type, $goods_in_fo);
             $this->setRenderData($data);
             $this->redirect('goods_edit', false);
             Util::showMessage("您输入的货号已存在!");
         }
     }
     //标签关键词
     $keywords_for_search = trim($keywords_for_search, ",");
     if ($keywords_for_search) {
         $keywords_for_search_array = array();
         foreach (explode(",", $keywords_for_search) as $value) {
             if (IString::getStrLen($value) <= 15) {
                 keywords::add($value, 0);
                 $keywords_for_search_array[] = $value;
             }
         }
         if ($keywords_for_search_array) {
             $data = array('goods_id' => $goods_id, 'keywords' => join(',', $keywords_for_search_array));
             $obj_goods_keywords = new IModel("goods_keywords");
             $obj_goods_keywords->setData($data);
             if ($obj_goods_keywords->getObj("goods_id={$goods_id}")) {
                 $obj_goods_keywords->update("goods_id={$goods_id}");
             } else {
                 $obj_goods_keywords->add();
             }
         }
     }
     //大图片
     $show_img = $focus_photo;
     $list_img = $focus_photo;
     if ($focus_photo) {
         $foot = substr($focus_photo, strpos($focus_photo, '.'));
         //图片扩展名
         $head = substr($focus_photo, 0, strpos($focus_photo, '.'));
         //获得配置文件中的数据
         $config = new Config("site_config");
         $config_info = $config->getInfo();
         $list_thumb_width = isset($config_info['list_thumb_width']) ? $config_info['list_thumb_width'] : 175;
         $list_thumb_height = isset($config_info['list_thumb_height']) ? $config_info['list_thumb_height'] : 175;
         $show_thumb_width = isset($config_info['show_thumb_width']) ? $config_info['show_thumb_width'] : 85;
         $show_thumb_height = isset($config_info['show_thumb_height']) ? $config_info['show_thumb_height'] : 85;
         //list
         $list_img = $head . '_' . $list_thumb_width . '_' . $list_thumb_height . $foot;
         //show
         $show_img = $head . '_' . $show_thumb_width . '_' . $show_thumb_height . $foot;
     } elseif ($goods_img) {
         $focus_photo = $goods_img;
     }
     //规格
     $spec_va = IReq::get('spec_va');
     $spec = array();
     $spec_array = array();
     if ($spec_va) {
         $arr = explode(';', $spec_va);
         $i = 0;
         foreach ($arr as $value) {
             if ($value) {
                 $brr = explode('|', $value);
                 $j = 0;
                 foreach ($brr as $va) {
                     $crr = explode(',', $va);
                     $spec[$i][$j]['id'] = $crr[1];
                     $spec[$i][$j]['name'] = $crr[2];
                     $spec[$i][$j]['type'] = $crr[3];
                     //商品规格类型
                     $spec_array[$j]['id'] = $crr[1];
                     if (!isset($spec_array[$j]['value'])) {
                         $spec_array[$j]['value'] = $crr[2] . ',';
                     } else {
                         if (!strpos(',,' . $spec_array[$j]['value'], ',' . $crr[2] . ',')) {
                             $spec_array[$j]['value'] .= $crr[2] . ',';
                         }
                     }
                     $spec_array[$j]['type'] = $crr[3];
                     $spec_array[$j]['name'] = $crr[4];
                     $j++;
                 }
                 $i++;
             }
         }
     }
     /*goods表操作*/
     $tb_goods->setData(array('name' => $goods_name, 'notes' => $goods_notes, 'goods_no' => $goods_no, 'sell_price' => $sell_price, 'market_price' => $market_price, 'discount' => $discount, 'store_nums' => $store_nums, 'brand_id' => $goods_brand, 'is_del' => $goods_status, 'from' => $goods_from, 'sellernick' => $goods_sellernick, 'commission' => $goods_commission, 'url' => $goods_url, 'content' => $content, 'keywords' => $seo_keywords, 'description' => $seo_description, 'weight' => $weight, 'unit' => $store_unit, 'point' => $point, 'exp' => $exp, 'sort' => $sort, 'small_img' => $show_img, 'img' => $focus_photo, 'list_img' => $list_img));
     $tb_goods->update('id=' . $goods_id);
     //商品扩展分类
     $tb_category = new IModel('category_extend');
     $tb_category->del('goods_id=' . $goods_id);
     if ($goods_category) {
         $tb_category->setData(array('goods_id' => $goods_id, 'category_id' => $goods_category));
         $tb_category->add();
     }
     /*commend_goods表操作*/
     $goods_commend = IReq::get('goods_commend');
     $tb_commend = new IModel('commend_goods');
     $tb_commend->del('goods_id=' . $goods_id);
     if (!empty($goods_commend)) {
         if (is_array($goods_commend)) {
             for ($i = 0; $i < count($goods_commend); $i++) {
                 $tb_commend->setData(array('commend_id' => $goods_commend[$i], 'goods_id' => $goods_id));
                 $tb_commend->add();
             }
         } else {
             $tb_commend->setData(array('commend_id' => $goods_commend, 'goods_id' => $goods_id));
             $tb_commend->add();
         }
     }
     /*goods_photo_relation表操作*/
     $photo_name = IReq::get('photo_name');
     $tb_goods_relation = new IModel('goods_photo_relation');
     $tb_goods_relation->del('goods_id=' . $goods_id);
     if ($photo_name) {
         $photo_name = substr($photo_name, 0, -1);
         $arr = explode(',', $photo_name);
         if (count($arr) > 0) {
             foreach ($arr as $value) {
                 //当图片存在的时候保存
                 if (file_exists($value)) {
                     $tb_goods_relation->setData(array('goods_id' => $goods_id, 'photo_id' => md5_file($value)));
                     $tb_goods_relation->add();
                 }
             }
         }
     }
     /*products表以及group_price的操作*/
     $member_ids = IFilter::act(IReq::get('member_ids'));
     $group_id = IFilter::act(IReq::get('group_id'));
     $products_id = IFilter::act(IReq::get('products_id'));
     //先对products表操作,先修改,再删除没有了的pro
     $tb_products = new Imodel('products');
     $tb_group_ob = new Imodel('group_price');
     if ($group_id) {
         $tb_group_ob->del('id in (' . $group_id . ')');
     }
     $store_nums = 0;
     //商品数量
     if ($spec_va) {
         $sell_price_array = array();
         //所有货品的销售价格
         $market_price_array = array();
         //所有货品的市场价格
         $discount_array = array();
         //所有货品的成本价格
         $weight_array = array();
         //所有货品的重量
         $arr = explode(';', $spec_va);
         $i = 0;
         foreach ($arr as $value) {
             if ($value) {
                 $brr = explode('|', $value);
                 $j = 0;
                 $ids = array();
                 $spec_md5 = '';
                 $pro_id = '';
                 $new_pro = '';
                 foreach ($brr as $va) {
                     $crr = explode(',', $va);
                     $pro_id = $crr[0];
                     $new_pro = $pro_id;
                     //判断商品是否为新添加的,如果是则pro_id以a开头
                     if (stristr($pro_id, 'a') != '') {
                         $pro_id = substr($pro_id, 1);
                     }
                     $ids[$j]['id'] = $crr[1];
                     $ids[$j]['value'] = $crr[2];
                     $spec_md5 .= md5($ids[$j]['value']) . ',';
                     $j++;
                 }
                 $specTemp = explode(',', trim($spec_md5, ','));
                 sort($specTemp);
                 $spec_md5 = md5(serialize($specTemp));
                 $store_nums += IReq::get('store_nums' . $pro_id);
                 $tb_products->setData(array('goods_id' => $goods_id, 'products_no' => IReq::get('goods_no' . $pro_id) ? IReq::get('goods_no' . $pro_id) : $goods_no . '-' . ($i + 1), 'spec_array' => serialize($ids), 'market_price' => IReq::get('market_price' . $pro_id) ? IReq::get('market_price' . $pro_id) : $market_price, 'sell_price' => IReq::get('sell_price' . $pro_id) ? IReq::get('sell_price' . $pro_id) : $sell_price, 'store_nums' => IReq::get('store_nums' . $pro_id) ? IReq::get('store_nums' . $pro_id) : $store_nums, 'discount' => IReq::get('discount' . $pro_id) ? IReq::get('discount' . $pro_id) : $discount, 'weight' => IReq::get('weight' . $pro_id) ? IReq::get('weight' . $pro_id) : $weight, 'spec_md5' => $spec_md5));
                 //获得所有的货品的销售价格、市场价格、成本价格、货品的重量
                 $sell_price_array[] = IReq::get('sell_price' . $pro_id) ? IReq::get('sell_price' . $pro_id) : $sell_price;
                 $market_price_array[] = IReq::get('market_price' . $pro_id) ? IReq::get('market_price' . $pro_id) : $market_price;
                 $discount_array[] = IReq::get('discount' . $pro_id) ? IReq::get('discount' . $pro_id) : $discount;
                 $weight_array[] = IReq::get('weight' . $pro_id) ? IReq::get('weight' . $pro_id) : $weight;
                 $mem_array = explode(',', $member_ids);
                 if (strpos('|' . $new_pro, 'a') > 0) {
                     $pr_id = $tb_products->add();
                     foreach ($mem_array as $cc) {
                         $gro_price = IFilter::act(IReq::get('mem_0_' . $new_pro . '_' . $cc), 'int');
                         if ($gro_price > 0 && $pr_id != 0) {
                             $tb_group_ob->setData(array('goods_id' => $goods_id, 'products_id' => $pr_id, 'group_id' => $cc, 'price' => $gro_price));
                             $tb_group_ob->add();
                         }
                     }
                 } else {
                     $tb_products->update('id=' . $pro_id);
                     $group_arr = explode(',', $group_id . ',0');
                     if ($group_arr) {
                         foreach ($group_arr as $va) {
                             foreach ($mem_array as $cc) {
                                 $gro_price = IFilter::act(IReq::get('mem_' . $va . '_' . $pro_id . '_' . $cc), 'int');
                                 if ($gro_price > 0) {
                                     $tb_group_ob->setData(array('goods_id' => $goods_id, 'products_id' => $pro_id, 'group_id' => $cc, 'price' => $gro_price));
                                     $tb_group_ob->add();
                                 }
                             }
                         }
                     } else {
                         foreach ($mem_array as $cc) {
                             $gro_price = IFilter::act(IReq::get('mem_0_' . $pro_id . '_' . $cc), 'int');
                             if ($gro_price > 0) {
                                 $tb_group_ob->setData(array('goods_id' => $goods_id, 'products_id' => $pro_id, 'group_id' => $cc, 'price' => $gro_price));
                                 $tb_group_ob->add();
                             }
                         }
                     }
                 }
             }
             $i++;
         }
         //如果商品的价格为空,则将货品的销售价格中最低的赋予
         $addition = array('store_nums' => $store_nums);
         if (!empty($sell_price_array)) {
             $addition['sell_price'] = min($sell_price_array);
         }
         if (!empty($market_price_array)) {
             $addition['market_price'] = min($market_price_array);
         }
         if (!empty($discount_array)) {
             $addition['discount'] = min($discount_array);
         }
         if (!empty($weight_array)) {
             $addition['weight'] = min($weight_array);
         }
         $tb_goods->setData($addition);
         //如果有products数据,则将products中的货品数量全部相加并送入goods表
         $tb_goods->update('id=' . $goods_id);
     }
     $mem_array = explode(',', $member_ids);
     $group_arr = explode(',', $group_id . ',0');
     if ($group_arr) {
         foreach ($group_arr as $va) {
             foreach ($mem_array as $cc) {
                 $gro_price = IFilter::act(IReq::get('mem_' . $va . '_0_' . $cc), 'int');
                 if ($gro_price > 0) {
                     $tb_group_ob->setData(array('goods_id' => $goods_id, 'products_id' => 0, 'group_id' => $cc, 'price' => $gro_price));
                     $tb_group_ob->add();
                 }
             }
         }
     }
     //获得删除的products_id
     $del_products_id = IFilter::act(IReq::get('del_products_id'));
     if ($del_products_id) {
         $del_products_id = substr($del_products_id, 0, -1);
         $info = explode(',', $del_products_id);
         foreach ($info as $value) {
             if (strpos('|' . $value, 'a') == false) {
                 $tb_products->del('id=' . $value);
             }
         }
     }
     $this->redirect("goods_list");
 }
예제 #4
0
 /**
  * @brief 商品添加和修改视图
  */
 function goods_edit()
 {
     $goods_id = IFilter::act(IReq::get('id'), 'int');
     //初始化数据
     $goods_class = new goods_class();
     $tb_category = new IModel('category');
     $this->category = $goods_class->sortdata($tb_category->query(false, '*', 'sort', 'asc'), 0, '--');
     $data = array();
     if ($goods_id) {
         //获取商品
         $obj_goods = new IModel('goods');
         $goods_info = $obj_goods->getObj('id=' . $goods_id);
         //读取到记录
         if ($goods_info) {
             $data = $goods_class->edit($goods_info);
             //获取货品
             $productObj = new IModel('products');
             $product_info = $productObj->query('goods_id = ' . $goods_id);
             if ($product_info) {
                 //获取货品会员价格
                 $groupPriceDB = new IModel('group_price');
                 foreach ($product_info as $k => $rs) {
                     $temp = array();
                     $productPrice = $groupPriceDB->query('product_id = ' . $rs['id']);
                     foreach ($productPrice as $key => $val) {
                         $temp[$val['group_id']] = $val['price'];
                     }
                     $product_info[$k]['groupPrice'] = $temp ? JSON::encode($temp) : '';
                 }
                 $data['product'] = $product_info;
             }
         } else {
             $this->goods_list();
             Util::showMessage("没有找到相关商品!");
             exit;
         }
     }
     $this->setRenderData($data);
     $this->redirect('goods_edit');
 }