PromoteMsgSmsAction.class.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维商城系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. class PromoteMsgSmsAction extends CommonAction{
  10. public function sms_index()
  11. {
  12. if(intval($_REQUEST['action_id'])!='')
  13. {
  14. $action_id= intval($_REQUEST['action_id']);
  15. }
  16. $this->assign('action_id',$action_id);
  17. $condition['type'] = 0;
  18. $this->assign("default_map",$condition);
  19. $map = $this->_search ();
  20. //追加默认参数
  21. if($this->get("default_map"))
  22. $map = array_merge($map,$this->get("default_map"));
  23. if (method_exists ( $this, '_filter' )) {
  24. $this->_filter ( $map );
  25. }
  26. $name=$this->getActionName();
  27. $model = D ("PromoteMsg");
  28. if (! empty ( $model )) {
  29. $this->_list ( $model, $map );
  30. }
  31. $this->display ();
  32. return;
  33. }
  34. public function add_sms()
  35. {
  36. //输出会员组
  37. $group_list = M("UserGroup")->findAll();
  38. $this->assign("group_list",$group_list);
  39. parent::index();
  40. }
  41. public function insert_sms()
  42. {
  43. //开始验证
  44. if($_REQUEST['content']=='')
  45. {
  46. $this->error(l("SMS_CONTENT_EMPTY_TIP"));
  47. }
  48. if(intval($_REQUEST['send_type'])==2)
  49. {
  50. if($_REQUEST['send_define_data']=='')
  51. {
  52. $this->error(l("SEND_DEFINE_DATE_EMPTY_TIP"));
  53. }
  54. }
  55. $msg_data['type'] = 0;
  56. $msg_data['content'] = $_REQUEST['content'];
  57. $msg_data['send_time'] = trim($_REQUEST['send_time'])==''?NOW_TIME:to_timespan($_REQUEST['send_time']);
  58. $msg_data['send_status'] = 0;
  59. $msg_data['send_type'] = intval($_REQUEST['send_type']);
  60. switch($msg_data['send_type'])
  61. {
  62. case 0:
  63. //会员组
  64. $msg_data['send_type_id'] = intval($_REQUEST['group_id']);
  65. break;
  66. case 2:
  67. //自定义号码
  68. $msg_data['send_type_id'] = 0;
  69. break;
  70. }
  71. $msg_data['send_define_data'] = $_REQUEST['send_define_data'];
  72. $rs = M("PromoteMsg")->add($msg_data);
  73. if($rs)
  74. {
  75. save_log($msg_data['content'].L("INSERT_SUCCESS"),1);
  76. $this->success(L("INSERT_SUCCESS"));
  77. }
  78. else
  79. {
  80. $this->error(L("INSERT_FAILED"));
  81. }
  82. }
  83. public function edit_sms() {
  84. $id = intval($_REQUEST ['id']);
  85. $condition['id'] = $id;
  86. $vo = M("PromoteMsg")->where($condition)->find();
  87. $this->assign ( 'vo', $vo );
  88. //输出会员组
  89. $group_list = M("UserGroup")->findAll();
  90. $this->assign("group_list",$group_list);
  91. $this->display ();
  92. }
  93. public function update_sms()
  94. {
  95. //开始验证
  96. if($_REQUEST['content']=='')
  97. {
  98. $this->error(L("SMS_CONTENT_EMPTY_TIP"));
  99. }
  100. if(intval($_REQUEST['send_type'])==2)
  101. {
  102. if($_REQUEST['send_define_data']=='')
  103. {
  104. $this->error(l("SEND_DEFINE_DATE_EMPTY_TIP"));
  105. }
  106. }
  107. $msg_data['type'] = 0;
  108. $msg_data['content'] = $_REQUEST['content'];
  109. $msg_data['send_time'] = trim($_REQUEST['send_time'])==''?NOW_TIME:to_timespan($_REQUEST['send_time']);
  110. $msg_data['send_type'] = intval($_REQUEST['send_type']);
  111. switch($msg_data['send_type'])
  112. {
  113. case 0:
  114. //会员组
  115. $msg_data['send_type_id'] = intval($_REQUEST['group_id']);
  116. break;
  117. case 2:
  118. //自定义号码
  119. $msg_data['send_type_id'] = 0;
  120. break;
  121. }
  122. $msg_data['send_define_data'] = $_REQUEST['send_define_data'];
  123. $msg_data['id'] = intval($_REQUEST['id']);
  124. if(intval($_REQUEST['resend'])==1)
  125. {
  126. $msg_data['send_status'] = 0;
  127. M("PromoteMsgList")->where("msg_id=".intval($msg_data['id']))->delete();
  128. }
  129. $rs = M("PromoteMsg")->save($msg_data);
  130. if($rs)
  131. {
  132. save_log($msg_data['content'].L("UPDATE_SUCCESS"),1);
  133. $this->success(L("UPDATE_SUCCESS"));
  134. }
  135. else
  136. {
  137. $this->error(L("UPDATE_FAILED"));
  138. }
  139. }
  140. public function foreverdelete() {
  141. //彻底删除指定记录
  142. $ajax = intval($_REQUEST['ajax']);
  143. $id = $_REQUEST ['id'];
  144. if (isset ( $id )) {
  145. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  146. $rel_data = M("PromoteMsg")->where($condition)->findAll();
  147. foreach($rel_data as $data)
  148. {
  149. $info[] = $data['title'];
  150. }
  151. if($info) $info = implode(",",$info);
  152. $list = M("PromoteMsg")->where ( $condition )->delete();
  153. if ($list!==false) {
  154. M("PromoteMsgList")->where(array ('msg_id' => array ('in', explode ( ',', $id ) ) ))->delete();
  155. save_log($info.l("FOREVER_DELETE_SUCCESS"),1);
  156. $this->success (l("FOREVER_DELETE_SUCCESS"),$ajax);
  157. } else {
  158. save_log($info.l("FOREVER_DELETE_FAILED"),0);
  159. $this->error (l("FOREVER_DELETE_FAILED"),$ajax);
  160. }
  161. } else {
  162. $this->error (l("INVALID_OPERATION"),$ajax);
  163. }
  164. }
  165. /**
  166. * 查看对列
  167. */
  168. public function index()
  169. {
  170. if(trim($_REQUEST['dest'])!='')
  171. $condition['dest'] = array('like','%'.trim($_REQUEST['dest']).'%');
  172. if(trim($_REQUEST['content'])!='')
  173. $condition['content'] = array('like','%'.trim($_REQUEST['content']).'%');
  174. $this->assign("default_map",$condition);
  175. parent::index();
  176. }
  177. public function show_content()
  178. {
  179. $id = intval($_REQUEST['id']);
  180. header("Content-Type:text/html; charset=utf-8");
  181. echo M("PromoteMsgList")->where("id=".$id)->getField("content");
  182. }
  183. public function send()
  184. {
  185. $id = intval($_REQUEST['id']);
  186. $msg_item = M("PromoteMsgList")->getById($id);
  187. $log_info = $msg_item['title'];
  188. if($msg_item)
  189. {
  190. if($msg_item['send_type']==0)
  191. {
  192. //短信
  193. require_once APP_ROOT_PATH."system/utils/es_sms.php";
  194. $sms = new sms_sender();
  195. $result = $sms->sendSms($msg_item['dest'],$msg_item['content'],get_gmtime(),1);
  196. $msg_item['result'] = $result['msg'];
  197. $msg_item['is_success'] = intval($result['status']);
  198. $msg_item['send_time'] = NOW_TIME;
  199. M("PromoteMsgList")->save($msg_item);
  200. if($result['status'])
  201. {
  202. save_log($log_info.l("SEND_NOW").l("SUCCESS"),1);
  203. header("Content-Type:text/html; charset=utf-8");
  204. echo l("SEND_NOW").l("SUCCESS");
  205. }
  206. else
  207. {
  208. save_log($log_info.l("SEND_NOW").l("FAILED").$result['msg'],0);
  209. header("Content-Type:text/html; charset=utf-8");
  210. echo l("SEND_NOW").l("FAILED").$result['msg'];
  211. }
  212. }
  213. else
  214. {
  215. //邮件
  216. require_once APP_ROOT_PATH."system/utils/es_mail.php";
  217. $mail = new mail_sender();
  218. $mail->AddAddress($msg_item['dest']);
  219. $mail->IsHTML($msg_item['is_html']); // 设置邮件格式为 HTML
  220. $mail->Subject = $msg_item['title']; // 标题
  221. $mail->Body = $mail_content; // 内容
  222. $result = $mail->Send();
  223. $msg_item['result'] = $mail->ErrorInfo;
  224. $msg_item['is_success'] = intval($result);
  225. $msg_item['send_time'] = NOW_TIME;
  226. M("PromoteMsgList")->save($msg_item);
  227. if($result)
  228. {
  229. save_log($log_info.l("SEND_NOW").l("SUCCESS"),1);
  230. header("Content-Type:text/html; charset=utf-8");
  231. echo l("SEND_NOW").l("SUCCESS");
  232. }
  233. else
  234. {
  235. save_log($log_info.l("SEND_NOW").l("FAILED").$mail->ErrorInfo,0);
  236. header("Content-Type:text/html; charset=utf-8");
  237. echo l("SEND_NOW").l("FAILED").$mail->ErrorInfo;
  238. }
  239. }
  240. }
  241. else
  242. {
  243. header("Content-Type:text/html; charset=utf-8");
  244. echo l("SEND_NOW").l("FAILED");
  245. }
  246. }
  247. public function smslist_foreverdelete() {
  248. //彻底删除指定记录
  249. $ajax = intval($_REQUEST['ajax']);
  250. $id = $_REQUEST ['id'];
  251. if (isset ( $id )) {
  252. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  253. $rel_data = M(MODULE_NAME)->where($condition)->findAll();
  254. foreach($rel_data as $data)
  255. {
  256. $info[] = $data['id'];
  257. }
  258. if($info) $info = implode(",",$info);
  259. $list = M(MODULE_NAME)->where ( $condition )->delete();
  260. if ($list!==false) {
  261. save_log($info.l("FOREVER_DELETE_SUCCESS"),1);
  262. $this->success (l("FOREVER_DELETE_SUCCESS"),$ajax);
  263. } else {
  264. save_log($info.l("FOREVER_DELETE_FAILED"),0);
  265. $this->error (l("FOREVER_DELETE_FAILED"),$ajax);
  266. }
  267. } else {
  268. $this->error (l("INVALID_OPERATION"),$ajax);
  269. }
  270. }
  271. }
  272. ?>