Commit 9c3f5fab by 宁成龙

完善转让和指派

parent 9b4543c1
......@@ -54,20 +54,6 @@ JS;
return parent::html(); // TODO: Change the autogenerated stub
}
// 处理请求
public function handle(Request $request)
{
// 获取选中的文章ID数组
$keys = $this->getKey();
// 获取请求参数
$action = $request->get('action');
$message = $action ? '文章发布成功' : '文章下线成功';
return $this->response()->success($message)->refresh();
}
// 设置请求参数
public function parameters()
{
......
......@@ -4,6 +4,7 @@ namespace App\Admin\Actions\User;
use App\Admin\Forms\User\AssignUserHandle;
use App\Admin\Forms\User\TransferUserHandle;
use App\Models\Order as OrderModel;
use App\Models\User;
use Dcat\Admin\Grid\BatchAction;
......@@ -27,7 +28,7 @@ class UserTransferAction extends BatchAction
public function render()
{
$form = AssignUserHandle::make();
$form = TransferUserHandle::make();
$buttonName = trans('user.labels.transfer');
return Modal::make()->lg()->title($this->title)->body($form->payload([]))->onLoad($this->getModalScript())->button('<button class="btn btn-primary">
<i class="feather icon-check-circle"></i><span class="d-none d-sm-inline" style="margin-left: 5px">' . $buttonName . '</span>
......
......@@ -2,6 +2,7 @@
namespace App\Admin\Forms\User;
use App\Admin\Service\UserService;
use App\Models\Cms\CmsUser;
use App\Models\Inquiry;
use App\Models\User;
......@@ -24,12 +25,7 @@ class AssignUserHandle extends Form implements LazyRenderable
{
try {
$ids = explode(",", $input['id']);
// $userList = User::getListByIdArr($ids);
$cmsUser = CmsUser::getInfoByUserId($input['sale_id']);
if (!$cmsUser) {
throw new \Exception('销售不存在');
}
User::updateByIdArr($ids, ['sale_id' => $input['sale_id'], "sale_name" => $cmsUser['name']]);
UserService::transferUser($ids, $input['sale_id']);
return $this
->response()
->success(trans('admin.update_succeeded'))
......
<?php
namespace App\Admin\Forms\User;
use App\Admin\Service\UserService;
use App\Models\Cms\CmsUser;
use App\Models\Inquiry;
use App\Models\User;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
class TransferUserHandle extends Form implements LazyRenderable
{
use LazyWidget;
/**
* Handle the form request.
*
* @param array $input
*
* @return mixed
*/
public function handle(array $input)
{
try {
$ids = explode(",", $input['id']);
UserService::transferUser($ids, $input['sale_id']);
return $this
->response()
->success(trans('admin.update_succeeded'))
->refresh();
} catch (\Throwable $throwable) {
// var_dump((string)$throwable);
return $this->response()->error(trans('admin.update_failed'));
}
}
/**
* Build a form here.
*/
public function form()
{
$this->disableResetButton();
$this->hidden('id')->attribute('id', 'id');
$this->select('sale_id')->options(CmsUser::pluck('name', 'userId')->toArray())->default(0)->required();
}
/**
* The data of the form.
*
* @return array
*/
public function default()
{
return [
];
}
}
......@@ -73,7 +73,6 @@ class AutoAssignCustomerService
$updateData = [
'max_num' => count($userList),
];
var_dump($updateData);
\App\Models\AutoAssignCustomer::updateById($assign['id'], $updateData);
}
}
......
......@@ -161,4 +161,30 @@ class UserService
throw $throwable;
}
}
public static function transferUser($ids, $saleId)
{
try {
DB::beginTransaction();
$saleInfo = CmsUser::getInfoByUserId($saleId);
if (empty($saleInfo)) {
throw new \Exception("saleId is not exist");
}
//更新客户的数据
$userList = User::getListByIdArr($ids);
$userIds = array_column($userList, "id");
$update = [
"sale_id" => $saleId,
"sale_name" => $saleInfo["name"],
];
User::updateByIdArr($userIds, $update);
DB::commit();
} catch (\Throwable $throwable) {
DB::rollBack();
throw $throwable;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment