store_setting.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <?php
  2. /**
  3. * 会员中心——我是卖家
  4. *
  5. *
  6. *
  7. **by 好商城V3 www.33hao.com 运营版*/
  8. defined('InShopNC') or exit('Access Invalid!');
  9. class store_settingControl extends BaseSellerControl {
  10. public function __construct() {
  11. parent::__construct();
  12. Language::read('member_store_index');
  13. }
  14. /**
  15. * 卖家店铺设置
  16. *
  17. * @param string
  18. * @param string
  19. * @return
  20. */
  21. public function store_settingOp(){
  22. /**
  23. * 实例化模型
  24. */
  25. $model_class = Model('store');
  26. /**
  27. * 获取设置
  28. */
  29. // $setting_config = $GLOBALS['setting_config'];
  30. $config_subdomain_edit = C('subdomain_edit');
  31. $config_subdomain_times = C('subdomain_times');
  32. $config_subdomain_length = C('subdomain_length');
  33. $config_subdomain_reserved = C('subdomain_reserved');
  34. $config_enabled_subdomain = C('enabled_subdomain');
  35. $store_id = $_SESSION['store_id'];//当前店铺ID
  36. /**
  37. * 获取店铺信息
  38. */
  39. $store_info = $model_class->getStoreInfoByID($store_id);
  40. $subdomain_edit = intval($config_subdomain_edit);//二级域名是否可修改
  41. $subdomain_times = intval($config_subdomain_times);//系统设置二级域名可修改次数
  42. $store_domain_times = intval($store_info['store_domain_times']);//店铺已修改次数
  43. $subdomain_length = explode('-',$config_subdomain_length);
  44. $subdomain_length[0] = intval($subdomain_length[0]);
  45. $subdomain_length[1] = intval($subdomain_length[1]);
  46. if ($subdomain_length[0] < 1 || $subdomain_length[0] >= $subdomain_length[1]){//域名长度
  47. $subdomain_length[0] = 3;
  48. $subdomain_length[1] = 12;
  49. }
  50. Tpl::output('subdomain_length',$subdomain_length);
  51. /**
  52. * 保存店铺设置
  53. */
  54. if (chksubmit()){
  55. $_POST['store_domain'] = trim($_POST['store_domain']);
  56. $store_domain = strtolower($_POST['store_domain']);
  57. //判断是否设置二级域名
  58. if (!empty($store_domain) && $store_domain != $store_info['store_domain']){
  59. $store_domain_count = strlen($store_domain);
  60. if ($store_domain_count < $subdomain_length[0] || $store_domain_count > $subdomain_length[1]){
  61. showDialog(Language::get('store_setting_wrong_uri').': '.$config_subdomain_length,'reload','error');
  62. }
  63. if (!preg_match('/^[\w-]+$/i',$store_domain)){//判断域名是否正确
  64. showDialog(Language::get('store_setting_lack_uri'));
  65. }
  66. $store = $model_class->getStoreInfo(array(
  67. 'store_domain'=>$store_domain
  68. ));
  69. //二级域名存在,则提示错误
  70. if (!empty($store) && ($store_id != $store['store_id'])){
  71. showDialog(Language::get('store_setting_exists_uri'),'reload','error');
  72. }
  73. //判断二级域名是否为系统禁止
  74. $subdomain_reserved = @explode(',',$config_subdomain_reserved);
  75. if(!empty($subdomain_reserved) && is_array($subdomain_reserved)){
  76. if (in_array($store_domain,$subdomain_reserved)){
  77. showDialog(Language::get('store_setting_invalid_uri'));
  78. }
  79. }
  80. if($subdomain_times > $store_domain_times){//可继续修改
  81. $param = array();
  82. $param['store_domain'] = $store_domain;
  83. if (!empty($store_info['store_domain'])) $param['store_domain_times'] = $store_domain_times+1;//第一次保存不计数
  84. $model_class->editStore($param, array('store_id' => $store_id));
  85. }
  86. $_POST['store_domain'] = '';//避免重复更新
  87. }
  88. $upload = new UploadFile();
  89. /**
  90. * 上传店铺图片
  91. */
  92. if (!empty($_FILES['store_banner']['name'])){
  93. $upload->set('default_dir', ATTACH_STORE);
  94. $upload->set('thumb_ext', '');
  95. $upload->set('file_name','');
  96. $upload->set('ifremove',false);
  97. $result = $upload->upfile('store_banner');
  98. if ($result){
  99. $_POST['store_banner'] = $upload->file_name;
  100. }else {
  101. showDialog($upload->error);
  102. }
  103. }
  104. //删除旧店铺图片
  105. if (!empty($_POST['store_banner']) && !empty($store_info['store_banner'])){
  106. @unlink(BASE_UPLOAD_PATH.DS.ATTACH_STORE.DS.$store_info['store_banner']);
  107. }
  108. /**
  109. * 上传店铺图片
  110. */
  111. if (!empty($_FILES['store_label']['name'])){
  112. $upload->set('default_dir', ATTACH_STORE);
  113. $upload->set('thumb_ext', '');
  114. $upload->set('file_name','');
  115. $upload->set('ifremove',false);
  116. $result = $upload->upfile('store_label');
  117. if ($result){
  118. $_POST['store_label'] = $upload->file_name;
  119. }else {
  120. showDialog($upload->error);
  121. }
  122. }
  123. //删除旧店铺图片
  124. if (!empty($_POST['store_label']) && !empty($store_info['store_label'])){
  125. @unlink(BASE_UPLOAD_PATH.DS.ATTACH_STORE.DS.$store_info['store_label']);
  126. }
  127. //删除旧店铺图片
  128. if (!empty($_POST['store_logo']) && !empty($store_info['store_logo'])){
  129. @unlink(BASE_UPLOAD_PATH.DS.ATTACH_STORE.DS.$store_info['store_logo']);
  130. }
  131. /**
  132. * 更新入库
  133. */
  134. $param = array(
  135. 'store_label' => empty($_POST['store_label']) ? $store_info['store_label'] : $_POST['store_label'],
  136. 'store_banner' => empty($_POST['store_banner']) ? $store_info['store_banner'] : $_POST['store_banner'],
  137. 'store_avatar' => empty($_POST['store_avatar']) ? $store_info['store_avatar'] : $_POST['store_avatar'],
  138. 'store_qq' => $_POST['store_qq'],
  139. 'store_ww' => $_POST['store_ww'],
  140. 'store_phone' => $_POST['store_phone'],
  141. 'store_zy' => $_POST['store_zy'],
  142. 'store_keywords' => $_POST['seo_keywords'],
  143. 'store_description' => $_POST['seo_description']
  144. );
  145. if (!empty($_POST['store_theme'])){
  146. $param['store_theme'] = $_POST['store_theme'];
  147. }
  148. //v3-b11 编辑店铺名称
  149. $store_name=$_POST['store_name'];
  150. if (!empty($_POST['store_name'])){
  151. $store = $model_class->getStoreInfo(array(
  152. 'store_name'=>$store_name
  153. ));
  154. //店铺名存在,则提示错误
  155. if (!empty($store) && ($store_id != $store['store_id'])){
  156. showDialog('此店铺名称已被其它人使用,请换其它名称。','reload','error');
  157. return;
  158. }
  159. $param['store_name'] = $_POST['store_name'];
  160. }
  161. //end 33h ao.co m
  162. $model_class->editStore($param, array('store_id' => $store_id));
  163. showDialog(Language::get('nc_common_save_succ'),'index.php?act=store_setting&op=store_setting','succ');
  164. }
  165. /**
  166. * 实例化店铺等级模型
  167. */
  168. // $model_store_grade = Model('store_grade');
  169. // $store_grade = $model_store_grade->getOneGrade($store_info['grade_id']);
  170. // 从基类中读取店铺等级信息
  171. $store_grade = $this->store_grade;
  172. //编辑器多媒体功能
  173. $editor_multimedia = false;
  174. $sg_fun = @explode('|',$store_grade['sg_function']);
  175. if(!empty($sg_fun) && is_array($sg_fun)){
  176. foreach($sg_fun as $fun){
  177. if ($fun == 'editor_multimedia'){
  178. $editor_multimedia = true;
  179. }
  180. }
  181. }
  182. Tpl::output('editor_multimedia',$editor_multimedia);
  183. if($subdomain_edit == 1 && ($subdomain_times > $store_domain_times)){//可继续修改二级域名
  184. Tpl::output('subdomain_edit',$subdomain_edit);
  185. }
  186. /**
  187. * 输出店铺信息
  188. */
  189. self::profile_menu('store_setting');
  190. Tpl::output('store_info',$store_info);
  191. Tpl::output('store_grade',$store_grade);
  192. Tpl::output('subdomain',$config_enabled_subdomain);
  193. Tpl::output('subdomain_times',$config_subdomain_times);
  194. /**
  195. * 页面输出
  196. */
  197. Tpl::showpage('store_setting_form');
  198. }
  199. /**
  200. * 店铺幻灯片
  201. */
  202. public function store_slideOp() {
  203. /**
  204. * 模型实例化
  205. */
  206. $model_store = Model('store');
  207. $model_upload = Model('upload');
  208. /**
  209. * 保存店铺信息
  210. */
  211. if ($_POST['form_submit'] == 'ok'){
  212. // 更新店铺信息
  213. $update = array();
  214. $update['store_slide'] = implode(',', $_POST['image_path']);
  215. $update['store_slide_url'] = implode(',', $_POST['image_url']);
  216. $model_store->editStore($update, array('store_id' => $_SESSION['store_id']));
  217. // 删除upload表中数据
  218. $model_upload->delByWhere(array('upload_type'=>3,'item_id'=>$_SESSION['store_id']));
  219. showDialog(Language::get('nc_common_save_succ'),'index.php?act=store_setting&op=store_slide','succ');
  220. }
  221. // 删除upload中的无用数据
  222. $upload_info = $model_upload->getUploadList(array('upload_type'=>3,'item_id'=>$_SESSION['store_id']),'file_name');
  223. if(is_array($upload_info) && !empty($upload_info)){
  224. foreach ($upload_info as $val){
  225. @unlink(BASE_UPLOAD_PATH.DS.ATTACH_SLIDE.DS.$val['file_name']);
  226. }
  227. }
  228. $model_upload->delByWhere(array('upload_type'=>3,'item_id'=>$_SESSION['store_id']));
  229. $store_info = $model_store->getStoreInfoByID($_SESSION['store_id']);
  230. if($store_info['store_slide'] != '' && $store_info['store_slide'] != ',,,,'){
  231. Tpl::output('store_slide', explode(',', $store_info['store_slide']));
  232. Tpl::output('store_slide_url', explode(',', $store_info['store_slide_url']));
  233. }
  234. self::profile_menu('store_slide');
  235. /**
  236. * 页面输出
  237. */
  238. Tpl::showpage('store_slide_form');
  239. }
  240. /**
  241. * 店铺幻灯片ajax上传
  242. */
  243. public function silde_image_uploadOp(){
  244. $upload = new UploadFile();
  245. $upload->set('default_dir',ATTACH_SLIDE);
  246. $upload->set('max_size',C('image_max_filesize'));
  247. $result = $upload->upfile($_POST['id']);
  248. $output = array();
  249. if(!$result){
  250. /**
  251. * 转码
  252. */
  253. if (strtoupper(CHARSET) == 'GBK'){
  254. $upload->error = Language::getUTF8($upload->error);
  255. }
  256. $output['error'] = $upload->error;
  257. echo json_encode($output);die;
  258. }
  259. $img_path = $upload->file_name;
  260. /**
  261. * 模型实例化
  262. */
  263. $model_upload = Model('upload');
  264. if(intval($_POST['file_id']) > 0){
  265. $file_info = $model_upload->getOneUpload($_POST['file_id']);
  266. @unlink(BASE_UPLOAD_PATH.DS.ATTACH_SLIDE.DS.$file_info['file_name']);
  267. $update_array = array();
  268. $update_array['upload_id'] = intval($_POST['file_id']);
  269. $update_array['file_name'] = $img_path;
  270. $update_array['file_size'] = $_FILES[$_POST['id']]['size'];
  271. $model_upload->update($update_array);
  272. $output['file_id'] = intval($_POST['file_id']);
  273. $output['id'] = $_POST['id'];
  274. $output['file_name'] = $img_path;
  275. echo json_encode($output);die;
  276. }else{
  277. /**
  278. * 图片数据入库
  279. */
  280. $insert_array = array();
  281. $insert_array['file_name'] = $img_path;
  282. $insert_array['upload_type'] = '3';
  283. $insert_array['file_size'] = $_FILES[$_POST['id']]['size'];
  284. $insert_array['item_id'] = $_SESSION['store_id'];
  285. $insert_array['upload_time'] = time();
  286. $result = $model_upload->add($insert_array);
  287. if(!$result){
  288. @unlink(BASE_UPLOAD_PATH.DS.ATTACH_SLIDE.DS.$img_path);
  289. $output['error'] = Language::get('store_slide_upload_fail','UTF-8');
  290. echo json_encode($output);die;
  291. }
  292. $output['file_id'] = $result;
  293. $output['id'] = $_POST['id'];
  294. $output['file_name'] = $img_path;
  295. echo json_encode($output);die;
  296. }
  297. }
  298. /**
  299. * ajax删除幻灯片图片
  300. */
  301. public function dorp_imgOp(){
  302. /**
  303. * 模型实例化
  304. */
  305. $model_upload = Model('upload');
  306. $file_info = $model_upload->getOneUpload(intval($_GET['file_id']));
  307. if(!$file_info){
  308. }else{
  309. @unlink(BASE_UPLOAD_PATH.DS.ATTACH_SLIDE.DS.$file_info['file_name']);
  310. $model_upload->del(intval($_GET['file_id']));
  311. }
  312. echo json_encode(array('succeed'=>Language::get('nc_common_save_succ','UTF-8')));die;
  313. }
  314. /**
  315. * 卖家店铺主题设置
  316. *
  317. * @param string
  318. * @param string
  319. * @return
  320. */
  321. public function themeOp(){
  322. /**
  323. * 店铺信息
  324. */
  325. $store_class = Model('store');
  326. $store_info = $store_class->getStoreInfoByID($_SESSION['store_id']);
  327. /**
  328. * 主题配置信息
  329. */
  330. $style_data = array();
  331. $style_configurl = BASE_ROOT_PATH.DS.DIR_SHOP.'/templates/'.TPL_SHOP_NAME.DS.'store'.DS.'style'.DS."styleconfig.php";
  332. if (file_exists($style_configurl)){
  333. include_once($style_configurl);
  334. }
  335. /**
  336. * 转码
  337. */
  338. if (strtoupper(CHARSET) == 'GBK'){
  339. $style_data = Language::getGBK($style_data);
  340. }
  341. /**
  342. * 当前店铺主题
  343. */
  344. $curr_store_theme = !empty($store_info['store_theme'])?$store_info['store_theme']:'default';
  345. /**
  346. * 当前店铺预览图片
  347. */
  348. $curr_image = SHOP_TEMPLATES_URL.'/store/style/'.$curr_store_theme.'/images/preview.jpg';
  349. $curr_theme = array(
  350. 'curr_name'=>$curr_store_theme,
  351. 'curr_truename'=>$style_data[$curr_store_theme]['truename'],
  352. 'curr_image'=>$curr_image
  353. );
  354. // 自营店全部可用
  355. if (checkPlatformStore()) {
  356. $themes = array_keys($style_data);
  357. } else {
  358. /**
  359. * 店铺等级
  360. */
  361. $grade_class = Model('store_grade');
  362. $grade = $grade_class->getOneGrade($store_info['grade_id']);
  363. /**
  364. * 可用主题
  365. */
  366. $themes = explode('|',$grade['sg_template']);
  367. }
  368. /**
  369. * 可用主题预览图片
  370. */
  371. foreach ($style_data as $key => $val){
  372. if (in_array($key,$themes)){
  373. $theme_list[$key] = array(
  374. 'name'=>$key,
  375. 'truename'=>$val['truename'],
  376. 'image'=>SHOP_TEMPLATES_URL.'/store/style/'.$key.'/images/preview.jpg'
  377. );
  378. }
  379. }
  380. /**
  381. * 页面输出
  382. */
  383. self::profile_menu('store_theme','store_theme');
  384. Tpl::output('store_info',$store_info);
  385. Tpl::output('curr_theme',$curr_theme);
  386. Tpl::output('theme_list',$theme_list);
  387. Tpl::showpage('store_theme');
  388. }
  389. /**
  390. * 卖家店铺主题设置
  391. *
  392. * @param string
  393. * @param string
  394. * @return
  395. */
  396. public function set_themeOp(){
  397. //读取语言包
  398. $lang = Language::getLangContent();
  399. $style = isset($_GET['style_name']) ? trim($_GET['style_name']) : null;
  400. if (!empty($style) && file_exists(BASE_TPL_PATH.DS.'/store/style/'.$style.'/images/preview.jpg')){
  401. $store_class = Model('store');
  402. $rs = $store_class->editStore(array('store_theme'=>$style), array('store_id' => $_SESSION['store_id']));
  403. showDialog($lang['store_theme_congfig_success'],'reload','succ');
  404. }else{
  405. showDialog($lang['store_theme_congfig_fail'],'','succ');
  406. }
  407. }
  408. /**
  409. * 用户中心右边,小导航
  410. *
  411. * @param string $menu_type 导航类型
  412. * @param string $menu_key 当前导航的menu_key
  413. * @return
  414. */
  415. private function profile_menu($menu_key='') {
  416. Language::read('member_layout');
  417. $menu_array = array(
  418. 1=>array('menu_key'=>'store_setting','menu_name'=>Language::get('nc_member_path_store_config'),'menu_url'=>'index.php?act=store_setting&op=store_setting'),
  419. 4=>array('menu_key'=>'store_slide','menu_name'=>Language::get('nc_member_path_store_slide'),'menu_url'=>'index.php?act=store_setting&op=store_slide'),
  420. 5=>array('menu_key'=>'store_theme','menu_name'=>'店铺主题','menu_url'=>'index.php?act=store_setting&op=theme'),
  421. );
  422. Tpl::output('member_menu',$menu_array);
  423. Tpl::output('menu_key',$menu_key);
  424. }
  425. }