message.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <?php
  2. /**
  3. * 消息通知
  4. *
  5. *
  6. *
  7. **by 好商城V3 www.33hao.com 运营版*/
  8. defined('InShopNC') or exit('Access Invalid!');
  9. class messageControl extends SystemControl
  10. {
  11. private $links = array(
  12. array('url'=>'act=message&op=email','lang'=>'email_set'),
  13. //V3-B11
  14. array('url'=>'act=message&op=mobile','lang'=>'mobile_set'),
  15. array('url'=>'act=message&op=seller_tpl', 'lang'=>'seller_tpl'),
  16. array('url'=>'act=message&op=member_tpl', 'lang'=>'member_tpl'),
  17. array('url'=>'act=message&op=email_tpl','lang'=>'email_tpl')
  18. );
  19. public function __construct(){
  20. parent::__construct();
  21. Language::read('setting,message');
  22. }
  23. /**
  24. * 邮件设置
  25. */
  26. public function emailOp(){
  27. $model_setting = Model('setting');
  28. if (chksubmit()){
  29. $update_array = array();
  30. $update_array['email_host'] = $_POST['email_host'];
  31. $update_array['email_port'] = $_POST['email_port'];
  32. $update_array['email_addr'] = $_POST['email_addr'];
  33. $update_array['email_id'] = $_POST['email_id'];
  34. $update_array['email_pass'] = $_POST['email_pass'];
  35. $result = $model_setting->updateSetting($update_array);
  36. if ($result === true){
  37. $this->log(L('nc_edit,email_set'),1);
  38. showMessage(L('nc_common_save_succ'));
  39. }else {
  40. $this->log(L('nc_edit,email_set'),0);
  41. showMessage(L('nc_common_save_fail'));
  42. }
  43. }
  44. $list_setting = $model_setting->getListSetting();
  45. Tpl::output('list_setting',$list_setting);
  46. Tpl::output('top_link',$this->sublink($this->links,'email'));
  47. Tpl::showpage('message.email');
  48. }
  49. /**
  50. * 短信平台设置 V3-B11 BY 3 3HA O .COM
  51. */
  52. public function mobileOp(){
  53. $model_setting = Model('setting');
  54. if (chksubmit()){
  55. $update_array = array();
  56. $update_array['mobile_host_type'] = $_POST['mobile_host_type'];
  57. $update_array['mobile_host'] = $_POST['mobile_host'];
  58. $update_array['mobile_username'] = $_POST['mobile_username'];
  59. $update_array['mobile_pwd'] = $_POST['mobile_pwd'];
  60. $update_array['mobile_key'] = $_POST['mobile_key'];
  61. $update_array['mobile_signature'] = $_POST['mobile_signature'];
  62. $update_array['mobile_memo'] = $_POST['mobile_memo'];
  63. $result = $model_setting->updateSetting($update_array);
  64. if ($result === true){
  65. $this->log(L('nc_edit,mobile_set'),1);
  66. showMessage(L('nc_common_save_succ'));
  67. }else {
  68. $this->log(L('nc_edit,mobile_set'),0);
  69. showMessage(L('nc_common_save_fail'));
  70. }
  71. }
  72. $list_setting = $model_setting->getListSetting();
  73. Tpl::output('list_setting',$list_setting);
  74. Tpl::output('top_link',$this->sublink($this->links,'mobile'));
  75. Tpl::showpage('message.mobile');
  76. }
  77. /**
  78. * 邮件模板列表
  79. */
  80. public function email_tplOp(){
  81. $model_templates = Model('mail_templates');
  82. $templates_list = $model_templates->getTplList();
  83. Tpl::output('templates_list',$templates_list);
  84. Tpl::output('top_link',$this->sublink($this->links,'email_tpl'));
  85. Tpl::showpage('message.email_tpl');
  86. }
  87. /**
  88. * 编辑邮件模板
  89. */
  90. public function email_tpl_editOp(){
  91. $model_templates = Model('mail_templates');
  92. if (chksubmit()){
  93. $obj_validate = new Validator();
  94. $obj_validate->validateparam = array(
  95. array("input"=>$_POST["code"], "require"=>"true", "message"=>L('mailtemplates_edit_no_null')),
  96. array("input"=>$_POST["title"], "require"=>"true", "message"=>L('mailtemplates_edit_title_null')),
  97. array("input"=>$_POST["content"], "require"=>"true", "message"=>L('mailtemplates_edit_content_null')),
  98. );
  99. $error = $obj_validate->validate();
  100. if ($error != ''){
  101. showMessage($error);
  102. }else {
  103. $update_array = array();
  104. $update_array['code'] = $_POST["code"];
  105. $update_array['title'] = $_POST["title"];
  106. $update_array['content'] = $_POST["content"];
  107. $result = $model_templates->editTpl($update_array,array('code'=>$_POST['code']));
  108. if ($result === true){
  109. $this->log(L('nc_edit,email_tpl'),1);
  110. showMessage(L('mailtemplates_edit_succ'),'index.php?act=message&op=email_tpl');
  111. }else {
  112. $this->log(L('nc_edit,email_tpl'),0);
  113. showMessage(L('mailtemplates_edit_fail'));
  114. }
  115. }
  116. }
  117. if (empty($_GET['code'])){
  118. showMessage(L('mailtemplates_edit_code_null'));
  119. }
  120. $templates_array = $model_templates->getTplInfo(array('code'=>$_GET['code']));
  121. Tpl::output('templates_array',$templates_array);
  122. Tpl::output('top_link',$this->sublink($this->links,'email_tpl'));
  123. Tpl::showpage('message.email_tpl.edit');
  124. }
  125. /**
  126. * 测试邮件发送
  127. *
  128. * @param
  129. * @return
  130. */
  131. public function email_testingOp(){
  132. /**
  133. * 读取语言包
  134. */
  135. $lang = Language::getLangContent();
  136. $email_host = trim($_POST['email_host']);
  137. $email_port = trim($_POST['email_port']);
  138. $email_addr = trim($_POST['email_addr']);
  139. $email_id = trim($_POST['email_id']);
  140. $email_pass = trim($_POST['email_pass']);
  141. $email_test = trim($_POST['email_test']);
  142. $subject = $lang['test_email'];
  143. $site_url = SHOP_SITE_URL;
  144. $site_title = C('site_name');
  145. $message = '<p>'.$lang['this_is_to']."<a href='".$site_url."' target='_blank'>".$site_title.'</a>'.$lang['test_email_send_ok'].'</p>';
  146. // if ($email_type == '1'){
  147. $obj_email = new Email();
  148. $obj_email->set('email_server',$email_host);
  149. $obj_email->set('email_port',$email_port);
  150. $obj_email->set('email_user',$email_id);
  151. $obj_email->set('email_password',$email_pass);
  152. $obj_email->set('email_from',$email_addr);
  153. $obj_email->set('site_name',$site_title);
  154. $result = $obj_email->send($email_test,$subject,$message);
  155. // }else {
  156. // $result = @mail($email_test,$subject,$message);
  157. // }
  158. if ($result === false){
  159. $message = $lang['test_email_send_fail'];
  160. if (strtoupper(CHARSET) == 'GBK'){
  161. $message = Language::getUTF8($message);
  162. }
  163. showMessage($message,'','json');
  164. }else {
  165. $message = $lang['test_email_send_ok'];
  166. if (strtoupper(CHARSET) == 'GBK'){
  167. $message = Language::getUTF8($message);
  168. }
  169. showMessage($message,'','json');
  170. }
  171. }
  172. /**
  173. * 商家消息模板
  174. */
  175. public function seller_tplOp() {
  176. $mstpl_list = Model('store_msg_tpl')->getStoreMsgTplList(array());
  177. Tpl::output('mstpl_list', $mstpl_list);
  178. Tpl::output('top_link',$this->sublink($this->links,'seller_tpl'));
  179. Tpl::showpage('message.seller_tpl');
  180. }
  181. /**
  182. * 商家消息模板编辑
  183. */
  184. public function seller_tpl_editOp() {
  185. if (chksubmit()) {
  186. $code = trim($_POST['code']);
  187. $type = trim($_POST['type']);
  188. if (empty($code) || empty($type)) {
  189. showMessage(L('param_error'));
  190. }
  191. switch ($type) {
  192. case 'message':
  193. $this->seller_tpl_update_message();
  194. break;
  195. case 'short':
  196. $this->seller_tpl_update_short();
  197. break;
  198. case 'mail':
  199. $this->seller_tpl_update_mail();
  200. break;
  201. }
  202. }
  203. $code = trim($_GET['code']);
  204. if (empty($code)) {
  205. showMessage(L('param_error'));
  206. }
  207. $where = array();
  208. $where['smt_code'] = $code;
  209. $smtpl_info = Model('store_msg_tpl')->getStoreMsgTplInfo($where);
  210. Tpl::output('smtpl_info', $smtpl_info);
  211. $this->links[] = array('url'=>'act=message&op=seller_tpl_edit','lang'=>'seller_tpl_edit');
  212. Tpl::output('top_link',$this->sublink($this->links,'seller_tpl_edit'));
  213. Tpl::showpage('message.seller_tpl.edit');
  214. }
  215. /**
  216. * 商家消息模板更新站内信
  217. */
  218. private function seller_tpl_update_message() {
  219. $message_content = trim($_POST['message_content']);
  220. if (empty($message_content)) {
  221. showMessage('请填写站内信模板内容。');
  222. }
  223. // 条件
  224. $where = array();
  225. $where['smt_code'] = trim($_POST['code']);
  226. // 数据
  227. $update = array();
  228. $update['smt_message_switch'] = intval($_POST['message_switch']);
  229. $update['smt_message_content'] = $message_content;
  230. $update['smt_message_forced'] = intval($_POST['message_forced']);
  231. $result = Model('store_msg_tpl')->editStoreMsgTpl($where, $update);
  232. $this->seller_tpl_update_showmessage($result);
  233. }
  234. /**
  235. * 商家消息模板更新短消息
  236. */
  237. private function seller_tpl_update_short() {
  238. $short_content = trim($_POST['short_content']);
  239. if (empty($short_content)) {
  240. showMessage('请填写短消息模板内容。');
  241. }
  242. // 条件
  243. $where = array();
  244. $where['smt_code'] = trim($_POST['code']);
  245. // 数据
  246. $update = array();
  247. $update['smt_short_switch'] = intval($_POST['short_switch']);
  248. $update['smt_short_content'] = $short_content;
  249. $update['smt_short_forced'] = intval($_POST['short_forced']);
  250. $result = Model('store_msg_tpl')->editStoreMsgTpl($where, $update);
  251. $this->seller_tpl_update_showmessage($result);
  252. }
  253. /**
  254. * 商家消息模板更新邮件
  255. */
  256. private function seller_tpl_update_mail() {
  257. $mail_subject = trim($_POST['mail_subject']);
  258. $mail_content = trim($_POST['mail_content']);
  259. if ((empty($mail_subject) || empty($mail_content))) {
  260. showMessage('请填写邮件模板内容。');
  261. }
  262. // 条件
  263. $where = array();
  264. $where['smt_code'] = trim($_POST['code']);
  265. // 数据
  266. $update = array();
  267. $update['smt_mail_switch'] = intval($_POST['mail_switch']);
  268. $update['smt_mail_subject'] = $mail_subject;
  269. $update['smt_mail_content'] = $mail_content;
  270. $update['smt_mail_forced'] = intval($_POST['mail_forced']);
  271. $result = Model('store_msg_tpl')->editStoreMsgTpl($where, $update);
  272. $this->seller_tpl_update_showmessage($result);
  273. }
  274. private function seller_tpl_update_showmessage($result) {
  275. if ($result) {
  276. showMessage(L('nc_common_op_succ'), urlAdmin('message', 'seller_tpl'));
  277. } else {
  278. showMessage(L('nc_common_op_fail'));
  279. }
  280. }
  281. /**
  282. * 用户消息模板
  283. */
  284. public function member_tplOp() {
  285. $mmtpl_list = Model('member_msg_tpl')->getMemberMsgTplList(array());
  286. Tpl::output('mmtpl_list', $mmtpl_list);
  287. Tpl::output('top_link',$this->sublink($this->links,'member_tpl'));
  288. Tpl::showpage('message.member_tpl');
  289. }
  290. /**
  291. * 用户消息模板编辑
  292. */
  293. public function member_tpl_editOp() {
  294. if (chksubmit()) {
  295. $code = trim($_POST['code']);
  296. $type = trim($_POST['type']);
  297. if (empty($code) || empty($type)) {
  298. showMessage(L('param_error'));
  299. }
  300. switch ($type) {
  301. case 'message':
  302. $this->member_tpl_update_message();
  303. break;
  304. case 'short':
  305. $this->member_tpl_update_short();
  306. break;
  307. case 'mail':
  308. $this->member_tpl_update_mail();
  309. break;
  310. }
  311. }
  312. $code = trim($_GET['code']);
  313. if (empty($code)) {
  314. showMessage(L('param_error'));
  315. }
  316. $where = array();
  317. $where['mmt_code'] = $code;
  318. $mmtpl_info = Model('member_msg_tpl')->getMemberMsgTplInfo($where);
  319. Tpl::output('mmtpl_info', $mmtpl_info);
  320. $this->links[] = array('url'=>'act=message&op=member_tpl_edit','lang'=>'member_tpl_edit');
  321. Tpl::output('top_link',$this->sublink($this->links,'member_tpl_edit'));
  322. Tpl::showpage('message.member_tpl.edit');
  323. }
  324. /**
  325. * 商家消息模板更新站内信
  326. */
  327. private function member_tpl_update_message() {
  328. $message_content = trim($_POST['message_content']);
  329. if (empty($message_content)) {
  330. showMessage('请填写站内信模板内容。');
  331. }
  332. // 条件
  333. $where = array();
  334. $where['mmt_code'] = trim($_POST['code']);
  335. // 数据
  336. $update = array();
  337. $update['mmt_message_switch'] = intval($_POST['message_switch']);
  338. $update['mmt_message_content'] = $message_content;
  339. $result = Model('member_msg_tpl')->editMemberMsgTpl($where, $update);
  340. $this->member_tpl_update_showmessage($result);
  341. }
  342. /**
  343. * 商家消息模板更新短消息
  344. */
  345. private function member_tpl_update_short() {
  346. $short_content = trim($_POST['short_content']);
  347. if (empty($short_content)) {
  348. showMessage('请填写短消息模板内容。');
  349. }
  350. // 条件
  351. $where = array();
  352. $where['mmt_code'] = trim($_POST['code']);
  353. // 数据
  354. $update = array();
  355. $update['mmt_short_switch'] = intval($_POST['short_switch']);
  356. $update['mmt_short_content'] = $short_content;
  357. $result = Model('member_msg_tpl')->editMemberMsgTpl($where, $update);
  358. $this->member_tpl_update_showmessage($result);
  359. }
  360. /**
  361. * 商家消息模板更新邮件
  362. */
  363. private function member_tpl_update_mail() {
  364. $mail_subject = trim($_POST['mail_subject']);
  365. $mail_content = trim($_POST['mail_content']);
  366. if ((empty($mail_subject) || empty($mail_content))) {
  367. showMessage('请填写邮件模板内容。');
  368. }
  369. // 条件
  370. $where = array();
  371. $where['mmt_code'] = trim($_POST['code']);
  372. // 数据
  373. $update = array();
  374. $update['mmt_mail_switch'] = intval($_POST['mail_switch']);
  375. $update['mmt_mail_subject'] = $mail_subject;
  376. $update['mmt_mail_content'] = $mail_content;
  377. $result = Model('member_msg_tpl')->editMemberMsgTpl($where, $update);
  378. $this->member_tpl_update_showmessage($result);
  379. }
  380. private function member_tpl_update_showmessage($result) {
  381. if ($result) {
  382. showMessage(L('nc_common_op_succ'), urlAdmin('message', 'member_tpl'));
  383. } else {
  384. showMessage(L('nc_common_op_fail'));
  385. }
  386. }
  387. }