menu.mod.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. if (!empty($default_menu)) {
  79. ksort($default_menu);
  80. }
  81. $wechat_menu_data = base64_encode(iserializer($default_menu));
  82. $all_default_menus = table('menu')->searchAccountMenuList(MENU_CURRENTSELF);
  83. if (!empty($all_default_menus)) {
  84. foreach ($all_default_menus as $menus_key => $menu_data) {
  85. if (empty($menu_data['data'])) {
  86. continue;
  87. }
  88. $single_menu_info = iunserializer(base64_decode($menu_data['data']));
  89. if (!is_array($single_menu_info) || empty($single_menu_info['button'])) {
  90. continue;
  91. }
  92. foreach ($single_menu_info['button'] as $key => &$single_button) {
  93. if (!empty($default_sub_button[$key])) {
  94. $single_button['sub_button'] = $default_sub_button[$key];
  95. } else {
  96. unset($single_button['sub_button']);
  97. }
  98. ksort($single_button);
  99. }
  100. unset($single_button);
  101. ksort($single_menu_info);
  102. $local_menu_data = base64_encode(iserializer($single_menu_info));
  103. if ($wechat_menu_data == $local_menu_data) {
  104. $default_menu_id = $menus_key;
  105. }
  106. }
  107. }
  108. if (!empty($default_menu_id)) {
  109. pdo_update('uni_account_menus', array('status' => STATUS_ON), array('id' => $default_menu_id));
  110. pdo_update('uni_account_menus', array('status' => STATUS_OFF), array('uniacid' => $_W['uniacid'], 'type' => MENU_CURRENTSELF, 'id !=' => $default_menu_id));
  111. } else {
  112. $insert_data = array(
  113. 'uniacid' => $_W['uniacid'],
  114. 'type' => MENU_CURRENTSELF,
  115. 'group_id' => -1,
  116. 'sex' => 0,
  117. 'data' => $wechat_menu_data,
  118. 'client_platform_type' => 0,
  119. 'area' => '',
  120. 'menuid' => 0,
  121. 'status' => STATUS_ON
  122. );
  123. pdo_insert('uni_account_menus', $insert_data);
  124. $insert_id = pdo_insertid();
  125. pdo_update('uni_account_menus', array('title' => '默认菜单_'.$insert_id), array('id' => $insert_id));
  126. pdo_update('uni_account_menus', array('status' => STATUS_OFF), array('uniacid' => $_W['uniacid'], 'type' => MENU_CURRENTSELF, 'id !=' => $insert_id));
  127. }
  128. return true;
  129. }
  130. function menu_update_conditional() {
  131. global $_W;
  132. $account_api = WeAccount::createByUniacid();
  133. $conditional_menu_info = $account_api->menuQuery();
  134. if (is_error($conditional_menu_info)) {
  135. return error(-1, $conditional_menu_info['message']);
  136. }
  137. pdo_update('uni_account_menus', array('status' => STATUS_OFF), array('uniacid' => $_W['uniacid'], 'type' => MENU_CONDITIONAL));
  138. if (!empty($conditional_menu_info['conditionalmenu'])) {
  139. foreach ($conditional_menu_info['conditionalmenu'] as $menu) {
  140. $data = array(
  141. 'uniacid' => $_W['uniacid'],
  142. 'type' => MENU_CONDITIONAL,
  143. 'group_id' => isset($menu['matchrule']['tag_id']) ? $menu['matchrule']['tag_id'] : (isset($menu['matchrule']['group_id']) ? $menu['matchrule']['group_id'] : '-1'),
  144. 'sex' => $menu['matchrule']['sex'],
  145. 'client_platform_type' => $menu['matchrule']['client_platform_type'],
  146. 'area' => trim($menu['matchrule']['country']) . trim($menu['matchrule']['province']) . trim($menu['matchrule']['city']),
  147. 'data' => base64_encode(iserializer($menu)),
  148. 'menuid' => $menu['menuid'],
  149. 'status' => STATUS_ON,
  150. );
  151. if (!empty($menu['matchrule'])) {
  152. $menu_info = table('menu')->accountMenuInfo(array('uniacid' => $_W['uniacid'], 'menuid' => $menu['menuid'], 'type' => MENU_CONDITIONAL));
  153. $menu_id = $menu_info['id'];
  154. }
  155. if (!empty($menu_id)) {
  156. $data['title'] = !empty($menu_info['title']) ? $menu_info['title'] : '个性化菜单_' . $menu_id;
  157. pdo_update('uni_account_menus', $data, array('uniacid' => $_W['uniacid'], 'id' => $menu_id));
  158. } else {
  159. pdo_insert('uni_account_menus', $data);
  160. $insert_id = pdo_insertid();
  161. pdo_update('uni_account_menus', array('title' => '个性化菜单_'.$insert_id), array('id' => $insert_id));
  162. }
  163. }
  164. }
  165. return true;
  166. }
  167. function menu_delete($id) {
  168. global $_W;
  169. $menu_info = menu_get($id);
  170. if (empty($menu_info)) {
  171. return error(-1, '菜单不存在或已经删除');
  172. }
  173. if ($menu_info['status'] == STATUS_OFF) {
  174. pdo_delete('uni_account_menus', array('uniacid' => $_W['uniacid'], 'id' => $id));
  175. return error(0, '删除菜单成功!');
  176. }
  177. if ($menu_info['type'] == MENU_CONDITIONAL && $menu_info['menuid'] > 0 && $menu_info['status'] != STATUS_OFF) {
  178. $account_api = WeAccount::createByUniacid();
  179. $result = $account_api->menuDelete($menu_info['menuid']);
  180. if (is_error($result)) {
  181. return error(-1, $result['message']);
  182. }
  183. pdo_delete('uni_account_menus', array('uniacid' => $_W['uniacid'], 'id' => $id));
  184. }
  185. return true;
  186. }
  187. function menu_push($id) {
  188. global $_W;
  189. $menu_info = menu_get($id);
  190. if (empty($menu_info)) {
  191. return error(-1, '菜单不存在或已删除');
  192. }
  193. if ($menu_info['status'] == STATUS_OFF) {
  194. $post = iunserializer(base64_decode($menu_info['data']));
  195. if (empty($post)) {
  196. return error(-1, '菜单数据错误');
  197. }
  198. $is_conditional = (!empty($post['matchrule']) && $menu_info['type'] == MENU_CONDITIONAL) ? true : false;
  199. $account_api = WeAccount::createByUniacid();
  200. $menu = $account_api->menuBuild($post, $is_conditional);
  201. $result = $account_api->menuCreate($menu);
  202. if (is_error($result)) {
  203. return error(-1, $result['message']);
  204. }
  205. if ($menu_info['type'] == MENU_CURRENTSELF) {
  206. pdo_update('uni_account_menus', array('status' => '1'), array('id' => $menu_info['id']));
  207. pdo_update('uni_account_menus', array('status' => '0'), array('id !=' => $menu_info['id'], 'uniacid' => $_W['uniacid'], 'type' => MENU_CURRENTSELF));
  208. } elseif ($menu_info['type'] == MENU_CONDITIONAL) {
  209. if ($post['matchrule']['group_id'] != -1) {
  210. $menu['matchrule']['groupid'] = $menu['matchrule']['tag_id'];
  211. unset($menu['matchrule']['tag_id']);
  212. }
  213. $status = pdo_update('uni_account_menus', array('status' => STATUS_ON, 'menuid' => $result), array('uniacid' => $_W['uniacid'], 'id' => $menu_info['id']));
  214. }
  215. return true;
  216. }
  217. if ($menu_info['status'] == STATUS_ON && $menu_info['type'] == MENU_CONDITIONAL && $menu_info['menuid'] > 0) {
  218. $account_api = WeAccount::createByUniacid();
  219. $result = $account_api->menuDelete($menu_info['menuid']);
  220. if (is_error($result)) {
  221. return error(-1, $result['message']);
  222. } else {
  223. pdo_update('uni_account_menus', array('status' => STATUS_OFF), array('id' => $menu_info['id']));
  224. return true;
  225. }
  226. }
  227. }