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/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..c45941805 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; @@ -54,7 +56,7 @@ class IndexController extends BaseLikeController $title = '云锦镇农(特)产品交易大数据'; break; default: - $title = '百合镇农(特)产品交易大数据'; + $title = '泸县农(特)产品交易大数据'; break; } return $this->success('ok', ['dayPayPrice' => $res, 'title' => $title]); @@ -63,35 +65,39 @@ 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' => 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(); - $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 +228,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()); + } } diff --git a/app/statistics/logic/ProductLogic.php b/app/statistics/logic/ProductLogic.php index 06be8df22..0fe9585ed 100644 --- a/app/statistics/logic/ProductLogic.php +++ b/app/statistics/logic/ProductLogic.php @@ -4,26 +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(); $data = [ "totalProductCounInfo" => [ "todayProductCount" => $todayProductCount, @@ -36,16 +51,17 @@ class ProductLogic extends BaseLogic "weeklyNewProductTotalGrowthRate" => $weeklyNewProductTotalGrowthRate ], "merchantCountInfo" => [ - "todayMerchantCount" => 1, - "yestertodayMerchantCount" => 1, + "todayMerchantCount" => $todayMerchantCount, + "yestertodayMerchantCount" => $yestertodayMerchantCount, "weeklyMerchantGrowthRate" => 0 ] ]; 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(); } } 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'];