* @since 2021-08-23 */ namespace App\Http\Controllers\Wap\TemplateLibraryApi; use App\Http\Controllers\Controller; use App\Http\Models\Site; use App\Http\Services\TemplateLibraryApiService; use Illuminate\Http\Request; use Illuminate\http\JsonResponse; use Illuminate\Support\Facades\DB; use itbdw\Ip\IpLocation; class TemplateLibraryApiController extends Controller { private $templateLibraryApiService; /** * 模版服务类 * TemplateLibraryApiController constructor. * @param TemplateLibraryApiService $templateLibraryApiService */ public function __construct(TemplateLibraryApiService $templateLibraryApiService) { $this->templateLibraryApiService = $templateLibraryApiService; } /** * 获取所有页面的关联模版以及变量(弃用,量大拖速度) * @param Request $request * @return JsonResponse */ public function getSitesTemplateList(Request $request) { try { $result = $request->all(); if (!empty($result['siteId'])) { [$siteInfo, $setting] = $this->templateLibraryApiService->getSettingList($result['siteId']); return $this->returnApiSuccess($this->templateLibraryApiService->getContentList($result['siteId']), $siteInfo, $setting); } return $this->returnApiError(); } catch (\Exception $exception) { return $this->returnApiError($exception->getMessage()); } } /** * 获取所有页面内容 * @param Request $request * @return JsonResponse */ public function getWebsitePageList(Request $request) { try { $result = $request->all(); if (!empty($result['siteId'])) { [$siteInfo, $setting] = $this->templateLibraryApiService->getSettingList($result['siteId']); $advertiseList = $this->templateLibraryApiService->getAdvertiseList($result['siteId']); $result = $this->templateLibraryApiService->getWebsitePageList($result['siteId'], $result['tplId'] ?? 0, $result['notTplId'] ?? 0); return $this->returnApiSuccess($result, $siteInfo, $setting, $advertiseList); } return $this->returnApiError(); } catch (\Exception $exception) { return $this->returnApiError($exception->getMessage()); } } /** * 根据页面id获取详情 * @param Request $request * @return JsonResponse */ public function getWebsitePageDetailsByUri(Request $request) { try { $result = $request->all(); if (((!empty($result['siteId']) && !empty($result['pageId']))) || ((!empty($result['siteId']) && !empty($result['uri'])))) { [$siteInfo, $setting] = $this->templateLibraryApiService->getSettingList($result['siteId']); return $this->returnApiSuccess($this->templateLibraryApiService->getWebsitePageDetailsByUri($result['siteId'], $result['pageId'] ?? 0, $result['uri'] ?? ''), $siteInfo, $setting); } return $this->returnApiError(); } catch (\Exception $exception) { return $this->returnApiError($exception->getMessage()); } } /** * 筛选父节点下面的子页面列表 * @param Request $request * @return JsonResponse */ public function getChildWebsitePageListByPageId(Request $request) { try { $result = $request->all(); if (!empty($result['siteId'])) { [$siteInfo, $setting] = $this->templateLibraryApiService->getSettingList($result['siteId']); $result = $this->templateLibraryApiService->getChildWebsitePageListByPageId($result['siteId'], $result['pid'] ?? 0, $result['tplId'] ?? 0, $result['notTplId'] ?? 0, $result['sortBy'] ?? false, $result['all'] ?? false, $result['pageSize'] ?? TABLE_PAGE_SIZE); return $this->returnApiSuccess($result, $siteInfo, $setting); } return $this->returnApiError(); } catch (\Exception $exception) { return $this->returnApiError($exception->getMessage()); } } /** * 页面关键词查询 * @param Request $request * @return JsonResponse */ public function search(Request $request) { $result = $request->all(); try { if (!empty($result['siteId']) && !empty($result['keyword'])) { [$siteInfo, $setting] = $this->templateLibraryApiService->getSettingList($result['siteId']); $result = $this->templateLibraryApiService->search($result['siteId'], $result['keyword'] ?? '', $result['pageSize'] ?? TABLE_PAGE_SIZE, $result['tplId'] ?? 0, $result['notTplId'] ?? 0); return $this->returnApiSuccess($result, $siteInfo, $setting); } return $this->returnApiError(); } catch (\Exception $exception) { return $this->returnApiError($exception->getMessage()); } } /** * 表单提交(弃用) * @param Request $request * @return JsonResponse */ public function formSubmission(Request $request) { $request = $request->all(); if (empty($request['siteId']) && empty($request['name']) && empty($request['email'] && empty($request['phone'] && empty($request['sign'])))) { return $this->returnApiError(['info' => '缺少必要参数']); } $pattern = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/"; if (!preg_match($pattern, $request['email'])) { return $this->returnApiError(['info' => '邮箱不匹配']); } $sign = strtolower(md5($request['siteId'] . $request['name'] . $request['email'] . $request['phone'])); if ($request['sign'] == $sign) { $this->templateLibraryApiService->formSubmission($request); return $this->returnApiSuccess([ 'info' => '提交成功', ]); } return $this->returnApiError([ 'info' => '无效的签名', ]); } /** * 表单提交 * @param Request $request * @return array|JsonResponse */ public function formSubmission1(Request $request) { try { $formData = $request->all(); $clientURL = $formData['url'] ?? ''; $data = [ 'user_id' => '1', 'notice' => '询盘', 'url' => $clientURL ?? '', 'request' => serialize($formData), 'cookie' => serialize($request->cookie()), 'client_ip' => ip2long($request->ip()), ]; $website = DB::connection('template') ->table('template_library_project_config') ->where('site_id', $formData['siteId'])->value('cn_title') ?? ''; $connection = DB::connection($this->templateLibraryApiService->connection($formData['siteId'])); $connection->table('user_log')->insert($data); if (empty($formData['name'])) { return $this->returnApiError([ 'info' => 'Please write your name', ]); } if (empty($formData['email'])) { return $this->returnApiError([ 'info' => 'Please write your the e-mail', ]); } $pattern = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/"; if (!preg_match($pattern, $formData['email'])) { return $this->returnApiError([ 'info' => 'Please write your the e-mail', ]); } if ($request->hasFile('files')) { foreach ($request->file('files') as $key => $file) { $fileUrl = $file->storeAs(date('Ymd') . '/' . $file->getClientOriginalExtension(), $file->getClientOriginalName(), 'public'); $fileUrl = sprintf('/storage/%s', $fileUrl); $formData['attach'][$key] = '' . $file->getClientOriginalName() . ''; } } $data = [ '姓名' => $formData['name'] ?? '-', '邮箱' => $formData['email'] ?? '-', '电话' => $formData['phone'] ?? '-', '国家' => $formData['country'] ?? '-' ]; if (!empty($formData['attach'])) { $data['附件'] = implode(', ', $formData['attach']); } $content = ''; if (!empty($formData['content'])) { $content = $formData['content']; } $country = IpLocation::getLocation($request->ip()); if (!empty($country)) { $country = $country['country'] ?? '' . $country['province'] ?? '' . $country['city'] ?? ''; } else { $country = ''; } $html = '
上市公司海外营销第一选择!        访问官网
'; $html .= '
尊敬的 ' . $formData['email'] . ' 用户:

您好!

您的网站 ' . $website . ' 于 ' . date('Y-m-d H:i:s') . ' 收到一封来自 IP:' . $request->ip() . ' (' . $country . ') 的询盘消息,请及时处理。详细信息如下:

'; $html .= ''; $i = 0; foreach ($data as $key => $val) { if ($i > 0 && $i % 2 == 0) { $html .= ''; } $html .= ''; $html .= ''; $i++; } if (!empty($formData['ext'])) { foreach ($formData['ext'] as $key => $ext) { $html .= ''; $html .= ''; $html .= ''; $html .= ''; } } $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= '
' . $key . ':' . $val . '
' . $ext['name'] . ':' . $ext['value'] . '
留言:'; $html .= '
' . $content . '
URL:'; $html .= '
温馨提示:此邮件由系统自动发出,请勿直接回复!
如有疑问或建议,可发送邮件至 hina@yinqingli.com,或致电400-865-6067.
为了您能够正常收到来自引擎力云平台的询盘邮件提醒,请将 service@googleseo.com.cn 添加进您的 域白名单。
'; $data = [ 'sender_name' => $request['name'], 'sender_email' => $request['email'], 'content' => $html, 'user_id' => 0, 'sender_uid' => 0, 'title' => '', 'client_ip' => ip2long($request->ip()), 'is_read' => 0, 'is_delete' => 0, 'mail_time' => 0, 'mail_response' => 0, 'create_time' => time(), ]; $connection->table('user_msg')->insert($data); return $this->returnApiSuccess([ 'info' => '提交成功', ]); } catch (\Throwable $exception) { return $this->returnApiError([ 'info' => '提交失败,服务器遇到了未知的错误~[' . $exception->getMessage() . ']', ]); } } /** * 引擎力案例短信验证 * @param Request $request * @return JsonResponse */ public function getVerifyResultBySiteId(Request $request) { $siteId = $request->input('siteId'); $code = $request->input('code'); if (empty($siteId) || empty($code)) { return $this->returnApiError([ 'info' => '缺少必要参数', ]); } $siteInfo = Site::query()->where('id', $siteId)->first(); $time = strtotime(date('Y-m-d H:i:s')) - strtotime($siteInfo->create_time_code); if ($code == $siteInfo->code && $time < 300) { return $this->returnApiSuccess([ 'info' => '验证成功,有效期还剩' . (300 - $time) . '秒', ]); } else { return $this->returnApiError([ 'info' => '验证失败,验证码错误或过期', ]); } } }