Files
cycle_api/app/Models/Wallet/Platform/WalletPlatformModel.php
2024-03-08 00:58:23 +08:00

59 lines
1.5 KiB
PHP

<?php
namespace App\Models\Wallet\Platform;
use App\Exceptions\ModelException;
use App\Models\Wallet\Base\WalletBaseModel;
use App\Tools\Times;
use App\Tools\Tools;
use Illuminate\Support\Facades\DB;
class WalletPlatformModel extends WalletBaseModel
{
protected $table = 'wallet_platform';
protected $primaryKey = 'id';
protected $fillable = [
'id',
'name',
'code',
'appid',
'secret',
'notify_ip',
'created_at',
];
const CODE_CYCLE = 'CYCLE';
function addPlatform(string $name, string $code): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|bool
{
$insert = [
'name' => $name,
'code' => $code,
'created_at' => Times::getNowDateTime(),
];
try {
Db::beginTransaction();
$resModel = $this->addItem($insert);
if(!$resModel) throw new ModelException('添加失败');
$appid_key = $resModel->id . $resModel->name . $resModel->code;
$resModel->appid = Tools::getMd5($appid_key);
$resModel->secret = Tools::generateRandStr(32);
$res = $resModel->save();
if(!$res) throw new ModelException('添加appid失败');
Db::commit();
}catch (\Exception $e) {
Db::rollBack();
throw $e;
}
return $resModel;
}
//@@给平台下发用户信息
static function userTransactionNotifyToPlatform($user_transaction_id)
{
}
}