私域操盘手 - 微信号好友列表的账号详情
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace app\cunkebao\controller\wechat;
|
||||
|
||||
use app\cunkebao\controller\BaseController;
|
||||
use app\cunkebao\model\WechatAccount as WechatAccountModel;
|
||||
use library\ResponseHelper;
|
||||
|
||||
/**
|
||||
@@ -9,11 +11,42 @@ use library\ResponseHelper;
|
||||
*/
|
||||
class GetWechatOnDeviceFriendProfileV1Controller extends BaseController
|
||||
{
|
||||
|
||||
protected function getWechatAccountProfileById()
|
||||
/**
|
||||
* 获取最近互动时间
|
||||
*
|
||||
* @param string $wechatId
|
||||
* @return string
|
||||
*/
|
||||
protected function getLastPlayTime(string $wechatId): string
|
||||
{
|
||||
return date('Y-m-d H:i:s', strtotime('-1 day'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信账号
|
||||
*
|
||||
* @param int $id
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function getWechatAccountProfileById(int $id): array
|
||||
{
|
||||
$account = WechatAccountModel::alias('w')
|
||||
->field(
|
||||
[
|
||||
'w.id', 'w.avatar', 'w.nickname', 'w.region', 'w.wechatId',
|
||||
'CASE WHEN w.alias IS NULL OR w.alias = "" THEN w.wechatId ELSE w.alias END AS wechatId',
|
||||
'f.createTime addTime', 'f.tags'
|
||||
]
|
||||
)
|
||||
->join('wechat_friendship f', 'w.wechatId=f.wechatId')
|
||||
->find($id);
|
||||
|
||||
if (is_null($account)) {
|
||||
throw new \Exception('未获取到微信账号数据', 404);
|
||||
}
|
||||
|
||||
return $account->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,8 +57,16 @@ class GetWechatOnDeviceFriendProfileV1Controller extends BaseController
|
||||
public function index()
|
||||
{
|
||||
try {
|
||||
$id = $this->request->param('id/d');
|
||||
$results = $this->getWechatAccountProfileById(
|
||||
$this->request->param('aId/d')
|
||||
);
|
||||
|
||||
return ResponseHelper::success(
|
||||
array_merge($results, [
|
||||
'play' => $this->getLastPlayTime($results['wechatId']),
|
||||
'tags' => json_decode($results['tags'], true)
|
||||
])
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
return ResponseHelper::error($e->getMessage(), $e->getCode());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user