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(); } }