This commit is contained in:
chan 2023-12-11 17:34:14 +08:00
commit 5b308017b5
9 changed files with 242 additions and 8 deletions

View File

@ -34,7 +34,7 @@ class SpuDao extends BaseDao
$order = 'S.price ASC';
} else if ($where['order'] == 'price_desc') {
$order = 'S.price DESC';
} else {
}else {
$order = 'P.'.$where['order'] . ' DESC';
}
}elseif($where['order'] == 'star'){

View File

@ -56,6 +56,7 @@ class Login extends BaseController
$msg = '账号或密码错误';
throw new ValidateException($msg);
}
$user['merchant'] = Db::name('merchant')->where('uid', $user['uid'])->find();
$expire = time()+ 3600 * 24;
$token = md5($expire);
// 缓存token

View File

@ -188,4 +188,43 @@ class Logistics extends BaseController
$latestTenOrder = Db::connect('logistics')->name('logistics')->field('receiver_address')->where(['status'=>1, 'courier_id' => $courierId])->order('id', 'desc')->limit(10)->select()->toArray();
return app('json')->success(compact('latestOrder', 'latestTenOrder'));
}
public function logisticsList()
{
$type = $this->request->param('type');
$courierId = $this->request->param('courier_id');
$startTime = $this->request->param('start_time');
$endTime = $this->request->param('end_time');
$list = [];
$count = 0;
if ($type == 1) {
// 待取货
$list = Db::connect('logistics')->name('logistics')->where(['status'=>0, 'courier_id'=>$courierId])->when($startTime&&$endTime,function ($query) use ($startTime, $endTime){
$query->whereBetween('qh_time', [$startTime, $endTime]);
})->select();
$count = Db::connect('logistics')->name('logistics')->where(['status'=>0, 'courier_id'=>$courierId])->when($startTime&&$endTime,function ($query) use ($startTime, $endTime){
$query->whereBetween('qh_time', [$startTime, $endTime]);
})->count();
}
if ($type == 2) {
// 配送中
$list = Db::connect('logistics')->name('logistics')->where(['status'=>1, 'courier_id'=>$courierId])->when($startTime&&$endTime,function ($query) use ($startTime, $endTime){
$query->whereBetween('create_time', [$startTime, $endTime]);
})->select();
$count = Db::connect('logistics')->name('logistics')->where(['status'=>1, 'courier_id'=>$courierId])->when($startTime&&$endTime,function ($query) use ($startTime, $endTime){
$query->whereBetween('create_time', [$startTime, $endTime]);
})->count();
}
if ($type == 3) {
// 已完成
$list = Db::connect('logistics')->name('logistics')->where([['status', 'in', [2,3]], 'courier_id'=>$courierId])->when($startTime&&$endTime,function ($query) use ($startTime, $endTime){
$query->whereBetween('ps_time', [$startTime, $endTime]);
})->select();
$count = Db::connect('logistics')->name('logistics')->where([['status', 'in', [2,3]], 'courier_id'=>$courierId])->when($startTime&&$endTime,function ($query) use ($startTime, $endTime){
$query->whereBetween('ps_time', [$startTime, $endTime]);
})->count();
}
return app('json')->success(compact('count', 'list'));
}
}

View File

