function ajax_edit_add($data = array(), $id = 0)
 {
     if (!empty($data['width']) && !empty($data['height']) && !empty($data['link_logo'])) {
         if (!empty($id)) {
             $sql = "SELECT link_logo FROM `{$this->App->prefix()}friend_link` WHERE link_id='{$id}'";
             $var = $this->App->findvar($sql);
             if ($data['link_logo'] != $var) {
                 Import::fileop()->delete_file(SYS_PATH . $var);
                 //删除文件
                 $q = dirname($var);
                 $h = basename($var);
                 Import::fileop()->delete_file(SYS_PATH . $q . DS . 'thumb_s' . DS . $h);
                 Import::fileop()->delete_file(SYS_PATH . $q . DS . 'thumb_b' . DS . $h);
                 if (file_exists(SYS_PATH . $data['link_logo'])) {
                     Import::img()->thumb(SYS_PATH . $data['link_logo'], SYS_PATH . $data['link_logo'], $data['width'], $data['height']);
                 }
             }
         }
     }
     if (empty($id)) {
         if ($this->App->insert('friend_link', $data)) {
             $this->action('system', 'add_admin_log', '添加友情链接:' . $data['link_name']);
         } else {
             echo "无法添加友情链接,意外错误!";
         }
     } else {
         if ($this->App->update('friend_link', $data, 'link_id', $id)) {
             $this->action('system', 'add_admin_log', '修改友情链接:' . $data['link_name']);
         } else {
             echo "数据未变动,无需更新!";
         }
     }
     exit;
 }
