fly 4 vuotta sitten
vanhempi
commit
f39bb7347a

+ 0 - 76
src/Controllers/CompanyAuth/AppController.php

@@ -12,7 +12,6 @@ use General\Controllers\CompanyAuth\Transformers\OfficialAccountTransformer;
 use General\Controllers\CompanyAuth\Transformers\OrderDayStatsTransformer;
 use General\Controllers\CompanyAuth\Transformers\OrderTransformer;
 use General\Controllers\CompanyAuth\Transformers\SendOrderTransformer;
-use General\Controllers\CompanyAuth\Transformers\UserTransformer;
 use General\Helpers\CommonHelper;
 use General\Requests\CompanyAuth\BookQueryRequest;
 use General\Requests\CompanyAuth\CustomSendMsgRequest;
@@ -26,8 +25,6 @@ use General\Services\OfficialAccount\OfficialAccountService;
 use General\Services\Order\OrderService;
 use General\Services\SendOrder\SendOrderService;
 use General\Services\SendOrder\SendOrderStatistic;
-use General\Services\User\UserService;
-use Illuminate\Http\Request;
 
 class AppController extends Controller
 {
@@ -232,79 +229,6 @@ class AppController extends Controller
     }
 
     /**
-     * @api {post} company/auth/users 用户信息
-     * @apiVersion 1.0.0
-     * @apiName users
-     * @apiGroup CompanyAuth
-     * @apiParam {String} channel_id 站点id
-     * @apiParam {Int} page 分页页码
-     * @apiParam {String} app_id 分配好的{app_id}
-     * @apiParam {String} nonce_str 随机字符串
-     * @apiParam {String} timestamp 时间戳
-     * @apiParam {String} uid (可以不传) 用户uid,','分隔;最多不超过100个
-     * @apiParam {String} start_time (可以不传) 开始时间(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)
-     * @apiParam {String} end_time (可以不传) 截止时间(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)
-     * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
-     * @apiSuccess {int}         code 状态码
-     * @apiSuccess {String}      msg  信息
-     * @apiSuccess {Object}      data 结果集
-     * @apiSuccess {Object}      list 数据结果
-     * @apiSuccess {Object}      meta 分页信息
-     * @apiSuccess {Int}      total 分页总数
-     * @apiSuccess {Int}         id 用户id
-     * @apiSuccess {Int}         channel_id 站点ID
-     * @apiSuccess {String}         app_id 关注app_id
-     * @apiSuccess {String}         opend_id 关注open_id
-     * @apiSuccess {String}         register_openid 注册open_id
-     * @apiSuccess {String}      ua 用户user_agent
-     * @apiSuccess {String}      register_ip 注册IP
-     * @apiSuccess {String}      register_time 注册时间
-     * @apiSuccess {String}      subscribe_time 关注时间
-     * @apiSuccessExample {json} Success-Response:
-     *     HTTP/1.1 200 OK
-     *{
-     *    "code": 0,
-     *    "msg": "",
-     *    "data": {
-     *        "list": [
-     *            {
-     *                "id": 7475378,
-     *                "channel_id": 166,
-     *                "app_id": null,
-     *                "opend_id": "oq6ID0ovAjyxnWZRbm3YPz8Pz8nE",
-     *                "register_time": "2018-03-20 00:00:08",
-     *                "subscribe_time": ""
-     *            }
-     *        ],
-     *        "meta": {
-     *            "total": 1,
-     *            "per_page": 100,
-     *            "current_page": 1,
-     *            "last_page": 1,
-     *            "next_page_url": "",
-     *            "prev_page_url": ""
-     *        }
-     *    }
-     *}
-     */
-    public function users(ChannelQueryRequest $request)
-    {
-        $channel_id = $request->get('channel_id');
-        $uid_str  = $request->get('uid', '');
-        $start_time = $request->get('start_time', '');
-        $end_time = $request->get('end_time', '');
-        $service = new UserService;
-        if ($uid_str) {
-            $uids = explode(',', $uid_str);
-            $uids = count($uids) > 100 ? collect($uids)->take(100) : $uids;
-            $result = $service->companyAuthUsers($channel_id, $start_time, $end_time, $uids);
-        } else {
-            $result = $service->companyAuthUsers($channel_id, $start_time, $end_time);
-        }
-        return response()->pagination(new UserTransformer, $result);
-    }
-
-    /**
      * @api {post} company/auth/sendOrders 派单信息列表
      * @apiVersion 1.0.0
      * @apiName sendOrders

+ 25 - 0
src/Controllers/CompanyAuth/Transformers/SubScribeRecordTransformer.php

@@ -0,0 +1,25 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * Date: 2017/3/31
+ * Time: 14:02
+ */
+
+namespace General\Controllers\CompanyAuth\Transformers;
+
+class SubScribeRecordTransformer
+{
+    public function transform($item)
+    {
+        return [
+            'uid' => $item->uid,
+            'distribution_channel_id' => $item->distribution_channel_id,
+            'app_id' => $item->appid,
+            'open_id' => $item->openid,
+            'is_subscribed' => $item->is_subscribed,
+            'subscribe_time' => (string)$item->subscribe_time,
+            'unsubscribe_time' => (string)$item->unsubscribe_time,
+        ];
+    }
+}

