| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- <?php
- namespace app\api\controller;
- use app\portal\model\UserModel;
- use app\weixin\model\Books;
- use app\weixin\model\Devices;
- use app\weixin\model\Member;
- use app\weixin\model\UserContactLog;
- use app\weixin\service\PRedis;
- use think\Controller;
- class TaskController extends Controller
- {
- /**
- * 订单超时处理
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function catchBook()
- {
- try {
- $key = input('key', '');
- $checkKey = config('task.key');
- if ($key != $checkKey) {
- showJson(1004, 2009, '', "\n");
- }
- $cancelTime = config('task.orderCancelTime');
- $cancelTime = $cancelTime ? $cancelTime * 60 : 30 * 60;
- // 未支付
- $cancelTime = date('Y-m-d H:i:s', time() - $cancelTime);
- $cancelCount = Books::where(['status' => 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."<br>\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);
- }
- }
|