You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
4.1 KiB
137 lines
4.1 KiB
<?php
|
|
/*----------------------------------------------------------------------
|
|
* 项目名称: CloudAdmin
|
|
* +----------------------------------------------------------------------
|
|
* 版权所有: 2014~2020 安徽云掌开发团队
|
|
* +----------------------------------------------------------------------
|
|
* 官方网站: [ http://www.yaoyz.com、http://www.ahyunzhang.com ]
|
|
* +----------------------------------------------------------------------
|
|
* Date: 2018/11/15 9:47
|
|
* +----------------------------------------------------------------------
|
|
* Des: 短信插件
|
|
+----------------------------------------------------------------------*/
|
|
|
|
|
|
namespace app\index\controller;
|
|
|
|
use think\Controller;
|
|
use think\Db;
|
|
|
|
class Crontab extends Controller
|
|
{
|
|
|
|
/**
|
|
* 房间表
|
|
* @var string
|
|
*/
|
|
private $table_room = 'CloudHouseRoom';
|
|
|
|
/**
|
|
* 一手房源时间节点副表
|
|
* @var string
|
|
*/
|
|
private $table_house_crontab = 'CloudHouseCrontab';
|
|
|
|
|
|
/**
|
|
* 租户表
|
|
* @var string
|
|
*/
|
|
private $table_tenant = 'CloudHouseTenant';
|
|
|
|
/**
|
|
* 短信日志表
|
|
* @var string
|
|
*/
|
|
private $table_sms_log = 'CloudSmsLog';
|
|
|
|
/**
|
|
* html5支付页面
|
|
* @var string
|
|
*/
|
|
private $url = 'http://xunxibaoapi.yaoyz.com/index/pay/index';
|
|
|
|
/**
|
|
* 到期子房源提醒
|
|
* @param int $day 默认3天
|
|
*/
|
|
public function index($day = 30)
|
|
{
|
|
if ($day && is_numeric($day)) {
|
|
//计算指定天数后的时间戳
|
|
$day_time = strtotime('+' . $day . ' day');
|
|
$_where[] = ['r.end_time', '<', $day_time]; //结束时间小于当前时间+30天
|
|
$_where[] = ['r.end_time', '>', time()]; //且结束时间大于当前时间
|
|
$_where[] = ['r.end_time', '<>', ''];
|
|
}
|
|
$_where[] = ['r.is_del', '=', 0];
|
|
$_data = Db::name($this->table_room)->alias('r')->leftJoin('cloud_house_tenant t', 'r.id = t.room_id')->where($_where)->field('r.*,t.phone,t.name')->select();
|
|
$this->send($_data);
|
|
}
|
|
|
|
/**
|
|
* 到期一手房源提醒
|
|
* @param int $day 默认3天
|
|
*/
|
|
public function house($day = 3)
|
|
{
|
|
if ($day && is_numeric($day)) {
|
|
//计算指定天数后的时间戳
|
|
$day_time = strtotime('+' . $day . ' day');
|
|
$_where[] = ['create_time', '<', $day_time]; //结束时间小于当前时间+30天
|
|
$_where[] = ['create_time', '>', time()]; //且结束时间大于当前时间
|
|
$_where[] = ['create_time', '<>', ''];
|
|
}
|
|
$_data = Db::name($this->table_house_crontab)->where($_where)->select();
|
|
$this->sendHouse($_data);
|
|
}
|
|
|
|
/**
|
|
* 执行短信发送
|
|
* @param $_arr
|
|
*
|
|
*/
|
|
private function send($_arr)
|
|
{
|
|
if (empty($_arr)) {
|
|
return;
|
|
}
|
|
$curr_month = date('Y-m');
|
|
$_sms = new \app\api\controller\Sms();
|
|
foreach ($_arr as $k => $v) {
|
|
$_str = [
|
|
'{url}' => $this->url . '?roomid=' . $v['id'] . '&phone=' . $v['phone'] . '&name=' . $v['name']
|
|
];
|
|
//判断本月是否发送过,已发送不再发送
|
|
$_data = Db::name($this->table_sms_log)->where('mobile', $v['phone'])->where('month', $curr_month)->find();
|
|
if (empty($_data)) {
|
|
$_sms::sendNotify($v['phone'], $_str, 23);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 执行短信发送
|
|
* @param $_arr
|
|
*
|
|
*/
|
|
private function sendHouse($_arr)
|
|
{
|
|
if (empty($_arr)) {
|
|
return;
|
|
}
|
|
$curr_month = date('Y-m');
|
|
$_sms = new \app\api\controller\Sms();
|
|
foreach ($_arr as $k => $v) {
|
|
$_str = [
|
|
'{address}' => $v['address'] . $v['house_name'] . $v['door_number']
|
|
];
|
|
//判断本月是否发送过,已发送不再发送
|
|
$_data = Db::name($this->table_sms_log)->whereLike('text', '%' . $v["house_name"] . '%')->where('mobile', $v['phone'])->where('month', $curr_month)->find();
|
|
if (empty($_data)) {
|
|
$_sms::sendNotify($v['phone'], $_str, 24);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|