|
@@ -9,6 +9,8 @@ use Illuminate\Support\Facades\DB;
|
|
use Modules\Audience\Models\GzhUgMapModel;
|
|
use Modules\Audience\Models\GzhUgMapModel;
|
|
use Modules\Audience\Models\UserGroupModel;
|
|
use Modules\Audience\Models\UserGroupModel;
|
|
use Modules\Audience\Services\UserGroupService;
|
|
use Modules\Audience\Services\UserGroupService;
|
|
|
|
+use Modules\Common\Errors\Errors;
|
|
|
|
+use Modules\Common\Exceptions\CommonBusinessException;
|
|
|
|
|
|
class UserGroupController extends CatchController
|
|
class UserGroupController extends CatchController
|
|
{
|
|
{
|
|
@@ -123,4 +125,60 @@ class UserGroupController extends CatchController
|
|
|
|
|
|
return 'ok';
|
|
return 'ok';
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取符合条件的用户分群列表
|
|
|
|
+ * @param Request $request
|
|
|
|
+ */
|
|
|
|
+ public function listUser(Request $request) {
|
|
|
|
+ $this->validate($request, [
|
|
|
|
+ 'timestamp' => 'required',
|
|
|
|
+ 'sign' => 'required'
|
|
|
|
+ ]);
|
|
|
|
+ $signKey = config('audience.ug.signKey');
|
|
|
|
+ if($request->input('sign') != md5(
|
|
|
|
+ $signKey.$request->input('timestamp')
|
|
|
|
+ )) {
|
|
|
|
+ CommonBusinessException::throwError(Errors::OPENPLATFORM_UG_SIGN_ERROR);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $tags = DB::table('user_groups')
|
|
|
|
+ ->where([
|
|
|
|
+ ['id' , '=', $request->input('ugId')],
|
|
|
|
+ ['is_enabled', '=', 1]
|
|
|
|
+ ])->value('tags');
|
|
|
|
+ if(!$tags) {
|
|
|
|
+ CommonBusinessException::throwError(Errors::OPENPLATFORM_UG_NOT_EXISTS);
|
|
|
|
+ }
|
|
|
|
+ $tagsArr = \json_decode($tags, true);
|
|
|
|
+ $authorizer_appid = DB::table('wechat_authorization_infos')
|
|
|
|
+ ->where([
|
|
|
|
+ ['id', '=', $request->input('gzhId')],
|
|
|
|
+ ['is_enabled', '=', 1]
|
|
|
|
+ ])->value('authorizer_appid');
|
|
|
|
+ if(!$authorizer_appid) {
|
|
|
|
+ CommonBusinessException::throwError(Errors::OPENPLATFORM_GZH_SHOUQUAN_ERROR);
|
|
|
|
+ }
|
|
|
|
+ $tagsArr['gzh_appids'] = [$authorizer_appid];
|
|
|
|
+ $sql = UserGroupService::getSQL($tagsArr);
|
|
|
|
+ $res = $sql->distinct()->select('b.uid', 'b.mp_openid')
|
|
|
|
+ ->get();
|
|
|
|
+ $uids = $res->pluck('uid')->toArray();
|
|
|
|
+ if(count($uids)) {
|
|
|
|
+ $uids = UserGroupService::dealHistoryReadBooks(UserGroupService::dealPayVideo($uids, $tags), $tags);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $openid = [];
|
|
|
|
+ foreach ($res as $item) {
|
|
|
|
+ if(in_array($item->uid, $uids)) {
|
|
|
|
+ $openid[] = $item->mp_openid;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return [
|
|
|
|
+ 'openid' => $openid
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
}
|
|
}
|