工作台 - 通讯录导入功能

This commit is contained in:
wong
2025-09-10 11:43:47 +08:00
parent 2c7d90e49d
commit 4385995742
6 changed files with 213 additions and 9 deletions

View File

@@ -7,6 +7,7 @@ use app\common\model\DeviceWechatLogin as DeviceWechatLoginModel;
use app\common\model\WechatCustomer as WechatCustomerModel;
use app\cunkebao\model\Workbench;
use app\cunkebao\model\WorkbenchAutoLike;
use app\cunkebao\model\WorkbenchImportContact;
use app\cunkebao\model\WorkbenchMomentsSync;
use app\cunkebao\model\WorkbenchGroupPush;
use app\cunkebao\model\WorkbenchGroupCreate;
@@ -30,6 +31,7 @@ class WorkbenchController extends Controller
const TYPE_GROUP_PUSH = 3; // 群消息推送
const TYPE_GROUP_CREATE = 4; // 自动建群
const TYPE_TRAFFIC_DISTRIBUTION = 5; // 流量分发
const TYPE_IMPORT_CONTACT = 6; // 联系人导入
/**
* 创建工作台
@@ -153,6 +155,19 @@ class WorkbenchController extends Controller
$config->updateTime = time();
$config->save();
break;
case self::TYPE_IMPORT_CONTACT: //联系人导入
$config = new WorkbenchImportContact;
$config->workbenchId = $workbench->id;
$config->devices = json_encode($param['deveiceGroups'], JSON_UNESCAPED_UNICODE);
$config->pools = json_encode($param['pools'], JSON_UNESCAPED_UNICODE);
$config->num = $param['num'];
$config->clearContact = $param['clearContact'];
$config->remark = $param['remark'];
$config->startTime = $param['startTime'];
$config->endTime = $param['endTime'];
$config->createTime = time();
$config->save();
break;
}
Db::commit();
@@ -206,6 +221,9 @@ class WorkbenchController extends Controller
'groupCreate' => function($query) {
$query->field('workbenchId,devices,startTime,endTime,groupSizeMin,groupSizeMax,maxGroupsPerDay,groupNameTemplate,groupDescription,poolGroups,wechatGroups');
},
'importContact' => function($query) {
$query->field('workbenchId,devices,pools,num,remarkType,remark,clearContact,startTime,endTime');
},
'user' => function ($query) {
$query->field('id,username');
}
@@ -321,21 +339,15 @@ class WorkbenchController extends Controller
}
$totalUsers = $totalUsers->count();
$totalAccounts = count($item->config->account);
$dailyAverage = Db::name('workbench_traffic_config_item')
->where('workbenchId', $item->id)
->count();
$day = (time() - strtotime($item->createTime)) / 86400;
$day = intval($day);
if ($dailyAverage > 0 && $totalAccounts > 0 && $day > 0) {
$dailyAverage = $dailyAverage / $totalAccounts / $day;
}
$item->config->total = [
'dailyAverage' => intval($dailyAverage),
'totalAccounts' => $totalAccounts,
@@ -346,6 +358,15 @@ class WorkbenchController extends Controller
}
unset($item->trafficConfig, $item->traffic_config);
break;
case self::TYPE_IMPORT_CONTACT:
if (!empty($item->importContact)) {
$item->config = $item->importContact;
$item->config->devices = json_decode($item->config->devices, true);
$item->config->pools = json_decode($item->config->pools, true);
}
unset($item->importContact, $item->import_contact);
break;
}
// 添加创建人名称
$item['creatorName'] = $item->user ? $item->user->username : '';
@@ -396,7 +417,10 @@ class WorkbenchController extends Controller
},
'groupCreate' => function($query) {
$query->field('workbenchId,devices,startTime,endTime,groupSizeMin,groupSizeMax,maxGroupsPerDay,groupNameTemplate,groupDescription,poolGroups,wechatGroups');
}
},
'importContact' => function($query) {
$query->field('workbenchId,devices,pools,num,remarkType,remark,clearContact,startTime,endTime');
},
];
$workbench = Workbench::where([
['id', '=', $id],
@@ -531,6 +555,14 @@ class WorkbenchController extends Controller
unset($workbench->trafficConfig, $workbench->traffic_config);
}
break;
case self::TYPE_IMPORT_CONTACT:
if (!empty($item->importContact)) {
$item->config = $item->importContact;
$item->config->devices = json_decode($item->config->devices, true);
$item->config->pools = json_decode($item->config->pools, true);
}
unset($item->importContact, $item->import_contact);
break;
}
unset(
$workbench->autoLike,
@@ -763,6 +795,19 @@ class WorkbenchController extends Controller
$config->save();
}
break;
case self::TYPE_IMPORT_CONTACT: //联系人导入
$config = WorkbenchImportContact::where('workbenchId', $param['id'])->find();;
if ($config) {
$config->devices = json_encode($param['deveiceGroups']);
$config->pools = json_encode($param['pools']);
$config->num = $param['num'];
$config->clearContact = $param['clearContact'];
$config->remark = $param['remark'];
$config->startTime = $param['startTime'];
$config->endTime = $param['endTime'];
$config->save();
}
break;
}
Db::commit();
@@ -945,6 +990,21 @@ class WorkbenchController extends Controller
$newConfig->save();
}
break;
case self::TYPE_IMPORT_CONTACT: //联系人导入
$config = WorkbenchImportContact::where('workbenchId',$id)->find();;
if ($config) {
$newConfig = new WorkbenchImportContact;
$newConfig->devices = json_encode($config->deveiceGroups);
$newConfig->pools = json_encode($config->pools);
$newConfig->num = $config->num;
$newConfig->clearContact = $config->clearContact;
$newConfig->remark = $config->remark;
$newConfig->startTime = $config->startTime;
$newConfig->endTime = $config->endTime;
$newConfig->createTime = time();
$newConfig->save();
}
break;
}
Db::commit();