message.mod.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  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 message_notice_read($id) {
  8. $id = intval($id);
  9. if (empty($id)) {
  10. return true;
  11. }
  12. table('core_message_notice_log')->fillIsRead(MESSAGE_READ)->whereId($id)->save();
  13. return true;
  14. }
  15. function message_notice_all_read($type = '') {
  16. global $_W;
  17. $message_table = table('core_message_notice_log');
  18. if (!empty($type)) {
  19. $message_table->whereType($type);
  20. }
  21. if ($_W['isadmin']) {
  22. $message_table->fillIsRead(MESSAGE_READ)->whereIsRead(MESSAGE_NOREAD)->save();
  23. return true;
  24. }
  25. $message_table->fillIsRead(MESSAGE_READ)->whereIsRead(MESSAGE_NOREAD)->whereUid($_W['uid'])->save();
  26. return true;
  27. }
  28. function message_setting($uid, $type = 0, $params = array()) {
  29. global $_W;
  30. $params['orderid'] = empty($params['orderid']) ? '' : $params['orderid'];
  31. $params['username'] = empty($params['username']) ? '' : $params['username'];
  32. $params['goods_name'] = empty($params['goods_name']) ? '' : $params['goods_name'];
  33. $params['money'] = empty($params['money']) ? 0 : $params['money'];
  34. $params['uid'] = empty($params['uid']) ? 0 : $params['uid'];
  35. $params['uuid'] = empty($params['uuid']) ? 0 : $params['uuid'];
  36. $params['updated_at'] = empty($params['updated_at']) ? '' : $params['updated_at'];
  37. $params['note'] = empty($params['note']) ? '' : $params['note'];
  38. $params['status'] = empty($params['status']) ? 2 : $params['status'];
  39. $params['source'] = empty($params['source']) ? '' : $params['source'];
  40. $params['module_name'] = empty($params['module_name']) ? '' : $params['module_name'];
  41. $data = array(
  42. 'order_message' => array(
  43. 'title' => '订单消息',
  44. 'msg' => '用户购买模块,服务等,提交订单或付款后,将会有消息提醒,建议打开',
  45. 'permission' => array('founder'),
  46. 'types' => array(
  47. MESSAGE_ORDER_PAY_TYPE => array(
  48. 'title' => '支付成功',
  49. 'msg' => '用户购买模块,服务等,付款后,将会有消息提醒,建议打开',
  50. 'permission' => array('founder'),
  51. 'notice_data' => array(
  52. 'sign' => $params['orderid'],
  53. 'message' => sprintf(
  54. '%s ' . date('Y-m-d H:i:s') . ' 在商城成功支付 %.2f元',
  55. $params['username'],
  56. $params['money']
  57. )
  58. ),
  59. ),
  60. MESSAGE_ORDER_APPLY_REFUND_TYPE => array(
  61. 'title' => '申请退款',
  62. 'msg' => '用户购买模块,服务等,付款后,将会有消息提醒,建议打开',
  63. 'permission' => array('founder'),
  64. 'notice_data' => array(
  65. 'sign' => $params['orderid'],
  66. 'message' => sprintf(
  67. '%s ' . date('Y-m-d H:i:s') . ' 在商城申请退款 %.2f元',
  68. $params['username'],
  69. $params['money']
  70. )
  71. ),
  72. ),
  73. )
  74. ),
  75. 'expire_message' => array(
  76. 'title' => '到期消息',
  77. 'msg' => '用户公众号,小程序到期,平台类型到期,将会有消息提醒,建议打开',
  78. 'permission' => array(),
  79. 'types' => array(
  80. MESSAGE_ACCOUNT_EXPIRE_TYPE => array(
  81. 'title' => '公众号到期',
  82. 'msg' => '用户公众号到期后,将会有消息提醒,建议打开',
  83. 'permission' => array(),
  84. 'notice_data' => array(
  85. 'sign' => $params['uniacid'],
  86. 'end_time' => $params['end_time'],
  87. 'message' => sprintf('%s-%s已过期', $params['account_name'], $params['type_name'])
  88. ),
  89. ),
  90. MESSAGE_WECHAT_EXPIRE_TYPE => array(
  91. 'title' => '小程序到期',
  92. 'msg' => '用户小程序到期后,将会有消息提醒,建议打开',
  93. 'permission' => array(),
  94. 'notice_data' => array(
  95. 'sign' => $params['uniacid'],
  96. 'end_time' => $params['end_time'],
  97. 'message' => sprintf('%s-%s已过期', $params['account_name'], $params['type_name'])
  98. ),
  99. ),
  100. MESSAGE_WEBAPP_EXPIRE_TYPE => array(
  101. 'title' => 'pc过期',
  102. 'msg' => '用户pc类型到期后,将会有消息提醒,建议打开',
  103. 'permission' => array(),
  104. 'notice_data' => array(
  105. 'sign' => $params['uniacid'],
  106. 'end_time' => $params['end_time'],
  107. 'message' => sprintf('%s-%s已过期', $params['account_name'], $params['type_name'])
  108. ),
  109. ),
  110. MESSAGE_USER_EXPIRE_TYPE => array(
  111. 'title' => '用户账号到期',
  112. 'msg' => '用户账号到期后,将会有消息提醒,建议打开',
  113. 'permission' => array(),
  114. 'notice_data' => array(
  115. 'sign' => $params['uid'],
  116. 'end_time' => $params['end_time'],
  117. 'message' => sprintf('%s 用户账号即将过期', $params['username'])
  118. ),
  119. ),
  120. )
  121. ),
  122. 'work_message' => array(
  123. 'title' => '工单提醒',
  124. 'msg' => '站点有工单消息时,将会有消息提醒,建议打开',
  125. 'permission' => array('founder'),
  126. 'types' => array(
  127. MESSAGE_WORKORDER_TYPE => array(
  128. 'title' => '新工单',
  129. 'msg' => '站点有新工时,将会有消息提醒,建议打开',
  130. 'permission' => array('founder'),
  131. 'notice_data' => array(
  132. 'sign' => $params['uuid'],
  133. 'create_time' => $params['updated_at'],
  134. 'message' => $params['note']
  135. ),
  136. ),
  137. )
  138. ),
  139. 'register_message' => array(
  140. 'title' => '注册提醒',
  141. 'msg' => '用户注册后,将会有消息提醒,建议打开',
  142. 'permission' => array('founder'),
  143. 'types' => array(
  144. MESSAGE_REGISTER_TYPE => array(
  145. 'title' => '新用户注册',
  146. 'msg' => '新用户注册后,将会有消息提醒,建议打开',
  147. 'permission' => array('founder'),
  148. 'notice_data' => array(
  149. 'sign' => $params['uid'],
  150. 'status' => $params['status'],
  151. 'message' => sprintf('%s-%s %s注册成功--%s', $params['username'], $params['type_name'], date("Y-m-d H:i:s"), $params['source'])
  152. ),
  153. ),
  154. ),
  155. ),
  156. 'upgrade_message' => array(
  157. 'title' => '升级提醒',
  158. 'msg' => '账号内应用有升级时,将通知账号主管理员,建议打开',
  159. 'permission' => array('founder'),
  160. 'types' => array(
  161. MESSAGE_WXAPP_MODULE_UPGRADE => array(
  162. 'title' => '小程序应用升级',
  163. 'msg' => '小程序的应用有升级时,将通知账号主管理员,建议打开',
  164. 'permission' => array('founder'),
  165. 'notice_data' => array(
  166. 'sign' => $params['uniacid'],
  167. 'message' => sprintf('%s小程序中的%s应用有更新', $params['account_name'], $params['module_name'])
  168. ),
  169. )
  170. )
  171. ),
  172. );
  173. if (empty($type)) {
  174. return $data;
  175. }
  176. foreach ($data as $item) {
  177. foreach ($item['types'] as $key => $row) {
  178. $types[$key] = $row;
  179. }
  180. }
  181. if (!is_numeric($type) || !in_array($type, array_keys($types))) {
  182. return error(1, '消息类型有误');
  183. }
  184. $users_table = table('users');
  185. $founder_notice_setting = $users_table->getNoticeSettingByUid($_W['config']['setting']['founder']);
  186. if (!empty($founder_notice_setting[$type]) && $founder_notice_setting[$type] == MESSAGE_DISABLE) {
  187. return error(2, '创始人未开启提醒');
  188. }
  189. if (!user_is_founder($uid, true)) {
  190. $user_notice_setting = $users_table->getNoticeSettingByUid($uid);
  191. if (!empty($user_notice_setting[$type]) && $user_notice_setting[$type] == MESSAGE_DISABLE) {
  192. return error(3, '用户未开启提醒');
  193. }
  194. }
  195. $notice_data = $types[$type]['notice_data'];
  196. $notice_data['uid'] = $uid;
  197. $notice_data['type'] = $type;
  198. $notice_data['url'] = '';
  199. return $notice_data;
  200. }
  201. function message_notice_record($uid, $type, $params) {
  202. $notice_info = message_setting($uid, $type, $params);
  203. if (is_error($notice_info)) {
  204. return $notice_info;
  205. }
  206. $message_validate_exists = message_validate_exists($notice_info);
  207. if (!empty($message_validate_exists)) {
  208. return true;
  209. }
  210. $notice_info['create_time'] = empty($notice_info['create_time']) ? TIMESTAMP : $notice_info['create_time'];
  211. $notice_info['is_read'] = empty($notice_info['is_read']) ? MESSAGE_NOREAD : $notice_info['is_read'];
  212. table('core_message_notice_log')->fill($notice_info)->save();
  213. message_send_wechat_notice($notice_info);
  214. return true;
  215. }
  216. function message_send_wechat_notice($notice_info) {
  217. global $_W;
  218. $setting = setting_load('message_wechat_notice_setting');
  219. $setting = $setting['message_wechat_notice_setting'];
  220. if (empty($setting['uniacid'])) {
  221. return error(-1, '未设置公众号');
  222. }
  223. $uniaccount = table('account')->getUniAccountByUniacid($setting['uniacid']);
  224. if (empty($uniaccount)) {
  225. return error(-1, '帐号不存在或是已经被删除');
  226. }
  227. $account_api = WeAccount::createByUniacid($uniaccount['uniacid']);
  228. if (is_error($account_api)) {
  229. return $account_api;
  230. }
  231. $type_template = array(
  232. MESSAGE_ORDER_TYPE => 'order',
  233. MESSAGE_ORDER_PAY_TYPE => 'order_pay',
  234. MESSAGE_ACCOUNT_EXPIRE_TYPE => 'expire',
  235. MESSAGE_WECHAT_EXPIRE_TYPE => 'expire',
  236. MESSAGE_WEBAPP_EXPIRE_TYPE => 'expire',
  237. MESSAGE_USER_EXPIRE_TYPE => 'expire',
  238. MESSAGE_WORKORDER_TYPE => 'work_order',
  239. MESSAGE_REGISTER_TYPE => 'register',
  240. MESSAGE_WXAPP_MODULE_UPGRADE => '',
  241. MESSAGE_SYSTEM_UPGRADE => '',
  242. MESSAGE_OFFICIAL_DYNAMICS => '',
  243. );
  244. if (empty($setting['template'][$type_template[$notice_info['type']]])) {
  245. return error(-1, '未设置模板ID');
  246. }
  247. if ($type_template[$notice_info['type']] == 'expire' && user_is_founder($notice_info['uid'], true)) {
  248. return error(-1, '主管理员不发送过期消息');
  249. }
  250. if ($notice_info['type'] == MESSAGE_REGISTER_TYPE) {
  251. $notice_info['uid'] = $_W['config']['setting']['founder'];
  252. }
  253. $users_bind = table('users_bind')->getByTypeAndUid(USER_REGISTER_TYPE_OPEN_WECHAT, $notice_info['uid']);
  254. if (empty($users_bind['bind_sign'])) {
  255. return error(-1, '用户未绑定微信');
  256. }
  257. $mc_mapping_fans_table = table('mc_mapping_fans');
  258. $mc_mapping_fans_table->searchWithUniacid($setting['uniacid']);
  259. $mc_mapping_fans_table->searchWithUnionid($users_bind['bind_sign']);
  260. $fans = $mc_mapping_fans_table->get();
  261. if (empty($fans['openid'])) {
  262. return error(-1, '用户未关注公众号');
  263. }
  264. $msg_data = array();
  265. switch ($notice_info['type']) {
  266. case MESSAGE_ACCOUNT_EXPIRE_TYPE:
  267. $time = empty($notice_info['end_time']) ? TIMESTAMP : $notice_info['end_time'];
  268. $msg_data = array(
  269. 'first' => array('value' => '您好,您有过期的账号!'),
  270. 'keyword1' => array('value' => $notice_info['message']),
  271. 'keyword2' => array('value' => '公众号'),
  272. 'keyword3' => array('value' => date('Y年m月d日 H:i', $time)),
  273. 'remark' => array('value' => '感谢您的使用!'),
  274. );
  275. break;
  276. case MESSAGE_WECHAT_EXPIRE_TYPE:
  277. $time = empty($notice_info['end_time']) ? TIMESTAMP : $notice_info['end_time'];
  278. $msg_data = array(
  279. 'first' => array('value' => '您好,您有过期的账号!'),
  280. 'keyword1' => array('value' => $notice_info['message']),
  281. 'keyword2' => array('value' => '小程序'),
  282. 'keyword3' => array('value' => date('Y年m月d日 H:i', $time)),
  283. 'remark' => array('value' => '感谢您的使用!'),
  284. );
  285. break;
  286. case MESSAGE_WEBAPP_EXPIRE_TYPE:
  287. $time = empty($notice_info['end_time']) ? TIMESTAMP : $notice_info['end_time'];
  288. $msg_data = array(
  289. 'first' => array('value' => '您好,您有过期的账号!'),
  290. 'keyword1' => array('value' => $notice_info['message']),
  291. 'keyword2' => array('value' => 'PC'),
  292. 'keyword3' => array('value' => date('Y年m月d日 H:i', $time)),
  293. 'remark' => array('value' => '感谢您的使用!'),
  294. );
  295. break;
  296. case MESSAGE_USER_EXPIRE_TYPE:
  297. $msg_data = array(
  298. 'first' => array('value' => '您好,您的账号即将过期!'),
  299. 'keyword1' => array('value' => $_W['user']['username']),
  300. 'keyword2' => array('value' => '用户账号'),
  301. 'keyword3' => array('value' => date('Y年m月d日 H:i', $_W['user']['endtime'])),
  302. 'remark' => array('value' => '感谢您的使用!'),
  303. );
  304. break;
  305. case MESSAGE_WORKORDER_TYPE:
  306. $time = empty($notice_info['create_time']) ? TIMESTAMP : $notice_info['create_time'];
  307. $msg_data = array(
  308. 'first' => array('value' => '您好,您有新的工单提交!!'),
  309. 'keyword1' => array('value' => $notice_info['sign']),
  310. 'keyword2' => array('value' => $notice_info['message']),
  311. 'keyword3' => array('value' => date('Y年m月d日 H:i', $time)),
  312. 'remark' => array('value' => '感谢您的使用!'),
  313. );
  314. break;
  315. case MESSAGE_REGISTER_TYPE:
  316. $source = substr($notice_info['message'], stripos($notice_info['message'], '--') + 2);
  317. $source_array = array('mobile' => '手动注册', 'system' => '手动注册', 'qq' => 'QQ 注册', 'wechat' => '微信注册', 'admin' => '管理员添加');
  318. $user = pdo_get('users', array('uid' => $notice_info['sign']));
  319. $msg_data = array(
  320. 'first' => array('value' => '您好,有新用户在站点注册!'),
  321. 'keyword1' => array('value' => $user['username']),
  322. 'keyword2' => array('value' => date('Y年m月d日 H:i')),
  323. 'keyword3' => array('value' => $source_array[$source]),
  324. 'remark' => array('value' => '感谢您的使用!'),
  325. );
  326. break;
  327. case MESSAGE_WXAPP_MODULE_UPGRADE:
  328. case MESSAGE_SYSTEM_UPGRADE:
  329. case MESSAGE_OFFICIAL_DYNAMICS:
  330. break;
  331. }
  332. return $account_api->sendTplNotice($fans['openid'], $setting['template'][$type_template[$notice_info['type']]], $msg_data);
  333. }
  334. function message_validate_exists($message) {
  335. $message_exists = table('core_message_notice_log')->messageExists($message);
  336. if (!empty($message_exists)) {
  337. return true;
  338. }
  339. return false;
  340. }
  341. function message_event_notice_list() {
  342. load()->model('user');
  343. global $_W;
  344. $message_table = table('core_message_notice_log');
  345. $message_table->searchWithIsRead(MESSAGE_NOREAD);
  346. if ($_W['isadmin']) {
  347. $message_table->searchWithOutType(MESSAGE_USER_EXPIRE_TYPE);
  348. } else {
  349. $message_table->searchWithUid($_W['uid']);
  350. $message_table->searchWithType(array(
  351. MESSAGE_ACCOUNT_EXPIRE_TYPE,
  352. MESSAGE_WECHAT_EXPIRE_TYPE,
  353. MESSAGE_WEBAPP_EXPIRE_TYPE,
  354. MESSAGE_USER_EXPIRE_TYPE,
  355. MESSAGE_WXAPP_MODULE_UPGRADE,
  356. MESSAGE_SYSTEM_UPGRADE,
  357. MESSAGE_OFFICIAL_DYNAMICS
  358. ));
  359. }
  360. $message_table->searchWithPage(1, 10);
  361. $lists = $message_table->orderby('id', 'DESC')->getall();
  362. $total = $message_table->getLastQueryTotal();
  363. $lists = message_list_detail($lists);
  364. return array(
  365. 'lists' => $lists,
  366. 'total' => $total,
  367. 'more_url' => url('message/notice') . (igetcookie('__iscontroller') ? 'iscontroller=1' : ''),
  368. 'all_read_url' => url('message/notice/all_read') . (igetcookie('__iscontroller') ? 'iscontroller=1' : ''),
  369. );
  370. }
  371. function message_account_expire() {
  372. global $_W;
  373. load()->model('account');
  374. $account_table = table('account');
  375. $expire_account_list = $account_table->searchAccountList();
  376. if (empty($expire_account_list)) {
  377. return true;
  378. }
  379. foreach ($expire_account_list as $account) {
  380. $account_detail = uni_fetch($account['uniacid']);
  381. if (empty($account_detail->owner['uid'])) {
  382. continue;
  383. }
  384. if ($account_detail['endtime'] > USER_ENDTIME_GROUP_UNLIMIT_TYPE && $account_detail['endtime'] < TIMESTAMP) {
  385. switch ($account_detail['type']) {
  386. case ACCOUNT_TYPE_APP_NORMAL:
  387. $type = MESSAGE_WECHAT_EXPIRE_TYPE;
  388. break;
  389. case ACCOUNT_TYPE_WEBAPP_NORMAL:
  390. $type = MESSAGE_WEBAPP_EXPIRE_TYPE;
  391. break;
  392. default:
  393. $type = MESSAGE_ACCOUNT_EXPIRE_TYPE;
  394. break;
  395. }
  396. $params = array(
  397. 'uniacid' => $account_detail['uniacid'],
  398. 'end_time' => $account_detail['endtime'],
  399. 'account_name' => $account_detail['name'],
  400. 'type_name' => $account_detail->typeName,
  401. );
  402. $result = message_notice_record($account_detail->owner['uid'], $type, $params);
  403. if (is_error($result) && $result['errno'] == 3) {
  404. message_notice_record($_W['config']['setting']['founder'], $type, $params);
  405. }
  406. }
  407. }
  408. return true;
  409. }
  410. function message_notice_worker() {
  411. global $_W;
  412. load()->func('communication');
  413. load()->classs('cloudapi');
  414. $api = new CloudApi();
  415. $table = table('core_message_notice_log');
  416. $time = 0;
  417. $table->searchWithType(MESSAGE_WORKORDER_TYPE);
  418. $message_record = $table->orderby('id', 'DESC')->get();
  419. if (!empty($message_record)) {
  420. $time = $message_record['create_time'];
  421. }
  422. if (!empty($time) && TIMESTAMP - $time < 60 * 60 * 6) {
  423. return true;
  424. }
  425. $api_url = $api->get('system', 'workorder', array('do' => 'notload', 'time' => $time), 'json', false);
  426. if (is_error($api_url)) {
  427. return true;
  428. }
  429. $request_url = $api_url['data']['url'];
  430. $response = ihttp_get($request_url);
  431. $uid = $_W['config']['setting']['founder'];
  432. if ($response['code'] == 200) {
  433. $content = $response['content'];
  434. $worker_notice_lists = json_decode($content, JSON_OBJECT_AS_ARRAY);
  435. if (!empty($worker_notice_lists)) {
  436. foreach ($worker_notice_lists as $list) {
  437. message_notice_record($uid, MESSAGE_WORKORDER_TYPE, array(
  438. 'uuid' => $list['uuid'],
  439. 'note' => $list['note'],
  440. 'updated_at' => $list['updated_at'],
  441. ));
  442. }
  443. }
  444. }
  445. return true;
  446. }
  447. function message_sms_expire_notice() {
  448. load()->model('cloud');
  449. load()->model('setting');
  450. $setting_user_expire = setting_load('user_expire');
  451. if (empty($setting_user_expire['user_expire']['status'])) {
  452. return true;
  453. }
  454. $setting_sms_sign = setting_load('site_sms_sign');
  455. $custom_sign = !empty($setting_sms_sign['site_sms_sign']['user_expire']) ? $setting_sms_sign['site_sms_sign']['user_expire'] : '';
  456. $day = max(1, intval($setting_user_expire['user_expire']['day']));
  457. $user_table = table('users');
  458. $user_table->searchWithMobile();
  459. $user_table->searchWithEndtime($day);
  460. $user_table->where('u.endtime >', TIMESTAMP - 86400 * 7);
  461. $user_table->searchWithSendStatus();
  462. $user_table->searchWithViceFounder();
  463. $users_expire = $user_table->getUsersList();
  464. if (empty($users_expire)) {
  465. return true;
  466. }
  467. foreach ($users_expire as $v) {
  468. if (empty($v['puid'])) {
  469. continue;
  470. }
  471. if (!empty($v['mobile']) && preg_match(REGULAR_MOBILE, $v['mobile'])) {
  472. $result = cloud_sms_send($v['mobile'], '800015', array('username' => $v['username']), $custom_sign, true);
  473. if (is_error($result)) {
  474. $content = "您的用户名{$v['username']}即将过期。";
  475. $data = array('mobile' => $v['mobile'], 'content' => $content, 'result' => $result['errno'] . $result['message'], 'createtime' => TIMESTAMP);
  476. table('core_sendsms_log')->fill($data)->save();
  477. } else {
  478. $profile_table = table('users_profile');
  479. $profile = $profile_table->whereUid($v['uid'])->get();
  480. if ($profile) {
  481. $profile_table->whereId($profile['id']);
  482. }
  483. $profile_table->fill(array('send_expire_status' => 1, 'uid' => $v['uid']))->save();
  484. }
  485. }
  486. }
  487. return true;
  488. }
  489. function message_user_expire_notice() {
  490. global $_W;
  491. if (!empty($_W['user']['endtime']) && $_W['user']['endtime'] < strtotime('+7 days')) {
  492. $params = array(
  493. 'uid' => $_W['user']['uid'],
  494. 'username' => $_W['user']['username'],
  495. 'end_time' => $_W['user']['endtime'],
  496. );
  497. $result = message_notice_record($_W['uid'], MESSAGE_USER_EXPIRE_TYPE, $params);
  498. if (is_error($result) && $result['errno'] == 3) {
  499. message_notice_record($_W['config']['setting']['founder'], MESSAGE_USER_EXPIRE_TYPE, $params);
  500. }
  501. }
  502. return true;
  503. }
  504. function message_sms_account_expire_notice() {
  505. load()->model('cloud');
  506. load()->model('setting');
  507. $setting_user_expire = setting_load('account_sms_expire');
  508. if (empty($setting_user_expire['account_sms_expire']['status'])) {
  509. return true;
  510. }
  511. $setting_sms_sign = setting_load('site_sms_sign');
  512. $custom_sign = !empty($setting_sms_sign['site_sms_sign']['account_expire']) ? $setting_sms_sign['site_sms_sign']['account_expire'] : '';
  513. $day = max(1, intval($setting_user_expire['account_sms_expire']['day']));
  514. $account_expire = table('account')
  515. ->searchWithuniAccountUsers()
  516. ->leftjoin('users_profile', 'c')
  517. ->on(array('b.uid' => 'c.uid'))
  518. ->leftjoin('uni_account', 'd')
  519. ->on('d.uniacid', 'a.uniacid')
  520. ->leftjoin('users', 'e')
  521. ->on('e.uid', 'b.uid')
  522. ->select(array('a.uniacid', 'd.name', 'c.mobile', 'e.username'))
  523. ->where(array(
  524. 'a.endtime >' => TIMESTAMP,
  525. 'a.endtime <' => TIMESTAMP + 86400 * $day,
  526. 'a.isdeleted' => 0,
  527. 'a.send_account_expire_status' => 0,
  528. 'b.role' => 'owner',
  529. 'c.mobile !=' => '',
  530. 'd.name !=' => '',
  531. 'e.endtime >' => TIMESTAMP
  532. ))
  533. ->getall();
  534. if (empty($account_expire)) {
  535. return true;
  536. }
  537. foreach ($account_expire as $v) {
  538. if (!empty($v['mobile']) && preg_match(REGULAR_MOBILE, $v['mobile'])) {
  539. $result = cloud_sms_send($v['mobile'], '800016', array('name' => $v['name']), $custom_sign, true);
  540. if (is_error($result)) {
  541. $content = "您的平台账号{$v['name']}即将过期,为了不影响正常使用,请及时联系管理员。";
  542. $data = array('mobile' => $v['mobile'], 'content' => $content, 'result' => $result['errno'] . $result['message'], 'createtime' => TIMESTAMP);
  543. table('core_sendsms_log')->fill($data)->save();
  544. } else {
  545. $profile_table = table('account');
  546. $profile = $profile_table->getByUniacid($v['uniacid']);
  547. if ($profile) {
  548. $profile_table->where('uniacid', $v['uniacid']);
  549. }
  550. $profile_table->fill(array('send_account_expire_status' => 1))->save();
  551. }
  552. }
  553. }
  554. return true;
  555. }
  556. function message_sms_api_account_expire_notice() {
  557. load()->model('cloud');
  558. load()->model('setting');
  559. $setting_api_expire = setting_load('api_sms_expire');
  560. if (empty($setting_api_expire['api_sms_expire']['status'])) {
  561. return true;
  562. }
  563. $setting_sms_sign = setting_load('site_sms_sign');
  564. $custom_sign = !empty($setting_sms_sign['site_sms_sign']['api_expire']) ? $setting_sms_sign['site_sms_sign']['api_expire'] : '';
  565. $num = max(1, intval($setting_api_expire['api_sms_expire']['num']));
  566. $account_expire = table('account')
  567. ->searchWithuniAccountUsers()
  568. ->leftjoin('users_profile', 'c')
  569. ->on(array('b.uid' => 'c.uid'))
  570. ->leftjoin('uni_account', 'd')
  571. ->on('d.uniacid', 'a.uniacid')
  572. ->leftjoin('users', 'e')
  573. ->on('e.uid', 'b.uid')
  574. ->select(array('a.uniacid', 'd.name', 'c.mobile'))
  575. ->where(array(
  576. 'a.endtime >' => TIMESTAMP,
  577. 'a.isdeleted' => 0,
  578. 'a.send_api_expire_status' => 0,
  579. 'b.role' => 'owner',
  580. 'c.mobile !=' => '',
  581. 'd.name !=' => '',
  582. 'e.endtime >' => TIMESTAMP
  583. ))
  584. ->getall();
  585. if (empty($account_expire)) {
  586. return true;
  587. }
  588. foreach ($account_expire as $v) {
  589. if (!empty($v['mobile']) && preg_match(REGULAR_MOBILE, $v['mobile'])) {
  590. $statistics_setting = (array) uni_setting_load(array('statistics'), $v['uniacid']);
  591. $statistics_setting = !empty($statistics_setting['statistics']) ? $statistics_setting['statistics'] : array();
  592. if (empty($statistics_setting) || empty($statistics_setting['founder'])) {
  593. continue;
  594. }
  595. $highest_api_visit = $statistics_setting['founder'];
  596. $month_use = 0;
  597. $stat_visit_teble = table('stat_visit');
  598. $stat_visit_teble->searchWithGreaterThenDate(date('Ym01'));
  599. $stat_visit_teble->searchWithLessThenDate(date('Ymt'));
  600. $stat_visit_teble->searchWithType('app');
  601. $stat_visit_teble->searchWithUnacid($v['uniacid']);
  602. $visit_list = $stat_visit_teble->getall();
  603. if (!empty($visit_list)) {
  604. foreach ($visit_list as $key => $val) {
  605. $month_use += $val['count'];
  606. }
  607. }
  608. $api_remain_num = empty($statistics_setting['use']) ? $highest_api_visit : ($highest_api_visit - $statistics_setting['use']);
  609. if ($api_remain_num > $num) {
  610. continue;
  611. }
  612. $result = cloud_sms_send($v['mobile'], '800017', array('name' => $v['name']), $custom_sign, true);
  613. if (is_error($result)) {
  614. $content = "您的平台账号{$v['name']}剩余的API流量即将耗尽,请及时购买。";
  615. $data = array('mobile' => $v['mobile'], 'content' => $content, 'result' => $result['errno'] . $result['message'], 'createtime' => TIMESTAMP);
  616. table('core_sendsms_log')->fill($data)->save();
  617. } else {
  618. $profile_table = table('account');
  619. $profile = $profile_table->getByUniacid($v['uniacid']);
  620. if ($profile) {
  621. $profile_table->where('uniacid', $v['uniacid']);
  622. }
  623. $profile_table->fill(array('send_api_expire_status' => 1))->save();
  624. }
  625. }
  626. }
  627. return true;
  628. }
  629. function message_notice_record_cloud($message) {
  630. load()->classs('cloudapi');
  631. $api = new CloudApi();
  632. $result = $api->post('system', 'notify', array('json' => $message), 'html', false);
  633. return $result;
  634. }
  635. function message_wxapp_modules_version_upgrade() {
  636. global $_W;
  637. load()->model('miniapp');
  638. load()->model('account');
  639. $wxapp_table = table('account');
  640. $wxapp_table->searchWithType(array(ACCOUNT_TYPE_APP_NORMAL));
  641. $uniacid_list = $wxapp_table->searchAccountList();
  642. if (empty($uniacid_list)) {
  643. return true;
  644. }
  645. $wxapp_list = table('account_wxapp')->wxappInfo(array_keys($uniacid_list));
  646. $wxapp_modules = table('modules')->getSupportWxappList();
  647. foreach ($uniacid_list as $uniacid_info) {
  648. $account_owner = account_owner($uniacid_info['uniacid']);
  649. if (empty($account_owner) || $account_owner['uid'] != $_W['uid']) {
  650. continue;
  651. }
  652. $uniacid_modules = miniapp_version_all($uniacid_info['uniacid']);
  653. if (empty($uniacid_modules[0]['modules'])) {
  654. continue;
  655. }
  656. foreach ($uniacid_modules[0]['modules'] as $module) {
  657. if ($module['version'] < $wxapp_modules[$module['mid']]['version']) {
  658. message_notice_record($_W['uid'], MESSAGE_WXAPP_MODULE_UPGRADE, array(
  659. 'uniacid' => $uniacid_info['uniacid'],
  660. 'account_name' => $wxapp_list[$uniacid_info['uniacid']]['name'],
  661. 'module_name' => $module['title'],
  662. ));
  663. }
  664. }
  665. }
  666. return true;
  667. }
  668. function message_list_detail($lists) {
  669. if (empty($lists)) {
  670. return $lists;
  671. }
  672. foreach ($lists as &$message) {
  673. $message['create_time'] = date('Y-m-d H:i:s', $message['create_time']);
  674. if ($message['type'] != MESSAGE_SYSTEM_UPGRADE && $message['type'] != MESSAGE_OFFICIAL_DYNAMICS) {
  675. $message['url'] = url('message/notice');
  676. }
  677. if ($message['type'] == MESSAGE_REGISTER_TYPE) {
  678. $source_array = array('mobile' => '手动注册', 'system' => '手动注册', 'qq' => 'QQ 注册', 'wechat' => '微信注册', 'admin' => '管理员添加');
  679. $msg = explode('--', $message['message']);
  680. if (count($msg) > 1 && !empty($source_array[$msg[1]])) {
  681. $message['message'] = $msg[0];
  682. $message['source'] = $source_array[$msg[1]];
  683. }
  684. }
  685. }
  686. return $lists;
  687. }