+ 154 - 0
src/Controllers/CompanyAuth/UserController.php

@@ -0,0 +1,154 @@
+<?php
+
+namespace General\Controllers\CompanyAuth;
+
+use App\Http\Controllers\Controller;
+use General\Controllers\CompanyAuth\Transformers\SubScribeRecordTransformer;
+use General\Controllers\CompanyAuth\Transformers\UserTransformer;
+use General\Requests\CompanyAuth\ChannelQueryRequest;
+use General\Services\User\UserService;
+
+class UserController extends Controller
+{
+    /**
+     * @apiDefine User 用户信息
+     */
+
+    /**
+     * @api {post} company/auth/users 用户信息
+     * @apiVersion 1.0.0
+     * @apiName users
+     * @apiGroup User
+     * @apiParam {String} channel_id 站点id
+     * @apiParam {Int} page 分页页码
+     * @apiParam {String} app_id 分配好的{app_id}
+     * @apiParam {String} nonce_str 随机字符串
+     * @apiParam {String} timestamp 时间戳
+     * @apiParam {String} uid (可以不传) 用户uid,','分隔;最多不超过100个
+     * @apiParam {String} start_time (可以不传) 开始时间(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)
+     * @apiParam {String} end_time (可以不传) 截止时间(时间区间小于30天,格式yyyy-MM-dd HH:mm:ss)
+     * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
+     * @apiSuccess {int}         code 状态码
+     * @apiSuccess {String}      msg  信息
+     * @apiSuccess {Object}      data 结果集
+     * @apiSuccess {Object}      list 数据结果
+     * @apiSuccess {Object}      meta 分页信息
+     * @apiSuccess {Int}      total 分页总数
+     * @apiSuccess {Int}         id 用户id
+     * @apiSuccess {Int}         channel_id 站点ID
+     * @apiSuccess {String}         app_id 关注app_id
+     * @apiSuccess {String}         opend_id 关注open_id
+     * @apiSuccess {String}         register_openid 注册open_id
+     * @apiSuccess {String}      ua 用户user_agent
+     * @apiSuccess {String}      register_ip 注册IP
+     * @apiSuccess {String}      register_time 注册时间
+     * @apiSuccess {String}      subscribe_time 关注时间
+     * @apiSuccessExample {json} Success-Response:
+     *     HTTP/1.1 200 OK
+     *{
+     *    "code": 0,
+     *    "msg": "",
+     *    "data": {
+     *        "list": [
+     *            {
+     *                "id": 7475378,
+     *                "channel_id": 166,
+     *                "app_id": null,
+     *                "opend_id": "oq6ID0ovAjyxnWZRbm3YPz8Pz8nE",
+     *                "register_time": "2018-03-20 00:00:08",
+     *                "subscribe_time": ""
+     *            }
+     *        ],
+     *        "meta": {
+     *            "total": 1,
+     *            "per_page": 100,
+     *            "current_page": 1,
+     *            "last_page": 1,
+     *            "next_page_url": "",
+     *            "prev_page_url": ""
+     *        }
+     *    }
+     *}
+     */
+    public function users(ChannelQueryRequest $request)
+    {
+        $channel_id = $request->get('channel_id');
+        $uid_str  = $request->get('uid', '');
+        $start_time = $request->get('start_time', '');
+        $end_time = $request->get('end_time', '');
+        $service = new UserService;
+        if ($uid_str) {
+            $uids = explode(',', $uid_str);
+            $uids = count($uids) > 100 ? collect($uids)->take(100) : $uids;
+            $result = $service->companyAuthUsers($channel_id, $start_time, $end_time, $uids);
+        } else {
+            $result = $service->companyAuthUsers($channel_id, $start_time, $end_time);
+        }
+        return response()->pagination(new UserTransformer, $result);
+    }
+
+    /**
+     * @api {post} company/auth/subscribeRecords 用户信息
+     * @apiVersion 1.0.0
+     * @apiName subscribeRecords
+     * @apiGroup User
+     * @apiParam {String} channel_id 站点id
+     * @apiParam {String} uid (可以不传) 用户uid,','分隔;最多不超过100个
+     * @apiParam {Int} page 分页页码
+     * @apiParam {String} app_id 分配好的{app_id}
+     * @apiParam {String} nonce_str 随机字符串
+     * @apiParam {String} timestamp 时间戳
+     * @apiParam {String} sign 签名 规则同微信支付签名MD5(排序好的请求字符串&key=分配好的{app_secret})
+     * @apiSuccess {int}         code 状态码
+     * @apiSuccess {String}      msg  信息
+     * @apiSuccess {Object}      data 结果集
+     * @apiSuccess {Object}      list 数据结果
+     * @apiSuccess {Object}      meta 分页信息
+     * @apiSuccess {Int}      total 分页总数
+     * @apiSuccess {Int}         uid 用户ID
+     * @apiSuccess {Int}         distribution_channel_id 站点ID
+     * @apiSuccess {String}         appid 关注app_id
+     * @apiSuccess {String}         openid 关注open_id
+     * @apiSuccess {Int}      is_subscribed 是否关注
+     * @apiSuccess {String}      subscribe_time 关注时间
+     * @apiSuccess {String}      unsubscribe_time 取关时间
+     * @apiSuccessExample {json} Success-Response:
+     *     HTTP/1.1 200 OK
+     *{
+     *    "code": 0,
+     *    "msg": "",
+     *    "data": {
+     *        "list": [
+     *            {
+     *                "id": 7475378,
+     *                "channel_id": 166,
+     *                "app_id": null,
+     *                "opend_id": "oq6ID0ovAjyxnWZRbm3YPz8Pz8nE",
+     *                "register_time": "2018-03-20 00:00:08",
+     *                "subscribe_time": ""
+     *            }
+     *        ],
+     *        "meta": {
+     *            "total": 1,
+     *            "per_page": 100,
+     *            "current_page": 1,
+     *            "last_page": 1,
+     *            "next_page_url": "",
+     *            "prev_page_url": ""
+     *        }
+     *    }
+     *}
+     */
+    public function subscribeRecords(ChannelQueryRequest $request)
+    {
+        $uid_str  = $request->get('uid', '');
+        $channel_id = $request->get('channel_id');
+        if ($uid_str) {
+            $uids = explode(',', $uid_str);
+            $uids = count($uids) > 100 ? collect($uids)->take(100) : $uids;
+            $service = new UserService;
+            $result = $service->findSubscribeRecords($channel_id, $uids);
+        }
+        return response()->pagination(new SubScribeRecordTransformer, $result);
+    }
+}

