Commit 7c76d512 by 杨树贤

标签批量修改接口

parent 901b7554
......@@ -656,21 +656,4 @@ class SupplierApiController extends Controller
$this->response(0, '申请审核成功');
}
//批量新增标签
public function BatchAddTags($request)
{
$supplierIds = $request->get('supplier_ids');
$systemTags = $request->get('system_tags');
$customTags = $request->get('custom_tags');
$supplierIds = $supplierIds ? explode(',', $supplierIds) : [];
$systemTags = $systemTags ? explode(',', $systemTags) : [];
$customTags = $customTags ? explode(',', $customTags) : [];
$supplierService = new SupplierService();
if (empty($systemTags) && empty($customTags)) {
$this->response(-1, '请设置标签');
}
$supplierService->batchAddTags($supplierIds, $systemTags, $customTags);
$this->response(0, '批量新增标签成功');
}
}
......@@ -3,6 +3,7 @@
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Services\SupplierService;
use App\Http\Services\SupplierTagService;
use App\Http\Transformers\SupplierLogTransformer;
use App\Model\LogModel;
......@@ -25,4 +26,21 @@ class SupplierTagApiController extends Controller
$data = $supplierTagService->getSystemTags();
$this->response(0, 'ok', $data, count($data));
}
//批量新增标签
public function BatchAddTags($request)
{
$supplierIds = $request->get('supplier_ids');
$systemTags = $request->get('system_tags');
$customTags = $request->get('customer_tags');
$supplierIds = $supplierIds ? explode(',', $supplierIds) : [];
$systemTags = $systemTags ? explode(',', $systemTags) : [];
$customTags = $customTags ? explode(',', $customTags) : [];
$supplierTagService = new SupplierTagService();
if (empty($systemTags) && empty($customTags)) {
$this->response(-1, '请设置标签');
}
$supplierTagService->batchAddTags($supplierIds, $systemTags, $customTags);
$this->response(0, '批量新增标签成功');
}
}
......@@ -126,9 +126,16 @@ class SupplierTagService
{
$suppliers = SupplierChannelModel::whereIn('supplier_id', $supplierIds)->get()->toArray();
foreach ($suppliers as $supplier) {
$systemTags = $supplier['system_tags'] ? explode(',', $supplier['system_tags']) : [];
$customTags = $supplier['custom_tags'] ? explode(',', $supplier['custom_tags']) : [];
$oldSystemTags = $supplier['system_tags'] ? explode(',', $supplier['system_tags']) : [];
$oldCustomTags = $supplier['customer_tags'] ? explode(',', $supplier['customer_tags']) : [];
$newSystemTags = array_merge($oldSystemTags, $addSysTags);
$newCustomTags = array_merge($oldCustomTags, $addCusTags);
$this->saveTags($supplier['supplier_id'], self::TAG_TYPE_SYSTEM, $newSystemTags, $oldSystemTags);
$this->saveTags($supplier['supplier_id'], self::TAG_TYPE_CUSTOMER, $newCustomTags, $oldCustomTags);
SupplierChannelModel::where('supplier_id', $supplier['supplier_id'])->update([
'system_tags' => $newSystemTags,
'customer_tags' => $newCustomTags
]);
}
}
}
\ No newline at end of file
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