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