From bded87e5e09fda2cc39bd5d0ee820a3c6d2c3d0c Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 13 Jul 2024 17:54:48 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E6=94=AF=E4=BB=98=E7=B1=BB=E5=9E=8B=E4=BD=99?= =?UTF-8?q?=E9=A2=9D=E4=B8=8D=E8=B6=B3=E7=9A=84=E5=BC=82=E5=B8=B8=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=92=8C=E9=97=A8=E5=BA=97=E7=BB=9F=E8=AE=A1=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E5=8A=9F=E8=83=BD=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/order/OrderLogic.php | 3 + app/statistics/controller/IndexController.php | 78 +++++++++++++------ 2 files changed, 57 insertions(+), 24 deletions(-) diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 2e98524de..ad7de5414 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -296,6 +296,9 @@ class OrderLogic extends BaseLogic if ($params['shipping_type'] == 2) { $_order['status'] = 1; } + if ($_order['pay_type']==PayEnum::BALANCE_PAY && $user!=null&&$user['now_money'] < $_order['pay_price']) { + throw new \Exception('余额不足'); + } //生成核销码 $generator = new BarcodeGeneratorPNG(); $barcode = $generator->getBarcode($verify_code, $generator::TYPE_CODE_128); diff --git a/app/statistics/controller/IndexController.php b/app/statistics/controller/IndexController.php index c68847701..1723c9374 100644 --- a/app/statistics/controller/IndexController.php +++ b/app/statistics/controller/IndexController.php @@ -5,8 +5,10 @@ namespace app\statistics\controller; use app\admin\logic\statistic\TradeStatisticLogic; use app\common\controller\BaseLikeController; 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_product\StoreProduct; +use app\common\model\system_store\SystemStore; use app\common\model\user\User; use app\common\model\user_recharge\UserRecharge; use app\statistics\logic\OrderLogic; @@ -63,35 +65,36 @@ class IndexController extends BaseLikeController /** * 门店统计 */ - public function sotre_count(){ - $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], + public function sotre_count() + { + $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], ]; - return $this->success('ok', ['merchatCountList'=>$data,'merchantTotalCount'=>count($data)]); + return $this->success('ok', ['merchatCountList' => $data, 'merchantTotalCount' => count($data)]); } - public function product_count_sotre_count(){ - $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], + public function product_count_sotre_count() + { + $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], ]; - $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(); - $productRankingTotal=0; - foreach($product_count as $item){ - $productRankingTotal+=$item['total_sales']; + $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(); + $productRankingTotal = 0; + foreach ($product_count as $item) { + $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() { @@ -222,4 +225,31 @@ class IndexController extends BaseLikeController } 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()); + } } From 551f98d4605655146ac14102d0f67f4f15d44b37 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 13 Jul 2024 18:00:44 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9IndexController?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E6=95=B0=E6=8D=AE=E6=A0=87=E9=A2=98=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/statistics/controller/IndexController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/statistics/controller/IndexController.php b/app/statistics/controller/IndexController.php index 1723c9374..171cb05fd 100644 --- a/app/statistics/controller/IndexController.php +++ b/app/statistics/controller/IndexController.php @@ -56,7 +56,7 @@ class IndexController extends BaseLikeController $title = '云锦镇农(特)产品交易大数据'; break; default: - $title = '百合镇农(特)产品交易大数据'; + $title = '泸县农(特)产品交易大数据'; break; } return $this->success('ok', ['dayPayPrice' => $res, 'title' => $title]); From 15717de1d5ee7319dd7a75e056f551dd49eba932 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 15 Jul 2024 10:18:24 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat(statistics):=20=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E5=BA=97=E9=93=BAID=E7=BB=9F=E8=AE=A1=E5=9C=B0=E6=96=B9?= =?UTF-8?q?=E5=95=86=E5=93=81=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/statistics/controller/IndexController.php | 15 +++++++++------ app/statistics/logic/ProductLogic.php | 8 ++++++-- .../store_order/StoreOrderController.php | 1 + 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/statistics/controller/IndexController.php b/app/statistics/controller/IndexController.php index 171cb05fd..c45941805 100644 --- a/app/statistics/controller/IndexController.php +++ b/app/statistics/controller/IndexController.php @@ -78,15 +78,18 @@ class IndexController extends BaseLikeController return $this->success('ok', ['merchatCountList' => $data, 'merchantTotalCount' => count($data)]); } + /** + * 地方商品数量统计 + */ public function product_count_sotre_count() { $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' => StoreBranchProduct::where('store_id',1)->count()], + ['street_name' => '立石镇', 'product_count' => StoreBranchProduct::where('store_id',2)->count()], + ['street_name' => '百和镇', 'product_count' => StoreBranchProduct::where('store_id',3)->count()], + ['street_name' => '得胜镇', 'product_count' => StoreBranchProduct::where('store_id',5)->count()], + ['street_name' => '玄滩镇', 'product_count' => StoreBranchProduct::where('store_id',6)->count()], + ['street_name' => '云锦镇', 'product_count' => StoreBranchProduct::where('store_id',7)->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(); diff --git a/app/statistics/logic/ProductLogic.php b/app/statistics/logic/ProductLogic.php index 06be8df22..e8f04ba30 100644 --- a/app/statistics/logic/ProductLogic.php +++ b/app/statistics/logic/ProductLogic.php @@ -4,6 +4,7 @@ namespace app\statistics\logic; use app\common\logic\BaseLogic; use app\common\model\store_branch_product\StoreBranchProduct; +use app\common\model\system_store\SystemStore; class ProductLogic extends BaseLogic { @@ -24,6 +25,9 @@ class ProductLogic extends BaseLogic } else { $weeklyNewProductTotalGrowthRate =bcdiv(($todayNewProductCount - $yestertodayNewProductCount),$yestertodayNewProductCount) * 100; } + $todayMerchantCount=SystemStore::where($where)->whereDay('create_time',$time)->count(); + $where['is_show']=1; + $yestertodayMerchantCount=SystemStore::where($where)->count(); $data = [ "totalProductCounInfo" => [ "todayProductCount" => $todayProductCount, @@ -36,8 +40,8 @@ class ProductLogic extends BaseLogic "weeklyNewProductTotalGrowthRate" => $weeklyNewProductTotalGrowthRate ], "merchantCountInfo" => [ - "todayMerchantCount" => 1, - "yestertodayMerchantCount" => 1, + "todayMerchantCount" => $todayMerchantCount, + "yestertodayMerchantCount" => $yestertodayMerchantCount, "weeklyMerchantGrowthRate" => 0 ] ]; diff --git a/app/store/controller/store_order/StoreOrderController.php b/app/store/controller/store_order/StoreOrderController.php index 6f1de710e..5cf8e9560 100644 --- a/app/store/controller/store_order/StoreOrderController.php +++ b/app/store/controller/store_order/StoreOrderController.php @@ -416,6 +416,7 @@ class StoreOrderController extends BaseAdminController 'price' => $params['price'], 'recharge_type' => 'INDUSTRYMEMBERS', 'user_ship'=>$params['user_ship']??0, + 'type'=>1, ]; $order = UserRecharge::create($data); $order['pay_price'] = $order['price']; From 443a50b0fedee7f5f7eeb2a3adeecc107dbc4200 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 15 Jul 2024 12:20:20 +0800 Subject: [PATCH 4/4] =?UTF-8?q?feat(ProductLogic):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=96=B0=E5=8A=9F=E8=83=BD=E4=BB=A5=E8=AE=A1=E7=AE=97=E5=BA=97?= =?UTF-8?q?=E9=93=BA=E4=BA=A7=E5=93=81=E9=94=80=E5=94=AE=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logic/store_product/StoreProductLogic.php | 3 +- app/api/controller/DemoOrderController.php | 105 ++++++++++++++++++ app/statistics/logic/ProductLogic.php | 42 ++++--- 3 files changed, 134 insertions(+), 16 deletions(-) create mode 100644 app/api/controller/DemoOrderController.php diff --git a/app/admin/logic/store_product/StoreProductLogic.php b/app/admin/logic/store_product/StoreProductLogic.php index 38ee89a68..a6bfde633 100644 --- a/app/admin/logic/store_product/StoreProductLogic.php +++ b/app/admin/logic/store_product/StoreProductLogic.php @@ -211,7 +211,8 @@ class StoreProductLogic extends BaseLogic 'manufacturer_information' => $params['manufacturer_information']??'', 'store_info' => $params['store_info']??'','cate_id'=>$params['cate_id'], 'top_cate_id'=>$dealCate['top_cate_id'],'two_cate_id'=>$dealCate['two_cate_id'], - 'bar_code'=> $params['bar_code'] + 'bar_code'=> $params['bar_code'], + 'purchase'=> $params['purchase'], ]); Db::commit(); diff --git a/app/api/controller/DemoOrderController.php b/app/api/controller/DemoOrderController.php new file mode 100644 index 000000000..b97c4037b --- /dev/null +++ b/app/api/controller/DemoOrderController.php @@ -0,0 +1,105 @@ +request->post('cart_id', []); + $addressId = (int)$this->request->post('address_id'); + // $pay_type = (int)$this->request->post('pay_type'); + // $auth_code = $this->request->post('auth_code'); //微信支付条码 + $params = $this->request->post(); + $user = User::where('id', $this->userId)->find(); + $res = OrderLogic::cartIdByOrderInfo($cartId, $addressId, $user, $params); + if ($res == false) { + $msg = OrderLogic::getError(); + if ($msg == '购物车为空') { + return $this->data([]); + } + return $this->fail(OrderLogic::getError()); + } + return $this->data($res); + } + + + /** + * 创建订单 + */ + public function createOrder() + { + $cartId = (array)$this->request->post('cart_id', []); + $store_id = (array)$this->request->post('store_id', 0); + $pay_type = (int)$this->request->post('pay_type'); + $addressId = (int)$this->request->post('address_id'); + $auth_code = $this->request->post('auth_code'); //微信支付条码 + $params = $this->request->post(); + if ($store_id <= 0 && $pay_type != 9) { + return $this->fail('自提点不能为空'); + } + if (count($cartId) > 100) { + return $this->fail('购物车商品不能超过100个'); + } + + $user = User::where('id', $this->userId)->find(); + if ($pay_type == PayEnum::PURCHASE_FUNDS || $pay_type == PayEnum::BALANCE_PAY) { + if (!isset($params['password'])) { + return $this->fail('缺失参数'); + } + if (empty($user['pay_password'])) { + return $this->fail('请设置密码'); + } + if (!password_verify($params['password'], $user['pay_password'])) { + return $this->fail('密码错误'); + } + } + + $order = OrderLogic::createOrder($cartId, $addressId, $user, $params); + if ($order != false) { + if ($order['pay_price'] <= 0) { + $pay_type = 3; + } + switch ($pay_type) { + case PayEnum::PURCHASE_FUNDS: + //采购款支付 + PayNotifyLogic::handle('purchase_funds', $order['order_id']); + return $this->success('采购款支付成功'); + case PayEnum::BALANCE_PAY: + //余额支付 + PayNotifyLogic::handle('balancePay', $order['order_id']); + return $this->success('余额支付成功'); + case PayEnum::CASH_PAY: + //现金支付 + PayNotifyLogic::handle('cash_pay', $order['order_id']); + return $this->success('现金支付成功'); + case PayEnum::WECHAT_PAY_MINI: + //微信小程序支付 + PayNotifyLogic::handle('wechat_common', $order['order_id']); + return $this->success('微信小程序支付成功'); + case PayEnum::WECHAT_PAY_BARCODE: + //微信条码支付 + PayNotifyLogic::handle('wechat_common', $order['order_id'], $order); + return $this->success('微信条码支付成功'); + case PayEnum::ALIPAY_BARCODE: + //支付宝条码支付 + PayNotifyLogic::handle('alipay_cashier', $order['order_id'], $order); + return $this->success('支付宝条码支付成功' ); + default: + return $this->fail('支付方式错误'); + } + // return $this->data(['order_id' => $order->id]); + } else { + return $this->fail(OrderLogic::getError()); + } + } +} diff --git a/app/statistics/logic/ProductLogic.php b/app/statistics/logic/ProductLogic.php index e8f04ba30..0fe9585ed 100644 --- a/app/statistics/logic/ProductLogic.php +++ b/app/statistics/logic/ProductLogic.php @@ -4,30 +4,41 @@ namespace app\statistics\logic; use app\common\logic\BaseLogic; use app\common\model\store_branch_product\StoreBranchProduct; +use app\common\model\store_product\StoreProduct; use app\common\model\system_store\SystemStore; class ProductLogic extends BaseLogic { - public static function Count($where,$time) + public static function Count($where, $time) { - $todayProductCount=StoreBranchProduct::where($where)->whereDay('create_time',$time)->count(); - $yestertodayProductCount=StoreBranchProduct::where($where)->where('create_time', '<',strtotime($time)-1)->count(); - if ($yestertodayProductCount == 0 ||$todayProductCount==0) { - $weeklyProductTotalGrowthRate = 0; + if (isset($where['store_id']) && $where['store_id'] > 0) { + $todayProductCount = StoreBranchProduct::where($where)->whereDay('create_time', $time)->count(); + $yestertodayProductCount = StoreBranchProduct::where($where)->where('create_time', '<', strtotime($time) - 1)->count(); + $todayNewProductCount = StoreBranchProduct::where($where)->whereDay('create_time', $time)->count(); + $yestertodayNewProductCount = StoreBranchProduct::where($where)->whereDay('create_time', date('Y-m-d', strtotime($time) - 1))->count(); } else { - $weeklyProductTotalGrowthRate =bcdiv(($todayProductCount - $yestertodayProductCount) ,$yestertodayProductCount) * 100; + $todayProductCount = StoreProduct::whereDay('create_time', $time)->count(); + $yestertodayProductCount = StoreProduct::count(); + + $todayNewProductCount = StoreProduct::whereDay('create_time', $time)->count(); + $yestertodayNewProductCount = StoreProduct::whereDay('create_time', date('Y-m-d', strtotime($time) - 1))->count(); } - $todayNewProductCount=StoreBranchProduct::where($where)->whereDay('create_time',$time)->count(); - $yestertodayNewProductCount=StoreBranchProduct::where($where)->whereDay('create_time', date('Y-m-d',strtotime($time)-1))->count(); - if ($todayNewProductCount == 0 ||$yestertodayNewProductCount==0) { + if ($yestertodayProductCount == 0 || $todayProductCount == 0) { + $weeklyProductTotalGrowthRate = 0; + } else { + $weeklyProductTotalGrowthRate = bcdiv(($todayProductCount - $yestertodayProductCount), $yestertodayProductCount) * 100; + } + + + if ($todayNewProductCount == 0 || $yestertodayNewProductCount == 0) { $weeklyNewProductTotalGrowthRate = 0; } else { - $weeklyNewProductTotalGrowthRate =bcdiv(($todayNewProductCount - $yestertodayNewProductCount),$yestertodayNewProductCount) * 100; + $weeklyNewProductTotalGrowthRate = bcdiv(($todayNewProductCount - $yestertodayNewProductCount), $yestertodayNewProductCount) * 100; } - $todayMerchantCount=SystemStore::where($where)->whereDay('create_time',$time)->count(); - $where['is_show']=1; - $yestertodayMerchantCount=SystemStore::where($where)->count(); + $todayMerchantCount = SystemStore::where($where)->whereDay('create_time', $time)->count(); + $where['is_show'] = 1; + $yestertodayMerchantCount = SystemStore::where($where)->count(); $data = [ "totalProductCounInfo" => [ "todayProductCount" => $todayProductCount, @@ -48,8 +59,9 @@ class ProductLogic extends BaseLogic return $data; } - public static function sales($where){ - $select=StoreBranchProduct::where($where)->limit(10)->order('sales desc')->field('id,store_name,image,sales')->select(); + public static function sales($where) + { + $select = StoreBranchProduct::where($where)->limit(10)->order('sales desc')->field('id,store_name,image,sales')->select(); return $select?->toArray(); } }