|
@@ -48,7 +48,7 @@ class KeyboardService extends BaseService
|
|
|
public static function getWhere(array $search = []): array
|
|
public static function getWhere(array $search = []): array
|
|
|
{
|
|
{
|
|
|
$where = [];
|
|
$where = [];
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (isset($search['id']) && !empty($search['id'])) {
|
|
if (isset($search['id']) && !empty($search['id'])) {
|
|
|
$where[] = ['id', '=', $search['id']];
|
|
$where[] = ['id', '=', $search['id']];
|
|
|
}
|
|
}
|
|
@@ -61,7 +61,7 @@ class KeyboardService extends BaseService
|
|
|
if (isset($search['language']) && !empty($search['language'])) {
|
|
if (isset($search['language']) && !empty($search['language'])) {
|
|
|
$where[] = ['language', '=', $search['language']];
|
|
$where[] = ['language', '=', $search['language']];
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return $where;
|
|
return $where;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -82,9 +82,9 @@ class KeyboardService extends BaseService
|
|
|
*/
|
|
*/
|
|
|
public static function findAll(array $search = [])
|
|
public static function findAll(array $search = [])
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return self::model()::where(self::getWhere($search))->get();
|
|
return self::model()::where(self::getWhere($search))->get();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -98,10 +98,10 @@ class KeyboardService extends BaseService
|
|
|
$paginator = self::model()::where(self::getWhere($search))
|
|
$paginator = self::model()::where(self::getWhere($search))
|
|
|
// ->orderBy("sort", 'asc')
|
|
// ->orderBy("sort", 'asc')
|
|
|
->paginate($limit);
|
|
->paginate($limit);
|
|
|
- foreach($paginator->items() as $item){
|
|
|
|
|
- if(isset($item->buttons) && !empty($item->buttons)){
|
|
|
|
|
- $item->buttons = json_decode($item->buttons,true);
|
|
|
|
|
- }else{
|
|
|
|
|
|
|
+ foreach ($paginator->items() as $item) {
|
|
|
|
|
+ if (isset($item->buttons) && !empty($item->buttons)) {
|
|
|
|
|
+ $item->buttons = json_decode($item->buttons, true);
|
|
|
|
|
+ } else {
|
|
|
$item->buttons = [];
|
|
$item->buttons = [];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -109,30 +109,30 @@ class KeyboardService extends BaseService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * @description:
|
|
|
|
|
|
|
+ * @description:
|
|
|
* @param {*} $params
|
|
* @param {*} $params
|
|
|
* @return {*}
|
|
* @return {*}
|
|
|
- */
|
|
|
|
|
|
|
+ */
|
|
|
public static function submit($params = [])
|
|
public static function submit($params = [])
|
|
|
{
|
|
{
|
|
|
$result = false;
|
|
$result = false;
|
|
|
$msg['code'] = self::NOT;
|
|
$msg['code'] = self::NOT;
|
|
|
$msg['msg'] = '';
|
|
$msg['msg'] = '';
|
|
|
- if(isset($params['buttons']) && !empty($params['buttons'])){
|
|
|
|
|
- if(is_array($params['buttons'])){
|
|
|
|
|
- $params['buttons'] = json_encode($params['buttons'],JSON_UNESCAPED_UNICODE);
|
|
|
|
|
|
|
+ if (isset($params['buttons']) && !empty($params['buttons'])) {
|
|
|
|
|
+ if (is_array($params['buttons'])) {
|
|
|
|
|
+ $params['buttons'] = json_encode($params['buttons'], JSON_UNESCAPED_UNICODE);
|
|
|
}
|
|
}
|
|
|
- }else{
|
|
|
|
|
- $params['buttons'] = json_encode([],JSON_UNESCAPED_UNICODE);
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $params['buttons'] = json_encode([], JSON_UNESCAPED_UNICODE);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 2. 判断是否是更新
|
|
// 2. 判断是否是更新
|
|
|
if (!empty($params['id'])) {
|
|
if (!empty($params['id'])) {
|
|
|
// 更新
|
|
// 更新
|
|
|
- $info = self::findOne(['id'=>$params['id']] );
|
|
|
|
|
|
|
+ $info = self::findOne(['id' => $params['id']]);
|
|
|
if (!$info) {
|
|
if (!$info) {
|
|
|
$msg['msg'] = '数据不存在!';
|
|
$msg['msg'] = '数据不存在!';
|
|
|
- }else{
|
|
|
|
|
|
|
+ } else {
|
|
|
$result = $info->update($params);
|
|
$result = $info->update($params);
|
|
|
$id = $params['id'];
|
|
$id = $params['id'];
|
|
|
}
|
|
}
|
|
@@ -142,43 +142,43 @@ class KeyboardService extends BaseService
|
|
|
$result = $info = self::model()::create($params);
|
|
$result = $info = self::model()::create($params);
|
|
|
$id = $result->id;
|
|
$id = $result->id;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- if($result){
|
|
|
|
|
- $msg['code'] = self::YES;
|
|
|
|
|
- $msg['msg'] = '设置成功';
|
|
|
|
|
- }else{
|
|
|
|
|
- $msg['msg'] = empty($msg['msg']) ?'操作失败':$msg['msg'];
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if ($result) {
|
|
|
|
|
+ $msg['code'] = self::YES;
|
|
|
|
|
+ $msg['msg'] = '设置成功';
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $msg['msg'] = empty($msg['msg']) ? '操作失败' : $msg['msg'];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return $msg;
|
|
return $msg;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 校验开始菜单 事件
|
|
// 校验开始菜单 事件
|
|
|
- public static function checkStart($chatId,$keyword = '')
|
|
|
|
|
|
|
+ public static function checkStart($chatId, $keyword = '')
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
// Log::error('开始使用菜单事件:',['chatId'=>$chatId,'keyword'=>$keyword]);
|
|
// Log::error('开始使用菜单事件:',['chatId'=>$chatId,'keyword'=>$keyword]);
|
|
|
// 查找开始使用的菜单
|
|
// 查找开始使用的菜单
|
|
|
$list = self::findAll(['button' => '开始使用'])->toArray();
|
|
$list = self::findAll(['button' => '开始使用'])->toArray();
|
|
|
-
|
|
|
|
|
- foreach($list as $item){
|
|
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($list as $item) {
|
|
|
$buttons = [];
|
|
$buttons = [];
|
|
|
- if(isset($item['buttons']) && !empty($item['buttons'])){
|
|
|
|
|
- $buttons = json_decode($item['buttons'],true);
|
|
|
|
|
|
|
+ if (isset($item['buttons']) && !empty($item['buttons'])) {
|
|
|
|
|
+ $buttons = json_decode($item['buttons'], true);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// var_dump($buttons);
|
|
// var_dump($buttons);
|
|
|
- foreach($buttons as $row){
|
|
|
|
|
- foreach($row as $k => $v){
|
|
|
|
|
- if(isset($v['text']) && $v['text'] == $keyword){
|
|
|
|
|
-
|
|
|
|
|
- if(isset($v['url']) && !empty($v['url'])){
|
|
|
|
|
- return self::menuEvent($chatId,$v['url']);
|
|
|
|
|
|
|
+ foreach ($buttons as $row) {
|
|
|
|
|
+ foreach ($row as $k => $v) {
|
|
|
|
|
+ if (isset($v['text']) && $v['text'] == $keyword) {
|
|
|
|
|
+
|
|
|
|
|
+ if (isset($v['url']) && !empty($v['url'])) {
|
|
|
|
|
+ return self::menuEvent($chatId, $v['url']);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -186,14 +186,14 @@ class KeyboardService extends BaseService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 开始菜单触发事件
|
|
// 开始菜单触发事件
|
|
|
- public static function menuEvent($chatId,$event = '')
|
|
|
|
|
|
|
+ public static function menuEvent($chatId, $event = '')
|
|
|
{
|
|
{
|
|
|
- switch($event){
|
|
|
|
|
|
|
+ switch ($event) {
|
|
|
case 'recentBets': // 近期注单
|
|
case 'recentBets': // 近期注单
|
|
|
// 删除个人缓存
|
|
// 删除个人缓存
|
|
|
Util::delCache($chatId);
|
|
Util::delCache($chatId);
|
|
|
return BetService::record($chatId);
|
|
return BetService::record($chatId);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
break;
|
|
break;
|
|
|
case 'flowList': // 流水列表
|
|
case 'flowList': // 流水列表
|
|
|
// 删除个人缓存
|
|
// 删除个人缓存
|
|
@@ -232,7 +232,12 @@ class KeyboardService extends BaseService
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static function getKeyWordReply($chatId,$text): ?array
|
|
|
|
|
|
|
+ private static function isValidURL($url)
|
|
|
|
|
+ {
|
|
|
|
|
+ return filter_var($url, FILTER_VALIDATE_URL) !== false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static function getKeyWordReply($chatId, $text): ?array
|
|
|
{
|
|
{
|
|
|
// 关键字回复
|
|
// 关键字回复
|
|
|
$keyboardText = KeyboardService::findOne(['button' => $text]);
|
|
$keyboardText = KeyboardService::findOne(['button' => $text]);
|
|
@@ -240,6 +245,22 @@ class KeyboardService extends BaseService
|
|
|
$keyboard = [];
|
|
$keyboard = [];
|
|
|
if ($keyboardText['buttons']) {
|
|
if ($keyboardText['buttons']) {
|
|
|
$keyboard = json_decode($keyboardText['buttons'], true);
|
|
$keyboard = json_decode($keyboardText['buttons'], true);
|
|
|
|
|
+ $newKeyboard = [];
|
|
|
|
|
+ foreach ($keyboard as $item) {
|
|
|
|
|
+ $t = [];
|
|
|
|
|
+ foreach ($item as $item1) {
|
|
|
|
|
+ if(static::isValidURL($item1['url'])){
|
|
|
|
|
+ $t[] = $item1;
|
|
|
|
|
+ }else{
|
|
|
|
|
+ $t[] = [
|
|
|
|
|
+ 'text' => $item1['text'],
|
|
|
|
|
+ 'callback_data' => $item1['url']
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!empty($t)) $newKeyboard[] = $t;
|
|
|
|
|
+ }
|
|
|
|
|
+ $keyboard = $newKeyboard;
|
|
|
}
|
|
}
|
|
|
Util::delCache($chatId);
|
|
Util::delCache($chatId);
|
|
|
$res = [
|
|
$res = [
|