Merge pull request 'dev' (#102) from dev into master

Reviewed-on: #102
This commit is contained in:
mkm 2023-12-19 21:17:47 +08:00
commit d826db5775
2 changed files with 125 additions and 44 deletions

View File

@ -2,6 +2,7 @@
namespace app\controller\api\dataview;
use app\common\dao\system\merchant\MerchantDao;
use app\common\model\store\order\StoreOrderProduct;
use app\common\model\store\product\Product as model;
use app\common\model\user\UserVisit;
@ -45,7 +46,34 @@ class Merchant extends BaseController
{
[$page, $limit] = $this->getPage();
$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');
$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);
$endDate = date("$endDate H:i:s", time());
// $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));
$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)
@ -114,20 +152,31 @@ class Merchant extends BaseController
$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);
$endDate = date("$endDate H:i:s", time());
// $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));
$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)
@ -135,21 +184,31 @@ class Merchant extends BaseController
$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);
$endDate = date("$endDate H:i:s", time());
// $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));
$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()

View File

@ -456,6 +456,14 @@ class Order extends BaseController
->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 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')
->order('total_sales DESC')
->limit(10)
@ -470,6 +478,13 @@ class Order extends BaseController
$merchantRankingList = Db::name('store_order')->alias('o')
->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`')
->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')
->order('total_sales DESC')
->limit(10)
@ -544,7 +559,14 @@ class Order extends BaseController
'user' => function ($query) {
$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();
$list = $query->page($page, $limit)->select();
return app('json')->success(compact('count', 'list'));