no message
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\user\User;
|
||||
use app\common\model\vip\VipLevel;
|
||||
use app\common\model\vip\VipOrder;
|
||||
|
||||
class VipOrderLogic extends BaseLogic
|
||||
{
|
||||
public static function levels(): array
|
||||
{
|
||||
return VipLevel::where('status', 1)
|
||||
->order('sort', 'desc')
|
||||
->order('id', 'asc')
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
public static function createOrder(array $params)
|
||||
{
|
||||
try {
|
||||
$level = VipLevel::where(['id' => $params['level_id'], 'status' => 1])->findOrEmpty();
|
||||
if ($level->isEmpty()) {
|
||||
throw new \Exception('VIP套餐不存在或已下架');
|
||||
}
|
||||
|
||||
// 有效期内不能重复购买同一等级
|
||||
$user = User::findOrEmpty($params['user_id']);
|
||||
if ($user->is_vip == 1 && $user->vip_expire_time > time() && $user->vip_level == $level['level']) {
|
||||
throw new \Exception('您当前已是' . $level['name'] . ',有效期内无需重复购买');
|
||||
}
|
||||
|
||||
$order = VipOrder::create([
|
||||
'sn' => generate_sn(VipOrder::class, 'sn'),
|
||||
'user_id' => $params['user_id'],
|
||||
'level_id' => $level['id'],
|
||||
'level_name' => $level['name'],
|
||||
'duration' => $level['duration'],
|
||||
'order_amount' => $level['price'],
|
||||
'pay_status' => PayEnum::UNPAID,
|
||||
'order_terminal' => $params['terminal'],
|
||||
]);
|
||||
return [
|
||||
'order_id' => (int) $order['id'],
|
||||
'from' => 'vip_order'
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function detail(array $params)
|
||||
{
|
||||
try {
|
||||
$order = VipOrder::where(['id' => $params['order_id'], 'user_id' => $params['user_id']])
|
||||
->append(['pay_status_text', 'pay_way_text'])
|
||||
->findOrEmpty();
|
||||
if ($order->isEmpty()) {
|
||||
throw new \Exception('订单不存在');
|
||||
}
|
||||
$data = $order->toArray();
|
||||
$data['pay_time'] = empty($data['pay_time']) ? '' : date('Y-m-d H:i:s', $data['pay_time']);
|
||||
return $data;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user