+ 28 - 0
src/Models/User/SubscribeRecord.php

@@ -0,0 +1,28 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: hp
+ * Date: 2017/11/21
+ * Time: 10:42
+ */
+
+namespace General\Models\User;
+
+use Illuminate\Database\Eloquent\Model;
+
+class SubscribeRecord extends Model
+{
+    protected $table = 'subscribe_records';
+
+    protected $fillable =
+    [
+        'uid',
+        'distribution_channel_id',
+        'appid',
+        'openid',
+        'is_subscribed',
+        'subscribe_time',
+        'unsubscribe_time',
+    ];
+}

+ 1 - 0
src/Requests/CompanyAuth/ChannelQueryRequest.php

@@ -22,6 +22,7 @@ class ChannelQueryRequest extends Request
             'end_time' => 'required_with:start_time|date|after_or_equal:start_time',
             'begin_date' => 'date',
             'end_date' => 'required_with:begin_date|date|after_or_equal:begin_date',
+            'uid' => 'string',
         ];
     }
 

+ 8 - 0
src/Services/User/UserService.php

@@ -9,6 +9,7 @@
 
 namespace General\Services\User;
 
+use General\Models\User\SubscribeRecord;
 use General\Models\User\User;
 
 class UserService
@@ -28,4 +29,11 @@ class UserService
         }
         return $sql->paginate(100);
     }
+
+    public function findSubscribeRecords(int $channel_id, array $uids)
+    {
+        return SubscribeRecord::where('distribution_channel_id', $channel_id)
+            ->whereIn('uid', $uids)
+            ->paginate(100);
+    }
 }