门店端适配新表 及操盘手端工作台优化
This commit is contained in:
@@ -20,9 +20,9 @@ Route::group('v1', function () {
|
||||
// Device控制器路由
|
||||
Route::group('device', function () {
|
||||
Route::get('list', 'app\\api\\controller\\DeviceController@getList'); // 获取设备列表 √
|
||||
//Route::get('add/:accountId', 'app\\api\\controller\\DeviceController@addDevice'); // 生成设备二维码
|
||||
Route::post('add', 'app\\api\\controller\\DeviceController@addDevice'); // 生成设备二维码(POST方式) √
|
||||
Route::post('updateDeviceGroup', 'app\\api\\controller\\DeviceController@updateDeviceGroup'); // 更新设备分组 √
|
||||
Route::post('updateaccount', 'app\\api\\controller\\DeviceController@updateaccount'); // 更新设备账号 √
|
||||
Route::post('createGroup', 'app\\api\\controller\\DeviceController@createGroup'); // 创建设备分组 √
|
||||
Route::get('groupList', 'app\\api\\controller\\DeviceController@getGroupList'); // 获取设备分组列表 √
|
||||
});
|
||||
|
||||
@@ -212,6 +212,55 @@ class DeviceController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新设备分组
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function updateaccount()
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
return errorJson('缺少授权信息');
|
||||
}
|
||||
|
||||
try {
|
||||
// 获取参数
|
||||
$id = $this->request->param('id', '');
|
||||
$accountId = $this->request->param('accountId', '');
|
||||
|
||||
if (empty($id)) {
|
||||
return errorJson('设备ID不能为空');
|
||||
}
|
||||
|
||||
if (empty($accountId)) {
|
||||
return errorJson('账号id不能为空');
|
||||
}
|
||||
|
||||
// 设置请求头
|
||||
$headerData = ['client:system'];
|
||||
$header = setHeader($headerData, $authorization, 'plain');
|
||||
|
||||
// 发送请求
|
||||
$result = requestCurl($this->baseUrl . 'api/device/updateaccount?accountId=' . $accountId . '&deviceId=' . $id, [], 'PUT', $header);
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
|
||||
if(empty($response)){
|
||||
return successJson([],'操作成功');
|
||||
}else{
|
||||
return errorJson([],$response);
|
||||
}
|
||||
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return errorJson('更新设备分组失败:' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备分组列表
|
||||
* @return \think\response\Json
|
||||
|
||||
@@ -3,17 +3,22 @@
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\model\WechatAccountModel;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 微信账号管理控制器
|
||||
*/
|
||||
class WechatController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取微信账号列表
|
||||
* 获取微信账号列表(主方法)
|
||||
*
|
||||
* @param string $pageIndex 页码
|
||||
* @param string $pageSize 每页大小
|
||||
* @param bool $isJob 是否为任务调用
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getlist($pageIndex = '', $pageSize = '', $isJob = false)
|
||||
public function getList($pageIndex = '', $pageSize = '', $isJob = false)
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
@@ -43,17 +48,20 @@ class WechatController extends BaseController
|
||||
$headerData = ['client:system'];
|
||||
$header = setHeader($headerData, $authorization, 'plain');
|
||||
|
||||
// 发送请求
|
||||
// 发送请求获取基本信息
|
||||
$result = requestCurl($this->baseUrl . 'api/WechatAccount/list', $params, 'GET', $header);
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
// 保存数据到数据库
|
||||
// 保存基本数据到数据库
|
||||
if (!empty($response['results'])) {
|
||||
foreach ($response['results'] as $item) {
|
||||
$this->saveWechatAccount($item);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取并更新微信账号状态信息
|
||||
$this->getListTenantWechatPartial($authorization);
|
||||
|
||||
if ($isJob) {
|
||||
return json_encode(['code' => 200, 'msg' => '获取微信账号列表成功', 'data' => $response]);
|
||||
} else {
|
||||
@@ -69,54 +77,178 @@ class WechatController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存微信账号数据到数据库
|
||||
* 获取微信账号状态信息
|
||||
*
|
||||
* @param string $authorization 授权token
|
||||
* @return \think\response\Json|void
|
||||
*/
|
||||
public function getListTenantWechatPartial($authorization = '')
|
||||
{
|
||||
// 获取授权token(如果未传入)
|
||||
if (empty($authorization)) {
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
return errorJson('缺少授权信息');
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// 从数据库获取微信账号和设备信息
|
||||
$wechatList = Db::table('s2_wechat_account')
|
||||
->where('isDeleted', 0)
|
||||
->select();
|
||||
|
||||
if (empty($wechatList)) {
|
||||
if (empty($authorization)) { // 只有作为独立API调用时才返回
|
||||
return json(['code' => 200, 'msg' => '获取成功', 'data' => []]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 构造请求参数
|
||||
$wechatAccountIds = [];
|
||||
$deviceIds = [];
|
||||
$accountIds = [];
|
||||
|
||||
foreach ($wechatList as $item) {
|
||||
$wechatAccountIds[] = $item['id'];
|
||||
$deviceIds[] = $item['currentDeviceId'] ?: 0;
|
||||
$accountIds[] = $item['deviceAccountId'] ?: 0;
|
||||
}
|
||||
|
||||
// 设置请求头
|
||||
$headerData = ['client:system'];
|
||||
$header = setHeader($headerData, $authorization, 'plain');
|
||||
|
||||
$params = [
|
||||
'wechatAccountIdsStr' => json_encode($wechatAccountIds),
|
||||
'deviceIdsStr' => json_encode($deviceIds),
|
||||
'accountIdsStr' => json_encode($accountIds),
|
||||
'groupId' => ''
|
||||
];
|
||||
|
||||
// 发送请求获取状态信息
|
||||
$result = requestCurl($this->baseUrl . 'api/WechatAccount/listTenantWechatPartial', $params, 'GET', $header);
|
||||
$response = handleApiResponse($result);
|
||||
|
||||
// 如果请求成功并返回数据,则更新数据库
|
||||
if (!empty($response)) {
|
||||
$this->batchUpdateWechatAccounts($response);
|
||||
}
|
||||
|
||||
// 只有作为独立API调用时才返回
|
||||
if (empty($authorization)) {
|
||||
// 返回更新后的数据
|
||||
$updatedWechatList = Db::table('s2_wechat_account')
|
||||
->where('isDeleted', 0)
|
||||
->select();
|
||||
return json(['code' => 200, 'msg' => '获取成功', 'data' => $updatedWechatList]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
if (empty($authorization)) { // 只有作为独立API调用时才返回
|
||||
return json(['code' => 500, 'msg' => '获取失败:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新微信账号数据
|
||||
*
|
||||
* @param array $data 接口返回的数据
|
||||
*/
|
||||
private function batchUpdateWechatAccounts($data)
|
||||
{
|
||||
// 更新微信账号信息
|
||||
if (!empty($data['totalFriend'])) {
|
||||
// 遍历所有微信账号ID
|
||||
$wechatIds = array_keys($data['totalFriend']);
|
||||
foreach ($wechatIds as $wechatId) {
|
||||
// 构建更新数据
|
||||
$updateData = [
|
||||
'maleFriend' => $data['maleFriend'][$wechatId] ?? 0,
|
||||
'femaleFriend' => $data['femaleFriend'][$wechatId] ?? 0,
|
||||
'unknowFriend' => $data['unknowFriend'][$wechatId] ?? 0,
|
||||
'totalFriend' => $data['totalFriend'][$wechatId] ?? 0,
|
||||
'yesterdayMsgCount' => $data['yesterdayMsgCount'][$wechatId] ?? 0,
|
||||
'sevenDayMsgCount' => $data['sevenDayMsgCount'][$wechatId] ?? 0,
|
||||
'thirtyDayMsgCount' => $data['thirtyDayMsgCount'][$wechatId] ?? 0,
|
||||
'wechatAlive' => isset($data['wechatAlive'][$wechatId]) ? (int)$data['wechatAlive'][$wechatId] : 0,
|
||||
'updateTime' => time()
|
||||
];
|
||||
|
||||
// 更新数据库
|
||||
Db::table('s2_wechat_account')
|
||||
->where('id', $wechatId)
|
||||
->update($updateData);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新设备状态
|
||||
if (!empty($data['deviceAlive'])) {
|
||||
foreach ($data['deviceAlive'] as $deviceId => $isAlive) {
|
||||
// 更新微信账号的设备状态
|
||||
Db::table('s2_wechat_account')
|
||||
->where('currentDeviceId', $deviceId)
|
||||
->update([
|
||||
'deviceAlive' => (int)$isAlive,
|
||||
'updateTime' => time()
|
||||
]);
|
||||
|
||||
// 更新设备表的状态
|
||||
Db::table('s2_device')
|
||||
->where('id', $deviceId)
|
||||
->update([
|
||||
'alive' => (int)$isAlive,
|
||||
'updateTime' => time()
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存微信账号基本数据到数据库
|
||||
*
|
||||
* @param array $item 微信账号数据
|
||||
*/
|
||||
private function saveWechatAccount($item)
|
||||
{
|
||||
// 处理时间字段
|
||||
$createTime = isset($item['createTime']) ? strtotime($item['createTime']) : 0;
|
||||
$deleteTime = !empty($item['isDeleted']) ? strtotime($item['deleteTime']) : 0;
|
||||
|
||||
// 构建数据
|
||||
$data = [
|
||||
'id' => $item['id'],
|
||||
'wechatId' => $item['wechatId'],
|
||||
'deviceAccountId' => $item['deviceAccountId'],
|
||||
'imei' => $item['imei'],
|
||||
'deviceMemo' => $item['deviceMemo'],
|
||||
'accountUserName' => $item['accountUserName'],
|
||||
'accountRealName' => $item['accountRealName'],
|
||||
'accountNickname' => $item['accountNickname'],
|
||||
'keFuAlive' => $item['keFuAlive'],
|
||||
'deviceAlive' => $item['deviceAlive'],
|
||||
'wechatAlive' => $item['wechatAlive'],
|
||||
'yesterdayMsgCount' => $item['yesterdayMsgCount'],
|
||||
'sevenDayMsgCount' => $item['sevenDayMsgCount'],
|
||||
'thirtyDayMsgCount' => $item['thirtyDayMsgCount'],
|
||||
'totalFriend' => $item['totalFriend'],
|
||||
'maleFriend' => $item['maleFriend'],
|
||||
'femaleFriend' => $item['femaleFriend'],
|
||||
'wechatGroupName' => $item['wechatGroupName'],
|
||||
'tenantId' => $item['tenantId'],
|
||||
'nickname' => $item['nickname'],
|
||||
'alias' => $item['alias'],
|
||||
'avatar' => $item['avatar'],
|
||||
'gender' => $item['gender'],
|
||||
'region' => $item['region'],
|
||||
'signature' => $item['signature'],
|
||||
'bindQQ' => $item['bindQQ'],
|
||||
'bindEmail' => $item['bindEmail'],
|
||||
'bindMobile' => $item['bindMobile'],
|
||||
'currentDeviceId' => $item['currentDeviceId'],
|
||||
'isDeleted' => $item['isDeleted'],
|
||||
'groupId' => $item['groupId'],
|
||||
'memo' => $item['memo'],
|
||||
'wechatVersion' => $item['wechatVersion'],
|
||||
'wechatId' => $item['wechatId'] ?? '',
|
||||
'deviceAccountId' => $item['deviceAccountId'] ?? 0,
|
||||
'imei' => $item['imei'] ?? '',
|
||||
'deviceMemo' => $item['deviceMemo'] ?? '',
|
||||
'accountUserName' => $item['accountUserName'] ?? '',
|
||||
'accountRealName' => $item['accountRealName'] ?? '',
|
||||
'accountNickname' => $item['accountNickname'] ?? '',
|
||||
'wechatGroupName' => $item['wechatGroupName'] ?? '',
|
||||
'alias' => $item['alias'] ?? '',
|
||||
'tenantId' => $item['tenantId'] ?? 0,
|
||||
'nickname' => $item['nickname'] ?? '',
|
||||
'avatar' => $item['avatar'] ?? '',
|
||||
'gender' => $item['gender'] ?? 0,
|
||||
'region' => $item['region'] ?? '',
|
||||
'signature' => $item['signature'] ?? '',
|
||||
'bindQQ' => $item['bindQQ'] ?? '',
|
||||
'bindEmail' => $item['bindEmail'] ?? '',
|
||||
'bindMobile' => $item['bindMobile'] ?? '',
|
||||
'currentDeviceId' => $item['currentDeviceId'] ?? 0,
|
||||
'isDeleted' => $item['isDeleted'] ?? 0,
|
||||
'groupId' => $item['groupId'] ?? 0,
|
||||
'memo' => $item['memo'] ?? '',
|
||||
'wechatVersion' => $item['wechatVersion'] ?? '',
|
||||
'labels' => !empty($item['labels']) ? json_encode($item['labels']) : json_encode([]),
|
||||
'createTime' => $createTime,
|
||||
'deleteTime' => $deleteTime,
|
||||
'updateTime' => time()
|
||||
];
|
||||
|
||||
// 保存或更新数据
|
||||
$account = WechatAccountModel::where('id', $item['id'])->find();
|
||||
if ($account) {
|
||||
$account->save($data);
|
||||
|
||||
@@ -168,9 +168,8 @@ class AuthService
|
||||
|
||||
// 尝试从缓存获取授权信息
|
||||
$authorization = Cache::get($cacheKey);
|
||||
$authorization = 'xwz8Uh2doczeTCqSvakElfZMPn-jRce5WTnKTz3ljqpa63PnUOy5beT3TDhxnGNsROofYzpUphfhraxPrQfXvSuMyxFj_vrMUenzptj6hdG8Y4h1NrPXHFUr5Rlw-cIq0uyZZhjYp6xDTLg-IipgyAvBPdJM0vIgbizbo-agd8_Ubwbl0EOPqrMscYdsGrnv9_Lbr_B4-tHMNMa6yerb6kP6rzx8KQ4mJ6Cr5OmPX2WAmFkYykS3p0erWtb9PGHcxgaI1SVkEF4vH2H_iSOxfz5v27xd4HFE63IA5ZtDHQBNeiR0avST36UJSTZz3vjta9FDsw';
|
||||
|
||||
// 如果缓存中没有或已过期,则重新获取
|
||||
$authorization = 'aXRi4R80zwTXo9V-VCXVYk4IMLl5ufKASoRtYHfaRh_uLwil_mO9U_jWfxeR1yupJIPuQCZknXGpctr9PTS1hbormw3RSrOwunNKTsvvcGzjTa0bBUz3S9W8x_PtvbY4_JpoXl8x8hm8cUa37zLlN7DQBAmj8He40FCxMTh1MC4xorM11aXoVFvYcrAkv_urHINWDmfNhH9icXzreiX9Uynw4fq7BkuP7yr6WHQ5z0NkOfKoMcesH4gPn_h_OLHC0T_ps2ky--M5HOvd5WgBmYRecNOcqbe4e0oIIO5ffANLsybyhLOEha3a03qKsyfAFWdf0A';
|
||||
// 如果缓存中没有或已过期,则重新获取
|
||||
if (empty($authorization)) {
|
||||
try {
|
||||
// 从环境变量中获取API用户名和密码
|
||||
|
||||
@@ -162,19 +162,13 @@ class WorkbenchController extends Controller
|
||||
$query->field('workbenchId,syncInterval,syncCount,syncType,startTime,endTime,accountType,devices,contentLibraries');
|
||||
},
|
||||
'user' => function($query) {
|
||||
$query->field('username');
|
||||
},
|
||||
// 'groupPush' => function($query) {
|
||||
// $query->field('workbenchId,pushInterval,pushContent,pushTime,devices,targetGroups');
|
||||
// },
|
||||
// 'groupCreate' => function($query) {
|
||||
// $query->field('workbenchId,groupNamePrefix,maxGroups,membersPerGroup,devices,targetGroups');
|
||||
// }
|
||||
$query->field('id,username');
|
||||
}
|
||||
];
|
||||
|
||||
$list = Workbench::where($where)
|
||||
->with($with)
|
||||
->field('id,name,type,status,autoStart,createTime,updateTime')
|
||||
->field('id,name,type,status,autoStart,userId,createTime,updateTime')
|
||||
->order('id', 'desc')
|
||||
->page($page, $limit)
|
||||
->select()
|
||||
@@ -195,6 +189,15 @@ class WorkbenchController extends Controller
|
||||
$item->config = $item->momentsSync;
|
||||
$item->config->devices = json_decode($item->config->devices, true);
|
||||
$item->config->contentLibraries = json_decode($item->config->contentLibraries, true);
|
||||
|
||||
// 获取内容库名称
|
||||
if (!empty($item->config->contentLibraries)) {
|
||||
$libraryNames = \app\cunkebao\model\ContentLibrary::where('id', 'in', $item->config->contentLibraries)
|
||||
->column('name');
|
||||
$item->config->contentLibraryNames = $libraryNames;
|
||||
} else {
|
||||
$item->config->contentLibraryNames = [];
|
||||
}
|
||||
}
|
||||
unset($item->momentsSync,$item->moments_sync);
|
||||
break;
|
||||
@@ -217,6 +220,9 @@ class WorkbenchController extends Controller
|
||||
unset($item->groupCreate,$item->group_create);
|
||||
break;
|
||||
}
|
||||
// 添加创建人名称
|
||||
$item['creatorName'] = $item->user ? $item->user->username : '';
|
||||
unset($item['user']); // 移除关联数据
|
||||
return $item;
|
||||
});
|
||||
|
||||
@@ -292,6 +298,7 @@ class WorkbenchController extends Controller
|
||||
$workbench->config = $workbench->momentsSync;
|
||||
$workbench->config->devices = json_decode($workbench->config->devices, true);
|
||||
$workbench->config->contentLibraries = json_decode($workbench->config->contentLibraries, true);
|
||||
unset($workbench->momentsSync,$workbench->moments_sync);
|
||||
}
|
||||
break;
|
||||
case self::TYPE_GROUP_PUSH:
|
||||
|
||||
@@ -20,6 +20,6 @@ class User extends Model
|
||||
// 定义关联的工作台
|
||||
public function workbench()
|
||||
{
|
||||
return $this->hasMany('Workbench', 'id', 'userId');
|
||||
return $this->belongsTo('Workbench', 'id', 'userId');
|
||||
}
|
||||
}
|
||||
@@ -56,9 +56,11 @@ class Workbench extends Model
|
||||
return $this->hasOne('WorkbenchGroupCreate', 'workbenchId', 'id');
|
||||
}
|
||||
|
||||
// 用户关联
|
||||
/**
|
||||
* 用户关联
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOne('User', 'id', 'userId');
|
||||
return $this->belongsTo('User', 'userId', 'id');
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ use think\Model;
|
||||
*/
|
||||
class WorkbenchAutoLike extends Model
|
||||
{
|
||||
protected $table = 'ck_workbench_auto_like';
|
||||
protected $pk = 'id';
|
||||
protected $name = 'workbench_auto_like';
|
||||
|
||||
|
||||
@@ -37,13 +37,14 @@ class BaseController extends Api
|
||||
if (!$device) {
|
||||
$device = Db::name('device_user')
|
||||
->alias('du')
|
||||
->join(['s2_device' => 'd'], 'd.id = du.deviceId','left')
|
||||
->join(['s2_wechat_account' => 'wa'], 'd.id = wa.currentDeviceId','left')
|
||||
->join('device d', 'd.id = du.deviceId','left')
|
||||
->join('device_wechat_login dwl', 'dwl.deviceId = du.deviceId','left')
|
||||
->join('wechat_account wa', 'dwl.wechatId = wa.wechatId','left')
|
||||
->where([
|
||||
'du.userId' => $this->userInfo['id'],
|
||||
'du.companyId' => $this->userInfo['companyId']
|
||||
])
|
||||
->field('d.*,wa.id as wechatAccountId,wa.wechatId,wa.alias')
|
||||
->field('d.*,wa.wechatId,wa.alias,wa.s2_wechatAccountId as wechatAccountId')
|
||||
->find();
|
||||
// 将设备信息存入缓存
|
||||
if ($device) {
|
||||
|
||||
@@ -28,25 +28,25 @@ class StatisticsController extends BaseController
|
||||
$lastEndTime = $timeRange['last_end_time'];
|
||||
|
||||
// 1. 总客户数
|
||||
$totalCustomers = WechatFriendModel::where(['wechatAccountId'=> $wechatAccountId])
|
||||
$totalCustomers = WechatFriendModel::where(['ownerWechatId'=> $wechatAccountId])
|
||||
->whereTime('createTime', '>=', $startTime)
|
||||
->whereTime('createTime', '<', $endTime)
|
||||
->count();
|
||||
|
||||
// 上期总客户数
|
||||
$lastTotalCustomers = WechatFriendModel::where(['wechatAccountId'=> $wechatAccountId])
|
||||
$lastTotalCustomers = WechatFriendModel::where(['ownerWechatId'=> $wechatAccountId])
|
||||
->whereTime('createTime', '>=', $lastStartTime)
|
||||
->whereTime('createTime', '<', $lastEndTime)
|
||||
->count();
|
||||
|
||||
// 2. 新增客户数
|
||||
$newCustomers = WechatFriendModel::where(['wechatAccountId'=> $wechatAccountId])
|
||||
$newCustomers = WechatFriendModel::where(['ownerWechatId'=> $wechatAccountId])
|
||||
->whereTime('createTime', '>=', $startTime)
|
||||
->whereTime('createTime', '<', $endTime)
|
||||
->count();
|
||||
|
||||
// 上期新增客户数
|
||||
$lastNewCustomers = WechatFriendModel::where(['wechatAccountId'=> $wechatAccountId])
|
||||
$lastNewCustomers = WechatFriendModel::where(['ownerWechatId'=> $wechatAccountId])
|
||||
->whereTime('createTime', '>=', $lastStartTime)
|
||||
->whereTime('createTime', '<', $lastEndTime)
|
||||
->count();
|
||||
@@ -106,33 +106,33 @@ class StatisticsController extends BaseController
|
||||
$endTime = $timeRange['end_time'];
|
||||
|
||||
// 1. 客户增长趋势数据
|
||||
$totalCustomers = WechatFriendModel::where(['wechatAccountId'=> $wechatAccountId])
|
||||
$totalCustomers = WechatFriendModel::where(['ownerWechatId'=> $wechatAccountId])
|
||||
->whereTime('createTime', '<', $endTime)
|
||||
->count();
|
||||
|
||||
$newCustomers = WechatFriendModel::where(['wechatAccountId'=> $wechatAccountId])
|
||||
$newCustomers = WechatFriendModel::where(['ownerWechatId'=> $wechatAccountId])
|
||||
->whereTime('createTime', '>=', $startTime)
|
||||
->whereTime('createTime', '<', $endTime)
|
||||
->count();
|
||||
|
||||
// 计算流失客户数(假设超过30天未互动的客户为流失客户)
|
||||
$lostCustomers = WechatFriendModel::where(['wechatAccountId'=> $wechatAccountId,'isDeleted'=> 1])
|
||||
$lostCustomers = WechatFriendModel::where(['ownerWechatId'=> $wechatAccountId])->where('createTime','>',0)
|
||||
->whereTime('deleteTime', '<', date('Y-m-d', strtotime('-30 days')))
|
||||
->count();
|
||||
|
||||
// 2. 客户来源分布数据
|
||||
// 朋友推荐
|
||||
$friendRecommend = WechatFriendModel::where(['wechatAccountId'=> $wechatAccountId])
|
||||
$friendRecommend = WechatFriendModel::where(['ownerWechatId'=> $wechatAccountId])
|
||||
->whereIn('addFrom', [17, 1000017])
|
||||
->count();
|
||||
|
||||
// 微信搜索
|
||||
$wechatSearch = WechatFriendModel::where(['wechatAccountId'=> $wechatAccountId])
|
||||
$wechatSearch = WechatFriendModel::where(['ownerWechatId'=> $wechatAccountId])
|
||||
->whereIn('addFrom', [3, 15, 1000003, 1000015])
|
||||
->count();
|
||||
|
||||
// 微信群
|
||||
$wechatGroup = WechatFriendModel::where(['wechatAccountId'=> $wechatAccountId])
|
||||
$wechatGroup = WechatFriendModel::where(['ownerWechatId'=> $wechatAccountId])
|
||||
->whereIn('addFrom', [14, 1000014])
|
||||
->count();
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use think\Model;
|
||||
|
||||
class FlowPackageModel extends Model
|
||||
{
|
||||
protected $table = 'ck_flow_package';
|
||||
protected $name = 'flow_package';
|
||||
|
||||
// 定义字段自动转换
|
||||
protected $type = [
|
||||
|
||||
@@ -10,7 +10,7 @@ use think\Model;
|
||||
class FlowPackageOrderModel extends Model
|
||||
{
|
||||
// 设置表名
|
||||
protected $table = 'ck_flow_package_order';
|
||||
protected $name = 'flow_package_order';
|
||||
|
||||
// 自动写入时间戳
|
||||
protected $autoWriteTimestamp = true;
|
||||
|
||||
@@ -6,7 +6,7 @@ use think\Model;
|
||||
|
||||
class UserFlowPackageModel extends Model
|
||||
{
|
||||
protected $table = 'ck_user_flow_package';
|
||||
protected $name = 'user_flow_package';
|
||||
/**
|
||||
* 获取用户当前有效的流量套餐
|
||||
*
|
||||
|
||||
@@ -6,6 +6,6 @@ use think\Model;
|
||||
|
||||
class WechatFriendModel extends Model
|
||||
{
|
||||
protected $table = 's2_wechat_friend';
|
||||
protected $name = 'wechat_friend';
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user