feat: 添加了订单支付类型余额不足的异常处理和门店统计相关功能的优化

This commit is contained in:
mkm 2024-07-13 17:54:48 +08:00
parent 346b92aa67
commit bded87e5e0
2 changed files with 57 additions and 24 deletions

View File

@ -296,6 +296,9 @@ class OrderLogic extends BaseLogic
if ($params['shipping_type'] == 2) { if ($params['shipping_type'] == 2) {
$_order['status'] = 1; $_order['status'] = 1;
} }
if ($_order['pay_type']==PayEnum::BALANCE_PAY && $user!=null&&$user['now_money'] < $_order['pay_price']) {
throw new \Exception('余额不足');
}
//生成核销码 //生成核销码
$generator = new BarcodeGeneratorPNG(); $generator = new BarcodeGeneratorPNG();
$barcode = $generator->getBarcode($verify_code, $generator::TYPE_CODE_128); $barcode = $generator->getBarcode($verify_code, $generator::TYPE_CODE_128);

View File

@ -5,8 +5,10 @@ namespace app\statistics\controller;
use app\admin\logic\statistic\TradeStatisticLogic; use app\admin\logic\statistic\TradeStatisticLogic;
use app\common\controller\BaseLikeController; use app\common\controller\BaseLikeController;
use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_order\StoreOrder;
use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_order_cart_info\StoreOrderCartInfo;
use app\common\model\store_product\StoreProduct; use app\common\model\store_product\StoreProduct;
use app\common\model\system_store\SystemStore;
use app\common\model\user\User; use app\common\model\user\User;
use app\common\model\user_recharge\UserRecharge; use app\common\model\user_recharge\UserRecharge;
use app\statistics\logic\OrderLogic; use app\statistics\logic\OrderLogic;
@ -63,35 +65,36 @@ class IndexController extends BaseLikeController
/** /**
* 门店统计 * 门店统计
*/ */
public function sotre_count(){ public function sotre_count()
$data=[ {
['street_name'=>'喻寺镇','merchant_count'=>1], $data = [
['street_name'=>'立石镇','merchant_count'=>1], ['street_name' => '喻寺镇', 'merchant_count' => 1],
['street_name'=>'百和镇','merchant_count'=>1], ['street_name' => '立石镇', 'merchant_count' => 1],
['street_name'=>'得胜镇','merchant_count'=>1], ['street_name' => '百和镇', 'merchant_count' => 1],
['street_name'=>'玄滩镇','merchant_count'=>1], ['street_name' => '得胜镇', 'merchant_count' => 1],
['street_name'=>'云锦镇','merchant_count'=>1], ['street_name' => '玄滩镇', 'merchant_count' => 1],
['street_name' => '云锦镇', 'merchant_count' => 1],
]; ];
return $this->success('ok', ['merchatCountList'=>$data,'merchantTotalCount'=>count($data)]); return $this->success('ok', ['merchatCountList' => $data, 'merchantTotalCount' => count($data)]);
} }
public function product_count_sotre_count(){ public function product_count_sotre_count()
$data=[ {
['street_name'=>'喻寺镇','product_count'=>1], $data = [
['street_name'=>'立石镇','product_count'=>1], ['street_name' => '喻寺镇', 'product_count' => 1],
['street_name'=>'百和镇','product_count'=>1], ['street_name' => '立石镇', 'product_count' => 1],
['street_name'=>'得胜镇','product_count'=>1], ['street_name' => '百和镇', 'product_count' => 1],
['street_name'=>'玄滩镇','product_count'=>1], ['street_name' => '得胜镇', 'product_count' => 1],
['street_name'=>'云锦镇','product_count'=>1], ['street_name' => '玄滩镇', 'product_count' => 1],
['street_name' => '云锦镇', 'product_count' => 1],
]; ];
$townProductCount=StoreProduct::count(); $townProductCount = StoreProduct::count();
$product_count=StoreBranchProduct::group('product_id')->order('total_sales desc')->limit(20)->field('image,product_id,store_name,sum(sales) as total_sales')->select(); $product_count = StoreBranchProduct::group('product_id')->order('total_sales desc')->limit(20)->field('image,product_id,store_name,sum(sales) as total_sales')->select();
$productRankingTotal=0; $productRankingTotal = 0;
foreach($product_count as $item){ foreach ($product_count as $item) {
$productRankingTotal+=$item['total_sales']; $productRankingTotal += $item['total_sales'];
} }
return $this->success('ok', ['townProductCountList'=>$data,'productRankingList'=>$product_count,'townProductCount'=>$townProductCount,'productRankingTotal'=>$productRankingTotal]); return $this->success('ok', ['townProductCountList' => $data, 'productRankingList' => $product_count, 'townProductCount' => $townProductCount, 'productRankingTotal' => $productRankingTotal]);
} }
public function user() public function user()
{ {
@ -222,4 +225,31 @@ class IndexController extends BaseLikeController
} }
return $this->success('ok', $res); return $this->success('ok', $res);
} }
public function store_order_day()
{
$arr = SystemStore::where('is_show', 1)->field('id,name street_name')->select()
->each(function($item){
$res = StoreOrder::where('paid', 1)->where('refund_status', 0)->where('store_id', $item['id'])->whereDay('create_time')->field('count(id) count,sum(pay_price) price')->find();
$month = StoreOrder::where('paid', 1)->where('refund_status', 0)->where('store_id', $item['id'])->whereMonth('create_time')->field('count(id) count,sum(pay_price) price')->find();
$item['dayOrderAmount']=$res['price']??0;
$item['dayOrderCount']=$res['count']??0;
$item['monthOrderAmount']=$month['price']??0;
$item['monthOrderCount']=$month['count']??0;
return $item;
});
return $this->success('ok', $arr?->toArray());
}
public function store_order_day_two()
{
$arr = SystemStore::where('is_show', 1)->field('id,name street_name')->select()
->each(function($item){
$today_order_amount = StoreOrder::where('paid', 1)->where('refund_status', 0)->where('store_id', $item['id'])->whereDay('create_time')->sum('pay_price');
$yesterday_order_amount = StoreOrder::where('paid', 1)->where('refund_status', 0)->where('store_id', $item['id'])->whereMonth('create_time','yesterday')->sum('pay_price');
$item['today_order_amount']=$today_order_amount;
$item['yesterday_order_amount']=$yesterday_order_amount;
return $item;
});
return $this->success('ok', $arr?->toArray());
}
} }