SearchHotelLogModel.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. declare (strict_types=1);
  3. namespace App\Model\Mongo;
  4. use Carbon\Carbon;
  5. use Hyperf\Mongodb\Mongodb;
  6. use Hyperf\Utils\ApplicationContext;
  7. use Hyperf\Utils\CodeGen\Project;
  8. use MongoDB\Client;
  9. /**
  10. * Class UserRelationModel
  11. * @return Client|UserRelationModel
  12. *
  13. * @package App\Model\Mongo
  14. */
  15. class SearchHotelLogModel extends Mongodb
  16. {
  17. protected $collectionName = 'search_hotel_log'; // mongoDB 表名
  18. protected $poolName = 'kaifang';
  19. public function db()
  20. {
  21. $container = ApplicationContext::getContainer();
  22. /**
  23. * @var $mongodb Client
  24. */
  25. $mongodb = $container->get(self::class);
  26. return $mongodb->selectDatabase(env('MONGODB_KAIFANG_DB'))
  27. ->selectCollection($this->collectionName);
  28. }
  29. public function create(string $userId, string $fid, array $project)
  30. {
  31. self::db()->insertOne([
  32. 'user_uid' => $userId,
  33. 'fid' => $fid,
  34. 'data' => json_encode($project),
  35. 'type' => 'chuji',
  36. 'created_at' => Carbon::now()->toDateTimeString(),
  37. ]);
  38. }
  39. }