1]) ->where('created_at', '<=', $cancelTime) ->count('id'); Books::where(['status' => 1]) ->where('created_at', '<=', $cancelTime) ->update(['status' => 4, 'remark' => '超时自动取消']); // 已取消的删除 $deleteTime = date('Y-m-d H:i:s', time() - 3 * 24 * 3600); $deleteCount = Books::where(['status' => 4]) ->where('created_at', '<=', $deleteTime) ->count('id'); Books::where(['status' => 4]) ->where('created_at', '<=', $deleteTime) ->delete(); $msg = "报名订单自动取消已处理成功,累计取消{$cancelCount}个,删除{$deleteCount}个"; return showJson(1005, $msg, '', "\n"); } catch (\Exception $exception) { return showJson(1004, $exception->getMessage(), '', "\n"); } } /** * 认识申请超时处理 */ public function cancelContact() { $key = input('key', ''); $checkKey = config('task.contactKey'); if ($key != $checkKey) { showJson(1004, 2009, '', "\n"); } try { // 申请失效时间 $siteInfo = cmf_get_site_info(); $expire = isset($siteInfo['contact_time']) ? intval($siteInfo['contact_time']) : 0; $expire = $expire ? $expire : 1; $dataList = UserContactLog::where(['status' => 1]) ->where('created_at', '<', date('Y-m-d H:i:s', time() - $expire * 24 * 3600)) ->field('id,contact_uid') ->select(); if (empty($dataList)) { showJson(1004, 1003, '', "\n"); } $results = []; foreach ($dataList as $val) { $cid = isset($val['id']) ? intval($val['id']) : 0; $userId = isset($val['contact_uid']) ? intval($val['contact_uid']) : 0; if ($cid && $userId) { $res = Member::contactConfirm($userId, $cid, 4); if (is_array($res)) { $results[] = $res; } } } PRedis::set('tasks:contact:' . date('Ymd'), ['datalist' => $dataList, 'result' => $results], 3600); $msg = "认识申请记录超时处理结果,累计处理" . count($results) . "个"; return showJson(1005, $msg, "\n"); } catch (\Exception $exception) { return showJson(1004, $exception->getMessage(), '', "\n"); } } /** * 批量推荐队列处理 */ public function catchMakeHearts() { set_time_limit(0); $key = input('key', ''); $checkKey = config('task.heartKey'); if ($key != $checkKey) { showJson(1004, 2009, '', "\n"); } try { $userIds = []; $queenKey = "queens:hearts:" . date('Ymd'); //echo $queenKey."
\n"; for ($i = 0; $i < 500; $i++) { $userId = PRedis::lpop($queenKey); //echo $userId."\n"; if ($userId) { $userIds[] = $userId; $url = url('/api/task/catchUserHeart', '', '', true); httpRequest($url, ['uid' => $userId], 'post', '', 2); } } $msg = "更新推荐数据结果,累计处理" . count($userIds) . "个会员数据更新"; return showJson(1005, $msg, "\n"); } catch (\Exception $exception) { return showJson(1004, $exception->getMessage(), '', "\n"); } } /** * 清除过期签到爱心 */ public function clearSignHeart() { set_time_limit(0); $key = input('key', ''); $checkKey = config('task.clearHeartKey'); if ($key != $checkKey) { showJson(1004, 2009, '', "\n"); } try { $month = date('Y-m-01', time() - 2 * 86400); $users = AccountLog::where(['type' => 12, 'status' => 2]) ->where('created_at', '>=', $month) ->order('created_at', 'asc') ->column('user_id'); $userIds = []; if ($users) { foreach ($users as $userId) { // 清除签到爱心 if ($userId && \app\weixin\service\Member::clearSignRedHeart($userId)) { $userIds[] = $userId; } } } $msg = "清除签到爱心数据结果,共" . count($users) . "个,累计处理" . count($userIds) . "个会员数据更新"; return showJson(1005, $msg, "\n"); } catch (\Exception $exception) { return showJson(1004, $exception->getMessage(), '', "\n"); } } /** * 处理怦然心动 */ public function catchUserHeart() { $uid = input('uid', 0); $dataList = Member::getHeartList($uid, '', true); showJson(1005, 1001, $dataList); } /** * 更新怦然心动推荐数据入队处理 */ public function makeHearts() { set_time_limit(0); $key = input('key', ''); $checkKey = config('task.heartKey'); if ($key != $checkKey) { showJson(1004, 2009, '', "\n"); } try { // 查询需要推荐的用户 $dataList = Member::alias('m') ->join('user_profile up', 'up.userid=m.id', 'left') ->field('m.openid,m.user_nickname,m.id,up.idcard_check,m.is_reg_profile') ->where(['m.user_status' => 1, 'm.user_type' => 2, 'up.idcard_check' => 2, 'm.is_reg_profile' => 1]) ->where(function ($query) { return $query->where('m.heart_recommend_at', '<', date('Y-m-d 19:00:00')) ->whereOr('m.heart_recommend_at', 'exp', 'is null'); }) ->order('m.id') ->column('m.id'); if (empty($dataList)) { showJson(1004, 1003, '', "\n"); } $sql = Member::getLastSql(); //echo $sql; // 处理数据更新 $userids = []; $queenKey = "queens:hearts:" . date('Ymd'); foreach ($dataList as $userId) { if ($userId && PRedis::rpush($queenKey, $userId)) { $userids[] = $userId; } } PRedis::expire($queenKey, 2 * 3600); PRedis::set('tasks:hearts:' . date('Ymd'), ['datalist' => $dataList, 'results' => $userids, 'time' => date('Y-m-d H:i:s'), 'sql' => $sql], 3600); $msg = "更新推荐数据入队结果,累计处理" . count($userids) . "个会员数据更新"; return showJson(1005, $msg, "\n"); } catch (\Exception $exception) { return showJson(1004, $exception->getMessage(), '', "\n"); } } /** * 更新隐身 * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException */ public function updateHeartStatus() { set_time_limit(0); $key = input('key', ''); $checkKey = config('task.upHeartKey'); if ($key != $checkKey) { showJson(1004, 2009, '', "\n"); } $where = ['m.is_heart' => 1, 'm.is_reg_profile' => 1, 'm.user_status' => 1, 'm.user_type' => 2]; $dataList = Member::alias('m') ->join('user_profile up', 'up.userid=m.id', 'left') ->where($where) ->where(function ($query) { $query->where(db()->raw("up.introduce is NULL or up.introduce = ''")) ->whereOr(db()->raw("up.family is NULL or up.family = ''")) ->whereOr(db()->raw("up.hobby is NULL or up.hobby = ''")) ->whereOr(db()->raw("up.purpose is NULL or up.purpose = ''")) ->whereOr(db()->raw("up.cause is NULL or up.cause = ''")) ->whereOr(db()->raw("up.expect is NULL or up.expect = ''")); }) ->field('m.id,up.introduce,up.family,up.hobby,up.purpose,up.cause,up.expect') ->select() ->each(function ($profile, $k) { if (empty($profile) || (empty($profile['photolist']) || empty($profile['introduce']) || empty($profile['family']) || empty($profile['hobby']) || empty($profile['purpose']) || empty($profile['cause']) || empty($profile['expect']))) { Member::where(['id' => $profile['id']])->update(['is_heart' => 2, 'remark' => '系统检测自动设置隐身']); } }); showJson(1005, 1001, $dataList); } /** * 活动报名分销收益结算 * @throws \think\Exception * @throws \think\Exception\DbException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException */ public function catchBookMarket() { set_time_limit(0); $key = input('key', ''); $checkKey = config('task.catchBookMarket'); if ($key != $checkKey) { showJson(1004, 2009, '', "\n"); } $catchIds = []; $catchList = []; $bookList = Books::alias('b') ->leftJoin('activity a', 'a.id=b.aid') ->leftJoin('user u', 'u.id=b.uid') ->where('a.endtime', '<=', time()) // ->where('a.endtime', '>', time()-24*3600*3) ->where('u.parent_id', '>', 0) ->where(['a.is_top' => 0, 'a.status' => 1, 'b.status' => 3, 'b.is_market' => 2]) ->field('b.id,b.uid,b.aid,b.money,u.parent_id,b.status') ->order('a.endtime desc, b.book_at asc,b.id asc') ->paginate(80) ->each(function ($item, $k) use (&$catchList, &$catchIds) { $userId = isset($item['uid']) ? intval($item['uid']) : 0; $aid = isset($item['aid']) ? $item['aid'] : 0; $money = isset($item['money']) ? floatval($item['money']) : 0; $inviteInfo = Member::getInviteInfo($userId); $inviteId = isset($inviteInfo['invite_id']) ? $inviteInfo['invite_id'] : 0; //$item['invite'] = $inviteInfo; PRedis::set('markets:activity:book_temp_' . $aid . ':' . $userId . '_' . $inviteId, ['info' => $item, 'inviteInfo' => $inviteInfo], 5 * 86400); if ($inviteInfo && $inviteId > 0 && $aid > 0 && $money > 0) { if (!UserBalanceLog::checkHasMarketBySource($inviteId, $userId, $aid, 9)) { $catchList[] = $item; PRedis::set('markets:activity:book_' . $aid . ':' . $userId . '_' . $inviteId, ['info' => $item, 'inviteInfo' => $inviteInfo], 7200); Award::marketAward($inviteId, $userId, 9, $money); $catchIds[] = $item['id']; } } }); if ($catchIds) { Books::whereIn('id', $catchIds)->update(['is_market' => 1, 'remark' => '分销已结算']); } $bookList = $bookList ? $bookList->toArray() : []; showJson(1005, 1001, ['total' => $bookList['total'], 'bookList' => $bookList['data'], 'catchList' => $catchList]); } /** * 更新报表数据 * @throws \think\Exception * @throws \think\exception\PDOException */ public function updateExport() { set_time_limit(0); $key = input('key', ''); $checkKey = config('task.updateExport'); if ($key != $checkKey) { showJson(1004, 2009, '', "\n"); } $result = Export::updateData(); showJson(1005, 1001, ['ids' => $result, 'date' => date('Y-m-d H:i:s')]); } /** * 更新销售资源过期数据 * @throws \think\Exception * @throws \think\exception\PDOException */ public function salesExpired() { set_time_limit(0); $key = input('key', ''); $checkKey = config('task.salesExpired'); if ($key != $checkKey) { showJson(1004, 2009, '', "\n"); } if(date("H:i") >= '05:00'){ showJson(1004, 2009, '', "\n"); } $count = 0; $datas = []; $result = PoolModel::alias('p') // ->where('p.expire_at', '<', date('Y-m-d H:i:s')) ->where(['p.type' => 0, 'p.status' => 1]) ->field('id,sale_uid,user_id,followup_num,expire_at') ->limit(100) ->order('p.expire_at asc,p.id asc') ->select() ->each(function ($item, $k) use ($count, $datas) { $userId = isset($item['user_id']) ? $item['user_id'] : 0; $expireAt = isset($item['expire_at']) ? $item['expire_at'] : ''; $updateData = ['updated_at' => date('Y-m-d H:i:s')]; // 到期数据处理 if($expireAt && $expireAt <= date('Y-m-d H:i:s')){ $data = [ 'sale_uid' => 0, 'user_id' => $userId, 'type' => 2, 'followup_num' => 0, 'intention' => 0, 'create_time' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'), 'expire_at' => 0, 'status' => 1, ]; $info = PoolModel::checkData($userId); if (empty($info)) { $datas[] = $data; } else { PoolModel::where(['id' => $info['id'], 'user_id' => $userId])->update($data); } // 到期未跟进 $updateData['stop_time'] = date('Y-m-d H:i:s'); if($item['followup_num'] <= 0){ $updateData['agency'] = 3; } $count++; }else if ($expireAt){ // 今日坠海 $time = strtotime($expireAt); $dayTime = strtotime(date('Y-m-d')); if($time >= time() && $time < $dayTime + 86400){ $item['expire_text'] = '今天坠海'; $updateData['agency'] = 4; }else if($time>=$dayTime+86400 && $time < $dayTime + 2 * 86400){ $item['expire_text'] = '明天坠海'; $updateData['agency'] = 5; }else if($time>=$dayTime+7*86400 && $time < $dayTime + 15 * 86400){ $item['expire_text'] = '一礼拜后坠海'; } $updateData = []; } // 更新待办事项 if($updateData){ $count++; PoolModel::where(['id' => $item['id']])->update($updateData); } }); if ($datas) { PoolModel::insertAll($datas); } // 缓存 PRedis::set("caches:sales:expired", ['datas'=> $datas,'result'=> $result, 'date'=> date('Y-m-d H:i:s')], 86400); showJson(1005, 1008, ['count' => $count, 'date' => date('Y-m-d H:i:s')]); } }