商户 各接口

This commit is contained in:
chenbo 2023-12-19 15:26:15 +08:00
parent 4f70d330f1
commit 91935ddb7c

View File

@ -122,19 +122,28 @@ class Merchant extends BaseController
$startDate = $this->request->param('start_date'); $startDate = $this->request->param('start_date');
$endDate = $this->request->param('end_date'); $endDate = $this->request->param('end_date');
$merId = $this->request->param('mer_id'); $merId = $this->request->param('mer_id');
$res = Cache::store('file')->remember(self::class . '@merchantProductRanking' . $merId. $startDate. $endDate, function () use ($repository, $startDate, $endDate, $merId) { // $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') // $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')) // ->field(\think\facade\Db::raw('sum(A.product_num) as total,A.product_id,cart_info'))
->whereBetweenTime('B.pay_time', $startDate, $endDate) // ->whereBetweenTime('B.pay_time', $startDate, $endDate)
->where('B.mer_id', $merId) // ->where('B.mer_id', $merId)
->where('B.paid', 1)->group('A.product_id')->limit(30)->order('total DESC')->select(); // ->where('B.paid', 1)->group('A.product_id')->limit(30)->order('total DESC')->select();
$totalCount = 0; // $totalCount = 0;
foreach ($list as $item) { // foreach ($list as $item) {
$totalCount += $item['total']; // $totalCount += $item['total'];
} // }
return compact('list', 'totalCount'); // return compact('list', 'totalCount');
}, 2000 + random_int(600, 1200)); // }, 2000 + random_int(600, 1200));
return app('json')->success($res); $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 app('json')->success(compact('list', 'totalCount'));
} }
public function merchantProductVisit(UserVisitRepository $repository) public function merchantProductVisit(UserVisitRepository $repository)
@ -142,20 +151,30 @@ class Merchant extends BaseController
$startDate = $this->request->param('start_date'); $startDate = $this->request->param('start_date');
$endDate = $this->request->param('end_date'); $endDate = $this->request->param('end_date');
$merId = $this->request->param('mer_id'); $merId = $this->request->param('mer_id');
$res = Cache::store('file')->remember(self::class . '@merchantProductVisit' . $merId . $startDate. $endDate, function () use ($repository, $startDate, $endDate, $merId) { // $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') // $list = UserVisit::getDB()->alias('A')->join('StoreProduct B', 'A.type_id = B.product_id')
->join('Merchant C', 'C.mer_id = B.mer_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')) // ->field(\think\facade\Db::raw('count(A.type_id) as total,B.image,B.store_name'))
->whereBetweenTime('A.create_time', $startDate, $endDate) // ->whereBetweenTime('A.create_time', $startDate, $endDate)
->where('A.type', 'product')->where('B.mer_id', $merId)->group('A.type_id')->order('total DESC') // ->where('A.type', 'product')->where('B.mer_id', $merId)->group('A.type_id')->order('total DESC')
->limit(30)->select(); // ->limit(30)->select();
$totalCount = 0; // $totalCount = 0;
foreach ($list as $item) { // foreach ($list as $item) {
$totalCount += $item['total']; // $totalCount += $item['total'];
} // }
return compact('list', 'totalCount'); // return compact('list', 'totalCount');
}, 2000 + random_int(600, 1200)); // }, 2000 + random_int(600, 1200));
return app('json')->success($res); $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 app('json')->success(compact('list', 'totalCount'));
} }
public function merchantProductCart(ProductRepository $repository) public function merchantProductCart(ProductRepository $repository)
@ -163,21 +182,30 @@ class Merchant extends BaseController
$startDate = $this->request->param('start_date'); $startDate = $this->request->param('start_date');
$endDate = $this->request->param('end_date'); $endDate = $this->request->param('end_date');
$merId = $this->request->param('mer_id'); $merId = $this->request->param('mer_id');
$res = Cache::store('file')->remember(self::class . '@merchantProductCart' . $merId . $startDate. $endDate, function () use ($repository, $startDate, $endDate, $merId) { // $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') // $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')) // ->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) // ->whereBetweenTime('B.create_time', $startDate, $endDate)
->where('A.mer_id', $merId) // ->where('A.mer_id', $merId)
->where('B.product_type', 0)->where('B.is_pay', 0)->where('B.is_del', 0) // ->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(); // ->where('B.is_new', 0)->where('B.is_fail', 0)->group('A.product_id')->limit(30)->order('total DESC')->select();
$totalCount = 0; // $totalCount = 0;
foreach ($list as $item) { // foreach ($list as $item) {
$totalCount += $item['total']; // $totalCount += $item['total'];
} // }
return compact('list', 'totalCount'); // return compact('list', 'totalCount');
}, 2000 + random_int(600, 1200)); // }, 2000 + random_int(600, 1200));
$list = \app\common\model\store\product\Product::getDB()->alias('A')->leftJoin('StoreCart B', 'A.product_id = B.product_id')
return app('json')->success($res); ->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 app('json')->success(compact('list', 'totalCount'));
} }
public function merchant() public function merchant()