12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace App\Distributor\Repositories;
- use App\Models\SmmUserAccount as Model;
- use Carbon\Carbon;
- use Dcat\Admin\Repositories\EloquentRepository;
- class SmmUserAccount extends EloquentRepository
- {
- /**
- * Model.
- *
- * @var string
- */
- protected $eloquentClass = Model::class;
- /**
- * 插入新的社媒账号(仅在找到对应社媒时插入)
- *
- * @param string $mediaName 要查找的社媒名称
- * @param string $accountName 要插入的账号名称
- * @param string $accessToken 访问令牌
- * @return Model|null 新创建的模型实例或null
- */
- public static function createAccountIfMediaExists($mediaName, $accountId,$accountName, $accessToken)
- {
- $model = new Model();
- // 查找匹配的社媒记录
- $mediaRecord = $model->where('title', $mediaName)->first();
- if (!$mediaRecord) {
- return null;
- }
- // 创建新账号并关联父级
- $data = [
- 'account_id' => $accountId,
- 'title' => $accountName,
- 'access_token' => $accessToken,
- 'parent_id' => $mediaRecord->id,
- 'created_at' => Carbon::now(), // 自动生成时间戳
- 'updated_at' => Carbon::now(),
- ];
- return $model->insert($data);
- }
- }
|