123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- <?php
- declare(strict_types=1);
- namespace App\Controller\Api\v1;
- use App\Controller\AbstractController;
- use App\Master\Enum\RedisKeyEnum;
- use App\Master\Framework\Extend\Module;
- use App\Master\Framework\Library\GeTui\Push;
- use App\Master\Framework\Library\Tencent\TencentIm;
- use App\Model\Arts\DemoModel;
- use App\Model\Arts\DriverModel;
- use App\Model\Arts\OrderModel;
- use App\Request\Api\v1\DemoIndexRequest;
- use App\Service\QueueService;
- use App\Utils\AppResult;
- use App\Utils\Control\AuthUser;
- use App\Utils\RedisUtil;
- use Hyperf\DbConnection\Db;
- use Hyperf\Di\Annotation\Inject;
- use Psr\Http\Message\ServerRequestInterface;
- use function Hyperf\Coroutine\co;
- /**
- * Demo
- * 示例
- */
- class DemoController extends AbstractController
- {
- // 日志模块名称
- const LOG_MODULE = 'v1/DemoController';
- #[Inject]
- protected QueueService $service;
- /**
- * 示例接口
- *
- * @param DemoIndexRequest $request 校验参数注入类
- * @return string
- */
- public function index(DemoIndexRequest $request)
- {
- // 【快车】早高峰时间
- // $taxi_morning_peak_time = explode('-', site('taxi_morning_peak_time'));
- // return AppResult::response200('Coming Soon!!!', [
- // $taxi_morning_peak_time,
- // strtotime($taxi_morning_peak_time[0]),
- // date('Y-m-d H:i:s', strtotime($taxi_morning_peak_time[0])),
- // date('Y-m-d H:i:s', strtotime($taxi_morning_peak_time[1])),
- // strtotime('2024-08-31 12:00:00'),
- // date('Y-m-d H:i:s', strtotime('2024-08-31 12:00:00')),
- // date('H:i', strtotime('2024-08-31 12:00:00')),
- // strtotime(date('H:i', strtotime('2024-08-31 12:00:00'))),
- // date('Y-m-d H:i:s', strtotime(date('H:i', strtotime('2024-08-31 12:00:00')))),
- // ]);
- // return AppResult::response200('Coming Soon!!!');
- // $tencent = new TencentIm();
- // $tencent->delete_chat("user_5",'driver_6');
- // RedisUtil::getInstance(RedisKeyEnum::USER_DRIVER_CHAT_DEL,"user_5")->setex("driver_6",60);
- // return AppResult::response200('Coming Soon!!!',$tencent->getData());
- // // 删除司机用户聊天框
- // RedisUtil::getInstance(RedisKeyEnum::USER_DRIVER_CHAT_DEL,"user_3")->setex("driver_1",10);
- // return AppResult::response200('Coming Soon!!!');
- $params = $request->validated();// 获取校验参数结果
- // $data = [
- // 'push_cid' => $params['push_cid'],
- // 'push_title' => '好滴用车来新订单了',
- // 'push_content' => "订单距您5km,立即前往接单!",
- // 'ring_name' => $params['ring_name'],//'ringing.mp3',
- // 'type' => 1,
- // 'platform' => $params['platform'],
- // ];
- // $this->service->pushGeTui($data);
- //// $geTui = new Push();
- //// $geTui->push($data['push_cid'], $data['push_title'], $data['push_content'], $data['ring_name'], $data['type'], $data['platform']);
- // return AppResult::response200('Coming Soon!!!');
- $model = new OrderModel();
- $order = $model->getDetail(['order_no' => $params['order_no']]);
- $list = DriverModel::query()
- ->select([
- 'id',
- 'push_cid',
- 'platform',
- 'lng',
- Db::raw("(st_distance(point ({$order['start_lng']}, {$order['start_lat']}),point(lng,lat))*111195) as distance")
- ])
- ->with(['car'])
- ->where('status', 1)
- ->where('is_online', 1)
- ->where('push_cid', '!=', '')
- //->havingRaw('distance < ?', [10000])
- ->get();
- $list = json_decode(json_encode($list), true);
- // $count = 0;
- if (!empty($list)) {
- foreach ($list as $item) {
- if (!empty($item['push_cid'])) {
- // 司机距离
- $distance = 0;
- if (isset($item['distance'])) {
- if ($item['distance'] >= 1000) {
- $distance = round(($item['distance'] / 1000), 2) . 'km';
- } else {
- $distance = round($item['distance'], 1) . 'm';
- }
- }
- dd("订单距您{$distance},立即前往接单!");
- // $this->service->pushGeTui([
- // 'push_cid' => $item['push_cid'],
- // 'push_title' => '好滴用车来新订单了',
- // 'push_content' => "订单距您{$distance},立即前往接单!",
- // 'ring_name' => $order['appointment_time'] > 0 ? 'ringing1.mp3': 'ringing.mp3',
- // 'type' => 1,
- // 'platform' => $item['platform'],
- // ]);
- // $count += 1;
- }
- }
- }
- return AppResult::response200('Coming Soon!!!', [
- $order,$list
- ]);
- /**
- * 当处理HTTP请求时,无论是通过路径参数、查询参数还是请求体传递的参数,Hyperf都会将其作为字符串类型返回。
- * 这是因为HTTP请求中的参数本质上就是字符串,即使它们代表的是其他数据类型(如整数、布尔值等)。
- * 注意:所有的参数(除 Content-type:application/json 外)类型都是字符串 如有需要 则可强转后使用
- * 例如,如果期望得到一个整数值,可以使用 intval() 函数将字符串转换为整数。同样,对于布尔值,可以使用 boolval() 函数。
- *
- * POST 建议使用 Content-type:application/json
- */
- $params = $request->validated();// 获取校验参数结果
- /**
- * 获取用户信息
- */
- $user = AuthUser::getInstance()->get();
- $model = new DemoModel();
- $list = $model->getList($params);
- $setup = Module::_SetupModule('siteBase');
- // 测试投递异步队列消息
- $this->service->demoPush(['name' => 'one'], 10);
- $this->service->demoTwoPush(['name' => 'two']);
- // 携程 闭包
- co(function () use ($params){
- sleep(10);
- });
- return AppResult::response200('Coming Soon!!!', [
- 'params' => $params,
- 'list' => $list,
- 'module_setup' => $setup,
- ]);
- }
- /**
- * 原始示例
- * @param ServerRequestInterface $request
- * @return string
- */
- public function demo01(ServerRequestInterface $request)
- {
- return AppResult::response200('Coming Soon!!!', [
- // 获取请求参数方式
- 'params' => $request->getQueryParams()
- ]);
- }
- //曾经 答题贡献的分数,用户曾经都要给到新机构
- public function test()
- {
- return;
- /*$rs1 = Db::table('vote_jigou')->where(['id' => 1])->decrement('score',1);
- dd($rs1);
- $rs2 = Db::table('vote_jigou')->where(['id' => 1])->increment('score',1);
- dd($rs2);
- $rs3 = Db::table('vote_jigou')->where(['id' => 1])->update(['score'=>1]);
- dd($rs3);
- return AppResult::success('绑定成功');*/
- return AppResult::success('token','testuid_'.rand(100,150100));
- }
- }
|