diff --git a/app/controller/api/dataview/Merchant.php b/app/controller/api/dataview/Merchant.php index 88315b6a..95b96472 100644 --- a/app/controller/api/dataview/Merchant.php +++ b/app/controller/api/dataview/Merchant.php @@ -2,7 +2,12 @@ namespace app\controller\api\dataview; +use app\common\model\store\order\StoreOrderProduct; +use app\common\model\store\product\Product as model; +use app\common\model\user\UserVisit; +use app\common\repositories\store\order\StoreOrderProductRepository; use app\common\repositories\store\order\StoreOrderRepository; +use app\common\repositories\store\product\ProductRepository; use app\common\repositories\user\UserRelationRepository; use app\common\repositories\user\UserVisitRepository; use crmeb\basic\BaseController; @@ -10,6 +15,7 @@ use app\common\repositories\system\merchant\MerchantRepository as repository; use think\App; use think\Db; use think\exception\ValidateException; +use think\facade\Cache; class Merchant extends BaseController { @@ -82,4 +88,68 @@ class Merchant extends BaseController // Db::name('store_product')->where('mer_id', $merId)->count(); return compact('productNum','payPrice', 'payUser', 'visitNum', 'likeStore'); } + + public function merchantProductRanking(StoreOrderProductRepository $repository) + { + $startDate = $this->request->param('start_date'); + $endDate = $this->request->param('end_date'); + $merId = $this->request->param('mer_id'); + $res = Cache::store('file')->remember(self::class . '@merchantProductRanking' . $merId. $startDate. $endDate, function () use ($repository, $startDate, $endDate, $merId) { + $list = StoreOrderProduct::getDB()->alias('A')->leftJoin('StoreOrder B', 'A.order_id = B.order_id') + ->field(\think\facade\Db::raw('sum(A.product_num) as total,A.product_id,cart_info')) + ->whereBetweenTime('B.pay_time', $startDate, $endDate) + ->where('B.mer_id', $merId) + ->where('B.paid', 1)->group('A.product_id')->limit(30)->order('total DESC')->select(); + $totalCount = 0; + foreach ($list as $item) { + $totalCount += $item['total']; + } + return compact('list', 'totalCount'); + }, 2000 + random_int(600, 1200)); + return app('json')->success($res); + } + + public function merchantProductVisit(UserVisitRepository $repository) + { + $startDate = $this->request->param('start_date'); + $endDate = $this->request->param('end_date'); + $merId = $this->request->param('mer_id'); + $res = Cache::store('file')->remember(self::class . '@merchantProductVisit' . $merId . $startDate. $endDate, function () use ($repository, $startDate, $endDate, $merId) { + $list = UserVisit::getDB()->alias('A')->join('StoreProduct B', 'A.type_id = B.product_id') + ->join('Merchant C', 'C.mer_id = B.mer_id') + ->field(\think\facade\Db::raw('count(A.type_id) as total,B.image,B.store_name')) + ->whereBetweenTime('A.create_time', $startDate, $endDate) + ->where('A.type', 'product')->where('B.mer_id', $merId)->group('A.type_id')->order('total DESC') + ->limit(30)->select(); + $totalCount = 0; + foreach ($list as $item) { + $totalCount += $item['total']; + } + return compact('list', 'totalCount'); + }, 2000 + random_int(600, 1200)); + return app('json')->success($res); + } + + public function merchantProductCart(ProductRepository $repository) + { + $startDate = $this->request->param('start_date'); + $endDate = $this->request->param('end_date'); + $merId = $this->request->param('mer_id'); + $res = Cache::store('file')->remember(self::class . '@merchantProductCart' . $merId . $startDate. $endDate, function () use ($repository, $startDate, $endDate, $merId) { + $list = \app\common\model\store\product\Product::getDB()->alias('A')->leftJoin('StoreCart B', 'A.product_id = B.product_id') + ->field(\think\facade\Db::raw('sum(B.cart_num) as total,A.product_id,A.store_name,A.image')) + ->whereBetweenTime('B.create_time', $startDate, $endDate) + ->where('A.mer_id', $merId) + ->where('B.product_type', 0)->where('B.is_pay', 0)->where('B.is_del', 0) + ->where('B.is_new', 0)->where('B.is_fail', 0)->group('A.product_id')->limit(30)->order('total DESC')->select(); + $totalCount = 0; + foreach ($list as $item) { + $totalCount += $item['total']; + } + return compact('list', 'totalCount'); + }, 2000 + random_int(600, 1200)); + + return app('json')->success($res); + } + } \ No newline at end of file diff --git a/route/api.php b/route/api.php index f61f3a21..944abc26 100644 --- a/route/api.php +++ b/route/api.php @@ -757,6 +757,9 @@ Route::group('api/', function () { // api.dataview.Merchant Route::get('merchant_list', 'Merchant/merchantList'); Route::get('merchant_count_main', 'Merchant/merchantCountMain'); + Route::get('merchant_product_ranking', 'Merchant/merchantProductRanking'); + Route::get('merchant_product_visit', 'Merchant/merchantProductVisit'); + Route::get('merchant_product_cart', 'Merchant/merchantProductCart'); // api.dataview.Finance Route::get('withdraw_list', 'Finance/withdrawList');