admin/addon/aliapp/event/NoticeImpendingExpiration.php

83 lines
3.0 KiB
PHP

<?php
/**
* SAAS应用系统 --- 十年开发经验汇集巨献!
* ==========================================================
* Copy right 2020-2050 成都众联思索科技有限公司,保留所有权利。
* ----------------------------------------------------------
* 官方网址: https://www.zoomtk.com
* 这不是自由软件!未经允许不得用于商业目或程序代码摘取及修改。
* 任何企业和个人未经允许对程序代码以任何形式任何目的再发布传播。
* 唯一发布渠道www.zoomtk.com;非官方渠道统一视为侵权行为。
* ==========================================================
*/
namespace addon\aliapp\event;
use addon\aliapp\model\AliPayMessage;
use app\model\NewBaseModel;
use think\facade\Db;
class NoticeImpendingExpiration{
private $limit = 10;
public function handle($param = []){
$this->noticeMessageHandle();
return $param;
}
/**
* Common: 权益即将过期通知
* Author: wu-hui
* Time: 2023/01/11 10:43
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function noticeMessageHandle(){
// 获取通知列表
$list = $this->getList();
$updateData = [];
foreach($list as $item){
// 发送通知
$res = (new AliPayMessage($item['site_id']))->sendMessage($item['member_id'],'INTEREST_EXPIRATION_NOTICE',[
'store_name' => $item['store_name'],// 商家名称
'surplus' => (int)$item['surplus'],// 剩余次数
'content' => $item['goods_name'],// 优惠内容
]);
// 发送成功
if($res['code'] == 0){
$updateData[] = [
'id' => $item['id'],
'time_notice' => time(),
'is_notice' => 1,
];
}
}
(new NewBaseModel(['table_name'=>'member_goods_card_notice']))->saveAll($updateData);
}
/**
* Common: 获取通知列表
* Author: wu-hui
* Time: 2023/01/11 10:38
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function getList(){
$list = Db::name('member_goods_card_notice')->alias('mgcn')
->join('member_goods_card mgc','mgcn.member_goods_card = mgc.card_id','left')
->join('store','mgc.store_id = store.store_id','left')
->field('mgcn.id,mgc.site_id,mgc.member_id,mgc.goods_name,(mgc.total_num - mgc.total_use_num) as surplus,store.store_name')
->where('mgcn.id','>',0)
->where('mgcn.is_notice',0)
->order('mgcn.id','ASC')
->limit($this->limit)
->select();
return $list ? $list->toArray() : [];
}
}