notice.ctrl.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. load()->model('message');
  8. $dos = array('display', 'change_read_status', 'event_notice', 'all_read', 'setting', 'read', 'wechat_setting');
  9. $do = in_array($do, $dos) ? $do : 'display';
  10. if (in_array($do, array('display', 'all_read'))) {
  11. $type = $types = intval($_GPC['type']);
  12. if ($type == MESSAGE_ACCOUNT_EXPIRE_TYPE) {
  13. $types = array(MESSAGE_ACCOUNT_EXPIRE_TYPE, MESSAGE_WECHAT_EXPIRE_TYPE, MESSAGE_WEBAPP_EXPIRE_TYPE);
  14. }
  15. if ($type == MESSAGE_ORDER_TYPE) {
  16. $types = array(MESSAGE_ORDER_TYPE, MESSAGE_ORDER_APPLY_REFUND_TYPE);
  17. }
  18. if (empty($type) && (!user_is_founder($_W['uid']) || user_is_vice_founder())){
  19. $types = array(MESSAGE_ACCOUNT_EXPIRE_TYPE, MESSAGE_WECHAT_EXPIRE_TYPE, MESSAGE_WEBAPP_EXPIRE_TYPE, MESSAGE_USER_EXPIRE_TYPE, MESSAGE_WXAPP_MODULE_UPGRADE);
  20. }
  21. }
  22. if ($do == 'display') {
  23. $message_id = intval($_GPC['message_id']);
  24. message_notice_read($message_id);
  25. $pindex = max(intval($_GPC['page']), 1);
  26. $psize = 10;
  27. $message_table = table('core_message_notice_log');
  28. $is_read = !empty($_GPC['is_read']) ? intval($_GPC['is_read']) : '';
  29. if (!empty($is_read)) {
  30. $message_table->searchWithIsRead($is_read);
  31. }
  32. if (user_is_founder($_W['uid'], true)) {
  33. if (!empty($types)) {
  34. $message_table->searchWithType($types);
  35. } else {
  36. $message_table->searchWithOutType(array(MESSAGE_USER_EXPIRE_TYPE, MESSAGE_ORDER_WISH_TYPE));
  37. }
  38. } else {
  39. $message_table->searchWithUid($_W['uid']);
  40. $message_table->searchWithType(array(
  41. MESSAGE_ACCOUNT_EXPIRE_TYPE,
  42. MESSAGE_WECHAT_EXPIRE_TYPE,
  43. MESSAGE_WEBAPP_EXPIRE_TYPE,
  44. MESSAGE_USER_EXPIRE_TYPE,
  45. MESSAGE_WXAPP_MODULE_UPGRADE,
  46. MESSAGE_SYSTEM_UPGRADE,
  47. MESSAGE_OFFICIAL_DYNAMICS,
  48. MESSAGE_ORDER_WISH_TYPE,
  49. ));
  50. }
  51. $message_table->searchWithPage($pindex, $psize);
  52. $lists = $message_table->orderby('id', 'DESC')->getall();
  53. $lists = message_list_detail($lists);
  54. $total = $message_table->getLastQueryTotal();
  55. $pager = pagination($total, $pindex, $psize);
  56. $wechat_setting = setting_load('message_wechat_notice_setting');
  57. $wechat_setting = $wechat_setting['message_wechat_notice_setting'];
  58. if (!empty($wechat_setting['uniacid'])) {
  59. $uni_account = table('account')->getUniAccountByUniacid($wechat_setting['uniacid']);
  60. $uni_account['qrcode'] = tomedia('qrcode_'. $uni_account['acid'] . '.jpg') . '?time='.$_W['timestamp'];
  61. }
  62. }
  63. if ($do == 'change_read_status') {
  64. $id = $_GPC['id'];
  65. message_notice_read($id);
  66. iajax(0, '成功');
  67. }
  68. if ($do == 'event_notice') {
  69. if (user_is_founder($_W['uid'], true)) {
  70. message_store_notice();
  71. }
  72. $message = message_event_notice_list();
  73. $cookie_name = $_W['config']['cookie']['pre'] . '__notice';
  74. if (empty($_COOKIE[$cookie_name]) || $_COOKIE[$cookie_name] < TIMESTAMP) {
  75. message_account_expire();
  76. message_notice_worker();
  77. message_sms_expire_notice();
  78. message_user_expire_notice();
  79. message_wxapp_modules_version_upgrade();
  80. }
  81. iajax(0, $message);
  82. }
  83. if ($do == 'read') {
  84. $message_id = pdo_getcolumn('message_notice_log', array('id' => intval($_GPC['id'])), 'id');
  85. if (!empty($message_id)) {
  86. pdo_update('message_notice_log', array('is_read' => MESSAGE_READ), array('id' => $message_id));
  87. }
  88. iajax(0, '已标记已读');
  89. }
  90. if ($do == 'all_read') {
  91. message_notice_all_read($types);
  92. if ($_W['isajax']) {
  93. iajax(0, '全部已读', url('message/notice', array('type' => $type)));
  94. }
  95. itoast('', referer());
  96. }
  97. if ($do == 'setting') {
  98. $setting = message_setting($_W['uid']);
  99. $notice_setting = $_W['user']['notice_setting'];
  100. foreach ($setting as &$value) {
  101. foreach ($value['types'] as $type => $item) {
  102. $value['types'][$type]['status'] = empty($notice_setting[$type]) ? MESSAGE_ENABLE : $notice_setting[$type];
  103. }
  104. }
  105. if (!user_is_founder($_W['uid'], true)) {
  106. $founder_notice_setting = table('users')->getNoticeSettingByUid($_W['config']['setting']['founder']);
  107. }
  108. $type = intval($_GPC['type']);
  109. if (!empty($type)) {
  110. $notice_setting[$type] = empty($notice_setting[$type]) || $notice_setting[$type] == MESSAGE_ENABLE ? MESSAGE_DISABLE : MESSAGE_ENABLE;
  111. user_update(array('uid' => $_W['uid'], 'notice_setting' => $notice_setting));
  112. iajax(0, '更新成功', url('message/notice/setting'));
  113. }
  114. }
  115. if ($do == 'wechat_setting') {
  116. if (!user_is_founder($_W['uid'], true)) {
  117. itoast('无权限', referer(), 'error');
  118. }
  119. $uniacid = intval($_GPC['uniacid']);
  120. $template = safe_gpc_array($_GPC['tpl']);
  121. $wechat_setting = setting_load('message_wechat_notice_setting');
  122. $wechat_setting = $wechat_setting['message_wechat_notice_setting'];
  123. if (!empty($_GPC['delete'])) {
  124. $wechat_setting = array(
  125. 'uniacid' => 0,
  126. 'template' => array('order' => '', 'expire' => '', 'register' => '', 'work' => '', 'upgrade' => '', 'message' => '')
  127. );
  128. setting_save($wechat_setting, 'message_wechat_notice_setting');
  129. itoast('', referer(), 'success');
  130. }
  131. if (!empty($uniacid)) {
  132. $wechat_setting = array(
  133. 'uniacid' => $uniacid,
  134. 'template' => array('order' => '', 'expire' => '', 'register' => '', 'work' => '', 'upgrade' => '', 'message' => '')
  135. );
  136. setting_save($wechat_setting, 'message_wechat_notice_setting');
  137. iajax(0, '操作成功');
  138. }
  139. if (!empty($template)) {
  140. foreach ($template as $type => $tpl) {
  141. if (!empty($tpl['tpl']) && !preg_match('/^[a-zA-Z0-9_-]{43}$/', $tpl['tpl'])) {
  142. $error = $tpl['name'];
  143. break;
  144. }
  145. $wechat_setting['template'][$type] = $tpl['tpl'];
  146. }
  147. setting_save($wechat_setting, 'message_wechat_notice_setting');
  148. if (empty($error)) {
  149. iajax(0, '');
  150. } else {
  151. iajax(1, $error);
  152. }
  153. }
  154. if (!empty($wechat_setting['uniacid'])) {
  155. $uni_account = uni_fetch($wechat_setting['uniacid']);
  156. $account = $uni_account->account;
  157. $account['logo'] = $uni_account->logo;
  158. $account['switchurl'] = $uni_account->switchurl;
  159. }
  160. if (!empty($wechat_setting['uniacid'])) {
  161. $tpl_list = array(
  162. 'order' => array(
  163. 'tpl' => $wechat_setting['template']['order'],
  164. 'name' => '新订单提醒',
  165. 'help' => '请在微信公众平台选择行业为:“IT科技 - 互联网|电子商务”,添加标题为:”新订单提醒“,编号为:“OPENTM400045127”的模板。',
  166. ),
  167. 'order_pay' => array(
  168. 'tpl' => $wechat_setting['template']['order_pay'],
  169. 'name' => '订单支付成功通知',
  170. 'help' => '请在微信公众平台选择行业为:“IT科技 - 互联网|电子商务”,添加标题为:”支付成功提醒“,编号为:“OPENTM409997121”的模板。',
  171. ),
  172. 'expire' => array(
  173. 'tpl' => $wechat_setting['template']['expire'],
  174. 'name' => '账号到期消息',
  175. 'help' => '请在微信公众平台选择行业为:“IT科技 - 互联网|电子商务”,添加标题为:”服务到期提醒“,编号为:“OPENTM408237933”的模板。',
  176. ),
  177. 'register' => array(
  178. 'tpl' => $wechat_setting['template']['register'],
  179. 'name' => '注册提醒',
  180. 'help' => '请在微信公众平台选择行业为:“IT科技 - 互联网|电子商务”,添加标题为:”注册成功通知“,编号为:“OPENTM409879450”的模板。',
  181. ),
  182. 'work_order' => array(
  183. 'tpl' => $wechat_setting['template']['work_order'],
  184. 'name' => '工单提醒',
  185. 'help' => '请在微信公众平台选择行业为:“IT科技 - 互联网|电子商务”,添加标题为:”新工单提醒“,编号为:“OPENTM407358460”的模板。',
  186. ),
  187. );
  188. }
  189. $accounts = uni_user_accounts($_W['uid'], 'account');
  190. foreach ($accounts as $k => $item) {
  191. if ($item['level'] != ACCOUNT_SERVICE_VERIFY) {
  192. unset($accounts[$k]);
  193. } else {
  194. $accounts[$k]['logo'] = is_file(IA_ROOT . '/attachment/headimg_' . $item['acid'] . '.jpg') ? tomedia('headimg_'.$item['acid']. '.jpg').'?time='.time() : './resource/images/nopic-107.png';
  195. }
  196. }
  197. }
  198. template('message/notice');