Membermessage.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. use think\facade\Db;
  6. /**
  7. *
  8. *
  9. * ----------------------------------------------------------------------------
  10. *
  11. * 控制器
  12. */
  13. class Membermessage extends BaseMember
  14. {
  15. public function initialize()
  16. {
  17. parent::initialize(); // TODO: Change the autogenerated stub
  18. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/membermessage.lang.php');
  19. }
  20. /**
  21. * 收到(普通)站内信列表
  22. *
  23. * @param
  24. * @return
  25. */
  26. public function message()
  27. {
  28. $message_model = model('message');
  29. $message_array = $message_model->getMessageList(array('message_type' => '2', 'to_member_id_common' => session('member_id'), 'no_message_state' => '2'), 10);
  30. View::assign('show_page', $message_model->page_info->render());
  31. View::assign('message_array', $message_array);
  32. // 新消息数量
  33. $this->showReceivedNewNum();
  34. View::assign('drop_type', 'msg_list');
  35. $this->setMemberCurItem('message');
  36. $this->setMemberCurMenu('member_message');
  37. return View::fetch($this->template_dir . 'message');
  38. }
  39. /**
  40. * 收到(私信)站内信列表
  41. *
  42. * @param
  43. * @return
  44. */
  45. public function personalmsg()
  46. {
  47. $message_model = model('message');
  48. $message_array = $message_model->getMessageList(array('message_type' => '0', 'to_member_id_common' => session('member_id'), 'no_message_state' => '2'), 10);
  49. View::assign('show_page', $message_model->page_info->render());
  50. View::assign('message_array', $message_array);
  51. // 新消息数量
  52. $this->showReceivedNewNum();
  53. View::assign('drop_type', 'msg_list');
  54. $this->setMemberCurItem('close');
  55. $this->setMemberCurMenu('member_message');
  56. return View::fetch($this->template_dir . 'message');
  57. }
  58. /**
  59. * 查询会员是否允许发送站内信
  60. *
  61. * @return bool
  62. */
  63. private function allowSendMessage($member_id)
  64. {
  65. $member_info = model('member')->getMemberInfoByID($member_id);
  66. if ($member_info['is_allowtalk'] == '1') {
  67. return true;
  68. } else {
  69. return false;
  70. }
  71. }
  72. /**
  73. * 私人站内信列表
  74. *
  75. * @param
  76. * @return
  77. */
  78. public function privatemsg()
  79. {
  80. $message_model = model('message');
  81. $message_array = $message_model->getMessageList(array('message_type_in' => '0,2', 'from_member_id' => session('member_id'), 'no_message_state' => '1'), 10);
  82. View::assign('show_page', $message_model->page_info->render());
  83. View::assign('message_array', $message_array);
  84. // 新消息数量
  85. $this->showReceivedNewNum();
  86. View::assign('drop_type', 'msg_private');
  87. $this->setMemberCurItem('private');
  88. $this->setMemberCurMenu('member_message');
  89. return View::fetch($this->template_dir . 'sendlist');
  90. }
  91. /**
  92. * 系统站内信列表
  93. *
  94. * @param
  95. * @return
  96. */
  97. public function systemmsg()
  98. {
  99. $message_model = model('message');
  100. $message_array = $message_model->getMessageList(array('from_member_id' => '0', 'message_type' => '1', 'to_member_id' => session('member_id'), 'no_del_member_id' => session('member_id')), 10);
  101. if (!empty($message_array) && is_array($message_array)) {
  102. foreach ($message_array as $k => $v) {
  103. $v['message_open'] = '0';
  104. if (!empty($v['read_member_id'])) {
  105. $tmp_readid_arr = explode(',', $v['read_member_id']);
  106. if (in_array(session('member_id'), $tmp_readid_arr)) {
  107. $v['message_open'] = '1';
  108. }
  109. }
  110. $v['from_member_name'] = lang('home_message_system_message');
  111. $message_array[$k] = $v;
  112. }
  113. }
  114. View::assign('show_page', $message_model->page_info->render());
  115. View::assign('message_array', $message_array);
  116. // 新消息数量
  117. $this->showReceivedNewNum();
  118. View::assign('drop_type', 'msg_system');
  119. $this->setMemberCurItem('system');
  120. $this->setMemberCurMenu('member_message');
  121. return View::fetch($this->template_dir . 'message');
  122. }
  123. /**
  124. * 发送站内信页面
  125. *
  126. * @param
  127. * @return
  128. */
  129. public function sendmsg()
  130. {
  131. $referer_url = get_referer();
  132. //查询会员是否允许发送站内信
  133. $isallowsend = $this->allowSendMessage(session('member_id'));
  134. if (!$isallowsend) {
  135. $this->error(lang('home_message_noallowsend'));
  136. }
  137. $member_model = model('member');
  138. $member_name_string = '';
  139. $member_id = intval(input('param.member_id'));
  140. if ($member_id > 0) {
  141. //连接发放站内信页面
  142. $member_info = $member_model->getMemberInfoByID($member_id);
  143. if (empty($member_info)) {
  144. $this->error(lang('param_error'));
  145. }
  146. $member_name_string = $member_info['member_name'];
  147. View::assign('member_name', $member_name_string);
  148. }
  149. //批量给好友发放站内信页面
  150. $friend_model = model('snsfriend');
  151. $friend_list = $friend_model->getSnsfriendList(array('friend_frommid' => session('member_id')));
  152. View::assign('friend_list', $friend_list);
  153. // 新消息数量
  154. $this->showReceivedNewNum();
  155. $this->setMemberCurItem('sendmsg');
  156. $this->setMemberCurMenu('member_message');
  157. return View::fetch($this->template_dir . 'send');
  158. }
  159. /**
  160. * 站内信保存操作
  161. *
  162. * @param
  163. * @return
  164. */
  165. public function savemsg()
  166. {
  167. //查询会员是否允许发送站内信
  168. $isallowsend = $this->allowSendMessage(session('member_id'));
  169. if (!$isallowsend) {
  170. ds_json_encode(10001, lang('home_message_noallowsend'));
  171. }
  172. $data = [
  173. 'to_member_name' => input('post.to_member_name'),
  174. 'msg_content' => input('post.msg_content')
  175. ];
  176. $message_validate = ds_validate('message');
  177. if (!$message_validate->scene('savemsg')->check($data)) {
  178. ds_json_encode(10001, $message_validate->getError());
  179. }
  180. $msg_content = trim(input('post.msg_content'));
  181. $membername_arr = explode(',', input('post.to_member_name'));
  182. if (in_array(session('member_name'), $membername_arr)) {
  183. unset($membername_arr[array_search(session('member_name'), $membername_arr)]);
  184. }
  185. //查询有效会员
  186. $member_model = model('member');
  187. $member_list = $member_model->getMemberList(array(array('member_name', 'in', $membername_arr)));
  188. if (!empty($member_list)) {
  189. $message_model = model('message');
  190. foreach ($member_list as $k => $v) {
  191. $insert_arr = array();
  192. $insert_arr['from_member_id'] = session('member_id');
  193. $insert_arr['from_member_name'] = session('member_name');
  194. $insert_arr['member_id'] = $v['member_id'];
  195. $insert_arr['to_member_name'] = $v['member_name'];
  196. $insert_arr['msg_content'] = $msg_content;
  197. $insert_arr['message_type'] = intval(input('post.msg_type'));
  198. $message_model->addMessage($insert_arr);
  199. }
  200. } else {
  201. ds_json_encode(10001, lang('home_message_receiver_error'));
  202. }
  203. ds_json_encode(10000, lang('home_message_send_success'));
  204. }
  205. /**
  206. * 普通站内信查看操作
  207. *
  208. * @param
  209. * @return
  210. */
  211. public function showmsgcommon()
  212. {
  213. $message_model = model('message');
  214. $message_id = intval(input('param.message_id'));
  215. $drop_type = trim(input('param.type'));
  216. if (!in_array($drop_type, array('msg_list')) || $message_id <= 0) {
  217. $this->error(lang('param_error'));
  218. }
  219. //查询站内信
  220. $special_condition = array();
  221. $special_condition['message_id'] = "$message_id";
  222. $special_condition['to_member_id_common'] = session('member_id');
  223. $special_condition['no_message_state'] = "2";
  224. $message_info = $message_model->getOneMessage($special_condition);
  225. if (empty($message_info)) {
  226. $this->error(lang('home_message_no_record'));
  227. }
  228. unset($special_condition);
  229. if ($message_info['message_parent_id'] > 0) {
  230. //查询该站内信的父站内信
  231. $parent_array = $message_model->getOneMessage(array('message_id' => "{$message_info['message_parent_id']}", 'message_type' => '0', 'no_message_state' => '2'));
  232. //查询该站内信的回复站内信
  233. $reply_array = $message_model->getMessageList(array('message_parent_id' => "{$message_info['message_parent_id']}", 'message_type' => '0', 'no_message_state' => '2'));
  234. } else { //此信息为父站内信
  235. $parent_array = $message_info;
  236. //查询回复站内信
  237. $reply_array = $message_model->getMessageList(array('message_parent_id' => "$message_id", 'message_type' => '0', 'no_message_state' => '2'));
  238. }
  239. //处理获取站内信数组
  240. $message_list = array();
  241. if (!empty($reply_array)) {
  242. foreach ($reply_array as $k => $v) {
  243. $message_list[$v['message_id']] = $v;
  244. }
  245. }
  246. if (!empty($parent_array)) {
  247. $message_list[$parent_array['message_id']] = $parent_array;
  248. }
  249. unset($parent_array);
  250. unset($reply_array);
  251. //更新已读状态
  252. $messageid_arr = array_keys($message_list);
  253. if (!empty($messageid_arr)) {
  254. $messageid_str = "'" . implode("','", $messageid_arr) . "'";
  255. $message_model->editCommonMessage(array('message_open' => '1'), array('message_id_in' => "$messageid_str"));
  256. }
  257. //更新未读站内信数量cookie值
  258. $cookie_name = 'msgnewnum' . session('member_id');
  259. $countnum = $message_model->getNewMessageCount(session('member_id'));
  260. Cookie($cookie_name, $countnum, 2 * 3600); //保存2小时
  261. View::assign('message_num', $countnum);
  262. View::assign('message_id', $message_id); //点击的该条站内信编号
  263. View::assign('message_list', $message_list); //站内信列表
  264. // 新消息数量
  265. $this->showReceivedNewNum();
  266. View::assign('drop_type', $drop_type);
  267. $this->setMemberCurMenu('member_message');
  268. $this->setMemberCurItem('showmsg');
  269. return View::fetch($this->template_dir . 'view');
  270. }
  271. /**
  272. * 系统站内信查看操作
  273. *
  274. * @param
  275. * @return
  276. */
  277. public function showmsgbatch()
  278. {
  279. $message_model = model('message');
  280. $message_id = intval(input('param.message_id'));
  281. $drop_type = trim(input('param.type'));
  282. if (!in_array($drop_type, array('msg_system', 'msg_seller')) || $message_id <= 0) {
  283. $this->error(lang('param_error'));
  284. }
  285. //查询站内信
  286. $special_condition = array();
  287. $special_condition['message_id'] = $message_id;
  288. $special_condition['to_member_id'] = session('member_id');
  289. $special_condition['no_del_member_id'] = session('member_id');
  290. $message_info = $message_model->getOneMessage($special_condition);
  291. if (empty($message_info)) {
  292. $this->error(lang('home_message_no_record'));
  293. }
  294. if ($drop_type == 'msg_system') {
  295. $message_info['from_member_name'] = lang('home_message_system_message');
  296. }
  297. if ($drop_type == 'msg_seller') {
  298. //查询店铺信息
  299. $store_model = model('store');
  300. $store_info = $store_model->getStoreInfo(array('member_id' => "{$message_info['from_member_id']}"));
  301. $message_info['from_member_name'] = $store_info['store_name'];
  302. $message_info['store_id'] = $store_info['store_id'];
  303. }
  304. $message_list[0] = $message_info;
  305. View::assign('message_list', $message_list); //站内信列表
  306. //更新为已读信息
  307. $tmp_readid_str = '';
  308. if (!empty($message_info['read_member_id'])) {
  309. $tmp_readid_arr = explode(',', $message_info['read_member_id']);
  310. if (!in_array(session('member_id'), $tmp_readid_arr)) {
  311. $tmp_readid_arr[] = session('member_id');
  312. }
  313. foreach ($tmp_readid_arr as $readid_k => $readid_v) {
  314. if ($readid_v == '') {
  315. unset($tmp_readid_arr[$readid_k]);
  316. }
  317. }
  318. $tmp_readid_arr = array_unique($tmp_readid_arr); //去除相同
  319. sort($tmp_readid_arr); //排序
  320. $tmp_readid_str = "," . implode(',', $tmp_readid_arr) . ",";
  321. } else {
  322. $tmp_readid_str = "," . session('member_id') . ",";
  323. }
  324. $message_model->editCommonMessage(array('read_member_id' => $tmp_readid_str), array('message_id' => "{$message_id}"));
  325. //更新未读站内信数量cookie值
  326. $cookie_name = 'msgnewnum' . session('member_id');
  327. $countnum = $message_model->getNewMessageCount(session('member_id'));
  328. Cookie($cookie_name, $countnum, 2 * 3600); //保存2小时
  329. View::assign('message_num', $countnum);
  330. // 新消息数量
  331. $this->showReceivedNewNum();
  332. View::assign('drop_type', $drop_type);
  333. $this->setMemberCurMenu('member_message');
  334. $this->setMemberCurItem('system');
  335. return View::fetch($this->template_dir . 'view');
  336. }
  337. /**
  338. * 短消息回复保存
  339. *
  340. * @param
  341. * @return
  342. */
  343. public function savereply()
  344. {
  345. //查询会员是否允许发送站内信
  346. $isallowsend = $this->allowSendMessage(session('member_id'));
  347. if (!$isallowsend) {
  348. ds_json_encode(10001, lang('home_message_noallowsend'));
  349. }
  350. if (request()->isPost()) {
  351. $message_id = intval(input('post.message_id'));
  352. if ($message_id <= 0) {
  353. $this->error(lang('param_error'), (string)url('Membermessage/message'));
  354. }
  355. if (empty(input('post.msg_content'))) {
  356. ds_json_encode(10001, lang('home_message_reply_content_null'));
  357. }
  358. $message_model = model('message');
  359. //查询站内信
  360. $special_condition = array();
  361. $special_condition['message_id'] = "$message_id";
  362. $special_condition['no_message_state'] = "2"; //未删除
  363. $message_info = $message_model->getOneMessage($special_condition);
  364. if (empty($message_info)) {
  365. ds_json_encode(10001, lang('home_message_no_record'));
  366. }
  367. //不能回复自己的站内信
  368. if ($message_info['from_member_id'] == session('member_id')) {
  369. ds_json_encode(10001, lang('home_message_no_record'));
  370. }
  371. $insert_arr = array();
  372. if ($message_info['message_parent_id'] > 0) {
  373. $insert_arr['message_parent_id'] = $message_info['message_parent_id'];
  374. } else {
  375. $insert_arr['message_parent_id'] = $message_info['message_id'];
  376. }
  377. $insert_arr['from_member_id'] = session('member_id');
  378. $insert_arr['from_member_name'] = session('member_name');
  379. $insert_arr['member_id'] = $message_info['from_member_id'];
  380. $insert_arr['to_member_name'] = $message_info['from_member_name'];
  381. $insert_arr['msg_content'] = input('post.msg_content');
  382. $insert_state = $message_model->addMessage($insert_arr);
  383. if ($insert_state) {
  384. //更新父类站内信更新时间
  385. $update_arr = array();
  386. $update_arr['message_update_time'] = TIMESTAMP;
  387. $update_arr['message_open'] = 1;
  388. $message_model->editCommonMessage($update_arr, array('message_id' => "{$insert_arr['message_parent_id']}"));
  389. }
  390. ds_json_encode(10000, lang('home_message_send_success'));
  391. } else {
  392. ds_json_encode(10001, lang('home_message_reply_command_wrong'));
  393. }
  394. }
  395. /**
  396. * 删除普通信
  397. */
  398. public function dropcommonmsg()
  399. {
  400. $message_id = trim(input('param.message_id'));
  401. $drop_type = trim(input('param.drop_type'));
  402. if (!in_array($drop_type, array('msg_private', 'msg_list', 'sns_msg')) || empty($message_id)) {
  403. ds_json_encode(10001, lang('param_error'));
  404. }
  405. $messageid_arr = explode(',', $message_id);
  406. $messageid_str = '';
  407. if (!empty($messageid_arr)) {
  408. $messageid_str = "'" . implode("','", $messageid_arr) . "'";
  409. }
  410. $message_model = model('message');
  411. $special_condition = array('message_id_in' => $messageid_str);
  412. if ($drop_type == 'msg_private') {
  413. $special_condition['from_member_id'] = session('member_id');
  414. } elseif ($drop_type == 'msg_list') {
  415. $special_condition['to_member_id_common'] = session('member_id');
  416. } elseif ($drop_type == 'sns_msg') {
  417. $special_condition['from_to_member_id'] = session('member_id');
  418. }
  419. $drop_state = $message_model->delCommonMessage($special_condition, $drop_type);
  420. if ($drop_state) {
  421. //更新未读站内信数量cookie值
  422. $cookie_name = 'msgnewnum' . session('member_id');
  423. $countnum = $message_model->getNewMessageCount(session('member_id'));
  424. cookie($cookie_name, $countnum, 2 * 3600); //保存2小时
  425. ds_json_encode(10000, lang('home_message_delete_success'));
  426. } else {
  427. ds_json_encode(10001, lang('home_message_delete_fail'));
  428. }
  429. }
  430. /**
  431. * 删除批量站内信
  432. */
  433. public function dropbatchmsg()
  434. {
  435. $message_id = trim(input('param.message_id'));
  436. $drop_type = trim(input('param.drop_type'));
  437. if (!in_array($drop_type, array('msg_system', 'msg_seller')) || empty($message_id)) {
  438. ds_json_encode(10001, lang('home_message_delete_request_wrong'));
  439. }
  440. $messageid_arr = explode(',', $message_id);
  441. $messageid_str = '';
  442. if (!empty($messageid_arr)) {
  443. $messageid_str = "'" . implode("','", $messageid_arr) . "'";
  444. }
  445. $message_model = model('message');
  446. $special_condition = array('message_id_in' => $messageid_str);
  447. if ($drop_type == 'msg_system') {
  448. $special_condition['message_type'] = '1';
  449. $special_condition['from_member_id'] = '0';
  450. }
  451. if ($drop_type == 'msg_seller') {
  452. $special_condition['message_type'] = '2';
  453. }
  454. $drop_state = $message_model->delBatchMessage($special_condition, session('member_id'));
  455. if ($drop_state) {
  456. //更新未读站内信数量cookie值
  457. $cookie_name = 'msgnewnum' . session('member_id');
  458. $countnum = $message_model->getNewMessageCount(session('member_id'));
  459. Cookie($cookie_name, $countnum, 2 * 3600); //保存2小时
  460. ds_json_encode(10000, lang('home_message_delete_success'));
  461. } else {
  462. ds_json_encode(10001, lang('home_message_delete_fail'));
  463. }
  464. }
  465. /**
  466. * 消息接收设置
  467. *
  468. * 注意:由于用户消息模板不是循环输出,所以每增加一种消息模板,
  469. * 都需要在模板(member_message_setting)中需要手工添加该消息模板的选项卡,
  470. * 在control部分也要添加相关的验证,否则默认开启无法关闭。
  471. */
  472. public function setting()
  473. {
  474. $membermsgsetting_model = model('membermsgsetting');
  475. $insert = array(
  476. // 付款成功提醒
  477. array(
  478. 'membermt_code' => 'order_payment_success', 'member_id' => session('member_id'),
  479. 'membermt_isreceive' => intval(input('post.order_payment_success', '0'))
  480. ), // 商品出库提醒
  481. array(
  482. 'membermt_code' => 'order_deliver_success', 'member_id' => session('member_id'),
  483. 'membermt_isreceive' => intval(input('post.order_deliver_success', '0'))
  484. ), // 余额变动提醒
  485. array(
  486. 'membermt_code' => 'predeposit_change', 'member_id' => session('member_id'),
  487. 'membermt_isreceive' => intval(input('post.predeposit_change', '0'))
  488. ), // 充值卡余额变动提醒
  489. array(
  490. 'membermt_code' => 'recharge_card_balance_change', 'member_id' => session('member_id'),
  491. 'membermt_isreceive' => intval(input('post.recharge_card_balance_change', '0'))
  492. ), // 代金券使用提醒
  493. array(
  494. 'membermt_code' => 'voucher_use', 'member_id' => session('member_id'),
  495. 'membermt_isreceive' => intval(input('post.voucher_use', '0'))
  496. ), // 退款退货提醒
  497. array(
  498. 'membermt_code' => 'refund_return_notice', 'member_id' => session('member_id'),
  499. 'membermt_isreceive' => intval(input('post.refund_return_notice', '0'))
  500. ), // 到货通知提醒
  501. array(
  502. 'membermt_code' => 'arrival_notice', 'member_id' => session('member_id'),
  503. 'membermt_isreceive' => intval(input('post.arrival_notice', '0'))
  504. ), // 商品咨询回复提醒
  505. array(
  506. 'membermt_code' => 'consult_goods_reply', 'member_id' => session('member_id'),
  507. 'membermt_isreceive' => intval(input('post.consult_goods_reply', '0'))
  508. ), // 平台客服回复提醒
  509. array(
  510. 'membermt_code' => 'consult_mall_reply', 'member_id' => session('member_id'),
  511. 'membermt_isreceive' => intval(input('post.consult_mall_reply', '0'))
  512. ), // 代金券即将到期
  513. array(
  514. 'membermt_code' => 'voucher_will_expire', 'member_id' => session('member_id'),
  515. 'membermt_isreceive' => intval(input('post.voucher_will_expire', '0'))
  516. ), // 兑换码即将到期提醒
  517. array(
  518. 'membermt_code' => 'vr_code_will_expire', 'member_id' => session('member_id'),
  519. 'membermt_isreceive' => intval(input('post.vr_code_will_expire', '0'))
  520. ),
  521. );
  522. if (request()->isPost()) {
  523. Db::name('membermsgsetting')->where(array('member_id' => session('member_id')))->delete();
  524. $result = $membermsgsetting_model->addMembermsgsettingAll($insert);
  525. if ($result) {
  526. ds_json_encode(10000, lang('ds_common_save_succ'));
  527. } else {
  528. ds_json_encode(10001, lang('ds_common_save_fail'));
  529. }
  530. }
  531. // 新消息数量
  532. $this->showReceivedNewNum();
  533. $setting_list = $membermsgsetting_model->getMembermsgsettingList(array('member_id' => session('member_id')));
  534. if (empty($setting_list)) {
  535. $setting_list = $insert;
  536. }
  537. $setting_array = array();
  538. if (!empty($setting_list)) {
  539. foreach ($setting_list as $val) {
  540. $setting_array[$val['membermt_code']] = intval($val['membermt_isreceive']);
  541. }
  542. }
  543. View::assign('setting_array', $setting_array);
  544. $this->setMemberCurItem('setting');
  545. $this->setMemberCurMenu('member_message');
  546. return View::fetch($this->template_dir . 'setting');
  547. }
  548. /**
  549. * 统计未读消息
  550. */
  551. private function showReceivedNewNum()
  552. {
  553. //查询新接收到普通的消息
  554. $newcommon = $this->receivedCommonNewNum();
  555. View::assign('newcommon', $newcommon);
  556. //查询新接收到系统的消息
  557. $newsystem = $this->receivedSystemNewNum();
  558. View::assign('newsystem', $newsystem);
  559. //查询新接收到卖家的消息
  560. $newpersonal = $this->receivedPersonalNewNum();
  561. View::assign('newpersonal', $newpersonal);
  562. //查询会员是否允许发送站内信
  563. $isallowsend = $this->allowSendMessage(session('member_id'));
  564. View::assign('isallowsend', $isallowsend);
  565. }
  566. /**
  567. * 统计收到站内信未读条数
  568. *
  569. * @return int
  570. */
  571. private function receivedCommonNewNum()
  572. {
  573. $message_model = model('message');
  574. $countnum = $message_model->getMessageCount(array('message_type' => '2', 'to_member_id_common' => session('member_id'), 'no_message_state' => '2', 'message_open_common' => '0'));
  575. return $countnum;
  576. }
  577. /**
  578. * 统计系统站内信未读条数
  579. *
  580. * @return int
  581. */
  582. private function receivedSystemNewNum()
  583. {
  584. $message_model = model('message');
  585. $special_condition = array();
  586. $special_condition['message_type'] = '1'; //系统消息
  587. $special_condition['to_member_id'] = session('member_id');
  588. $special_condition['no_del_member_id'] = session('member_id');
  589. $special_condition['no_read_member_id'] = session('member_id');
  590. $countnum = $message_model->getMessageCount($special_condition);
  591. return $countnum;
  592. }
  593. /**
  594. * 统计私信未读条数
  595. *
  596. * @return int
  597. */
  598. private function receivedPersonalNewNum()
  599. {
  600. $message_model = model('message');
  601. $countnum = $message_model->getMessageCount(array('message_type' => '0', 'to_member_id_common' => session('member_id'), 'no_message_state' => '2', 'message_open_common' => '0'));
  602. return $countnum;
  603. }
  604. /**
  605. * 用户中心右边,小导航
  606. *
  607. * @param string $menu_key 当前导航的menu_key
  608. * @return
  609. */
  610. protected function getMemberItemList()
  611. {
  612. $menu_array = array(
  613. 1 => array(
  614. 'name' => 'message', 'text' => lang('home_message_received_message'),
  615. 'url' => (string)url('Membermessage/message')
  616. ), 2 => array(
  617. 'name' => 'private', 'text' => lang('home_message_private_message'),
  618. 'url' => (string)url('Membermessage/privatemsg')
  619. ), 3 => array(
  620. 'name' => 'system', 'text' => lang('home_message_system_message'),
  621. 'url' => (string)url('Membermessage/systemmsg')
  622. ), 4 => array(
  623. 'name' => 'close', 'text' => lang('home_message_close'),
  624. 'url' => (string)url('Membermessage/personalmsg')
  625. ), 5 => array(
  626. 'name' => 'setting', 'text' => lang('receiving_set'), 'url' => (string)url('Membermessage/setting')
  627. )
  628. );
  629. if (request()->action() == 'sendmsg') {
  630. $menu_array[] = array(
  631. 'name' => 'sendmsg', 'text' => lang('home_message_send_message'),
  632. 'url' => (string)url('Membermessage/sendmsg')
  633. );
  634. } elseif (request()->action() == 'showmsg') {
  635. $menu_array[] = array(
  636. 'name' => 'showmsg', 'text' => lang('home_message_view_message'), 'url' => '#'
  637. );
  638. }
  639. return $menu_array;
  640. }
  641. }