Commit fbd67fa1 by mushishixian

数据处理

parent 098ccbcd
...@@ -124,9 +124,17 @@ class SupplierFilter ...@@ -124,9 +124,17 @@ class SupplierFilter
$inCodeIdSql = "(" . $inCodeIdSql . ")"; $inCodeIdSql = "(" . $inCodeIdSql . ")";
$inUserIdSql = "(" . $inUserIdSql . ")"; $inUserIdSql = "(" . $inUserIdSql . ")";
if ($subordinateCodeIds) { if ($subordinateCodeIds) {
$query->whereRaw(DB::raw("(create_uid in $inUserIdSql or purchase_uid in $inCodeIdSql or channel_uid REGEXP '$likeSqlRaw' or is_type = 1) ")); if ($canViewFakeSupplier) {
$query->whereRaw(DB::raw("(create_uid in $inUserIdSql or purchase_uid in $inCodeIdSql or channel_uid REGEXP '$likeSqlRaw' or is_type = 1) "));
} else {
$query->whereRaw(DB::raw("(create_uid in $inUserIdSql or purchase_uid in $inCodeIdSql or channel_uid REGEXP '$likeSqlRaw') "));
}
} else { } else {
$query->whereRaw(DB::raw("(create_uid in $inUserIdSql or is_type = 1)")); if ($canViewFakeSupplier) {
$query->whereRaw(DB::raw("(create_uid in $inUserIdSql or is_type = 1)"));
} else {
$query->whereRaw(DB::raw("(create_uid in $inUserIdSql)"));
}
} }
} else { } else {
......
...@@ -4,26 +4,131 @@ ...@@ -4,26 +4,131 @@
namespace App\Http\Services; namespace App\Http\Services;
//后台用户相关信息服务 //后台用户相关信息服务
use App\Model\IntracodeModel;
use App\Model\SupplierChannelModel; use App\Model\SupplierChannelModel;
use App\Model\SupplierContactModel;
use App\Model\UserInfoModel;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
class DataService class DataService
{ {
//清除不合理的开发员 //修复数据
public function clearPurchaseUid() public function repairData($limit = 0)
{ {
//先找出和无效采购员(离职或者不是采购员)相关的供应商
//写死
$invalidChannelUserName = [
"葛金菊",
"姜喆",
"罗晓民",
"周亚琳",
"左佳晨",
"陈泽彬",
"李跃",
"赵佩旋",
"朱国军",
"许金荣",
"余佳兰",
"李晶晶",
"朱玉嘉"
];
//找出对应的code_id
$userModel = new UserInfoModel();
$invalidChannelUserIds = $userModel->whereIn('name', $invalidChannelUserName)->pluck('userId');
//找出对应的codeId
$adminUserService = new AdminUserService();
$codeIds = $adminUserService->getCodeIdsByUserIds($invalidChannelUserIds);
$codeIds = $codeIds->toArray();
$likeSqlRaw = implode('|', $codeIds);
$model = new SupplierChannelModel(); $model = new SupplierChannelModel();
$suppliers = $model->where('purchase_uid', '!=', '')->where('is_type', 0)->get(); //根据code_id去找供应商表里面找到包含该code_id的供应商
$validPurchaseUserIds = [10039, 10201, 10177]; if (!empty($limit)) {
$suppliers = $model->whereRaw("channel_uid REGEXP '$likeSqlRaw'")->where('is_type',
0)->limit($limit)->get();
} else {
$suppliers = $model->whereRaw("channel_uid REGEXP '$likeSqlRaw'")->where('is_type', 0)->get();
}
if ($suppliers) {
$suppliers = $suppliers->toArray();
} else {
echo "已经处理完";
die;
}
$i = 0;
foreach ($suppliers as $supplier) { foreach ($suppliers as $supplier) {
//如果不是开发员id不属于上面的有效id,就清空 $channelUidResult = [];
if (!in_array($supplier['purchase_uid'], $validPurchaseUserIds)) { $channelUid = explode(',', $supplier['channel_uid']);
$model->where('supplier_id', $supplier['supplier_id'])->update(['purchase_uid' => '']); foreach ($channelUid as $key => $uid) {
var_dump($supplier['purchase_uid']); //如果不属于不合理采购员codeId,则保留
} else { if (!in_array($uid, $codeIds)) {
// var_dump($supplier['purchase_uid']); $channelUidResult[] = $uid;
}
}
$channelUidResult = implode(',', $channelUidResult);
$content = "采购员从" . implode(',', $channelUid) . '修改到' . $channelUidResult;
//写日志
$remark = implode(',', $channelUid) . "|" . $channelUidResult;
$logService = new LogService();
$logService->AddLog($supplier['supplier_id'], 1, "系统修改采购员", $content, $remark);
$model->where('supplier_id', $supplier['supplier_id'])->update([
'channel_uid' => $channelUidResult,
]);
$i++;
if (!empty($limit)) {
print_r($supplier['supplier_id'] . "<br>");
}
}
echo "修改了${i}条记录";
die;
}
//补全联系人
public function completeContact($limit = 0)
{
$i = 0;
//先找出联系人和采购员数量对不上的记录;
$model = new SupplierChannelModel();
if (!empty($limit)) {
$suppliers = $model->where('is_type', 0)->limit($limit)->get()->toArray();
} else {
$suppliers = $model->where('is_type', 0)->get()->toArray();
}
$contactModel = new SupplierContactModel();
foreach ($suppliers as $supplier) {
//找出联系人数量
if (empty($supplier['channel_uid'])) {
continue;
}
$contactCount = $contactModel->where('supplier_id', $supplier['supplier_id'])->where('can_check_uids', '!=',
'')->count();
$channelUidCount = count(explode(',', $supplier['channel_uid']));
if ($contactCount >= $channelUidCount) {
continue;
}
//直接根据采购员id
// $needAppendCount = $channelUidCount - $count;
// $countArray = array_fill(0, $needAppendCount, 1);
$countArray = array_fill(0, $channelUidCount, 1);
//补的时候,记得把采购员id写进去
$channelUids = explode(',', $supplier['channel_uid']);
foreach ($countArray as $key => $value) {
$channelUserId = $channelUids[$key];
$data = [
'supplier_id' => $supplier['supplier_id'],
'can_check_uids' => $channelUserId,
'add_time' => time(),
'admin_id' => 1000,
];
$contactModel->insert($data);
}
$i++;
if (!empty($limit)) {
print_r($supplier['supplier_id'] . "<br>");
} }
// dd($supplier['supplier_id']);
} }
echo "已经处理" . $i . "家供应商的联系方式";
} }
//导出不合理的采购员的供应商 //导出不合理的采购员的供应商
...@@ -42,7 +147,11 @@ class DataService ...@@ -42,7 +147,11 @@ class DataService
$names[] = $name; $names[] = $name;
} }
$names = implode('|', $names); $names = implode('|', $names);
$result[] = ['name' => '"'.$item['supplier_name'].'"', 'value' => $names,'code'=>$item['supplier_code']]; $result[] = [
'name' => '"' . $item['supplier_name'] . '"',
'value' => $names,
'code' => $item['supplier_code']
];
} }
// 需要导出的内容 // 需要导出的内容
......
...@@ -42,5 +42,6 @@ Route::group(['middleware' => ['web'], 'namespace' => 'Api'], function () { ...@@ -42,5 +42,6 @@ Route::group(['middleware' => ['web'], 'namespace' => 'Api'], function () {
}); });
Route::match(['get', 'post'], '/test', function () { Route::match(['get', 'post'], '/test', function () {
$service = new \App\Http\Services\DataService(); $service = new \App\Http\Services\DataService();
$service->exportNotValidChannelUid(); $service->repairData(10);
// $service->completeContact(10);
}); });
...@@ -238,7 +238,7 @@ ...@@ -238,7 +238,7 @@
//执行重载 //执行重载
table.reload('list', { table.reload('list', {
page: { page: {
curr: 1 curr: currentPage
} }
, where: whereCondition , where: whereCondition
}); });
......
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