| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- namespace Modules\Api\Controllers;
- use App\Jobs\Inner\ReceiveVideosJob;
- use App\Model\Mongo\HotelLogModel;
- use Hyperf\HttpServer\Request;
- use Hyperf\Validation\Contract\ValidatorFactoryInterface;
- use Psr\SimpleCache\CacheInterface;
- class InnerController extends BaseController
- {
- use \Hyperf\Di\Aop\ProxyTrait;
- use \Hyperf\Di\Aop\PropertyHandlerTrait;
- function __construct()
- {
- if (method_exists(parent::class, '__construct')) {
- parent::__construct(...func_get_args());
- }
- $this->__handlePropertyHandler(__CLASS__);
- }
- /**
- * 内部通信token
- * @var string
- */
- private $innerToken = 'VC4Pfzrg9nKpq';
- public function receiveVideo(Request $request, ValidatorFactoryInterface $validatorFactory)
- {
- if (!$this->checkToken()) {
- return json_fail('通信失败.');
- }
- $inputData = $request->all();
- $rules = ['source_type' => 'required', 'data' => 'required|array'];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- if ($inputData['source_type'] != 'video') {
- return json_fail('通信数据类型有误');
- }
- if (!empty($inputData['data'])) {
- // 异步调度.
- dispatch_job(new ReceiveVideosJob($inputData['data']));
- }
- $res = ['result' => 'success'];
- return $this->jsonSuccess($res);
- }
- /**
- * 检查token合法性.
- * @return bool
- */
- private function checkToken()
- {
- $token = request()->header('AUTH-TOKEN', '');
- if (empty($token)) {
- $token = request()->input('token', '');
- }
- return $token === $this->innerToken;
- }
- /**
- * 搜索开房记录
- * @param Request $request
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed
- */
- public function searchHotelRecord(Request $request, ValidatorFactoryInterface $validatorFactory)
- {
- if (!$this->checkToken()) {
- return json_fail('通信失败.');
- }
- $inputData = $request->all();
- $rules = ['card_no' => 'required|string|max:18'];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $options = ['skip' => 0, 'limit' => 5, 'sort' => ['check_time' => -1]];
- $cache = make(CacheInterface::class);
- $hotelRecordData = $cache->remember('check_fid_list:' . $inputData['card_no'], 60 * 24 * 7, function () use($inputData, $options) {
- return make(HotelLogModel::class)->db()->find(['ct_type' => 'ID', 'ct_fid' => $inputData['card_no']], $options)->toArray();
- });
- $data = [];
- if ($hotelRecordData) {
- foreach ($hotelRecordData as $key => $item) {
- $check_time = 'XXXX-XX-XX';
- $ct_fid = 'XXXXXXXX';
- $birthday = 'XXXX-XX-XX';
- // 处理时间
- if (strlen($item['check_time']) > 2) {
- $check_time = substr($item['check_time'], 0, 4) . '-XX-XX';
- }
- // 处理出生日期
- if (strlen($item['birthday']) > 2) {
- $birthday = substr($item['birthday'], 0, 4) . '-XX-XX';
- }
- // 处理身身份证
- if (strlen($item['ct_fid']) > 2) {
- $ct_fid = substr($item['ct_fid'], 0, -4) . 'XXXX';
- }
- $data[] = [
- 'check_id' => $item['_id']->__toString(),
- 'username' => $item['username'],
- 'gender' => $item['gender'] === 1 ? '男' : ($item['gender'] === 2 ? '女' : '未知'),
- 'ct_fid' => $ct_fid,
- 'birthday' => $birthday,
- 'check_address' => 'XXXXXX',
- 'check_time' => $check_time,
- // 同住性别
- 'check_sex' => $item['gender'] === 2 ? '男' : '女',
- ];
- }
- }
- return $this->jsonSuccess($data);
- }
- /**
- * @param $data
- * @return mixed
- */
- private function jsonSuccess($data)
- {
- $result = ['code' => 200, 'message' => '', 'data' => $data, 'handshake' => ''];
- return response()->json($result);
- }
- }
|