123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- <?php
- namespace App\Http\Controllers\Admin;
- use App\Http\Logics\Admin\ReportLogic;
- use App\Http\Models\Site;
- use App\Http\Requests\Report\ContractRequest;
- use App\Http\Requests\Report\SummaryRequest;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\DB;
- use App\Http\Traits\HasSites;
- /**
- * 项目管理下的 项目概况下的 月报扩展,数据报表
- * Class ReportController
- * @package App\Http\Controllers\Admin
- */
- class ReportController extends Controller
- {
- use HasSites;
- protected $logic;
- public function __construct(ReportLogic $logic)
- {
- $this->logic = $logic;
- }
- //数据报表
- public function index($siteId)
- {
- $site = Site::query()->where(['id' => $siteId])->select(['old_id'])->first();
- if (empty($site->old_id)) {
- return view('admin/site/tips', [
- 'siteId' => $siteId,
- 'tips' => '关联站点信息不存在'
- ]);
- }
- return view('admin/report/index_for_site', [
- 'site' => $site,
- 'siteId' => $siteId //admin/site/side_layout 需要此字段
- ]
- );
- }
- //客户界面的数据报表
- public function customerReport()
- {
- $site = $this->hasUserOneSite();
- if (!$site) {
- return view('admin/errors/tips');
- }
- if (empty($site->old_id)) {
- return view('admin/errors/tips', [
- 'tips' => '关联站点信息不存在'
- ]);
- }
- return view('admin/report/customer_report', [
- 'site' => $site,
- ]
- );
- }
- //月报扩展
- public function extend($siteId)
- {
- $sixMonth = [];
- for ($count = 1; $count <= 6; $count++) {
- $sixMonth[] = date('Ym', strtotime('first day of -' . $count . ' month'));
- }
- $site = Site::query()->where(['id' => $siteId])->first();
- if (empty($site->old_id)) {
- return view('admin/site/tips', [
- 'siteId' => $siteId,
- 'tips' => '关联站点信息不存在'
- ]);
- }
- $rankConnection = DB::connection('rank');
- $reportExtendList = $rankConnection->table('report_extend')
- ->where(['project_id' => $site->old_id])->limit(6)->orderBy('ym', 'desc')->get();
- $reportSummaryList = $rankConnection->table('report_summary')
- ->where(['project_id' => $site->old_id])->get()->map(function ($item) {
- return (array)$item;
- })->groupBy('ym')->toArray();
- $customList = $rankConnection->table('webmaster_custom')->whereIn('ym', $sixMonth)->where([
- 'project_id' => $site->old_id
- ])->get()->toArray();
- $ym = date('Ym', strtotime('-1 month'));
- $reportExtend = $rankConnection->table('report_extend')
- ->where(['project_id' => $site->old_id, 'ym' => $ym])->first();
- $summaryList = $rankConnection->table('report_summary')
- ->where(['project_id' => $site->old_id, 'ym' => $ym])->get()->toArray();
- $keyCustomList = array_column($customList, null, 'ym');
- $contract = $rankConnection->table('report_contract')->where(['project_id' => $site->old_id, 'ym' => $ym])->first();
- return view('admin/report/extend', [
- 'data' => $site,
- 'siteId' => $siteId,
- 'sixMonth' => $sixMonth,
- 'keyCustomList' => $keyCustomList,
- 'reportExtend' => $reportExtend,
- 'reportExtendList' => $reportExtendList,
- 'reportSummaryList' => $reportSummaryList,
- 'summaryList' => $summaryList,
- 'contractList' => $contract
- ]);
- }
- //月报扩展下的 外链文章同步
- public function syncCustomer(Request $request, $oldId)
- {
- $ymMapData = $request->input('ymMapData');
- if (!is_array($ymMapData)) {
- return response()->json(['message' => '参数错误'], 422);
- }
- foreach ($ymMapData as $key => $item) {
- $condition = ['project_id' => $oldId, 'ym' => $key];
- DB::connection('rank')->table('webmaster_custom')
- ->updateOrInsert($condition, [
- 'link_count' => $item['linkCount'],
- 'article_count' => $item['articleCount'],
- 'create_time' => time()
- ]);
- }
- return response()->json(['message' => '操作成功']);
- }
- //月报扩展下的 月度总结同步
- public function syncSummary(SummaryRequest $request, $oldId)
- {
- $validated = $request->validated();
- $validated['dataList'] = $validated['dataList'] ?? [];
- $validated['fileList'] = $validated['fileList'] ?? [];
- $ym = date('Ym', strtotime('-1 month'));
- $this->logic->syncSummary($ym, $oldId, $validated);
- $this->logic->syncFileExtend($ym, $oldId, $validated);
- return response()->json(['message' => '操作成功']);
- }
- //月报扩展下的 合同同步
- public function syncContract(ContractRequest $request, $oldId)
- {
- $rankConnection = DB::connection('rank');
- $ym = date('Ym', strtotime('-1 month'));
- $validated = $request->validated();
- $validated['create_time'] = time();
- $rankConnection->table('report_contract')->updateOrInsert(['ym' => $ym, 'project_id' => $oldId], $validated);
- return response()->json(['message' => '操作成功']);
- }
- //清除上一个月数据
- public function clearLastMonthData($siteId)
- {
- $lstMonth = date('Ym', strtotime('-1 month', strtotime(date('Y-m-01'))));
- $projectId = Site::query()->where('id', $siteId)->value('old_id');
- if (!empty($projectId)) {
- $rankConnection = DB::connection('rank');
- $rankConnection->table('webmaster_country')->where([['project_id', '=', $projectId], ['ym', '=', $lstMonth]])->delete();
- $rankConnection->table('webmaster_custom')->where([['project_id', '=', $projectId], ['ym', '=', $lstMonth]])->delete();
- $rankConnection->table('webmaster_effect')->where([['project_id', '=', $projectId], ['ym', '=', $lstMonth]])->delete();
- $rankConnection->table('webmaster_flow')->where([['project_id', '=', $projectId], ['flow_ym', '=', $lstMonth]])->delete();
- $rankConnection->table('webmaster_include')->where([['project_id', '=', $projectId], ['ym', '=', $lstMonth]])->delete();
- $rankConnection->table('webmaster_keyword')->where([['project_id', '=', $projectId], ['ym', '=', $lstMonth]])->delete();
- $rankConnection->table('webmaster_keyword_info')->where([['project_id', '=', $projectId], ['ym', '=', $lstMonth]])->delete();
- }
- return response()->json(['message' => '操作成功']);
- }
- //推送消息至app
- public function pushMessage($siteId)
- {
- DB::table('report_notice')->insert(['site_id' => $siteId]);
- $info = DB::table('report_notice_task')->where([['site_id', '=', $siteId], ['status', '=', 0]])->first();
- if (empty($info)) {
- DB::table('report_notice_task')->insert(['site_id' => $siteId]);
- }
- return response()->json(['message' => '操作成功']);
- }
- }
|