first(); } /** * @description: 查询所有数据 * @param array $search * @return \Illuminate\Database\Eloquent\Collection */ public static function findAll(array $search = []) { return self::model()::where(self::getWhere($search))->get(); } /** * @description: 分页查询 * @param array $search * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator */ public static function paginate(array $search = []) { $limit = isset($search['limit']) ? $search['limit'] : 15; $paginator = self::model()::where(self::getWhere($search)) // ->orderBy("sort", 'asc') ->paginate($limit); foreach($paginator->items() as $item){ if(isset($item->buttons) && !empty($item->buttons)){ $item->buttons = json_decode($item->buttons,true); }else{ $item->buttons = []; } } return ['total' => $paginator->total(), 'data' => $paginator->items()]; } /** * @description: * @param {*} $params * @return {*} */ public static function submit($params = []) { $result = false; $msg['code'] = self::NOT; $msg['msg'] = ''; 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); } // 2. 判断是否是更新 if (!empty($params['id'])) { // 更新 $info = self::findOne(['id'=>$params['id']] ); if (!$info) { $msg['msg'] = '数据不存在!'; }else{ $result = $info->update($params); $id = $params['id']; } } else { // 创建 $result = $info = self::model()::create($params); $id = $result->id; } if($result){ $msg['code'] = self::YES; $msg['msg'] = '设置成功'; }else{ $msg['msg'] = empty($msg['msg']) ?'操作失败':$msg['msg']; } return $msg; } // 校验开始菜单 事件 public static function checkStart($chatId,$keyword = '') { // Log::error('开始使用菜单事件:',['chatId'=>$chatId,'keyword'=>$keyword]); // 查找开始使用的菜单 $list = self::findAll(['button' => '开始使用'])->toArray(); foreach($list as $item){ $buttons = []; if(isset($item['buttons']) && !empty($item['buttons'])){ $buttons = json_decode($item['buttons'],true); } // 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']); } } } } } return false; } // 开始菜单触发事件 public static function menuEvent($chatId,$event = '') { switch($event){ case 'recentBets': // 近期注单 // 删除个人缓存 Util::delCache($chatId); return BetService::record($chatId); break; case 'flowList': // 流水列表 // 删除个人缓存 Util::delCache($chatId); return BalanceLogService::getFlowingHistory($chatId); break; case 'winningHistory': // 开奖历史 // 删除个人缓存 Util::delCache($chatId); return IssueService::currentLotteryResults($chatId); break; case 'currentBetting': // 本期下注 // 删除个人缓存 Util::delCache($chatId); return BetService::currentBet($chatId); case 'checkBalance': // 查看余额 // 删除个人缓存 Util::delCache($chatId); return WalletService::getBalance($chatId); case 'selectLanguage': // 选择语言 // 删除个人缓存 Util::delCache($chatId); return UserService::getLanguages($chatId); break; case 'topUp': // 充值上分 // 删除个人缓存 Util::delCache($chatId); return SanJinRechargeService::qbApply($chatId); break; default: return false; } } }