luck-draw/app/controller/api/Common.php

82 lines
2.0 KiB
PHP

<?php
namespace app\controller\api;
use app\exception\RepositoryException;
use app\repository\AccountRepository;
use app\repository\CommonRepository;
use app\repository\OperationRepository;
use app\repository\OrderRepository;
use app\service\Sms;
use app\validate\CommonValidate;
use think\Collection;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\response\Json;
class Common extends Base
{
protected $noNeedLogin = [
'slidePositions',
'slides',
];
/**
* 发送短信验证码
*
* @OA\Post(
* path="/common/send-code",
* tags={"common"},
* operationId="sendCode",
* )
*/
public function sendCode(): Json
{
$input = input('post.');
$validate = new CommonValidate();
if (!$validate->scene('send_sms')->check($input)) {
return $this->json(4001, '参数错误');
}
if (!in_array($input['type'], ['register', 'login', 'binding'])) {
return $this->json(4002, '参数错误');
}
CommonRepository::getInstance()->sendSms($input['phone'], $input['type']);
return $this->json();
}
/**
* 查看轮播图可视位置配置信息
*/
public function slidePositions(): Json
{
$repo = OperationRepository::getInstance();
$list = $repo->slidePositions();
return $this->json(0, 'success', $list);
}
/**
* 轮播图
*/
public function slides(): Json
{
$size = $this->request->param('size/d', 0);
$position = trim($this->request->param('position/s', ''));
if (empty($position)) {
return $this->json();
}
try {
$repo = OperationRepository::getInstance();
$list = $repo->slideListByPosition($position, $size);
} catch (\Exception $e) {
$list = new Collection();
}
return $this->json(0, 'success', $list);
}
}