no message

This commit is contained in:
kuaifan 2022-03-31 09:57:03 +08:00
parent b1e35e6824
commit 9d56dd122f
2 changed files with 15 additions and 1 deletions

View File

@ -6,9 +6,10 @@ namespace App\Models;
* App\Models\FileLink * App\Models\FileLink
* *
* @property int $id * @property int $id
* @property int|null $file_id 项目ID * @property int|null $file_id 文件ID
* @property int|null $num 累计访问 * @property int|null $num 累计访问
* @property string|null $code 链接码 * @property string|null $code 链接码
* @property int|null $userid 会员ID
* @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at * @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \App\Models\File|null $file * @property-read \App\Models\File|null $file
@ -21,6 +22,7 @@ namespace App\Models;
* @method static \Illuminate\Database\Eloquent\Builder|FileLink whereId($value) * @method static \Illuminate\Database\Eloquent\Builder|FileLink whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|FileLink whereNum($value) * @method static \Illuminate\Database\Eloquent\Builder|FileLink whereNum($value)
* @method static \Illuminate\Database\Eloquent\Builder|FileLink whereUpdatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|FileLink whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|FileLink whereUserid($value)
* @mixin \Eloquent * @mixin \Eloquent
*/ */
class FileLink extends AbstractModel class FileLink extends AbstractModel

View File

@ -13,11 +13,23 @@ class AddFileLinksUserid extends Migration
*/ */
public function up() public function up()
{ {
$isAdd = false;
Schema::table('file_links', function (Blueprint $table) { Schema::table('file_links', function (Blueprint $table) {
if (!Schema::hasColumn('file_links', 'userid')) { if (!Schema::hasColumn('file_links', 'userid')) {
$isAdd = true;
$table->integer('userid')->nullable()->default(0)->after('code')->comment('会员ID'); $table->integer('userid')->nullable()->default(0)->after('code')->comment('会员ID');
} }
}); });
if ($isAdd) {
// 更新数据
\App\Models\FileLink::chunkById(100, function ($lists) {
/** @var \App\Models\FileLink $item */
foreach ($lists as $item) {
$item->userid = intval(\App\Models\File::whereId($item->file_id)->value('userid'));
$item->save();
}
});
}
} }
/** /**