account.mod.php 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327
  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 uni_account_type_sign($type_sign = '') {
  8. $all_account_type_sign = array(
  9. ACCOUNT_TYPE_SIGN => array(
  10. 'contain_type' => array(ACCOUNT_TYPE_OFFCIAL_NORMAL, ACCOUNT_TYPE_OFFCIAL_AUTH),
  11. 'level' => array(ACCOUNT_SUBSCRIPTION => '订阅号', ACCOUNT_SERVICE => '服务号', ACCOUNT_SUBSCRIPTION_VERIFY => '认证订阅号', ACCOUNT_SERVICE_VERIFY => '认证服务号'),
  12. 'jointype' => array(ACCOUNT_TYPE_OFFCIAL_NORMAL => '普通接入', ACCOUNT_TYPE_OFFCIAL_AUTH => '授权接入'),
  13. 'icon' => 'wi wi-wx-circle',
  14. 'createurl' => url('account/post-step'),
  15. 'title' => '公众号',
  16. ),
  17. WXAPP_TYPE_SIGN => array(
  18. 'contain_type' => array(ACCOUNT_TYPE_APP_NORMAL, ACCOUNT_TYPE_APP_AUTH),
  19. 'level' => array(),
  20. 'jointype' => array(ACCOUNT_TYPE_APP_NORMAL => '普通接入', ACCOUNT_TYPE_APP_AUTH => '授权接入'),
  21. 'icon' => 'wi wi-wxapp',
  22. 'createurl' => url('wxapp/post/design_method'),
  23. 'title' => '微信小程序',
  24. ),
  25. WEBAPP_TYPE_SIGN => array(
  26. 'contain_type' => array(ACCOUNT_TYPE_WEBAPP_NORMAL),
  27. 'level' => array(),
  28. 'icon' => 'wi wi-pc-circle',
  29. 'createurl' => url('account/create', array('sign' => 'webapp')),
  30. 'title' => 'PC',
  31. ),
  32. PHONEAPP_TYPE_SIGN => array(
  33. 'contain_type' => array(ACCOUNT_TYPE_PHONEAPP_NORMAL),
  34. 'level' => array(),
  35. 'icon' => 'wi wi-app',
  36. 'createurl' => url('account/create', array('sign' => 'phoneapp')),
  37. 'title' => 'APP',
  38. ),
  39. ALIAPP_TYPE_SIGN => array(
  40. 'contain_type' => array(ACCOUNT_TYPE_ALIAPP_NORMAL),
  41. 'level' => array(),
  42. 'icon' => 'wi wi-aliapp',
  43. 'createurl' => url('account/create', array('sign' => 'aliapp')),
  44. 'title' => '支付宝小程序',
  45. ),
  46. BAIDUAPP_TYPE_SIGN => array(
  47. 'contain_type' => array(ACCOUNT_TYPE_BAIDUAPP_NORMAL),
  48. 'level' => array(),
  49. 'icon' => 'wi wi-baiduapp',
  50. 'createurl' => url('account/create', array('sign' => 'baiduapp')),
  51. 'title' => '百度小程序',
  52. ),
  53. TOUTIAOAPP_TYPE_SIGN => array(
  54. 'contain_type' => array(ACCOUNT_TYPE_TOUTIAOAPP_NORMAL),
  55. 'level' => array(),
  56. 'icon' => 'wi wi-toutiaoapp',
  57. 'createurl' => url('account/create', array('sign' => 'toutiaoapp')),
  58. 'title' => '抖音小程序',
  59. ),
  60. );
  61. if (!empty($type_sign)) {
  62. return !empty($all_account_type_sign[$type_sign]) ? $all_account_type_sign[$type_sign] : array();
  63. }
  64. return $all_account_type_sign;
  65. }
  66. function uni_account_type($type = 0) {
  67. $all_account_type = array(
  68. ACCOUNT_TYPE_OFFCIAL_NORMAL => array(
  69. 'title' => '公众号',
  70. 'type_sign' => ACCOUNT_TYPE_SIGN,
  71. 'table_name' => 'account_wechats',
  72. 'module_support_name' => MODULE_SUPPORT_ACCOUNT_NAME,
  73. 'module_support_value' => MODULE_SUPPORT_ACCOUNT,
  74. ),
  75. ACCOUNT_TYPE_OFFCIAL_AUTH => array(
  76. 'title' => '公众号',
  77. 'type_sign' => ACCOUNT_TYPE_SIGN,
  78. 'table_name' => 'account_wechats',
  79. 'module_support_name' => MODULE_SUPPORT_ACCOUNT_NAME,
  80. 'module_support_value' => MODULE_SUPPORT_ACCOUNT,
  81. ),
  82. ACCOUNT_TYPE_APP_NORMAL => array(
  83. 'title' => '微信小程序',
  84. 'type_sign' => WXAPP_TYPE_SIGN,
  85. 'table_name' => 'account_wxapp',
  86. 'support_version' => 1,
  87. 'version_tablename' => 'wxapp_versions',
  88. 'module_support_name' => MODULE_SUPPORT_WXAPP_NAME,
  89. 'module_support_value' => MODULE_SUPPORT_WXAPP,
  90. ),
  91. ACCOUNT_TYPE_APP_AUTH => array(
  92. 'title' => '微信小程序',
  93. 'type_sign' => WXAPP_TYPE_SIGN,
  94. 'table_name' => 'account_wxapp',
  95. 'support_version' => 1,
  96. 'version_tablename' => 'wxapp_versions',
  97. 'module_support_name' => MODULE_SUPPORT_WXAPP_NAME,
  98. 'module_support_value' => MODULE_SUPPORT_WXAPP,
  99. ),
  100. ACCOUNT_TYPE_WEBAPP_NORMAL => array(
  101. 'title' => 'PC',
  102. 'type_sign' => WEBAPP_TYPE_SIGN,
  103. 'table_name' => 'account_webapp',
  104. 'module_support_name' => MODULE_SUPPORT_WEBAPP_NAME,
  105. 'module_support_value' => MODULE_SUPPORT_WEBAPP,
  106. ),
  107. ACCOUNT_TYPE_PHONEAPP_NORMAL => array(
  108. 'title' => 'APP',
  109. 'type_sign' => PHONEAPP_TYPE_SIGN,
  110. 'table_name' => 'account_phoneapp',
  111. 'support_version' => 1,
  112. 'version_tablename' => 'wxapp_versions',
  113. 'module_support_name' => MODULE_SUPPORT_PHONEAPP_NAME,
  114. 'module_support_value' => MODULE_SUPPORT_PHONEAPP,
  115. ),
  116. ACCOUNT_TYPE_ALIAPP_NORMAL => array(
  117. 'title' => '支付宝小程序',
  118. 'type_sign' => ALIAPP_TYPE_SIGN,
  119. 'table_name' => 'account_aliapp',
  120. 'support_version' => 1,
  121. 'version_tablename' => 'wxapp_versions',
  122. 'module_support_name' => MODULE_SUPPORT_ALIAPP_NAME,
  123. 'module_support_value' => MODULE_SUPPORT_ALIAPP,
  124. ),
  125. ACCOUNT_TYPE_BAIDUAPP_NORMAL => array(
  126. 'title' => '百度小程序',
  127. 'type_sign' => BAIDUAPP_TYPE_SIGN,
  128. 'table_name' => 'account_baiduapp',
  129. 'support_version' => 1,
  130. 'version_tablename' => 'wxapp_versions',
  131. 'module_support_name' => MODULE_SUPPORT_BAIDUAPP_NAME,
  132. 'module_support_value' => MODULE_SUPPORT_BAIDUAPP,
  133. ),
  134. ACCOUNT_TYPE_TOUTIAOAPP_NORMAL => array(
  135. 'title' => '抖音小程序',
  136. 'type_sign' => TOUTIAOAPP_TYPE_SIGN,
  137. 'table_name' => 'account_toutiaoapp',
  138. 'support_version' => 1,
  139. 'version_tablename' => 'wxapp_versions',
  140. 'module_support_name' => MODULE_SUPPORT_TOUTIAOAPP_NAME,
  141. 'module_support_value' => MODULE_SUPPORT_TOUTIAOAPP,
  142. ),
  143. );
  144. if (!empty($type)) {
  145. return !empty($all_account_type[$type]) ? $all_account_type[$type] : array();
  146. }
  147. return $all_account_type;
  148. }
  149. function uni_need_account_info() {
  150. global $controller, $action, $do, $_GPC;
  151. $module_name = empty($_GPC['module_name']) ? '' : safe_gpc_string($_GPC['module_name']);
  152. $system_welcome = empty($_GPC['system_welcome']) ? '' : safe_gpc_string($_GPC['system_welcome']);
  153. $module_type = empty($_GPC['module_type']) ? '' : safe_gpc_string($_GPC['module_type']);
  154. if (defined('FRAME') && in_array(FRAME, array('account', 'wxapp')) && !$system_welcome && $module_type != 'system_welcome') {
  155. if ('site' == $controller && 'entry' == $action) {
  156. $eid = !empty($_GPC['eid']) ? intval($_GPC['eid']) : 0;
  157. if (!empty($eid)) {
  158. $entry = module_entry($eid);
  159. } else {
  160. $entry_module_name = $module_name ? $module_name : safe_gpc_string($_GPC['m']);
  161. $entry = table('modules_bindings')
  162. ->where(array(
  163. 'module' => $entry_module_name,
  164. 'do' => $do
  165. ))
  166. ->get();
  167. if (empty($entry)) {
  168. $entry = array(
  169. 'module' => $entry_module_name,
  170. 'do' => safe_gpc_string($_GPC['do']),
  171. 'state' => safe_gpc_string($_GPC['state']),
  172. 'direct' => safe_gpc_string($_GPC['direct']),
  173. );
  174. }
  175. }
  176. if ($entry['direct']) {
  177. return false;
  178. }
  179. }
  180. return true;
  181. }
  182. if ($controller == 'miniapp') {
  183. if ($action == 'version' && $do == 'display') {
  184. return true;
  185. }
  186. }
  187. return false;
  188. }
  189. function uni_account_create_info() {
  190. global $_W;
  191. load()->model('permission');
  192. $account_create_info = permission_user_account_num();
  193. $account_all_type_sign = uni_account_type_sign();
  194. foreach ($account_all_type_sign as $sign => &$sign_info) {
  195. if ($_W['isadmin']) {
  196. $sign_info['can_create'] = true;
  197. } else {
  198. $sign_limit = $sign . '_limit';
  199. $founder_sign_limit = 'founder_' . $sign . '_limit';
  200. if (!empty($account_create_info[$sign_limit]) && (!empty($account_create_info[$founder_sign_limit]) && $_W['user']['owner_uid'] || empty($_W['user']['owner_uid']))) {
  201. $sign_info['can_create'] = true;
  202. } else {
  203. $sign_info['can_create'] = false;
  204. }
  205. }
  206. }
  207. return $account_all_type_sign;
  208. }
  209. function uni_account_extra_info($uniacid) {
  210. $uniacid = max(0, intval($uniacid));
  211. if (empty($uniacid)) {
  212. return array();
  213. }
  214. $account = pdo_get('account', array('uniacid' => $uniacid));
  215. if (empty($account) || empty($account['type'])) {
  216. return array();
  217. }
  218. $account_extra = uni_account_type($account['type']);
  219. return $account_extra;
  220. }
  221. function uni_user_accounts($uid = 0, $type = 'account') {
  222. global $_W;
  223. $uid = intval($uid) > 0 ? intval($uid) : $_W['uid'];
  224. if (!in_array($type, array('account', 'wxapp', 'webapp', 'phoneapp', 'aliapp', 'baiduapp', 'toutiaoapp'))) {
  225. $type = 'account';
  226. }
  227. $cachekey = cache_system_key('user_accounts', array('type' => $type, 'uid' => $uid));
  228. $cache = cache_load($cachekey);
  229. if (!empty($cache)) {
  230. return $cache;
  231. }
  232. $type = in_array($type, array('account')) ? 'wechats' : $type;
  233. $select_fields = 'w.acid, w.uniacid, w.name, a.type';
  234. if (in_array($type, array('wechats', 'wxapp'))) {
  235. $select_fields .= ', w.level, w.key, w.secret, w.token';
  236. }
  237. $where = '';
  238. $params = array();
  239. if (!user_is_founder($uid, true)) {
  240. $select_fields .= ', u.role';
  241. $where .= " LEFT JOIN " . tablename('uni_account_users') . " u ON u.uniacid = w.uniacid WHERE u.uid = :uid AND u.role IN(:role1, :role2, :role3, :role4) ";
  242. $params[':uid'] = $uid;
  243. $params[':role1'] = ACCOUNT_MANAGE_NAME_OPERATOR;
  244. $params[':role2'] = ACCOUNT_MANAGE_NAME_MANAGER;
  245. $params[':role3'] = ACCOUNT_MANAGE_NAME_OWNER;
  246. $params[':role4'] = ACCOUNT_MANAGE_NAME_VICE_FOUNDER;
  247. }
  248. $where .= !empty($where) ? " AND a.isdeleted <> 1 AND u.role IS NOT NULL" : " WHERE a.isdeleted <> 1";
  249. $sql = "SELECT " . $select_fields . " FROM " . tablename('account_' . $type) . " w LEFT JOIN " . tablename('account') . " a ON a.acid = w.acid AND a.uniacid = w.uniacid" . $where;
  250. $result = pdo_fetchall($sql, $params, 'uniacid');
  251. cache_write($cachekey, $result);
  252. return $result;
  253. }
  254. function account_owner($uniacid = 0) {
  255. global $_W;
  256. load()->model('user');
  257. $uniacid = intval($uniacid);
  258. if (empty($uniacid)) {
  259. return array();
  260. }
  261. $ownerid = pdo_getcolumn('uni_account_users', array('uniacid' => $uniacid, 'role' => 'owner'), 'uid');
  262. if (empty($ownerid)) {
  263. $ownerid = pdo_getcolumn('uni_account_users', array('uniacid' => $uniacid, 'role' => 'vice_founder'), 'uid');
  264. if (empty($ownerid)) {
  265. $founders = explode(',', $_W['config']['setting']['founder']);
  266. $ownerid = $founders[0];
  267. }
  268. }
  269. $owner = user_single($ownerid);
  270. if (empty($owner)) {
  271. return array();
  272. }
  273. return $owner;
  274. }
  275. function uni_fetch($uniacid = 0) {
  276. global $_W;
  277. $uniacid = empty($uniacid) ? $_W['uniacid'] : intval($uniacid);
  278. $account_api = WeAccount::createByUniacid($uniacid);
  279. if (is_error($account_api)) {
  280. return $account_api;
  281. }
  282. $account_api->__toArray();
  283. $account_api['accessurl'] = $account_api['manageurl'] = wurl('account/post', array('uniacid' => $uniacid, 'account_type' => $account_api['type']), true);
  284. $account_api['roleurl'] = wurl('account/post-user/edit', array('uniacid' => $uniacid, 'account_type' => $account_api['type']), true);
  285. return $account_api;
  286. }
  287. function uni_modules_by_uniacid($uniacid) {
  288. load()->model('user');
  289. load()->model('module');
  290. $account_info = table('account')->getByUniacid($uniacid);
  291. $uni_account_type = uni_account_type($account_info['type']);
  292. $owner_uid = pdo_getall('uni_account_users', array('uniacid' => $uniacid, 'role' => array('owner', 'vice_founder')), array('uid', 'role'), 'role');
  293. $owner_uid = !empty($owner_uid['owner']) ? $owner_uid['owner']['uid'] : (!empty($owner_uid['vice_founder']) ? $owner_uid['vice_founder']['uid'] : 0);
  294. $cachekey = cache_system_key('unimodules', array('uniacid' => $uniacid));
  295. $modules = cache_load($cachekey);
  296. if (empty($modules)) {
  297. $enabled_modules = table('modules')->getNonRecycleModules();
  298. if (!empty($owner_uid) && !user_is_founder($owner_uid, true)) {
  299. $group_modules = table('account')->accountGroupModules($uniacid);
  300. $user_modules = user_modules($owner_uid);
  301. if (!empty($user_modules)) {
  302. $group_modules = array_unique(array_merge($group_modules, array_keys($user_modules)));
  303. $group_modules = array_intersect(array_keys($enabled_modules), $group_modules);
  304. }
  305. } else {
  306. $group_modules = array_keys($enabled_modules);
  307. }
  308. cache_write($cachekey, $group_modules);
  309. $modules = $group_modules;
  310. }
  311. $modules = array_merge($modules, module_system());
  312. $module_list = array();
  313. if (!empty($modules)) {
  314. foreach ($modules as $name) {
  315. if (empty($name)) {
  316. continue;
  317. }
  318. $module_info = module_fetch($name);
  319. $module_info[$uni_account_type['module_support_name']] = empty($module_info[$uni_account_type['module_support_name']]) ? '' : $module_info[$uni_account_type['module_support_name']];
  320. if ($module_info[$uni_account_type['module_support_name']] != $uni_account_type['module_support_value']) {
  321. continue;
  322. }
  323. if (!empty($module_info['recycle_info'])) {
  324. foreach (module_support_type() as $support => $value) {
  325. if ($module_info['recycle_info'][$support] > 0 && $module_info[$support] == $value['support']) {
  326. $module_info[$support] = $value['not_support'];
  327. }
  328. }
  329. }
  330. if ($module_info[MODULE_SUPPORT_ACCOUNT_NAME] != MODULE_SUPPORT_ACCOUNT &&
  331. in_array($account_info['type'], array(ACCOUNT_TYPE_OFFCIAL_NORMAL, ACCOUNT_TYPE_OFFCIAL_AUTH))) {
  332. continue;
  333. }
  334. if ($module_info[MODULE_SUPPORT_WEBAPP_NAME] != MODULE_SUPPORT_WEBAPP &&
  335. in_array($account_info['type'], array(ACCOUNT_TYPE_WEBAPP_NORMAL))) {
  336. continue;
  337. }
  338. if ($module_info[MODULE_SUPPORT_PHONEAPP_NAME] != MODULE_SUPPORT_PHONEAPP &&
  339. in_array($account_info['type'], array(ACCOUNT_TYPE_PHONEAPP_NORMAL))) {
  340. continue;
  341. }
  342. if ($module_info[MODULE_SUPPORT_ALIAPP_NAME] != MODULE_SUPPORT_ALIAPP &&
  343. in_array($account_info['type'], array(ACCOUNT_TYPE_ALIAPP_NORMAL))) {
  344. continue;
  345. }
  346. if ($module_info[MODULE_SUPPORT_BAIDUAPP_NAME] != MODULE_SUPPORT_BAIDUAPP &&
  347. in_array($account_info['type'], array(ACCOUNT_TYPE_BAIDUAPP_NORMAL))) {
  348. continue;
  349. }
  350. if ($module_info[MODULE_SUPPORT_TOUTIAOAPP_NAME] != MODULE_SUPPORT_TOUTIAOAPP &&
  351. in_array($account_info['type'], array(ACCOUNT_TYPE_TOUTIAOAPP_NORMAL))) {
  352. continue;
  353. }
  354. if ($module_info[MODULE_SUPPORT_WXAPP_NAME] != MODULE_SUPPORT_WXAPP &&
  355. $module_info[MODULE_SUPPORT_ACCOUNT_NAME] != MODULE_SUPPORT_ACCOUNT &&
  356. in_array($account_info['type'], array(ACCOUNT_TYPE_APP_NORMAL, ACCOUNT_TYPE_APP_AUTH))) {
  357. continue;
  358. }
  359. if ($module_info[MODULE_SUPPORT_SYSTEMWELCOME_NAME] == MODULE_SUPPORT_SYSTEMWELCOME &&
  360. $module_info[MODULE_SUPPORT_ACCOUNT_NAME] != MODULE_SUPPORT_ACCOUNT &&
  361. $module_info[MODULE_SUPPORT_WEBAPP_NAME] != MODULE_SUPPORT_WEBAPP &&
  362. $module_info[MODULE_SUPPORT_PHONEAPP_NAME] != MODULE_SUPPORT_PHONEAPP &&
  363. $module_info[MODULE_SUPPORT_ALIAPP_NAME] != MODULE_SUPPORT_ALIAPP &&
  364. $module_info[MODULE_SUPPORT_BAIDUAPP_NAME] != MODULE_SUPPORT_BAIDUAPP &&
  365. $module_info[MODULE_SUPPORT_WXAPP_NAME] != MODULE_SUPPORT_WXAPP) {
  366. continue;
  367. }
  368. if (!empty($module_info)) {
  369. $module_list[$name] = $module_info;
  370. }
  371. }
  372. }
  373. $module_list['core'] = array('title' => '系统事件处理模块', 'name' => 'core', 'issystem' => 1, 'enabled' => 1, 'isdisplay' => 0);
  374. return $module_list;
  375. }
  376. function uni_modules() {
  377. global $_W;
  378. return uni_modules_by_uniacid($_W['uniacid']);
  379. }
  380. function uni_modules_app_binding() {
  381. global $_W;
  382. $cachekey = cache_system_key('unimodules_binding', array('uniacid' => $_W['uniacid']));
  383. $cache = cache_load($cachekey);
  384. if (!empty($cache)) {
  385. return $cache;
  386. }
  387. load()->model('module');
  388. $result = array();
  389. $modules = uni_modules();
  390. if (!empty($modules)) {
  391. foreach ($modules as $module) {
  392. if ($module['type'] == 'system') {
  393. continue;
  394. }
  395. $entries = module_app_entries($module['name'], array('home', 'profile', 'shortcut', 'function', 'cover'));
  396. if (empty($entries)) {
  397. continue;
  398. }
  399. if ($module['type'] == '') {
  400. $module['type'] = 'other';
  401. }
  402. $result[$module['name']] = array(
  403. 'name' => $module['name'],
  404. 'type' => $module['type'],
  405. 'title' => $module['title'],
  406. 'entries' => array(
  407. 'cover' => $entries['cover'],
  408. 'home' => $entries['home'],
  409. 'profile' => $entries['profile'],
  410. 'shortcut' => $entries['shortcut'],
  411. 'function' => $entries['function']
  412. )
  413. );
  414. unset($module);
  415. }
  416. }
  417. cache_write($cachekey, $result);
  418. return $result;
  419. }
  420. function uni_groups($groupids = array(), $show_all = false) {
  421. load()->model('module');
  422. global $_W;
  423. $cache_key_id = 0;
  424. if (!empty($groupids)) {
  425. foreach ($groupids as $groupid_key => $groupid_val) {
  426. $groupid_val = intval($groupid_val);
  427. $groupids[$groupid_key] = $groupid_val;
  428. $cache_key_id .= $groupid_val;
  429. }
  430. }
  431. $cachekey = cache_system_key('uni_groups', array('groupids' => $cache_key_id));
  432. $list = cache_load($cachekey);
  433. if (empty($list)) {
  434. $condition = array('uniacid' => 0, 'uid' => 0);
  435. if (!empty($groupids)) {
  436. foreach ($groupids as $groupid_key => $groupid_val) {
  437. $groupids[$groupid_key] = intval($groupid_val);
  438. }
  439. $condition['id IN'] = $groupids;
  440. }
  441. $list = table('uni_group')->where($condition)->orderby('id', 'desc')->getall('id');
  442. if (!empty($groupids)) {
  443. if (in_array('-1', $groupids)) {
  444. $list[-1] = array('id' => -1, 'name' => '所有服务', 'modules' => array('title' => '系统所有模块'), 'templates' => array('title' => '系统所有模板'));
  445. }
  446. if (in_array('0', $groupids)) {
  447. $list[0] = array('id' => 0, 'name' => '基础服务', 'modules' => array('title' => '系统模块'), 'templates' => array('title' => '系统模板'));
  448. }
  449. }
  450. if (!empty($list)) {
  451. foreach ($list as $k => &$row) {
  452. $modules = (array)iunserializer($row['modules']);
  453. $row['modules_all'] = array();
  454. if (!empty($modules)) {
  455. foreach ($modules as $type => $modulenames) {
  456. $type = $type == 'modules' ? 'account' : $type;
  457. if (empty($modulenames) || !is_array($modulenames)) {
  458. continue;
  459. }
  460. $row['modules_all'] = array_merge($row['modules_all'], $modulenames);
  461. $row[$type] = empty($row[$type]) ? $modulenames : array_merge($row[$type], $modulenames);
  462. }
  463. $row['modules_all'] = array_unique($row['modules_all']);
  464. }
  465. if (!empty($row['templates'])) {
  466. $row['templates'] = (array)iunserializer($row['templates']);
  467. if (!empty($row['templates'])) {
  468. $row['templates'] = table('modules')->getAllTemplateByIds($row['templates'], 'name');
  469. }
  470. }
  471. }
  472. }
  473. cache_write($cachekey, $list);
  474. }
  475. $group_list = array();
  476. if (empty($list)) {
  477. return $group_list;
  478. }
  479. $modules_info = array();
  480. foreach ($list as &$item) {
  481. if (empty($item['modules_all'])) {
  482. continue;
  483. }
  484. $modules_all = $item['modules_all'];
  485. $item['modules_all'] = array();
  486. if (!empty($item['account'])) {
  487. $account_modules = $item['account'];
  488. $item['account'] = array();
  489. foreach ($account_modules as $name) {
  490. if (empty($modules_info[$name]) || !is_array($modules_info[$name])) {
  491. $modules_info[$name] = module_main_info($name);
  492. }
  493. if (empty($item['modules_all'][$name])) {
  494. $item['modules_all'][$name] = $modules_info[$name];
  495. }
  496. if (in_array($name, $modules_all)) {
  497. $item['modules_all'][$name]['group_support']['account_support'] = 2;
  498. }
  499. $item['account'][$name] = $modules_info[$name];
  500. }
  501. }
  502. if (!empty($item['wxapp'])) {
  503. $wxapp_modules = $item['wxapp'];
  504. $item['wxapp'] = array();
  505. foreach ($wxapp_modules as $name) {
  506. if (empty($modules_info[$name]) || !is_array($modules_info[$name])) {
  507. $modules_info[$name] = module_main_info($name);
  508. }
  509. if (empty($item['modules_all'][$name])) {
  510. $item['modules_all'][$name] = $modules_info[$name];
  511. }
  512. if (in_array($name, $modules_all)) {
  513. $item['modules_all'][$name]['group_support']['wxapp_support'] = 2;
  514. }
  515. $item['wxapp'][$name] = $modules_info[$name];
  516. }
  517. }
  518. if (!empty($item['webapp'])) {
  519. $wxapp_modules = $item['webapp'];
  520. $item['webapp'] = array();
  521. foreach ($wxapp_modules as $name) {
  522. if (empty($modules_info[$name]) || !is_array($modules_info[$name])) {
  523. $modules_info[$name] = module_main_info($name);
  524. }
  525. if (empty($item['modules_all'][$name])) {
  526. $item['modules_all'][$name] = $modules_info[$name];
  527. }
  528. if (in_array($name, $modules_all)) {
  529. $item['modules_all'][$name]['group_support']['webapp_support'] = 2;
  530. }
  531. $item['webapp'][$name] = $modules_info[$name];
  532. }
  533. }
  534. if (!empty($item['phoneapp'])) {
  535. $phoneapp_modules = $item['phoneapp'];
  536. $item['phoneapp'] = array();
  537. foreach ($phoneapp_modules as $name) {
  538. if (empty($modules_info[$name]) || !is_array($modules_info[$name])) {
  539. $modules_info[$name] = module_main_info($name);
  540. }
  541. if (empty($item['modules_all'][$name])) {
  542. $item['modules_all'][$name] = $modules_info[$name];
  543. }
  544. if (in_array($name, $modules_all)) {
  545. $item['modules_all'][$name]['group_support']['phoneapp_support'] = 2;
  546. }
  547. $item['phoneapp'][$name] = $modules_info[$name];
  548. }
  549. }
  550. if (!empty($item['aliapp'])) {
  551. $aliapp_modules = $item['aliapp'];
  552. $item['aliapp'] = array();
  553. foreach ($aliapp_modules as $name) {
  554. if (empty($modules_info[$name]) || !is_array($modules_info[$name])) {
  555. $modules_info[$name] = module_main_info($name);
  556. }
  557. if (empty($item['modules_all'][$name])) {
  558. $item['modules_all'][$name] = $modules_info[$name];
  559. }
  560. if (in_array($name, $modules_all)) {
  561. $item['modules_all'][$name]['group_support']['aliapp_support'] = 2;
  562. }
  563. $item['aliapp'][$name] = $modules_info[$name];
  564. }
  565. }
  566. if (!empty($item['baiduapp'])) {
  567. $baiduapp_modules = $item['baiduapp'];
  568. $item['baiduapp'] = array();
  569. foreach ($baiduapp_modules as $name) {
  570. if (empty($modules_info[$name]) || !is_array($modules_info[$name])) {
  571. $modules_info[$name] = module_main_info($name);
  572. }
  573. if (empty($item['modules_all'][$name])) {
  574. $item['modules_all'][$name] = $modules_info[$name];
  575. }
  576. if (in_array($name, $modules_all)) {
  577. $item['modules_all'][$name]['group_support']['baiduapp_support'] = 2;
  578. }
  579. $item['baiduapp'][$name] = $modules_info[$name];
  580. }
  581. }
  582. if (!empty($item['toutiaoapp'])) {
  583. $toutiaoapp_modules = $item['toutiaoapp'];
  584. $item['toutiaoapp'] = array();
  585. foreach ($toutiaoapp_modules as $name) {
  586. if (empty($modules_info[$name]) || !is_array($modules_info[$name])) {
  587. $modules_info[$name] = module_main_info($name);
  588. }
  589. if (empty($item['modules_all'][$name])) {
  590. $item['modules_all'][$name] = $modules_info[$name];
  591. }
  592. if (in_array($name, $modules_all)) {
  593. $item['modules_all'][$name]['group_support']['toutiaoapp_support'] = 2;
  594. }
  595. $item['toutiaoapp'][$name] = $modules_info[$name];
  596. }
  597. }
  598. if (!empty($item['welcome'])) {
  599. $welcome_modules = $item['welcome'];
  600. $item['welcome'] = array();
  601. foreach ($welcome_modules as $name) {
  602. if (empty($modules_info[$name]) || !is_array($modules_info[$name])) {
  603. $modules_info[$name] = module_main_info($name);
  604. }
  605. if (empty($item['modules_all'][$name])) {
  606. $item['modules_all'][$name] = $modules_info[$name];
  607. }
  608. if (in_array($name, $modules_all)) {
  609. $item['modules_all'][$name]['group_support']['welcome_support'] = 2;
  610. }
  611. $item['welcome'][$name] = $modules_info[$name];
  612. }
  613. }
  614. }
  615. if (!empty($groupids)) {
  616. foreach ($groupids as $id) {
  617. $group_list[$id] = empty($list[$id]) ? array() : $list[$id];
  618. }
  619. } else {
  620. if (user_is_vice_founder() && empty($show_all)) {
  621. $founder_own_table = table('users_founder_own_uni_groups');
  622. $founder_own_uni_groups = $founder_own_table->getOwnUniGroupsByFounderUid($_W['uid']);
  623. foreach ($list as $group_key => $group) {
  624. if (!in_array($group_key, array_keys($founder_own_uni_groups))) {
  625. unset($list[$group_key]);
  626. continue;
  627. }
  628. }
  629. }
  630. $group_list = $list;
  631. }
  632. return $group_list;
  633. }
  634. function uni_templates() {
  635. global $_W;
  636. load()->model('user');
  637. $owneruid = pdo_fetchcolumn("SELECT uid FROM " . tablename('uni_account_users') . " WHERE uniacid = :uniacid AND role = 'owner'", array(':uniacid' => $_W['uniacid']));
  638. $owner = user_single(array('uid' => $owneruid));
  639. if (empty($owner) || user_is_founder($owner['uid'])) {
  640. $groupid = '-1';
  641. } else {
  642. $groupid = $owner['groupid'];
  643. }
  644. if ($groupid == '-1') {
  645. $templates = table('modules')->getAllTemplates('mid');
  646. return $templates;
  647. }
  648. $extend = pdo_getall('uni_account_group', array('uniacid' => $_W['uniacid']), array(), 'groupid');
  649. $uni_extend = pdo_get('uni_account_extra_modules', array('uniacid' => $_W['uniacid']));
  650. $owner_extend_groups = table('users_extra_group')->getUniGroupsByUid($owneruid);
  651. $owner_extend_templates = table('users_extra_modules')->getExtraModulesByUid($owneruid);
  652. $modules_table = table('modules');
  653. $modules_table->searchTemplateWithName('default');
  654. $template_default = $modules_table->getAllTemplates('mid');
  655. if (empty($groupid) && empty($extend) && empty($uni_extend) && empty($owner_extend_groups) && empty($owner_extend_templates)) {
  656. return $template_default;
  657. }
  658. $group = pdo_fetch("SELECT id, name, package FROM " . tablename('users_group') . " WHERE id = :id", array(':id' => $groupid));
  659. $packageids = iunserializer($group['package']);
  660. if (!is_array($packageids)) {
  661. $packageids = array();
  662. }
  663. if (!empty($extend)) {
  664. foreach ($extend as $extend_packageid => $row) {
  665. $packageids[] = $extend_packageid;
  666. }
  667. }
  668. if (!empty($owner_extend_groups)) {
  669. foreach ($owner_extend_groups as $id => $row) {
  670. $packageids[] = $id;
  671. }
  672. }
  673. if (in_array('-1', $packageids)) {
  674. return table('modules')->getAllTemplates('mid');
  675. }
  676. $template_modules = array();
  677. if (!empty($packageids)) {
  678. $wechatgroup = table('uni_group')->where(array('id' => $packageids))->getall();
  679. if (!empty($wechatgroup)) {
  680. foreach ($wechatgroup as $row) {
  681. $account_modules = iunserializer($row['modules']);
  682. if (!is_array($account_modules['modules']) || empty($account_modules['modules'])) {
  683. continue;
  684. }
  685. foreach ($account_modules['modules'] as $module_name) {
  686. $template_modules[] = $module_name;
  687. }
  688. }
  689. }
  690. }
  691. if (!empty($uni_extend)) {
  692. $uni_extend_modules = iunserializer($uni_extend['modules']);
  693. if (is_array($uni_extend_modules['modules']) && !empty($uni_extend_modules['modules'])) {
  694. foreach ($uni_extend_modules['modules'] as $module_name) {
  695. $template_modules[] = $module_name;
  696. }
  697. }
  698. }
  699. $template_modules = array_unique($template_modules);
  700. $template_modules[] = 'default';
  701. if (is_array($owner_extend_templates)) {
  702. $template_modules = array_merge($template_modules, array_column($owner_extend_templates, 'module_name'));
  703. }
  704. $result = table('modules')->getTemplateByNames($template_modules, 'mid');
  705. return $result;
  706. }
  707. function uni_setting_save($name, $value) {
  708. global $_W;
  709. $uniacid = !empty($_W['uniacid']) ? $_W['uniacid'] : $_W['account']['uniacid'];
  710. if (empty($name)) {
  711. return false;
  712. }
  713. if (is_array($value)) {
  714. $value = serialize($value);
  715. }
  716. $unisetting = pdo_get('uni_settings', array('uniacid' => $uniacid), array('uniacid'));
  717. if (!empty($unisetting)) {
  718. pdo_update('uni_settings', array($name => $value), array('uniacid' => $uniacid));
  719. } else {
  720. pdo_insert('uni_settings', array($name => $value, 'uniacid' => $uniacid));
  721. }
  722. cache_delete(cache_system_key('uniaccount', array('uniacid' => $uniacid)));
  723. return true;
  724. }
  725. function uni_setting_load($name = '', $uniacid = 0) {
  726. global $_W;
  727. $uniacid = empty($uniacid) ? $_W['uniacid'] : $uniacid;
  728. $cachekey = cache_system_key('unisetting', array('uniacid' => $uniacid));
  729. $unisetting = cache_load($cachekey);
  730. if (empty($unisetting) || ($name == 'remote' && empty($unisetting['remote']))) {
  731. $unisetting = pdo_get('uni_settings', array('uniacid' => $uniacid));
  732. if (!empty($unisetting)) {
  733. $serialize = array('site_info', 'stat', 'oauth', 'passport', 'notify',
  734. 'creditnames', 'default_message', 'creditbehaviors', 'payment',
  735. 'recharge', 'tplnotice', 'mcplugin', 'statistics', 'bind_domain', 'remote');
  736. foreach ($unisetting as $key => &$row) {
  737. if (in_array($key, $serialize) && !empty($row)) {
  738. $row = (array)iunserializer($row);
  739. }
  740. }
  741. } else {
  742. $unisetting = array();
  743. }
  744. cache_write($cachekey, $unisetting);
  745. }
  746. if (empty($unisetting)) {
  747. return array();
  748. }
  749. if (empty($name)) {
  750. return $unisetting;
  751. }
  752. if (!is_array($name)) {
  753. $name = array($name);
  754. }
  755. return array_elements($name, $unisetting);
  756. }
  757. function uni_account_user_role_insert($uniacid, $uid, $role) {
  758. $vice_account = array(
  759. 'uniacid' => intval($uniacid),
  760. 'uid' => intval($uid),
  761. 'role' => trim($role)
  762. );
  763. $account_user = pdo_get('uni_account_users', $vice_account, array('id'));
  764. if (!empty($account_user)) {
  765. return false;
  766. }
  767. return pdo_insert('uni_account_users', $vice_account);
  768. }
  769. function uni_owner_account_nums($uid, $role) {
  770. $account_all_type = uni_account_type();
  771. $account_all_type_sign = array_keys(uni_account_type_sign());
  772. foreach ($account_all_type_sign as $type_info) {
  773. $key_name = $type_info . '_num';
  774. $num[$key_name] = 0;
  775. }
  776. $uniacocunts = table('account')->searchAccountList();
  777. if (!empty($uniacocunts)) {
  778. $uni_account_users_table = table('uni_account_users');
  779. $uni_account_users_table->searchWithRole($role);
  780. $all_account = $uni_account_users_table->getCommonUserOwnAccountUniacids($uid);
  781. foreach ($all_account as $account) {
  782. foreach ($account_all_type as $type_key => $type_info) {
  783. if ($type_key == $account['type']) {
  784. $key_name = $type_info['type_sign'] . '_num';
  785. $num[$key_name] += 1;
  786. continue;
  787. }
  788. }
  789. }
  790. }
  791. return $num;
  792. }
  793. function uni_update_week_stat() {
  794. global $_W;
  795. $cachekey = cache_system_key('stat_todaylock', array('uniacid' => $_W['uniacid']));
  796. $cache = cache_load($cachekey);
  797. if (!empty($cache) && $cache['expire'] > TIMESTAMP) {
  798. return true;
  799. }
  800. $seven_days = array(
  801. date('Ymd', strtotime('-1 days')),
  802. date('Ymd', strtotime('-2 days')),
  803. date('Ymd', strtotime('-3 days')),
  804. date('Ymd', strtotime('-4 days')),
  805. date('Ymd', strtotime('-5 days')),
  806. date('Ymd', strtotime('-6 days')),
  807. date('Ymd', strtotime('-7 days')),
  808. );
  809. $week_stat_fans = pdo_getall('stat_fans', array('date' => $seven_days, 'uniacid' => $_W['uniacid']), '', 'date');
  810. $stat_update_yes = false;
  811. foreach ($seven_days as $sevens) {
  812. if (empty($week_stat_fans[$sevens]) || $week_stat_fans[$sevens]['cumulate'] <= 0) {
  813. $stat_update_yes = true;
  814. break;
  815. }
  816. }
  817. if (empty($stat_update_yes)) {
  818. return true;
  819. }
  820. $account = uni_fetch($_W['uniacid']);
  821. if (is_error($account)) {
  822. return $account;
  823. }
  824. if ($account['level'] == ACCOUNT_SUBSCRIPTION_VERIFY || $account['level'] == ACCOUNT_SERVICE_VERIFY) {
  825. $account_obj = WeAccount::createByUniacid();
  826. $weixin_stat = $account_obj->getFansStat();
  827. if (empty($weixin_stat) || is_error($weixin_stat)) {
  828. return error(-1, '调用微信接口错误');
  829. }
  830. }
  831. foreach ($seven_days as $sevens) {
  832. if ($account['level'] == ACCOUNT_SUBSCRIPTION_VERIFY || $account['level'] == ACCOUNT_SERVICE_VERIFY) {
  833. $update_stat = array(
  834. 'uniacid' => $_W['uniacid'],
  835. 'new' => $weixin_stat[$sevens]['new'],
  836. 'cancel' => $weixin_stat[$sevens]['cancel'],
  837. 'cumulate' => $weixin_stat[$sevens]['cumulate'],
  838. 'date' => $sevens,
  839. );
  840. } else {
  841. $update_stat = array(
  842. 'cumulate' => pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename('mc_mapping_fans') . " WHERE uniacid = :uniacid AND follow = :follow AND followtime < :endtime", array(':uniacid' => $_W['uniacid'], ':endtime' => strtotime($sevens) + 86400, ':follow' => 1)),
  843. 'date' => $sevens,
  844. 'new' => $week_stat_fans[$sevens]['new'],
  845. 'cancel' => $week_stat_fans[$sevens]['cancel'],
  846. 'uniacid' => $_W['uniacid'],
  847. );
  848. }
  849. if (empty($week_stat_fans[$sevens])) {
  850. pdo_insert('stat_fans', $update_stat);
  851. } elseif (empty($week_stat_fans[$sevens]['cumulate']) || $week_stat_fans[$sevens]['cumulate'] < 0) {
  852. pdo_update('stat_fans', $update_stat, array('id' => $week_stat_fans[$sevens]['id']));
  853. }
  854. }
  855. cache_write($cachekey, array('expire' => TIMESTAMP + 7200));
  856. return true;
  857. }
  858. function account_create($uniacid, $account) {
  859. global $_W;
  860. $account_all_type = uni_account_type();
  861. $type = $account['type'];
  862. $type_sign = $account_all_type[$type]['type_sign'];
  863. unset($account['type']);
  864. $accountdata = array('uniacid' => $uniacid, 'type' => $type, 'hash' => random(8));
  865. $user_create_account_info = permission_user_account_num();
  866. if (!$_W['isadmin'] && $_W['user']['endtime'] > USER_ENDTIME_GROUP_UNLIMIT_TYPE) {
  867. $accountdata['endtime'] = $_W['user']['endtime'];
  868. }
  869. pdo_insert('account', $accountdata);
  870. $acid = pdo_insertid();
  871. $account['acid'] = $acid;
  872. $account['uniacid'] = $uniacid;
  873. if (in_array($type_sign, array(ACCOUNT_TYPE_SIGN, WXAPP_TYPE_SIGN))) {
  874. $account['token'] = empty($account['token']) ? random(32) : $account['token'];
  875. $account['encodingaeskey'] = empty($account['encodingaeskey']) ? random(43) : $account['encodingaeskey'];
  876. }
  877. pdo_insert($account_all_type[$type]['table_name'], $account);
  878. return $acid;
  879. }
  880. function account_fetch($acid) {
  881. $account_info = pdo_get('account', array('acid' => $acid));
  882. if (empty($account_info)) {
  883. return error(-1, '公众号不存在');
  884. }
  885. return uni_fetch($account_info['uniacid']);
  886. }
  887. function uni_setmeal($uniacid = 0) {
  888. global $_W;
  889. if (!$uniacid) {
  890. $uniacid = $_W['uniacid'];
  891. }
  892. $owneruid = pdo_fetchcolumn("SELECT uid FROM " . tablename('uni_account_users') . " WHERE uniacid = :uniacid AND role = 'owner'", array(':uniacid' => $uniacid));
  893. if (empty($owneruid)) {
  894. $user = array(
  895. 'uid' => -1,
  896. 'username' => '创始人',
  897. 'timelimit' => '未设置',
  898. 'groupid' => '-1',
  899. 'groupname' => '所有服务'
  900. );
  901. return $user;
  902. }
  903. load()->model('user');
  904. $groups = pdo_getall('users_group', array(), array('id', 'name'), 'id');
  905. $owner = user_single(array('uid' => $owneruid));
  906. $user = array(
  907. 'uid' => $owner['uid'],
  908. 'username' => $owner['username'],
  909. 'groupid' => $owner['groupid'],
  910. 'groupname' => empty($groups[$owner['groupid']]['name']) ? '' : $groups[$owner['groupid']]['name']
  911. );
  912. if (empty($owner['endtime'])) {
  913. $user['timelimit'] = date('Y-m-d', $owner['starttime']) . ' ~ 无限制' ;
  914. } else {
  915. if ($owner['endtime'] <= TIMESTAMP) {
  916. $user['timelimit'] = '已到期';
  917. } else {
  918. $year = 0;
  919. $month = 0;
  920. $day = 0;
  921. $endtime = $owner['endtime'];
  922. $time = strtotime('+1 year');
  923. if ($endtime > $time) {
  924. $year = $year + 1;
  925. $time = strtotime("+1 year", $time);
  926. }
  927. $time = strtotime("-1 year", $time);
  928. $time = strtotime("+1 month", $time);
  929. if ($endtime > $time) {
  930. $month = $month + 1;
  931. $time = strtotime("+1 month", $time);
  932. }
  933. $time = strtotime("-1 month", $time);
  934. $time = strtotime("+1 day", $time);
  935. if ($endtime > $time) {
  936. $day = $day + 1;
  937. $time = strtotime("+1 day", $time);
  938. }
  939. if (empty($year)) {
  940. $timelimit = empty($month) ? $day . '天' : date('Y-m-d', $owner['starttime']) . '~' . date('Y-m-d', $owner['endtime']);
  941. } else {
  942. $timelimit = date('Y-m-d', $owner['starttime']) . '~' . date('Y-m-d', $owner['endtime']);
  943. }
  944. $user['timelimit'] = $timelimit;
  945. }
  946. }
  947. return $user;
  948. }
  949. function account_delete($uniacid) {
  950. global $_W;
  951. load()->func('file');
  952. load()->model('module');
  953. load()->model('job');
  954. $account = pdo_get('uni_account', array('uniacid' => $uniacid));
  955. if (empty($account)) {
  956. itoast('公众号不存在或是已经被删除', '', '');
  957. }
  958. $state = permission_account_user_role($_W['uid'], $uniacid);
  959. if (!in_array($state, array(ACCOUNT_MANAGE_NAME_OWNER, ACCOUNT_MANAGE_NAME_FOUNDER, ACCOUNT_MANAGE_NAME_VICE_FOUNDER))) {
  960. itoast('没有该公众号操作权限!', url('account/recycle'), 'error');
  961. }
  962. if ($uniacid == $_W['uniacid']) {
  963. isetcookie('__uniacid', '');
  964. }
  965. cache_delete(cache_system_key('uniaccount', array('uniacid' => $uniacid)));
  966. $rules = pdo_getall('rule', array('uniacid' => $uniacid), array('id', 'module'));
  967. if (!empty($rules)) {
  968. foreach ($rules as $index => $rule) {
  969. $deleteid[] = intval($rule['id']);
  970. }
  971. table('rule')->where('id IN', $deleteid)->delete();
  972. }
  973. @unlink(IA_ROOT . '/attachment/qrcode_' . $uniacid . '.jpg');
  974. @unlink(IA_ROOT . '/attachment/headimg_' . $uniacid . '.jpg');
  975. file_remote_delete('qrcode_' . $uniacid . '.jpg');
  976. file_remote_delete('headimg_' . $uniacid . '.jpg');
  977. $jobid = job_create_delete_account($uniacid, $account['name'], $_W['uid']);
  978. $tables = array(
  979. 'account', 'account_wechats', 'account_wxapp', 'wxapp_versions', 'account_webapp', 'account_phoneapp',
  980. 'core_paylog', 'cover_reply', 'mc_chats_record', 'mc_credits_recharge', 'mc_credits_record',
  981. 'mc_fans_groups', 'mc_groups', 'mc_handsel', 'mc_mapping_fans', 'mc_mass_record', 'mc_member_address',
  982. 'mc_member_fields', 'mc_members', 'menu_event', 'qrcode', 'qrcode_stat', 'rule', 'rule_keyword',
  983. 'site_article', 'site_category', 'site_multi', 'site_nav', 'site_slide', 'site_styles', 'site_styles_vars',
  984. 'stat_keyword', 'stat_rule', 'uni_account', 'uni_account_modules', 'uni_account_users', 'uni_settings',
  985. 'uni_group', 'uni_account_extra_modules', 'uni_verifycode', 'users_permission', 'wechat_news',
  986. 'users_lastuse', 'users_operate_history', 'users_operate_star'
  987. );
  988. foreach ($tables as $table) {
  989. $tablename = str_replace($GLOBALS['_W']['config']['db']['tablepre'], '', $table);
  990. pdo_delete($tablename, array( 'uniacid' => $uniacid));
  991. }
  992. return $jobid;
  993. }
  994. function account_wechatpay_proxy() {
  995. global $_W;
  996. $proxy_account = cache_load(cache_system_key('proxy_wechatpay_account'));
  997. if (empty($proxy_account)) {
  998. $proxy_account = cache_build_proxy_wechatpay_account();
  999. }
  1000. unset($proxy_account['borrow'][$_W['uniacid']]);
  1001. unset($proxy_account['service'][$_W['uniacid']]);
  1002. return $proxy_account;
  1003. }
  1004. function uni_account_module_shortcut_enabled($modulename, $status = STATUS_ON) {
  1005. global $_W;
  1006. $module = module_fetch($modulename);
  1007. if (empty($module)) {
  1008. return error(1, '抱歉,你操作的模块不能被访问!');
  1009. }
  1010. $module_status = pdo_get('uni_account_modules', array('module' => $modulename, 'uniacid' => $_W['uniacid']), array('id', 'shortcut'));
  1011. if (empty($module_status)) {
  1012. $data = array(
  1013. 'uniacid' => $_W['uniacid'],
  1014. 'module' => $modulename,
  1015. 'enabled' => STATUS_ON,
  1016. 'shortcut' => $status ? STATUS_ON : STATUS_OFF,
  1017. 'settings' => '',
  1018. );
  1019. pdo_insert('uni_account_modules', $data);
  1020. } else {
  1021. $data = array(
  1022. 'shortcut' => $status ? STATUS_ON : STATUS_OFF,
  1023. );
  1024. pdo_update('uni_account_modules', $data, array('id' => $module_status['id']));
  1025. }
  1026. cache_build_module_info($modulename);
  1027. return true;
  1028. }
  1029. function uni_account_member_fields($uniacid) {
  1030. if (empty($uniacid)) {
  1031. return array();
  1032. }
  1033. $account_member_fields = pdo_getall('mc_member_fields', array('uniacid' => $uniacid), array(), 'fieldid');
  1034. $system_member_fields = pdo_getall('profile_fields', array(), array(), 'id');
  1035. $less_field_indexes = array_diff(array_keys($system_member_fields), array_keys($account_member_fields));
  1036. if (empty($less_field_indexes)) {
  1037. foreach ($account_member_fields as &$field) {
  1038. $field['field'] = $system_member_fields[$field['fieldid']]['field'];
  1039. }
  1040. unset($field);
  1041. return $account_member_fields;
  1042. }
  1043. $account_member_add_fields = array('uniacid' => $uniacid);
  1044. foreach ($less_field_indexes as $field_index) {
  1045. $account_member_add_fields['fieldid'] = $system_member_fields[$field_index]['id'];
  1046. $account_member_add_fields['title'] = $system_member_fields[$field_index]['title'];
  1047. $account_member_add_fields['available'] = $system_member_fields[$field_index]['available'];
  1048. $account_member_add_fields['displayorder'] = $system_member_fields[$field_index]['displayorder'];
  1049. pdo_insert('mc_member_fields', $account_member_add_fields);
  1050. $insert_id = pdo_insertid();
  1051. $account_member_fields[$insert_id]['id'] = $insert_id;
  1052. $account_member_fields[$insert_id]['field'] = $system_member_fields[$field_index]['field'];
  1053. $account_member_fields[$insert_id]['fid'] = $system_member_fields[$field_index]['id'];
  1054. $account_member_fields[$insert_id] = array_merge($account_member_fields[$insert_id], $account_member_add_fields);
  1055. }
  1056. return $account_member_fields;
  1057. }
  1058. function uni_account_global_oauth() {
  1059. load()->model('setting');
  1060. $oauth = setting_load('global_oauth');
  1061. $oauth = !empty($oauth['global_oauth']) ? $oauth['global_oauth'] : array();
  1062. if (!empty($oauth['oauth']['account'])) {
  1063. $account_exist = uni_fetch($oauth['oauth']['account']);
  1064. if (empty($account_exist) || is_error($account_exist)) {
  1065. $oauth['oauth']['account'] = 0;
  1066. }
  1067. }
  1068. return $oauth;
  1069. }
  1070. function uni_search_link_account($module_name, $type_sign, $uniacid = 0) {
  1071. global $_W;
  1072. load()->model('miniapp');
  1073. load()->model('phoneapp');
  1074. $module_name = trim($module_name);
  1075. if (empty($module_name) || empty($type_sign)) {
  1076. return array();
  1077. }
  1078. $all_account_type = uni_account_type();
  1079. $all_account_type_sign = uni_account_type_sign();
  1080. if (empty($all_account_type_sign[$type_sign])) {
  1081. return array();
  1082. }
  1083. $owned_account = uni_user_accounts($_W['uid'], $type_sign);
  1084. if (!empty($owned_account)) {
  1085. foreach ($owned_account as $key => $account) {
  1086. if (!empty($uniacid) && $account['uniacid'] == $uniacid) {
  1087. unset($owned_account[$key]);
  1088. continue;
  1089. }
  1090. $account['role'] = permission_account_user_role($_W['uid'], $account['uniacid']);
  1091. if (!in_array($account['role'], array(ACCOUNT_MANAGE_NAME_OWNER, ACCOUNT_MANAGE_NAME_VICE_FOUNDER, ACCOUNT_MANAGE_NAME_FOUNDER))) {
  1092. unset($owned_account[$key]);
  1093. continue;
  1094. }
  1095. $account_modules = uni_modules_by_uniacid($account['uniacid']);
  1096. if (empty($account_modules[$module_name])) {
  1097. unset($owned_account[$key]);
  1098. continue;
  1099. }
  1100. $type = $all_account_type_sign[$type_sign]['contain_type'][0];
  1101. $type_info = $all_account_type[$type];
  1102. if ($account_modules[$module_name][$type_info['module_support_name']] != $type_info['module_support_value']) {
  1103. unset($owned_account[$key]);
  1104. continue;
  1105. }
  1106. $account_support_version = array_filter($all_account_type, function ($item) {
  1107. return $item['support_version'];
  1108. });
  1109. $account_support_version = array_keys($account_support_version);
  1110. if (in_array($type, $account_support_version)) {
  1111. $last_version = miniapp_fetch($account['uniacid']);
  1112. if (empty($last_version['version']) || empty($last_version['version']['modules']) || !is_array($last_version['version']['modules'])) {
  1113. unset($owned_account[$key]);
  1114. continue;
  1115. }
  1116. $module_version = array();
  1117. foreach ($last_version['version']['modules'] as $item) {
  1118. if (!empty($item['name']) && $item['name'] == $module_name) {
  1119. $module_version = $item;
  1120. break;
  1121. }
  1122. }
  1123. if (empty($module_version) || !empty($module_version['account']) || !empty($module_version['uniacid'])) {
  1124. unset($owned_account[$key]);
  1125. continue;
  1126. }
  1127. }
  1128. }
  1129. }
  1130. return $owned_account;
  1131. }
  1132. function uni_account_oauth_host() {
  1133. global $_W;
  1134. $oauth_url = $_W['siteroot'];
  1135. $unisetting = uni_setting_load();
  1136. if (!empty($unisetting['bind_domain']) && !empty($unisetting['bind_domain']['domain'])) {
  1137. $oauth_url = $unisetting['bind_domain']['domain'] . '/';
  1138. } else {
  1139. if (ACCOUNT_TYPE_OFFCIAL_NORMAL == $_W['account']['type']) {
  1140. if (!empty($unisetting['oauth']['host'])) {
  1141. $oauth_url = $unisetting['oauth']['host'] . '/';
  1142. } else {
  1143. $global_unisetting = uni_account_global_oauth();
  1144. $oauth_url = !empty($global_unisetting['oauth']['host']) ? $global_unisetting['oauth']['host'] . '/' : $oauth_url;
  1145. }
  1146. }
  1147. }
  1148. return $oauth_url;
  1149. }
  1150. function uni_user_see_more_info($user_type, $see_more = false) {
  1151. global $_W;
  1152. if (empty($user_type)) {
  1153. return false;
  1154. }
  1155. if ($user_type == ACCOUNT_MANAGE_NAME_VICE_FOUNDER && !empty($see_more) || $_W['role'] != $user_type) {
  1156. return true;
  1157. }
  1158. return false;
  1159. }
  1160. function uni_delete_rule($rid, $relate_table_name) {
  1161. global $_W;
  1162. $rid = intval($rid);
  1163. if (empty($rid)) {
  1164. return false;
  1165. }
  1166. $allowed_table_names = array('news_reply', 'cover_reply');
  1167. if (!in_array($relate_table_name, $allowed_table_names)) {
  1168. return false;
  1169. }
  1170. $rule_result = pdo_delete('rule', array('id' => $rid, 'uniacid' => $_W['uniacid']));
  1171. $rule_keyword_result = pdo_delete('rule_keyword', array('rid' => $rid, 'uniacid' => $_W['uniacid']));
  1172. if ($rule_result && $rule_keyword_result) {
  1173. $result = pdo_delete($relate_table_name, array('rid' => $rid));
  1174. }
  1175. return $result ? true : false;
  1176. }
  1177. function uni_get_account_by_appid($appid, $account_type, $except_uniacid = 0) {
  1178. $type_info = uni_account_type($account_type);
  1179. if (in_array($type_info['type_sign'], array(WEBAPP_TYPE_SIGN, PHONEAPP_TYPE_SIGN))) {
  1180. return array();
  1181. }
  1182. $sql = 'SELECT t.`key`, t.name, a.acid, a.uniacid FROM '
  1183. . tablename($type_info['table_name'])
  1184. . 't JOIN ' . tablename('account')
  1185. . ' a ON t.uniacid = a.uniacid WHERE a.isdeleted != 1';
  1186. if (in_array($type_info['type_sign'], array(BAIDUAPP_TYPE_SIGN, TOUTIAOAPP_TYPE_SIGN))) {
  1187. $sql .= ' AND t.`appid` = :appid';
  1188. } else {
  1189. $sql .= ' AND t.`key` = :appid';
  1190. }
  1191. $params = array(':appid' => $appid);
  1192. if (!empty($except_uniacid)) {
  1193. $sql .= ' AND a.uniacid != :except_uniacid';
  1194. $params[':except_uniacid'] = intval($except_uniacid);
  1195. }
  1196. $account = pdo_fetch($sql, $params);
  1197. if (!empty($account)) {
  1198. $account['type_title'] = $type_info['title'];
  1199. $account['key_title'] = 'AppId';
  1200. }
  1201. return $account;
  1202. }