no message
This commit is contained in:
parent
f98286d2f6
commit
21292655e5
@ -83,7 +83,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--PackageConversion modal-->
|
||||
<!--PackageConversion modal-->
|
||||
<div class="modal fade" id="PackageConversion-modal" tabindex="-1" role="dialog" aria-labelledby="deleteidModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||
<div class="modal-content">
|
||||
|
||||
@ -19,10 +19,10 @@
|
||||
<tbody>
|
||||
{foreach $oUserPlanList as $oUserPlanRow}
|
||||
<tr>
|
||||
<td>{$oUserPlanRow['order_id']}</td>
|
||||
<td>{$oUserPlanRow['id']}</td>
|
||||
<td>{$oUserPlanRow['user_product_name']} <a href="#" onclick="productDetail('{$oUserPlanRow['product_code']}'); return false;"><i class="feather icon-search"></i></a></td>
|
||||
<td>{$oUserPlanRow['user_price']}</td>
|
||||
<td>{$oUserPlanRow['plan_type']}</td>
|
||||
<td>{$oUserPlanRow['status']}</td>
|
||||
<td>{$oUserPlanRow['created_at']}</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
|
||||
@ -10,19 +10,67 @@ use App\Services\TomTool\PageBar;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Slim\Http\Response;
|
||||
use Slim\Http\ServerRequest;
|
||||
use App\Models\PlanActivated;
|
||||
use App\Models\PlanExpired;
|
||||
use App\Models\PlanPending;
|
||||
//use App\Models\PlanActivated;
|
||||
//use App\Models\PlanExpired;
|
||||
//use App\Models\PlanPending;
|
||||
use App\Models\Product;
|
||||
use App\Models\Order;
|
||||
use App\Services\Db;
|
||||
use voku\helper\AntiXSS;
|
||||
|
||||
final class PlanController extends BaseController
|
||||
{
|
||||
|
||||
public function ajaxPlanLog(ServerRequest $request, Response $response, array $args): ResponseInterface
|
||||
{
|
||||
$iPage = $args['page'] ?? 1;
|
||||
|
||||
$oOrder = Order::where("user_id", $this->user->id)
|
||||
->orderByRaw("CASE
|
||||
WHEN status = 'payment_pending' THEN 1
|
||||
WHEN status = 'activated' THEN 2
|
||||
WHEN status = 'pending' THEN 3
|
||||
WHEN status = 'expired' THEN 4
|
||||
ELSE 5
|
||||
END")
|
||||
->orderBy('id', 'desc') // 按 id 降序排序
|
||||
->paginate(20, ['*'], 'page', $iPage);
|
||||
|
||||
$sPageBar = PageBar::cool($oOrder->lastPage(), $oOrder->currentPage(), "/user/plan/");
|
||||
|
||||
foreach ($oOrder as &$oUserPlanRow) {
|
||||
$oUserPlanRow->created_at = date("Y-m-d H:i:s", $oUserPlanRow->create_time);
|
||||
|
||||
if ($oUserPlanRow->error_str) {
|
||||
$oUserPlanRow->status = $oUserPlanRow->error_str;
|
||||
}
|
||||
|
||||
else if ($oUserPlanRow->status == "payment_pending") {
|
||||
$oUserPlanRow->status = "等待支付";
|
||||
} else if ($oUserPlanRow->status == "activated") {
|
||||
$oUserPlanRow->status = "<span class='text-primary'>使用中</span>";
|
||||
} else if ($oUserPlanRow->status == "pending") {
|
||||
$oUserPlanRow->status = "提前续订";
|
||||
} else if ($oUserPlanRow->status == "expired") {
|
||||
$oUserPlanRow->status = "已过期";
|
||||
}
|
||||
}
|
||||
|
||||
$sView = $this->view()
|
||||
->assign('oUserPlanList', $oOrder)
|
||||
->assign('pageBar', $sPageBar)
|
||||
->fetch('user/plan/ajax_planLog.tpl');
|
||||
|
||||
return $response->withJson([
|
||||
'ret' => 1,
|
||||
'view' => $sView,
|
||||
]);
|
||||
}
|
||||
|
||||
public function ajaxPlanLog__(ServerRequest $request, Response $response, array $args): ResponseInterface
|
||||
{
|
||||
$iPage = $args['page'] ?? 1;
|
||||
|
||||
$activatedPlans = PlanActivated::select('*', DB::raw("'activated' as plan_type"))
|
||||
->where('user_id', $this->user->id);
|
||||
|
||||
@ -80,6 +128,8 @@ final class PlanController extends BaseController
|
||||
]);
|
||||
}
|
||||
|
||||
// tomd($sProductCode, 1);
|
||||
|
||||
$oProductDetail = Product::where("code", $sProductCode)->first()->toArray();
|
||||
$oProductDetail["content"] = json_decode($oProductDetail["content"], true);
|
||||
|
||||
|
||||
@ -26,6 +26,28 @@ final class Order extends Model
|
||||
protected $connection = 'default';
|
||||
protected $table = 'order';
|
||||
|
||||
public static function _add(&$oOrder, $sStatus = false)
|
||||
{
|
||||
// $order_id = $oOrder->order_id ? $oOrder->order_id : $oOrder->id;
|
||||
|
||||
$oPlanPending = new Order();
|
||||
$oPlanPending->order_id = $order_id;
|
||||
$oPlanPending->user_id = $oOrder->user_id;
|
||||
$oPlanPending->product_code = $oOrder->product_code;
|
||||
$oPlanPending->user_product_name = $oOrder->user_product_name;
|
||||
$oPlanPending->user_price = $oOrder->user_price;
|
||||
$oPlanPending->user_coupon = $oOrder->user_coupon;
|
||||
if ($sStatus) {
|
||||
$oPlanPending->status = $sStatus;
|
||||
}
|
||||
// $oPlanPending->updated_at = time();
|
||||
// $oPlanPending->created_at = $oOrder->create_time;
|
||||
$oPlanPending->create_time = time();
|
||||
$oPlanPending->update_time = time();
|
||||
|
||||
return $oPlanPending->_save();
|
||||
}
|
||||
|
||||
public function _save(array $options = [])
|
||||
{
|
||||
$result = parent::save($options);
|
||||
|
||||
@ -25,9 +25,9 @@ final class UserMoneyLog extends Model
|
||||
protected $table = 'user_money_log';
|
||||
|
||||
protected $casts = [
|
||||
'create_time' => 'datetime'
|
||||
// 'create_time' => 'datetime'
|
||||
];
|
||||
|
||||
|
||||
public function add(int $user_id, float $before, float $after, float $amount, string $remark, int $type = 0): void
|
||||
{
|
||||
$this->user_id = $user_id;
|
||||
@ -39,4 +39,10 @@ final class UserMoneyLog extends Model
|
||||
$this->create_time = time();
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function getCreateTimeAttribute($value)
|
||||
{
|
||||
return date('Y-m-d H:i:s', $value); // 将 Unix 时间戳格式化为 datetime 字符串
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -860,8 +860,10 @@ final class Cron
|
||||
|
||||
} else if ($oUser->class < $iPayClass) { // 当前无套餐,直接进激活队列
|
||||
|
||||
$oPlanPending = new PlanPending();
|
||||
$oPlanPending->_add($oOrder);
|
||||
// $oPlanPending = new Order();
|
||||
// $oPlanPending->_add($oOrder);
|
||||
$oOrder->status = "pending";
|
||||
$oOrder->_save();
|
||||
|
||||
$oPlanQueue = new PlanQueue();
|
||||
$oPlanQueue->_add($oOrder, "new");
|
||||
@ -870,14 +872,16 @@ final class Cron
|
||||
|
||||
} else { // 当前有套餐,进入pending表
|
||||
|
||||
$oPlanPending = new PlanPending();
|
||||
$oPlanPending->_add($oOrder);
|
||||
// $oPlanPending = new PlanPending();
|
||||
// $oPlanPending->_add($oOrder);
|
||||
$oOrder->status = "pending";
|
||||
$oOrder->_save();
|
||||
|
||||
self::_helper_log("订单".$oOrder->id."转为待激活状态");
|
||||
|
||||
}
|
||||
|
||||
$oOrder->delete();
|
||||
// $oOrder->delete();
|
||||
|
||||
} else if ($oOrder->create_time + 86400 < time()) {
|
||||
|
||||
@ -900,7 +904,7 @@ final class Cron
|
||||
);
|
||||
}
|
||||
|
||||
$oOrder->delete();
|
||||
// $oOrder->delete();
|
||||
|
||||
}
|
||||
|
||||
@ -969,27 +973,35 @@ final class Cron
|
||||
public static function planQueue_pendingToActivation()
|
||||
{
|
||||
self::_helper_log("pending到activation - 开始");
|
||||
$oPlanQueueList = PlanQueue::whereNull("status");
|
||||
|
||||
$oPlanQueueList = PlanQueue::whereNull("status")->get();
|
||||
// exit;
|
||||
foreach ($oPlanQueueList as $oPlanQueue) {
|
||||
|
||||
$oPlanPending = PlanPending::where("user_id", $oPlanQueue->user_id)->where("status", "!=", "fail")->orderBy("id", "ASC")->first(); // * 待激活表
|
||||
// $oPlanPending = PlanPending::where("user_id", $oPlanQueue->user_id)->where("status", "!=", "fail")->orderBy("id", "ASC")->first(); // * 待激活表
|
||||
$oPlanPending = Order::where("user_id", $oPlanQueue->user_id)
|
||||
->where("status", "pending")
|
||||
->whereNull("error_code")
|
||||
->orderBy("id", "ASC")
|
||||
->first();
|
||||
|
||||
// 没有待激活套餐时,跳过。否则都必然$oPlanQueue->_delete();
|
||||
if (!$oPlanPending) {
|
||||
continue;
|
||||
}
|
||||
// tomd($oPlanPending, 1);
|
||||
|
||||
try {
|
||||
|
||||
// 没有待激活套餐时,跳过。否则都必然$oPlanQueue->_delete();
|
||||
if (!$oPlanPending) {
|
||||
// throw new \Exception("没有待激活套餐");
|
||||
continue; // 没有待激活就直接桡过,而不是报错
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$oProduct = Product::where("code", $oPlanPending->product_code)->first(); // * 商品表
|
||||
|
||||
// 没有对应商品时
|
||||
if (!$oProduct) {
|
||||
$oPlanPending->status = "fail";
|
||||
$oPlanPending->status_str = "激活失败,该商品已从数据库存中移除,金额以退回至钱包。";
|
||||
$oPlanPending->error_code = "fail";
|
||||
$oPlanPending->error_str = "激活失败,该商品已从数据库存中移除,金额以退回至钱包。";
|
||||
|
||||
// 退回钱包
|
||||
$oUser = User::find($oPlanQueue->user_id);
|
||||
@ -1022,11 +1034,22 @@ final class Cron
|
||||
|
||||
self::_plan_to_user($oUser, $oProductContent); // 套餐赋予用户
|
||||
|
||||
//// 写日入以激活表
|
||||
$oPlanActivated = PlanActivated::where("user_id", $oPlanQueue->user_id)->orderBy("id", "ASC")->first(); // 目前已激活plan
|
||||
// 以激活表
|
||||
// $oPlanActivated = PlanActivated::where("user_id", $oPlanQueue->user_id)->orderBy("id", "ASC")->first(); // 目前已激活plan
|
||||
$oPlanActivated = Order::where("user_id", $oPlanQueue->user_id)
|
||||
->where("status", "activated")
|
||||
->orderBy("id", "ASC")
|
||||
->first();
|
||||
|
||||
self::plan_activatedToExpired($oPlanActivated); // 已激活转为过期
|
||||
self::plan_pendingToActivated($oPlanPending); // 待激活转为激活
|
||||
if ($oPlanActivated) {
|
||||
// self::plan_activatedToExpired($oPlanActivated); // 已激活转为过期
|
||||
$oPlanActivated->status = "expired";
|
||||
$oPlanActivated->_save();
|
||||
}
|
||||
|
||||
// self::plan_pendingToActivated($oPlanPending); // 待激活转为激活
|
||||
$oPlanPending->status = "activated";
|
||||
$oPlanPending->_save();
|
||||
|
||||
$oPlanQueue->_delete();
|
||||
|
||||
@ -1038,14 +1061,19 @@ final class Cron
|
||||
|
||||
DB::rollBack();
|
||||
|
||||
$oPlanPending = PlanPending::where("user_id", $oPlanQueue->user_id)->where("status", "!=", "fail")->orderBy("id", "ASC")->first();
|
||||
$oPlanPending->status = "fail";
|
||||
$oPlanPending->status_str = "套餐激活失败,请联系管理员";
|
||||
$oPlanPending->_save();
|
||||
|
||||
$oPlanQueue->status = "fail:planQueue_pendingToActivation";
|
||||
$oPlanQueue->type .= "_fail_".rand(1, 9999);
|
||||
$oPlanQueue->_save();
|
||||
|
||||
// $oPlanPending = $oPlanPending::
|
||||
// $oPlanPending = PlanPending::where("user_id", $oPlanQueue->user_id)->where("status", "!=", "fail")->orderBy("id", "ASC")->first();
|
||||
|
||||
if ($oPlanPending) {
|
||||
$oPlanPending->error_code = "error";
|
||||
$oPlanPending->error_str = "套餐激活失败,请联系管理员";
|
||||
$oPlanPending->_save();
|
||||
}
|
||||
|
||||
$sMsg = self::_helper_toJson($e->getMessage());
|
||||
|
||||
self::_helper_log($sMsg, self::_eToArr($e, $sMsg));
|
||||
@ -1061,7 +1089,7 @@ final class Cron
|
||||
{
|
||||
self::_helper_log("自动续订 - 开始");
|
||||
|
||||
$oPlanQueueList = PlanQueue::where("type", "expire")->whereNull("status");
|
||||
$oPlanQueueList = PlanQueue::where("type", "expire")->whereNull("status")->get();
|
||||
|
||||
foreach ($oPlanQueueList as $oPlanQueue) {
|
||||
|
||||
@ -1071,8 +1099,9 @@ final class Cron
|
||||
continue;
|
||||
}
|
||||
|
||||
// 检查当前套餐,正常必然有,容错
|
||||
$oPlanActivated = PlanActivated::where("user_id", $oPlanQueue->user_id)->orderBy("id", "ASC")->first(); // * 数据
|
||||
// $oPlanActivated = PlanActivated::where("user_id", $oPlanQueue->user_id)->orderBy("id", "ASC")->first(); // * 当前激活套餐
|
||||
$oPlanActivated = Order::where("user_id", $oPlanQueue->user_id)->where("status", "activated")->OrderBy("id", "ASC")->first();
|
||||
|
||||
if (!$oPlanActivated) {
|
||||
continue;
|
||||
}
|
||||
@ -1148,6 +1177,7 @@ final class Cron
|
||||
self::_helper_log($sMsg, self::_eToArr($e, $sMsg));
|
||||
|
||||
$oPlanQueue->status = "fail:planQueue_expireToBuy";
|
||||
$oPlanQueue->type .= "_fail_".rand(1, 9999);
|
||||
$oPlanQueue->_save();
|
||||
|
||||
}
|
||||
@ -1169,7 +1199,7 @@ final class Cron
|
||||
$iToExpire = date('Y-m-d H:i:s');
|
||||
$iToClass = 0;
|
||||
|
||||
$oPlanExpireQueueList = PlanQueue::where("type", "expire")->whereNull("status");
|
||||
$oPlanExpireQueueList = PlanQueue::where("type", "expire")->whereNull("status")->get();
|
||||
|
||||
foreach ($oPlanExpireQueueList as $oPlanExpireQueue)
|
||||
{
|
||||
@ -1189,9 +1219,11 @@ final class Cron
|
||||
$oUser->save();
|
||||
|
||||
//// activated转移到expired
|
||||
$oPlanActivated = PlanActivated::where("user_id", $oPlanExpireQueue->user_id)->first(); // 必然有,没有自然报错,user唯一
|
||||
|
||||
self::plan_activatedToExpired($oPlanActivated);
|
||||
// $oPlanActivated = PlanActivated::where("user_id", $oPlanExpireQueue->user_id)->first(); // 必然有,没有自然报错,user唯一
|
||||
$oPlanActivated = Order::where("user_id", $oPlanExpireQueue->user_id)->where("status", "activated") ->first();
|
||||
$oPlanActivated->status = "expired";
|
||||
$oPlanActivated->_save();
|
||||
// self::plan_activatedToExpired($oPlanActivated);
|
||||
//// end
|
||||
|
||||
//// 通知
|
||||
@ -1224,6 +1256,7 @@ final class Cron
|
||||
self::_helper_log($sMsg, self::_eToArr($e, $sMsg));
|
||||
|
||||
$oPlanExpireQueue->status = "fail:planQueue_expireDone";
|
||||
$oPlanExpireQueue->type .= "_fail_".rand(1, 9999);
|
||||
$oPlanExpireQueue->_save();
|
||||
|
||||
}
|
||||
|
||||
@ -65,9 +65,9 @@ final class Test extends Base
|
||||
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_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();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user