人人商城

menu.mod.php 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. function menu_languages() {
  8. $languages = array(
  9. array('ch'=>'简体中文', 'en'=>'zh_CN'),
  10. array('ch'=>'繁体中文TW', 'en'=>'zh_TW'),
  11. array('ch'=>'繁体中文HK', 'en'=>'zh_HK'),
  12. array('ch'=>'英文', 'en'=>'en'),
  13. array('ch'=>'印尼', 'en'=>'id'),
  14. array('ch'=>'马来', 'en'=>'ms'),
  15. array('ch'=>'西班牙', 'en'=>'es'),
  16. array('ch'=>'韩国', 'en'=>'ko'),
  17. array('ch'=>'意大利 ', 'en'=>'it'),
  18. array('ch'=>'日本', 'en'=>'ja'),
  19. array('ch'=>'波兰', 'en'=>'pl'),
  20. array('ch'=>'葡萄牙', 'en'=>'pt'),
  21. array('ch'=>'俄国', 'en'=>'ru'),
  22. array('ch'=>'泰文', 'en'=>'th'),
  23. array('ch'=>'越南', 'en'=>'vi'),
  24. array('ch'=>'阿拉伯语', 'en'=>'ar'),
  25. array('ch'=>'北印度', 'en'=>'hi'),
  26. array('ch'=>'希伯来', 'en'=>'he'),
  27. array('ch'=>'土耳其', 'en'=>'tr'),
  28. array('ch'=>'德语', 'en'=>'de'),
  29. array('ch'=>'法语', 'en'=>'fr')
  30. );
  31. return $languages;
  32. }
  33. function menu_get($id) {
  34. global $_W;
  35. $id = intval($id);
  36. if (empty($id)) {
  37. return array();
  38. }
  39. $menu_info = table('menu')->accountMenuInfo(array('id' => $id));
  40. if (!empty($menu_info)) {
  41. return $menu_info;
  42. } else {
  43. return array();
  44. }
  45. }
  46. function menu_default() {
  47. $result = array();
  48. $result = table('menu')->accountDefaultMenuInfo();
  49. return $result;
  50. }
  51. function menu_update_currentself() {
  52. global $_W;
  53. $account_api = WeAccount::createByUniacid();
  54. $default_menu_info = $account_api->menuCurrentQuery();
  55. if (is_error($default_menu_info)) {
  56. return error(-1, $default_menu_info['message']);
  57. }
  58. if ($account_api->type != ACCOUNT_TYPE_XZAPP_NORMAL && $account_api->type != ACCOUNT_TYPE_XZAPP_AUTH) {
  59. if (empty($default_menu_info['is_menu_open']) || empty($default_menu_info['selfmenu_info'])) {
  60. return true;
  61. }
  62. $default_menu = $default_menu_info['selfmenu_info'];
  63. } else {
  64. $default_menu = $default_menu_info['menu'];
  65. }
  66. $default_sub_button = array();
  67. if (!empty($default_menu['button'])) {
  68. foreach ($default_menu['button'] as $key => &$button) {
  69. if (!empty($button['sub_button'])) {
  70. $default_sub_button[$key] = $button['sub_button'];
  71. } else {
  72. unset($button['sub_button']);
  73. }
  74. ksort($button);
  75. }
  76. unset($button);
  77. }
  78. ksort($default_menu);
  79. $wechat_menu_data = base64_encode(iserializer($default_menu));
  80. $all_default_menus = table('menu')->searchAccountMenuList(MENU_CURRENTSELF);
  81. if (!empty($all_default_menus)) {
  82. foreach ($all_default_menus as $menus_key => $menu_data) {
  83. if (empty($menu_data['data'])) {
  84. continue;
  85. }
  86. $single_menu_info = iunserializer(base64_decode($menu_data['data']));
  87. if (!is_array($single_menu_info) || empty($single_menu_info['button'])) {
  88. continue;
  89. }
  90. foreach ($single_menu_info['button'] as $key => &$single_button) {
  91. if (!empty($default_sub_button[$key])) {
  92. $single_button['sub_button'] = $default_sub_button[$key];
  93. } else {
  94. unset($single_button['sub_button']);
  95. }
  96. ksort($single_button);
  97. }
  98. unset($single_button);
  99. ksort($single_menu_info);
  100. $local_menu_data = base64_encode(iserializer($single_menu_info));
  101. if ($wechat_menu_data == $local_menu_data) {
  102. $default_menu_id = $menus_key;
  103. }
  104. }
  105. }
  106. if (!empty($default_menu_id)) {
  107. pdo_update('uni_account_menus', array('status' => STATUS_ON), array('id' => $default_menu_id));
  108. pdo_update('uni_account_menus', array('status' => STATUS_OFF), array('uniacid' => $_W['uniacid'], 'type' => MENU_CURRENTSELF, 'id !=' => $default_menu_id));
  109. } else {
  110. $insert_data = array(
  111. 'uniacid' => $_W['uniacid'],
  112. 'type' => MENU_CURRENTSELF,
  113. 'group_id' => -1,
  114. 'sex' => 0,
  115. 'data' => $wechat_menu_data,
  116. 'client_platform_type' => 0,
  117. 'area' => '',
  118. 'menuid' => 0,
  119. 'status' => STATUS_ON
  120. );
  121. pdo_insert('uni_account_menus', $insert_data);
  122. $insert_id = pdo_insertid();
  123. pdo_update('uni_account_menus', array('title' => '默认菜单_'.$insert_id), array('id' => $insert_id));
  124. pdo_update('uni_account_menus', array('status' => STATUS_OFF), array('uniacid' => $_W['uniacid'], 'type' => MENU_CURRENTSELF, 'id !=' => $insert_id));
  125. }
  126. return true;
  127. }
  128. function menu_update_conditional() {
  129. global $_W;
  130. $account_api = WeAccount::createByUniacid();
  131. $conditional_menu_info = $account_api->menuQuery();
  132. if (is_error($conditional_menu_info)) {
  133. return error(-1, $conditional_menu_info['message']);
  134. }
  135. pdo_update('uni_account_menus', array('status' => STATUS_OFF), array('uniacid' => $_W['uniacid'], 'type' => MENU_CONDITIONAL));
  136. if (!empty($conditional_menu_info['conditionalmenu'])) {
  137. foreach ($conditional_menu_info['conditionalmenu'] as $menu) {
  138. $data = array(
  139. 'uniacid' => $_W['uniacid'],
  140. 'type' => MENU_CONDITIONAL,
  141. 'group_id' => isset($menu['matchrule']['tag_id']) ? $menu['matchrule']['tag_id'] : (isset($menu['matchrule']['group_id']) ? $menu['matchrule']['group_id'] : '-1'),
  142. 'sex' => $menu['matchrule']['sex'],
  143. 'client_platform_type' => $menu['matchrule']['client_platform_type'],
  144. 'area' => trim($menu['matchrule']['country']) . trim($menu['matchrule']['province']) . trim($menu['matchrule']['city']),
  145. 'data' => base64_encode(iserializer($menu)),
  146. 'menuid' => $menu['menuid'],
  147. 'status' => STATUS_ON,
  148. );
  149. if (!empty($menu['matchrule'])) {
  150. $menu_info = table('menu')->accountMenuInfo(array('uniacid' => $_W['uniacid'], 'menuid' => $menu['menuid'], 'type' => MENU_CONDITIONAL));
  151. $menu_id = $menu_info['id'];
  152. }
  153. if (!empty($menu_id)) {
  154. $data['title'] = !empty($menu_info['title']) ? $menu_info['title'] : '个性化菜单_' . $menu_id;
  155. pdo_update('uni_account_menus', $data, array('uniacid' => $_W['uniacid'], 'id' => $menu_id));
  156. } else {
  157. pdo_insert('uni_account_menus', $data);
  158. $insert_id = pdo_insertid();
  159. pdo_update('uni_account_menus', array('title' => '个性化菜单_'.$insert_id), array('id' => $insert_id));
  160. }
  161. }
  162. }
  163. return true;
  164. }
  165. function menu_delete($id) {
  166. global $_W;
  167. $menu_info = menu_get($id);
  168. if (empty($menu_info)) {
  169. return error(-1, '菜单不存在或已经删除');
  170. }
  171. if ($menu_info['status'] == STATUS_OFF) {
  172. pdo_delete('uni_account_menus', array('uniacid' => $_W['uniacid'], 'id' => $id));
  173. return error(0, '删除菜单成功!');
  174. }
  175. if ($menu_info['type'] == MENU_CONDITIONAL && $menu_info['menuid'] > 0 && $menu_info['status'] != STATUS_OFF) {
  176. $account_api = WeAccount::createByUniacid();
  177. $result = $account_api->menuDelete($menu_info['menuid']);
  178. if (is_error($result)) {
  179. return error(-1, $result['message']);
  180. }
  181. pdo_delete('uni_account_menus', array('uniacid' => $_W['uniacid'], 'id' => $id));
  182. }
  183. return true;
  184. }
  185. function menu_push($id) {
  186. global $_W;
  187. $menu_info = menu_get($id);
  188. if (empty($menu_info)) {
  189. return error(-1, '菜单不存在或已删除');
  190. }
  191. if ($menu_info['status'] == STATUS_OFF) {
  192. $post = iunserializer(base64_decode($menu_info['data']));
  193. if (empty($post)) {
  194. return error(-1, '菜单数据错误');
  195. }
  196. $is_conditional = (!empty($post['matchrule']) && $menu_info['type'] == MENU_CONDITIONAL) ? true : false;
  197. $account_api = WeAccount::createByUniacid();
  198. $menu = $account_api->menuBuild($post, $is_conditional);
  199. $result = $account_api->menuCreate($menu);
  200. if (is_error($result)) {
  201. return error(-1, $result['message']);
  202. }
  203. if ($menu_info['type'] == MENU_CURRENTSELF) {
  204. pdo_update('uni_account_menus', array('status' => '1'), array('id' => $menu_info['id']));
  205. pdo_update('uni_account_menus', array('status' => '0'), array('id !=' => $menu_info['id'], 'uniacid' => $_W['uniacid'], 'type' => MENU_CURRENTSELF));
  206. } elseif ($menu_info['type'] == MENU_CONDITIONAL) {
  207. if ($post['matchrule']['group_id'] != -1) {
  208. $menu['matchrule']['groupid'] = $menu['matchrule']['tag_id'];
  209. unset($menu['matchrule']['tag_id']);
  210. }
  211. $status = pdo_update('uni_account_menus', array('status' => STATUS_ON, 'menuid' => $result), array('uniacid' => $_W['uniacid'], 'id' => $menu_info['id']));
  212. }
  213. return true;
  214. }
  215. if ($menu_info['status'] == STATUS_ON && $menu_info['type'] == MENU_CONDITIONAL && $menu_info['menuid'] > 0) {
  216. $account_api = WeAccount::createByUniacid();
  217. $result = $account_api->menuDelete($menu_info['menuid']);
  218. if (is_error($result)) {
  219. return error(-1, $result['message']);
  220. } else {
  221. pdo_update('uni_account_menus', array('status' => STATUS_OFF), array('id' => $menu_info['id']));
  222. return true;
  223. }
  224. }
  225. }