| xqd
@@ -9,6 +9,7 @@
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
|
|
use App\Models\AlbumAgentModel;
|
|
|
+use App\Models\AlbumProductModel;
|
|
|
use App\Models\AlbumUserModel;
|
|
|
use App\Models\AlbumWatchRecord;
|
|
|
use App\Models\CustomerDetailsModel;
|
| xqd
@@ -284,11 +285,174 @@ class AlbumBossController extends Controller
|
|
|
$totalCustomerCount = AlbumWatchRecord::where([
|
|
|
['agent_id', $data['agent_id']],
|
|
|
['store_id', $data['store_id']],
|
|
|
+ ['updated_at','>=',$start],
|
|
|
+ ['updated_at','<=',$end]
|
|
|
+ ])->orderByDesc('id')->groupBy('open_id')->count();
|
|
|
+
|
|
|
+ return $this->api(compact('shareCount', 'totalCustomerCount', 'newCustomerCount', 'downloadCount', 'favoriteCount'));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @api {post} /api/album_boss/agent_overview 经销商总览(agent_overview)
|
|
|
+ * @apiDescription 经销商总览(agent_overview)
|
|
|
+ * @apiGroup Boss
|
|
|
+ * @apiPermission none
|
|
|
+ * @apiVersion 0.1.0
|
|
|
+ * @apiParam {int} [store_id] 商户id
|
|
|
+ * @apiParam {int} [start] 开始时间
|
|
|
+ * @apiParam {int} [end] 结束时间
|
|
|
+ * @apiSuccessExample {json} Success-Response:
|
|
|
+ * HTTP/1.1 200 OK
|
|
|
+ * {
|
|
|
+ * "status": true,
|
|
|
+ * "status_code": 0,
|
|
|
+ * "message": "",
|
|
|
+ * "data": {
|
|
|
+ * "customerFollow":11,
|
|
|
+ * "downloadCount":11,
|
|
|
+ * "shareCount":11,
|
|
|
+ * "newCustomerCount":11,
|
|
|
+ * "totalCustomerCount":11,
|
|
|
+ * "activeCustomers": [
|
|
|
+ * {
|
|
|
+ * "day" : 03/25,
|
|
|
+ * "num" : 111
|
|
|
+ * }
|
|
|
+ * ],
|
|
|
+ * "newCustomers": [
|
|
|
+ * {
|
|
|
+ * "day" : 03/25,
|
|
|
+ * "num" : 111
|
|
|
+ * }
|
|
|
+ * ]
|
|
|
+ * "arrFavorite": [
|
|
|
+ * {
|
|
|
+ * 'name':'asdawd',
|
|
|
+ * 'point':'asdawd',
|
|
|
+ * 'num':'1',
|
|
|
+ * }
|
|
|
+ * ]
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ * @apiErrorExample {json} Error-Response:
|
|
|
+ * HTTP/1.1 400 Bad Request
|
|
|
+ * {
|
|
|
+ * "state": false,
|
|
|
+ * "code": 1000,
|
|
|
+ * "message": "传入参数不正确",
|
|
|
+ * "data": null or []
|
|
|
+ * }
|
|
|
+ * 可能出现的错误代码:
|
|
|
+ * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
|
|
|
+ */
|
|
|
+ public function albumOverview(Request $request)
|
|
|
+ {
|
|
|
+
|
|
|
+ $userAuth = Auth('api')->user();
|
|
|
+ if (!$userAuth) {
|
|
|
+ return $this->error(ErrorCode::ERROR_POWER, '登陆过期!');
|
|
|
+ }
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'store_id' => 'required',
|
|
|
+ ], [
|
|
|
+ 'store_id.required' => '缺少商户参数',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if ($userAuth->role != 4) {
|
|
|
+ return $this->error(ErrorCode::NOT_BOSS, '该用户没有Boss权限');
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
|
|
|
+ }
|
|
|
+
|
|
|
+ $end = $request->input('end');
|
|
|
+ $start = $request->input('start');
|
|
|
+ $store_id = $request->input('store_id');
|
|
|
+ if (!$end) {
|
|
|
+ $end = time();
|
|
|
+ }
|
|
|
+ if (!$start) {
|
|
|
+ $start = 0;
|
|
|
+ }
|
|
|
+ $end = date('Y-m-d H:i:s', $end);
|
|
|
+ $start = date('Y-m-d H:i:s', $start);
|
|
|
+ $resGoods = AlbumWatchRecord::where([
|
|
|
+ ['store_id',$store_id],['action',3],['updated_at','>=',$start],
|
|
|
+ ['updated_at','<=',$end]
|
|
|
+ ])->get();
|
|
|
+ $arrFavorite = array();
|
|
|
+ $total = 0;
|
|
|
+
|
|
|
+ foreach ($resGoods as $key => $val) {
|
|
|
+ $goods_data = json_decode($val->detail, true);
|
|
|
+ $goods_id = $goods_data['goods_id'];
|
|
|
+ $goods = AlbumProductModel::find($goods_id);
|
|
|
+ if (!$goods) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (isset($arr[$goods->id])) {
|
|
|
+ $arrFavorite[$goods->id]['num']++;
|
|
|
+ } else {
|
|
|
+ $arrFavorite[$goods->id]['num'] = 1;
|
|
|
+ $arrFavorite[$goods->id]['name'] = $goods->name;
|
|
|
+ }
|
|
|
+ $total++;
|
|
|
+ }
|
|
|
+ $activeCustomers = array();
|
|
|
+ $newCustomers = array();
|
|
|
+ for ($d = 0; $d < 15; $d++) {
|
|
|
+ $Start = mktime(0, 0, 0, date('m'), date('d'), date('y')) + 86400 * $d;
|
|
|
+ $End = $Start + 86400;
|
|
|
+ $End = date('Y-m-d H:i:s', $End);
|
|
|
+ $Start = date('Y-m-d H:i:s', $Start);
|
|
|
+ $customerNum = AlbumWatchRecord::where([
|
|
|
+ ['store_id', $store_id],
|
|
|
+ ['updated_at','>=',$Start],
|
|
|
+ ['updated_at','<=',$End]
|
|
|
+ ])->orderByDesc('id')->groupBy('open_id')->count();
|
|
|
+ $newCustomer = AlbumWatchRecord::where([
|
|
|
+ ['store_id', $store_id],
|
|
|
+ ['is_new', 1],
|
|
|
+ ['updated_at','>=',$Start],
|
|
|
+ ['updated_at','<=',$End]
|
|
|
+ ])->orderByDesc('id')->count();
|
|
|
+ $activeCustomers[] = [
|
|
|
+ 'day' => date('m', $Start) . '-' . date('d', $End),
|
|
|
+ 'num' => $customerNum
|
|
|
+ ];
|
|
|
+ $newCustomers[] = [
|
|
|
+ 'day' => date('m', $Start) . '-' . date('d', $End),
|
|
|
+ 'num' => $newCustomer
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $customerFollow = CustomerDetailsModel::where('store_id', $store_id)->count();
|
|
|
+ $downloadCount = AlbumWatchRecord::where([
|
|
|
+ ['store_id', $store_id],
|
|
|
+ ['action', 9],
|
|
|
+ ['updated_at','>=',$start],
|
|
|
+ ['updated_at','<=',$end]
|
|
|
+ ])->orderByDesc('id')->count();
|
|
|
+
|
|
|
+ $shareCount = AlbumWatchRecord::where([
|
|
|
+ ['store_id', $store_id],
|
|
|
+ ['action', 8],
|
|
|
+ ['updated_at','>=',$start],
|
|
|
+ ['updated_at','<=',$end]
|
|
|
+ ])->orderByDesc('id')->count();
|
|
|
+
|
|
|
+ $newCustomerCount = AlbumWatchRecord::where([
|
|
|
+ ['store_id', $store_id],
|
|
|
['is_new', 1],
|
|
|
['updated_at','>=',$start],
|
|
|
['updated_at','<=',$end]
|
|
|
])->orderByDesc('id')->count();
|
|
|
|
|
|
- return $this->api(compact('shareCount', 'totalCustomerCount', 'newCustomerCount', 'downloadCount', 'favoriteCount'));
|
|
|
+ $totalCustomerCount = AlbumWatchRecord::where([
|
|
|
+ ['store_id', $store_id],
|
|
|
+ ['updated_at','>=',$start],
|
|
|
+ ['updated_at','<=',$end]
|
|
|
+ ])->orderByDesc('id')->groupBy('open_id')->count();
|
|
|
+ return $this->api(compact('totalCustomerCount', 'newCustomerCount', 'shareCount', 'downloadCount', 'customerFollow', 'newCustomers', 'activeCustomers', 'arrFavorite'));
|
|
|
}
|
|
|
}
|