Membermessage.php 29 KB

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