69 lines
1.9 KiB
PHP
69 lines
1.9 KiB
PHP
<?php
|
|
namespace App\Models\Wallet\Platform;
|
|
|
|
use App\Cache\Table\Wallet\TableWalletPlatformCache;
|
|
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;
|
|
}
|
|
|
|
function updateItem($aItem,$col = null): bool|int
|
|
{
|
|
$res = parent::updateItem($aItem,$col); // TODO: Change the autogenerated stub
|
|
if($res && isset($aItem[$this->primaryKey])) {
|
|
$this->delTableCache($aItem[$this->primaryKey]);
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
function delTableCache($key): bool
|
|
{
|
|
$oTableWalletPlatformCache = new TableWalletPlatformCache();
|
|
return $oTableWalletPlatformCache->del($key);
|
|
}
|
|
|
|
}
|