mirror of
https://github.com/kuaifan/dootask.git
synced 2026-02-27 20:30:32 +00:00
perf: 优化移交个人项目
This commit is contained in:
parent
9c72558878
commit
fd52db7f71
@ -212,6 +212,7 @@ class ProjectController extends AbstractController
|
||||
* @apiParam {String} [flow] 开启流程
|
||||
* - open: 开启
|
||||
* - close: 关闭(默认)
|
||||
* @apiParam {Number} [personal] 个人项目,注册成功时创建(仅支持创建一个个人项目)
|
||||
*
|
||||
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
||||
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||
@ -224,6 +225,7 @@ class ProjectController extends AbstractController
|
||||
$name = trim(Request::input('name', ''));
|
||||
$desc = trim(Request::input('desc', ''));
|
||||
$flow = trim(Request::input('flow', 'close'));
|
||||
$isPersonal = intval(Request::input('personal'));
|
||||
if (mb_strlen($name) < 2) {
|
||||
return Base::retError('项目名称不可以少于2个字');
|
||||
} elseif (mb_strlen($name) > 32) {
|
||||
@ -260,6 +262,12 @@ class ProjectController extends AbstractController
|
||||
'desc' => $desc,
|
||||
'userid' => $user->userid,
|
||||
]);
|
||||
if ($isPersonal) {
|
||||
if (Project::whereUserid($user->userid)->wherePersonal(1)->exists()) {
|
||||
return Base::retError('个人项目已存在,无须重复创建');
|
||||
}
|
||||
$project->personal = 1;
|
||||
}
|
||||
AbstractModel::transaction(function() use ($flow, $insertColumns, $project) {
|
||||
$project->save();
|
||||
ProjectUser::createInstance([
|
||||
|
||||
@ -18,6 +18,7 @@ use Request;
|
||||
* @property string|null $name 名称
|
||||
* @property string|null $desc 描述、备注
|
||||
* @property int|null $userid 创建人
|
||||
* @property int|null $personal 是否个人项目
|
||||
* @property int|null $dialog_id 聊天会话ID
|
||||
* @property string|null $archived_at 归档时间
|
||||
* @property int|null $archived_userid 归档会员
|
||||
@ -45,6 +46,7 @@ use Request;
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Project whereDialogId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Project whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Project whereName($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Project wherePersonal($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Project whereUpdatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Project whereUserid($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|Project withTrashed()
|
||||
|
||||
@ -61,7 +61,12 @@ class ProjectUser extends AbstractModel
|
||||
$item->save();
|
||||
}
|
||||
if ($item->project) {
|
||||
$item->project->addLog("移交项目身份", ['userid' => [$originalUserid, ' => ',$newUserid]]);
|
||||
if ($item->project->personal) {
|
||||
$name = User::userid2nickname($originalUserid) ?: ('ID:' . $originalUserid);
|
||||
$item->project->name = "【{$name}】{$item->project->name}";
|
||||
$item->project->save();
|
||||
}
|
||||
$item->project->addLog("移交项目身份", ['userid' => [$originalUserid, ' => ', $newUserid]]);
|
||||
$item->project->syncDialogUser();
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddProjectsPersonal extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$isAdd = false;
|
||||
Schema::table('projects', function (Blueprint $table) use (&$isAdd) {
|
||||
if (!Schema::hasColumn('projects', 'personal')) {
|
||||
$isAdd = true;
|
||||
$table->boolean('personal')->default(0)->after('userid')->nullable()->comment('是否个人项目');
|
||||
}
|
||||
});
|
||||
if ($isAdd) {
|
||||
// 更新数据
|
||||
\App\Models\Project::whereName('个人项目')->chunkById(100, function ($lists) {
|
||||
/** @var \App\Models\Project $item */
|
||||
foreach ($lists as $item) {
|
||||
if ($item->desc == '注册时系统自动创建项目,你可以自由删除。') {
|
||||
$item->personal = 1;
|
||||
$item->save();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('projects', function (Blueprint $table) {
|
||||
$table->dropColumn("personal");
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -466,8 +466,9 @@ export default {
|
||||
this.$store.dispatch("call", {
|
||||
url: 'project/add',
|
||||
data: {
|
||||
personal: 1,
|
||||
name: this.$L('个人项目'),
|
||||
desc: this.$L('注册时系统自动创建项目,你可以自由删除。')
|
||||
desc: this.$L('注册时系统自动创建项目,你可以自由删除。'),
|
||||
},
|
||||
}).then(() => {
|
||||
this.goNext2();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user