message.php 14 KB

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