@ -2,10 +2,20 @@
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;
use app\common\repositories\system\merchant\MerchantRepository as repository;
use think\App;
use think\facade\Db;
use think\exception\ValidateException;
use think\facade\Cache;
class Merchant extends BaseController
{
@ -37,4 +47,116 @@ class Merchant extends BaseController
$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));
}
// 商户统计
public function merchantCountMain()
{
$merId = $this->request->param('mer_id');
$today = $this->mainGroup('today', $merId);
$yesterday = $this->mainGroup('yesterday', $merId);
$lastWeek = $this->mainGroup(date('Y-m-d', strtotime('- 7day')), $merId);
$lastWeekRate = [];
foreach ($lastWeek as $k => $item) {
if ($item == $today[$k])
$lastWeekRate[$k] = 0;
else if ($item == 0)
$lastWeekRate[$k] = $today[$k];
else if ($today[$k] == 0)
$lastWeekRate[$k] = -$item;
else
$lastWeekRate[$k] = (float)bcdiv(bcsub($today[$k], $item, 4), $item, 4);
}
$day = date('Y-m-d');
return app('json')->success(compact('today', 'yesterday', 'lastWeekRate', 'day'));
}
public function mainGroup($date, $merId)
{
$userVisitRepository = app()->make(UserVisitRepository::class);
$repository = app()->make(StoreOrderRepository::class);
$relationRepository = app()->make(UserRelationRepository::class);
$payPrice = (float)$repository->dayOrderPrice($date, $merId);
$payUser = (float)$repository->dayOrderUserNum($date, $merId);
$visitNum = (float)$userVisitRepository->dateVisitUserNum($date, $merId);
$likeStore = (float)$relationRepository->dayLikeStore($date, $merId);
$productNum = \think\facade\Db::name('store_product')->alias('p')->field('count(p.product_id) as think_count')
->join('merchant m', 'm.mer_id = p.mer_id')
->whereTime('p.create_time', '<=', $date)
->where('m.mer_id', $merId)
->count();
// 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);
}
public function merchant()
{
$merId = $this->request->param('mer_id');
$merchant = Db::name('merchant')->where('mer_id', $merId)->find();
return app('json')->success(compact('merchant'));
}
}

View File

