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 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); } }