control.php 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326
  1. <?php
  2. /**
  3. * 前台control父类,店铺control父类,会员control父类
  4. *
  5. ***/
  6. defined('InShopNC') or exit('Access Invalid!');
  7. class Control
  8. {
  9. /**
  10. * 检查短消息数量
  11. *
  12. */
  13. protected function checkMessage() {
  14. if($_SESSION['member_id'] == '') return ;
  15. //判断cookie是否存在
  16. $cookie_name = 'msgnewnum'.$_SESSION['member_id'];
  17. if (cookie($cookie_name) != null){
  18. $countnum = intval(cookie($cookie_name));
  19. }else {
  20. $message_model = Model('message');
  21. $countnum = $message_model->countNewMessage($_SESSION['member_id']);
  22. setNcCookie($cookie_name,"$countnum",2*3600);//保存2小时
  23. }
  24. Tpl::output('message_num',$countnum);
  25. }
  26. /**
  27. * 输出头部的公用信息
  28. *
  29. */
  30. protected function showLayout() {
  31. $this->checkMessage();//短消息检查
  32. $this->article();//文章输出
  33. $this->showCartCount();
  34. Tpl::output('hot_search',@explode(',',C('hot_search')));//热门搜索
  35. $model_class = Model('goods_class');
  36. $goods_class = $model_class->get_all_category();
  37. Tpl::output('show_goods_class',$goods_class);//商品分类
  38. //获取导航
  39. Tpl::output('nav_list', rkcache('nav',true));
  40. }
  41. /**
  42. * 显示购物车数量
  43. */
  44. protected function showCartCount() {
  45. if (cookie('cart_goods_num') != null){
  46. $cart_num = intval(cookie('cart_goods_num'));
  47. }else {
  48. //已登录状态,存入数据库,未登录时,优先存入缓存,否则存入COOKIE
  49. if($_SESSION['member_id']) {
  50. $save_type = 'db';
  51. } else {
  52. $save_type = 'cookie';
  53. }
  54. $cart_num = Model('cart')->getCartNum($save_type,array('buyer_id'=>$_SESSION['member_id']));//查询购物车商品种类
  55. }
  56. Tpl::output('cart_goods_num',$cart_num);
  57. }
  58. /**
  59. * 输出会员等级
  60. * @param bool $is_return 是否返回会员信息,返回为true,输出会员信息为false
  61. */
  62. protected function getMemberAndGradeInfo($is_return = false){
  63. $member_info = array();
  64. //会员详情及会员级别处理
  65. if($_SESSION['member_id']) {
  66. $model_member = Model('member');
  67. $member_info = $model_member->getMemberInfoByID($_SESSION['member_id']);
  68. if ($member_info){
  69. $member_gradeinfo = $model_member->getOneMemberGrade(intval($member_info['member_exppoints']));
  70. $member_info = array_merge($member_info,$member_gradeinfo);
  71. }
  72. }
  73. if ($is_return == true){//返回会员信息
  74. return $member_info;
  75. } else {//输出会员信息
  76. Tpl::output('member_info',$member_info);
  77. }
  78. }
  79. /**
  80. * 验证会员是否登录
  81. *
  82. */
  83. protected function checkLogin(){
  84. if ($_SESSION['is_login'] !== '1'){
  85. if (trim($_GET['op']) == 'favoritesgoods' || trim($_GET['op']) == 'favoritesstore'){
  86. $lang = Language::getLangContent('UTF-8');
  87. echo json_encode(array('done'=>false,'msg'=>$lang['no_login']));
  88. die;
  89. }
  90. $ref_url = request_uri();
  91. if ($_GET['inajax']){
  92. showDialog('','','js',"login_dialog();",200);
  93. }else {
  94. @header("location: index.php?act=login&ref_url=".urlencode($ref_url));
  95. }
  96. exit;
  97. }
  98. }
  99. /**
  100. * 添加到任务队列
  101. *
  102. * @param array $goods_array
  103. * @param boolean $ifdel 是否删除以原记录
  104. */
  105. protected function addcron($data = array(), $ifdel = false) {
  106. $model_cron = Model('cron');
  107. if (isset($data[0])) { // 批量插入
  108. $where = array();
  109. foreach ($data as $k => $v) {
  110. if (isset($v['content'])) {
  111. $data[$k]['content'] = serialize($v['content']);
  112. }
  113. // 删除原纪录条件
  114. if ($ifdel) {
  115. $where[] = '(type = ' . $data['type'] . ' and exeid = ' . $data['exeid'] . ')';
  116. }
  117. }
  118. // 删除原纪录
  119. if ($ifdel) {
  120. $model_cron->delCron(implode(',', $where));
  121. }
  122. $model_cron->addCronAll($data);
  123. } else { // 单条插入
  124. if (isset($data['content'])) {
  125. $data['content'] = serialize($data['content']);
  126. }
  127. // 删除原纪录
  128. if ($ifdel) {
  129. $model_cron->delCron(array('type' => $data['type'], 'exeid' => $data['exeid']));
  130. }
  131. $model_cron->addCron($data);
  132. }
  133. }
  134. //文章输出
  135. protected function article() {
  136. if (C('cache_open')) {
  137. if ($article = rkcache("index/article")) {
  138. Tpl::output('show_article', $article['show_article']);
  139. Tpl::output('article_list', $article['article_list']);
  140. return;
  141. }
  142. } else {
  143. if (file_exists(BASE_DATA_PATH.'/cache/index/article.php')){
  144. include(BASE_DATA_PATH.'/cache/index/article.php');
  145. Tpl::output('show_article', $show_article);
  146. Tpl::output('article_list', $article_list);
  147. return;
  148. }
  149. }
  150. $model_article_class = Model('article_class');
  151. $model_article = Model('article');
  152. $show_article = array();//商城公告
  153. $article_list = array();//下方文章
  154. $notice_class = array('notice');
  155. $code_array = array('member','store','payment','sold','service','about');
  156. $notice_limit = 5;
  157. $faq_limit = 5;
  158. $class_condition = array();
  159. $class_condition['home_index'] = 'home_index';
  160. $class_condition['order'] = 'ac_sort asc';
  161. $article_class = $model_article_class->getClassList($class_condition);
  162. $class_list = array();
  163. if(!empty($article_class) && is_array($article_class)){
  164. foreach ($article_class as $key => $val){
  165. $ac_code = $val['ac_code'];
  166. $ac_id = $val['ac_id'];
  167. $val['list'] = array();//文章
  168. $class_list[$ac_id] = $val;
  169. }
  170. }
  171. $condition = array();
  172. $condition['article_show'] = '1';
  173. $condition['home_index'] = 'home_index';
  174. $condition['field'] = 'article.article_id,article.ac_id,article.article_url,article.article_title,article.article_time,article_class.ac_name,article_class.ac_parent_id';
  175. $condition['order'] = 'article_sort asc,article_time desc';
  176. $condition['limit'] = '300';
  177. $article_array = $model_article->getJoinList($condition);
  178. if(!empty($article_array) && is_array($article_array)){
  179. foreach ($article_array as $key => $val){
  180. $ac_id = $val['ac_id'];
  181. $ac_parent_id = $val['ac_parent_id'];
  182. if($ac_parent_id == 0) {//顶级分类
  183. $class_list[$ac_id]['list'][] = $val;
  184. } else {
  185. $class_list[$ac_parent_id]['list'][] = $val;
  186. }
  187. }
  188. }
  189. if(!empty($class_list) && is_array($class_list)){
  190. foreach ($class_list as $key => $val){
  191. $ac_code = $val['ac_code'];
  192. if(in_array($ac_code,$notice_class)) {
  193. $list = $val['list'];
  194. array_splice($list, $notice_limit);
  195. $val['list'] = $list;
  196. $show_article[$ac_code] = $val;
  197. }
  198. if (in_array($ac_code,$code_array)){
  199. $list = $val['list'];
  200. $val['class']['ac_name'] = $val['ac_name'];
  201. array_splice($list, $faq_limit);
  202. $val['list'] = $list;
  203. $article_list[] = $val;
  204. }
  205. }
  206. }
  207. if (C('cache_open')) {
  208. wkcache('index/article', array(
  209. 'show_article' => $show_article,
  210. 'article_list' => $article_list,
  211. ));
  212. } else {
  213. $string = "<?php\n\$show_article=".var_export($show_article,true).";\n";
  214. $string .= "\$article_list=".var_export($article_list,true).";\n?>";
  215. file_put_contents(BASE_DATA_PATH.'/cache/index/article.php',($string));
  216. }
  217. Tpl::output('show_article',$show_article);
  218. Tpl::output('article_list',$article_list);
  219. }
  220. }
  221. /********************************** 前台control父类 **********************************************/
  222. class BaseHomeControl extends Control {
  223. public function __construct(){
  224. //输出头部的公用信息
  225. $this->showLayout();
  226. //输出会员信息
  227. $this->getMemberAndGradeInfo(false);
  228. Language::read('common,home_layout');
  229. Tpl::setDir('home');
  230. Tpl::setLayout('home_layout');
  231. if ($_GET['column'] && strtoupper(CHARSET) == 'GBK'){
  232. $_GET = Language::getGBK($_GET);
  233. }
  234. if(!C('site_status')) halt(C('closed_reason'));
  235. }
  236. }
  237. /********************************** H5页面内容 **********************************************/
  238. class BaseH5Control extends Control {
  239. public function __construct(){
  240. // //输出头部的公用信息
  241. // $this->showLayout();
  242. // //输出会员信息
  243. // $this->getMemberAndGradeInfo(false);
  244. //
  245. // Language::read('common,home_layout');
  246. Tpl::setDir('h5_hb');
  247. // Tpl::setLayout('home_layout');
  248. //
  249. // if ($_GET['column'] && strtoupper(CHARSET) == 'GBK'){
  250. // $_GET = Language::getGBK($_GET);
  251. // }
  252. // if(!C('site_status')) halt(C('closed_reason'));
  253. }
  254. }
  255. /********************************** 购买流程父类 **********************************************/
  256. class BaseBuyControl extends Control {
  257. protected $member_info = array(); // 会员信息
  258. protected function __construct(){
  259. Language::read('common,home_layout');
  260. //输出会员信息
  261. $this->member_info = $this->getMemberAndGradeInfo(true);
  262. Tpl::output('member_info', $this->member_info);
  263. Tpl::setDir('buy');
  264. Tpl::setLayout('buy_layout');
  265. if ($_GET['column'] && strtoupper(CHARSET) == 'GBK'){
  266. $_GET = Language::getGBK($_GET);
  267. }
  268. if(!C('site_status')) halt(C('closed_reason'));
  269. //获取导航
  270. Tpl::output('nav_list', rkcache('nav',true));
  271. }
  272. }
  273. /********************************** 会员control父类 **********************************************/
  274. class BaseMemberControl extends Control {
  275. protected $member_info = array(); // 会员信息
  276. protected $quicklink = array(); // 常用菜单
  277. public function __construct(){
  278. if(!C('site_status')) halt(C('closed_reason'));
  279. Language::read('common,member_layout');
  280. if ($_GET['column'] && strtoupper(CHARSET) == 'GBK'){
  281. $_GET = Language::getGBK($_GET);
  282. }
  283. //会员验证
  284. $this->checkLogin();
  285. //输出头部的公用信息
  286. $this->showLayout();
  287. Tpl::setDir('member');
  288. Tpl::setLayout('member_layout');
  289. //获得会员信息
  290. $this->member_info = $this->getMemberAndGradeInfo(true);
  291. $this->quicklink = explode(',', $this->member_info['member_quicklink']);
  292. Tpl::output('member_info', $this->member_info);
  293. // 常用操作及导航
  294. $common_menu_list = $this->_getCommonOperationsAndNavLink();
  295. }
  296. /**
  297. * 常用操作
  298. *
  299. * @param string $act
  300. * 如果菜单中的切换卡不在一个菜单中添加$act参数,值为当前菜单的下标
  301. *
  302. */
  303. protected function _getCommonOperationsAndNavLink ($act = '') {
  304. // 左侧导航
  305. $menu_list = $this->_getMenuList();
  306. $operations_list = array();
  307. foreach ($menu_list as $key => $val) {
  308. foreach ($val['child'] as $k=>$v) {
  309. if (in_array($k, $this->quicklink)) {
  310. $ql = array_flip($this->quicklink);
  311. $operations_list[$ql[$k]] = array_merge($v,array('key' => $k));
  312. $menu_list[$key]['child'][$k]['selected'] = true;
  313. }
  314. if (($_GET['act'] == $k && $act == '') || $act == $k) {
  315. $nav['act'] = $k;
  316. $nav['name'] = $v['name'];
  317. }
  318. }
  319. }
  320. Tpl::output('menu_list', $menu_list);
  321. // 菜单高亮
  322. Tpl::output('menu_highlight', $nav['act']);
  323. ksort($operations_list);
  324. Tpl::output('common_menu_list', $operations_list);
  325. // 面包屑
  326. $nav_link = array();
  327. $nav_link[] = array('title' => L('homepage'), 'link'=>SHOP_SITE_URL);
  328. if ($nav == '') {
  329. $nav_link[] = array('title' => '我的商城');
  330. } else {
  331. $nav_link[] = array('title' => '我的商城', 'link' => urlShop('member', 'home'));
  332. $nav_link[] = array('title' => $nav['name']);
  333. }
  334. Tpl::output('nav_link_list',$nav_link);
  335. }
  336. /**
  337. * 买家的左侧上部的头像和订单数量
  338. *
  339. */
  340. public function get_member_info() {
  341. //生成缓存的键值
  342. $hash_key = $_SESSION['member_id'];
  343. //写入缓存的数据
  344. $cachekey_arr = array('member_name','store_id','member_avatar','member_qq','member_email','member_ww','member_goldnum','member_points',
  345. 'available_predeposit','member_snsvisitnum','credit_arr','order_nopay','order_noreceiving','order_noeval','fan_count');
  346. if (false){
  347. foreach ($_cache as $k=>$v){
  348. $member_info[$k] = $v;
  349. }
  350. } else {
  351. $model_order = Model('order');
  352. $model_member = Model('member');
  353. $member_info = $model_member->getMemberInfo(array('member_id'=>$_SESSION['member_id']));
  354. $member_info['order_nopay'] = $model_order->getOrderStateNewCount(array('buyer_id'=>$_SESSION['member_id']));
  355. $member_info['order_noreceiving'] = $model_order->getOrderStateSendCount(array('buyer_id'=>$_SESSION['member_id']));
  356. $member_info['order_noeval'] = $model_order->getOrderStateEvalCount(array('buyer_id'=>$_SESSION['member_id']));
  357. if (C('voucher_allow') == 1) {
  358. $time_to = time();//当前日期
  359. $member_info['voucher'] = Model()->table('voucher')->where(array('voucher_owner_id'=> $_SESSION['member_id'],'voucher_state'=> 1,'voucher_start_date'=> array('elt',$time_to),'voucher_end_date'=> array('egt',$time_to)))->count();
  360. }
  361. }
  362. Tpl::output('member_info',$member_info);
  363. Tpl::output('header_menu_sign','snsindex');//默认选中顶部“买家首页”菜单
  364. }
  365. /**
  366. * 左侧导航
  367. * 菜单数组中child的下标要和其链接的act对应。否则面包屑不能正常显示
  368. * @return array
  369. */
  370. private function _getMenuList() {
  371. $menu_list = array(
  372. 'trade' => array('name' => '交易管理', 'child' => array(
  373. 'member_order' => array('name' => '实物交易订单', 'url'=>urlShop('member_order', 'index')),
  374. 'member_vr_order' => array('name' => '虚拟兑码订单', 'url'=>urlShop('member_vr_order','index')),
  375. 'member_favorites' => array('name' => '我的收藏', 'url'=>urlShop('member_favorites', 'fglist')),
  376. 'member_evaluate' => array('name' => '交易评价/晒单', 'url'=>urlShop('member_evaluate', 'list')),
  377. 'predeposit' => array('name' => '账户余额', 'url'=>urlShop('predeposit', 'pd_log_list')),
  378. 'member_flea' => array('name' => '我的闲置', 'url'=>urlShop('member_flea', 'index')),
  379. 'member_points' => array('name' => '我的积分', 'url'=>urlShop('member_points', 'index')),
  380. 'member_voucher' => array('name' => '我的代金券', 'url'=>urlShop('member_voucher', 'index'))
  381. )),
  382. 'serv' => array('name' => '客户服务', 'child' => array(
  383. 'member_refund' => array('name' => '退款及退货', 'url'=>urlShop('member_refund', 'index')),
  384. 'member_complain' => array('name' => '交易投诉', 'url'=>urlShop('member_complain', 'index')),
  385. 'member_consult' => array('name' => '商品咨询', 'url'=>urlShop('member_consult', 'my_consult')),
  386. 'member_inform' => array('name' => '违规举报', 'url'=>urlShop('member_inform', 'index')),
  387. 'member_mallconsult'=> array('name' => '平台客服', 'url'=>urlShop('member_mallconsult', 'index'))
  388. )),
  389. 'info' => array('name' => '资料管理', 'child' => array(
  390. 'member_information'=> array('name' => '账户信息', 'url'=>urlShop('member_information', 'member')),
  391. 'member_security' => array('name' => '账户安全', 'url'=>urlShop('member_security', 'index')),
  392. 'member_address' => array('name' => '收货地址', 'url'=>urlShop('member_address', 'address')),
  393. 'member_message' => array('name' => '我的消息', 'url'=>urlShop('member_message', 'message')),
  394. 'member_snsfriend' => array('name' => '我的好友', 'url'=>urlShop('member_snsfriend', 'find')),
  395. 'member_goodsbrowse'=> array('name' => '我的足迹', 'url'=>urlShop('member_goodsbrowse', 'list')),
  396. 'member_connect' => array('name' => '第三方账号登录', 'url'=>urlShop('member_connect', 'qqbind')),
  397. 'member_sharemanage'=> array('name' => '分享绑定', 'url'=>urlShop('member_sharemanage', 'index'))
  398. )),
  399. 'app' => array('name' => '应用管理', 'child' => array(
  400. 'sns' => array('name' => '个人主页', 'url'=>urlShop('member_snshome', 'index')),
  401. 'cms' => array('name' => '我的CMS', 'url'=>urlCMS('member_article', 'article_list')),
  402. 'circle' => array('name' => '我的圈子', 'url'=>urlCircle('p_center', 'index')),
  403. 'microshop' => array('name' => '我的微商城', 'url'=>urlMicroshop('home', 'index', array('member_id' => $_SESSION['member_id'])))
  404. ))
  405. );
  406. return $menu_list;
  407. }
  408. }
  409. /********************************** SNS control父类 **********************************************/
  410. class BaseSNSControl extends Control {
  411. protected $relation = 0;//浏览者与主人的关系:0 表示游客 1 表示一般普通会员 2表示朋友 3表示自己4表示已关注主人
  412. protected $master_id = 0; //主人编号
  413. const MAX_RECORDNUM = 20;//允许插入新记录的最大条数
  414. protected $master_info;
  415. public function __construct(){
  416. Tpl::setDir('sns');
  417. Tpl::setLayout('sns_layout');
  418. Language::read('common,sns_layout');
  419. //验证会员及与主人关系
  420. $this->check_relation();
  421. //查询会员信息
  422. $this->getMemberAndGradeInfo(false);
  423. $this->master_info = $this->get_member_info();
  424. Tpl::output('master_info',$this->master_info);
  425. //添加访问记录
  426. $this->add_visit();
  427. //我的关注
  428. $this->my_attention();
  429. //获取设置
  430. $this->get_setting();
  431. //允许插入新记录的最大条数
  432. Tpl::output('max_recordnum',self::MAX_RECORDNUM);
  433. $this->showCartCount();
  434. Tpl::output('nav_list', rkcache('nav',true));
  435. }
  436. /**
  437. * 格式化时间
  438. * @param string $time时间戳
  439. */
  440. protected function formatDate($time){
  441. $handle_date = @date('Y-m-d',$time);//需要格式化的时间
  442. $reference_date = @date('Y-m-d',time());//参照时间
  443. $handle_date_time = strtotime($handle_date);//需要格式化的时间戳
  444. $reference_date_time = strtotime($reference_date);//参照时间戳
  445. if ($reference_date_time == $handle_date_time){
  446. $timetext = @date('H:i',$time);//今天访问的显示具体的时间点
  447. }elseif (($reference_date_time-$handle_date_time)==60*60*24){
  448. $timetext = Language::get('sns_yesterday');
  449. }elseif ($reference_date_time-$handle_date_time==60*60*48){
  450. $timetext = Language::get('sns_beforeyesterday');
  451. }else {
  452. $month_text = Language::get('nc_month');
  453. $day_text = Language::get('nc_day');
  454. $timetext = @date("m{$month_text}d{$day_text}",$time);
  455. }
  456. return $timetext;
  457. }
  458. /**
  459. * 会员信息
  460. *
  461. * @return array
  462. */
  463. public function get_member_info() {
  464. if($this->master_id <= 0){
  465. showMessage(L('wrong_argument'), '', '', 'error');
  466. }
  467. $model = Model();
  468. $member_info = Model('member')->getMemberInfoByID($this->master_id);
  469. if(empty($member_info)){
  470. showMessage(L('wrong_argument'), 'index.php?act=member_snshome', '', 'error');
  471. }
  472. //粉丝数
  473. $fan_count = $model->table('sns_friend')->where(array('friend_tomid'=>$this->master_id))->count();
  474. $member_info['fan_count'] = $fan_count;
  475. //关注数
  476. $attention_count = $model->table('sns_friend')->where(array('friend_frommid'=>$this->master_id))->count();
  477. $member_info['attention_count'] = $attention_count;
  478. //兴趣标签
  479. $mtag_list = $model->table('sns_membertag,sns_mtagmember')->field('mtag_name')->on('sns_membertag.mtag_id = sns_mtagmember.mtag_id')->join('inner')->where(array('sns_mtagmember.member_id'=>$this->master_id))->select();
  480. $tagname_array = array();
  481. if(!empty($mtag_list)){
  482. foreach ($mtag_list as $val){
  483. $tagname_array[] = $val['mtag_name'];
  484. }
  485. }
  486. $member_info['tagname'] = $tagname_array;
  487. return $member_info;
  488. }
  489. /**
  490. * 访客信息
  491. */
  492. protected function get_visitor(){
  493. $model = Model();
  494. //查询谁来看过我
  495. $visitme_list = $model->table('sns_visitor')->where(array('v_ownermid'=>$this->master_id))->limit(9)->order('v_addtime desc')->select();
  496. if (!empty($visitme_list)){
  497. foreach ($visitme_list as $k=>$v){
  498. $v['adddate_text'] = $this->formatDate($v['v_addtime']);
  499. $v['addtime_text'] = @date('H:i',$v['v_addtime']);
  500. $visitme_list[$k] = $v;
  501. }
  502. }
  503. Tpl::output('visitme_list',$visitme_list);
  504. if($this->relation == 3){ // 主人自己才有我访问过的人
  505. //查询我访问过的人
  506. $visitother_list = $model->table('sns_visitor')->where(array('v_mid'=>$this->master_id))->limit(9)->order('v_addtime desc')->select();
  507. if (!empty($visitother_list)){
  508. foreach ($visitother_list as $k=>$v){
  509. $v['adddate_text'] = $this->formatDate($v['v_addtime']);
  510. $visitother_list[$k] = $v;
  511. }
  512. }
  513. Tpl::output('visitother_list',$visitother_list);
  514. }
  515. }
  516. /**
  517. * 验证会员及主人关系
  518. */
  519. private function check_relation(){
  520. $model = Model();
  521. //验证主人会员编号
  522. $this->master_id = intval($_GET['mid']);
  523. if ($this->master_id <= 0){
  524. if ($_SESSION['is_login'] == 1){
  525. $this->master_id = $_SESSION['member_id'];
  526. }else {
  527. @header("location: index.php?act=login&ref_url=".urlencode('index.php?act=member_snshome'));
  528. }
  529. }
  530. Tpl::output('master_id', $this->master_id);
  531. $model = Model();
  532. //判断浏览者与主人的关系
  533. if ($_SESSION['is_login'] == '1'){
  534. if ($this->master_id == $_SESSION['member_id']){//主人自己
  535. $this->relation = 3;
  536. }else{
  537. $this->relation = 1;
  538. //查询好友表
  539. $friend_arr = $model->table('sns_friend')->where(array('friend_frommid'=>$_SESSION['member_id'],'friend_tomid'=>$this->master_id))->find();
  540. if (!empty($friend_arr) && $friend_arr['friend_followstate'] == 2){
  541. $this->relation = 2;
  542. }elseif($friend_arr['friend_followstate'] == 1){
  543. $this->relation = 4;
  544. }
  545. }
  546. }
  547. Tpl::output('relation',$this->relation);
  548. }
  549. /**
  550. * 增加访问记录
  551. */
  552. private function add_visit(){
  553. $model = Model();
  554. //记录访客
  555. if ($_SESSION['is_login'] == '1' && $this->relation != 3){
  556. //访客为会员且不是空间主人则添加访客记录
  557. $visitor_info = $model->table('member')->find($_SESSION['member_id']);
  558. if (!empty($visitor_info)){
  559. //查询访客记录是否存在
  560. $existevisitor_info = $model->table('sns_visitor')->where(array('v_ownermid'=>$this->master_id, 'v_mid'=>$visitor_info['member_id']))->find();
  561. if (!empty($existevisitor_info)){//访问记录存在则更新访问时间
  562. $update_arr = array();
  563. $update_arr['v_addtime'] = time();
  564. $model->table('sns_visitor')->update(array('v_id'=>$existevisitor_info['v_id'], 'v_addtime'=>time()));
  565. }else {//添加新访问记录
  566. $insert_arr = array();
  567. $insert_arr['v_mid'] = $visitor_info['member_id'];
  568. $insert_arr['v_mname'] = $visitor_info['member_name'];
  569. $insert_arr['v_mavatar'] = $visitor_info['member_avatar'];
  570. $insert_arr['v_ownermid'] = $this->master_info['member_id'];
  571. $insert_arr['v_ownermname'] = $this->master_info['member_name'];
  572. $insert_arr['v_ownermavatar'] = $this->master_info['member_avatar'];
  573. $insert_arr['v_addtime'] = time();
  574. $model->table('sns_visitor')->insert($insert_arr);
  575. }
  576. }
  577. }
  578. //增加主人访问次数
  579. $cookie_str = cookie('visitor');
  580. $cookie_arr = array();
  581. $is_increase = false;
  582. if (empty($cookie_str)){
  583. //cookie不存在则直接增加访问次数
  584. $is_increase = true;
  585. }else{
  586. //cookie存在但是为空则直接增加访问次数
  587. $cookie_arr = explode('_',$cookie_str);
  588. if(!in_array($this->master_id,$cookie_arr)){
  589. $is_increase = true;
  590. }
  591. }
  592. if ($is_increase == true){
  593. //增加访问次数
  594. $model->table('member')->update(array('member_id'=>$this->master_id, 'member_snsvisitnum'=>array('exp', 'member_snsvisitnum+1')));
  595. //设置cookie,24小时之内不再累加
  596. $cookie_arr[] = $this->master_id;
  597. setNcCookie('visitor',implode('_',$cookie_arr),24*3600);//保存24小时
  598. }
  599. }
  600. //我的关注
  601. private function my_attention(){
  602. if(intval($_SESSION['member_id']) >0){
  603. $my_attention = Model()->table('sns_friend')->where(array('friend_frommid'=>$_SESSION['member_id']))->order('friend_addtime desc')->limit(4)->select();
  604. Tpl::output('my_attention', $my_attention);
  605. }
  606. }
  607. /**
  608. * 获取设置信息
  609. */
  610. private function get_setting(){
  611. $m_setting = Model()->table('sns_setting')->find($this->master_id);
  612. Tpl::output('skin_style', (!empty($m_setting['setting_skin'])?$m_setting['setting_skin']:'skin_01'));
  613. }
  614. /**
  615. * 留言板
  616. */
  617. protected function sns_messageboard(){
  618. $model = Model();
  619. $where = array();
  620. $where['from_member_id'] = array('neq',0);
  621. $where['to_member_id'] = $this->master_id;
  622. $where['message_state'] = array('neq',2);
  623. $where['message_parent_id'] = 0;
  624. $where['message_type'] = 2;
  625. $message_list = $model->table('message')->where($where)->order('message_id desc')->limit(10)->select();
  626. if(!empty($message_list)){
  627. $pmsg_id = array();
  628. foreach ($message_list as $key=>$val){
  629. $pmsg_id[] = $val['message_id'];
  630. $message_list[$key]['message_time'] = $this->formatDate($val['message_time']);
  631. }
  632. $where = array();
  633. $where['message_parent_id'] = array('in',$pmsg_id);
  634. $rmessage_array = $model->table('message')->where($where)->select();
  635. $rmessage_list = array();
  636. if(!empty($rmessage_array)){
  637. foreach ($rmessage_array as $key=>$val){
  638. $val['message_time'] = $this->formatDate($val['message_time']);
  639. $rmessage_list[$val['message_parent_id']][] = $val;
  640. }
  641. foreach ($rmessage_list as $key=>$val){
  642. $rmessage_list[$key] = array_slice($val, -3, 3);
  643. }
  644. }
  645. Tpl::output('rmessage_list', $rmessage_list);
  646. }
  647. Tpl::output('message_list', $message_list);
  648. }
  649. }
  650. /********************************** 店铺 control父类 **********************************************/
  651. class BaseStoreControl extends Control {
  652. protected $store_info;
  653. protected $store_decoration_only = false;
  654. public function __construct(){
  655. Language::read('common,store_layout,store_show_store_index');
  656. if(!C('site_status')) halt(C('closed_reason'));
  657. //输出头部的公用信息
  658. $this->showLayout();
  659. Tpl::setDir('store');
  660. Tpl::setLayout('store_layout');
  661. //输出会员信息
  662. $this->getMemberAndGradeInfo(false);
  663. $store_id = intval($_GET['store_id']);
  664. if($store_id <= 0) {
  665. showMessage(L('nc_store_close'), '', '', 'error');
  666. }
  667. $model_store = Model('store');
  668. $store_info = $model_store->getStoreOnlineInfoByID($store_id);
  669. if(empty($store_info)) {
  670. showMessage(L('nc_store_close'), '', '', 'error');
  671. } else {
  672. $this->store_info = $store_info;
  673. }
  674. if($store_info['store_decoration_switch'] > 0 & $store_info['store_decoration_only'] == 1) {
  675. $this->store_decoration_only = true;
  676. }
  677. //店铺装修
  678. $this->outputStoreDecoration($store_info['store_decoration_switch'], $store_id);
  679. $this->outputStoreInfo($this->store_info);
  680. $this->getStoreNavigation($store_id);
  681. $this->outputSeoInfo($this->store_info);
  682. }
  683. /**
  684. * 输出店铺装修
  685. */
  686. protected function outputStoreDecoration($decoration_id, $store_id) {
  687. if($decoration_id > 0 ) {
  688. $model_store_decoration = Model('store_decoration');
  689. $decoration_info = $model_store_decoration->getStoreDecorationInfoDetail($decoration_id, $store_id);
  690. if($decoration_info) {
  691. $decoration_background_style = $model_store_decoration->getDecorationBackgroundStyle($decoration_info['decoration_setting']);
  692. Tpl::output('decoration_background_style', $decoration_background_style);
  693. Tpl::output('decoration_nav', $decoration_info['decoration_nav']);
  694. Tpl::output('decoration_banner', $decoration_info['decoration_banner']);
  695. $html_file = BASE_UPLOAD_PATH.DS.ATTACH_STORE.DS.'decoration'.DS.'html'.DS.md5($store_id).'.html';
  696. if(is_file($html_file)) {
  697. Tpl::output('decoration_file', $html_file);
  698. }
  699. }
  700. Tpl::output('store_theme', 'default');
  701. } else {
  702. Tpl::output('store_theme', $this->store_info['store_theme']);
  703. }
  704. }
  705. /**
  706. * 检查店铺开启状态
  707. *
  708. * @param int $store_id 店铺编号
  709. * @param string $msg 警告信息
  710. */
  711. protected function outputStoreInfo($store_info){
  712. if(!$this->store_decoration_only) {
  713. $model_store = Model('store');
  714. $model_seller = Model('seller');
  715. //店铺分类
  716. $goodsclass_model = Model('store_goods_class');
  717. $goods_class_list = $goodsclass_model->getShowTreeList($store_info['store_id']);
  718. Tpl::output('goods_class_list', $goods_class_list);
  719. //热销排行
  720. $hot_sales = $model_store->getHotSalesList($store_info['store_id'], 5);
  721. Tpl::output('hot_sales', $hot_sales);
  722. //收藏排行
  723. $hot_collect = $model_store->getHotCollectList($store_info['store_id'], 5);
  724. Tpl::output('hot_collect', $hot_collect);
  725. }
  726. Tpl::output('store_info', $store_info);
  727. Tpl::output('page_title', $store_info['store_name']);
  728. }
  729. protected function getStoreNavigation($store_id) {
  730. $model_store_navigation = Model('store_navigation');
  731. $store_navigation_list = $model_store_navigation->getStoreNavigationList(array('sn_store_id' => $store_id));
  732. Tpl::output('store_navigation_list', $store_navigation_list);
  733. }
  734. protected function outputSeoInfo($store_info) {
  735. $seo_param = array();
  736. $seo_param['shopname'] = $store_info['store_name'];
  737. $seo_param['key'] = $store_info['store_keywords'];
  738. $seo_param['description'] = $store_info['store_description'];
  739. Model('seo')->type('shop')->param($seo_param)->show();
  740. }
  741. }
  742. class BaseGoodsControl extends BaseStoreControl {
  743. public function __construct(){
  744. Language::read('common,store_layout');
  745. if(!C('site_status')) halt(C('closed_reason'));
  746. Tpl::setDir('store');
  747. Tpl::setLayout('home_layout');
  748. //输出头部的公用信息
  749. $this->showLayout();
  750. //输出会员信息
  751. $this->getMemberAndGradeInfo(false);
  752. }
  753. protected function getStoreInfo($store_id) {
  754. $model_store = Model('store');
  755. $store_info = $model_store->getStoreOnlineInfoByID($store_id);
  756. if(empty($store_info)) {
  757. showMessage(L('nc_store_close'), '', '', 'error');
  758. }
  759. $this->outputStoreInfo($store_info);
  760. }
  761. }
  762. /**
  763. * 店铺 control新父类
  764. *
  765. */
  766. class BaseSellerControl extends Control {
  767. //店铺信息
  768. protected $store_info = array();
  769. //店铺等级
  770. protected $store_grade = array();
  771. public function __construct(){
  772. Language::read('common,store_layout,member_layout');
  773. if(!C('site_status')) halt(C('closed_reason'));
  774. Tpl::setDir('seller');
  775. Tpl::setLayout('seller_layout');
  776. //输出会员信息
  777. $this->getMemberAndGradeInfo(false);
  778. Tpl::output('nav_list', rkcache('nav',true));
  779. if ($_GET['act'] !== 'seller_login') {
  780. if(empty($_SESSION['seller_id'])) {
  781. @header('location: index.php?act=seller_login&op=show_login');die;
  782. }
  783. // 验证店铺是否存在
  784. $model_store = Model('store');
  785. $this->store_info = $model_store->getStoreInfoByID($_SESSION['store_id']);
  786. if (empty($this->store_info)) {
  787. @header('location: index.php?act=seller_login&op=show_login');die;
  788. }
  789. // 店铺关闭标志
  790. if (intval($this->store_info['store_state']) === 0) {
  791. Tpl::output('store_closed', true);
  792. Tpl::output('store_close_info', $this->store_info['store_close_info']);
  793. }
  794. // 店铺等级
  795. if (checkPlatformStore()) {
  796. $this->store_grade = array(
  797. 'sg_id' => '0',
  798. 'sg_name' => '自营店铺专属等级',
  799. 'sg_goods_limit' => '0',
  800. 'sg_album_limit' => '0',
  801. 'sg_space_limit' => '999999999',
  802. 'sg_template_number' => '6',
  803. // see also store_settingControl.themeOp()
  804. // 'sg_template' => 'default|style1|style2|style3|style4|style5',
  805. 'sg_price' => '0.00',
  806. 'sg_description' => '',
  807. 'sg_function' => 'editor_multimedia',
  808. 'sg_sort' => '0',
  809. );
  810. } else {
  811. $store_grade = rkcache('store_grade', true);
  812. $this->store_grade = $store_grade[$this->store_info['grade_id']];
  813. }
  814. if ($_SESSION['seller_is_admin'] !== 1 && $_GET['act'] !== 'seller_center' && $_GET['act'] !== 'seller_logout') {
  815. if (!in_array($_GET['act'], $_SESSION['seller_limits'])) {
  816. showMessage('没有权限', '', '', 'error');
  817. }
  818. }
  819. // 卖家菜单
  820. Tpl::output('menu', $_SESSION['seller_menu']);
  821. // 当前菜单
  822. $current_menu = $this->_getCurrentMenu($_SESSION['seller_function_list']);
  823. Tpl::output('current_menu', $current_menu);
  824. // 左侧菜单
  825. if($_GET['act'] == 'seller_center') {
  826. if(!empty($_SESSION['seller_quicklink'])) {
  827. $left_menu = array();
  828. foreach ($_SESSION['seller_quicklink'] as $value) {
  829. $left_menu[] = $_SESSION['seller_function_list'][$value];
  830. }
  831. }
  832. } else {
  833. $left_menu = $_SESSION['seller_menu'][$current_menu['model']]['child'];
  834. }
  835. Tpl::output('left_menu', $left_menu);
  836. Tpl::output('seller_quicklink', $_SESSION['seller_quicklink']);
  837. $this->checkStoreMsg();
  838. }
  839. }
  840. /**
  841. * 记录卖家日志
  842. *
  843. * @param $content 日志内容
  844. * @param $state 1成功 0失败
  845. */
  846. protected function recordSellerLog($content = '', $state = 1){
  847. $seller_info = array();
  848. $seller_info['log_content'] = $content;
  849. $seller_info['log_time'] = TIMESTAMP;
  850. $seller_info['log_seller_id'] = $_SESSION['seller_id'];
  851. $seller_info['log_seller_name'] = $_SESSION['seller_name'];
  852. $seller_info['log_store_id'] = $_SESSION['store_id'];
  853. $seller_info['log_seller_ip'] = getIp();
  854. $seller_info['log_url'] = $_GET['act'].'&'.$_GET['op'];
  855. $seller_info['log_state'] = $state;
  856. $model_seller_log = Model('seller_log');
  857. $model_seller_log->addSellerLog($seller_info);
  858. }
  859. /**
  860. * 记录店铺费用
  861. *
  862. * @param $cost_price 费用金额
  863. * @param $cost_remark 费用备注
  864. */
  865. protected function recordStoreCost($cost_price, $cost_remark) {
  866. // 平台店铺不记录店铺费用
  867. if (checkPlatformStore()) {
  868. return false;
  869. }
  870. $model_store_cost = Model('store_cost');
  871. $param = array();
  872. $param['cost_store_id'] = $_SESSION['store_id'];
  873. $param['cost_seller_id'] = $_SESSION['seller_id'];
  874. $param['cost_price'] = $cost_price;
  875. $param['cost_remark'] = $cost_remark;
  876. $param['cost_state'] = 0;
  877. $param['cost_time'] = TIMESTAMP;
  878. $model_store_cost->addStoreCost($param);
  879. // 发送店铺消息
  880. $param = array();
  881. $param['code'] = 'store_cost';
  882. $param['store_id'] = $_SESSION['store_id'];
  883. $param['param'] = array(
  884. 'price' => $cost_price,
  885. 'seller_name' => $_SESSION['seller_name'],
  886. 'remark' => $cost_remark
  887. );
  888. QueueClient::push('sendStoreMsg', $param);
  889. }
  890. protected function getSellerMenuList($is_admin, $limits) {
  891. $seller_menu = array();
  892. if (intval($is_admin) !== 1) {
  893. $menu_list = $this->_getMenuList();
  894. foreach ($menu_list as $key => $value) {
  895. foreach ($value['child'] as $child_key => $child_value) {
  896. if (!in_array($child_value['act'], $limits)) {
  897. unset($menu_list[$key]['child'][$child_key]);
  898. }
  899. }
  900. if(count($menu_list[$key]['child']) > 0) {
  901. $seller_menu[$key] = $menu_list[$key];
  902. }
  903. }
  904. } else {
  905. $seller_menu = $this->_getMenuList();
  906. }
  907. $seller_function_list = $this->_getSellerFunctionList($seller_menu);
  908. return array('seller_menu' => $seller_menu, 'seller_function_list' => $seller_function_list);
  909. }
  910. private function _getCurrentMenu($seller_function_list) {
  911. $current_menu = $seller_function_list[$_GET['act']];
  912. if(empty($current_menu)) {
  913. $current_menu = array(
  914. 'model' => 'index',
  915. 'model_name' => '首页'
  916. );
  917. }
  918. return $current_menu;
  919. }
  920. private function _getMenuList() {
  921. $menu_list = array(
  922. 'goods' => array('name' => '商品', 'child' => array(
  923. array('name' => '商品发布', 'act'=>'store_goods_add', 'op'=>'index'),
  924. array('name' => '淘宝导入', 'act'=>'taobao_import', 'op'=>'index'),
  925. array('name' => '出售中的商品', 'act'=>'store_goods_online', 'op'=>'index'),
  926. array('name' => '仓库中的商品', 'act'=>'store_goods_offline', 'op'=>'index'),
  927. array('name' => '关联版式', 'act'=>'store_plate', 'op'=>'index'),
  928. array('name' => '商品规格', 'act' => 'store_spec', 'op' => 'index'),
  929. array('name' => '图片空间', 'act'=>'store_album', 'op'=>'album_cate'),
  930. )),
  931. 'order' => array('name' => '订单物流', 'child' => array(
  932. array('name' => '实物交易订单', 'act'=>'store_order', 'op'=>'index'),
  933. array('name' => '虚拟兑码订单', 'act'=>'store_vr_order', 'op'=>'index'),
  934. array('name' => '发货', 'act'=>'store_deliver', 'op'=>'index'),
  935. array('name' => '发货设置', 'act'=>'store_deliver_set', 'op'=>'daddress_list'),
  936. array('name' => '运单模板', 'act'=>'store_waybill', 'op'=>'waybill_manage'),
  937. array('name' => '评价管理', 'act'=>'store_evaluate', 'op'=>'list'),
  938. array('name' => '物流工具', 'act'=>'store_transport', 'op'=>'index'),
  939. )),
  940. 'promotion' => array('name' => '促销', 'child' => array(
  941. array('name' => '抢购管理', 'act'=>'store_groupbuy', 'op'=>'index'),
  942. array('name' => '限时折扣', 'act'=>'store_promotion_xianshi', 'op'=>'xianshi_list'),
  943. array('name' => '满即送', 'act'=>'store_promotion_mansong', 'op'=>'mansong_list'),
  944. array('name' => '优惠套装', 'act'=>'store_promotion_bundling', 'op'=>'bundling_list'),
  945. array('name' => '推荐展位', 'act' => 'store_promotion_booth', 'op' => 'booth_goods_list'),
  946. array('name' => '代金券管理', 'act'=>'store_voucher', 'op'=>'templatelist'),
  947. array('name' => '活动管理', 'act'=>'store_activity', 'op'=>'store_activity'),
  948. )),
  949. 'store' => array('name' => '店铺', 'child' => array(
  950. array('name' => '店铺设置', 'act'=>'store_setting', 'op'=>'store_setting'),
  951. array('name' => '店铺装修', 'act'=>'store_decoration', 'op'=>'decoration_setting'),
  952. array('name' => '店铺导航', 'act'=>'store_navigation', 'op'=>'navigation_list'),
  953. array('name' => '店铺动态', 'act'=>'store_sns', 'op'=>'index'),
  954. array('name' => '店铺信息', 'act'=>'store_info', 'op'=>'bind_class'),
  955. array('name' => '店铺分类', 'act'=>'store_goods_class', 'op'=>'index'),
  956. array('name' => '线下商铺', 'act'=>'store_live', 'op'=>'store_live'),
  957. array('name' => '品牌申请', 'act'=>'store_brand', 'op'=>'brand_list'),
  958. )),
  959. 'consult' => array('name' => '售后服务', 'child' => array(
  960. array('name' => '咨询管理', 'act'=>'store_consult', 'op'=>'consult_list'),
  961. array('name' => '投诉管理', 'act'=>'store_complain', 'op'=>'list'),
  962. array('name' => '退款记录', 'act'=>'store_refund', 'op'=>'index'),
  963. array('name' => '退货记录', 'act'=>'store_return', 'op'=>'index'),
  964. )),
  965. 'statistics' => array('name' => '统计结算', 'child' => array(
  966. array('name' => '店铺概况', 'act'=>'statistics_general', 'op'=>'general'),
  967. array('name' => '商品分析', 'act'=>'statistics_goods', 'op'=>'goodslist'),
  968. array('name' => '运营报告', 'act'=>'statistics_sale', 'op'=>'sale'),
  969. array('name' => '行业分析', 'act'=>'statistics_industry', 'op'=>'hot'),
  970. array('name' => '流量统计', 'act'=>'statistics_flow', 'op'=>'storeflow'),
  971. array('name' => '实物结算', 'act'=>'store_bill', 'op'=>'index'),
  972. array('name' => '虚拟结算', 'act'=>'store_vr_bill', 'op'=>'index'),
  973. )),
  974. 'message' => array('name' => '客服消息', 'child' => array(
  975. array('name' => '客服设置', 'act'=>'store_callcenter', 'op'=>'index'),
  976. array('name' => '系统消息', 'act'=>'store_msg', 'op'=>'index'),
  977. array('name' => '聊天记录查询', 'act'=>'store_im', 'op'=>'index'),
  978. )),
  979. 'account' => array('name' => '账号', 'child' => array(
  980. array('name' => '账号列表', 'act'=>'store_account', 'op'=>'account_list'),
  981. array('name' => '账号组', 'act'=>'store_account_group', 'op'=>'group_list'),
  982. array('name' => '账号日志', 'act'=>'seller_log', 'op'=>'log_list'),
  983. array('name' => '店铺消费', 'act'=>'store_cost', 'op'=>'cost_list'),
  984. ))
  985. );
  986. return $menu_list;
  987. }
  988. private function _getSellerFunctionList($menu_list) {
  989. $format_menu = array();
  990. foreach ($menu_list as $key => $menu_value) {
  991. foreach ($menu_value['child'] as $submenu_value) {
  992. $format_menu[$submenu_value['act']] = array(
  993. 'model' => $key,
  994. 'model_name' => $menu_value['name'],
  995. 'name' => $submenu_value['name'],
  996. 'act' => $submenu_value['act'],
  997. 'op' => $submenu_value['op'],
  998. );
  999. }
  1000. }
  1001. return $format_menu;
  1002. }
  1003. /**
  1004. * 自动发布店铺动态
  1005. *
  1006. * @param array $data 相关数据
  1007. * @param string $type 类型 'new','coupon','xianshi','mansong','bundling','groupbuy'
  1008. * 所需字段
  1009. * new goods表' goods_id,store_id,goods_name,goods_image,goods_price,goods_transfee_charge,goods_freight
  1010. * xianshi p_xianshi_goods表' goods_id,store_id,goods_name,goods_image,goods_price,goods_freight,xianshi_price
  1011. * mansong p_mansong表' mansong_name,start_time,end_time,store_id
  1012. * bundling p_bundling表' bl_id,bl_name,bl_img,bl_discount_price,bl_freight_choose,bl_freight,store_id
  1013. * groupbuy goods_group表' group_id,group_name,goods_id,goods_price,groupbuy_price,group_pic,rebate,start_time,end_time
  1014. * coupon在后台发布
  1015. */
  1016. public function storeAutoShare($data, $type) {
  1017. $param = array(
  1018. 3 => 'new',
  1019. 4 => 'coupon',
  1020. 5 => 'xianshi',
  1021. 6 => 'mansong',
  1022. 7 => 'bundling',
  1023. 8 => 'groupbuy'
  1024. );
  1025. $param_flip = array_flip($param);
  1026. if (!in_array($type, $param) || empty($data)) {
  1027. return false;
  1028. }
  1029. $auto_setting = Model('store_sns_setting')->getStoreSnsSettingInfo(array('sauto_storeid' => $_SESSION ['store_id']));
  1030. $auto_sign = false; // 自动发布开启标志
  1031. if ($auto_setting['sauto_' . $type] == 1) {
  1032. $auto_sign = true;
  1033. if (CHARSET == 'GBK') {
  1034. foreach ((array)$data as $k => $v) {
  1035. $data[$k] = Language::getUTF8($v);
  1036. }
  1037. }
  1038. $goodsdata = addslashes(json_encode($data));
  1039. if ($auto_setting['sauto_' . $type . 'title'] != '') {
  1040. $title = $auto_setting['sauto_' . $type . 'title'];
  1041. } else {
  1042. $auto_title = 'nc_store_auto_share_' . $type . rand(1, 5);
  1043. $title = Language::get($auto_title);
  1044. }
  1045. }
  1046. if ($auto_sign) {
  1047. // 插入数据
  1048. $stracelog_array = array();
  1049. $stracelog_array['strace_storeid'] = $this->store_info['store_id'];
  1050. $stracelog_array['strace_storename'] = $this->store_info['store_name'];
  1051. $stracelog_array['strace_storelogo'] = empty($this->store_info['store_avatar']) ? '' : $this->store_info['store_avatar'];
  1052. $stracelog_array['strace_title'] = $title;
  1053. $stracelog_array['strace_content'] = '';
  1054. $stracelog_array['strace_time'] = TIMESTAMP;
  1055. $stracelog_array['strace_type'] = $param_flip[$type];
  1056. $stracelog_array['strace_goodsdata'] = $goodsdata;
  1057. Model('store_sns_tracelog')->saveStoreSnsTracelog($stracelog_array);
  1058. return true;
  1059. } else {
  1060. return false;
  1061. }
  1062. }
  1063. /**
  1064. * 商家消息数量
  1065. */
  1066. private function checkStoreMsg() {//判断cookie是否存在
  1067. $cookie_name = 'storemsgnewnum'.$_SESSION['seller_id'];
  1068. if (cookie($cookie_name) != null && intval(cookie($cookie_name)) >=0){
  1069. $countnum = intval(cookie($cookie_name));
  1070. }else {
  1071. $where = array();
  1072. $where['store_id'] = $_SESSION['store_id'];
  1073. $where['sm_readids'] = array('notlike', '%,'.$_SESSION['seller_id'].',%');
  1074. if ($_SESSION['seller_smt_limits'] !== false) {
  1075. $where['smt_code'] = array('in', $_SESSION['seller_smt_limits']);
  1076. }
  1077. $countnum = Model('store_msg')->getStoreMsgCount($where);
  1078. setNcCookie($cookie_name,intval($countnum),2*3600);//保存2小时
  1079. }
  1080. Tpl::output('store_msg_num',$countnum);
  1081. }
  1082. }
  1083. class BaseStoreSnsControl extends Control {
  1084. const MAX_RECORDNUM = 20; // 允许插入新记录的最大次数,sns页面该常量是一样的。
  1085. public function __construct(){
  1086. Language::read('common,store_layout');
  1087. Tpl::output('max_recordnum', self::MAX_RECORDNUM);
  1088. Tpl::setDir('store');
  1089. Tpl::setLayout('store_layout');
  1090. // 自定义导航条
  1091. $this->getStoreNavigation();
  1092. //输出头部的公用信息
  1093. $this->showLayout();
  1094. //查询会员信息
  1095. $this->getMemberAndGradeInfo(false);
  1096. }
  1097. // 自定义导航条
  1098. protected function getStoreNavigation() {
  1099. $model_store_navigation = Model('store_navigation');
  1100. $store_navigation_list = $model_store_navigation->getStoreNavigationList(array('sn_store_id' => $_GET['sid']));
  1101. Tpl::output('store_navigation_list', $store_navigation_list);
  1102. }
  1103. protected function getStoreInfo($store_id) {
  1104. //得到店铺等级信息
  1105. $store_info = Model('store')->getStoreInfoByID($store_id);
  1106. if (empty($store_info)) {
  1107. showMessage(Language::get('store_sns_store_not_exists'),'','html','error');
  1108. }
  1109. //处理地区信息
  1110. $area_array = array();
  1111. $area_array = explode("\t",$store_info["area_info"]);
  1112. $map_city = Language::get('store_sns_city');
  1113. $city = '';
  1114. if(strpos($area_array[0], $map_city) !== false){
  1115. $city = $area_array[0];
  1116. }else {
  1117. $city = $area_array[1];
  1118. }
  1119. $store_info['city'] = $city;
  1120. Tpl::output('store_theme', $store_info['store_theme']);
  1121. Tpl::output('store_info', $store_info);
  1122. }
  1123. }
  1124. /**
  1125. * 积分中心control父类
  1126. */
  1127. class BasePointShopControl extends Control {
  1128. protected $member_info;
  1129. public function __construct(){
  1130. Language::read('common,home_layout');
  1131. //输出头部的公用信息
  1132. $this->showLayout();
  1133. //输出会员信息
  1134. $this->member_info = $this->getMemberAndGradeInfo(true);
  1135. Tpl::output('member_info',$this->member_info);
  1136. Tpl::setDir('home');
  1137. Tpl::setLayout('home_layout');
  1138. if ($_GET['column'] && strtoupper(CHARSET) == 'GBK'){
  1139. $_GET = Language::getGBK($_GET);
  1140. }
  1141. if(!C('site_status')) halt(C('closed_reason'));
  1142. //判断系统是否开启积分和积分中心功能
  1143. if (C('points_isuse') != 1 || C('pointshop_isuse') != 1){
  1144. showMessage(Language::get('pointshop_unavailable'),urlShop('index','index'),'html','error');
  1145. }
  1146. Tpl::output('index_sign','pointshop');
  1147. }
  1148. /**
  1149. * 获得积分中心会员信息包括会员名、ID、会员头像、会员等级、经验值、等级进度、积分、已领代金券、已兑换礼品、礼品购物车
  1150. */
  1151. public function pointshopMInfo($is_return = false){
  1152. if($_SESSION['is_login'] == '1'){
  1153. $model_member = Model('member');
  1154. if (!$this->member_info){
  1155. //查询会员信息
  1156. $member_infotmp = $model_member->getMemberInfoByID($_SESSION['member_id']);
  1157. } else {
  1158. $member_infotmp = $this->member_info;
  1159. }
  1160. $member_infotmp['member_exppoints'] = intval($member_infotmp['member_exppoints']);
  1161. //当前登录会员等级信息
  1162. $membergrade_info = $model_member->getOneMemberGrade($member_infotmp['member_exppoints'],true);
  1163. $member_info = array_merge($member_infotmp,$membergrade_info);
  1164. Tpl::output('member_info',$member_info);
  1165. //查询已兑换并可以使用的代金券数量
  1166. $model_voucher = Model('voucher');
  1167. $vouchercount = $model_voucher->getCurrentAvailableVoucherCount($_SESSION['member_id']);
  1168. Tpl::output('vouchercount',$vouchercount);
  1169. //购物车兑换商品数
  1170. $pointcart_count = Model('pointcart')->countPointCart($_SESSION['member_id']);
  1171. Tpl::output('pointcart_count',$pointcart_count);
  1172. //查询已兑换商品数(未取消订单)
  1173. $pointordercount = Model('pointorder')->getMemberPointsOrderGoodsCount($_SESSION['member_id']);
  1174. Tpl::output('pointordercount',$pointordercount);
  1175. if ($is_return){
  1176. return array('member_info'=>$member_info,'vouchercount'=>$vouchercount,'pointcart_count'=>$pointcart_count,'pointordercount'=>$pointordercount);
  1177. }
  1178. }
  1179. }
  1180. }