FastMovieAI AI短剧创作平台 二开基线
- 源码: xhadmincn/FastMovieAI (Apache 2.0) - 二开: Docker部署, Swoole改Select, route.php修复, 补update/VERSION - vendor/示例资源已gitignore
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace plugin\user\app\model;
|
||||
|
||||
use app\model\Basic;
|
||||
use plugin\control\app\model\PluginChannelsUser;
|
||||
use plugin\finance\utils\enum\BillScene;
|
||||
use plugin\user\utils\enum\MoneyAction;
|
||||
use think\facade\Db;
|
||||
|
||||
class PluginUserBill extends Basic
|
||||
{
|
||||
public function channels()
|
||||
{
|
||||
return $this->hasOne(PluginChannelsUser::class, 'id', 'channels_uid');
|
||||
}
|
||||
protected function getOptions(): array
|
||||
{
|
||||
return [
|
||||
'type' => [
|
||||
'num' => 'float',
|
||||
'before' => 'float',
|
||||
'after' => 'float',
|
||||
],
|
||||
];
|
||||
}
|
||||
public static function consume($order)
|
||||
{
|
||||
$uid = $order->uid;
|
||||
$wallet = self::where('uid', $uid)->find();
|
||||
if (!$wallet) {
|
||||
$wallet = new self();
|
||||
$wallet->uid = $uid;
|
||||
}
|
||||
if ($wallet->balance < $order->money) {
|
||||
throw new \Exception('余额不足');
|
||||
}
|
||||
PluginUserBill::create([
|
||||
'uid' => $uid,
|
||||
'form_id' => $order->id,
|
||||
'num' => $order->money,
|
||||
'before' => $wallet->balance,
|
||||
'after' => $wallet->balance - $order->money,
|
||||
'remarks' => $order->title . ' 订单号:' . $order->trade_no,
|
||||
'action' => MoneyAction::DECREASE['value'],
|
||||
'scene' => $order->type,
|
||||
]);
|
||||
$wallet->balance = Db::raw('balance - ' . $order->money);
|
||||
$wallet->balance_used = Db::raw('balance_used + ' . $order->money);
|
||||
$wallet->save();
|
||||
}
|
||||
public static function expend($uid, $money, $title)
|
||||
{
|
||||
$wallet = self::where('uid', $uid)->find();
|
||||
if (!$wallet) {
|
||||
$wallet = new self();
|
||||
$wallet->uid = $uid;
|
||||
}
|
||||
PluginUserBill::create([
|
||||
'uid' => $uid,
|
||||
'num' => $money,
|
||||
'before' => $wallet->balance,
|
||||
'after' => $wallet->balance - $money,
|
||||
'remarks' => $title,
|
||||
'action' => MoneyAction::DECREASE['value'],
|
||||
'scene' => BillScene::ADMIN['value'],
|
||||
]);
|
||||
$wallet->balance = Db::raw('balance - ' . $money);
|
||||
$wallet->balance_sum = Db::raw('balance_sum - ' . $money);
|
||||
$wallet->save();
|
||||
}
|
||||
public static function income($uid, $money, $title)
|
||||
{
|
||||
$wallet = self::where('uid', $uid)->find();
|
||||
if (!$wallet) {
|
||||
$wallet = new self();
|
||||
$wallet->uid = $uid;
|
||||
}
|
||||
PluginUserBill::create([
|
||||
'uid' => $uid,
|
||||
'num' => $money,
|
||||
'before' => $wallet->balance,
|
||||
'after' => $wallet->balance + $money,
|
||||
'remarks' => $title,
|
||||
'action' => MoneyAction::INCREASE['value'],
|
||||
'scene' => BillScene::ADMIN['value'],
|
||||
]);
|
||||
$wallet->balance = Db::raw('balance + ' . $money);
|
||||
$wallet->balance_sum = Db::raw('balance_sum + ' . $money);
|
||||
$wallet->save();
|
||||
}
|
||||
protected function sceneExternal()
|
||||
{
|
||||
return $this->visible(['id', 'create_time', 'num', 'before', 'after', 'remarks', 'action', 'scene', 'action_text', 'scene_text']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user