admin/business/common/models/PlatLog.php

63 lines
1.3 KiB
PHP

<?php
/**
* Created by PhpStorm.
*
*
*
* Date: 2021/9/22
* Time: 13:37
*/
namespace business\common\models;
use app\common\models\BaseModel;
use business\common\services\BusinessService;
use Illuminate\Database\Eloquent\Builder;
class PlatLog extends BaseModel
{
public $table = 'yz_business_plat_log';
public $timestamps = true;
protected $guarded = [];
protected $appends = [];
protected $casts = [];
public function getPlatLogId($uid = 0)
{
$res = self::getPlatLog($uid);
return $res->final_plat_id ?: 0;
}
public function getPlatLog($uid = 0)
{
if ($uid = $uid ?: \YunShop::app()->getMemberId()) {
$model = self::where('uid', $uid)->first();
if ($model && $model->final_plat_id) {
$res = BusinessService::checkBusinessRight($model->final_plat_id, $uid);
if (!$res['identity']) {
$model->final_plat_id = 0;
$model->save();
}
}
if (!$model) {
$model = self::create([
'uniacid' => \YunShop::app()->uniacid,
'uid' => $uid,
'final_plat_id' => 0
]);
}
} else {
$model = (Object)[];
}
return $model;
}
}