where('jg_type',1)->where('jg_status',0)->limit(0,50)->order('id')->select();
foreach ($list as $v) {
UserMessage::where(['id'=>$v['id']])->update(['jg_status'=>1]);
UserMessage::Jpush($v['user_id'],$v['content']);
}
}
/**
* @title 同步回答量
* @desc 同步回答量
* @author qc
* @url /api/Task/forum_num
*/
public function forum_num(){
$forum = UserForum::where('is_deleted',0)->field('id')->select();
foreach ($forum as $k => $v){
$apply = ForumReply::where('forum_id',$v['id'])->where('is_deleted',0)->count();
if($apply){
UserForum::where('id',$v['id'])->update(['r_num'=>$apply]);
}else{
UserForum::where('id',$v['id'])->update(['r_num'=>0]);
}
}
$this->success('执行完成');
}
/**
* @title 标签推送[根据标签id]
* @desc 标签推送
* @author qc
* @url /api/Task/taskLabelMessage
*/
//按照标签推送
public function taskLabelMessage()
{
$list = LabelMessage::where('jg_status',0)->where('is_deleted',0)->select()->toArray();
foreach ($list as $v) {
//定时判断
if($v['is_regular'] == 0){
$date = date('Y-m-d H:i');
$push_time = date('Y-m-d H:i',strtotime($v['push_time']));
if($date < $push_time){
continue;
}
}
//定时判断end
LabelMessage::where(['id'=>$v['id']])->update(['jg_status'=>1]);
$ext = [];
$ext['title'] = $v['title'];
$channel = ['xiaomi'=>"108240",'huawei'=>'IM','oppo'=>'news']; //公信
//$channel = ['xiaomi'=>"108237",'huawei'=>'IM','oppo'=>'message']; //私信
// 全部推送
if(!$v['label']) {
$user_arr = User::where('status',1)->where('is_deleted',0)->column('id');
// return json($user_arr);
foreach ($user_arr as $user_id) {
if($v['type'] == 2){
$res = UserMessage::Jpush($user_id,$v['content'],'','','','',$channel,$ext);
}else if($v['type'] == 3) {
// $ext = [];
// $ext['title'] = $v['title'];
// $channel = ['xiaomi'=>"108240",'huawei'=>'IM','oppo'=>'news'];
if(in_array($v['module'],['video','article','datum'])) {
$res = UserMessage::Jpush($user_id,$v['content'],$v['module'],'',$v['first_id'],$v['second_id'],$channel,$ext);
}else{
// if($v['module'] == 'supplier'){
// //供应商产品
// $res = UserMessage::Jpush($user_id,$v['content'],$v['module'],5,$v['first_id'],'',$channel,$ext);
// }
// if($v['module'] == 'activity'){
// //活动
// $res = UserMessage::Jpush($user_id,$v['content'],$v['module'],3,$v['first_id'],$channel,$ext);
// }
// if($v['module'] == 'forum'){
// //问答
// $res = UserMessage::Jpush($user_id,$v['content'],$v['module'],6,$v['first_id'],$channel,$ext);
// }
// if($v['module'] == 'press'){
// //新闻 暂时没有对应type
// $res = UserMessage::Jpush($user_id,$v['content'],$v['module'],5,$v['first_id'],$channel,$ext);
// }
// if($v['module'] == 'recruit'){
// //招聘 暂时没有对应type
// $res = UserMessage::Jpush($user_id,$v['content'],$v['module'],5,$v['first_id'],$channel,$ext);
// }
$res = UserMessage::Jpush($user_id,$v['content'],$v['module'],'',$v['first_id'],$v['second_id'],$channel,$ext);
}
}
// return json($res);
// $arr = [
// 'user_id' => $user_id,
// 'type' => 4,
// 'log' => json_encode($res),
// ];
// Db::name('client_log')->insert($arr);
}
}else{
// 搜索内容推送
if($v['type'] == 4){
$label = Db::name('user_label')->group('user_id')->where('label','in',$v['label'])->column('user_id');
$user_arr = $label;
}else{
$label_arr = explode(',',$v['label']);
$where_str = '';
$search_arr=[];
$tag_arr = [];
foreach ($label_arr as $t){
$search_arr[] = " title like '".'%'.$t."%'" .' ';
$tag_arr[] = $t;
}
if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr);
// $user_arr = UserSearch::where($where_str)->column('user_id');
//// return json($user_arr);
$user_arr = [];
$user = User::where('label','<>',null)->where('label','<>','||')->where('is_deleted',0)->field('id,label')->select();
$tags = UserTag::where('title','in',$tag_arr)->column('id');
foreach ($user as $key => $val){
$label = explode('|',$val['label']);
foreach ($label as $val1){
if (array_search($val1, $tags) !== false) {
// echo '存在';
$user_arr[] = $val['id'];
} else {
// echo '不存在';
}
}
}
$user_arr = array_unique($user_arr);
}
foreach (array_unique($user_arr) as $user_id) {
if($v['type'] == 2){
// $ext = [];
// $ext['title'] = $v['title'];
// $channel = ['xiaomi'=>"108240",'huawei'=>'IM','oppo'=>'news'];
// $res = UserMessage::Jpush($user_id,$v['content']);
$res = UserMessage::Jpush($user_id,$v['content'],'','','','',$channel,$ext);
}else if($v['type'] == 3 || $v['type'] == 4) {
// $ext = [];
// $ext['title'] = $v['title'];
// $channel = ['xiaomi'=>"108240",'huawei'=>'IM','oppo'=>'news'];
if(in_array($v['module'],['video','article','datum'])) {
$res = UserMessage::Jpush($user_id,$v['content'],$v['module'],'',$v['first_id'],$v['second_id'],$channel,$ext);
}else{
$res = UserMessage::Jpush($user_id,$v['content'],$v['module'],'',$v['first_id'],'',$channel,$ext);
}
}
}
}
}
}
/**
* @title 半年清理一次设备号
* @desc
* @author qc
* @url /api/Task/removeFacility
*/
public function removeFacility(){
UserFacility::where(['set_time','< time',date('Y-m-d H:i:s',strtotime('-180 days'))])->update(['facility'=>'','set_time'=>date('Y-m-d H:i:s')]);
}
/**
* @title 定时取消活动订单
* @desc
* @author qc
* @url /api/Task/cancelApplyOrder
*/
public function cancelApplyOrder()
{
$list = ActivityApply::with(['itemList'])
->where([['create_at','< time',date('Y-m-d H:i:s',strtotime('-5 minutes'))],['pay_type','<>',9],['pay_state','=',0],['cancel_state','=',0]])
->select()->toArray();
foreach ($list as $v) {
Db::startTrans();
try {
ActivityApply::where('id',$v['id'])->update(['cancel_state'=>1]);
$act_title = \app\common\model\Activity::where('id',$v['act_id'])->value('title');
$info_url = 'https://'.$_SERVER['HTTP_HOST'].'/dist/#/activity_order_info?id='.$v['id'];
$message = '您报名的《'.$act_title."》活动订单,由于超时未支付,已为您取消";//,点击查看详情";
UserMessage::sendUserMessage($v['user_id'],'apply',4,0,0,$v['id'],$message,$v['id']);
foreach ($v['item_list'] as $it) {
ActivityPrice::where('id',$it['price_id'])->setInc('stock',$it['num']);
}
Db::commit();
}catch (\Exception $e) {
Db::rollback();
}
}
}
/**
* @title 定时取消商城订单
* @desc
* @author qc
* @url /api/Task/cancelGoodsOrder
*/
public function cancelGoodsOrder()
{
$list = GoodsOrder::with(['orderItem'])
->where([['create_at','< time',date('Y-m-d H:i:s',strtotime('-1 day'))],['status','=',0],['pay_state','=',0],['cancel_state','=',0]])
->select()->toArray();
// return json($list);
$num = 0;
foreach ($list as $v) {
$order_id = $v['id'];
Db::startTrans();
try {
$detail = $v;
if($detail['status'] != 0) $this->exception('订单状态有误');
// 取消订单状态
GoodsOrder::update(['status'=>9,'cancel_state'=>1],['id'=>$order_id]);
// 订单处理
foreach ($detail['order_item'] as $item_info) {
// 更改订单详情状态
GoodsOrderItem::update(['status'=>9],['id'=>$item_info['id']]);
StoreGoodsItem::stockChange($item_info['spec_id'],$item_info['goods_id'],$item_info['num']);
}
Db::commit();
}catch (\Exception $e){
$this->ret_msg = $e->getMessage();
$this->is_commit = false;
Db::rollback();
}
$num++;
}
$this->success('取消'.$num.'条订单');
}
/**
* @title 定时自动收货
* @desc
* @author qc
* @url /api/Task/confirmGoodsOrder
*/
public function confirmGoodsOrder(){
//express_send_at 发货时间
//['express_send_at','< time',date('Y-m-d H:i:s',strtotime('-2 days'))]
$list = GoodsOrder::where([['pay_state','=',1],['status','=',2]])
->select()->toArray();
foreach ($list as $detail) {
$data = get_delivery($detail['express_send_no']);
Db::startTrans();
if($data['issign'] == 1){
$express_send_date = end($data['list']);
$express_send_date = $express_send_date['time'];
if($express_send_date < date('Y-m-d H:i:s',strtotime('-2 days'))){
try {
$order_id = $detail['id'];
// $detail = GoodsOrder::where('id',$order_id)->find()->toArray();
if($detail['status'] == 0) $this->error('订单未支付');
if($detail['status'] == 1) $this->error('订单未发货');
if($detail['status'] == 3) $this->error('订单已收货');
GoodsOrder::update(['status'=>3,'express_state'=>2],['id'=>$order_id]);
GoodsOrderItem::update(['status'=>3,'express_state'=>2],['order_id'=>$order_id]);
UserMessage::create(['user_id'=>$detail['user_id'],'type_id'=>3,'relation_id'=>$order_id,'content'=>'订单收货成功']);
Db::commit();
}catch (\Exception $e) {
Db::rollback();
}
}
}
}
$this->success('执行成功');
}
/**
* @title 活动报名定时提醒
* @desc
* @author qc
* @url /api/Task/activityReminder
*/
public function activityReminder()
{
$where = [];
$where[] = ['task_send','=',0];
$where[] = ['start_time','> time',date('Y-m-d H:i:s',strtotime('-24 hours'))];
$where[] = ['status','=',1];
$where[] = ['is_deleted','=',0];
$list = \app\common\model\Activity::where($where)->select()->toArray();
foreach ($list as $act_info)
{
\app\common\model\Activity::where(['id'=>$act_info['id']])->update(['task_send'=>1]);
$ticket_list = ActivityApplyItem::where(['act_id'=>$act_info['id'],'sh_status'=>1,'is_hx'=>0])->select();
foreach ($ticket_list as $v) {
// 短信通知
if($v['phone_pre'] == '86' && $v['phone']) UserSynth::phoneMessageSend($v['phone'],0,['ActivityName'=>$act_info['title'], 'time'=>$act_info['start_time'], 'adress'=>$act_info['address']]);
}
}
}
/**
* @title 热搜定时
* @desc
* @author qc
* @url /api/Task/topSearchTask
*/
public function topSearchTask()
{
$where[] = ['hot_time','< time',date('Y-m-d H:i:s',strtotime('-7 days'))];
// 视频
$list = VideoUrl::where($where)->column('id');
array_walk($list,function ($v){
VideoUrl::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v,'video');
});
// 图文
$list = ArticleItem::where($where)->column('id');
array_walk($list,function ($v){
ArticleItem::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v,'article');
});
// 资料
$list = DatumUrl::where($where)->column('id');
array_walk($list,function ($v){
DatumUrl::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v,'datum');
});
// 活动
$list = \app\common\model\Activity::where($where)->column('id');
array_walk($list,function ($v){
\app\common\model\Activity::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v,'activity');
});
// 需求
$list = \app\common\model\PlatformDemand::where($where)->column('id');
array_walk($list,function ($v){
\app\common\model\PlatformDemand::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v,'demand');
});
// 新闻
$list = \app\common\model\Press::where($where)->column('id');
array_walk($list,function ($v){
\app\common\model\Press::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v,'press');
});
// 问答
$list = \app\common\model\UserForum::where($where)->column('id');
array_walk($list,function ($v){
\app\common\model\UserForum::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v,'forum');
});
// 招聘
$list = \app\common\model\Recruit::where($where)->column('id');
array_walk($list,function ($v){
\app\common\model\Recruit::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v,'recruit');
});
// 供应商
$list = \app\common\model\SupplierGoods::where($where)->column('id');
array_walk($list,function ($v){
\app\common\model\SupplierGoods::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v,'supplier_goods');
});
// 商品
$list = \app\common\model\StoreGoods::where($where)->column('id');
array_walk($list,function ($v){
\app\common\model\StoreGoods::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v,'goods');
});
$this->success('执行成功');
}
function getDaysFromDate($date) {
$startDate = new \DateTime($date);
$endDate = new \DateTime('now');
$interval = $startDate->diff($endDate);
return $interval->days;
}
/**
* @title 热搜定时1
* @desc
* @author qc
* @url /api/Task/emptyTopSearchTask
*/
public function emptyTopSearchTask1()
{
//热搜规则
//根据后台输入的热搜阅读量排序
//每10分钟前端更新一次
//后台热搜阅读量每天晚上的23:59点,清楚7天前的那一天所有新增的内容的热搜阅读量
//如:
//2023年11月5日,新增了2篇文章,1个视频(不关心是几点新增的)
//2023年11月12日,晚上23:59,将新增的2篇文章跟1个视频的热搜阅读清0
//热搜阅读量可以手动更改,每次有用户点击时,热搜阅读量也增加1
//top_search hot_num
$start_time = date('Y-m-d 00:00:00',strtotime('-7 days'));
$end_time = date('Y-m-d 23:59:59',strtotime('-7 days'));
// return $start_time.'---'.$end_time;
$where[] = ['release_time','> time',$start_time];
$where[] = ['release_time','< time',$end_time];
// $list = TopSearch::where($where)->column('id');
// return json($list);
// TopSearch::where($where)->update(['hot_num'=>0]);
// foreach ($list as $k => $v){
// TopSearch::where('id',$v)->update(['hot_num'=>0]);
// }
//清除热搜实例
// $clean_days = sysconf('clean_days'); //清除热搜天数
//
// $list = \app\common\model\Press::where('release_time','<>','')->field('id,release_time')->order('release_time desc')->select();
// $arr = [];
// foreach ($list as $k => $v){
// $specifiedDate = $v['release_time'];
// $days = $this->getDaysFromDate($specifiedDate);
// $c = $days % $clean_days;
// if($c == 0){
// \app\common\model\Press::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
// TopSearch::saveData($v,'press');
// }
// //echo "从 $specifiedDate 到今天的天数是: $days 天";
// }
// return json($list);
//清除热搜实例end
// 使用示例
$list = VideoUrl::where($where)->column('id');
array_walk($list,function ($v){
VideoUrl::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v,'video');
});
// 图文
$list = ArticleItem::where($where)->column('id');
array_walk($list,function ($v){
ArticleItem::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v,'article');
});
// 资料
$list = DatumUrl::where($where)->column('id');
array_walk($list,function ($v){
DatumUrl::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v,'datum');
});
// 活动
$list = \app\common\model\Activity::where($where)->column('id');
array_walk($list,function ($v){
\app\common\model\Activity::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v,'activity');
});
// 需求
$list = \app\common\model\PlatformDemand::where($where)->column('id');
array_walk($list,function ($v){
\app\common\model\PlatformDemand::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v,'demand');
});
// 新闻
$list = \app\common\model\Press::where($where)->column('id');
array_walk($list,function ($v){
\app\common\model\Press::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v,'press');
});
// 问答
$list = \app\common\model\UserForum::where($where)->column('id');
array_walk($list,function ($v){
\app\common\model\UserForum::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v,'forum');
});
// 招聘
$list = \app\common\model\Recruit::where($where)->column('id');
array_walk($list,function ($v){
\app\common\model\Recruit::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v,'recruit');
});
// 供应商
$list = \app\common\model\SupplierGoods::where($where)->column('id');
array_walk($list,function ($v){
\app\common\model\SupplierGoods::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v,'supplier_goods');
});
// 商品
$list = \app\common\model\StoreGoods::where($where)->column('id');
array_walk($list,function ($v){
\app\common\model\StoreGoods::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v,'goods');
});
$this->success('执行成功');
}
public function emptyTopSearchTask(){
//热搜规则
//根据后台输入的热搜阅读量排序
//每10分钟前端更新一次
//后台热搜阅读量每天晚上的23:59点,清楚7天前的那一天所有新增的内容的热搜阅读量
//如:
//2023年11月5日,新增了2篇文章,1个视频(不关心是几点新增的)
//2023年11月12日,晚上23:59,将新增的2篇文章跟1个视频的热搜阅读清0
//热搜阅读量可以手动更改,每次有用户点击时,热搜阅读量也增加1
//top_search hot_num
$start_time = date('Y-m-d 00:00:00');
$start_time1 = date('Y-m-d 00:00:00',strtotime('-1 days'));
// $end_time = date('Y-m-d 23:59:59',strtotime('-7 days'));
// return $start_time.'---'.$end_time;
// $where[] = ['release_time','> time',$start_time];
// $where[] = ['release_time','< time',$end_time];
// $list = TopSearch::where($where)->column('id');
// return json($list);
// TopSearch::where($where)->update(['hot_num'=>0]);
// foreach ($list as $k => $v){
// TopSearch::where('id',$v)->update(['hot_num'=>0]);
// }
$where = [];
// $where = ['release_time','<>',''];
$clean_days = sysconf('clean_days'); //清除热搜天数
//清除热搜实例
//
//
// $list = \app\common\model\Press::where('release_time','<>','')->field('id,release_time')->order('release_time desc')->select();
// $arr = [];
// foreach ($list as $k => $v){
// $specifiedDate = $v['release_time'];
// $days = $this->getDaysFromDate($specifiedDate);
// $c = $days % $clean_days;
// if($c == 0){
// $arr[] = $v;
// \app\common\model\Press::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
// TopSearch::saveData($v['id'],'press');
// }
// //echo "从 $specifiedDate 到今天的天数是: $days 天";
// }
// return json($arr);
//清除热搜实例end
$where = [];
if($clean_days > 1){
$where[] = ['release_time','< time',$start_time];
$where[] = ['release_time','< time',$start_time1];
}
// 使用示例
//视频
$list = VideoUrl::where('release_time','<>','')->where($where)->field('id,release_time')->order('release_time desc')->select();
foreach ($list as $k => $v){
if($clean_days <= 1){
VideoUrl::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v['id'],'video');
}else{
$specifiedDate = $v['release_time'];
$days = $this->getDaysFromDate($specifiedDate);
$c = $days % $clean_days;
if($c == 0){
VideoUrl::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v['id'],'video');
}
}
//echo "从 $specifiedDate 到今天的天数是: $days 天";
}
// 图文
$list = ArticleItem::where('release_time','<>','')->where($where)->field('id,release_time')->order('release_time desc')->select();
foreach ($list as $k => $v){
if($clean_days <= 1){
ArticleItem::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v['id'],'article');
}else{
$specifiedDate = $v['release_time'];
$days = $this->getDaysFromDate($specifiedDate);
$c = $days % $clean_days;
if($c == 0){
ArticleItem::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v['id'],'article');
}
}
//echo "从 $specifiedDate 到今天的天数是: $days 天";
}
// 资料
$list = DatumUrl::where('release_time','<>','')->where($where)->field('id,release_time')->order('release_time desc')->select();
foreach ($list as $k => $v){
if($clean_days <= 1){
DatumUrl::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v['id'],'datum');
}else{
$specifiedDate = $v['release_time'];
$days = $this->getDaysFromDate($specifiedDate);
$c = $days % $clean_days;
if($c == 0){
DatumUrl::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v['id'],'datum');
}
}
//echo "从 $specifiedDate 到今天的天数是: $days 天";
}
// 活动
$list = \app\common\model\Activity::where('release_time','<>','')->where($where)->field('id,release_time')->order('release_time desc')->select();
foreach ($list as $k => $v){
if($clean_days <= 1){
\app\common\model\Activity::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_nm'=>0]);
TopSearch::saveData($v['id'],'activity');
}else{
$specifiedDate = $v['release_time'];
$days = $this->getDaysFromDate($specifiedDate);
$c = $days % $clean_days;
if($c == 0){
\app\common\model\Activity::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_nm'=>0]);
TopSearch::saveData($v['id'],'activity');
}
}
//echo "从 $specifiedDate 到今天的天数是: $days 天";
}
// 需求
$list = \app\common\model\PlatformDemand::where('release_time','<>','')->where($where)->field('id,release_time')->order('release_time desc')->select();
foreach ($list as $k => $v){
if($clean_days <= 1){
\app\common\model\PlatformDemand::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v['id'],'demand');
}else{
$specifiedDate = $v['release_time'];
$days = $this->getDaysFromDate($specifiedDate);
$c = $days % $clean_days;
if($c == 0){
\app\common\model\PlatformDemand::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v['id'],'demand');
}
}
//echo "从 $specifiedDate 到今天的天数是: $days 天";
}
// 新闻
$list = \app\common\model\Press::where('release_time','<>','')->where($where)->field('id,release_time')->order('release_time desc')->select();
foreach ($list as $k => $v){
if($clean_days <= 1){
\app\common\model\Press::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v['id'],'press');
}else{
$specifiedDate = $v['release_time'];
$days = $this->getDaysFromDate($specifiedDate);
$c = $days % $clean_days;
if($c == 0){
\app\common\model\Press::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v['id'],'press');
}
}
//echo "从 $specifiedDate 到今天的天数是: $days 天";
}
// 问答
$list = \app\common\model\UserForum::where('release_time','<>','')->where($where)->field('id,release_time')->order('release_time desc')->select();
foreach ($list as $k => $v){
if($clean_days <= 1){
\app\common\model\UserForum::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v['id'],'forum');
}else{
$specifiedDate = $v['release_time'];
$days = $this->getDaysFromDate($specifiedDate);
$c = $days % $clean_days;
if($c == 0){
\app\common\model\UserForum::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v['id'],'forum');
}
}
//echo "从 $specifiedDate 到今天的天数是: $days 天";
}
// 招聘
$list = \app\common\model\Recruit::where('release_time','<>','')->where($where)->field('id,release_time')->order('release_time desc')->select();
foreach ($list as $k => $v){
if($clean_days <= 1){
\app\common\model\Recruit::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v['id'],'recruit');
}else{
$specifiedDate = $v['release_time'];
$days = $this->getDaysFromDate($specifiedDate);
$c = $days % $clean_days;
if($c == 0){
\app\common\model\Recruit::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v['id'],'recruit');
}
}
//echo "从 $specifiedDate 到今天的天数是: $days 天";
}
// 供应商
$list = \app\common\model\SupplierGoods::where('release_time','<>','')->where($where)->field('id,release_time')->order('release_time desc')->select();
foreach ($list as $k => $v){
if($clean_days <= 1){
\app\common\model\SupplierGoods::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v['id'],'supplier_goods');
}else{
$specifiedDate = $v['release_time'];
$days = $this->getDaysFromDate($specifiedDate);
$c = $days % $clean_days;
if($c == 0){
\app\common\model\SupplierGoods::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v['id'],'supplier_goods');
}
}
//echo "从 $specifiedDate 到今天的天数是: $days 天";
}
// 商品
$list = \app\common\model\StoreGoods::where('release_time','<>','')->where($where)->field('id,release_time')->order('release_time desc')->select();
foreach ($list as $k => $v){
if($clean_days <= 1){
\app\common\model\StoreGoods::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v['id'],'goods');
}else{
$specifiedDate = $v['release_time'];
$days = $this->getDaysFromDate($specifiedDate);
$c = $days % $clean_days;
if($c == 0){
\app\common\model\StoreGoods::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
TopSearch::saveData($v['id'],'goods');
}
}
//echo "从 $specifiedDate 到今天的天数是: $days 天";
}
$this->success('执行成功');
}
/**
* @title 定时取消商城订单
* @desc
* @author qc
* @url /api/Task/cancelStoreGoods
*/
public function cancelStoreGoods()
{
$list = GoodsOrder::with(['orderItem','orderRefund'])
->where([['pay_state','=',0],['status','=',0],['create_at','< time',date('Y-m-d H:i:s',strtotime('-1 days'))]])
->select()->toArray();
foreach ($list as $detail) {
// 取消订单状态
GoodsOrder::update(['status'=>9,'cancel_state'=>1],['id'=>$detail['id']]);
// 订单处理
foreach ($detail['order_item'] as $item_info) {
// 更改订单详情状态
GoodsOrderItem::update(['status'=>9],['id'=>$item_info['id']]);
StoreGoodsItem::stockChange($item_info['spec_id'],$item_info['goods_id'],$item_info['num']);
}
}
$this->success('执行成功');
}
/**
* @title 定时增加热搜量
* @desc
* @author qc
* @url /api/Task/regular_hot_num
*/
public function regular_hot_num(){
$date = date("Y-m-d H:i:s");
//资料
$list = DatumUrl::where('regular_hot_end_time','> time',$date)->select();
foreach ($list as $k => $v){
if($v['regular_hot_start_time'] < $v['regular_hot_end_time'] && $v['hot_target_num'] > $v['hot_num']){
// $startdate = strtotime($v['regular_hot_start_time']);
// $enddate = strtotime($v['regular_hot_end_time']);
// $diff_seconds = ($enddate-$startdate)/60;
// $min_num = ceil($diff_seconds/10);
// $hot_num = $v['hot_target_num'] - $v['hot_num'];
// $num = ceil($hot_num/$min_num);
$t_num = $v['hot_num'] + $v['regular_num'];
\app\common\model\DatumUrl::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>$t_num]);
TopSearch::saveData($v['id'],'datum');
}
}
//图文
$list = ArticleItem::where('regular_hot_end_time','> time',$date)->select();
foreach ($list as $k => $v){
if($v['regular_hot_start_time'] < $v['regular_hot_end_time'] && $v['hot_target_num'] > $v['hot_num']){
$t_num = $v['hot_num'] + $v['regular_num'];
ArticleItem::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>$t_num]);
TopSearch::saveData($v['id'],'article');
}
}
//视频
$list = VideoUrl::where('regular_hot_end_time','> time',$date)->select();
foreach ($list as $k => $v){
if($v['regular_hot_start_time'] < $v['regular_hot_end_time'] && $v['hot_target_num'] > $v['hot_num']){
$t_num = $v['hot_num'] + $v['regular_num'];
VideoUrl::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>$t_num]);
TopSearch::saveData($v['id'],'video');
}
}
//问答
$list = UserForum::where('regular_hot_end_time','> time',$date)->select();
foreach ($list as $k => $v){
if($v['regular_hot_start_time'] < $v['regular_hot_end_time'] && $v['hot_target_num'] > $v['hot_num']){
$t_num = $v['hot_num'] + $v['regular_num'];
UserForum::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>$t_num]);
TopSearch::saveData($v['id'],'forum');
}
}
//新闻
$list = \app\common\model\Press::where('regular_hot_end_time','> time',$date)->select();
foreach ($list as $k => $v){
if($v['regular_hot_start_time'] < $v['regular_hot_end_time'] && $v['hot_target_num'] > $v['hot_num']){
$t_num = $v['hot_num'] + $v['regular_num'];
\app\common\model\Press::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>$t_num]);
TopSearch::saveData($v['id'],'press');
}
}
//活动
$list = \app\common\model\Activity::where('regular_hot_end_time','> time',$date)->select();
foreach ($list as $k => $v){
if($v['regular_hot_start_time'] < $v['regular_hot_end_time'] && $v['hot_target_num'] > $v['hot_nm']){
$t_num = $v['hot_nm'] + $v['regular_num'];
\app\common\model\Activity::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_nm'=>$t_num]);
TopSearch::saveData($v['id'],'activity');
}
}
//招聘
$list = \app\common\model\Recruit::where('regular_hot_end_time','> time',$date)->select();
foreach ($list as $k => $v){
if($v['regular_hot_start_time'] < $v['regular_hot_end_time'] && $v['hot_target_num'] > $v['hot_num']){
$t_num = $v['hot_num'] + $v['regular_num'];
\app\common\model\Recruit::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>$t_num]);
TopSearch::saveData($v['id'],'recruit');
}
}
//需求
$list = \app\common\model\PlatformDemand::where('regular_hot_end_time','> time',$date)->select();
foreach ($list as $k => $v){
if($v['regular_hot_start_time'] < $v['regular_hot_end_time'] && $v['hot_target_num'] > $v['hot_num']){
$t_num = $v['hot_num'] + $v['regular_num'];
\app\common\model\PlatformDemand::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>$t_num]);
TopSearch::saveData($v['id'],'demand');
}
}
//供应商
$list = \app\common\model\SupplierGoods::where('regular_hot_end_time','> time',$date)->select();
foreach ($list as $k => $v){
if($v['regular_hot_start_time'] < $v['regular_hot_end_time'] && $v['hot_target_num'] > $v['hot_num']){
$t_num = $v['hot_num'] + $v['regular_num'];
\app\common\model\SupplierGoods::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>$t_num]);
TopSearch::saveData($v['id'],'supplier_goods');
}
}
$this->success('执行成功');
}
/**
* @title 发送邮箱验证码
* @desc 发送邮箱验证码
* @author qc
* @url /api/Task/detectionEmail
* @method POST
* @tag 邮箱验证码
* @param name:email type:int require:1 default:-- desc:邮箱
* @return name:code type:string default:-- desc:验证码
*/
public function detectionEmail(){
$Expedite = new Expedite();
$esms = $Expedite->emailSms('2014945457@qq.com');
return json_encode($esms,true);
}
/**
* @title 发送邮箱验证码
* @desc 发送邮箱验证码
* @author qc
* @url /api/Task/emailSms
* @method POST
* @tag 邮箱验证码
* @param name:email type:int require:1 default:-- desc:邮箱
* @return name:code type:string default:-- desc:验证码
*/
function emailSms($email = ''){
//$email = input('post.email');
$user_info = User::where('email',$email)->where('is_deleted',0)->field('id,status')->find();
if($user_info && $user_info['status'] == 0)$this ->error('用户被禁用,请联系官方');
$code = rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9);
require_once env('root_path').'/vendor/aliyunmail/aliyun-php-sdk-core/Config.php';
$iClientProfile = \DefaultProfile::getProfile("cn-hangzhou", "LTAI5tJ5p12drZegeWVG33xZ", "82UWAiY5e5wH8tSkRvMtqVoGO0h8SB");
$client = new \DefaultAcsClient($iClientProfile);
$request = new Dm\SingleSendMailRequest();
// D:\project\gyx\gaoyixia\vendor\aliyunmail\aliyun-php-sdk-dm\Dm\Request\V20151123\SingleSendMailRequest.php
$request->setAccountName("gyx@yzm.gyxqcdz.com");
$request->setFromAlias("[验证码]");
$request->setAddressType(1);
$request->setTagName("zonghuzhuche");
$request->setReplyToAddress("true");
$request->setToAddress($email);
$request->setSubject("验证码");
$img= "http://gaoyixia.hdlkeji.com/code/33.png";
$img ="
";
$html_body = '您的验证码'.$code.'有效时间5分钟';
$request->setHtmlBody($html_body);
try {
$send_res = $client->getAcsResponse($request);
$sms_data = array(
'phone'=>$email,
'code'=>$code,
'result'=>'OK'
);
Db::name('store_member_sms')->insert($sms_data);
$this->success('发送成功');
} catch (ClientException $e) {
$this->error($e->getErrorMessage());
// print_r($e->getErrorCode());
// print_r($e->getErrorMessage());
} catch (ServerException $e) {
$this->error($e->getErrorMessage());
// print_r($e->getErrorCode());
// print_r($e->getErrorMessage());
}
}
}