Membermessage.php 28 KB

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