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() : []; } }