182 lines
4.7 KiB
PHP
182 lines
4.7 KiB
PHP
<?php
|
||
|
||
namespace App\Services\Tg\Hook\Mod;
|
||
|
||
use App\Models\User as ModelUser;
|
||
use App\Services\Tg\Hook\Dog;
|
||
use App\Services\Tg\ReportUser as ServiceTgReportUser;
|
||
use App\Utils\Tools;
|
||
use App\Services\CountUser as ServiceCountUser;
|
||
|
||
class User extends Base {
|
||
|
||
private $oDog;
|
||
|
||
public function __construct($aUpdate)
|
||
{
|
||
|
||
$this->oDog = new Dog(new ModelUser());
|
||
$this->oDog->_setDogName("user"); // 必须,me用,正常就是类名,只不过后期没准改名,所以就这里写死
|
||
// $this->oDog->_setPrimaryKey("code"); // 可选,默认id
|
||
// $this->oDog->_setStrField(["content"]); // 可选,指定长文本字段
|
||
// $this->oDog->_setInFormat(["date"]);
|
||
$this->oDog->_setOutFormat([
|
||
"transfer_enable" => "gb",
|
||
"u" => "gb",
|
||
"d" => "gb",
|
||
]);
|
||
}
|
||
|
||
public function __call($sName, $aArg)
|
||
{
|
||
|
||
return $this->oDog->$sName($aArg[0]);
|
||
|
||
}
|
||
|
||
public function findFull($aParam)
|
||
{
|
||
return $this->oDog->find($aParam);
|
||
}
|
||
|
||
public function find($aParam)
|
||
{
|
||
$sMail = $aParam["aArg"][1] ?? false;
|
||
|
||
$aSelectField = [
|
||
"id",
|
||
"email",
|
||
"money",
|
||
"total_pay",
|
||
"class",
|
||
"class_expire",
|
||
"transfer_enable",
|
||
"u",
|
||
"d",
|
||
"reg_date",
|
||
];
|
||
|
||
$this->_setSelectField($aSelectField);
|
||
|
||
return $this->oDog->find($aParam);
|
||
}
|
||
|
||
public function moneyAdd($aParam)
|
||
{
|
||
$aParam["_sUpDown"] = "up";
|
||
|
||
if ($aParam["aArg"][1] == "?") {
|
||
return "/user#moneyAdd__[key]__[where]__确认[y/n:default] [money]";
|
||
}
|
||
|
||
return $this->_moneyUpDown($aParam);
|
||
}
|
||
|
||
private function _moneyUpDown($aParam)
|
||
{
|
||
$sKey = $aParam["aOption"][1] ?? false;
|
||
$sWhere = $aParam["aOption"][2] ?? false;
|
||
$sConfirm = $aParam["aOption"][3] ?? "n";
|
||
$iMoney = $aParam["aArg"][1] ?? false;
|
||
|
||
$sUpDown = $aParam["_sUpDown"] ?? false;
|
||
|
||
if (!$sUpDown) {
|
||
return "需要upDown";
|
||
}
|
||
|
||
if (!$sKey) {
|
||
return "需要key";
|
||
}
|
||
|
||
if (!$sWhere) {
|
||
return "需要where";
|
||
}
|
||
|
||
if (!$iMoney) {
|
||
return "需要money";
|
||
}
|
||
|
||
$oUser = ModelUser::select("id", "email", "money", "total_pay", "class")->where($sKey, $sWhere)->first();
|
||
|
||
if (!$oUser) {
|
||
return "没有这个user";
|
||
}
|
||
|
||
if ($sConfirm == "n") {
|
||
$sStr = "<p>给他加【".$iMoney."】的money,确认加y<p>";
|
||
$sStr .= $this->toJson($oUser);
|
||
|
||
return $sStr;
|
||
}
|
||
|
||
if ($sConfirm == "y") {
|
||
$oUser->money += $iMoney;
|
||
$oUser->save();
|
||
|
||
return $this->toJson($oUser);
|
||
}
|
||
|
||
}
|
||
|
||
public function CountReg($aParam)
|
||
{
|
||
|
||
@$sOption1 = $aParam['aOption'][1] ?? 'day';
|
||
@$sOption2 = $aParam['aOption'][2] ?? 0;
|
||
@$sOption3 = $aParam['aOption'][3];
|
||
@$sOption4 = $aParam['aOption'][4];
|
||
|
||
$sMsg = '?';
|
||
|
||
if ($sOption1 == 'day') {
|
||
$r = (new ServiceCountUser())->RegByDay($sOption2);
|
||
}
|
||
|
||
if ($sOption1 == 'date') {
|
||
$r = (new ServiceCountUser())->RegByDate($sOption2, $sOption3);
|
||
}
|
||
|
||
$sTop = "\n\n--注册统计--------------------";
|
||
$sMsg = '';
|
||
$iTotalCount = 0;
|
||
foreach ($r as $row) {
|
||
$sMsg .= "\n\n";
|
||
$sMsg .= $row['from'].":".$row['count'];
|
||
$iTotalCount += $row['count'] ?? 0;
|
||
}
|
||
|
||
$sTotal = "\n\n总数:".$iTotalCount;
|
||
$sTotal .= "\n\n---------------------------";
|
||
|
||
$sFoot = "\n\n---------------------------";
|
||
|
||
return $sTop.$sTotal.$sMsg.$sFoot;
|
||
}
|
||
|
||
public function Report($aParam)
|
||
{
|
||
|
||
// @list(, $sOption1, $sOption2, $sOption3) = explode("_", $sText, 4);
|
||
|
||
@$sOption1 = $aParam['aOption'][1];
|
||
@$sOption2 = $aParam['aOption'][2];
|
||
@$sOption3 = $aParam['aOption'][3];
|
||
@$sOption4 = $aParam['aOption'][4];
|
||
|
||
$sMsg = '?';
|
||
|
||
if ($sOption1 == 'day') {
|
||
$sMsg = (new ServiceTgReportUser())->ByDay($sOption2);
|
||
}
|
||
|
||
if ($sOption1 == 'date') {
|
||
$sMsg = (new ServiceTgReportUser())->ByDate($sOption2, $sOption3);
|
||
}
|
||
|
||
return $sMsg;
|
||
|
||
}
|
||
|
||
}
|