commit
d826db5775
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace app\controller\api\dataview;
|
namespace app\controller\api\dataview;
|
||||||
|
|
||||||
|
use app\common\dao\system\merchant\MerchantDao;
|
||||||
use app\common\model\store\order\StoreOrderProduct;
|
use app\common\model\store\order\StoreOrderProduct;
|
||||||
use app\common\model\store\product\Product as model;
|
use app\common\model\store\product\Product as model;
|
||||||
use app\common\model\user\UserVisit;
|
use app\common\model\user\UserVisit;
|
||||||
@ -45,7 +46,34 @@ class Merchant extends BaseController
|
|||||||
{
|
{
|
||||||
[$page, $limit] = $this->getPage();
|
[$page, $limit] = $this->getPage();
|
||||||
$where = $this->request->params([ 'status', 'statusTag', 'is_trader', 'category_id', 'type_id', 'area_id', 'street_id']);
|
$where = $this->request->params([ 'status', 'statusTag', 'is_trader', 'category_id', 'type_id', 'area_id', 'street_id']);
|
||||||
return app('json')->success($this->repository->lst($where, $page, $limit));
|
$dao = new MerchantDao();
|
||||||
|
$query = $dao->search($where);
|
||||||
|
$count = $query->where(function ($query) {
|
||||||
|
if ($this->streetCode != '') {
|
||||||
|
$query->where('street_id', $this->streetCode);
|
||||||
|
} else {
|
||||||
|
$query->where('area_id', $this->areaCode);
|
||||||
|
}
|
||||||
|
})->count($dao->getPk());
|
||||||
|
$list = $query->page($page, $limit)->setOption('field', [])
|
||||||
|
->where(function ($query) {
|
||||||
|
if ($this->streetCode != '') {
|
||||||
|
$query->where('street_id', $this->streetCode);
|
||||||
|
} else {
|
||||||
|
$query->where('area_id', $this->areaCode);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
->with([
|
||||||
|
'admin' => function ($query) {
|
||||||
|
$query->field('mer_id,account');
|
||||||
|
},
|
||||||
|
'merchantCategory',
|
||||||
|
'merchantType'
|
||||||
|
])
|
||||||
|
->order('mer_id','desc')
|
||||||
|
->field('sort, mer_id, mer_name, real_name, mer_phone, mer_address, mark, status, create_time,is_best,is_trader,type_id,category_id,copy_product_num,export_dump_num,is_margin,margin,mer_avatar')->select();
|
||||||
|
|
||||||
|
return app('json')->success(compact('count', 'list'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 商户统计
|
// 商户统计
|
||||||
@ -94,19 +122,29 @@ 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) {
|
$endDate = date("$endDate H:i:s", time());
|
||||||
$list = StoreOrderProduct::getDB()->alias('A')->leftJoin('StoreOrder B', 'A.order_id = B.order_id')
|
// $res = Cache::store('file')->remember(self::class . '@merchantProductRanking' . $merId. $startDate. $endDate, function () use ($repository, $startDate, $endDate, $merId) {
|
||||||
->field(\think\facade\Db::raw('sum(A.product_num) as total,A.product_id,cart_info'))
|
// $list = StoreOrderProduct::getDB()->alias('A')->leftJoin('StoreOrder B', 'A.order_id = B.order_id')
|
||||||
->whereBetweenTime('B.pay_time', $startDate, $endDate)
|
// ->field(\think\facade\Db::raw('sum(A.product_num) as total,A.product_id,cart_info'))
|
||||||
->where('B.mer_id', $merId)
|
// ->whereBetweenTime('B.pay_time', $startDate, $endDate)
|
||||||
->where('B.paid', 1)->group('A.product_id')->limit(30)->order('total DESC')->select();
|
// ->where('B.mer_id', $merId)
|
||||||
$totalCount = 0;
|
// ->where('B.paid', 1)->group('A.product_id')->limit(30)->order('total DESC')->select();
|
||||||
foreach ($list as $item) {
|
// $totalCount = 0;
|
||||||
$totalCount += $item['total'];
|
// foreach ($list as $item) {
|
||||||
}
|
// $totalCount += $item['total'];
|
||||||
return compact('list', 'totalCount');
|
// }
|
||||||
}, 2000 + random_int(600, 1200));
|
// return compact('list', 'totalCount');
|
||||||
return app('json')->success($res);
|
// }, 2000 + random_int(600, 1200));
|
||||||
|
$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)
|
||||||
@ -114,20 +152,31 @@ 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) {
|
$endDate = date("$endDate H:i:s", time());
|
||||||
$list = UserVisit::getDB()->alias('A')->join('StoreProduct B', 'A.type_id = B.product_id')
|
// $res = Cache::store('file')->remember(self::class . '@merchantProductVisit' . $merId . $startDate. $endDate, function () use ($repository, $startDate, $endDate, $merId) {
|
||||||
->join('Merchant C', 'C.mer_id = B.mer_id')
|
// $list = UserVisit::getDB()->alias('A')->join('StoreProduct B', 'A.type_id = B.product_id')
|
||||||
->field(\think\facade\Db::raw('count(A.type_id) as total,B.image,B.store_name'))
|
// ->join('Merchant C', 'C.mer_id = B.mer_id')
|
||||||
->whereBetweenTime('A.create_time', $startDate, $endDate)
|
// ->field(\think\facade\Db::raw('count(A.type_id) as total,B.image,B.store_name'))
|
||||||
->where('A.type', 'product')->where('B.mer_id', $merId)->group('A.type_id')->order('total DESC')
|
// ->whereBetweenTime('A.create_time', $startDate, $endDate)
|
||||||
->limit(30)->select();
|
// ->where('A.type', 'product')->where('B.mer_id', $merId)->group('A.type_id')->order('total DESC')
|
||||||
$totalCount = 0;
|
// ->limit(30)->select();
|
||||||
foreach ($list as $item) {
|
// $totalCount = 0;
|
||||||
$totalCount += $item['total'];
|
// foreach ($list as $item) {
|
||||||
}
|
// $totalCount += $item['total'];
|
||||||
return compact('list', 'totalCount');
|
// }
|
||||||
}, 2000 + random_int(600, 1200));
|
// return compact('list', 'totalCount');
|
||||||
return app('json')->success($res);
|
// }, 2000 + random_int(600, 1200));
|
||||||
|
$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)
|
||||||
@ -135,21 +184,31 @@ 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) {
|
$endDate = date("$endDate H:i:s", time());
|
||||||
$list = \app\common\model\store\product\Product::getDB()->alias('A')->leftJoin('StoreCart B', 'A.product_id = B.product_id')
|
// $res = Cache::store('file')->remember(self::class . '@merchantProductCart' . $merId . $startDate. $endDate, function () use ($repository, $startDate, $endDate, $merId) {
|
||||||
->field(\think\facade\Db::raw('sum(B.cart_num) as total,A.product_id,A.store_name,A.image'))
|
// $list = \app\common\model\store\product\Product::getDB()->alias('A')->leftJoin('StoreCart B', 'A.product_id = B.product_id')
|
||||||
->whereBetweenTime('B.create_time', $startDate, $endDate)
|
// ->field(\think\facade\Db::raw('sum(B.cart_num) as total,A.product_id,A.store_name,A.image'))
|
||||||
->where('A.mer_id', $merId)
|
// ->whereBetweenTime('B.create_time', $startDate, $endDate)
|
||||||
->where('B.product_type', 0)->where('B.is_pay', 0)->where('B.is_del', 0)
|
// ->where('A.mer_id', $merId)
|
||||||
->where('B.is_new', 0)->where('B.is_fail', 0)->group('A.product_id')->limit(30)->order('total DESC')->select();
|
// ->where('B.product_type', 0)->where('B.is_pay', 0)->where('B.is_del', 0)
|
||||||
$totalCount = 0;
|
// ->where('B.is_new', 0)->where('B.is_fail', 0)->group('A.product_id')->limit(30)->order('total DESC')->select();
|
||||||
foreach ($list as $item) {
|
// $totalCount = 0;
|
||||||
$totalCount += $item['total'];
|
// foreach ($list as $item) {
|
||||||
}
|
// $totalCount += $item['total'];
|
||||||
return compact('list', 'totalCount');
|
// }
|
||||||
}, 2000 + random_int(600, 1200));
|
// return compact('list', 'totalCount');
|
||||||
|
// }, 2000 + random_int(600, 1200));
|
||||||
return app('json')->success($res);
|
$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 app('json')->success(compact('list', 'totalCount'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function merchant()
|
public function merchant()
|
||||||
|
@ -456,6 +456,14 @@ class Order extends BaseController
|
|||||||
->field('p.product_id, p.store_name, p.image, COUNT(o.`order_id`) AS total_sales')
|
->field('p.product_id, p.store_name, p.image, COUNT(o.`order_id`) AS total_sales')
|
||||||
->join('store_order_product op', 'p.product_id = op.product_id')
|
->join('store_order_product op', 'p.product_id = op.product_id')
|
||||||
->join('store_order o', 'op.order_id = o.order_id')
|
->join('store_order o', 'op.order_id = o.order_id')
|
||||||
|
->join('product_order_log og', 'o.order_id = og.order_id')
|
||||||
|
->where(function($query) {
|
||||||
|
if ($this->streetCode != '') {
|
||||||
|
$query->where('og.street_code', $this->streetCode);
|
||||||
|
} else {
|
||||||
|
$query->where('og.district_code', $this->areaCode);
|
||||||
|
}
|
||||||
|
})
|
||||||
->group('p.product_id')
|
->group('p.product_id')
|
||||||
->order('total_sales DESC')
|
->order('total_sales DESC')
|
||||||
->limit(10)
|
->limit(10)
|
||||||
@ -470,6 +478,13 @@ class Order extends BaseController
|
|||||||
$merchantRankingList = Db::name('store_order')->alias('o')
|
$merchantRankingList = Db::name('store_order')->alias('o')
|
||||||
->field('m.`mer_id`, m.`mer_name`, m.mini_banner, COUNT(o.`order_id`) AS total_sales')
|
->field('m.`mer_id`, m.`mer_name`, m.mini_banner, COUNT(o.`order_id`) AS total_sales')
|
||||||
->join('merchant m', 'o.`mer_id` = m.`mer_id`')
|
->join('merchant m', 'o.`mer_id` = m.`mer_id`')
|
||||||
|
->where(function($query) {
|
||||||
|
if ($this->streetCode != '') {
|
||||||
|
$query->where('m.street_id', $this->streetCode);
|
||||||
|
} else {
|
||||||
|
$query->where('m.area_id', $this->areaCode);
|
||||||
|
}
|
||||||
|
})
|
||||||
->group('m.mer_id')
|
->group('m.mer_id')
|
||||||
->order('total_sales DESC')
|
->order('total_sales DESC')
|
||||||
->limit(10)
|
->limit(10)
|
||||||
@ -544,7 +559,14 @@ class Order extends BaseController
|
|||||||
'user' => function ($query) {
|
'user' => function ($query) {
|
||||||
$query->field('uid,nickname,avatar');
|
$query->field('uid,nickname,avatar');
|
||||||
},
|
},
|
||||||
]);
|
])->join('product_order_log og', 'StoreOrder.order_id = og.order_id')
|
||||||
|
->where(function($query) {
|
||||||
|
if ($this->streetCode != '') {
|
||||||
|
$query->where('og.street_code', $this->streetCode);
|
||||||
|
} else {
|
||||||
|
$query->where('og.district_code', $this->areaCode);
|
||||||
|
}
|
||||||
|
});
|
||||||
$count = $query->count();
|
$count = $query->count();
|
||||||
$list = $query->page($page, $limit)->select();
|
$list = $query->page($page, $limit)->select();
|
||||||
return app('json')->success(compact('count', 'list'));
|
return app('json')->success(compact('count', 'list'));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user