KunWeb/ciyon/web/cwebcomon.php

359 lines
16 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace web;
class cwebcomon {
static function mlmbonus($db, $money, $userrow, $bonusset) {
if ($userrow['upid'] <= 0)
return;
if (!isset($bonusset[0]))
return;
$csql = new \ciy\sql('ap_user');
$csql->where('id', $userrow['upid']);
$uprow = $db->getone($csql);
if (!is_array($uprow))
return;
self::usercashoe($db, 20, $uprow['id'], $money * $bonusset[0]['percent'], $bonusset[0]['name']);
if ($uprow['upid'] <= 0)
return;
if (!isset($bonusset[1]))
return;
$csql = new \ciy\sql('ap_user');
$csql->where('id', $uprow['upid']);
$up2row = $db->getone($csql);
if (!is_array($up2row))
return;
self::usercashoe($db, 21, $up2row['id'], $money * $bonusset[1]['percent'], $bonusset[1]['name']);
if ($up2row['upid'] <= 0)
return;
if (!isset($bonusset[2]))
return;
$csql = new \ciy\sql('ap_user');
$csql->where('id', $up2row['upid']);
$up3row = $db->getone($csql);
if (!is_array($up3row))
return;
self::usercashoe($db, 22, $up3row['id'], $money * $bonusset[2]['percent'], $bonusset[2]['name']);
//最高三级代理
}
static function usercashie($db, $type, $userid, $money, $name = '') {
$updata = array();
if ($money > 0)
$updata['mymoney'] = array('mymoney+' . $money);
else
$updata['mymoney'] = array('mymoney' . $money);
$csql = new \ciy\sql('ap_user');
$csql->where('id', $userid);
if ($db->update($csql, $updata) === false)
throw new \Exception('账户余额更新失败:' . $db->error);
//直接打款
$updata = array();
$updata['cashtype'] = $type;
$updata['iemoney'] = $money;
$updata['vuser'] = $userid;
$updata['name'] = $name;
$updata['addtimes'] = tostamp();
$csql = new \ciy\sql('ap_cash_ie');
if ($db->insert($csql, $updata) === false)
throw new \Exception('新建消费收支失败:' . $db->error);
}
static function usercashoe($db, $type, $userid, $money, $name = '') {
$updata = array();
if ($money > 0)
$updata['mycashmoney'] = array('mycashmoney+' . $money);
else
$updata['mycashmoney'] = array('mycashmoney' . $money);
$csql = new \ciy\sql('ap_user');
$csql->where('id', $userid);
if ($db->update($csql, $updata) === false)
throw new \Exception('账户余额更新失败:' . $db->error);
//直接打款
$updata = array();
$updata['cashtype'] = $type;
$updata['oemoney'] = $money;
$updata['vuser'] = $userid;
$updata['name'] = $name;
$updata['addtimes'] = tostamp();
$csql = new \ciy\sql('ap_cash_oe');
if ($db->insert($csql, $updata) === false)
throw new \Exception('新建佣金收支失败:' . $db->error);
}
static function www_showpage($count, $pageno, $pagecount, $pageurl, $pagecb) {
// $count总数据条数比如有 100 条数据,$count=100
// $pageno当前页码比如现在在第 5 页,$pageno=5
// $pagecount每页显示的数据条数比如每页显示 10 条,$pagecount=10
// $pageurl分页链接的基础 URL比如index.php?act=list&
// $pagecb页码回调函数用于生成最终的 URL 参数比如把页码转为page=5
if ($count <= 0) {
// 1...3,4,5,6,7,8
$isend = (-$count < $pagecount);
//if($pageno < 20) $isend = false;
$epage = $pageno + 2;//结束页
$spage = $pageno - 6;//起始页
if ($isend)
$epage = $pageno;
if ($spage < 1)
$spage = 1;
echo '<a ' . ($pageno <= 1 ? ' class="disabled"' : " href=\"" . $pageurl . $pagecb($pageno - 1) . "\"") . '>上页</a>';
if ($spage > 1)
echo '<a href="' . $pageurl . $pagecb(1) . '">1</a>';
if ($spage > 2)
echo '<span>...</span>';
for ($i = $spage; $i <= $epage; $i++)
echo '<a ' . ($i == $pageno ? ' class="active"' : " href=\"" . $pageurl . $pagecb($i) . "\"") . '>' . $i . '</a>';
echo '<a ' . ($isend ? ' class="disabled"' : " href=\"" . $pageurl . $pagecb($pageno + 1) . "\"") . '>下页</a>';
} else {
//1...3,4,5,6,7...n
$epage = $pageno + 6;
$spage = $pageno - 2;
$pagemax = ceil($count / $pagecount);
if ($spage < 1)
$spage = 1;
if ($epage > $pagemax)
$epage = $pagemax;
echo '<a ' . ($pageno <= 1 ? ' class="disabled"' : " href=\"" . $pageurl . $pagecb($pageno - 1) . "\"") . '>上页</a>';
if ($spage > 1)
echo '<a href="' . $pageurl . $pagecb(1) . '">1</a>';
if ($spage > 2)
echo '<span>...</span>';
for ($i = $spage; $i <= $epage; $i++)
echo '<a ' . ($i == $pageno ? ' class="active"' : " href=\"" . $pageurl . $pagecb($i) . "\"") . '>' . $i . '</a>';
if ($epage < $pagemax - 1)
echo '<span>...</span>';
if ($epage < $pagemax)
echo '<a href="' . $pageurl . $pagecb($pagemax) . '">' . $pagemax . '</a>';
echo '<a ' . ($pageno >= $pagemax ? ' class="disabled"' : " href=\"" . $pageurl . $pagecb($pageno + 1) . "\"") . '>下页</a>';
}
}
// static function www_Kun_showpage($totalData,$PageSize,$currentPage,$pageurl,$pagecb) {
// // totalData 共有多少数据;
// // totalPage 一共可分多少页;
// // PageSize 每页显示多少数据;
// // currentPage 当前页码数 endPage:最大显示到页数 startPage:最小显示到页数
// if($totalData<=0){
// $isend = ( -$totalData < $PageSize);
// $endPage = $currentPage + 2;
// $startPage = $currentPage - 6;
// if($isend==true){
// $endPage = $currentPage;
// }
// if($startPage<1){
// $startPage = 1;
// }
// echo '<button id="prev-page" disabled>上一页</button>';
// if ($startPage > 1)
// echo '<a href="' . $pageurl . $pagecb(1) . '">1</a>';
// if ($startPage > 2)
// echo '<span>...</span>';
// for ($i = $startPage; $i <= $endPage; $i++)
// echo '<a ' . ($i == $currentPage ? ' class="active"' : " href=\"" . $pageurl . $pagecb($i) . "\"") . '>' . $i . '</a>';
// echo '<a ' . ($isend ? ' class="disabled"' : " href=\"" . $pageurl . $pagecb($currentPage + 1) . "\"") . '>下页</a>';
// }else{
// //1...3,4,5,6,7...n
// $endPage = $currentPage + 6;
// clog('我是endPage: '.$endPage);
// $startPage = $currentPage - 2;
// $totalPage = ceil($totalData / $PageSize);
// clog('我是totalPage: '.$totalPage);
// if ($startPage < 1){
// $startPage = 1;
// }
// if ($endPage > $totalPage){
// $endPage = $totalPage;
// }
// echo '<a ' . ($currentPage <= 1 ? ' class="disabled" ' : " href=\"" . $pageurl . $pagecb($currentPage - 1) . "\"") . '>上一页</a>';
// if ($startPage > 1){
// echo '<a href="' . $pageurl . $pagecb(1) . '">1</a>';
// }
// if ($startPage > 2){
// echo '<span>...</span>';
// }
// for ($i = $startPage; $i <= $endPage; $i++)
// echo '<a ' . ($i == $currentPage ? ' class="active"' : " href=\"" . $pageurl . $pagecb($i) . "\"") . '>' . $i . '</a>';
// if ($endPage < $totalPage - 1)
// echo '<span>...</span>';
// if ($endPage < $totalPage)
// echo '<a href="' . $pageurl . $pagecb($totalPage) . '">' . $totalPage . '</a>';
// echo '<a ' . ($currentPage >= $totalPage ? ' class="disabled"' : " href=\"" . $pageurl . $pagecb($currentPage + 1) . "\"") . '>下一页</a>';
// }
// }
static function www_Kun_showpage($totalData,$PageSize,$currentPage,$pageurl,$pagecb) {
// totalData 共有多少数据;
// totalPage 一共可分多少页;
// PageSize 每页显示多少数据;
// currentPage 当前页码数 endPage:最大显示到页数 startPage:最小显示到页数
if($totalData<=0){
$isend = ( -$totalData < $PageSize);
$endPage = $currentPage + 2;
$startPage = $currentPage - 6;
if($isend==true){
$endPage = $currentPage;
}
if($startPage<1){
$startPage = 1;
}
echo '<a ' . ($currentPage <= 1 ? ' class="kun-page-link disabled" ' : " href=\"" . $pageurl . $pagecb($currentPage - 1) . "\" class=\"kun-page-link\"") . '>上一页</a>';
if ($startPage > 1)
// 仅给a标签添加kun-page-link类名
echo '<a href="' . $pageurl . $pagecb(1) . '" class="kun-page-link">1</a>';
if ($startPage > 2)
echo '<span>...</span>';
for ($i = $startPage; $i <= $endPage; $i++)
echo '<a ' . ($i == $currentPage ? ' class="kun-page-link active"' : " href=\"" . $pageurl . $pagecb($i) . "\" class=\"kun-page-link\"") . '>' . $i . '</a>';
echo '<a ' . ($isend ? ' class="kun-page-link disabled"' : " href=\"" . $pageurl . $pagecb($currentPage + 1) . "\" class=\"kun-page-link\"") . '>下页</a>';
}else{
//1...3,4,5,6,7...n
$endPage = $currentPage + 6;
// clog('我是endPage: '.$endPage);
$startPage = $currentPage - 2;
$totalPage = ceil($totalData / $PageSize);
// clog('我是totalPage: '.$totalPage);
if ($startPage < 1){
$startPage = 1;
}
if ($endPage > $totalPage){
$endPage = $totalPage;
}
echo '<a ' . ($currentPage <= 1 ? ' class="kun-page-link disabled" ' : " href=\"" . $pageurl . $pagecb($currentPage - 1) . "\" class=\"kun-page-link\"") . '>上一页</a>';
if ($startPage > 1){
echo '<a href="' . $pageurl . $pagecb(1) . '" class="kun-page-link">1</a>';
}
if ($startPage > 2){
echo '<span>...</span>';
}
for ($i = $startPage; $i <= $endPage; $i++)
echo '<a ' . ($i == $currentPage ? ' class="kun-page-link active"' : " href=\"" . $pageurl . $pagecb($i) . "\" class=\"kun-page-link\"") . '>' . $i . '</a>';
if ($endPage < $totalPage - 1)
echo '<span>...</span>';
if ($endPage < $totalPage)
echo '<a href="' . $pageurl . $pagecb($totalPage) . '" class="kun-page-link">' . $totalPage . '</a>';
echo '<a ' . ($currentPage >= $totalPage ? ' class="kun-page-link disabled"' : " href=\"" . $pageurl . $pagecb($currentPage + 1) . "\" class=\"kun-page-link\"") . '>下一页</a>';
}
}
// 圆点
static function www_Kun_showpage_r($totalData,$PageSize,$currentPage,$pageurl,$pagecb) {
// totalData 共有多少数据;
// totalPage 一共可分多少页;
// PageSize 每页显示多少数据;
// currentPage 当前页码数 endPage:最大显示到页数 startPage:最小显示到页数
if($totalData<=0){
$isend = ( -$totalData < $PageSize);
$endPage = $currentPage + 2;
$startPage = $currentPage - 6;
if($isend==true){
$endPage = $currentPage;
}
if($startPage<1){
$startPage = 1;
}
// 上一页:添加 ← 字符
echo '<a ' . ($currentPage <= 1 ? ' class="kun-page-link page-prev disabled" ' : " href=\"" . $pageurl . $pagecb($currentPage - 1) . "\" class=\"kun-page-link page-prev\"") . '><</a>';
if ($startPage > 1)
echo '<a href="' . $pageurl . $pagecb(1) . '" class="kun-page-link page-num">1</a>';
if ($startPage > 2)
echo '<span class="page-ellipsis">...</span>';
for ($i = $startPage; $i <= $endPage; $i++)
echo '<a ' . ($i == $currentPage ? ' class="kun-page-link page-num active"' : " href=\"" . $pageurl . $pagecb($i) . "\" class=\"kun-page-link page-num\"") . '>' . $i . '</a>';
// 下一页:添加 → 字符
echo '<a ' . ($isend ? ' class="kun-page-link page-next disabled"' : " href=\"" . $pageurl . $pagecb($currentPage + 1) . "\" class=\"kun-page-link page-next\"") . '>></a>';
}else{
//1...3,4,5,6,7...n
$endPage = $currentPage + 6;
$startPage = $currentPage - 2;
$totalPage = ceil($totalData / $PageSize);
if ($startPage < 1){
$startPage = 1;
}
if ($endPage > $totalPage){
$endPage = $totalPage;
}
// 上一页:添加 ← 字符
echo '<a ' . ($currentPage <= 1 ? ' class="kun-page-link page-prev disabled" ' : " href=\"" . $pageurl . $pagecb($currentPage - 1) . "\" class=\"kun-page-link page-prev\"") . '><</a>';
if ($startPage > 1){
echo '<a href="' . $pageurl . $pagecb(1) . '" class="kun-page-link page-num">1</a>';
}
if ($startPage > 2){
echo '<span class="page-ellipsis">...</span>';
}
for ($i = $startPage; $i <= $endPage; $i++)
echo '<a ' . ($i == $currentPage ? ' class="kun-page-link page-num active"' : " href=\"" . $pageurl . $pagecb($i) . "\" class=\"kun-page-link page-num\"") . '>' . $i . '</a>';
if ($endPage < $totalPage - 1)
echo '<span class="page-ellipsis">...</span>';
if ($endPage < $totalPage)
echo '<a href="' . $pageurl . $pagecb($totalPage) . "\" class=\"kun-page-link page-num\">" . $totalPage . '</a>';
// 下一页:添加 → 字符
echo '<a ' . ($currentPage >= $totalPage ? ' class="kun-page-link page-next disabled"' : " href=\"" . $pageurl . $pagecb($currentPage + 1) . "\" class=\"kun-page-link page-next\"") . '>></a>';
}
}
static function www_convertseoword($seowords, $content, $keystr = '') {
$seo = array();
$max = rand(2, 5);
shuffle($seowords);
foreach ($seowords as $row) {
if ($row['rank'] > rand(0, 100))
$seo[$row['name']] = $row['url'];
}
$repcnt = 0;
foreach ($seo as $key => $val) {
$ind = strpos($content, $key);
if ($ind === false)
continue;
$tmp = substr($content, 0, $ind);
$inda = strrpos($tmp, '<a ciy href=');
if ($inda !== false) {
$indb = strpos($tmp, '</a>', $inda);
if ($indb === false) //包含
continue;
}
$content = substr_replace($content, '<a ciy href="' . $val . '">' . $key . '</a>', $ind, strlen($key));
$repcnt++;
if ($repcnt >= $max)
break;
}
if (!empty($keystr)) {
$keystr = str_replace('', ',', $keystr);
$keystr = str_replace(';', ',', $keystr);
$keystr = str_replace('', ',', $keystr);
$keys = explode(',', $keystr);
foreach ($keys as $key) {
if (empty($key))
continue;
$ind = strpos($content, $key);
if ($ind === false)
continue;
$tmp = substr($content, 0, $ind);
$inda = strrpos($tmp, '<strong>');
if ($inda !== false) {
$indb = strpos($tmp, '</strong>', $inda);
if ($indb === false) //包含
continue;
}
$content = substr_replace($content, '<strong>' . $key . '</strong>', $ind, strlen($key));
}
}
return $content;
}
}