Sellermsg.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Sellermsg extends BaseSeller {
  18. public function initialize() {
  19. parent::initialize(); // TODO: Change the autogenerated stub
  20. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellermsg.lang.php');
  21. }
  22. /**
  23. * 消息列表
  24. */
  25. public function index() {
  26. $where = array();
  27. $where[] = array('store_id', '=', session('store_id'));
  28. if (!session('seller_is_admin')) {
  29. $where[] = array('storemt_code', 'in', session('seller_smt_limits'));
  30. }
  31. $storemsg_model = model('storemsg');
  32. $msg_list = $storemsg_model->getStoremsgList($where, '*', 10);
  33. // 整理数据
  34. if (!empty($msg_list)) {
  35. foreach ($msg_list as $key => $val) {
  36. $msg_list[$key]['storemsg_readids'] = explode(',', $val['storemsg_readids']);
  37. }
  38. }
  39. View::assign('msg_list', $msg_list);
  40. View::assign('show_page', $storemsg_model->page_info->render());
  41. $this->setSellerCurMenu('Sellermsg');
  42. $this->setSellerCurItem('msg_list');
  43. return View::fetch($this->template_dir . 'index');
  44. }
  45. /**
  46. * 消息详细
  47. */
  48. public function msg_info() {
  49. $storemsg_id = intval(input('param.storemsg_id'));
  50. if ($storemsg_id <= 0) {
  51. $this->error(lang('param_error'));
  52. }
  53. $storemsg_model = model('storemsg');
  54. $where = array();
  55. $where[] = array('storemsg_id', '=', $storemsg_id);
  56. if (session('seller_smt_limits') !== false) {
  57. $where[] = array('storemt_code', 'in', session('seller_smt_limits'));
  58. }
  59. $msg_info = $storemsg_model->getStoremsgInfo($where);
  60. if (empty($msg_info)) {
  61. $this->error(lang('param_error'));
  62. }
  63. View::assign('msg_list', $msg_info);
  64. // 验证时候已读
  65. $storemsg_readids = explode(',', $msg_info['storemsg_readids']);
  66. if (!in_array(session('seller_id'), $storemsg_readids)) {
  67. // 消息阅读表插入数据
  68. $data = array();
  69. $data['seller_id'] = session('seller_id');
  70. $data['storemsg_id'] = $storemsg_id;
  71. model('storemsgread')->addStoremsgread($data);
  72. $update = array();
  73. $storemsg_readids[] = session('seller_id');
  74. $update['storemsg_readids'] = implode(',', $storemsg_readids) . ',';
  75. $storemsg_model->editStoremsg(array('storemsg_id' => $storemsg_id), $update);
  76. }
  77. return View::fetch($this->template_dir . 'msg_info');
  78. }
  79. /**
  80. * AJAX标记为已读
  81. */
  82. public function mark_as_read() {
  83. $smids = input('param.smids');
  84. if (!preg_match('/^[\d,]+$/i', $smids)) {
  85. ds_json_encode(10001, lang('param_error'));
  86. }
  87. $smids = explode(',', $smids);
  88. $storemsgread_model = model('storemsgread');
  89. $storemsg_model = model('storemsg');
  90. foreach ($smids as $val) {
  91. $condition = array();
  92. $condition[] = array('seller_id','=',session('seller_id'));
  93. $condition[] = array('storemsg_id','=',$val);
  94. $read_info = $storemsgread_model->getStoremsgreadInfo($condition);
  95. if (empty($read_info)) {
  96. $data = array();
  97. $data['seller_id'] = session('seller_id');
  98. $data['storemsg_id'] = $val;
  99. // 消息阅读表插入数据
  100. $storemsgread_model->addStoremsgread($data);
  101. // 更新店铺消息表
  102. $storemsg_info = $storemsg_model->getStoremsgInfo(array('storemsg_id' => $val));
  103. $storemsg_readids = explode(',', $storemsg_info['storemsg_readids']);
  104. $storemsg_readids[] = session('seller_id');
  105. $storemsg_readids = array_unique($storemsg_readids);
  106. $update = array();
  107. $update['storemsg_readids'] = implode(',', $storemsg_readids) . ',';
  108. $storemsg_model->editStoremsg(array('storemsg_id' => $val), $update);
  109. }
  110. }
  111. ds_json_encode(10000, lang('ds_common_op_succ'));
  112. }
  113. /**
  114. * AJAX删除消息
  115. */
  116. public function del_msg() {
  117. // 验证参数
  118. $smids = input('param.smids');
  119. if (!preg_match('/^[\d,]+$/i', $smids)) {
  120. ds_json_encode(10001, lang('param_error'));
  121. }
  122. $smid_array = explode(',', $smids);
  123. // 验证是否为管理员
  124. if (!$this->checkIsAdmin()) {
  125. ds_json_encode(10001, lang('param_error'));
  126. }
  127. $condition = array();
  128. $condition[] = array('store_id', '=', session('store_id'));
  129. $condition[] = array('storemsg_id', 'in', $smid_array);
  130. // 删除消息记录
  131. model('storemsg')->delStoremsg($condition);
  132. // 删除阅读记录
  133. $condition = array();
  134. $condition[] = array('storemsg_id', 'in', $smid_array);
  135. model('storemsgread')->delStoremsgread($condition);
  136. ds_json_encode(10000, lang('ds_common_op_succ'));
  137. }
  138. /**
  139. * 消息接收设置
  140. */
  141. public function msg_setting() {
  142. // 验证是否为管理员
  143. if (!$this->checkIsAdmin()) {
  144. $this->error(lang('param_error'));
  145. }
  146. // 店铺消息模板列表
  147. $smt_list = model('storemsgtpl')->getStoremsgtplList(array(), 'storemt_code,storemt_name,storemt_message_switch,storemt_message_forced,storemt_short_switch,smt_short_forced,storemt_mail_switch,storemt_mail_forced,storemt_weixin_switch,storemt_weixin_forced');
  148. // 店铺接收设置
  149. $setting_list = model('storemsgsetting')->getStoremsgsettingList(array('store_id' => session('store_id')), '*', 'storemt_code');
  150. if (!empty($smt_list)) {
  151. foreach ($smt_list as $key => $val) {
  152. // 站内信消息模板是否开启
  153. if ($val['storemt_message_switch']) {
  154. // 是否强制接收,强制接收必须开启
  155. $smt_list[$key]['storems_message_switch'] = $val['storemt_message_forced'] ? 1 : (isset($setting_list[$val['storemt_code']]) ? intval($setting_list[$val['storemt_code']]['storems_message_switch']) : 0);
  156. // 已开启接收模板
  157. if ($smt_list[$key]['storems_message_switch']) {
  158. $smt_list[$key]['is_opened'][] = lang('business_alert');
  159. }
  160. }
  161. // 短消息模板是否开启
  162. if ($val['storemt_short_switch']) {
  163. // 是否强制接收,强制接收必须开启
  164. $smt_list[$key]['storems_short_switch'] = $val['smt_short_forced'] ? 1 : (isset($setting_list[$val['storemt_code']]) ? intval($setting_list[$val['storemt_code']]['storems_short_switch']) : 0);
  165. // 已开启接收模板
  166. if ($smt_list[$key]['storems_short_switch']) {
  167. $smt_list[$key]['is_opened'][] = lang('sms_alerts');
  168. }
  169. }
  170. // 邮件模板是否开启
  171. if ($val['storemt_mail_switch']) {
  172. // 是否强制接收,强制接收必须开启
  173. $smt_list[$key]['storems_mail_switch'] = $val['storemt_mail_forced'] ? 1 : (isset($setting_list[$val['storemt_code']]) ? intval($setting_list[$val['storemt_code']]['storems_mail_switch']) : 0);
  174. // 已开启接收模板
  175. if ($smt_list[$key]['storems_mail_switch']) {
  176. $smt_list[$key]['is_opened'][] = lang('email_alerts');
  177. }
  178. }
  179. // 微信模板是否开启
  180. if ($val['storemt_weixin_switch']) {
  181. // 是否强制接收,强制接收必须开启
  182. $smt_list[$key]['storems_weixin_switch'] = $val['storemt_weixin_forced'] ? 1 : (isset($setting_list[$val['storemt_code']]) ? intval($setting_list[$val['storemt_code']]['storems_weixin_switch']) : 0);
  183. // 已开启接收模板
  184. if ($smt_list[$key]['storems_weixin_switch']) {
  185. $smt_list[$key]['is_opened'][] = lang('weixin_alerts');
  186. }
  187. }
  188. if(!empty($smt_list[$key]['is_opened']) && is_array($smt_list[$key]['is_opened'])){
  189. $smt_list[$key]['is_opened'] = implode('&nbsp;|&nbsp;&nbsp;', $smt_list[$key]['is_opened']);
  190. }else{
  191. $smt_list[$key]['is_opened'] = '';
  192. }
  193. }
  194. }
  195. View::assign('smt_list', $smt_list);
  196. $this->setSellerCurMenu('Sellermsg');
  197. $this->setSellerCurItem('msg_setting');
  198. return View::fetch($this->template_dir . 'msg_setting');
  199. }
  200. /**
  201. * 编辑店铺消息接收设置
  202. */
  203. public function edit_msg_setting() {
  204. // 验证是否为管理员
  205. if (!$this->checkIsAdmin()) {
  206. $this->error(lang('param_error'));
  207. }
  208. $code = trim(input('param.code'));
  209. if ($code == '') {
  210. return false;
  211. }
  212. // 店铺消息模板
  213. $smt_info = model('storemsgtpl')->getStoremsgtplInfo(array('storemt_code' => $code), 'storemt_code,storemt_name,storemt_message_switch,storemt_message_forced,storemt_short_switch,smt_short_forced,storemt_mail_switch,storemt_mail_forced,storemt_weixin_switch,storemt_weixin_forced');
  214. if (empty($smt_info)) {
  215. return false;
  216. }
  217. // 店铺消息接收设置
  218. $setting_info = model('storemsgsetting')->getStoremsgsettingInfo(array(
  219. 'storemt_code' => $code,
  220. 'store_id' => session('store_id')
  221. ));
  222. View::assign('smt_info', $smt_info);
  223. View::assign('smsetting_info', $setting_info);
  224. return View::fetch($this->template_dir . 'setting_edit');
  225. }
  226. /**
  227. * 保存店铺接收设置
  228. */
  229. public function save_msg_setting() {
  230. // 验证是否为管理员
  231. if (!$this->checkIsAdmin()) {
  232. ds_json_encode(10001, lang('param_error'));
  233. }
  234. $code = trim(input('post.code'));
  235. if ($code == '') {
  236. ds_json_encode(10001, lang('param_error'));
  237. }
  238. $data = [
  239. 'storems_short_number' => input('post.storems_short_number'),
  240. 'storems_mail_number' => input('post.storems_mail_number'),
  241. ];
  242. $sellermsg_validate = ds_validate('sellermsg');
  243. if (!$sellermsg_validate->scene('save_msg_setting')->check($data)) {
  244. ds_json_encode(10001, $sellermsg_validate->getError());
  245. }
  246. $smt_info = model('storemsgtpl')->getStoremsgtplInfo(array('storemt_code' => $code), 'storemt_code,storemt_name,storemt_message_switch,storemt_message_forced,storemt_short_switch,smt_short_forced,storemt_mail_switch,storemt_mail_forced,storemt_weixin_switch,storemt_weixin_forced');
  247. // 保存
  248. $data = array();
  249. $data['storemt_code'] = $smt_info['storemt_code'];
  250. $data['store_id'] = session('store_id');
  251. // 验证站内信是否开启
  252. if ($smt_info['storemt_message_switch']) {
  253. $data['storems_message_switch'] = $smt_info['storemt_message_forced'] ? 1 : intval(input('post.message_forced'));
  254. } else {
  255. $data['storems_message_switch'] = 0;
  256. }
  257. // 验证短消息是否开启
  258. if ($smt_info['storemt_short_switch']) {
  259. $data['storems_short_switch'] = $smt_info['smt_short_forced'] ? 1 : intval(input('post.short_forced'));
  260. } else {
  261. $data['storems_short_switch'] = 0;
  262. }
  263. $data['storems_short_number'] = input('post.storems_short_number', '');
  264. // 验证邮件是否开启
  265. if ($smt_info['storemt_mail_switch']) {
  266. $data['storems_mail_switch'] = $smt_info['storemt_mail_forced'] ? 1 : intval(input('post.mail_forced'));
  267. } else {
  268. $data['storems_mail_switch'] = 0;
  269. }
  270. // 验证微信是否开启
  271. if ($smt_info['storemt_weixin_switch']) {
  272. $data['storems_weixin_switch'] = $smt_info['storemt_weixin_forced'] ? 1 : intval(input('post.weixin_forced'));
  273. } else {
  274. $data['storems_weixin_switch'] = 0;
  275. }
  276. $data['storems_mail_number'] = input('post.storems_mail_number', '');
  277. $conditiion = array();
  278. $conditiion['storemt_code'] = $smt_info['storemt_code'];
  279. $conditiion['store_id'] = session('store_id');
  280. $storemsgsetting_info = model('storemsgsetting')->getStoremsgsettingInfo($conditiion);
  281. // 插入数据
  282. if (empty($storemsgsetting_info)) {
  283. $result = model('storemsgsetting')->addStoremsgsetting($data);
  284. } else {
  285. $result = model('storemsgsetting')->editStoremsgsetting($data, $conditiion);
  286. }
  287. if ($result) {
  288. ds_json_encode(10000, lang('ds_common_op_succ'));
  289. } else {
  290. ds_json_encode(10001, lang('ds_common_op_fail'));
  291. }
  292. }
  293. private function checkIsAdmin() {
  294. return session('seller_is_admin') ? true : false;
  295. }
  296. /**
  297. * 用户中心右边,小导航
  298. *
  299. * @param string $name 当前导航的name
  300. * @param array $array 附加菜单
  301. * @return
  302. */
  303. protected function getSellerItemList() {
  304. $menu_array = array(
  305. 1 => array('name' => 'msg_list', 'text' => lang('system_message'), 'url' => (string) url('Sellermsg/index')), 2 => array(
  306. 'name' => 'msg_setting', 'text' => lang('receiving_setting'), 'url' => (string) url('Sellermsg/msg_setting')
  307. ),
  308. );
  309. if (!$this->checkIsAdmin()) {
  310. unset($menu_array[2]);
  311. }
  312. return $menu_array;
  313. }
  314. }