123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- <?php
- namespace app\common\model;
- use think\facade\Db;
- class Smslog extends BaseModel
- {
- public $page_info;
-
- function sendSms($smslog_phone, $smslog_param, $smslog_type = '', $smslog_captcha = '', $member_id = '0', $member_name = '', $if_queue = false)
- {
- $smslog_msg = $smslog_param['message'];
-
- $begin_add_time = strtotime(date('Y-m-d', TIMESTAMP));
- $end_add_time = strtotime(date('Y-m-d', TIMESTAMP)) + 24 * 3600;
-
- $condition = array();
- $condition[] = array('smslog_ip', '=', request()->ip());
- $condition[] = array('smslog_smstime', 'between', array($begin_add_time, $end_add_time));
- if ($smslog_captcha && $this->getSmsCount($condition) > 20) {
- return array('state' => FALSE, 'code' => 10001, 'message' => '同一IP地址一天内只能发送20条短信,请勿多次获取动态码!');
- }
-
- $condition = array();
- $condition[] = array('smslog_phone', '=', $smslog_phone);
- $condition[] = array('smslog_smstime', 'between', array(TIMESTAMP - 30, TIMESTAMP));
- if ($smslog_captcha && $this->getSmsCount($condition) > 0) {
- return array('state' => FALSE, 'code' => 10001, 'message' => '同一手机30秒后才能再次发送短信,请勿多次获取动态码!');
- }
-
- $condition = array();
- $condition[] = array('smslog_phone', '=', $smslog_phone);
- $condition[] = array('smslog_smstime', 'between', array($begin_add_time, $end_add_time));
- if ($smslog_captcha && $this->getSmsCount($condition) > 5) {
- return array('state' => FALSE, 'code' => 10001, 'message' => '同一手机一天内只能发送5条短信,请勿多次获取动态码!');
- }
-
- $condition = array();
- $condition[] = array('smslog_msg', '=', $smslog_msg);
- $condition[] = array('smslog_smstime', 'between', array($begin_add_time, $end_add_time));
- if ($this->getSmsCount($condition) > 3) {
- return array('state' => FALSE, 'code' => 10001, 'message' => '相同的短信内容,一天不能发送3次!');
- }
-
- if (empty($member_id) || empty($member_name)) {
-
- $member = model('member')->getMemberInfo(array('member_mobile' => $smslog_phone));
- $member_id = isset($member['member_id']) ? $member['member_id'] : '0';
- $member_name = isset($member['member_name']) ? $member['member_name'] : '';
- }
- $smslog_state = 0;
- if (!$if_queue) {
- $sms = new \sendmsg\Sms();
- $send_result = $sms->send($smslog_phone, $smslog_param);
- if ($send_result['code'] == true) {
- $smslog_state = 1;
- } else {
- return array('state' => FALSE, 'code' => 10001, 'message' => $send_result['msg']);
- }
- } else {
- $smslog_msg = json_encode($smslog_param);
- }
- $log['smslog_phone'] = $smslog_phone;
- $log['smslog_captcha'] = $smslog_captcha;
- $log['smslog_ip'] = request()->ip();
- $log['smslog_msg'] = $smslog_msg;
- $log['smslog_type'] = $smslog_type;
- $log['smslog_smstime'] = TIMESTAMP;
- $log['member_id'] = $member_id;
- $log['member_name'] = $member_name;
- $log['smslog_state'] = $smslog_state;
- $result = $this->addSms($log);
- if ($result >= 0) {
- return array('state' => TRUE, 'code' => 10000, 'message' => '');
- } else {
- return array('state' => FALSE, 'code' => 10001, 'message' => '手机短信发送失败');
- }
- }
-
- public function editSms($update, $condition)
- {
- return Db::name('smslog')->where($condition)->update($update);
- }
-
- public function addSms($log_array)
- {
- $log_id = Db::name('smslog')->insertGetId($log_array);
- return $log_id;
- }
-
- public function getSmsInfo($condition)
- {
- if (empty($condition)) {
- return false;
- }
- $result = Db::name('smslog')->where($condition)->order('smslog_id desc')->find();
- return $result;
- }
-
- public function getSmsList($condition = array(), $pagesize = '', $limit = 0, $order = 'smslog_id desc')
- {
- if ($pagesize) {
- $result = Db::name('smslog')->where($condition)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
- $this->page_info = $result;
- $result = $result->items();
- } else {
- $result = Db::name('smslog')->where($condition)->limit($limit)->order($order)->select()->toArray();
- }
- return $result;
- }
-
- public function getSmsCount($condition)
- {
- return Db::name('smslog')->where($condition)->count();
- }
-
- public function delSmsLog($condition)
- {
- return Db::name('smslog')->where($condition)->delete();
- }
- }
|