123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- <?php
- /**
- * 模版站api
- * @copyright 2021-浙江引擎力营销策划有限公司
- * @author Lc<sunshinecc1@163.com>
- * @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] = '<a href="' . $fileUrl . '" target="_blank">' . $file->getClientOriginalName() . '</a>';
- }
- }
- $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 = '<div class="sep-email" style="max-width:960px; color:#333; margin: auto; background: #f9f9f9; line-height: 1.8em; font-size: 14px; font-family: \'Lucida Grande\', \'Microsoft Yahei\';"><table align="center" bgcolor="#373d41" border="0" cellpadding="0" cellspacing="0" height="48" style="width:100%;"><tbody><tr><td align="center" border="0" height="48" style="padding-left:8px;height:48px;" valign="middle" width="74"><a href="https://www.yinqingli.com/" target="_blank" rel="noopener"><img border="0" height="20" src="https://www.yinqingli.com/uploads/image/logo2.png" ></a></td><td align="right" colspan="2" height="48" style="color:#ffffff; padding-right:12px;height:48px;" valign="middle" width="703"> <a href="javascript:;" style="color:#ffffff;text-decoration:none;font-family:\'Microsoft YaHei\';font-size: 12px;" target="_blank" rel="noopener">上市公司海外营销第一选择!</a> <a href="https://www.yinqingli.com/" style="color:#ffffff;text-decoration:none;font-family:\'Microsoft YaHei\';font-size: 12px;" target="_blank" rel="noopener">访问官网</a></td></tr> </tbody></table>';
- $html .= '<div style="position: relative; padding: 20px 30px 50px 30px;"><b>尊敬的 ' . $formData['email'] . ' 用户:</b><div style="color:#555; border-bottom: solid 1px #ccc; padding-bottom: 10px; margin-bottom: 25px;"><p style="text-indent: 2em;">您好!</p><p style="text-indent: 2em;">您的网站 ' . $website . ' 于 ' . date('Y-m-d H:i:s') . ' 收到一封来自 IP:' . $request->ip() . ' (' . $country . ') 的询盘消息,请及时处理。详细信息如下:</p></div>';
- $html .= '<table style="line-height:2em;color:#333;font-size:14px;width:90%"><tr>';
- $i = 0;
- foreach ($data as $key => $val) {
- if ($i > 0 && $i % 2 == 0) {
- $html .= '</tr><tr>';
- }
- $html .= '<td style="width:100px;text-align:right">' . $key . ':</td>';
- $html .= '<td style="border-bottom:solid 1px #ccc;color:#666;">' . $val . '</td>';
- $i++;
- }
- if (!empty($formData['ext'])) {
- foreach ($formData['ext'] as $key => $ext) {
- $html .= '<tr>';
- $html .= '<td style="width:100px;text-align:right">' . $ext['name'] . ':</td>';
- $html .= '<td colspan="3" style="border-bottom:solid 1px #ccc; color:#666;">' . $ext['value'] . '</td>';
- $html .= '</tr>';
- }
- }
- $html .= '</tr><tr><td style="text-align:right">留言:</td>';
- $html .= '<td colspan="3" style="border-bottom:solid 1px #ccc;color:#666;">';
- $html .= '<div style="line-height:1.8em;padding:2px 0;">' . $content . '</div></td></tr>';
- $html .= '<tr><td style="text-align:right">URL:</td>';
- $html .= '<td colspan="3" style="border-bottom: solid 1px #ccc; color:#666;">';
- $html .= '<div style="line-height:1.8em;padding: 2px 0;"><a href="' . $clientURL . '">' . $clientURL . '</a></div></td></tr>';
- $html .= '</table></div><div style="padding: 20px 30px; background: #e8e8e8; position: relative; font-size: 13px;"><div><strong style="color: #f60">温馨提示:</strong>此邮件由系统自动发出,请勿直接回复!<br />如有疑问或建议,可发送邮件至 <u>hina@yinqingli.com</u>,或致电400-865-6067.<br />为了您能够正常收到来自引擎力云平台的询盘邮件提醒,请将 <u>service@googleseo.com.cn</u> 添加进您的 <b>域白名单。</b><br /></div></div></div>';
- $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' => '验证失败,验证码错误或过期',
- ]);
- }
- }
- }
|