I('num'), 'title' => '', 'upload' => U('Admin/Ueditor/imageUp', array('savepath' => $path, 'savepath1' => $path1, 'tablename' => $tablename, 'indexid' => $indexid, 'imgname' => $imgname, 'addoldimg' => $addoldimg, 'curid' => $curid, 'pictitle' => 'banner', 'dir' => 'images')), 'size' => '500k', 'type' => 'jpg,png,gif,jpeg', 'input' => I('input'), 'isdellocalimg' => $isdellocalimg, 'tablename' => $tablename, 'func' => empty($func) ? 'undefined' : $func, ); $this->assign('info', $info); return $this->fetch('', getAdmStoId()); } /* 删除上传的图片 */ public function delupload() { $info = array( 'status' => 1, 'msg' => 0, ); $action = I('action'); $filename = I('filename'); $filename1 = $filename; $delqclo = I('delqclo'); $delsmall = I('delsmall'); $delwximglist = I('delwximglist'); $tablename = I('tablename'); $filename = str_replace('../', '', $filename); $filename = trim($filename, '.'); $filename = trim($filename, '/'); $store_id = getAdmStoId(); if (!empty($_SESSION['manager_id']) && $tablename == 'manager') { $manager = D('manager_admin')->where('manager_id', $_SESSION['manager_id'])->find(); if ($manager) { $store_id = 0; } } if ($action == 'del' && !empty($filename)) { // if (file_exists(ROOT_PATH . $filename)) { // $size = getimagesize($filename); // $filetype = explode('/', $size['mime']); // // if ($filetype[0] != 'image') { // return false; // exit; // } // $filesize = filesize($filename); $sfilename = "s_" . basename($filename); $sdir = dirname($filename); $newsfilename = $sdir . "/" . $sfilename; //如果是微信菜单上传的图片 if ($tablename == "store_wximglist") { $file_info = array('filename' => $filename1, //国片相对于网站根目录的路径 'content-type' => $filetype[1], //文件类型 'filelength' => $filesize //图文大小 ); $access_token = m_get_access_token(null,$store_id); $url = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token={$access_token}&type=image"; $real_path = "{$_SERVER['DOCUMENT_ROOT']}{$file_info['filename']}"; // $data = array("media" => "@{$real_path}", 'form-data' => $file_info); if (class_exists('\CURLFile')) { $data['media'] = new \CURLFile($real_path, $size['mime'], basename($filename1)); } else { $data = array( 'media' => '@' . realpath($filename) . ";type=" . $filetype[1] . ";filename=" . basename($filename1) ); } $wxres = wx_https_request($url, 'post', 'json', $data); if ($wxres['media_id']) { $savedate['store_id'] = getAdmStoId(); $savedate['imgname'] = basename($filename); $savedate['img'] = $filename1; $savedate['media_id'] = $wxres['media_id']; $savedate['url'] = $wxres['url']; $savedate['localpath'] = 'wechat'; $savedate['wid'] = $size[0]; $savedate['hei'] = $size[1]; $savedate['addtime'] = time(); $info = array( 'status' => 1, 'media_id' => $wxres['media_id'], 'msg' => 0, ); D('store_wximglist')->save($savedate); } } //腾讯云 if ($delqclo == "1") { vendor('qcloudcos.myqcloudcos'); $delres = Myqcloudcos::delFile('wxd', $filename); //var_dump($filename);die; if ($delsmall == "1") { $delres = Myqcloudcos::delFile('wxd', $newsfilename); } } mdelFile($filename); if ($delsmall == "1") { //unlink($newsfilename); mdelFile($newsfilename); } //图片库 if ($delwximglist == "1") { $model = M("store_wximglist"); $model->where(array('img' => $filename1, 'store_id' => $store_id))->delete(); } exit(json_encode($info)); } // } } /****** 图库删除图片 *****/ public function delupload1() { $info = array( 'status' => 1, 'msg' => 0, ); $action = I('action'); $filename = I('filename'); $filename1 = $filename; $delqclo = I('delqclo'); $delsmall = I('delsmall'); $delwximglist = I('delwximglist'); $tablename = I('tablename'); $filename = str_replace('../', '', $filename); $filename = trim($filename, '.'); $filename = trim($filename, '/'); $store_id = getAdmStoId(); if (empty($store_id)) $store_id = 0; if (!empty($_SESSION['manager_id']) && $tablename == 'manager') { $manager = D('manager_admin')->where('manager_id', $_SESSION['manager_id'])->find(); if ($manager) { $store_id = 0; } } if (!empty($filename)) { $sfilename = "s_" . basename($filename); $sdir = dirname($filename); $newsfilename = $sdir . "/" . $sfilename; //腾讯云 if ($delqclo == "1") { vendor('qcloudcos.myqcloudcos'); $delres = Myqcloudcos::delFile('wxd', $filename); if ($delsmall == "1") { $delres = Myqcloudcos::delFile('wxd', $newsfilename); } } //mdelFile($filename); if ($delsmall == "1") { mdelFile($newsfilename); } //图片库 if ($delwximglist == "1") { $model = M("store_wximglist"); $model->where(array('img' => $filename1, 'store_id' => $store_id))->delete(); } exit(json_encode($info)); } } /***** 图库页面展示 *****/ public function upload1() { $func = I('func'); $path = I('path', 'temp'); $path1 = I('path1', 'temp'); $tablename = I('tablename'); $isdellocalimg = 1; $gid = I('groupid'); if ($tablename == "store_config" || $tablename == "marketing" || $tablename == "weixin") { $isdellocalimg = 0; } $info = array( 'num' => I('num/d'), 'title' => '', 'upload' => U('Admin/Ueditor/imageUp1', array('savepath' => $path, 'savepath1' => $path1, 'tablename' => $tablename, 'pictitle' => 'banner', 'dir' => 'images', 'groupid' => $gid)), 'size' => '500k', 'type' => 'jpg,png,gif,jpeg', 'input' => I('input'), 'isdellocalimg' => $isdellocalimg, 'tablename' => $tablename, 'func' => empty($func) ? 'undefined' : $func, 'cururl' => U('Admin/uploadify/upload1', array('num' => I('num/d'), 'path' => $path, 'path1' => $path1, 'tablename' => $tablename, 'func' => (empty($func) ? 'undefined' : $func), 'groupid' => 'currentgid')), ); $list = array(); $p = input('p/d', 1); $size = input('size/d', 12); $where = array(); $store_id = getAdmStoId(); if (!empty($_SESSION['manager_id']) && $tablename == 'manager') { $manager = D('manager_admin')->where('manager_id', $_SESSION['manager_id'])->find(); if ($manager) { $store_id = 0; } } /*--添加门店ID--*/ $where["store_id"] = $store_id; if ($gid != '') { $where["groupid"] = $gid; } if ($tablename == "store_wximglist" || $tablename == "weixin") { $where['media_id'] = array('neq', 'null'); } // else // { // $where['media_id']=['=',null]; // } $modal = M('store_wximglist'); $res = $modal->where($where)->order('addtime desc')->page("$p,$size")->select(); $count = $modal->where($where)->count();// 查询满足要求的总记录数 $pager = new Page($count, $size);// 实例化分页类 传入总记录数和每页显示的记录数 $page = $pager->show();//分页显示输出 $amount = $modal->where($where)->count();//当前商家图库总数 $groupamount = $modal->where($where)->field("count(1) as num,groupid")->group("groupid")->select(); //按分组统计 $grouplist = M('store_wximggroup')->where(array('store_id' => $store_id))->field('id,group_name,0 as num')->select(); //所有分组 $unknow = array( 'id' => 0, 'group_name' => '未分组', 'num' => 0 ); //$grouplist[]=$unknow; //新增一条未分组记录 array_unshift($grouplist, $unknow); //头部插入一条记录 //var_dump($grouplist); if (!empty($grouplist)) { foreach ($grouplist as $item) { if (!empty($groupamount)) { foreach ($groupamount as $item1) { if ($item1['groupid'] == $item['id']) { $item['num'] = $item1['num']; } } } $item2[] = $item; } } $this->assign('gid', $gid);//当前分组ID $this->assign('groupid', ($gid == '' ? -1 : $gid));// $this->assign('all', ($gid == '' ? -1 : 1)); $this->assign('groupinfo', $item2); $this->assign('page', $page);// 赋值分页输出 $this->assign('pager', $pager); $this->assign('tablename', $tablename); $this->assign('list', $res);// 赋值数据集 $this->assign('count', $amount); $this->assign('info', $info); return $this->fetch(); } /******* 删除本地图片 *******/ public function dellocalhost() { $info = array( 'status' => 1, 'msg' => 0, ); $filename = I('filename'); $filename = str_replace('../', '', $filename); $filename = trim($filename, '.'); $filename = trim($filename, '/'); if (!empty($filename)) { if (file_exists(ROOT_PATH . $filename)) { mdelFile($filename); } } exit(json_encode($info)); } public function preview() { // 此页面用来协助 IE6/7 预览图片,因为 IE 6/7 不支持 base64 $DIR = 'preview'; // Create target dir if (!file_exists($DIR)) { @mkdir($DIR); } $cleanupTargetDir = true; // Remove old files $maxFileAge = 5 * 3600; // Temp file age in seconds if ($cleanupTargetDir) { if (!is_dir($DIR) || !$dir = opendir($DIR)) { die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}'); } while (($file = readdir($dir)) !== false) { $tmpfilePath = $DIR . DIRECTORY_SEPARATOR . $file; // Remove temp file if it is older than the max age and is not the current file if (@filemtime($tmpfilePath) < time() - $maxFileAge) { @unlink($tmpfilePath); } } closedir($dir); } $src = file_get_contents('php://input'); if (preg_match("#^data:image/(\w+);base64,(.*)$#", $src, $matches)) { $previewUrl = sprintf( "%s://%s%s", isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http', $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'] ); $previewUrl = str_replace("preview.php", "", $previewUrl); $base64 = $matches[2]; $type = $matches[1]; if ($type === 'jpeg') { $type = 'jpg'; } $filename = md5($base64) . ".$type"; $filePath = $DIR . DIRECTORY_SEPARATOR . $filename; if (file_exists($filePath)) { die('{"jsonrpc" : "2.0", "result" : "' . $previewUrl . 'preview/' . $filename . '", "id" : "id"}'); } else { $data = base64_decode($base64); file_put_contents($filePath, $data); die('{"jsonrpc" : "2.0", "result" : "' . $previewUrl . 'preview/' . $filename . '", "id" : "id"}'); } } else { die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "un recoginized source"}}'); } } //获取当前图片在公众号的media_id public function getwxid() { $tablename = I('tablename'); $store_id = getAdmStoId(); if (!empty($_SESSION['manager_id']) && empty($store_id))// { $store_id = 0; } $info1 = array( 'status' => 0, 'msg' => '0', ); $result = ''; $filename1 = $filename = I('filename'); $info = M('store_wximglist')->where(array('store_id' => $store_id, 'img' => $filename))->find(); //var_dump($info);die; if (!empty($info)) { if (empty($info['media_id'])) //当前图片未上传至微信公众号 { $filename = str_replace('../', '', $filename); $filename = trim($filename, '.'); $filename = trim($filename, '/'); $size = getimagesize($filename); $filetype = explode('/', $size['mime']); if ($filetype[0] != 'image') { return false; exit; } //$wechat = D('wx_user')->where('store_id', getAdmStoId())->find(); //$jssdk = new \app\mobile\logic\Jssdk($wechat['appid'], $wechat['appsecret']); //$access_token = $jssdk->get_access_token(); $access_token = m_get_access_token(null,getAdmStoId()); $url = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token={$access_token}&type=image"; $real_path = "{$_SERVER['DOCUMENT_ROOT']}/{$filename}"; if (class_exists('\CURLFile')) { $data['media'] = new \CURLFile($real_path, $size['mime'], basename($filename1)); } else { $data = array( 'media' => '@' . realpath($filename) . ";type=" . $filetype[1] . ";filename=" . basename($filename1) ); } $wxres = wx_https_request($url, 'post', 'json', $data); if ($wxres['media_id']) { $savedate['media_id'] = $wxres['media_id']; $savedate['url'] = $wxres['url']; $result = $wxres['media_id']; //删除本地图片 if (file_exists(ROOT_PATH . $filename)) { mdelFile($filename); } D('store_wximglist')->where(array('store_id' => $store_id, 'img' => $filename1))->save($savedate); } } else { $result = $info['media_id']; } } if (!empty($result)) { $info1 = array( 'status' => 1, 'media_id' => $result, ); } //var_dump($info1); //return $info1; exit(json_encode($info1)); } //新增分组 public function addgroup() { $info = array( 'status' => 0, 'msg' => '0', ); $group_name = I('group_name'); $store_id = getAdmStoId(); $tablename = I('tablename'); if (!empty($_SESSION['manager_id']) && $tablename == 'manager') { $manager = D('manager_admin')->where('manager_id', $_SESSION['manager_id'])->find(); if ($manager) { $store_id = 0; } } if (!empty($group_name)) { $data['group_name'] = $group_name; $data['store_id'] = $store_id; $data['group_addtime'] = time(); $model = M('store_wximggroup')->add($data); if ($model > 0) { $info = array( 'status' => 1, 'groupid' => $model, ); } } exit(json_encode($info)); } //删除分组 public function delgroup() { $info = array( 'status' => 0, 'msg' => '0', ); $id = I('id'); $store_id = getAdmStoId(); $tablename = I('tablename'); if (!empty($_SESSION['manager_id']) && $tablename == 'manager') { $manager = D('manager_admin')->where('manager_id', $_SESSION['manager_id'])->find(); if ($manager) { $store_id = 0; } } if (!empty($id)) { M('store_wximglist')->where(array('groupid' => $id, 'store_id' => $store_id))->update(array('groupid' => 0)); $model = M('store_wximggroup')->where(array('id' => $id))->delete(); if ($model > 0) { $info = array( 'status' => 1, ); } } exit(json_encode($info)); } //移动分组 public function movegroup() { $info = array( 'status' => 0, 'msg' => '0', ); $tablename = I('tablename'); $store_id = getAdmStoId(); if (!empty($_SESSION['manager_id']) && $tablename == 'manager') { $manager = D('manager_admin')->where('manager_id', $_SESSION['manager_id'])->find(); if ($manager) { $store_id = 0; } } $id = I('id');//图片ID $groupid = I('groupid'); //将移动到的分组ID if (!empty($id) && !empty($groupid)) { $model = M('store_wximglist')->where(array('id' => $id, 'store_id' => $store_id))->update(array('groupid' => $groupid)); mlog($model, "1122"); if ($model > 0) { $info = array( 'status' => 1, ); } } exit(json_encode($info)); } //修改分组名称 public function updategroup() { $info = array( 'status' => 0, 'msg' => '0', ); $tablename = I('tablename'); $store_id = getAdmStoId(); if (!empty($_SESSION['manager_id']) && $tablename == 'manager') { $manager = D('manager_admin')->where('manager_id', $_SESSION['manager_id'])->find(); if ($manager) { $store_id = 0; } } $id = I('id'); $group_name = I('group_name'); if (!empty($id) && !empty($group_name)) { $model = M('store_wximggroup')->where(array('id' => $id, 'store_id' => $store_id))->update(array('group_name' => $group_name)); if ($model > 0) { $info = array( 'status' => 1, 'group_name' => $group_name, ); } } exit(json_encode($info)); } //修改图片命名 public function updateimgname() { $info = array( 'status' => 0, 'msg' => '0', ); $id = I('id'); $tablename = I('tablename'); $store_id = getAdmStoId(); if (!empty($_SESSION['manager_id']) && $tablename == 'manager') { $manager = D('manager_admin')->where('manager_id', $_SESSION['manager_id'])->find(); if ($manager) { $store_id = 0; } } $imgname = I('imgname'); if (!empty($id) && !empty($imgname)) { $model = M('store_wximglist')->where(array('id' => $id, 'store_id' => $store_id))->update(array('imgname' => $imgname)); if ($model > 0) { $info = array( 'status' => 1, 'imgname' => $imgname, ); } } exit(json_encode($info)); } public function delfile() { $path = I("filename"); mdelFile(ROOT_PATH . $path); return 1; } /*----------------------------商品选择-----------------------------*/ public function search_goods() { $stoid = getAdmStoId(); if (empty($stoid)) $stoid = 1; $GoodsLogic = new GoodsLogic(); $brandList = $GoodsLogic->t_getSortBrands($stoid); $categoryList = $GoodsLogic->t_getSortCategory($stoid); $this->assign('categoryList', $categoryList); $this->assign('brandList', $brandList); $pagenum = 10;//每页显示多少条 if ((int)I('pagenum/s') > 0) { $pagenum = I('pagenum/s'); } $where = ' 1 = 1 and is_on_sale=1'; // 搜索条件 I('intro') && $where = "$where and " . I('intro') . " = 1"; I('brand_id') && $where = "$where and brand_id = " . I('brand_id'); (I('is_on_sale') !== '') && $where = "$where and is_on_sale = " . I('is_on_sale'); $cat_id = I('cat_id'); $brand_id=I('brand_id'); // 关键词搜索 $key_word = trim(urldecode(urldecode(I('key_word')))); $this->assign('key_word',$key_word); if ($key_word) { $where = "$where and (goods_name like '%$key_word%' or goods_sn like '%$key_word%' or keywords like '%$key_word%' or sku='$key_word')"; } $where .= " and store_id=" . $stoid; if ($cat_id > 0) { $grandson_ids = getCatGrandson($cat_id); $where .= " and cat_id in(" . implode(',', $grandson_ids) . ") "; // 初始化搜索条件 } $t=time(); $where.=" and on_time<".$t." and (down_time>".$t." or down_time=0 or down_time='' or down_time is null)"; $model = M('Goods'); $count = $model->where($where)->count(); $pager = new Page($count, $pagenum); $show = $pager->show(); $goodsList = $model->where($where)->limit($pager->firstRow . ',' . $pager->listRows)->select(); $catList = D('goods_category')->where(" store_id=" . $stoid)->select(); $catList = convert_arr_key($catList, 'id'); $this->assign('catList', $catList); $this->assign('goodsList', $goodsList); $this->assign('pager', $pager); $this->assign('page', $show);// 赋值分页输出 $this->assign('cat_id',$cat_id); $this->assign('brand_id',$brand_id); $this->assign('pagenum', $pagenum); /*回调函数*/ $this->assign("func", I('func')); upload_ylp_log('搜索商品'); return $this->fetch('', $stoid); } /*------------------选择商品分组------------------*/ public function search_goods_group() { $stoid = getAdmStoId(); if (empty($stoid)) $stoid = 1; $goods_group = M('goods_group'); $list = array(); $p = input('p/d', 1); $size = input('size/d', 5); $where = array(); /*--添加门店ID--*/ $where["store_id"] = $stoid; $keywords = trim(I('keywords')); $keywords && $where['gpname'] = array('like', '%' . $keywords . '%'); $where['status'] = 1; $list = $goods_group->where($where)->order('add_time desc')->page("$p,$size")->select(); $count = $goods_group->where($where)->count();// 查询满足要求的总记录数 $pager = new Page($count, $size);// 实例化分页类 传入总记录数和每页显示的记录数 $page = $pager->show();//分页显示输出 $this->assign('grouplist', $list);// 赋值数据集 $this->assign('page', $page);// 赋值分页输出 $this->assign('pager', $pager); /*回调函数*/ $this->assign("func", I('func')); upload_ylp_log('搜索商品分组'); return $this->fetch('', $stoid); } /*---------------------------音频选择---------------------------*/ public function search_audio() { $stoid = getAdmStoId(); if (empty($stoid)) $stoid = 1; $model = M('audio'); $where = "store_id=" . $stoid; $count = $model->where($where)->count(); $pager = new Page($count, 5); $rs = $model->where($where)->order('id desc')->limit($pager->firstRow . ',' . $pager->listRows)->select(); $show = $pager->show(); $this->assign('pager', $pager); $this->assign('page', $show);// 赋值分页输出 $this->assign('data', $rs); return $this->fetch('', $stoid); } /*-------------------团购-------------------*/ public function search_group_ware() { /*回调函数*/ $this->assign("func", I('func')); $stoid = getAdmStoId(); if (empty($stoid)) $stoid = 1; $where = ' 1 = 1 '; // 搜索条件 $time = time(); // 关键词搜索 $key_word = trim(urldecode(urldecode(I('key_word')))); $this->assign('key_word',$key_word); if ($key_word) { $where = "$where and (a.title like '%$key_word%' or a.goods_name like '%$key_word%' or g.sku like '%$key_word%' )"; } $where .= " and a.is_end = 0 and a.store_id=" . $stoid; $where .= " and a.start_time<=" . $time . " and a.end_time>=" . $time; $where.=" and g.is_on_sale=1 and g.is_mainshow=1 and g.on_time<".$time." and (g.down_time>".$time." or g.down_time=0 or g.down_time='' or g.down_time is null)"; $model = M('group_buy'); $count = $model->alias('a')->join('goods g', 'a.goods_id=g.goods_id and a.id=g.prom_id', 'left')->where($where)->count(); $pager = new Page($count, 5); $rs = $model->alias('a')->join('goods g', 'a.goods_id=g.goods_id and a.id=g.prom_id', 'left')->where($where)->order('a.ordid asc,a.id desc')->limit($pager->firstRow . ',' . $pager->listRows)->field('a.*,g.market_price,g.shop_price,g.original_img')->select(); $show = $pager->show(); $this->assign('pager', $pager); $this->assign('page', $show);// 赋值分页输出 $this->assign('data', $rs); upload_ylp_log('团购'); return $this->fetch('', $stoid); } /*-------------------秒杀-------------------*/ public function search_skill_ware() { /*回调函数*/ $this->assign("func", I('func')); $stoid = getAdmStoId(); if (empty($stoid)) $stoid = 1; $where = ' 1 = 1 '; // 搜索条件 $where .= " and a.store_id=" . $stoid; $time = time(); // 关键词搜索 $key_word = I('key_word') ? trim(I('key_word')) : ''; if ($key_word) { $where = "$where and (a.title like '%$key_word%' or a.goods_name like '%$key_word%' or g.sku like '%$key_word%' )"; } $where .= " and a.is_end=0 and a.show_time<=" . $time . " and a.end_time>=" . $time; $where.=" and g.is_on_sale=1 and g.is_mainshow=1 and g.on_time<".$time." and (g.down_time>".$time." or g.down_time=0 or g.down_time='' or g.down_time is null)"; $model = M('flash_sale'); $count = $model->alias('a')->join('goods g', 'a.goods_id=g.goods_id and a.id=g.prom_id')->where($where)->count(); $pager = new Page($count, 5); $rs = $model->alias('a')->join('goods g', 'a.goods_id=g.goods_id and a.id=g.prom_id')->where($where)->order('a.ordid asc,a.id desc')->limit($pager->firstRow . ',' . $pager->listRows)->field('a.*,g.market_price,g.shop_price,g.original_img')->select(); $show = $pager->show(); $this->assign('pager', $pager); $this->assign('page', $show);// 赋值分页输出 $this->assign('data', $rs); upload_ylp_log('秒杀'); return $this->fetch('', $stoid); } public function upload2() { $func = I('func'); $path = I('path', 'temp'); $path1 = I('path1', 'temp'); $tablename = I('tablename'); $indexid = I('indexid'); $imgname = I('imgname'); $curid = I('curid'); $addoldimg = urlencode(I('addoldimg')); $isdellocalimg = 1; if ($tablename == "store_config" || $tablename == "marketing") { $isdellocalimg = 0; } $info = array( 'num' => I('num'), 'title' => '', 'upload' => U('Admin/Ueditor/imageUp', array('savepath' => $path, 'savepath1' => $path1, 'tablename' => $tablename, 'indexid' => $indexid, 'imgname' => $imgname, 'addoldimg' => $addoldimg, 'curid' => $curid, 'pictitle' => 'banner', 'dir' => 'images')), 'size' => '500k', 'type' => 'jpg,png,gif,jpeg', 'input' => I('input'), 'isdellocalimg' => $isdellocalimg, 'tablename' => $tablename, 'func' => empty($func) ? 'undefined' : $func, ); $this->assign('info', $info); return $this->fetch('', getAdmStoId()); } /*-------------------拼单-------------------*/ public function search_pind_ware() { /*回调函数*/ $this->assign("func", I('func')); $stoid = getAdmStoId(); if (empty($stoid)) $stoid = 1; $where = ' 1 = 1 '; // 搜索条件 $where .= " and a.store_id=" . $stoid; $time = time(); // 关键词搜索 $key_word = I('key_word') ? trim(I('key_word')) : ''; if ($key_word) { $where = "$where and (a.title like '%$key_word%' or a.goods_name like '%$key_word%' or g.sku like '%$key_word%' )"; } $where .= " and a.is_end=0 and a.is_show=1 and a.show_time<=" . $time . " and a.end_time>=" . $time; $where.=" and g.is_on_sale=1 and g.is_mainshow=1 and g.on_time<".$time." and (g.down_time>".$time." or g.down_time=0 )"; $model = M('teamlist'); $count = $model->alias('a')->join('goods g', 'a.goods_id=g.goods_id and a.id=g.prom_id')->where($where)->count(); $pager = new Page($count, 5); $rs = $model->alias('a')->join('goods g', 'a.goods_id=g.goods_id and a.id=g.prom_id')->where($where)->order('id desc')->limit($pager->firstRow . ',' . $pager->listRows)->field('a.*,g.market_price,g.shop_price,g.original_img')->select(); $show = $pager->show(); $this->assign('pager', $pager); $this->assign('page', $show);// 赋值分页输出 $this->assign('data', $rs); upload_ylp_log('秒杀'); return $this->fetch('', $stoid); } //上传压缩文件 public function upload_zip() { $func = I('func'); $tablename = I('tablename'); $isdellocalimg = 1; $info = array( 'num' => I('num'), 'title' => '', 'upload' => U('Admin/Uploadify/up_cert',array('tablename'=>$tablename)), 'input' => I('input'), 'size' => '500k', 'func' => empty($func) ? 'undefined' : $func, ); $this->assign('info', $info); return $this->fetch('', getAdmStoId()); } /****** 删除压缩文件 *****/ public function delupload_zip() { $action = I('action'); $filename = I('filename'); if ($action == 'del' && !empty($filename)) { $p = $filename; if (file_exists($filename)) { unlink($filename); } exit(json(['code'=>1,'mgs'=>'删除成功'])); }else{ exit(json(['code'=>-1,'mgs'=>'删除失败'])); } } //上传证书 public function up_cert(){ //$erpid=tpCache('shop_info.ERPId',getAdmStoId()); $tablename = I('tablename',"wx_user"); $dir=ROOT_PATH.'/public/cert/'.getAdmStoId().'/'; if ($tablename=="weapp") { $dir=ROOT_PATH.'/public/cert/'.getAdmStoId().'/weapp/'; } //创建目录失败 if(!file_exists($dir) && !mkdir($dir,0777,true)){ $data=array( 'msg' => '目录创建失败', 'code'=>'-1' ); return json($data); }else if(!is_writeable($dir)){ $data=array( 'msg' => '目录没有写权限', 'code'=>'-1' ); return json($data); } //清除文件夹中的内容 delfile($dir); $file = request()->file('Filedata'); if(empty($file)) $file = request()->file('file'); //图库-新 if(empty($file)) $file = request()->file('upfile'); $info = $file->move($dir); $saveFileName = $info->getSaveName(); $zip = new \ZipArchive; $res = $zip->open($dir.$saveFileName); if ($res === TRUE) { //解压缩到test文件夹 $zip->extractTo($dir); $zip->close(); $state = "SUCCESS"; $dir1=$dir.'/apiclient_cert.pem'; $isup=0; //判断文件是否存在 if(file_exists($dir1)){ $isup=1; } //如果文件名不对,就要修改文件名 if($isup!=1){ //打开文件夹 $handle = opendir($dir); if($handle){ while(($fl = readdir($handle)) !== false){ $temp = $dir.DIRECTORY_SEPARATOR.$fl; //如果不加 $fl!='.' && $fl != '..' 则会造成把$dir的父级目录也读取出来 if(is_dir($temp) && $fl!='.' && $fl != '..'){ continue;//此处是目录 }else{ if($fl!='.' && $fl != '..'){ //如果文件名不对。就要修改 if(strpos($temp,'apiclient')=== false && strpos($temp,'pem')!==false){ $arr=explode('_',$temp); $n=count($arr)-1; $newname=$dir."apiclient_".$arr[$n]; rename($temp,$newname); //修改文件名 } //如果文件名不对。就要修改 if(strpos($temp,'apiclient')=== false && strpos($temp,'.p12')!==false){ $arr=explode('_',$temp); $n=count($arr)-1; $newname=$dir."apiclient_".$arr[$n]; rename($temp,$newname); //修改文件名 } } } } } } $return_data['title'] = "压缩文件"; $return_data['original'] = ''; // 这里好像没啥用 暂时注释起来 $return_data['state'] = $state; $return_data['path'] = $dir.$saveFileName; M($tablename)->where('store_id',getAdmStoId()) ->save(['wx_cert'=>$dir.$saveFileName]); return json($return_data); } else { $return_data['state'] = "ERROR"; return json($return_data); } } //上传视频 public function up_load_video(){ $qclurl=QCLOUD_IMGURL; $this->assign('qclurl',$qclurl); $gdata=M('up_video_group')->where('store_id',getAdmStoId()) ->select(); $this->assign('grpList',$gdata); return $this->fetch('', getAdmStoId()); } public function save_video(){ $video_name=I("video_name"); $group_id=I("group_id"); $video_img=I("video_img"); $video_time=I("video_time"); $file = request()->file('file'); $data['file_size']=round($file->getSize()/1024,2); $savePath = '/public/upload/video/'.getAdmStoId().'/'.date('Y').'/'.date('m-d').'/'; $dir=ROOT_PATH.$savePath; //创建目录失败 if(!file_exists($dir) && !mkdir($dir,0777,true)){ $data=array( 'msg' => '目录创建失败', 'code'=>'-1' ); return json($data); }else if(!is_writeable($dir)){ $data=array( 'msg' => '目录没有写权限', 'code'=>'-1' ); return json($data); } $info = $file->move($dir); $saveFileName = $info->getSaveName(); mlog("save_video:".$saveFileName,"upload_save_video/".getAdmStoId()); $name_arr=explode('\\',$saveFileName); $name_arr2=explode('/',$saveFileName); mlog("save_video1:".json_encode($name_arr),"upload_save_video/".getAdmStoId()); $db_filename=$savePath.$saveFileName; //保存到腾讯云的地址 if(count($name_arr)>1) { $db_filename = $savePath . $name_arr[1]; //保存到腾讯云的地址 }else if(count($name_arr2)>1){ $db_filename = $savePath . $name_arr2[1]; //保存到腾讯云的地址 } $full_filename=$dir.$saveFileName; //保存到本地的全路径 //保存到存储云 vendor('qcloudcos.myqcloudcos'); $resfolder=Myqcloudcos::statFolder('wxd',$savePath); if ($resfolder && $resfolder['code']!=0)//不存在创建 { Myqcloudcos::createFolder('wxd',$savePath); } //上传到腾讯云 $res=Myqcloudcos::upload('wxd',$full_filename,$db_filename); if($res && $res['code']==0){ //mdelFile($full_filename); } $data['store_id']=getAdmStoId(); $data['video_name']=$video_name; $data['video_url']=$db_filename; $data['video_img']=$video_img; $data['group_id']=$group_id; $data['goods_id']=$goods_id; $data['add_time']=time(); $data['video_time']=$video_time; $rs= M("up_video")->save($data); if($rs) return json(['code'=>0,'msg'=>'保存成功','full'=>$full_filename]); return json(['code'=>-1,'msg'=>'保存失败']); } public function up_my_video(){ $is_ajax=I("is_ajax"); $qclurl=QCLOUD_IMGURL; $this->assign('qclurl',$qclurl); if($is_ajax){ $where="1=1"; $groupid=I("groupid"); $keywords=I("keywords"); $keywords=urldecode(urldecode($keywords)); if($groupid){ $where.=" and group_id=".$groupid; } if($keywords){ $where.=" and video_name like '%".$keywords."%'"; } $count =M("up_video")->where("store_id",getAdmStoId())->where($where)->count('id'); $Page = new AjaxPage($count,10); $show = $Page->show(); $start=$Page->firstRow; $page_size=$Page->listRows; $list=M("up_video")->where("store_id",getAdmStoId())->where($where) ->limit("$start,$page_size") ->select(); $this->assign("list",$list); $this->assign("page",$show); return $this->fetch('ajax_up_my_video', getAdmStoId()); } $gdata=M('up_video_group')->where('store_id',getAdmStoId()) ->select(); $this->assign('grpList',$gdata); return $this->fetch('', getAdmStoId()); } //--添加视频分组,编辑-- public function add_video_group(){ $name=I('name'); $stoid=getAdmStoId(); $rs=M('up_video_group')->where("gpname",$name) ->where('store_id',$stoid) ->find(); if($rs) return json(['code'=>-1,'msg'=>'已经有该分组名称了,请重新命名']); $data['store_id']=$stoid; $data['gpname']=$name; $data['add_time']=time(); $gid=I("gid"); if($gid){ $rss=M('up_video_group')->where('id',$gid)->save($data); }else{ $rss=M('up_video_group')->save($data); } if($rss) return json(['code'=>0,'msg'=>'添加成功']); return json(['code'=>-1,'msg'=>'添加失败']); } //删除存在本地的视频 public function del_local_video(){ $path = I("filename"); mdelFile($path); return 1; } //---编辑视频--- public function edit_up_video(){ $id=I("id"); $is_ajax=I("is_ajax"); if($is_ajax==1){ $video_name=I("video_name"); $group_id=I("group_id"); $video_img=I("video_img"); $video_time=I("video_time"); $db_filename=I("video_url"); $data['file_size']=I("file_size"); $file = request()->file('file'); //--如果是重新上传文件的话-- if($file) { $data['file_size'] = round($file->getSize() / 1024, 2); $savePath = '/public/upload/video/' . getAdmStoId() . '/' . date('Y') . '/' . date('m-d') . '/'; $dir = ROOT_PATH . $savePath; //创建目录失败 if (!file_exists($dir) && !mkdir($dir, 0777, true)) { $data = array( 'msg' => '目录创建失败', 'code' => '-1' ); return json($data); } else if (!is_writeable($dir)) { $data = array( 'msg' => '目录没有写权限', 'code' => '-1' ); return json($data); } $info = $file->move($dir); $saveFileName = $info->getSaveName(); mlog("save_video:" . $saveFileName, "upload_save_video/" . getAdmStoId()); $name_arr = explode('\\', $saveFileName); $name_arr2 = explode('/', $saveFileName); mlog("save_video1:" . json_encode($name_arr), "upload_save_video/" . getAdmStoId()); $db_filename = $savePath . $saveFileName; //保存到腾讯云的地址 if (count($name_arr) > 1) { $db_filename = $savePath . $name_arr[1]; //保存到腾讯云的地址 } else if (count($name_arr2) > 1) { $db_filename = $savePath . $name_arr2[1]; //保存到腾讯云的地址 } $full_filename = $dir . $saveFileName; //保存到本地的全路径 //保存到存储云 vendor('qcloudcos.myqcloudcos'); $resfolder = Myqcloudcos::statFolder('wxd', $savePath); if ($resfolder && $resfolder['code'] != 0)//不存在创建 { Myqcloudcos::createFolder('wxd', $savePath); } //上传到腾讯云 $res = Myqcloudcos::upload('wxd', $full_filename, $db_filename); if ($res && $res['code'] == 0) { //mdelFile($full_filename); } } $data['store_id']=getAdmStoId(); $data['video_name']=$video_name; $data['video_url']=$db_filename; $data['video_img']=$video_img; $data['group_id']=$group_id; $data['add_time']=time(); $data['video_time']=$video_time; $rs= M("up_video")->where("id",$id)->save($data); if($rs) return json(['code'=>0,'msg'=>'保存成功','full'=>$full_filename,'vd_url'=>$db_filename]); return json(['code'=>-1,'msg'=>'保存失败']); } $gdata=M('up_video_group')->where('store_id',getAdmStoId()) ->select(); $this->assign('grpList',$gdata); $info=M("up_video")->where('id',$id)->where('store_id',getAdmStoId())->find(); $this->assign("info",$info); return $this->fetch("",getAdmStoId()); } //---视频分组的修改--- public function ajax_video_group(){ $where="1=1"; $keywords=I("keywords"); $keywords=urldecode(urldecode($keywords)); if($keywords){ $where.=" and gpname like '%".$keywords."%'"; } $count =M("up_video_group")->where("store_id",getAdmStoId())->where($where)->count('id'); $Page = new AjaxPage($count,10); $show = $Page->show(); $start=$Page->firstRow; $page_size=$Page->listRows; $list=M("up_video_group")->where("store_id",getAdmStoId())->where($where) ->limit("$start,$page_size") ->select(); $this->assign("list",$list); $this->assign("page",$show); return $this->fetch('ajax_video_group', getAdmStoId()); } //--删除商品分组-- public function del_video_group(){ $id=I("gid"); M("up_video_group") ->where("id",$id) ->where("store_id",getAdmStoId())->delete(); M("up_video")->where('group_id',$id) ->where("store_id",getAdmStoId())->save(["group_id"=>0]); return json(['code'=>0,'msg'=>'成功']); } //--获取商品分组-- public function get_group(){ $gdata=M('up_video_group')->where('store_id',getAdmStoId()) ->select(); return json(['code'=>0,'msg'=>'成功','data'=>$gdata]); } }