admin/addon/aliapp/event/ImpendingExpirationListGet.php

128 lines
4.4 KiB
PHP

<?php
/**
* SAAS应用系统 --- 十年开发经验汇集巨献!
* ==========================================================
* Copy right 2020-2050 成都众联思索科技有限公司,保留所有权利。
* ----------------------------------------------------------
* 官方网址: https://www.zoomtk.com
* 这不是自由软件!未经允许不得用于商业目或程序代码摘取及修改。
* 任何企业和个人未经允许对程序代码以任何形式任何目的再发布传播。
* 唯一发布渠道www.zoomtk.com;非官方渠道统一视为侵权行为。
* ==========================================================
*/
namespace addon\aliapp\event;
use think\facade\Db;
class ImpendingExpirationListGet{
private $limit = 500;
public function handle($param = []){
$this->noticeHandle();
return $param;
}
/**
* Common: 权益即将过期列表获取
* Author: wu-hui
* Time: 2023/01/11 10:25
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function noticeHandle(){
// 获取所有开启通知的商家设置信息
$configList = $this->getConfigList();
// 获取即将过期信息
$list = $this->getExpiringSoonList($configList);
$insertData = [];
foreach($list as $item){
$insertData[] = [
'site_id' => $item['site_id'],
'uid' => $item['member_id'],
'member_goods_card' => $item['card_id'],
'time_day' => $configList[$item['site_id']],
'time_notice' => 0,
'is_notice' => 0,
];
}
Db::name('member_goods_card_notice')->insertAll($insertData);
}
/**
* Common: 获取所有平台的 服务卡即将过期提前多少天提醒设置
* Author: wu-hui
* Time: 2023/01/11 9:29
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function getConfigList(){
$list = Db::name('config')
->field("convert(json_extract(value,'$.days_in_advance'), signed) as days_in_advance,site_id")
->where('config_key','ORDER_EVENT_TIME_CONFIG')
->where("convert(json_extract(value,'$.days_in_advance'), signed) > 0")
->select();
if($list) {
$list = $list->toArray();
return array_column($list,'days_in_advance','site_id');
}
return [];
}
/**
* Common: 获取指定数量的即将过期信息列表
* Author: wu-hui
* Time: 2023/01/11 10:20
* @param $configList
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function getExpiringSoonList($configList){
$list = [];
foreach($configList as $siteId => $days_in_advance){
// 获取过期时间
$endTime = strtotime("+{$days_in_advance} day");
$list = array_merge($list,$this->getExpiringList($siteId,$endTime,(int)($this->limit - count($list))));
if(count($list) >= $this->limit) break;
}
return $list;
}
/**
* Common: 根据条件获取对应的信息列表
* Author: wu-hui
* Time: 2023/01/11 10:20
* @param $siteId
* @param $endTime
* @param $maxNum
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function getExpiringList($siteId,$endTime,$maxNum){
$list = Db::name('member_goods_card')->alias('mgc')
->join('member_goods_card_notice mgcn','mgcn.member_goods_card = mgc.card_id','left')
->field('mgc.site_id,mgc.member_id,mgc.card_id')
->where('mgc.site_id',$siteId)
->where('mgc.end_time','<=',$endTime)
->where('mgcn.id IS NULL')
->order('mgc.end_time','ASC')
->limit($maxNum)
->select();
return $list ? $list->toArray() : [];
}
}