coupon-admin/app/controller/api/Index.php

100 lines
2.5 KiB
PHP

<?php
namespace app\controller\api;
use app\exception\RepositoryException;
use app\job\NotifySms;
use app\model\AccountFootmarks;
use app\model\HotKeyword;
use app\repository\AccountRepository;
use app\service\ExtraConfig;
use think\Collection;
use think\facade\Queue;
use think\response\Json;
class Index extends Base
{
protected $noNeedLogin = [
'miniProgramSetting',
'clearFootmarks',
'hotKeywords'
];
public function index(): Json
{
return json(['code' => 0, 'msg' => 'I am index']);
}
/**
* 测试用
*
* @return Json
* @throws RepositoryException
*/
public function test(): Json
{
$userId = $this->request->middleware('userInfo')['user_id'] ?? 0;
$user = AccountRepository::getInstance()->info($userId, []);
return json(['code' => 0, 'msg' => 'I am test ', 'data' => $user]);
}
public function login(): Json
{
$userId = $this->request->middleware('userInfo')['user_id'] ?? 0;
return json(['code' => 0, 'msg' => 'I am login '.$userId]);
}
public function notify()
{
$beginNotifyList = AccountRepository::getInstance()->getBeginNotifyList();
// $res = Queue::later(3, NotifySms::class, $beginNotifyList);
// $getSuccessList = AccountRepository::getInstance()->getSuccessList();
return $this->json(0, 'success', $beginNotifyList);
}
/**
* 小程序个性装修配置
*/
public function miniProgramSetting(): Json
{
$conf = ExtraConfig::miniProgram();
return $this->json(0, 'success', $conf);
}
/**
* 推荐显示的热搜词
*/
public function hotKeywords(): Json
{
try {
$type = input('type/s',"");
$list = HotKeyword::allRecommends($type);
} catch (\Exception $e) {
$list = new Collection();
}
return $this->json(0, 'success', $list);
}
/**
* 清理过期足迹
*
* @return Json
*/
public function clearFootmarks(): Json
{
try {
//清理N天以前的数据
$day = 30;
$time = date('Y-m-d H:i:s', time() - $day * 86400);
$count = AccountFootmarks::where('created_at', '<', $time)->count();
AccountFootmarks::where('created_at', '<', $time)->delete();
return $this->json(0, '成功清理足迹(条):'.$count);
} catch (\Exception $e) {
return $this->json(5000, '清理足迹失败');
}
}
}