perf: 添加定位签到

This commit is contained in:
kuaifan 2024-11-09 09:16:00 +08:00
parent 13fb884387
commit e5df3e6746
5 changed files with 56 additions and 23 deletions

View File

@ -1376,6 +1376,7 @@ class DialogController extends AbstractController
* @apiParam {Number} lng 经度
* @apiParam {Number} lat 纬度
* @apiParam {String} title 位置名称
* @apiParam {Number} [distance] 距离(米)
* @apiParam {String} [address] 位置地址
* @apiParam {String} [thumb] 预览图片url
*
@ -1392,6 +1393,7 @@ class DialogController extends AbstractController
$lng = floatval(Request::input('lng'));
$lat = floatval(Request::input('lat'));
$title = trim(Request::input('title'));
$distance = intval(Request::input('distance'));
$address = trim(Request::input('address'));
$thumb = trim(Request::input('thumb'));
//
@ -1411,6 +1413,7 @@ class DialogController extends AbstractController
'lng' => $lng,
'lat' => $lat,
'title' => $title,
'distance' => $distance,
'address' => $address,
'thumb' => $thumb,
];

View File

@ -427,7 +427,7 @@ class SystemController extends AbstractController
}
if (in_array('locat', $all['modes'])) {
if (empty($all['locat_bd_lbs_key'])) {
return Base::retError('请填写百度地图LBS Key');
return Base::retError('请填写百度地图AK');
}
if (!is_array($all['locat_bd_lbs_point'])) {
return Base::retError('请选择允许签到位置');

View File

@ -118,7 +118,7 @@ class UserBot extends AbstractModel
if (in_array('locat', $setting['modes']) && Base::isEEUIApp()) {
$menu[] = [
'key' => 'locat-checkin',
'label' => $setting['locat_remark'] ?: Doo::translate('定位签到'),
'label' => Doo::translate('定位签到'),
'config' => [
'key' => $setting['locat_bd_lbs_key'],
'lng' => $setting['locat_bd_lbs_point']['lng'],
@ -130,7 +130,7 @@ class UserBot extends AbstractModel
if (in_array('manual', $setting['modes'])) {
$menu[] = [
'key' => 'manual-checkin',
'label' => $setting['manual_remark'] ?: Doo::translate('手动打卡')
'label' => Doo::translate('手动签到')
];
}
return $menu;
@ -177,9 +177,10 @@ class UserBot extends AbstractModel
* 签到机器人
* @param $command
* @param $userid
* @param $extra
* @return string
*/
public static function checkinBotQuickMsg($command, $userid)
public static function checkinBotQuickMsg($command, $userid, $extra = [])
{
if (Cache::get("UserBot::checkinBotQuickMsg:{$userid}") === "yes") {
return "操作频繁!";
@ -194,7 +195,24 @@ class UserBot extends AbstractModel
if (!in_array('manual', $setting['modes'])) {
return '暂未开放手动签到。';
}
if ($error = UserBot::checkinBotCheckin($userid, Base::time(), true)) {
if ($error = UserBot::checkinBotCheckin('manual-' . $userid, Base::time(), true)) {
return $error;
}
return null;
} elseif ($command === 'locat-checkin') {
$setting = Base::setting('checkinSetting');
if ($setting['open'] !== 'open') {
return '暂未开启签到功能。';
}
if (!in_array('locat', $setting['modes'])) {
return '暂未开放定位签到。';
}
if ($extra['type'] === 'bd') {
// todo 判断距离
} else {
return '错误的定位签到。';
}
if ($error = UserBot::checkinBotCheckin('locat-' . $userid, Base::time(), true)) {
return $error;
}
return null;
@ -207,7 +225,7 @@ class UserBot extends AbstractModel
* 签到机器人签到
* @param mixed $mac
* - 多个使用,分隔
* - 支持mac地址、userid、checkin-userid
* - 支持mac地址、(manual|locat|face|checkin)-userid
* @param $time
* @param bool $alreadyTip 签到过是否提示
* @return string|null 返回string表示错误信息返回null表示签到成功
@ -247,7 +265,15 @@ class UserBot extends AbstractModel
'remark' => $UserCheckinMac->remark,
];
}
} elseif (Base::isNumber($mac)) {
} elseif (preg_match('/^(manual|locat|face|checkin)-(\d+)$/i', $mac, $match)) {
$type = str_replace('checkin', 'face', $match[1]);
$mac = intval($match[2]);
$remark = match ($type) {
'manual' => $setting['manual_remark'] ?: 'Manual',
'locat' => $setting['locat_remark'] ?: 'Location',
'face' => $setting['face_remark'] ?: 'Machine',
default => '',
};
if ($UserInfo = User::whereUserid($mac)->whereBot(0)->first()) {
$array = [
'userid' => $UserInfo->userid,
@ -256,20 +282,7 @@ class UserBot extends AbstractModel
];
$checkins[] = [
'userid' => $UserInfo->userid,
'remark' => $setting['manual_remark'] ?: 'Manual',
];
}
} elseif (Base::leftExists($mac, "checkin-", true)) {
$mac = Base::leftDelete($mac, "checkin-", true);
if ($UserInfo = User::whereUserid($mac)->whereBot(0)->first()) {
$array = [
'userid' => $UserInfo->userid,
'mac' => '00:00:00:00:00:00',
'date' => $nowDate,
];
$checkins[] = [
'userid' => $UserInfo->userid,
'remark' => $setting['face_remark'] ?: 'Machine',
'remark' => $remark,
];
}
}

View File

@ -63,6 +63,22 @@ class BotReceiveMsgTask extends AbstractTask
*/
private function botManagerReceive(WebSocketDialogMsg $msg, User $botUser)
{
// 位置消息
if ($msg->type === 'location') {
// 签到机器人
if ($botUser->email === 'check-in@bot.system') {
$content = UserBot::checkinBotQuickMsg('locat-checkin', $msg->userid, $msg->msg);
if ($content) {
WebSocketDialogMsg::sendMsg(null, $msg->dialog_id, 'template', [
'type' => 'content',
'content' => $content,
], $botUser->userid, false, false, true); // todo 未能在任务end事件来发送任务
}
}
return;
}
// 文本消息
if ($msg->type !== 'text') {
return;
}

View File

@ -1769,8 +1769,8 @@ export default {
}
const thumb = $A.urlAddParams('https://api.map.baidu.com/staticimage/v2', {
ak: item.config.key,
center: `${item.config.lng},${item.config.lat}`,
markers: `${item.config.lng},${item.config.lat}`,
center: `${data.point.lng},${data.point.lat}`,
markers: `${data.point.lng},${data.point.lat}`,
width: 800,
height: 480,
zoom: 19,
@ -1781,6 +1781,7 @@ export default {
lng: data.point.lng,
lat: data.point.lat,
title: data.title,
distance: data.distance,
address: data.address || '',
thumb
})