DemoController.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller\Api\v1;
  4. use App\Controller\AbstractController;
  5. use App\Master\Enum\RedisKeyEnum;
  6. use App\Master\Framework\Extend\Module;
  7. use App\Master\Framework\Library\GeTui\Push;
  8. use App\Master\Framework\Library\Tencent\TencentIm;
  9. use App\Model\Arts\DemoModel;
  10. use App\Model\Arts\DriverModel;
  11. use App\Model\Arts\OrderModel;
  12. use App\Request\Api\v1\DemoIndexRequest;
  13. use App\Service\QueueService;
  14. use App\Utils\AppResult;
  15. use App\Utils\Control\AuthUser;
  16. use App\Utils\RedisUtil;
  17. use Hyperf\DbConnection\Db;
  18. use Hyperf\Di\Annotation\Inject;
  19. use Psr\Http\Message\ServerRequestInterface;
  20. use function Hyperf\Coroutine\co;
  21. /**
  22. * Demo
  23. * 示例
  24. */
  25. class DemoController extends AbstractController
  26. {
  27. // 日志模块名称
  28. const LOG_MODULE = 'v1/DemoController';
  29. #[Inject]
  30. protected QueueService $service;
  31. /**
  32. * 示例接口
  33. *
  34. * @param DemoIndexRequest $request 校验参数注入类
  35. * @return string
  36. */
  37. public function index(DemoIndexRequest $request)
  38. {
  39. // 【快车】早高峰时间
  40. // $taxi_morning_peak_time = explode('-', site('taxi_morning_peak_time'));
  41. // return AppResult::response200('Coming Soon!!!', [
  42. // $taxi_morning_peak_time,
  43. // strtotime($taxi_morning_peak_time[0]),
  44. // date('Y-m-d H:i:s', strtotime($taxi_morning_peak_time[0])),
  45. // date('Y-m-d H:i:s', strtotime($taxi_morning_peak_time[1])),
  46. // strtotime('2024-08-31 12:00:00'),
  47. // date('Y-m-d H:i:s', strtotime('2024-08-31 12:00:00')),
  48. // date('H:i', strtotime('2024-08-31 12:00:00')),
  49. // strtotime(date('H:i', strtotime('2024-08-31 12:00:00'))),
  50. // date('Y-m-d H:i:s', strtotime(date('H:i', strtotime('2024-08-31 12:00:00')))),
  51. // ]);
  52. // return AppResult::response200('Coming Soon!!!');
  53. // $tencent = new TencentIm();
  54. // $tencent->delete_chat("user_5",'driver_6');
  55. // RedisUtil::getInstance(RedisKeyEnum::USER_DRIVER_CHAT_DEL,"user_5")->setex("driver_6",60);
  56. // return AppResult::response200('Coming Soon!!!',$tencent->getData());
  57. // // 删除司机用户聊天框
  58. // RedisUtil::getInstance(RedisKeyEnum::USER_DRIVER_CHAT_DEL,"user_3")->setex("driver_1",10);
  59. // return AppResult::response200('Coming Soon!!!');
  60. $params = $request->validated();// 获取校验参数结果
  61. // $data = [
  62. // 'push_cid' => $params['push_cid'],
  63. // 'push_title' => '好滴用车来新订单了',
  64. // 'push_content' => "订单距您5km,立即前往接单!",
  65. // 'ring_name' => $params['ring_name'],//'ringing.mp3',
  66. // 'type' => 1,
  67. // 'platform' => $params['platform'],
  68. // ];
  69. // $this->service->pushGeTui($data);
  70. //// $geTui = new Push();
  71. //// $geTui->push($data['push_cid'], $data['push_title'], $data['push_content'], $data['ring_name'], $data['type'], $data['platform']);
  72. // return AppResult::response200('Coming Soon!!!');
  73. $model = new OrderModel();
  74. $order = $model->getDetail(['order_no' => $params['order_no']]);
  75. $list = DriverModel::query()
  76. ->select([
  77. 'id',
  78. 'push_cid',
  79. 'platform',
  80. 'lng',
  81. Db::raw("(st_distance(point ({$order['start_lng']}, {$order['start_lat']}),point(lng,lat))*111195) as distance")
  82. ])
  83. ->with(['car'])
  84. ->where('status', 1)
  85. ->where('is_online', 1)
  86. ->where('push_cid', '!=', '')
  87. //->havingRaw('distance < ?', [10000])
  88. ->get();
  89. $list = json_decode(json_encode($list), true);
  90. // $count = 0;
  91. if (!empty($list)) {
  92. foreach ($list as $item) {
  93. if (!empty($item['push_cid'])) {
  94. // 司机距离
  95. $distance = 0;
  96. if (isset($item['distance'])) {
  97. if ($item['distance'] >= 1000) {
  98. $distance = round(($item['distance'] / 1000), 2) . 'km';
  99. } else {
  100. $distance = round($item['distance'], 1) . 'm';
  101. }
  102. }
  103. dd("订单距您{$distance},立即前往接单!");
  104. // $this->service->pushGeTui([
  105. // 'push_cid' => $item['push_cid'],
  106. // 'push_title' => '好滴用车来新订单了',
  107. // 'push_content' => "订单距您{$distance},立即前往接单!",
  108. // 'ring_name' => $order['appointment_time'] > 0 ? 'ringing1.mp3': 'ringing.mp3',
  109. // 'type' => 1,
  110. // 'platform' => $item['platform'],
  111. // ]);
  112. // $count += 1;
  113. }
  114. }
  115. }
  116. return AppResult::response200('Coming Soon!!!', [
  117. $order,$list
  118. ]);
  119. /**
  120. * 当处理HTTP请求时,无论是通过路径参数、查询参数还是请求体传递的参数,Hyperf都会将其作为字符串类型返回。
  121. * 这是因为HTTP请求中的参数本质上就是字符串,即使它们代表的是其他数据类型(如整数、布尔值等)。
  122. * 注意:所有的参数(除 Content-type:application/json 外)类型都是字符串 如有需要 则可强转后使用
  123. * 例如,如果期望得到一个整数值,可以使用 intval() 函数将字符串转换为整数。同样,对于布尔值,可以使用 boolval() 函数。
  124. *
  125. * POST 建议使用 Content-type:application/json
  126. */
  127. $params = $request->validated();// 获取校验参数结果
  128. /**
  129. * 获取用户信息
  130. */
  131. $user = AuthUser::getInstance()->get();
  132. $model = new DemoModel();
  133. $list = $model->getList($params);
  134. $setup = Module::_SetupModule('siteBase');
  135. // 测试投递异步队列消息
  136. $this->service->demoPush(['name' => 'one'], 10);
  137. $this->service->demoTwoPush(['name' => 'two']);
  138. // 携程 闭包
  139. co(function () use ($params){
  140. sleep(10);
  141. });
  142. return AppResult::response200('Coming Soon!!!', [
  143. 'params' => $params,
  144. 'list' => $list,
  145. 'module_setup' => $setup,
  146. ]);
  147. }
  148. /**
  149. * 原始示例
  150. * @param ServerRequestInterface $request
  151. * @return string
  152. */
  153. public function demo01(ServerRequestInterface $request)
  154. {
  155. return AppResult::response200('Coming Soon!!!', [
  156. // 获取请求参数方式
  157. 'params' => $request->getQueryParams()
  158. ]);
  159. }
  160. //曾经 答题贡献的分数,用户曾经都要给到新机构
  161. public function test()
  162. {
  163. return;
  164. /*$rs1 = Db::table('vote_jigou')->where(['id' => 1])->decrement('score',1);
  165. dd($rs1);
  166. $rs2 = Db::table('vote_jigou')->where(['id' => 1])->increment('score',1);
  167. dd($rs2);
  168. $rs3 = Db::table('vote_jigou')->where(['id' => 1])->update(['score'=>1]);
  169. dd($rs3);
  170. return AppResult::success('绑定成功');*/
  171. return AppResult::success('token','testuid_'.rand(100,150100));
  172. }
  173. }