老数据副表

This commit is contained in:
2025-12-22 16:01:11 +08:00
parent 079a945e93
commit 90218d8ae3
3 changed files with 113 additions and 39 deletions
+49
View File
@@ -0,0 +1,49 @@
<?php
namespace app\common\model;
use support\Model;
class PostOld extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'post_old';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = true;
protected $dateFormat = 'U';
/**
* 允许自动填充模型字段
*/
protected $fillable = ['id', 'user_id', 'category_id', 'sku_id', 'content', 'shop_name', 'location_name', 'latitude', 'longitude', 'geo', 'status', 'sort', 'like', 'favorite', 'comment', 'is_free', 'model', 'browse', 'created_at', 'updated_at', 'price', 'age'];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
}
+24
View File
@@ -3,6 +3,8 @@
namespace app\common\service;
use app\common\logic\AuthLogic;
use app\common\model\Post;
use app\common\model\PostOld;
use app\common\model\UserOld;
use app\common\validate\UserValidate;
use app\common\traits\crud\CrudServiceTrait;
@@ -300,6 +302,28 @@ class UserService
$uinfo->mobile = $mobile;
$uinfo->save();
$postOld = PostOld::where('mobile', $mobile)->get();
if (!empty($postOld)) {
foreach ($postOld as $item) {
$post = [
"id" => $item->id,
"user_id" => $uinfo->id,
"category_id" => $item->id,
"sku_id" => $item->sku_id,
"content" => $item->content,
"shop_name" => $item->shop_name,
"location_name" => $item->location_name,
"status" => 1,
"is_free" => $item->is_free,
"model" => $item->model,
"browse" => $item->browse,
"price" => $item->price,
"age" => $item->age,
];
Post::firstOrCreate($post);
}
}
return $wxinfo;
}