354 lines
9.0 KiB
PHP
354 lines
9.0 KiB
PHP
<?php
|
||
|
||
//declare(strict_types=1);
|
||
|
||
namespace App\Services\Tg\Hook\Mod;
|
||
|
||
use App\Models\Order as ModelOrder;
|
||
use App\Models\User as ModelUser;
|
||
use App\Utils\Tools;
|
||
use App\Services\DB;
|
||
use App\Services\Cron;
|
||
use App\Command\Cron as CommandCron;
|
||
use App\Services\TomTool\Http;
|
||
use App\Models\PlanQueue;
|
||
|
||
final class Test extends Base
|
||
{
|
||
// id:1778 测试员test1,可着它嚯嚯
|
||
|
||
public function go($aParam)
|
||
{
|
||
|
||
// $oPlanQueue = new PlanQueue();
|
||
// $oPlanQueue->user_id = 123123;
|
||
// $oPlanQueue->updated_at = time();
|
||
// $oPlanQueue->_save();
|
||
// $r = $oPlanQueue->save();
|
||
|
||
// tomd(444);
|
||
// tomd($r, 44444);
|
||
// exit;
|
||
|
||
|
||
|
||
|
||
$method = $aParam["aArg"][1];
|
||
|
||
if (method_exists($this, $method)) {
|
||
return $this->$method();
|
||
}
|
||
|
||
// abort(404);
|
||
}
|
||
|
||
public function rootGet()
|
||
{
|
||
$oUserRoot = ModelUser::select("email", "class", "transfer_enable", "u", "autorenew", "money")->where("email", "root")->first();
|
||
|
||
return $this->toJson($oUserRoot);
|
||
}
|
||
|
||
public function doveGet()
|
||
{
|
||
$oUserRoot = ModelUser::select("email", "class", "transfer_enable", "u", "autorenew", "money")->where("email", "dove")->first();
|
||
|
||
return $this->toJson($oUserRoot);
|
||
}
|
||
|
||
public function orderClear()
|
||
{
|
||
DB::table('order')->delete();
|
||
DB::table('plan_pending')->delete();
|
||
DB::table('plan_activated')->delete();
|
||
DB::table('plan_expired')->delete();
|
||
DB::table('plan_queue')->delete();
|
||
DB::table('invoice')->delete();
|
||
DB::table('paylist')->delete();
|
||
DB::table('payback')->delete();
|
||
|
||
return 1;
|
||
}
|
||
|
||
public function rootDown()
|
||
{
|
||
$oUserRoot = ModelUser::where("email", "root")->first();
|
||
$oUserRoot->u = 0;
|
||
$oUserRoot->class = 1;
|
||
$oUserRoot->transfer_enable = 0;
|
||
return $oUserRoot->save();
|
||
}
|
||
|
||
public function userDown($aParam)
|
||
{
|
||
$sUser = $aParam["aArg"][1] ?? false;
|
||
|
||
if (!$sUser) {
|
||
return "需要arg1";
|
||
}
|
||
|
||
$oUserRoot = ModelUser::where("email", $sUser)->first();
|
||
$oUserRoot->u = 0;
|
||
$oUserRoot->class = 1;
|
||
$oUserRoot->transfer_enable = 0;
|
||
return $oUserRoot->save();
|
||
}
|
||
|
||
public function rootUp()
|
||
{
|
||
$oUserRoot = ModelUser::where("email", "root")->first();
|
||
$oUserRoot->u = 222;
|
||
$oUserRoot->class = 2;
|
||
$oUserRoot->transfer_enable = 111;
|
||
return $oUserRoot->save();
|
||
}
|
||
|
||
public function userUp($aParam)
|
||
{
|
||
|
||
$sUser = $aParam["aArg"][1] ?? false;
|
||
|
||
if (!$sUser) {
|
||
return "需要arg1";
|
||
}
|
||
|
||
$oUserRoot = ModelUser::where("email", $sUser)->first();
|
||
$oUserRoot->u = 222;
|
||
$oUserRoot->class = 2;
|
||
$oUserRoot->transfer_enable = 111;
|
||
return $oUserRoot->save();
|
||
}
|
||
|
||
public function rootExpire()
|
||
{
|
||
$oUserRoot = ModelUser::where("email", "root")->first();
|
||
$oUserRoot->u = 222;
|
||
$oUserRoot->class = 2;
|
||
$oUserRoot->transfer_enable = 111;
|
||
return $oUserRoot->save();
|
||
}
|
||
|
||
public function userExpire()
|
||
{
|
||
$sUser = $aParam["aArg"][1] ?? false;
|
||
|
||
if (!$sUser) {
|
||
return "需要arg1";
|
||
}
|
||
|
||
$oUserRoot = ModelUser::where("email", $sUser)->first();
|
||
$oUserRoot->u = 222;
|
||
$oUserRoot->class = 2;
|
||
$oUserRoot->transfer_enable = 111;
|
||
return $oUserRoot->save();
|
||
}
|
||
|
||
public function orderCombo()
|
||
{
|
||
$job = new Cron();
|
||
$job->orderToPlan(); // 账单激活 | 用户当前class非2就进过期队列
|
||
$job->plan_expireToQueue(); // 标记过期队列
|
||
$job->planQueue_pendingToActivation(); // 队列排除 1 激活pending
|
||
$job->planQueue_expireToBuy(); // 队列排除 2 自动续订 购买激活
|
||
$job->planQueue_expireDone(); // 队列3 处理完成 发送通知
|
||
|
||
return 1;
|
||
}
|
||
|
||
public function orderPay()
|
||
{
|
||
$job = new Cron();
|
||
$job->processPendingOrder();
|
||
}
|
||
|
||
public function expireCheck()
|
||
{
|
||
$job = new Cron();
|
||
$job->class_expire_check();
|
||
}
|
||
|
||
public function activation()
|
||
{
|
||
$job = new Cron();
|
||
$job->plan_expire_activation();
|
||
}
|
||
|
||
public function autoRenew()
|
||
{
|
||
$job = new Cron();
|
||
$job->plan_expire_autorenew();
|
||
}
|
||
|
||
public function planDone()
|
||
{
|
||
$job = new Cron();
|
||
$job->plan_expire_done();
|
||
}
|
||
|
||
public function plan()
|
||
{
|
||
|
||
$job = new Cron();
|
||
$job->processPendingOrder(); // 账单激活 | 用户当前class非2就进过期队列
|
||
$job->class_expire_check(); // 标记过期队列
|
||
$job->plan_expire_activation(); // 队列排除 1 激活pending
|
||
$job->plan_expire_autorenew(); // 队列排除 2 自动续订 购买激活
|
||
$job->plan_expire_done(); // 队列3 处理完成 发送通知
|
||
|
||
}
|
||
|
||
public function cronAll()
|
||
{
|
||
(new CommandCron([]))->boot();
|
||
}
|
||
|
||
public function cron($aParam)
|
||
{
|
||
$sFunc = $aParam["aArg"][1];
|
||
$job = new Cron();
|
||
return $job->$sFunc();
|
||
}
|
||
|
||
public function smtpClearDayCount()
|
||
{
|
||
$job = new Cron();
|
||
$job->smtpClearDayCount();
|
||
}
|
||
|
||
public function payReturn($aParam)
|
||
{
|
||
$sCode = $aParam["aArg"][1] ?? false;
|
||
|
||
$oHttp = new Http();
|
||
|
||
$oHttp->sMethod = "get";
|
||
$oHttp->sToUrl = $_ENV['baseUrl']."/payment/notify/".$sCode;
|
||
// $oHttp->bIsJson = true;
|
||
//$oHttp->aData[]
|
||
|
||
$r = $oHttp->send();
|
||
|
||
return $this->toJson($r);
|
||
}
|
||
|
||
public function runMailBulk()
|
||
{
|
||
Cron::processEmailQueue_bulk();
|
||
}
|
||
|
||
private function OrderFormat($v)
|
||
{
|
||
$v['create_time'] = date("Y-m-d H:i:m", $v['create_time']);
|
||
$v['update_time'] = date("Y-m-d H:i:m", $v['update_time']);
|
||
$v['product_content'] = json_decode($v['product_content']);
|
||
|
||
return $v;
|
||
}
|
||
|
||
private function ValueTypeFormat($sValue)
|
||
{
|
||
list($sValue, $sValueType) = explode("#", $sValue);
|
||
|
||
if ($sValueType) {
|
||
if ($sValueType == "gb") {
|
||
$sValue = Tools::tomGbToB($sValue);
|
||
} else if ($sValueType == "date") {
|
||
$sValue = strtotime($sValue);
|
||
}
|
||
}
|
||
|
||
return $sValue;
|
||
}
|
||
|
||
public function OrderSet($aParam)
|
||
{
|
||
|
||
$iId = $aParam['aOption'][1];
|
||
$sField = $aParam['aOption'][2];
|
||
$sValue = $aParam['aArg'][1];
|
||
$sValue = $this->ValueTypeFormat($sValue);
|
||
|
||
if (!$iId) {
|
||
return "参数不对";
|
||
}
|
||
|
||
$oOrder = ModelOrder::find($iId);
|
||
|
||
if ($oOrder) {
|
||
$oOrder->$sField = $sValue;
|
||
$r = $oOrder->save();
|
||
} else {
|
||
$r = '没有';
|
||
}
|
||
|
||
return $r;
|
||
|
||
}
|
||
|
||
public function UserSet($aParam)
|
||
{
|
||
|
||
$iId = 1778;
|
||
$sField = $aParam['aOption'][1];
|
||
$sValue = $aParam['aArg'][1];
|
||
$sValue = $this->ValueTypeFormat($sValue);
|
||
|
||
$oUser = ModelUser::find($iId);
|
||
|
||
if ($oUser) {
|
||
$oUser->$sField = $sValue;
|
||
$r = $oUser->save();
|
||
} else {
|
||
$r = '没有';
|
||
}
|
||
|
||
return $r;
|
||
|
||
}
|
||
|
||
public function OrderLimit($aParam)
|
||
{
|
||
$iUserId = 1778;
|
||
$iLimit = $aParam['aArg'][1] ?? 3;
|
||
|
||
$aOrderList = ModelOrder::where("user_id", $iUserId)->orderBy('id', 'desc')->limit($iLimit)->get()->toArray();
|
||
|
||
foreach ($aOrderList as $v) {
|
||
$aOrderSingle = $this->OrderFormat($v);
|
||
$sMsg = json_encode($aOrderSingle, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||
$this->oTGHttp->sendToTG($sMsg);
|
||
}
|
||
|
||
$this->oHttp::response(200, 'ok');
|
||
}
|
||
|
||
public function OrderClone($aParam)
|
||
{
|
||
$iId = $aParam['aArg'][1];
|
||
|
||
$oOrder = ModelOrder::find($iId);
|
||
|
||
$oOrderNew = $oOrder->replicate();
|
||
|
||
return $oOrderNew->save();
|
||
}
|
||
|
||
public function OrderStatusList()
|
||
{
|
||
$tmp = [
|
||
"pending_payment" => "等待付款",
|
||
"paid_gateway" => "已付款 - 通道",
|
||
"paid_balance" => "已付款 - 余额",
|
||
"paid_admin" => "已付款 - 管理员",
|
||
"pending_activation" => "等待激活",
|
||
"cancelled" => "取消",
|
||
"activated" => "已激活",
|
||
"expired" => "过期",
|
||
"说明" => "付款之后是已付款状态,走一次cron变成等待激活",
|
||
];
|
||
|
||
return json_encode($tmp, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||
}
|
||
|
||
}
|