where('store_id',getAdmStoId())->where('type',0)->find(); if($rs){ if($rs['end_time']redirect(U('Admin/template/not_template')); $this->assign('end_time',$rs['end_time']); }else{ $rs0=M('store_module')->where('type=0 and store_id=' . getAdmStoId())->find(); if($rs0){ $tt=C('m_end_time'); if($ttredirect(U('Admin/template/not_template')); else { $this->assign('end_time',C('m_end_time')); $this->assign('lyh', 1); } }else{ if($rs['end_time']redirect(U('Admin/template/not_template')); } } } } /***模板列表***/ public function templateList() { $pagenum = I('pagenum/d', 10); $key_word = I('key_word') ? trim(I('key_word')) : ''; // 关键词搜索 $cur_page = I('p/d', 0);//当前页数 $this->assign('key_word', $key_word); $this->assign('pagenum', $pagenum); $this->assign('cur_page', $cur_page); return $this->fetch('', getAdmStoId()); } public function ajaxtemplateList() { $key_word = I('key_word') ? trim(I('key_word')) : ''; // 关键词搜索 $cur_page = I('p/d', 0);//当前页数 if ($cur_page <= 0) { $cur_page = 1; } $pagenum = I('pagenum/d', 10); $where = " a.type=0 and a.store_id=" . getAdmStoId(); $this->assign('stoid', getAdmStoId()); if ($key_word) { $where .= " and (a.page_title like '%$key_word%' or c.page_title like '%$key_word%' or a.template_sn like '%$key_word%')"; } $model = M('store_module'); $count = $model->alias('a') ->join('storage_recharge b','a.id=b.module_id and a.store_id=b.store_id','left') ->join('store_module c','a.from_id=c.id','left') ->where($where)->count(); $Page = new AjaxPage($count, $pagenum); $show = $Page->show(); $List = $model->alias('a') ->join('store_renew_module b','a.from_id=b.module_id and a.store_id=b.store_id','left') ->join('store_module c','a.from_id=c.id','left') ->where($where) ->field('a.*,b.end_time,c.page_title as page_title_type') ->order("a.billdate desc") ->limit($Page->firstRow . ',' . $Page->listRows)->select(); $oldurl = U('admin/template/templatelist', array( "key_word" => $key_word, "pagenum" => $pagenum, "p" => $cur_page, )); $this->assign('oldurl', urlencode($oldurl)); $this->assign('key_word', $key_word); $this->assign('pagenum', $pagenum); $this->assign('cur_page', $cur_page); $this->assign('temList', $List); $this->assign('page', $show);// 赋值分页输出 $this->assign('pager', $Page); // upload_ylp_log('模块列表'); return $this->fetch("", getAdmStoId()); } /*--模板添加和修改页--*/ public function templatehandle() { /*--获取id--*/ $id = I('id'); $new = I("new"); $this->assign("new", $new); $this->initEditor(); $stoid = getAdmStoId(); /*-------模块读取-------*/ $rs = M("module")->order('sort')->where('is_use',1)->select(); //元素 {"content":citem,"ename":data.data.eng_name,"name":"","icon":"",type:"1"}; type:1表示自定义模块 foreach ($rs as $k => $v) { $str = file_get_contents(ROOT_PATH . $v['controljson']); $jdata = json_decode($str, true); $data[] = [ "content" => $jdata['content'], "ename" => $v['eng_name'], "name" => $v['name'], "icon" => getimg($v['module_icon'], NOIMG), "type" => 0 ]; } /*---------如果有自定义模块-------*/ $rrs = M('custommodule_list')->where('store_id', $stoid)->select(); if ($rrs) { $data[] = [ "content" => ['ename' => "", 'name' => ""], "ename" => "custom", "name" => "自定义", "icon" => "/public/static/images/model/custom_img.png", "type" => 1 ]; $this->assign("customlist", $rrs); } if (empty($data)) $data = -1; $this->assign("module", json_encode($data)); if (!empty($id)) { /*--模板读取--*/ $temdata = M("store_module")->where('id', $id)->find(); /*--3是空模板--*/ if ($temdata['type'] <> 3) { /*--要读取content--*/ if ($temdata['type'] == 0) $p = ROOT_PATH . "/public/template/feature/" . $stoid . '/' . $temdata['template_sn'] . ".json"; else $p = ROOT_PATH . "/public/template/feature/" . $temdata['template_sn'] . ".json"; if (file_exists($p)) { $str = file_get_contents($p); if ($temdata['type'] != 0 && $new == 1) { $str = str_replace('stoid/1.html', "stoid/" . $stoid . "html", $str); $str = str_replace('stoid\/1.html', "stoid\/" . $stoid . ".html", $str); $str = str_replace('stoid\/1\/', "stoid\/" . $stoid . "\/", $str); $str = str_replace('stoid/1/', "stoid/" . $stoid . "/", $str); } $jjdata = json_decode($str, true); if ($temdata['type'] != 0) { foreach ($jjdata as $kh => $vh) { $content = $vh['content']; if ($content['moudletype'] == 3 || $content['moudletype'] == 2 || $content['classstyle'] == 2) { $content['data'] = []; } $jjdata[$kh]['content'] = $content; } } } else { $this->assign("temdata", -1); $this->assign("config", -1); $this->assign("err", "未找到模板文件"); return $this->fetch(); } $this->assign("temdata", json_encode($jjdata)); /*--config--{"title":"","descr":"","istop":0,"isright":0,"money":0};*/ $data = [ "title" => $temdata['page_title'], "descr" => $temdata['page_describe'], "istop" => $temdata['istop'], "isright" => $temdata['isright'], "money" => $temdata['money'], "bkcolor" => $temdata['bkcolor'], ]; $this->assign("config", json_encode($data)); //商家要对from_id进行映射,如果是收费模板,要进行记录 if($temdata['type']==2 || $temdata['type']==1){ $this->assign("from_id",$id); }else if($temdata['type']==0){ $this->assign("from_id",$temdata['from_id']); } } else { $this->assign("temdata", -1); $this->assign("config", -1); } } else { $this->assign("temdata", -1); $this->assign("config", -1); } return $this->fetch("", getAdmStoId()); } /*-------模板的保存------------*/ public function temlatesave() { /*--清除缓存--*/ ClearALLCache(); delFile(TEMP_PATH . "/" . getAdmStoId()); $data = I("post."); $id = I('id'); $from_id = I('from_id/d',0); $stoid = getAdmStoId(); /*---创建模板存放目录---*/ if (!is_dir(ROOT_PATH . '/public/template/feature/' . $stoid . '/')) mkdir(ROOT_PATH . '/public/template/feature/' . $stoid . '/'); /*----页面基础配置----*/ $conf = $data[1]; /*----json文件保存----*/ $str = json_encode($data[0]); if (!empty($id)) { $r10 = $rs = M('store_module')->where('id', $id)->find(); } /*----------------新增,或者是空模板-----------------*/ if (empty($id) || $r10['type'] == 3) { $mr = get_total_millisecond(); $sn = date('YmdHis') . $mr . rand(1000, 9999); /*--json文件操作--*/ $filename = '/public/template/feature/' . $stoid . '/' . $sn . '.json'; if (file_exists(ROOT_PATH . $filename) && $filename) { mdelFile(ROOT_PATH . $filename); } file_put_contents(ROOT_PATH . $filename, $str); /*---调用风格表存储手机端显示文件---*/ $filename2 = '/public/template/feature/' . $stoid . '/' . $sn . '.html'; if (file_exists(ROOT_PATH . $filename2) && $filename2) { mdelFile(ROOT_PATH . $filename2); } /*---手机前端要显示保存的内容---*/ $htm = ""; foreach ($data[0] as $k => $v) { if ($v['type'] == 1) { $htmlfile = '/public/template/custom/' . getAdmStoId() . '/' . $v['content']['ename'] . '.html'; if (file_exists(ROOT_PATH . $htmlfile)) { $cstr = file_get_contents(ROOT_PATH . $htmlfile); $htm .= $cstr; } else { return json(['code' => -1, 'msg' => '未找自定义模板的文件']); } } else { /*--风格类型--*/ $type = $v['content']['style']; $r0 = M("module")->where('eng_name', $v['ename'])->find(); $r1 = M("module_list")->where('parent_id', $r0['id'])->where('type', $type)->find(); /*--获取手机前端要显示html--*/ $htmlfile = "/public/template/html/" . $r0['eng_name'] . "/mobliehtm" . $r1['class_eng_name'] . ".html"; if (file_exists(ROOT_PATH . $htmlfile)) { $cstr = file_get_contents(ROOT_PATH . $htmlfile); } else { return json(['code' => -1, 'msg' => '未找到手机端展示文件']); } /*--根据字段替换--*/ $fields = explode(",", $r1['fields']); foreach ($fields as $kk => $vv) { $val = $v['content'][$vv]; if ($vv == 'no') { $val = uniqid(); } if ($vv == 'scoll_length') { $val = $v['content']['length']; if (count($v['content']['data']) < $val) { $val = count($v['content']['data']); } } if (gettype($val) == 'boolean') { $val = (int)$val; } $val=$val==null?0:$val; $replacestr = "{{" . $vv . "}}"; $cstr = str_replace($replacestr, $val . "", $cstr); } /*--如果有循环体--*/ if (!empty($v['content']['data'])) { $rhtm = ""; $width = 100 / count($v['content']['data']); /*--截取循环里面的循环体--*/ $start1 = strpos($cstr, '', 0); if ($start1) { $end1 = strpos($cstr, '', 0); /* $str = "{{name}}"; */ $repeat = substr($cstr, $start1 + 9, $end1 - $start1 - 9); $cstr = str_replace('', "", $cstr); $cstr = str_replace('', "", $cstr); $cstr = str_replace($repeat, "{{the_repeat}}", $cstr); foreach ($v['content']['data'] as $kk => $vv) { $vv['width'] = $width; $rp = $repeat; foreach ($vv as $mk => $mv) { $replacestr = "{{" . $mk . "}}"; $rp = str_replace($replacestr, $mv . "", $rp); } $rhtm .= $rp; } $cstr = str_replace("{{the_repeat}}", $rhtm, $cstr); } else { /*--如果有按数组替换的--*/ if (strpos($cstr, '{{data[0]', 0)) { /*--根据字段替换--*/ foreach ($v['content']['data'] as $kk => $vv) { foreach ($vv as $km => $vm) { $replacestr = "{{data[" . $kk . "]." . $km . "}}"; $cstr = str_replace($replacestr, $vm . "", $cstr); } } } else { /*---如果是商品分组的手动选择商品---*/ if ( $v['content']['classstyle'] == 1 || $v['content']['moudletype'] == 2 || $v['content']['moudletype'] == 3 || $v['content']['moudletype'] == 4 ) { $idlist = ""; foreach ($v['content']['data'] as $kk => $vv) { $idlist .= $vv['goodsid'] . ","; } $idlist = substr($idlist, 0, strlen($idlist) - 1); $replacestr = "{{idlist}}"; $cstr = str_replace($replacestr, $idlist . "", $cstr); } } } } $htm .= $cstr; } } /*---写入文件---*/ file_put_contents(ROOT_PATH . $filename2, $htm); /*--存储数据--*/ $sdata = [ "type" => 0,//默认免费模板 "page_title" => $conf['title'], "page_describe" => $conf['descr'], "bkcolor" => $conf['bkcolor'], "istop" => $conf['istop'], "isright" => $conf['isright'], "money" => $conf['money'], "template_sn" => $sn, "billdate" => time(), "store_id" => getAdmStoId(), "from_id" => $from_id ]; $u = M('store_module')->save($sdata); if ($u){ upload_ylp_log('D01模板添加/确认提交'); return json(['code' => 1]); } else return json(['code' => -1, 'msg' => '保存失败']); } /*----------------编辑-----------------*/ else { $rs = M('store_module')->where('id', $id)->where('store_id', getAdmStoId())->find(); if (!$rs) { return json(['code' => -1, 'msg' => '未找到模板']); } $sn = $rs['template_sn']; /*--json文件操作--*/ $filename = '/public/template/feature/' . $stoid . '/' . $sn . '.json'; if (file_exists(ROOT_PATH . $filename) && $filename) { mdelFile(ROOT_PATH . $filename); } file_put_contents(ROOT_PATH . $filename, $str); /*---调用风格表存储手机端显示文件---*/ $filename2 = '/public/template/feature/' . $stoid . '/' . $sn . '.html'; if (file_exists(ROOT_PATH . $filename2) && $filename2) { mdelFile(ROOT_PATH . $filename2); } /*---手机前端要显示保存的内容---*/ $htm = ""; foreach ($data[0] as $k => $v) { if ($v['type'] == 1) { $htmlfile = '/public/template/custom/' . getAdmStoId() . '/' . $v['content']['ename'] . '.html'; if (file_exists(ROOT_PATH . $htmlfile)) { $cstr = file_get_contents(ROOT_PATH . $htmlfile); $htm .= $cstr; } else { return json(['code' => -1, 'msg' => '未找自定义模板的文件']); } } else { /*--风格类型--*/ $type = $v['content']['style']; $r0 = M("module")->where('eng_name', $v['ename'])->find(); $r1 = M("module_list")->where('parent_id', $r0['id'])->where('type', $type)->find(); /*--获取手机前端要显示html--*/ $htmlfile = "/public/template/html/" . $r0['eng_name'] . "/mobliehtm" . $r1['class_eng_name'] . ".html"; if (file_exists(ROOT_PATH . $htmlfile)) { $cstr = file_get_contents(ROOT_PATH . $htmlfile); } else { return json(['code' => -1, 'msg' => '未找到手机端展示文件']); } /*--根据字段替换--*/ $fields = explode(",", $r1['fields']); foreach ($fields as $kk => $vv) { $val = $v['content'][$vv]; if ($vv == 'no') { $val = uniqid(); } if ($vv == 'scoll_length') { $val = $v['content']['length']; if (count($v['content']['data']) < $val) { $val = count($v['content']['data']); } } if (gettype($val) == 'boolean') { $val = (int)$val; } $val=$val==null?0:$val; $replacestr = "{{" . $vv . "}}"; $cstr = str_replace($replacestr, $val . "", $cstr); } /*--如果有循环体--*/ if (!empty($v['content']['data'])) { $rhtm = ""; $width = 100 / count($v['content']['data']); /*--截取循环里面的循环体--*/ $start1 = strpos($cstr, '', 0); if ($start1) { $end1 = strpos($cstr, '', 0); /* $str = "{{name}}"; */ $repeat = substr($cstr, $start1 + 9, $end1 - $start1 - 9); $cstr = str_replace('', "", $cstr); $cstr = str_replace('', "", $cstr); $cstr = str_replace($repeat, "{{the_repeat}}", $cstr); foreach ($v['content']['data'] as $kk => $vv) { $vv['width'] = $width; $rp = $repeat; foreach ($vv as $mk => $mv) { $replacestr = "{{" . $mk . "}}"; $rp = str_replace($replacestr, $mv . "", $rp); } $rhtm .= $rp; } $cstr = str_replace("{{the_repeat}}", $rhtm, $cstr); } else { /*--如果有按数组替换的--*/ if (strpos($cstr, '{{data[0]', 0)) { /*--根据字段替换--*/ foreach ($v['content']['data'] as $kk => $vv) { foreach ($vv as $km => $vm) { $replacestr = "{{data[" . $kk . "]." . $km . "}}"; $cstr = str_replace($replacestr, $vm . "", $cstr); } } } else { /*---如果是商品分组的手动选择商品---*/ if ( $v['content']['classstyle'] == 1 || $v['content']['classstyle'] == 2 || $v['content']['classstyle'] == 3 || $v['content']['moudletype'] == 2 || $v['content']['moudletype'] == 3 || $v['content']['moudletype'] == 4 ) { $idlist = ""; foreach ($v['content']['data'] as $kk => $vv) { $idlist .= $vv['goodsid'] . ","; } $idlist = substr($idlist, 0, strlen($idlist) - 1); $replacestr = "{{idlist}}"; $cstr = str_replace($replacestr, $idlist . "", $cstr); } } } } $htm .= $cstr; } } /*---写入文件---*/ file_put_contents(ROOT_PATH . $filename2, $htm); $mid = session('admin_id'); $rr = M("admin")->where("admin_id", $mid)->find(); /*--存储数据--*/ $sdata = [ "type" => 0,//默认免费模板 "page_title" => $conf['title'], "page_describe" => $conf['descr'], "bkcolor" => $conf['bkcolor'], "istop" => $conf['istop'], "isright" => $conf['isright'], "money" => $conf['money'], "editdate" => time(), "editip" => getIP(), "editman" => $rr['ERPName'], "store_id" => getAdmStoId(), "from_id" => $from_id ]; $u = M('store_module')->where('id', $id)->save($sdata); if ($u){ // upload_ylp_log('模板新增'); return json(['code' => 1]); } else return json(['code' => -1]); } } //搜索选择模板 public function templatesearch() { $typelist=M('module_type')->order('ordid asc')->select(); $this->assign("typelist",$typelist); $p = I('p/d', 1); $type = I('type'); $type_id = I('type_id/d'); $kw = I('keywords'); $this->assign('keywords', $kw); $sto_id = getAdmStoId(); $where = " type<>0 and type<>4 "; if ($type) { $this->assign('type', $type); $where .=" and type=".$type; } if ($type_id) { $where .=" and type_id=".$type_id; } else { $type_id=0; } $this->assign('gettypeid', $type_id); if (!empty($kw)) { $where .= " and (page_title like '%" . $kw . "%' )"; } $count = M('store_module')->where($where)->count(); $Page = new Page($count, 10); $mList = M('store_module')->where($where)->order('type desc,billdate DESC') ->limit($Page->firstRow . ',' . $Page->listRows)->select(); /*--数组顶部插入--*/ $show = $Page->show();//分页显示输出 foreach ($mList as $k =>$v){ $check = M('store_renew_module')->where(['module_id'=>$v['id'],'store_id'=>$sto_id])->where('end_time>'.time().' or end_time=0')->field('id')->find(); if ($check) { $mList[$k]['money'] = 0; $mList[$k]['isshow'] = 1; } } $this->assign('page', $show);//赋值分页输出 $this->assign('mList', $mList); $this->assign('pager', $Page);//赋值分页输出 return $this->fetch("", $sto_id); } /*--模板拷贝--*/ public function copytemplate() { /*--清除缓存--*/ ClearALLCache(); delFile(TEMP_PATH . "/" . getAdmStoId()); $stoid = getAdmStoId(); $mr = get_total_millisecond(); $id = I("id"); $rs = M('store_module')->where('id', $id)->find(); $oldsn = $rs['template_sn']; $newsn = date('YmdHis') . $mr . rand(1000, 9999); /*--复制json--*/ $file = ROOT_PATH . '/public/template/feature/' . $stoid . '/' . $oldsn . '.json'; $newfile = ROOT_PATH . '/public/template/feature/' . $stoid . '/' . $newsn . '.json'; if (file_exists($file)) { $str = file_get_contents($file); file_put_contents($newfile, $str); } else { return json(['code' => -1, "msg" => '未找到原文件']); } /*--复制html--*/ $file = ROOT_PATH . '/public/template/feature/' . $stoid . '/' . $oldsn . '.html'; $newfile = ROOT_PATH . '/public/template/feature/' . $stoid . '/' . $newsn . '.html'; if (file_exists($file)) { $str = file_get_contents($file); file_put_contents($newfile, $str); } else { return json(['code' => -1, "msg" => '未找到原文件']); } $rs['template_sn'] = $newsn; $rs['billdate'] = time(); $rs['isdefault'] = 0; unset($rs['id']); unset($rs['editdate']); unset($rs['editip']); unset($rs['editman']); $u = M('store_module')->save($rs); if ($u) { // upload_ylp_log('模板复制'); return json(['code' => 1]); } else return json(['code' => -1, "msg" => '复制失败']); } /*--删除模板--*/ public function deltemplate() { /*--清除缓存--*/ ClearALLCache(); delFile(TEMP_PATH . "/" . getAdmStoId()); $stoid = getAdmStoId(); $id = I("id"); $r = M("store_module") ->where('id', $id)->where('store_id', $stoid)->find(); if (!$r) return json(['code' => -1]); $sn = $r['template_sn']; $file = ROOT_PATH . '/public/template/feature/' . $stoid . '/' . $sn . '.json'; $file2 = ROOT_PATH . '/public/template/feature/' . $stoid . '/' . $sn . '.html'; mdelFile($file); mdelFile($file2); $r = M("store_module")->where('id', $id)->delete(); if ($r) { // upload_ylp_log('模板删除'); return json(['code' => 1]); } else return json(['code' => -1]); } /*---模板设置为首页---*/ public function sethomepage() { /*--清除缓存--*/ ClearALLCache(); $this->delFile(TEMP_PATH . "/" . getAdmStoId()); $id = I('id'); $stoid = getAdmStoId(); /*--查找模板--*/ $r0 = M('store_module')->where(['id' => $id, 'type' => 0, 'store_id' => $stoid])->find(); if ($r0) { // upload_ylp_log('设置模板首页'); M('store_module')->where(['type' => 0, 'store_id' => $stoid])->save(['isdefault' => 0]); M('store_module')->where(['id' => $id, 'type' => 0, 'store_id' => $stoid])->save(['isdefault' => 1]); return json(['code' => 1]); } else { return json(['code' => -1, 'msg' => '未找到该模板']); } } /*--模板取消首页--*/ public function canclehomepage() { /*--清除缓存--*/ ClearALLCache(); $this->delFile(TEMP_PATH . "/" . getAdmStoId()); $id = I('id'); $stoid = getAdmStoId(); /*--查找模板--*/ $r0 = M('store_module')->where(['id' => $id, 'type' => 0, 'store_id' => $stoid])->find(); if ($r0) { // upload_ylp_log('模板首页取消'); M('store_module')->where(['id' => $id, 'type' => 0, 'store_id' => $stoid])->save(['isdefault' => 0]); return json(['code' => 1]); } else { return json(['code' => -1, 'msg' => '未找到该模板']); } } /*--自定义模块--*/ public function custommodule() { $pagenum = I('pagenum/d', 10); $key_word = I('key_word') ? trim(I('key_word')) : ''; // 关键词搜索 $cur_page = I('p/d', 0);//当前页数 $this->assign('key_word', $key_word); $this->assign('pagenum', $pagenum); $this->assign('cur_page', $cur_page); return $this->fetch("", getAdmStoId()); } /*--自定义模块--*/ public function ajaxcustommodule() { $pagenum = I('pagenum/d', 10); $key_word = I('key_word') ? trim(I('key_word')) : ''; // 关键词搜索 $cur_page = I('p/d', 0);//当前页数 $where = " store_id=" . getAdmStoId(); $this->assign('stoid', getAdmStoId()); if ($key_word) { $where .= " and (name like '%$key_word%' or eng_name like '%$key_word%')"; } $model = M('custommodule_list'); $count = $model->where($where)->count(); $Page = new AjaxPage($count, $pagenum); $show = $Page->show(); $List = $model->where($where)->order("billdate desc")->limit($Page->firstRow . ',' . $Page->listRows)->select(); $oldurl = U('admim/template/custommodule', array( "key_word" => $key_word, "pagenum" => $pagenum, "p" => $cur_page, )); $this->assign('oldurl', urlencode($oldurl)); $this->assign('key_word', $key_word); $this->assign('pagenum', $pagenum); $this->assign('cur_page', $cur_page); $this->assign('temList', $List); $this->assign('page', $show);// 赋值分页输出 $this->assign('pager', $Page); // upload_ylp_log('自定义模板'); return $this->fetch("", getAdmStoId()); } /*--自定义模块--*/ public function custommodulehandle() { $stoid = getAdmStoId(); /*-------模块读取-------*/ $rs = M("module")->order('sort')->where('is_use',1)->select(); //元素 {"content":citem,"ename":data.data.eng_name,"name":"","icon":}; foreach ($rs as $k => $v) { $str = file_get_contents(ROOT_PATH . $v['controljson']); $jdata = json_decode($str, true); $data[] = [ "content" => $jdata['content'], "ename" => $v['eng_name'], "name" => $v['name'], "icon" => getimg($v['module_icon'], NOIMG), "type" => 0 ]; } if (empty($data)) $data = -1; $this->assign("module", json_encode($data)); $id = I('id'); if (!empty($id)) { /*--模板读取--*/ $temdata = M("custommodule_list")->where('id', $id)->where('store_id', $stoid)->find(); /*--要读取content--*/ $p = ROOT_PATH . "/public/template/custom/" . $stoid . '/' . $temdata['eng_name'] . ".json"; if (file_exists($p)) { $str = file_get_contents($p); $jjdata = json_decode($str, true); } else { $this->assign("err", "未找到模板文件"); return $this->fetch(); } $this->assign("temdata", json_encode($jjdata)); /*--config--{"title":"","descr":"","istop":0,"isright":0,"money":0};*/ $data = [ "title" => $temdata['name'], ]; $this->assign("config", json_encode($data)); } else { $this->assign("temdata", -1); $this->assign("config", -1); } return $this->fetch("", getAdmStoId()); } /*--自定义模块保存--*/ function custommodulesave() { $data = I("post."); $id = I('id'); $stoid = getAdmStoId(); /*---创建模板存放目录---*/ if (!is_dir(ROOT_PATH . '/public/template/custom/' . $stoid . '/')) mkdir(ROOT_PATH . '/public/template/custom/' . $stoid . '/'); /*----页面基础配置----*/ $conf = $data[1]; /*----json文件保存----*/ $str = json_encode($data[0]); /*----------------新增,或者是空模板-----------------*/ if (empty($id)) { /*--模块名称不能重复--*/ $uy = M('custommodule_list')->where('name', $conf['title'])->where('store_id', $stoid)->find(); if ($uy) { return json(['code' => -1, 'msg' => '自定义模块名称不能重复']); } $mr = get_total_millisecond(); $sn = date('YmdHis') . $mr . rand(1000, 9999); /*--json文件操作--*/ $filename = '/public/template/custom/' . $stoid . '/' . $sn . '.json'; if (file_exists(ROOT_PATH . $filename) && $filename) { mdelFile(ROOT_PATH . $filename); } file_put_contents(ROOT_PATH . $filename, $str); /*---调用风格表存储手机端显示文件---*/ $filename2 = '/public/template/custom/' . $stoid . '/' . $sn . '.html'; if (file_exists(ROOT_PATH . $filename2) && $filename2) { mdelFile(ROOT_PATH . $filename2); } /*---手机前端要显示保存的内容---*/ $htm = ""; foreach ($data[0] as $k => $v) { /*--风格类型--*/ $type = $v['content']['style']; $r0 = M("module")->where('eng_name', $v['ename'])->find(); $r1 = M("module_list")->where('parent_id', $r0['id'])->where('type', $type)->find(); /*--获取手机前端要显示html--*/ $htmlfile = "/public/template/html/" . $r0['eng_name'] . "/mobliehtm" . $r1['class_eng_name'] . ".html"; if (file_exists(ROOT_PATH . $htmlfile)) { $cstr = file_get_contents(ROOT_PATH . $htmlfile); } else { return json(['code' => -1, 'msg' => '未找到手机端展示文件']); } /*--根据字段替换--*/ $fields = explode(",", $r1['fields']); foreach ($fields as $kk => $vv) { $val = $v['content'][$vv]; if ($vv == 'no') { $val = uniqid(); } if ($vv == 'scoll_length') { $val = $v['content']['length']; if (count($v['content']['data']) < $val) { $val = count($v['content']['data']); } } if (gettype($val) == 'boolean') { $val = (int)$val; } $replacestr = "{{" . $vv . "}}"; $cstr = str_replace($replacestr, $val . "", $cstr); } /*--如果有循环体--*/ if (!empty($v['content']['data'])) { $rhtm = ""; $width = 100 / count($v['content']['data']); /*--截取循环里面的循环体--*/ $start1 = strpos($cstr, '', 0); if ($start1) { $end1 = strpos($cstr, '', 0); /* $str = "{{name}}"; */ $repeat = substr($cstr, $start1 + 9, $end1 - $start1 - 9); $cstr = str_replace('', "", $cstr); $cstr = str_replace('', "", $cstr); $cstr = str_replace($repeat, "{{the_repeat}}", $cstr); foreach ($v['content']['data'] as $kk => $vv) { $vv['width'] = $width; $rp = $repeat; foreach ($vv as $mk => $mv) { $replacestr = "{{" . $mk . "}}"; $rp = str_replace($replacestr, $mv . "", $rp); } $rhtm .= $rp; } $cstr = str_replace("{{the_repeat}}", $rhtm, $cstr); } else { /*--如果有按数组替换的--*/ if (strpos($cstr, '{{data[0]', 0)) { /*--根据字段替换--*/ foreach ($v['content']['data'] as $kk => $vv) { foreach ($vv as $km => $vm) { $replacestr = "{{data[" . $kk . "]." . $km . "}}"; $cstr = str_replace($replacestr, $vm . "", $cstr); } } } else { /*---如果是商品分组的手动选择商品---*/ if ( $v['content']['classstyle'] == 1 || $v['content']['moudletype'] == 2 || $v['content']['moudletype'] == 3 || $v['content']['moudletype'] == 4 ) { $idlist = ""; foreach ($v['content']['data'] as $kk => $vv) { $idlist .= $vv['goodsid'] . ","; } $idlist = substr($idlist, 0, strlen($idlist) - 1); $replacestr = "{{idlist}}"; $cstr = str_replace($replacestr, $idlist . "", $cstr); } } } } $htm .= $cstr; } /*---写入文件---*/ file_put_contents(ROOT_PATH . $filename2, $htm); /*--存储数据--*/ $sdata = [ "name" => $conf['title'], "eng_name" => $sn, "billdate" => time(), "store_id" => $stoid ]; $u = M('custommodule_list')->save($sdata); if ($u){ upload_ylp_log('D02自定义模块添加/确认提交'); return json(['code' => 1]); } else return json(['code' => -1, 'msg' => '保存失败']); } /*----------------编辑-----------------*/ else { /*--模块名称不能重复--*/ $uy = M('custommodule_list')->where('id', 'neq', $id) ->where('name', $conf['title'])->where('store_id', $stoid)->find(); if ($uy) { return json(['code' => -1, 'msg' => '自定义模块名称不能重复']); } $rs = M('custommodule_list')->where('id', $id)->where('store_id', $stoid)->find(); if (!$rs) { return json(['code' => -1, 'msg' => '未找到自定义模块']); } $sn = $rs['eng_name']; /*--json文件操作--*/ $filename = '/public/template/custom/' . $stoid . '/' . $sn . '.json'; if (file_exists(ROOT_PATH . $filename) && $filename) { mdelFile(ROOT_PATH . $filename); } file_put_contents(ROOT_PATH . $filename, $str); /*---调用风格表存储手机端显示文件---*/ $filename2 = '/public/template/custom/' . $stoid . '/' . $sn . '.html'; if (file_exists(ROOT_PATH . $filename2) && $filename2) { mdelFile(ROOT_PATH . $filename2); } /*---手机前端要显示保存的内容---*/ $htm = ""; foreach ($data[0] as $k => $v) { /*--风格类型--*/ $type = $v['content']['style']; $r0 = M("module")->where('eng_name', $v['ename'])->find(); $r1 = M("module_list")->where('parent_id', $r0['id'])->where('type', $type)->find(); /*--获取手机前端要显示html--*/ $htmlfile = "/public/template/html/" . $r0['eng_name'] . "/mobliehtm" . $r1['class_eng_name'] . ".html"; if (file_exists(ROOT_PATH . $htmlfile)) { $cstr = file_get_contents(ROOT_PATH . $htmlfile); } else { return json(['code' => -1, 'msg' => '未找到手机端展示文件']); } /*--根据字段替换--*/ $fields = explode(",", $r1['fields']); foreach ($fields as $kk => $vv) { $val = $v['content'][$vv]; if ($vv == 'no') { $val = uniqid(); } if ($vv == 'scoll_length') { $val = $v['content']['length']; if (count($v['content']['data']) < $val) { $val = count($v['content']['data']); } } if (gettype($val) == 'boolean') { $val = (int)$val; } $replacestr = "{{" . $vv . "}}"; $cstr = str_replace($replacestr, $val . "", $cstr); } /*--如果有循环体--*/ if (!empty($v['content']['data'])) { $rhtm = ""; $width = 100 / count($v['content']['data']); /*--截取循环里面的循环体--*/ $start1 = strpos($cstr, '', 0); if ($start1) { $end1 = strpos($cstr, '', 0); /* $str = "{{name}}"; */ $repeat = substr($cstr, $start1 + 9, $end1 - $start1 - 9); $cstr = str_replace('', "", $cstr); $cstr = str_replace('', "", $cstr); $cstr = str_replace($repeat, "{{the_repeat}}", $cstr); foreach ($v['content']['data'] as $kk => $vv) { $vv['width'] = $width; $rp = $repeat; foreach ($vv as $mk => $mv) { $replacestr = "{{" . $mk . "}}"; $rp = str_replace($replacestr, $mv . "", $rp); } $rhtm .= $rp; } $cstr = str_replace("{{the_repeat}}", $rhtm, $cstr); } else { /*--如果有按数组替换的--*/ if (strpos($cstr, '{{data[0]', 0)) { /*--根据字段替换--*/ foreach ($v['content']['data'] as $kk => $vv) { foreach ($vv as $km => $vm) { $replacestr = "{{data[" . $kk . "]." . $km . "}}"; $cstr = str_replace($replacestr, $vm . "", $cstr); } } } else { /*---如果是商品分组的手动选择商品---*/ if ( $v['content']['classstyle'] == 1 || $v['content']['moudletype'] == 2 || $v['content']['moudletype'] == 3 || $v['content']['moudletype'] == 4 ) { $idlist = ""; foreach ($v['content']['data'] as $kk => $vv) { $idlist .= $vv['goodsid'] . ","; } $idlist = substr($idlist, 0, strlen($idlist) - 1); $replacestr = "{{idlist}}"; $cstr = str_replace($replacestr, $idlist . "", $cstr); } } } } $htm .= $cstr; } /*---写入文件---*/ file_put_contents(ROOT_PATH . $filename2, $htm); $mid = session('admin_id'); $rr = M("admin")->where("admin_id", $mid)->find(); /*--存储数据--*/ $sdata = [ "name" => $conf['title'], "eng_name" => $sn, "editdate" => time(), "editip" => getIP(), "editman" => $rr['ERPName'], "store_id" => $stoid ]; $u = M('custommodule_list')->where('id', $id)->where('store_id', $stoid)->save($sdata); if ($u){ // upload_ylp_log('自定义模块编辑'); return json(['code' => 1]); } else return json(['code' => -1]); } } /*--删除自定义模块--*/ public function delcustommodule() { /*--清除缓存--*/ ClearALLCache(); delFile(TEMP_PATH . "/" . getAdmStoId()); $stoid = getAdmStoId(); $id = I("id"); $r = M("custommodule_list")->where('id', $id)->where('store_id', $stoid)->find(); if (!$r) return json(['code' => -1, 'msg' => '未找到自定义模块']); /*--判断模板能否删除--*/ $rs = M("store_module")->where('type', 0)->where('store_id', $stoid)->select(); foreach ($rs as $kl => $vl) { $p = ROOT_PATH . "/public/template/feature/" . $stoid . '/' . $vl['template_sn'] . ".json"; if (file_exists($p)) { $str = file_get_contents($p); $jjdata = json_decode($str, true); foreach ($jjdata as $k => $v) { if ($r['eng_name'] == $v['content']['ename']) { return json(['code' => -1, "msg" => '有模板使用了该模块,不能删除']); } } } } $sn = $r['eng_name']; $file = ROOT_PATH . '/public/template/custom/' . $stoid . '/' . $sn . '.json'; $file2 = ROOT_PATH . '/public/template/custom/' . $stoid . '/' . $sn . '.html'; mdelFile($file); mdelFile($file2); $r = M("custommodule_list")->where('id', $id)->delete(); if ($r) { // upload_ylp_log('自定义模块删除'); return json(['code' => 1]); } else return json(['code' => -1]); } /*--店铺导航--*/ public function shopnav() { $stoid = getAdmStoId(); $rs = M("store_footer")->where('store_id', $stoid)->order('type asc')->select(); $htmlfile = "/public/template/footer/footer.json"; /*--如果不存在默认导航,则添加默认导航--*/ if (empty($rs)) { if (file_exists(ROOT_PATH . $htmlfile)) { $cstr = file_get_contents(ROOT_PATH . $htmlfile); /*--替换总后台的stoid--*/ $cstr = str_replace('stoid/1.html', "stoid/" . $stoid . "html", $cstr); $cstr = str_replace('stoid\/1.html', "stoid\/" . $stoid . ".html", $cstr); $cstr = str_replace('stoid\/1\/', "stoid\/" . $stoid . "\/", $cstr); $cstr = str_replace('stoid/1/', "stoid/" . $stoid . "/", $cstr); } else { $this->assign("navdata", "-1"); $this->assign("err", '未找到手机端展示文件'); return $this->fetch("", $stoid); } $data = json_decode($cstr, true); $data['store_id'] = $stoid; $data['type'] = 0; $rs[] = $data; $data['data'] = json_encode($data['data']); $aa = M("store_footer")->save($data); $rs[0]['id'] = M("store_footer")->getLastInsID(); } else { foreach ($rs as $k => $v) { $str0=$v['data']; /*--替换总后台的stoid--*/ $str0 = str_replace('stoid/1.html', "stoid/" . $stoid . "html", $str0); $str0 = str_replace('stoid\/1.html', "stoid\/" . $stoid . ".html", $str0); $str0 = str_replace('stoid\/1\/', "stoid\/" . $stoid . "\/", $str0); $str0 = str_replace('stoid/1/', "stoid/" . $stoid . "/", $str0); $str = htmlspecialchars_decode($str0); $dd = json_decode($str, true); $rs[$k]['data'] = $dd; } } // upload_ylp_log('店铺导航'); $this->assign("navdata", json_encode($rs)); return $this->fetch("", $stoid); } /*--添加导航--*/ public function shopnav_add() { $jdata = [['src' => '', 'src_sele' => '', 'nav_name' => '新菜单', 'url' => '', 'urltitle' => '请选择'], ['src' => '', 'src_sele' => '', 'nav_name' => '新菜单', 'url' => '', 'urltitle' => '请选择'], ['src' => '', 'src_sele' => '', 'nav_name' => '新菜单', 'url' => '', 'urltitle' => '请选择'], ]; $stoid = getAdmStoId(); $ele = array('bkcolor' => '#fff', 'fontcolor' => '#eee', 'store_id' => $stoid, "type" => 1, 'fontcolor_sele' => '#f00', 'name' => "新增方案", "is_use" => 0, 'billdate' => time(), 'data' => json_encode($jdata) ); $rs = M("store_footer")->save($ele); if ($rs) { upload_ylp_log('D03店铺导航添加/确认提交'); unset($ele['billdate']); $ele['data'] = $jdata; $id = M("store_footer")->getLastInsID(); $ele['id'] = $id; return json(['code' => 1, 'id' => $id, 'data' => $ele]); } else return json(['code' => -1]); } /*--删除导航--*/ public function shopnav_del() { /*--清理缓存--*/ Cache::rm("shopfooter" . getAdmStoId()); delFile(TEMP_PATH . "/" . getAdmStoId()); $stoid = getAdmStoId(); $id = I('id'); $rs = M("store_footer")->where('store_id', $stoid)->where('id', $id)->delete(); if ($rs) { // upload_ylp_log('导航删除'); $file = '/public/template/footer/' . getAdmStoId() . '/' . $id . '.html'; if (file_exists(ROOT . $file)) { mdelFile(ROOT . $file); } return json(['code' => 1]); } else { return json(['code' => -1]); } } /*---导航启用---*/ public function shopnav_open() { $stoid = getAdmStoId(); $id = I('id/d'); /*--清理缓存--*/ Cache::rm("shopfooter" . $stoid); $this->delFile(TEMP_PATH . "/" . getAdmStoId()); if (!is_dir(ROOT_PATH . '/public/template/footer/' . $stoid . '/')) mkdir(ROOT_PATH . '/public/template/footer/' . $stoid . '/'); $data = I("post.")['data']; $file = '/public/template/footer/' . getAdmStoId() . '/' . $id . '.html'; if (file_exists(ROOT . $file)) { mdelFile(ROOT . $file); } /*--获取手机前端要显示html--*/ $htmlfile = "/public/template/footer/footer.html"; if (file_exists(ROOT_PATH . $htmlfile)) { $cstr = file_get_contents(ROOT_PATH . $htmlfile); } else { return json(['code' => -1, 'msg' => '未找到手机端展示文件']); } $htm = ""; /*--根据字段替换--*/ foreach ($data as $kk => $vv) { if ($kk == "data") continue; if ($vv == 'no') { $val = uniqid(); } $replacestr = "{{" . $kk . "}}"; $cstr = str_replace($replacestr, $vv . "", $cstr); } /*--如果有循环体--*/ if (!empty($data['data'])) { $rhtm = ""; $width = 100 / count($data['data']); $cstr = str_replace('{{width}}', $width . "", $cstr); /*--截取循环里面的循环体--*/ $start1 = strpos($cstr, '', 0); /*--如果有进行循环--*/ if ($start1) { $end1 = strpos($cstr, '', 0); /* $str = "{{name}}"; */ $repeat = substr($cstr, $start1 + 9, $end1 - $start1 - 9); $cstr = str_replace('', "", $cstr); $cstr = str_replace('', "", $cstr); $cstr = str_replace($repeat, "{{the_repeat}}", $cstr); foreach ($data['data'] as $kk => $vv) { $ind = $kk + 1; $rp = $repeat; $rp = str_replace("{{index}}", $ind . "", $rp); foreach ($vv as $mk => $mv) { $replacestr = "{{" . $mk . "}}"; $rp = str_replace($replacestr, $mv . "", $rp); } $rhtm .= $rp; } $cstr = str_replace("{{the_repeat}}", $rhtm, $cstr); } $htm .= $cstr; } /*---写入文件---*/ file_put_contents(ROOT_PATH . $file, $htm); M('store_footer')->where('store_id', $stoid)->save(['is_use' => 0]); M('store_footer')->where('store_id', $stoid)->where('id', $id)->save(['is_use' => 1]); // upload_ylp_log('导航启用'); return json(['code' => 1]); } /*---导航启用---*/ public function shopnav_close() { $stoid = getAdmStoId(); $id = I('id/d'); /*--清理缓存--*/ Cache::rm("shopfooter_" . $stoid); $this->delFile(TEMP_PATH . "/" . getAdmStoId()); M('store_footer')->where('store_id', $stoid)->where('id', $id)->save(['is_use' => 0]); // upload_ylp_log('导航取消启用'); return json(['code' => 1]); } /*---导航保存---*/ public function nav_save() { /*--清理缓存--*/ $stoid = getAdmStoId(); Cache::rm("shopfooter_" . $stoid); delFile(TEMP_PATH . "/" . $stoid); $data = I("post."); $isok = 1; $ars = M("admin")->where('admin_id', getAdminId())->find(); if (!is_dir(ROOT_PATH . '/public/template/footer/' . $stoid . '/')) mkdir(ROOT_PATH . '/public/template/footer/' . $stoid . '/'); foreach ($data as $k => $v) { $id = $v['id']; $sdata = null; foreach ($v as $kk => $vv) { if ($kk == 'data') { $vv = json_encode($vv); } if ($kk != 'id' || $kk != 'billdate') { $sdata[$kk] = $vv; } } $sdata['editdate'] = time(); $sdata['editip'] = getIP(); $sdata['editman'] = $ars['ERPUser']; $aa = M("store_footer")->where('id', $id)->save($sdata); if (!$aa) { $isok = 0;break; } $file = '/public/template/footer/' . getAdmStoId() . '/' . $id . '.html'; if (file_exists(ROOT . $file)) { mdelFile(ROOT . $file); } /*--获取手机前端要显示html--*/ $htmlfile = "/public/template/footer/footer.html"; if (file_exists(ROOT_PATH . $htmlfile)) { $cstr = file_get_contents(ROOT_PATH . $htmlfile); } else { return json(['code' => -1, 'msg' => '未找到手机端展示文件']); } $data1 = $v; $htm = ""; /*--根据字段替换--*/ foreach ($data1 as $kk => $vv) { if ($kk == "data") continue; if ($vv == 'no') { $val = uniqid(); } $replacestr = "{{" . $kk . "}}"; $cstr = str_replace($replacestr, $vv . "", $cstr); } /*--如果有循环体--*/ if (!empty($data1['data'])) { $rhtm = ""; $width = 100 / count($data1['data']); $cstr = str_replace('{{width}}', $width . "", $cstr); /*--截取循环里面的循环体--*/ $start1 = strpos($cstr, '', 0); /*--如果有进行循环--*/ if ($start1) { $end1 = strpos($cstr, '', 0); /* $str = "{{name}}"; */ $repeat = substr($cstr, $start1 + 9, $end1 - $start1 - 9); $cstr = str_replace('', "", $cstr); $cstr = str_replace('', "", $cstr); $cstr = str_replace($repeat, "{{the_repeat}}", $cstr); foreach ($data1['data'] as $kk => $vv) { $ind = $kk + 1; $rp = $repeat; $rp = str_replace("{{index}}", $ind . "", $rp); foreach ($vv as $mk => $mv) { $replacestr = "{{" . $mk . "}}"; $rp = str_replace($replacestr, $mv . "", $rp); } $rhtm .= $rp; } $cstr = str_replace("{{the_repeat}}", $rhtm, $cstr); } $htm .= $cstr; } /*---写入文件---*/ file_put_contents(ROOT_PATH . $file, $htm); } if ($isok) { // upload_ylp_log('导航保存'); return json(['code' => 1]); } else { return json(['code' => -1]); } } //选择商品20170508 public function search_goods() { //小程序搜索 $miniapp=I("miniapp"); $this->assign("miniapp",$miniapp); $GoodsLogic = new GoodsLogic(); $brandList = $GoodsLogic->getSortBrands(); $categoryList = $GoodsLogic->getSortCategory(); $this->assign('categoryList', $categoryList); $this->assign('brandList', $brandList); $pagenum=10; $where = ' 1 = 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'); // 关键词搜索 $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=" . getAdmStoId(); if ($cat_id > 0) { $grandson_ids = getCatGrandson($cat_id); $where .= " and cat_id in(" . implode(',', $grandson_ids) . ") "; // 初始化搜索条件 } $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=" . getAdmStoId())->select(); $catList = convert_arr_key($catList, 'id'); $this->assign('catList', $catList); $this->assign('goodsList', $goodsList); $this->assign('pager', $pager); $this->assign('pagenum', $pagenum); $this->assign('page', $show);// 赋值分页输出 // upload_ylp_log('搜索商品'); return $this->fetch('', getAdmStoId()); } //选择商品分组 public function search_goods_group() { $goods_group = M('goods_group'); $pagenum=10; $list = array(); $p = input('p/d', 1); $size = input('size/d', $pagenum); $where = array(); /*--添加门店ID--*/ $where["store_id"] = getAdmStoId(); $keywords = trim(I('keywords')); $keywords && $where['gpname'] = array('like', '%' . $keywords . '%'); $where['status'] = 1; $list = $goods_group->where($where)->order('gp_ordid asc,add_time asc')->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('pagenum', $pagenum); // upload_ylp_log('搜索商品分组'); return $this->fetch('', getAdmStoId()); } //选择商品品牌 public function search_goods_brand() { $goods_group = M('brand'); $pagenum=10; $list = array(); $p = input('p/d', 1); $size = input('size/d', $pagenum); $where = array(); /*--添加门店ID--*/ $where["store_id"] = getAdmStoId(); $keywords = trim(I('keywords')); $keywords && $where['name'] = array('like', '%' . $keywords . '%'); $list = $goods_group->where($where)->order('sort asc')->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('pagenum', $pagenum); // upload_ylp_log('搜索商品分组'); return $this->fetch('', getAdmStoId()); } //选择商品国别 public function search_goods_nation() { $goods_group = M('nation'); $pagenum=10; $list = array(); $p = input('p/d', 1); $size = input('size/d', $pagenum); $where = array(); /*--添加门店ID--*/ $where["store_id"] = getAdmStoId(); $keywords = trim(I('keywords')); $keywords && $where['name'] = array('like', '%' . $keywords . '%'); $list = $goods_group->where($where)->order('sort asc')->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('pagenum', $pagenum); // upload_ylp_log('搜索商品分组'); return $this->fetch('', getAdmStoId()); } //选择商品分类 public function search_goods_type() { $goods_group = M('goods_category'); $pagenum=20; $list = array(); $p = input('p/d', 1); $size = input('size/d', $pagenum); $parent_id = I('parent_id/d',0); $s_parent_id="0"; if ($parent_id) { $s_res=$goods_group->where('id',$parent_id)->find(); if ($s_res) { $s_parent_id=$s_res['parent_id']; } } $where = array(); /*--添加门店ID--*/ $where["store_id"] = getAdmStoId(); $where["parent_id"] = $parent_id; $keywords = trim(I('keywords')); $keywords && $where['mobile_name'] = array('like', '%' . $keywords . '%'); $list = $goods_group->where($where)->order('sort_order asc')->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('s_parent_id', $s_parent_id); $this->assign('parent_id', $parent_id); $this->assign('pager', $pager); $this->assign('pagenum', $pagenum); // upload_ylp_log('搜索商品分组'); return $this->fetch('', getAdmStoId()); } /** * 初始化编辑器链接 * 本编辑器参考 地址 http://fex.baidu.com/ueditor/ */ private function initEditor() { $this->assign("URL_upload", U('admin/Ueditor/imageUp', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 图片上传目录 $this->assign("URL_imageUp", U('admin/Ueditor/imageUp', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 不知道啥图片 $this->assign("URL_fileUp", U('admin/Ueditor/fileUp', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 文件上传s $this->assign("URL_scrawlUp", U('admin/Ueditor/scrawlUp', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 图片流 $this->assign("URL_getRemoteImage", U('admin/Ueditor/getRemoteImage', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 远程图片管理 $this->assign("URL_imageManager", U('admin/Ueditor/imageManager', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 图片管理 $this->assign("URL_getMovie", U('admin/Ueditor/getMovie', array('savepath' => 'goods', 'savepath1' => getERPId()))); // 视频上传 $this->assign("URL_Home", ""); } //获取续费的信息 public function getxufeimoney(){ $id=I("id"); $rs=M('store_module')->alias('a')->join('store_module b','a.from_id=b.id','left') ->field('a.from_id,b.money,b.days')->where('a.id',$id)->find(); if($rs){ return json(['code'=>1,'id'=>$rs['from_id'],'money'=>$rs['money'],'days'=>$rs['days']]); }else{ return json(['code'=>0]); } } //获取空模板 public function not_template(){ //先判断缴费记录是否有该商家的记录 $rss=M('store_module_endtime')->where('store_id='.getAdmStoId())->where('type',0)->find(); if($rss){ $this->assign('is_module_open', 1); }else { $rs = M('store_module')->where('type=0 and store_id=' . getAdmStoId())->find(); if ($rs) { $this->assign('is_module_open', 1); $this->assign('is_module_uu', 1); } else { $this->assign('is_module_open', 0); } } //先判断缴费记录是否有该商家的记录 $rss=M('store_module_endtime')->where('store_id='.getAdmStoId())->where('is_sy',0) ->where('type',0)->find(); if($rss){ $end_time=strtotime('+1 year',$rss['end_time']); $end_time=date("Y-m-d H:i:s",$end_time); $this->assign('end_time', $end_time); }else{ $end_time=strtotime('+1 year',time()); $end_time=date("Y-m-d H:i:s",$end_time); $this->assign('end_time', $end_time); } return $this->fetch('', getAdmStoId()); } //老用户提示界面 public function lyh_template(){ //先判断缴费记录是否有该商家的记录 $this->assign('is_module_open', 1); $this->assign('is_module_uu', 1); $stoid=getAdmStoId(); $w['is_sy'] = 1; $w['type'] = 0; $w['store_id'] = $stoid; $rh=M("store_module_endtime")->where($w)->find(); if(empty($rh)){ //先判断缴费记录是否有该商家的记录 $end_time = 1525104000; $data0['store_id'] = $stoid; $data0['beg_time'] = time(); $data0['end_time'] = $end_time; $data0['is_sy'] = 1; $data0['type'] = 0; $rh = M("store_module_endtime")->save($data0); }else{ $end_time = 1525104000; $data0['end_time'] = $end_time; M("store_module_endtime")->where('id',$rh['id'])->save($data0); } //先判断缴费记录是否有该商家的记录 $rss=M('store_module_endtime')->where('store_id='.$stoid)->where('is_sy',0) ->where('type',0)->find(); if($rss){ $end_time=strtotime('+1 year',$rss['end_time']); $end_time=date("Y-m-d H:i:s",$end_time); $this->assign('end_time', $end_time); }else{ $end_time=strtotime('+1 year',time()); $end_time=date("Y-m-d H:i:s",$end_time); $this->assign('end_time', $end_time); } return $this->fetch('', $stoid); } public function recharge_query(){ $back_no=I('bankOrderNo'); $rs=M("storage_recharge")->where('bankOrderNo',$back_no)->find(); if($rs){ if($rs['recharge_state']==1){ return json(['code'=>0,'data'=>['status'=>100]]); }else{ return json(['code'=>-1]); } }else{ return json(['code'=>-1]); } } //---恢复商品图片---- public function renew_img(){ $id=I("id"); $stoid=getAdmStoId(); $temdata = M("store_module")->where('id', $id)->find(); if($temdata){ if ($temdata['type'] <> 3) { /*--要读取content--*/ if ($temdata['type'] == 0) $p = ROOT_PATH . "/public/template/feature/" . $stoid . '/' . $temdata['template_sn'] . ".json"; else $p = ROOT_PATH . "/public/template/feature/" . $temdata['template_sn'] . ".json"; if (file_exists($p)) { $str = file_get_contents($p); $jjdata = json_decode($str, true); foreach ($jjdata as $kh => $vh) { $content = $vh['content']; //---如果存在data和商品---- if($content['data']){ foreach ($content['data'] as $km => $vm){ if($vm['goodsid']){ $rs=M("goods") ->where("goods_id",$vm['goodsid']) ->where('store_id',$stoid) ->field('original_img') ->find(); $content['data'][$km]['goodsimg']=QCLOUD_IMGURL.'/'.$rs['original_img']; } } } $jjdata[$kh]['content'] = $content; } /*---写入文件---*/ file_put_contents($p, json_encode($jjdata)); return json(['code'=>0,'msg'=>"修复成功",'data'=>$jjdata]); } else { return json(['code'=>-1,'msg'=>"未找到模板"]); } }else{ return json(['code'=>-1,'msg'=>"未找到模板"]); } }else{ return json(['code'=>-1,'msg'=>"未找到模板"]); } } public function renew_cus_img(){ $id=I("id"); $stoid=getAdmStoId(); $temdata = M("store_module")->where('id', $id)->find(); /*--模板读取--*/ $temdata = M("custommodule_list")->where('id', $id)->where('store_id', $stoid)->find(); /*--要读取content--*/ $p = ROOT_PATH . "/public/template/custom/" . $stoid . '/' . $temdata['eng_name'] . ".json"; if($temdata){ if (file_exists($p)) { $str = file_get_contents($p); $jjdata = json_decode($str, true); foreach ($jjdata as $kh => $vh) { $content = $vh['content']; //---如果存在data和商品---- if($content['data']){ foreach ($content['data'] as $km => $vm){ if($vm['goodsid']){ $rs=M("goods") ->where("goods_id",$vm['goodsid']) ->where('store_id',$stoid) ->field('original_img') ->find(); $content['data'][$km]['goodsimg']=QCLOUD_IMGURL.'/'.$rs['original_img']; } } } $jjdata[$kh]['content'] = $content; } /*---写入文件---*/ file_put_contents($p, json_encode($jjdata)); return json(['code'=>0,'msg'=>"修复成功",'data'=>$jjdata]); } else { return json(['code'=>-1,'msg'=>"未找到模板"]); } }else{ return json(['code'=>-1,'msg'=>"未找到模板"]); } } // 递归删除文件夹 function delFile($dir,$file_type='') { try{ if($dir==ROOT_PATH || $dir=="" || $dir==".sync" ) return; if(is_dir($dir)){ $files = scandir($dir); //打开目录 //列出目录中的所有文件并去掉 . 和 .. foreach($files as $filename){ if($filename!='.' && $filename!='..'){ if(!is_dir($dir.'/'.$filename)){ if(empty($file_type)){ unlink($dir.'/'.$filename); }else{ if(is_array($file_type)){ //正则匹配指定文件 if(preg_match($file_type[0],$filename)){ unlink($dir.'/'.$filename); } }else{ //指定包含某些字符串的文件 if(false!=stristr($filename,$file_type)){ unlink($dir.'/'.$filename); } } } }else{ delFile($dir.'/'.$filename); rmdir($dir.'/'.$filename); } } } }else{ if(file_exists($dir)) unlink($dir); } }catch (Exception $e){ mlog($e->getMessage(),"delFile"); } } }