Example #2
0
 function goodsinfo()
 {
     $this->layout('kong2');
     $gid = isset($_GET['id']) ? intval($_GET['id']) : 0;
     //$sid = isset($_GET['shopid']) ? intval($_GET['shopid']) : 0;
     $sid = $this->Session->read('Shop.uid');
     if ($gid > 0) {
         $sql = "SELECT * FROM `{$this->App->prefix()}user_shopgoods` WHERE goods_id='{$gid}' LIMIT 1";
         $rt = $this->App->findrow($sql);
         $this->set('rt', $rt);
     }
     if (isset($_POST) && !empty($_POST)) {
         $_POST['is_on_sale'] = isset($_POST['is_on_sale']) && intval($_POST['is_on_sale']) > 0 ? intval($_POST['is_on_sale']) : '0';
         $_POST['is_best'] = isset($_POST['is_best']) && intval($_POST['is_best']) > 0 ? intval($_POST['is_best']) : '0';
         $_POST['is_new'] = isset($_POST['is_new']) && intval($_POST['is_new']) > 0 ? intval($_POST['is_new']) : '0';
         $_POST['is_hot'] = isset($_POST['is_hot']) && intval($_POST['is_hot']) > 0 ? intval($_POST['is_hot']) : '0';
         $_POST['is_promote'] = isset($_POST['is_promote']) && intval($_POST['is_promote']) > 0 ? intval($_POST['is_promote']) : '0';
         if ($gid > 0) {
             //编辑
             if ($rt['original_img'] != $_POST['original_img']) {
                 //修改了上传文件 那么重新上传
                 $source_path = SYS_PATH . DS . str_replace('/', DS, $_POST['original_img']);
                 $pa = dirname($_POST['original_img']);
                 $thumb = basename($_POST['original_img']);
                 $tw_s = intval($GLOBALS['LANG']['th_width_s']) > 0 ? intval($GLOBALS['LANG']['th_width_s']) : 200;
                 $th_s = intval($GLOBALS['LANG']['th_height_s']) > 0 ? intval($GLOBALS['LANG']['th_height_s']) : 200;
                 $tw_b = intval($GLOBALS['LANG']['th_width_b']) > 0 ? intval($GLOBALS['LANG']['th_width_b']) : 450;
                 $th_b = intval($GLOBALS['LANG']['th_height_b']) > 0 ? intval($GLOBALS['LANG']['th_height_b']) : 450;
                 if (isset($_POST['goods_thumb']) && !empty($_POST['goods_thumb'])) {
                     //留空
                 } else {
                     Import::img()->thumb($source_path, dirname($source_path) . DS . 'thumb_s' . DS . $thumb, $tw_s, $th_s);
                     //小缩略图
                     $_POST['goods_thumb'] = $pa . '/thumb_s/' . $thumb;
                 }
                 Import::img()->thumb($source_path, dirname($source_path) . DS . 'thumb_b' . DS . $thumb, $tw_b, $th_b);
                 //大缩略图
                 $_POST['goods_img'] = $pa . '/thumb_b/' . $thumb;
             }
             $_POST['meta_keys'] = !empty($_POST['meta_keys']) ? str_replace(array(',', '。', '.'), ',', $_POST['meta_keys']) : "";
             $this->App->update('user_shopgoods', $_POST, 'goods_id', $gid);
             $this->jump(SITE_URL . 'shop/sp.php?type=photosinfo', 0, '修改成功!');
             exit;
         } else {
             //添加
             $_POST['meta_keys'] = !empty($_POST['meta_keys']) ? str_replace(array(',', '。', '.'), ',', $_POST['meta_keys']) : "";
             $_POST['add_time'] = mktime();
             $_POST['uid'] = $sid;
             //商品图片
             if (!empty($_POST['original_img'])) {
                 $pa = dirname($_POST['original_img']);
                 $thumb = basename($_POST['original_img']);
                 //商品小图
                 if (isset($_POST['goods_thumb']) && !empty($_POST['goods_thumb'])) {
                     //留空即可
                 } else {
                     $_POST['goods_thumb'] = $pa . '/thumb_s/' . $thumb;
                 }
                 //商品中图
                 $_POST['goods_img'] = $pa . '/thumb_b/' . $thumb;
             }
             $this->App->insert('user_shopgoods', $_POST);
             $this->jump(SITE_URL . 'shop/sp.php?type=photosinfo', 0, '添加成功!');
             exit;
         }
     }
     $this->set('catelist', $this->get_goods_cate_tree(0, $sid));
     $this->template('goodsinfo');
 }
 function ttest()
 {
     $imgobj = Import::img();
     $crawler = Import::crawler();
     $iconv = Import::gz_iconv();
     require_once SYS_PATH_ADMIN . 'inc' . DS . 'download.php';
     //$crawler->curl_get_con('http://www.womai.com/Product-0-526333.htm');exit;
     //$imgobj->grabImage("http://www.21ej.com/picture/139-848-892.gif",SYS_PATH."test.gif");
     DownImageKeep("http://www.21ej.com/picture/139-848-d892.gif", "http://www.baidu.com", SYS_PATH . "test.gif", "", 0, 1);
     exit;
     $sql = "SELECT tb1.url,tb2.goods_preg_1,tb2.goods_preg_2,tb2.goods_preg_3,tb2.goods_preg_4,tb2.goods_preg_5 FROM `{$this->App->prefix()}goods_cache_url` AS tb1 LEFT JOIN `{$this->App->prefix()}goods_cache_site` AS tb2 ON tb2.gcid = tb1.gcid WHERE tb1.gcid='1' LIMIT 3";
     $rt = $this->App->find($sql);
     $str = "";
     if (!empty($rt)) {
         foreach ($rt as $row) {
             $url = $row['url'];
             echo $con = $crawler->curl_get_con($url);
             exit;
             if (empty($con)) {
                 continue;
             }
             $con = $iconv->ec_iconv('GB2312', 'UTF8', $con);
             //分类
             $goods_preg_1 = $row['goods_preg_1'];
             @preg_match($goods_preg_1, $con, $arr1);
             $catetitle = isset($arr1[1]) ? $arr1[1] : "";
             //标题
             $goods_preg_2 = $row['goods_preg_2'];
             @preg_match($goods_preg_2, $con, $arr2);
             $goodstitle = isset($arr2[1]) ? $arr2[1] : "";
             //价格
             $goods_preg_3 = $row['goods_preg_3'];
             @preg_match($goods_preg_3, $con, $arr3);
             $goodsprice = isset($arr3[1]) ? $arr3[1] : "";
             $goods_preg_4 = $row['goods_preg_4'];
             if (!empty($goods_preg_4)) {
                 $goods_preg_4 = str_replace('"', "'", $goods_preg_4);
                 @preg_match($goods_preg_4, $con, $arr4);
                 $goodsimg = isset($arr4[1]) ? $arr4[1] : "";
                 $simg = "photos/g/" . date('Ym', mktime()) . "/ej" . mktime() . substr($goodsimg, -4);
                 $imgobj->imagescopy("http://www.21ej.com/" . $goodsimg, SYS_PATH . $simg);
             }
             $goods_preg_5 = $row['goods_preg_5'];
             if (!empty($goods_preg_5)) {
                 @preg_match($goods_preg_5, $con, $arr5);
                 $goodsdesc = isset($arr5[1]) ? $arr5[1] : "";
             }
         }
     }
 }
 function upload($filename, $filedir = "")
 {
     if (empty($filedir) || empty($filename)) {
         return false;
     }
     $imgobj = Import::img();
     $f_name = $_FILES[$filename]['name'];
     //获取上传源文件名
     $t = strrchr($f_name, '.');
     //图片类型
     $name = time() . time() . $t;
     //原始图名称
     //设置生成缩略图图片的大小
     $dir = basename(dirname($filedir));
     $tw_s = 260;
     $th_s = 260;
     $tw_b = 600;
     $th_b = 600;
     $result = false;
     switch ($dir) {
         case 'articlephoto':
             //文章图片
             break;
         case 'catephoto':
             //分类图片
             break;
         case 'companylogo':
             //客户公司图片
             break;
         case 'friendlogo':
             //友情链接图片图片
             break;
         case 'site_icon':
             //网站图标
             break;
         case 'brand':
             //品牌的banner图
         //品牌的banner图
         case 'goods':
             //商品
             $tw_s = intval($GLOBALS['LANG']['th_width_s']) > 0 ? intval($GLOBALS['LANG']['th_width_s']) : 260;
             $th_s = intval($GLOBALS['LANG']['th_height_s']) > 0 ? intval($GLOBALS['LANG']['th_height_s']) : 260;
             $tw_b = intval($GLOBALS['LANG']['th_width_b']) > 0 ? intval($GLOBALS['LANG']['th_width_b']) : 600;
             $th_b = intval($GLOBALS['LANG']['th_height_b']) > 0 ? intval($GLOBALS['LANG']['th_height_b']) : 600;
             break;
         case 'avatar':
             $tw_s = 150;
             $th_s = 150;
             $tw_b = 150;
             $th_b = 150;
             $result = true;
             break;
     }
     $imgname = $imgobj->upload($filename, $filedir . $name);
     $other = array('banner', 'brand', 'cover', 'top_img');
     if (file_exists($filedir . $name)) {
         if ($dir == 'avatar') {
             //头像 生成150
             $imgobj->thumb($filedir . $name, $filedir . 'thumb_s' . DS . $name, $tw_s, $th_s);
             @unlink($filedir . $name);
             //Import::->fileop()->delete_file($filedir.$name);
             $imgobj->thumb($filedir . 'thumb_s' . DS . $name, $filedir . $name, $tw_b, $th_b);
             @unlink($filedir . 'thumb_b' . DS . $name);
             //Import::->fileop()->delete_file($filedir.'thumb_b'.DS.$name);
         } else {
             if (!in_array($dir, $other)) {
                 $imgobj->thumb($filedir . $name, $filedir . 'thumb_s' . DS . $name, $tw_s, $th_s);
                 $imgobj->thumb($filedir . $name, $filedir . 'thumb_b' . DS . $name, $tw_b, $th_b);
             }
         }
     }
     return $name;
 }
 function zhuanyi_goods()
 {
     if (isset($_GET['kk']) && isset($_GET['maxpage'])) {
         $imgobj = Import::img();
         $kk = $_GET['kk'];
         $list = 20;
         if ($kk == 0) {
             $tt = $this->App->findvar("SELECT COUNT(goods_id) FROM `{$this->App->prefix()}goods`");
             $maxpage = ceil($tt / $list);
         } else {
             $maxpage = $_GET['maxpage'];
         }
         $start = $kk * $list;
         $sql = "SELECT g.*,u.user_name FROM `{$this->App->prefix()}goods` AS g LEFT JOIN `{$this->App->prefix()}user` AS u ON u.user_id = g.uid LIMIT {$start},{$list}";
         $rt = $this->App->find($sql);
         $str = "";
         if (!empty($rt)) {
             foreach ($rt as $row) {
                 //检查是否已经存在该记录
                 if ($row['uid'] > 0) {
                     $sgid = $this->App->findvar("SELECT sgid FROM `{$this->App->prefix()}suppliers_goods` WHERE suppliers_id='{$row['uid']}' AND goods_id='{$row['goods_id']}'");
                     if (empty($sgid)) {
                         $this->App->insert('suppliers_goods', array('suppliers_id' => $row['uid'], 'goods_id' => $row['goods_id'], 'market_price' => $row['market_price'], 'shop_price' => $row['shop_price'], 'pifa_price' => $row['pifa_price'], 'is_on_sale' => $row['is_on_sale'], 'is_delete' => $row['is_delete'], 'is_check' => $row['is_check'], 'addtime' => mktime()));
                         $str .= '转移=>供应商[' . $row['user_name'] . '] goods_id[' . $row['goods_id'] . '] 供应价[' . $row['market_price'] . '] 零售价[' . $row['shop_price'] . '] 批发价[' . $row['pifa_price'] . ']' . "<br/>";
                     } else {
                         //$this->App->update('suppliers_goods',array('suppliers_id'=>$row['uid'],'goods_id'=>$row['goods_id'],'market_price'=>$row['market_price'],'shop_price'=>$row['shop_price'],'pifa_price'=>$row['pifa_price'],'is_on_sale'=>$row['is_on_sale'],'is_delete'=>$row['is_delete'],'addtime'=>mktime()),array("goods_id='$row[goods_id]'","suppliers_id='$row[uid]'"));
                         $str .= "该商品已经存在=goods_id:" . $row['goods_id'] . ",正在更新!<br/>";
                     }
                 } else {
                     $str .= "没有指定供应商!<br/>";
                 }
             }
         }
         $kk = $kk + 1;
         $str .= "<font color=red>==============Load.....page(" . $kk . ")================</font><br />";
         if ($kk > $maxpage) {
             $kk = "";
         }
         sleep(2);
         $rts = array('kk' => $kk, 'url' => $str, 'maxpage' => $maxpage);
         die(Import::json()->encode($rts));
     }
     $this->template('zhuanyi_goods');
 }
 function ajax_upload($filename = "")
 {
     @set_time_limit(600);
     //最大运行时间
     $fop = Import::fileop();
     $aid = $this->Session->read('adminid');
     $fn = SYS_PATH . 'cache' . DS . 'admin-' . $aid . '.php';
     //记录错误日记
     $fop->writefile($fn, "");
     $tw_s = intval($GLOBALS['LANG']['th_width_s']) > 0 ? intval($GLOBALS['LANG']['th_width_s']) : 200;
     $th_s = intval($GLOBALS['LANG']['th_height_s']) > 0 ? intval($GLOBALS['LANG']['th_height_s']) : 200;
     $tw_b = intval($GLOBALS['LANG']['th_width_b']) > 0 ? intval($GLOBALS['LANG']['th_width_b']) : 450;
     $th_b = intval($GLOBALS['LANG']['th_height_b']) > 0 ? intval($GLOBALS['LANG']['th_height_b']) : 450;
     if (!empty($_FILES[$filename]['tmp_name'])) {
         $fn = SYS_PATH . 'cache' . DS . 'admin-upload-' . $aid . '.xls';
         if (file_exists($fn)) {
             unlink($fn);
         }
         //删除原来文件
         $fop->copyfile($filename, $fn);
         //复制文件到服务器
         if (!file_exists($fn)) {
             $fop->copyfile($filename, $fn);
             if (!file_exists($fn)) {
                 echo '<script> alert("上传时发生意外错误!"); </script>';
                 return false;
             }
         }
         $data = Import::excel();
         //$data->read($_FILES[$filename]['tmp_name']);
         $data->read($fn);
         //读取文件
         $importkey = $data->sheets[0]['cells'][1];
         for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
             //以下注释的for循环打印excel表数据
             $this->rtData = array();
             //商品数据
             $this->rtData_gallery = array();
             //商品相册
             for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
                 $this->goods_key($importkey[$j], $data->sheets[0]['cells'][$i][$j]);
                 //传送 键=>值 处理
             }
             $this->rtData['is_on_sale'] = '0';
             $uuid = 0;
             $uuid = $this->rtData['uid'];
             if (!($uuid > 0)) {
                 $uuid = '18';
             }
             $this->rtData['uid'] = $uuid;
             $this->rtData['add_time'] = mktime();
             $inData = $this->rtData;
             //print_r($inData); exit;
             $goods_id = 0;
             //检查该商品已经存在数据库中
             $sn = $inData['goods_bianhao'];
             //优先级是商品编号检查
             if (!empty($sn)) {
                 $sql = "SELECT goods_id FROM `{$this->App->prefix()}goods` WHERE goods_bianhao='{$sn}' AND uid='{$uuid}'";
                 $goods_id = $this->App->findvar($sql);
                 //if(!empty($snvar)) continue;
             } else {
                 $sa = $inData['goods_name'];
                 //商品名称检查是否该商品已经存在
                 if (!empty($sa)) {
                     //最后更新:2012-12-11 10:26
                     $sql = "SELECT goods_id FROM `{$this->App->prefix()}goods` WHERE goods_name='{$sa}' AND uid='{$uuid}'";
                     $goods_id = $this->App->findvar($sql);
                     //if(!empty($savar)) continue;
                 }
             }
             if (!empty($inData['goods_name'])) {
                 //商品图片
                 $val = $inData['original_img'];
                 if (!empty($val)) {
                     $pa = dirname($val);
                     $thumb = basename($val);
                     if (is_file(SYS_PATH . $pa . DS . 'thumb_s' . DS . $thumb)) {
                         $pp = SYS_PATH . $pa . DS . 'thumb_s' . DS . mktime() . $thumb;
                         $pps = $pa . '/thumb_s/' . mktime() . $thumb;
                     } else {
                         $pp = SYS_PATH . $pa . DS . 'thumb_s' . DS . $thumb;
                         $pps = $pa . '/thumb_s/' . $thumb;
                     }
                     Import::img()->thumb(SYS_PATH . $val, $pp, $tw_s, $th_s);
                     //小缩略图
                     $inData['goods_thumb'] = $pps;
                     if (is_file(SYS_PATH . $pa . DS . 'thumb_b' . DS . $thumb)) {
                         $pp = SYS_PATH . $pa . DS . 'thumb_b' . DS . mktime() . $thumb;
                         $pps = $pa . '/thumb_b/' . mktime() . $thumb;
                     } else {
                         $pp = SYS_PATH . $pa . DS . 'thumb_b' . DS . $thumb;
                         $pps = $pa . '/thumb_b/' . $thumb;
                     }
                     Import::img()->thumb(SYS_PATH . $val, $pp, $tw_b, $th_b);
                     //大缩略图
                     $inData['goods_img'] = $pps;
                 }
                 if ($goods_id > 0) {
                     //更新
                     if ($this->App->update('goods', $inData, 'goods_id', $goods_id)) {
                         //将原来的相册图片删除
                         $sql = "SELECT img_url FROM `{$this->App->prefix()}goods_gallery` WHERE goods_id ='{$goods_id}'";
                         $gallery_img = $this->App->findcol($sql);
                         if (!empty($gallery_img)) {
                             foreach ($gallery_img as $img) {
                                 $q = dirname($img);
                                 $h = basename($img);
                                 Import::fileop()->delete_file(SYS_PATH . $q . DS . 'thumb_s' . DS . $h);
                                 Import::fileop()->delete_file(SYS_PATH . $q . DS . 'thumb_b' . DS . $h);
                                 Import::fileop()->delete_file(SYS_PATH . $img);
                                 //
                             }
                             unset($gallery_img);
                         }
                         $this->App->delete('goods_gallery', 'goods_id', $goods_id);
                         //重新处理商品相册
                         $rt_gallery = $this->rtData_gallery;
                         if (!empty($rt_gallery)) {
                             foreach ($rt_gallery as $vv) {
                                 $vv = trim($vv);
                                 $pa = dirname($vv);
                                 $thumb = basename($vv);
                                 if (empty($vv) || !is_file(SYS_PATH . $vv)) {
                                     continue;
                                 }
                                 //生成缩略图
                                 if (is_file(SYS_PATH . $pa . DS . 'thumb_s' . DS . $thumb)) {
                                     $p = SYS_PATH . $pa . DS . 'thumb_s' . DS . mktime() . $thumb;
                                 } else {
                                     $p = SYS_PATH . $pa . DS . 'thumb_s' . DS . $thumb;
                                 }
                                 Import::img()->thumb(SYS_PATH . $vv, $p, $tw_s, $th_s);
                                 //小缩略图
                                 if (is_file(SYS_PATH . $pa . DS . 'thumb_b' . DS . $thumb)) {
                                     $p = SYS_PATH . $pa . DS . 'thumb_b' . DS . mktime() . $thumb;
                                 } else {
                                     $p = SYS_PATH . $pa . DS . 'thumb_b' . DS . $thumb;
                                 }
                                 Import::img()->thumb(SYS_PATH . $vv, $p, $tw_b, $th_b);
                                 //大缩略图
                                 //插入商品相册属性表
                                 $dd = array();
                                 $dd['goods_id'] = $goods_id;
                                 $dd['img_url'] = $vv;
                                 $this->App->insert('goods_gallery', $dd);
                             }
                             // end foreach
                         }
                         //end if 商品相册
                     } else {
                         //插入失败,写入日记
                         $aid = $this->Session->read('adminid');
                         $fn = SYS_PATH . 'cache' . DS . 'admin-' . $aid . '.php';
                         $fop->writefile($fn, "批量导入错误:\n" . '商品编号--' . implode('--', array_keys($inData)) . "\n" . $inData['goods_bianhao'] . '--' . implode('--', $inData) . "\n");
                     }
                 } else {
                     //插入数据库
                     if ($this->App->insert('goods', $inData)) {
                         $lastid = $this->App->iid();
                         $rt_gallery = $this->rtData_gallery;
                         //商品相册
                         //处理商品相册
                         if (!empty($rt_gallery)) {
                             foreach ($rt_gallery as $vv) {
                                 $vv = trim($vv);
                                 $pa = dirname($vv);
                                 $thumb = basename($vv);
                                 if (empty($vv) || !is_file(SYS_PATH . $vv)) {
                                     continue;
                                 }
                                 //生成缩略图
                                 if (is_file(SYS_PATH . $pa . DS . 'thumb_s' . DS . $thumb)) {
                                     $p = SYS_PATH . $pa . DS . 'thumb_s' . DS . mktime() . $thumb;
                                 } else {
                                     $p = SYS_PATH . $pa . DS . 'thumb_s' . DS . $thumb;
                                 }
                                 Import::img()->thumb(SYS_PATH . $vv, $p, $tw_s, $th_s);
                                 //小缩略图
                                 if (is_file(SYS_PATH . $pa . DS . 'thumb_b' . DS . $thumb)) {
                                     $p = SYS_PATH . $pa . DS . 'thumb_b' . DS . mktime() . $thumb;
                                 } else {
                                     $p = SYS_PATH . $pa . DS . 'thumb_b' . DS . $thumb;
                                 }
                                 Import::img()->thumb(SYS_PATH . $vv, $p, $tw_b, $th_b);
                                 //大缩略图
                                 //插入商品相册属性表
                                 $dd = array();
                                 $dd['goods_id'] = $lastid;
                                 $dd['img_url'] = $vv;
                                 $this->App->insert('goods_gallery', $dd);
                             }
                             // end foreach
                         }
                         //end if 商品相册
                     } else {
                         //插入失败,写入日记
                         $aid = $this->Session->read('adminid');
                         $fn = SYS_PATH . 'cache' . DS . 'admin-' . $aid . '.php';
                         $fop->writefile($fn, "批量导入错误:\n" . '商品编号--' . implode('--', array_keys($inData)) . "\n" . $inData['goods_bianhao'] . '--' . implode('--', $inData) . "\n");
                     }
                 }
             } else {
                 //写入错误日记
                 $aid = $this->Session->read('adminid');
                 $fn = SYS_PATH . 'cache' . DS . 'admin-' . $aid . '.php';
                 $fop->writefile($fn, "批量导入错误:\n" . implode('--', array_keys($inData)) . "\n" . implode('--', $inData) . "\n");
             }
             //end if
         }
         //end for
         echo '<script> alert("上传成功!");</script>';
         return false;
     }
     return $_FILES[$filename];
 }
 function keyword($keyword = '')
 {
     if (!empty($keyword)) {
         $wecha_id = $this->wecha_id;
         switch ($keyword) {
             case '推广链接':
                 $RL = $this->App->findrow("SELECT user_id,is_subscribe FROM `{$this->App->prefix()}user` WHERE wecha_id='{$wecha_id}' LIMIT 1");
                 $issubscribe = isset($RL['is_subscribe']) ? $RL['is_subscribe'] : '0';
                 $uid = isset($RL['user_id']) ? $RL['user_id'] : '0';
                 unset($RL);
                 if ($issubscribe == '0') {
                     return array('请先关注抢占分享地盘!', 'text');
                     exit;
                 }
                 $thisurl = SITE_URL . "m/in.php?tid=" . $uid;
                 return array('复制链接发送给朋友赚钱:' . $thisurl, 'text');
                 break;
             case 'ranklist':
                 // 排行榜
                 $RL = $this->App->findrow("SELECT user_id,user_rank FROM `{$this->App->prefix()}user` WHERE wecha_id='{$this->wecha_id}' LIMIT 1");
                 $uid = isset($RL['user_id']) ? $RL['user_id'] : '0';
                 $purt = $this->App->findrow("SELECT ut.parent_uid,u.wecha_id FROM `{$this->App->prefix()}user_tuijian` AS ut LEFT JOIN `{$this->App->prefix()}user` AS u ON u.user_id = ut.parent_uid WHERE ut.uid='{$uid}' LIMIT 1");
                 $puid = isset($purt['parent_uid']) ? $purt['parent_uid'] : '0';
                 if ($uid > 0) {
                     $gzcount = $this->App->findvar("SELECT COUNT(user_id) FROM `{$this->App->prefix()}user` LIMIT 1");
                     $gzcount = $gzcount * 5 + 750;
                     if ($puid > 0) {
                         $nickname = $this->App->findrow("SELECT nickname FROM `{$this->App->prefix()}user` WHERE user_id = '{$puid}' LIMIT 1");
                         if (empty($nickname)) {
                             $nickname = '官网';
                         }
                         $str = '来自好友【' . $nickname['nickname'] . '】的推荐成为第【' . $gzcount . '】位会员,立即关注,抢夺店主地盘!';
                     } else {
                         $str = '来自【官网】的推荐成为第【' . $gzcount . '】位会员,立即关注,抢夺店主地盘!';
                     }
                 }
                 $data = '{"touser":"******","msgtype":"text","text":{"content":"' . $str . '"}}';
                 $access_token = $this->_get_access_token();
                 $rt = $this->curlPost('https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' . $access_token, $data, 0);
                 $orderid = $this->App->findvar("SELECT order_id FROM  `{$this->App->prefix()}goods_order_info` where `user_id`='{$RL['user_id']}' and `pay_status`=1");
                 if ($orderid or $RL['user_rank'] > 1) {
                     return array('你已经是店主 发送你的名片给你的好友 赚钱吧', 'text');
                 } else {
                     return array("您还不是店主,请<a href=\"" . SITE_URL . "/m/oauth.php?oid=1\">购买商品</a>成为店主", 'text');
                 }
                 break;
             case 'qr':
                 //生成二维码
             //生成二维码
             case '我的二维码':
                 //生成二维码
                 $yuming = str_replace(array('www', '.'), '', $_SERVER["HTTP_HOST"]);
                 if (!empty($yuming)) {
                     $yuming = $yuming . DS;
                 }
                 if (!empty($wecha_id)) {
                     $tb = 'markimg';
                     $sql = "SELECT is_subscribe,user_rank,user_id,quid,headimgurl,nickname FROM `{$this->App->prefix()}user` WHERE wecha_id='{$wecha_id}' LIMIT 1";
                     $RT = $this->App->findrow($sql);
                     if ($RT['is_subscribe'] == '0') {
                         return array('关注后购买成为合伙人生成推广二维码赚钱吧!', 'text');
                         exit;
                     }
                     $access_token = $this->_get_access_token();
                     if ($RT['user_rank'] == '1') {
                         //生成推荐人二维码
                         $tb = 'markimg2';
                         /* $uid = isset($RT['user_id']) ? $RT['user_id'] : '0';
                         			$puid = $this->return_daili_uid($uid);//返回上级分销商 */
                         /*
                         if($puid > 0){
                         	 $sql = "SELECT is_subscribe,user_rank,user_id,quid,headimgurl,nickname FROM `{$this->App->prefix()}user` WHERE user_id='$puid' LIMIT 1";
                         	$RT = $this->App->findrow($sql); 
                         }else{//生成官网二维码
                         	$tb = 'markimg3';
                         	$this->send(array('openid'=>$wecha_id,'appid'=>'','appsecret'=>'','nickname'=>''),$tb);
                         	$sql = "SELECT site_url FROM `{$this->App->prefix()}systemconfig` WHERE type='basic' LIMIT 1";
                         	$f3 = $this->App->findvar($sql);
                         	if(!empty($f3)) $f3 = SYS_PATH.$f3;
                         	if(file_exists($f3)){
                         				$type = "image";
                         				$filedata = array("media"=>"@".$f3);
                         				$url = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=$access_token&type=$type";
                         				$result = $this->https_request($url,$filedata);
                         				$json = json_decode($result);
                         				$media_id = $json->media_id;
                         				if(!empty($media_id)) $this->send(array('openid'=>$wecha_id,'appid'=>'','appsecret'=>'','media_id'=>$media_id),'markimgsend'); 
                         				exit;
                         	}
                         	
                         	//return array('你是由官网推荐,请购买后生成你的推广二维码!', 'text');
                         	exit;
                         }
                         */
                         $this->send(array('openid' => $wecha_id, 'appid' => '', 'appsecret' => '', 'nickname' => ''), $tb);
                         //return array("对不起、您不是东家,获得推广图片,请购买<a href='#'>商品<a/>成为东家", 'xml');
                         exit;
                     }
                     $uid = $RT['user_id'];
                     $quid = $RT['quid'];
                     $headimgurl = $RT['headimgurl'];
                     $nickname = $RT['nickname'];
                     if (empty($nickname)) {
                         $nickname = "官网";
                     }
                     if (empty($headimgurl)) {
                         //return array('请先上传你的微信头像后生成吧!', 'text');
                         //exit;
                     }
                     unset($RT);
                     if (!($quid > 0)) {
                         $sql = "SELECT MAX(quid) FROM `{$this->App->prefix()}user` LIMIT 1";
                         $quid = $this->App->findvar($sql);
                         $quid = intval($quid) + 1;
                         $this->App->update('user', array('quid' => $quid), 'user_id', $uid);
                     }
                     $fop = Import::fileop();
                     $tis = SYS_PATH . 'cache' . DS . $yuming . 'qcode' . DS . $uid . DS . 'cache' . $quid . '.txt';
                     if (file_exists($tis) && mktime() - filemtime($tis) < 60) {
                         return;
                         exit;
                     }
                     if (!file_exists($tis) || mktime() - filemtime($tis) > 60) {
                         $fop->checkDir($tis);
                         @file_put_contents($tis, "run");
                     }
                     $access_token = $this->_get_access_token();
                     //提示生成
                     $this->send(array('openid' => $wecha_id, 'appid' => '', 'appsecret' => '', 'nickname' => ''), $tb);
                     $f3 = SYS_PATH . 'photos' . DS . $yuming . 'qcode' . DS . $uid . DS . 'ms' . $quid . '.jpg';
                     //原图
                     if (file_exists($f3)) {
                         $type = "image";
                         $filedata = array("media" => "@" . $f3);
                         $url = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token={$access_token}&type={$type}";
                         $result = $this->https_request($url, $filedata);
                         $json = json_decode($result);
                         $media_id = $json->media_id;
                         if (!empty($media_id)) {
                             $this->send(array('openid' => $wecha_id, 'appid' => '', 'appsecret' => '', 'media_id' => $media_id), 'markimgsend');
                         }
                         exit;
                     }
                     $f = SYS_PATH . 'cache' . DS . $yuming . 'qcode' . DS . $uid . DS . 's' . $quid . '.jpg';
                     if (!file_exists($f)) {
                         //生成二维码
                         $data = '{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": ' . $quid . '}}}';
                         //$data = '{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_str": "'.$wecha_id.'"}}}';
                         $rt = $this->curlPost('https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=' . $access_token, $data, 10);
                         $json = json_decode($rt);
                         $ticket = $json->ticket;
                         $url = $json->url;
                         if (!empty($ticket)) {
                             $str = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" . $ticket;
                             $img = file_get_contents($str);
                             if (empty($img)) {
                                 $img = Import::crawler()->curl_get_con($str);
                             }
                             if (!empty($img)) {
                                 $fop->checkDir($f);
                                 @file_put_contents($f, $img);
                             }
                         }
                     }
                     if (!file_exists($f)) {
                         return array('生成图片失败,请联系网站管理员解决此问题!', 'text');
                         exit;
                     }
                     $f2 = SYS_PATH . 'cache' . DS . $yuming . 'qcode' . DS . $uid . DS . 'm' . $quid . '.jpg';
                     //二维码
                     $fop->checkDir($f2);
                     $imgobj = Import::img();
                     $imgobj->thumb($f, $f2, 225, 225);
                     $sf = SYS_PATH . 'photos' . DS . $yuming . 'codebg.jpg';
                     //原图背景
                     if (file_exists($sf) == false) {
                         $sf = SYS_PATH . 'photos' . DS . 'codebg.jpg';
                         //原图背景
                     }
                     $f3 = SYS_PATH . 'photos' . DS . $yuming . 'qcode' . DS . $uid . DS . 'ms' . $quid . '.jpg';
                     //原图
                     $fop->checkDir($f3);
                     $imgobj->thumb($sf, $f3, 530, 800);
                     $t = 'false';
                     $t = $this->mark_img($f3, $f2, 152, 460);
                     if ($t == 'true') {
                         //头像
                         $t = "false";
                         $img = file_get_contents($headimgurl);
                         if (empty($img)) {
                             $img = Import::crawler()->curl_get_con($headimgurl);
                         }
                         $f4 = SYS_PATH . 'cache' . DS . $yuming . 'qcode' . DS . $uid . DS . 'mh' . $quid . '.jpg';
                         //头像
                         if (!empty($img)) {
                             $fop->checkDir($f4);
                             @file_put_contents($f4, $img);
                             if (file_exists($f4)) {
                                 $f5 = SYS_PATH . 'cache' . DS . $yuming . 'qcode' . DS . $uid . DS . 'mht' . $quid . '.jpg';
                                 //小头像
                                 $fop->checkDir($f5);
                                 $imgobj->thumb($f4, $f5, 70, 70);
                                 if (file_exists($f5)) {
                                     if ($this->mark_img($f3, $f5, 90, 30) == "true") {
                                         if ($this->mark_txt($f3, $nickname, 265, 58) == "true") {
                                             //昵称
                                             $type = "image";
                                             $filedata = array("media" => "@" . $f3);
                                             $url = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token={$access_token}&type={$type}";
                                             $result = $this->https_request($url, $filedata);
                                             $json = json_decode($result);
                                             $media_id = $json->media_id;
                                             if (!empty($media_id)) {
                                                 $this->send(array('openid' => $wecha_id, 'appid' => '', 'appsecret' => '', 'media_id' => $media_id), 'markimgsend');
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     } else {
                         return array('生成图片失败,请联系网站管理员解决此问题!', 'text');
                         exit;
                     }
                 }
                 break;
         }
         $sql = "SELECT * FROM `{$this->App->prefix()}wx_article` WHERE keyword LIKE '%{$keyword}%' ORDER BY vieworder ASC LIMIT 8";
         $rt = $this->App->find($sql);
         if (!empty($rt)) {
             if (count($rt) == 1) {
                 $rts = $rt[0];
                 if (!empty($rts)) {
                     $ty = $rts['type'];
                     if ($ty == 'txt') {
                         if (!empty($rts['content'])) {
                             return array($rts['content'], 'text');
                         } else {
                             return array("请在后台先编辑好内容", 'text');
                         }
                     } else {
                         $data['title'] = $rts['article_title'];
                         $data['keyword'] = $rts['about'];
                         $data['picurl'] = empty($rts['article_img']) ? SITE_URL . 'm/images/ico-success.png' : SITE_URL . $rts['article_img'];
                         $data['url'] = empty($rts['art_url']) ? SITE_URL . 'm/art.php?id=' . $rts['article_id'] : $rts['art_url'];
                         return array(array(array($data['title'], $data['keyword'], $data['picurl'], $data['url'])), 'news');
                     }
                 }
             } else {
                 $result = array();
                 $k = 0;
                 foreach ($rt as $row) {
                     if ($row['type'] == 'txt') {
                         continue;
                     }
                     $result[$k][] = $row['article_title'];
                     $result[$k][] = $row['about'];
                     $result[$k][] = empty($row['article_img']) ? SITE_URL . 'm/images/ico-success.png' : SITE_URL . $row['article_img'];
                     $result[$k][] = empty($row['art_url']) ? SITE_URL . 'm/art.php?id=' . $row['article_id'] : $row['art_url'];
                     ++$k;
                 }
                 return array($result, 'news');
             }
             //end if
         }
     }
     //商户主动将请求转发至客服
     /* $kehu = array('type' => '1');
     		 if ($kehu && $kehu['type'] == '1') {
              	return array('', 'transfer_customer_service');
              }*/
 }
 function info()
 {
     $gid = isset($_GET['id']) ? $_GET['id'] : 0;
     $this->js(array("edit/kindeditor.js"));
     $this->js('time/WdatePicker.js');
     //公共部分
     if (isset($_POST) && !empty($_POST)) {
         $_POST['is_best'] = isset($_POST['is_best']) && intval($_POST['is_best']) > 0 ? intval($_POST['is_best']) : '0';
         $_POST['is_new'] = isset($_POST['is_new']) && intval($_POST['is_new']) > 0 ? intval($_POST['is_new']) : '0';
         $_POST['is_hot'] = isset($_POST['is_hot']) && intval($_POST['is_hot']) > 0 ? intval($_POST['is_hot']) : '0';
         $_POST['is_on_sale'] = isset($_POST['is_on_sale']) && intval($_POST['is_on_sale']) > 0 ? intval($_POST['is_on_sale']) : '1';
         $_POST['is_shipping'] = isset($_POST['is_shipping']) && intval($_POST['is_shipping']) > 0 ? intval($_POST['is_shipping']) : '0';
         $_POST['is_alone_sale'] = isset($_POST['is_alone_sale']) && intval($_POST['is_alone_sale']) > 0 ? '0' : '1';
         $_POST['is_promote'] = isset($_POST['is_promote']) && intval($_POST['is_promote']) > 0 ? intval($_POST['is_promote']) : '0';
         if ($_POST['is_promote'] == '1') {
             if (isset($_POST['promote_start_date']) && !empty($_POST['promote_start_date'])) {
                 $_POST['promote_start_date'] = strtotime($_POST['promote_start_date'] . ' ' . $_POST['xiaoshi_start'] . ':' . $_POST['fen_start'] . ':' . $_POST['miao_start']);
             }
             if (isset($_POST['promote_end_date']) && !empty($_POST['promote_end_date'])) {
                 $_POST['promote_end_date'] = strtotime($_POST['promote_end_date'] . ' ' . $_POST['xiaoshi_end'] . ':' . $_POST['fen_end'] . ':' . $_POST['miao_end']);
             }
         }
         unset($_POST['xiaoshi_start'], $_POST['fen_start'], $_POST['miao_start']);
         unset($_POST['xiaoshi_end'], $_POST['fen_end'], $_POST['miao_end']);
         $_POST['is_qianggou'] = isset($_POST['is_qianggou']) && intval($_POST['is_qianggou']) > 0 ? intval($_POST['is_qianggou']) : '0';
         $_POST['qianggou_start_date'] = isset($_POST['qianggou_start_date']) && !empty($_POST['qianggou_start_date']) ? strtotime($_POST['qianggou_start_date']) : '0';
         $_POST['qianggou_end_date'] = isset($_POST['qianggou_end_date']) && !empty($_POST['qianggou_end_date']) ? strtotime($_POST['qianggou_end_date']) : '0';
         $_POST['is_jifen'] = '1';
         $_POST['is_check'] = '1';
         ######################
         //添加商品属性||过滤商品属性字段,以更好插入到商品表
         $atid = array('attr_id_list' => '0');
         //属性id,在gz_attribute表中
         $atvalue = array('attr_value_list' => '0');
         //用户添加的值
         $ataddi = array('attr_addi_list' => '0');
         //附加的东西,例如可以是价格图片等其他东西
         $gadesc = array('photo_gallery_desc' => '0');
         //商品相册描述
         $gaurl = array('photo_gallery_url' => '0');
         //商品相册图片
         $goods_gift = array('gift_type' => '0');
         $nprice = array('numberprice' => '0');
         $nrank = array('numberrank' => '0');
         $attr_id_list = array();
         $attr_value_list = array();
         $attr_addi_list = array();
         $photo_gallery_desc = array();
         $photo_gallery_url = array();
         $goods_gift_arr = array();
         $numberprice = array();
         //会员价格与等级是一一对应的
         $numberrank = array();
         if (isset($_POST['gift_type'])) {
             $goods_gift_arr = $_POST['gift_type'];
             $_POST = array_diff_key($_POST, $goods_gift);
         }
         if (isset($_POST['attr_id_list'])) {
             $attr_id_list = $_POST['attr_id_list'];
             //属性id,在gz_attribute表中
             $_POST = array_diff_key($_POST, $atid);
         }
         if (isset($_POST['attr_value_list'])) {
             $attr_value_list = $_POST['attr_value_list'];
             //用户添加的值
             $_POST = array_diff_key($_POST, $atvalue);
         }
         if (isset($_POST['attr_addi_list'])) {
             $attr_addi_list = $_POST['attr_addi_list'];
             //附加的东西,例如可以使图片等其他东西
             $_POST = array_diff_key($_POST, $ataddi);
         }
         //商品相册描述
         if (isset($_POST['photo_gallery_desc'])) {
             $photo_gallery_desc = $_POST['photo_gallery_desc'];
             $_POST = array_diff_key($_POST, $gadesc);
         }
         //商品相册图片
         if (isset($_POST['photo_gallery_url'])) {
             $photo_gallery_url = $_POST['photo_gallery_url'];
             $_POST = array_diff_key($_POST, $gaurl);
         }
         //商品的额外分类处理
         $sd = array('sub_cat_id' => '0');
         $subcateid = array();
         if (isset($_POST['sub_cat_id'])) {
             $subcateid = $_POST['sub_cat_id'];
             $_POST = array_diff_key($_POST, $sd);
         }
         //会员等级价格
         if (isset($_POST['numberprice'])) {
             $numberprice = $_POST['numberprice'];
             $_POST = array_diff_key($_POST, $nprice);
         }
         //会员等级
         if (isset($_POST['numberrank'])) {
             $numberrank = $_POST['numberrank'];
             $_POST = array_diff_key($_POST, $nrank);
         }
         ####################
     }
     if ($gid > 0) {
         //编辑页面
         //当前商品基本信息
         $sql = "SELECT * FROM `{$this->App->prefix()}goods` WHERE goods_id='{$gid}' LIMIT 1";
         $rt = $this->App->findrow($sql);
         if (empty($rt)) {
             $this->jump('goods.php?type?goods_list');
             exit;
         }
         //当前商品的相册
         $sql = "SELECT * FROM `{$this->App->prefix()}goods_gallery` WHERE goods_id='{$gid}'";
         $this->set('gallerylist', $this->App->find($sql));
         //当前商品属性的属性
         $sql = "SELECT tb1.*,tb2.attr_name,tb2.attr_is_select FROM `{$this->App->prefix()}goods_attr` AS tb1 LEFT JOIN `{$this->App->prefix()}attribute` AS tb2 ON tb1.attr_id=tb2.attr_id WHERE tb1.goods_id='{$gid}'";
         $goods_attr = $this->App->find($sql);
         $rt['goods_attr'] = array();
         if (!empty($goods_attr)) {
             foreach ($goods_attr as $row) {
                 $rt['goods_attr'][$row['attr_id']][] = $row;
             }
             unset($row, $goods_attr);
         }
         //商品的赠品类型
         $sql = "SELECT  type  FROM `{$this->App->prefix()}goods_gift` WHERE goods_id='{$gid}'";
         $rt['gift_type_id'] = $this->App->findcol($sql);
         if (isset($_POST) && !empty($_POST)) {
             if (empty($_POST['goods_name'])) {
                 echo '<script>alert("商品名称不能为空!");</script>';
             } else {
                 //货号
                 if (empty($_POST['goods_sn'])) {
                     $_POST['goods_sn'] = 'GZFH' . str_repeat('0', 6 - strlen($gid)) . $gid;
                 }
                 //检查当前的货号是否存在
                 $checkvar = $this->App->findvar("SELECT goods_sn FROM `{$this->App->prefix()}goods` WHERE goods_sn={$_POST['goods_sn']} LIMIT 1");
                 if (!empty($checkvar)) {
                     $_POST['goods_sn'] = $_POST['goods_sn'] . '-1';
                     //重新定义一个
                 }
                 if ($rt['original_img'] != $_POST['original_img']) {
                     //修改了上传文件 那么重新上传
                     $source_path = SYS_PATH . DS . str_replace('/', DS, $_POST['original_img']);
                     $pa = dirname($_POST['original_img']);
                     $thumb = basename($_POST['original_img']);
                     $tw_s = intval($GLOBALS['LANG']['th_width_s']) > 0 ? intval($GLOBALS['LANG']['th_width_s']) : 200;
                     $th_s = intval($GLOBALS['LANG']['th_height_s']) > 0 ? intval($GLOBALS['LANG']['th_height_s']) : 200;
                     $tw_b = intval($GLOBALS['LANG']['th_width_b']) > 0 ? intval($GLOBALS['LANG']['th_width_b']) : 450;
                     $th_b = intval($GLOBALS['LANG']['th_height_b']) > 0 ? intval($GLOBALS['LANG']['th_height_b']) : 450;
                     if (isset($_POST['goods_thumb']) && !empty($_POST['goods_thumb'])) {
                         //留空
                     } else {
                         Import::img()->thumb($source_path, dirname($source_path) . DS . 'thumb_s' . DS . $thumb, $tw_s, $th_s);
                         //小缩略图
                         $_POST['goods_thumb'] = $pa . '/thumb_s/' . $thumb;
                     }
                     Import::img()->thumb($source_path, dirname($source_path) . DS . 'thumb_b' . DS . $thumb, $tw_b, $th_b);
                     //大缩略图
                     $_POST['goods_img'] = $pa . '/thumb_b/' . $thumb;
                 }
                 $_POST['meta_keys'] = !empty($_POST['meta_keys']) ? str_replace(array(',', '。', '.'), ',', $_POST['meta_keys']) : "";
                 $_POST['last_update'] = mktime();
                 //更新时间
                 $this->App->update('goods', $_POST, 'goods_id', $gid);
                 //更新商品属性[从新添加]
                 if (!empty($attr_id_list) && !empty($gid)) {
                     foreach ($attr_id_list as $kk => $id) {
                         if (empty($attr_value_list[$kk])) {
                             continue;
                         }
                         $rtdata = array();
                         $rtdata['attr_id'] = $id;
                         $rtdata['attr_value'] = isset($attr_value_list[$kk]) ? $attr_value_list[$kk] : "NULL";
                         $rtdata['goods_id'] = $gid;
                         $rtdata['attr_addi'] = isset($attr_addi_list[$kk]) ? $attr_addi_list[$kk] : "";
                         $this->App->insert('goods_attr', $rtdata);
                     }
                     unset($rtdata);
                 }
                 ###########更新商品相册##########
                 if (!empty($photo_gallery_url) && !empty($gid)) {
                     foreach ($photo_gallery_url as $kk => $url) {
                         if (empty($url)) {
                             continue;
                         }
                         $rtdata['img_desc'] = isset($photo_gallery_desc[$kk]) ? $photo_gallery_desc[$kk] : "";
                         $rtdata['goods_id'] = $gid;
                         $rtdata['img_url'] = $url;
                         $this->App->insert('goods_gallery', $rtdata);
                     }
                     unset($rtdata);
                 }
                 //商品的子分类
                 if (!empty($subcateid)) {
                     foreach ($subcateid as $ids) {
                         $dd = array();
                         $dd['goods_id'] = $gid;
                         $dd['cat_id'] = $ids;
                         $this->App->insert('category_sub_goods', $dd);
                     }
                 }
                 //将关键字添加到goods_keyword表
                 if (!empty($_POST['meta_keys'])) {
                     $keys = explode(',', $_POST['meta_keys']);
                     foreach ($keys as $key) {
                         if (empty($key)) {
                             continue;
                         }
                         $key = trim($key);
                         $sql = "SELECT kid FROM `{$this->App->prefix()}goods_keyword` WHERE goods_id='{$gid}' AND keyword='{$key}'";
                         $kid = $this->App->findvar($sql);
                         $ds = array();
                         if (empty($kid)) {
                             $ds['goods_id'] = $gid;
                             $ds['keyword'] = $key;
                             $n = Import::basic()->Pinyin($key);
                             $ds['p_fix'] = !empty($n) ? ucwords(substr($n, 0, 1)) : "NAL";
                             $this->App->insert('goods_keyword', $ds);
                         }
                     }
                     unset($keys);
                 }
                 //赠品
                 if (!empty($goods_gift_arr)) {
                     foreach ($goods_gift_arr as $tt) {
                         if (empty($tt)) {
                             continue;
                         }
                         $dd['goods_id'] = $gid;
                         $dd['type'] = $tt;
                         $sql = "SELECT gifid FROM `{$this->App->prefix()}goods_gift` WHERE goods_id='{$gid}' AND type='{$tt}'";
                         $a = $this->App->findvar($sql);
                         if (empty($a)) {
                             $this->App->insert('goods_gift', $dd);
                         }
                     }
                 }
                 //会员等级价格添加
                 if (!empty($numberprice)) {
                     foreach ($numberprice as $ks => $price) {
                         //检查是否已经存在
                         $rankid = $numberrank[$ks];
                         $sql = "SELECT price_id FROM `{$this->App->prefix()}goods_user_price` WHERE goods_id='{$gid}' AND user_rank='{$rankid}'";
                         $price_id = $this->App->findvar($sql);
                         if ($price_id > 0) {
                             //存在
                             if ($price > 0) {
                                 //更改
                                 $sql = "UPDATE `{$this->App->prefix()}goods_user_price` SET user_price='{$price}' WHERE goods_id='{$gid}' AND user_rank='{$rankid}'";
                                 $this->App->query($sql);
                             } else {
                                 //删除
                                 $sql = "DELETE FROM `{$this->App->prefix()}goods_user_price` WHERE goods_id='{$gid}' AND user_rank='{$rankid}'";
                                 $this->App->query($sql);
                             }
                         } else {
                             //添加
                             $dt = array();
                             $dt['goods_id'] = $gid;
                             $dt['user_rank'] = $rankid;
                             $dt['user_price'] = $price;
                             $this->App->insert('goods_user_price', $dt);
                         }
                     }
                 }
                 $this->action('system', 'add_admin_log', '修改商品:' . $_POST['goods_name'] . '-goods_id:' . $gid);
                 $this->action('common', 'showdiv', $this->getthisurl());
             }
         }
         //该商品的其他子分类
         $sql = " SELECT tb1.*,tb2.cat_name FROM `{$this->App->prefix()}category_sub_goods` AS tb1";
         $sql .= " LEFT JOIN `{$this->App->prefix()}goods_cate` AS tb2 ON tb1.cat_id = tb2.cat_id";
         $sql .= " WHERE tb1.goods_id='{$gid}'";
         $this->set('subcatelist', $this->App->find($sql));
         $this->set('type', 'edit');
     } else {
         //添加
         if (isset($_POST) && !empty($_POST)) {
             if (empty($_POST['goods_name'])) {
                 echo '<script>alert("商品名称不能为空!");</script>';
             } else {
                 $_POST['meta_keys'] = !empty($_POST['meta_keys']) ? str_replace(array(',', '。', '.'), ',', $_POST['meta_keys']) : "";
                 $_POST['add_time'] = mktime();
                 if (!isset($_POST['goods_sn']) || empty($_POST['goods_sn'])) {
                     $gid = $this->App->findvar("SELECT MAX(goods_id) + 1 FROM `{$this->App->prefix()}goods`");
                     $gid = empty($gid) ? 1 : $gid;
                     $goods_sn = 'GZFH' . str_repeat('0', 6 - strlen($gid)) . $gid;
                     $_POST['goods_sn'] = $goods_sn;
                 }
                 //检查当前的货号是否存在
                 $checkvar = $this->App->findvar("SELECT goods_sn FROM `{$this->App->prefix()}goods` WHERE goods_sn={$_POST['goods_sn']} LIMIT 1");
                 if (!empty($checkvar)) {
                     $_POST['goods_sn'] = $_POST['goods_sn'] . '-1';
                     //重新定义一个
                 }
                 //商品图片
                 if (!empty($_POST['original_img'])) {
                     $pa = dirname($_POST['original_img']);
                     $thumb = basename($_POST['original_img']);
                     //商品小图
                     if (isset($_POST['goods_thumb']) && !empty($_POST['goods_thumb'])) {
                         //留空即可
                     } else {
                         $_POST['goods_thumb'] = $pa . '/thumb_s/' . $thumb;
                     }
                     //商品中图
                     $_POST['goods_img'] = $pa . '/thumb_b/' . $thumb;
                 }
                 if ($this->App->insert('goods', $_POST)) {
                     ##########商品属性添加###########
                     $isertid = $this->App->iid();
                     if (!empty($attr_id_list) && !empty($isertid)) {
                         foreach ($attr_id_list as $kk => $id) {
                             if (empty($attr_value_list[$kk])) {
                                 continue;
                             }
                             $rtdata = array();
                             $rtdata['attr_id'] = $id;
                             $rtdata['attr_value'] = isset($attr_value_list[$kk]) ? $attr_value_list[$kk] : "NULL";
                             $rtdata['goods_id'] = $isertid;
                             $rtdata['attr_addi'] = isset($attr_addi_list[$kk]) ? $attr_addi_list[$kk] : "";
                             $this->App->insert('goods_attr', $rtdata);
                         }
                         unset($rtdata);
                     }
                     ###########添加商品相册##########
                     if (!empty($photo_gallery_url) && !empty($isertid)) {
                         foreach ($photo_gallery_url as $kk => $url) {
                             if (empty($url)) {
                                 continue;
                             }
                             $rtdata['img_desc'] = isset($photo_gallery_desc[$kk]) ? $photo_gallery_desc[$kk] : "";
                             $rtdata['goods_id'] = $isertid;
                             $rtdata['img_url'] = $url;
                             $this->App->insert('goods_gallery', $rtdata);
                         }
                         unset($rtdata);
                     }
                     //商品的子分类
                     if (!empty($subcateid)) {
                         foreach ($subcateid as $ids) {
                             $dd = array();
                             $dd['goods_id'] = $isertid;
                             $dd['cat_id'] = $ids;
                             $this->App->insert('category_sub_goods', $dd);
                         }
                     }
                     //将关键字添加到goods_keyword表
                     if (!empty($_POST['meta_keys'])) {
                         $keys = explode(',', $_POST['meta_keys']);
                         foreach ($keys as $key) {
                             if (empty($key)) {
                                 continue;
                             }
                             $key = trim($key);
                             $ds = array();
                             $ds['goods_id'] = $isertid;
                             $ds['keyword'] = $key;
                             $n = Import::basic()->Pinyin($key);
                             $ds['p_fix'] = !empty($n) ? ucwords(substr($n, 0, 1)) : "NAL";
                             $this->App->insert('goods_keyword', $ds);
                         }
                         unset($keys);
                     }
                     //赠品
                     if (!empty($goods_gift_arr)) {
                         foreach ($goods_gift_arr as $tt) {
                             if (empty($tt)) {
                                 continue;
                             }
                             $dd['goods_id'] = $isertid;
                             $dd['type'] = $tt;
                             $sql = "SELECT gifid FROM `{$this->App->prefix()}goods_gift` WHERE goods_id='{$gid}' AND type='{$tt}'";
                             $a = $this->App->findvar($sql);
                             if (empty($a)) {
                                 $this->App->insert('goods_gift', $dd);
                             }
                         }
                     }
                     //会员等级价格添加
                     if (!empty($numberprice)) {
                         foreach ($numberprice as $ks => $price) {
                             if ($price > 0) {
                                 $dt = array();
                                 $dt['goods_id'] = $isertid;
                                 $dt['user_rank'] = $numberrank[$ks];
                                 $dt['user_price'] = $price;
                                 $this->App->insert('goods_user_price', $dt);
                             }
                         }
                     }
                     $this->action('system', 'add_admin_log', '添加商品:' . $_POST['goods_name'] . '-goods_id:' . $gid);
                     $this->action('common', 'showdiv', $this->getthisurl());
                 } else {
                     echo '<script> alert("添加失败,添加过程发生意外错误!"); </script>';
                 }
             }
             $rt = $_POST;
         }
         $this->set('type', 'add');
     }
     //商品的属性列表
     $sql = "SELECT * FROM `{$this->App->prefix()}attribute` ORDER BY sort_order,attr_id DESC";
     $this->set('attr_list', $this->App->find($sql));
     $fn = SYS_PATH . 'data/goods_spend_gift.php';
     $spendgift = array();
     if (file_exists($fn) && is_file($fn)) {
         include_once $fn;
     }
     $rt['gift_typesd'] = $spendgift;
     unset($spendgift);
     //$rt['province'] = $this->action('user','get_regions',1);  //获取省列表
     $this->set('rt', $rt);
     //分类列表
     $this->set('catelist', $this->action('common', 'get_goods_cate_tree'));
     //品牌列表
     $this->set('brandlist', $this->action('common', 'get_brand_cate_tree'));
     //会员等级
     $this->set('userrank', $this->App->find("SELECT * FROM `{$this->App->prefix()}user_level` WHERE lid!='10'"));
     $userprice = array();
     if ($gid > 0) {
         $userprice_ = $this->App->find("SELECT user_price,user_rank FROM `{$this->App->prefix()}goods_user_price` WHERE goods_id='{$gid}'");
         if (!empty($userprice_)) {
             foreach ($userprice_ as $row) {
                 $userprice[$row['user_rank']] = $row['user_price'];
             }
             unset($userprice_);
         }
     }
     $this->set('userprice', $userprice);
     $this->template('info');
 }
 function ajax_addads_info($data = array(), $id = 0)
 {
     if (!empty($data['tid'])) {
         //生成指定宽度高度的图片
         $tid = $data['tid'];
         $sql = "SELECT ad_width,ad_height FROM `{$this->App->prefix()}ad_position` WHERE tid='{$tid}'";
         $rr = $this->App->findrow($sql);
         $width = $rr['ad_width'];
         $height = $rr['ad_height'];
         if (!empty($width) && !empty($height) && !empty($data['ad_img'])) {
             if (!empty($id)) {
                 $sql = "SELECT ad_img FROM `{$this->App->prefix()}ad_content` WHERE pid='{$id}'";
                 $var = $this->App->findvar($sql);
                 if ($data['ad_img'] != $var) {
                     Import::fileop()->delete_file(SYS_PATH . $var);
                     //删除文件
                     $q = dirname($var);
                     $h = basename($var);
                     Import::fileop()->delete_file(SYS_PATH . $q . DS . 'thumb_s' . DS . $h);
                     Import::fileop()->delete_file(SYS_PATH . $q . DS . 'thumb_b' . DS . $h);
                     if (file_exists(SYS_PATH . $data['ad_img'])) {
                         Import::img()->thumb(SYS_PATH . $data['ad_img'], SYS_PATH . $data['ad_img'], $width, $height);
                     }
                 }
             }
         }
     }
     if (!empty($id)) {
         $data['uptime'] = time();
     } else {
         $data['addtime'] = time();
     }
     $ad_name = $data['ad_name'];
     if (empty($id)) {
         if ($this->App->insert('ad_content', $data)) {
             @file_get_contents(SITE_URL . 'data/flashdata/dynfocus/loadjs.php');
             //将数据写入文件
             $this->action('system', 'add_admin_log', '添加广告:' . $ad_name);
         } else {
             echo "无法添加广告,意外错误!";
         }
     } else {
         if ($this->App->update('ad_content', $data, 'pid', $id)) {
             @file_get_contents(SITE_URL . 'data/flashdata/dynfocus/loadjs.php');
             //将数据写入文件
             $this->action('system', 'add_admin_log', '修改广告:' . (empty($ad_name) ? "激活状态" : $ad_name));
         } else {
             echo "数据未变动,无需更新!";
         }
     }
     exit;
 }
 function ajax_suppliers_upload_cache_photo($data = array())
 {
     if (empty($data['str_spec'])) {
         die("非法!");
     }
     $uid = $this->check_is_suppliers();
     @set_time_limit(600);
     //最大运行时间
     $ar_spec = explode('++', $data['str_spec']);
     $goods = array();
     $photo_gallery_desc = array();
     $photo_gallery_url = array();
     foreach ($ar_spec as $str) {
         $item_ar = @explode('---', $str);
         if (count($item_ar) == 3) {
             if (in_array($item_ar[0], array('photo_gallery_desc', 'photo_gallery_url'))) {
                 if ($item_ar[0] == 'photo_gallery_desc') {
                     $photo_gallery_desc[$item_ar[2]][] = $item_ar[1];
                     //相册描述
                 } elseif ($item_ar[0] == 'photo_gallery_url') {
                     $photo_gallery_url[$item_ar[2]][] = $item_ar[1];
                     //相册图片
                 }
             } else {
                 $goods[$item_ar[2]][$item_ar[0]] = $item_ar[1];
             }
         }
     }
     $datas = array();
     $imgobj = Import::img();
     foreach ($goods as $item => $row) {
         if (empty($row['goods_bianhao'])) {
             $gid = $this->App->findvar("SELECT MAX(goods_id) + 1 FROM `{$this->App->prefix()}goods`");
             $gid = empty($gid) ? 1 : $gid;
             $goods_bianhao = '2EJ' . str_repeat('0', 6 - strlen($gid)) . $gid;
         } else {
             $goods_bianhao = $row['goods_bianhao'];
         }
         //检查是否已经存在
         if (empty($row['goods_sn'])) {
             $row['goods_sn'] = $goods_bianhao;
         }
         $ginfo = $this->App->findrow("SELECT goods_id,goods_thumb,goods_img,original_img FROM `{$this->App->prefix()}goods` WHERE goods_sn='{$row['goods_sn']}'");
         $gid = isset($ginfo['goods_id']) ? $ginfo['goods_id'] : 0;
         $datas['goods_bianhao'] = $goods_bianhao;
         $datas['goods_sn'] = $row['goods_sn'];
         if ($row['goods_numbers'] > 0) {
             $datas['goods_number'] = $row['goods_numbers'];
         }
         $datas['goods_name'] = $row['goods_name'];
         if ($row['pifa_price'] > 0) {
             $datas['market_price'] = $row['pifa_price'];
         }
         if ($row['pifa_price'] > 0) {
             $datas['pifa_price'] = $row['pifa_price'];
         }
         if ($row['shop_price'] > 0) {
             $datas['shop_price'] = $row['shop_price'];
         }
         if ($row['cat_id'] > 0) {
             $datas['cat_id'] = $row['cat_id'];
         }
         if ($row['brand_id'] > 0) {
             $datas['brand_id'] = $row['brand_id'];
         }
         $datas['goods_brief'] = $row['goods_brief'];
         $datas['goods_unit'] = $row['goods_unit'];
         if ($row['goods_weight'] > 0) {
             $datas['goods_weight'] = $row['goods_weight'];
         }
         if ($row['warn_number'] > 0) {
             $datas['warn_number'] = $row['warn_number'];
         }
         if (!empty($row['sourcepathname'])) {
             $imgobj->filecopy($row['sourcepathname'], $row['uploadname']);
             if ($gid > 0) {
                 $fop = Import::fileop();
                 //删除原来的图片
                 $fop->delete_file(SYS_PATH . $ginfo['goods_thumb']);
                 $fop->delete_file(SYS_PATH . $ginfo['goods_img']);
                 $fop->delete_file(SYS_PATH . $ginfo['original_img']);
                 //商品相册
                 /*$sql = "SELECT img_url FROM `{$this->App->prefix()}goods_gallery` WHERE goods_id ='$gid'";
                 		$gallery_img = $this->App->findcol($sql);
                 		if(!empty($gallery_img)){
                 			foreach($gallery_img as $img){
                 				$q = dirname($img);
                 				$h = basename($img);
                 				$fop->delete_file(SYS_PATH.$q.DS.'thumb_s'.DS.$h);
                 				$fop->delete_file(SYS_PATH.$q.DS.'thumb_b'.DS.$h);
                 				$fop->delete_file(SYS_PATH.$img); //
                 			}
                 			unset($gallery_img);
                 		}*/
                 unset($ginfo);
             }
         } else {
             continue;
         }
         if (!file_exists($row['uploadname'])) {
             continue;
         }
         $thumb = basename($row['uploadname']);
         $pa = 'photos/goods/' . date('Ym', mktime()) . '/';
         $tw_s = intval($GLOBALS['LANG']['th_width_s']) > 0 ? intval($GLOBALS['LANG']['th_width_s']) : 200;
         $th_s = intval($GLOBALS['LANG']['th_height_s']) > 0 ? intval($GLOBALS['LANG']['th_height_s']) : 200;
         $tw_b = intval($GLOBALS['LANG']['th_width_b']) > 0 ? intval($GLOBALS['LANG']['th_width_b']) : 450;
         $th_b = intval($GLOBALS['LANG']['th_height_b']) > 0 ? intval($GLOBALS['LANG']['th_height_b']) : 450;
         $datas['original_img'] = $pa . $thumb;
         //原始图
         Import::img()->thumb($row['uploadname'], dirname($row['uploadname']) . DS . 'thumb_s' . DS . $thumb, $tw_s, $th_s);
         //小缩略图
         $datas['goods_thumb'] = $pa . 'thumb_s/' . $thumb;
         Import::img()->thumb($row['uploadname'], dirname($row['uploadname']) . DS . 'thumb_b' . DS . $thumb, $tw_b, $th_b);
         //大缩略图
         $datas['goods_img'] = $pa . 'thumb_b/' . $thumb;
         if ($gid > 0) {
             $datas['last_update'] = mktime();
             $this->App->update('goods', $datas, 'goods_id', $gid);
         } else {
             $datas['add_time'] = mktime();
             $this->App->insert('goods', $datas);
             $gid = $this->App->iid();
         }
         ##########商品属性###########
         $ds = array();
         if (!empty($ds)) {
             foreach ($ds as $irow) {
                 $irow['goods_id'] = $gid;
                 $this->App->insert('goods_attr', $irow);
             }
         }
         ##########商品相册图片添加########
         if (isset($photo_gallery_url[$item]) && !empty($photo_gallery_url[$item])) {
             foreach ($photo_gallery_url[$item] as $k => $url) {
                 if (empty($url)) {
                     continue;
                 }
                 $rows['goods_id'] = $gid;
                 $rows['img_url'] = $url;
                 $rows['img_desc'] = $photo_gallery_desc[$item][$k];
                 $this->App->insert('goods_gallery', $rows);
             }
         }
         $sql = "SELECT sgid FROM `{$this->App->prefix()}suppliers_goods` WHERE goods_id='{$gid}' AND suppliers_id='{$uid}'";
         $sgid = $this->App->findvar($sql);
         $dd = array();
         $dd['goods_number'] = $datas['goods_number'] > 0 ? $datas['goods_number'] : 1000;
         $dd['warn_number'] = $datas['warn_number'] > 0 ? $datas['warn_number'] : 10;
         if ($row['pifa_price'] > 0) {
             $dd['market_price'] = $row['pifa_price'];
         }
         if ($row['pifa_price'] > 0) {
             $dd['pifa_price'] = $row['pifa_price'];
         }
         $dd['is_on_sale'] = 1;
         if ($row['shop_price'] > 0) {
             $dd['shop_price'] = $row['shop_price'];
         }
         $dd['is_check'] = 0;
         if (empty($sgid) || !($sgid > 0)) {
             $dd['goods_id'] = $gid;
             $dd['suppliers_id'] = $uid;
             $dd['addtime'] = mktime();
             $this->App->insert('suppliers_goods', $dd);
         } else {
             //更新
             $this->App->update('suppliers_goods', $dd, array("suppliers_id='{$uid}'", "goods_id='{$gid}'"));
         }
         unset($dd);
     }
     unset($ar_spec, $data, $goods);
     exit;
 }