/** * 推送 * * */ public function pushPrecent() { if (ob_get_level() == 0) { ob_start(); } $indexhtml = $this->homgepagehtml('pc'); $customer_data_get = CustomerPushfile::where('cus_id', $this->cus_id)->pluck('files'); if ($customer_data_get) { $new_data = 0; $customer_data = unserialize($customer_data_get); } else { $new_data = 1; $customer_data = []; } $mindexhtml = $this->homgepagehtml('mobile'); //$mindexhtml = $this->mhomgepagehtml(); $pc_classify_ids = Classify::where('cus_id', $this->cus_id)->where('pc_show', 1)->lists('id'); $mobile_classify_ids = Classify::where('cus_id', $this->cus_id)->where('mobile_show', 1)->lists('id'); $pc_article_ids = Articles::where('cus_id', $this->cus_id)->where('pc_show', 1)->lists('id'); $mobile_article_ids = Articles::where('cus_id', $this->cus_id)->where('mobile_show', 1)->lists('id'); $count = $this->htmlPagecount($pc_classify_ids, $mobile_classify_ids, $pc_article_ids, $mobile_article_ids); $this->html_precent = 70 / $count; $categoryhtml = $this->categoryhtml($pc_classify_ids); $mcategoryhtml = $this->mcategoryhtml($mobile_classify_ids); $articlehtml = $this->articlehtml($pc_article_ids); $marticlehtml = $this->marticlehtml($mobile_article_ids); $this->percent = 20 / $count; $path = public_path('customers/' . $this->customer . '/' . $this->customer . '.zip'); $zip = new ZipArchive(); if ($zip->open($path, ZipArchive::CREATE) === TRUE) { $zip->addFile($indexhtml, 'index.html'); $nowpercent = $this->percent + $this->lastpercent; if (floor($nowpercent) != $this->lastpercent) { echo floor($nowpercent) . '%<script type="text/javascript">parent.refresh(' . floor($nowpercent) . ');</script><br />'; ob_flush(); flush(); } $this->lastpercent += 70 + $this->percent; $zip->addFile($mindexhtml, 'm/index.html'); $nowpercent = $this->percent + $this->lastpercent; if (floor($nowpercent) != floor($this->lastpercent)) { echo floor($nowpercent) . '%<script type="text/javascript">parent.refresh(' . floor($nowpercent) . ');</script><br />'; ob_flush(); flush(); } $this->lastpercent += $this->percent; $zip->close(); } $customer_data = $this->compareZip($categoryhtml, $customer_data, 'p', 'category', $path); $customer_data = $this->compareZip($mcategoryhtml, $customer_data, 'm', 'm/category', $path); $customer_data = $this->compareZip($articlehtml, $customer_data, 'pf', 'detail', $path); $customer_data = $this->compareZip($marticlehtml, $customer_data, 'mf', 'm/detail', $path); if (90 < floor($this->lastpercent)) { echo '90%<script type="text/javascript">parent.refresh(90);</script><br />'; ob_flush(); flush(); } if ($zip->open($path, ZipArchive::CREATE) === TRUE) { $aim_dir = public_path('templates/GP006/'); $maim_dir = public_path('templates/GM001/'); $this->addDir($aim_dir, $zip); $this->addDir($maim_dir, $zip, 'm/'); $zip->close(); $data = serialize($customer_data); if ($new_data) { } else { CustomerPushfile::where('cus_id', $this->cus_id)->update(['files' => $data]); } $customerinfo = Customer::find($this->cus_id); $ftp_array = explode(':', $customerinfo->ftp_address); $ftp_array[1] = isset($ftp_array[1]) ? $ftp_array[1] : '21'; $conn = ftp_connect($ftp_array[0], $ftp_array[1]); if ($conn) { ftp_login($conn, $customerinfo->ftp_user, $customerinfo->ftp_pwd); ftp_put($conn, "site.zip", $path, FTP_BINARY); ftp_put($conn, "unzip.php", $path, FTP_BINARY); ftp_close($conn); } echo '100%<script type="text/javascript">parent.refresh(100);</script><br />'; Classify::where('cus_id', $this->cus_id)->where('pushed', 1)->update(['pushed' => 0]); Articles::where('cus_id', $this->cus_id)->where('pushed', 1)->update(['pushed' => 0]); } else { echo '打包失败'; } ob_end_flush(); }
/** * 推送 * * */ public function pushPrecent() { if (ob_get_level() == 0) { ob_start(); } $indexhtml = $this->homgepagehtml('pc'); $customer_data_get = CustomerPushfile::where('cus_id', $this->cus_id)->pluck('files'); if ($customer_data_get) { $new_data = 0; $customer_data = unserialize($customer_data_get); } else { $new_data = 1; $customer_data = []; } $mindexhtml = $this->homgepagehtml('mobile'); $pc_classify_ids = Classify::where('cus_id', $this->cus_id)->where('pc_show', 1)->lists('id'); $mobile_classify_ids = Classify::where('cus_id', $this->cus_id)->where('mobile_show', 1)->lists('id'); $pc_article_ids = Articles::where('cus_id', $this->cus_id)->where('pc_show', 1)->lists('id'); $mobile_article_ids = Articles::where('cus_id', $this->cus_id)->where('mobile_show', 1)->lists('id'); $count = $this->htmlPagecount($pc_classify_ids, $mobile_classify_ids, $pc_article_ids, $mobile_article_ids); $this->html_precent = 70 / $count; $categoryhtml = $this->categoryhtml($pc_classify_ids, 'pc'); $mcategoryhtml = $this->categoryhtml($mobile_classify_ids, 'mobile'); $articlehtml = $this->articlehtml($pc_article_ids, 'pc'); $marticlehtml = $this->articlehtml($mobile_article_ids, 'mobile'); $this->percent = 20 / $count; $path = public_path('customers/' . $this->customer . '/' . $this->customer . '.zip'); $template = new PrintController('online', 'mobile'); $quickbar_json = $template->quickBarJson(); $zip = new ZipArchive(); if ($zip->open($path, ZipArchive::CREATE) === TRUE) { $zip->addFile($indexhtml, 'index.html'); $nowpercent = $this->percent + $this->lastpercent; if (floor($nowpercent) != $this->lastpercent) { echo floor($nowpercent) . '%<script type="text/javascript">parent.refresh(' . floor($nowpercent) . ');</script><br />'; ob_flush(); flush(); } $this->lastpercent += 70 + $this->percent; $zip->addFile($mindexhtml, 'mobile/index.html'); $nowpercent = $this->percent + $this->lastpercent; if (floor($nowpercent) != floor($this->lastpercent)) { echo floor($nowpercent) . '%<script type="text/javascript">parent.refresh(' . floor($nowpercent) . ');</script><br />'; ob_flush(); flush(); } $this->lastpercent += $this->percent; $zip->close(); } //$customer_data = $this->compareZip($categoryhtml,$customer_data,'p','category',$path); //$customer_data = $this->compareZip($mcategoryhtml,$customer_data,'m','mobile/category',$path); //$customer_data = $this->compareZip($articlehtml,$customer_data,'pf','detail',$path); //$customer_data = $this->compareZip($marticlehtml,$customer_data,'mf','mobile/detail',$path); $this->compareZip($categoryhtml, $customer_data, 'p', 'category', $path); $this->compareZip($mcategoryhtml, $customer_data, 'm', 'mobile/category', $path); $this->compareZip($articlehtml, $customer_data, 'pf', 'detail', $path); $this->compareZip($marticlehtml, $customer_data, 'mf', 'mobile/detail', $path); if (90 > floor($this->lastpercent)) { echo '90%<script type="text/javascript">parent.refresh(90);</script><br />'; ob_flush(); flush(); } if ($zip->open($path, ZipArchive::CREATE) === TRUE) { $pc_dir = Template::where('website_info.cus_id', $this->cus_id)->Leftjoin('website_info', 'website_info.pc_tpl_id', '=', 'template.id')->pluck('name'); $mobile_dir = Template::where('website_info.cus_id', $this->cus_id)->Leftjoin('website_info', 'template.id', '=', 'website_info.mobile_tpl_id')->pluck('name'); $aim_dir = public_path("templates/{$pc_dir}/"); $maim_dir = public_path("templates/{$mobile_dir}/"); //$images_dir=public_path("customers/".$this->customer."/images/"); $this->addDir($aim_dir, $zip); //$this->addDir($images_dir,$zip,'images/'); $this->addDir($maim_dir, $zip, 'mobile/'); $zip->close(); $data = serialize($customer_data); if ($new_data) { $customerpushfile = new CustomerPushfile(); $customerpushfile->cus_id = $this->cus_id; $customerpushfile->files = $data; $customerpushfile->save(); } else { CustomerPushfile::where('cus_id', $this->cus_id)->update(['files' => $data]); } $customerinfo = Customer::find($this->cus_id); $ftp_array = explode(':', $customerinfo->ftp_address); $ftp_array[1] = isset($ftp_array[1]) ? $ftp_array[1] : '21'; $conn = ftp_connect($ftp_array[0], $ftp_array[1]); if ($conn) { ftp_login($conn, $customerinfo->ftp_user, $customerinfo->ftp_pwd); ftp_pasv($conn, 1); ftp_put($conn, "site.zip", $path, FTP_BINARY); ftp_put($conn, "unzip.php", public_path("packages/unzip.php"), FTP_ASCII); ftp_put($conn, "quickbar.json", public_path('customers/' . $this->customer . '/quickbar.json'), FTP_ASCII); ftp_put($conn, "mobile/quickbar.json", public_path('customers/' . $this->customer . '/quickbar.json'), FTP_ASCII); ftp_close($conn); } echo '100%<script type="text/javascript">parent.refresh(100);</script><br />'; Classify::where('cus_id', $this->cus_id)->where('pushed', 1)->update(['pushed' => 0]); Articles::where('cus_id', $this->cus_id)->where('pushed', 1)->update(['pushed' => 0]); $search_data = new TemplatesController(); $search_data->sendData(); $pc_domain = CustomerInfo::where('cus_id', $this->cus_id)->pluck('pc_domain'); @file_get_contents("{$pc_domain}/unzip.php"); } else { echo '打包失败'; } ob_end_flush(); }