| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- <?php
- namespace app\api\controller;
- use app\portal\model\UserModel;
- use app\weixin\model\AccountLog;
- use app\weixin\model\Books;
- use app\weixin\model\Devices;
- use app\weixin\model\Member;
- use app\weixin\model\UserBalanceLog;
- use app\weixin\model\UserContactLog;
- use app\weixin\service\Award;
- 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 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 = [];
- \app\weixin\service\Member::clearSignRedHeart('1000077');
- /*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('b.book_at asc,b.id asc')
- ->paginate(50)
- ->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;
- if ($inviteInfo && $inviteId > 0 && $aid > 0 && $money > 0) {
- if (!UserBalanceLog::checkHasMarketBySource($inviteId, $userId, $aid, 9)) {
- $catchList[] = $item;
- PRedis::set('markets:activity:book_' . $userId . '_' . $aid . '_' . $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]);
- }
- }
|