@ -4,6 +4,7 @@ namespace app\controller\api\dataview;
use app\common\dao\store\order\StoreOrderDao;
use app\common\dao\store\order\StoreRefundOrderDao;
use app\common\model\store\order\StoreOrder;
use app\common\repositories\BaseRepository;
use app\common\repositories\store\order\StoreOrderRepository;
use app\common\repositories\store\order\StoreRefundOrderRepository;
@ -563,7 +564,7 @@ class Order extends BaseController
{
[$page,$limit] = $this->getPage();
$where = $this->request->params(['refund_order_sn','status','refund_type','date','mer_id','order_sn','is_trader']);
$list = $repository->getAllList($where, $page, $limit)
$list = $repository->getAllList($where, $page, $limit);
foreach($list as &$item) {
$userAddressCode = explode(',', $item['order']['user_address_code']);
$area = Db::name('geo_area')->where('area_code', $userAddressCode[0])->value('area_name');
@ -585,7 +586,7 @@ class Order extends BaseController
unset($where['date']);
$status = $where['status'];
unset($where['status']);
$query = $dao->search($where, null)->where($repository->getOrderType($status))>with([
$query = $dao->search($where, null)->where($repository->getOrderType($status))->with([
'orderProduct',
'merchant' => function ($query) {
return $query->field('mer_id,mer_name,is_trader');
@ -596,10 +597,10 @@ class Order extends BaseController
'user' => function ($query) {
$query->field('uid,nickname,avatar');
},
]);;
]);
$count = $query->count();
$list = $query->page($page, $limit)->select();
foreach($list as $item) {
foreach($list as &$item) {
$userAddressCode = explode(',', $item['user_address_code']);
$area = Db::name('geo_area')->where('area_code', $userAddressCode[0])->value('area_name');
$street = Db::name('geo_street')->where('street_code', $userAddressCode[0])->value('street_name');
@ -621,4 +622,68 @@ class Order extends BaseController
return app('json')->success($data);
}
public function orderUserNumCount()
{
// 订单数
$orderNum = $this->dayOrderNum('today');
$yesterdayNum = $this->dayOrderNum('yesterday');
$monthOrderNum = $this->dayOrderNum(date('Y/m/d', strtotime('first day of')) . ' 00:00:00' . '-' . date('Y/m/d H:i:s'));
$date = date('Y/m/01 00:00:00', strtotime('last Month')) . '-' . date('Y/m/d 00:00:00', strtotime('-1 day', strtotime('first day of')));
$beforeOrderNum = $this->dayOrderNum($date);
$monthOrderNumRate = $this->getRate($beforeOrderNum, $monthOrderNum);
$orderNumRate = $this->getRate($yesterdayNum, $orderNum);
// 支付数
$orderPayNum = $this->dayOrderUserNum('today');
$yesterdayNum = $this->dayOrderUserNum('yesterday');
$monthOrderPayNum = $this->dayOrderUserNum(date('Y/m/d', strtotime('first day of')) . ' 00:00:00' . '-' . date('Y/m/d H:i:s'));
$date = gmdate('Y/m/01 00:00:00', strtotime('last Month')) . '-' . date('Y/m/d 00:00:00', strtotime('-1 day', strtotime('first day of')));
$beforeOrderNum = $this->dayOrderUserNum($date);
$monthOrderPayRate = $this->getRate($beforeOrderNum, $monthOrderNum);
$orderOrderPayRate = $this->getRate($yesterdayNum, $orderNum);
return app('json')->success(compact('orderNum', 'monthOrderNum', 'monthOrderNumRate', 'orderNumRate', 'orderPayNum', 'monthOrderPayNum', 'monthOrderPayRate', 'orderOrderPayRate'));
}
public function dayOrderNum($day)
{
return StoreOrder::getDB()->alias('o')
->join('product_order_log pog', 'o.order_id=pog.order_id')
->where('o.paid', 1)
->when($day, function ($query, $day) {
getModelTime($query, $day, 'o.pay_time');
})
->where('pog.street_code', $this->streetCode)
->count();
}
public function dayOrderUserNum($day, $merId = null)
{
return StoreOrder::getDB()->alias('o')
->join('product_order_log pog', 'o.order_id=pog.order_id')
->where('o.paid', 1)
->when($day, function ($query, $day) {
getModelTime($query, $day, 'o.pay_time');
})
->where('pog.street_code', $this->streetCode)->group('o.uid')->count();
}
protected function getRate($last, $today, $scale = 2)
{
if ($last == $today)
return 0;
else if ($last == 0)
return $today;
else if ($today == 0)
return -$last;
else
return (float)bcdiv(bcsub($today, $last, $scale), $last, $scale);
}
}

View File

@ -73,7 +73,7 @@ class User extends BaseController
$merchantTotalCount = 0;
// 查镇的用户统计不需要查店铺数
if ($this->streetCode != '') {
if ($this->streetCode == '') {
// 该地区下所有乡镇
$geoStreetList = Db::name('geo_street')->where('area_code',$this->areaCode)->select()->toArray();

View File

@ -71,7 +71,7 @@ class StoreSpu extends BaseController
unset($where['type_id'], $where['street_id']);
$where['is_gift_bag'] = 0;
$where['product_type'] = 0;
$where['product_type'] = $where['product_type']??0;
$where['order'] = $where['order'] ?: 'star';
if ($where['is_trader'] != 1) unset($where['is_trader']);
$data = $this->repository->getApiSearch($where, $page, $limit, $this->userInfo);

View File

@ -87,7 +87,7 @@ class StoreImport extends BaseController
$file = $this->request->file('file');
if (!$file) return app('json')->fail('请上传EXCEL文件');
$file = is_array($file) ? $file[0] : $file;
validate(["file|文件" => ['fileExt' => 'xlsx',]])->check(['file' => $file]);
validate(["file|文件" => ['fileExt' => 'xlsx',]],['请上传xlsx后缀的文件'])->check(['file' => $file]);
$upload = UploadService::create(1);
$ret = $upload->to('excel')->move('file');
if ($ret === false) return app('json')->fail($upload->getError());

View File

@ -727,6 +727,7 @@ Route::group('api/', function () {
Route::get('latest_logistics', 'Logistics/latestLogistics');
Route::get('logistics_count', 'Logistics/logisticsCount');
Route::get('logistics_map_count', 'Logistics/logisticsMapCount');
Route::get('logistics_list', 'Logistics/logisticsList');
/**---------------------物流溯源监控大屏api---------------------- end **/
@ -742,6 +743,7 @@ Route::group('api/', function () {
Route::get('take_order_list', 'Order/takeOrderList');
Route::get('take_order_count_title', 'Order/takeOrderCountTitle');
Route::get('street_currday_order_count', 'Order/streetCurrDayOrderCount');
Route::get('order_user_num_count', 'Order/orderUserNumCount');
// api.dataview.User
Route::get('user_merchat_count', 'User/userMerchantCount');
@ -756,6 +758,11 @@ 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');
Route::get('merchant', 'Merchant/merchant');
// api.dataview.Finance
Route::get('withdraw_list', 'Finance/withdrawList');