From e706d91c9ddfc83864bc366bcb2d6e136ee292a8 Mon Sep 17 00:00:00 2001 From: ztt <835303992@qq.com> Date: Tue, 27 Feb 2024 22:42:15 +0800 Subject: [PATCH 1/5] 1 --- app/api/service/statistics/CommissionData.php | 10 +- app/api/service/statistics/Data.php | 8 +- app/api/service/statistics/OrderData.php | 96 +++++++++++++++++-- app/api/service/statistics/RefundData.php | 11 ++- app/api/service/statistics/UserData.php | 10 +- 5 files changed, 122 insertions(+), 13 deletions(-) diff --git a/app/api/service/statistics/CommissionData.php b/app/api/service/statistics/CommissionData.php index 7b75de5f..7f2aa497 100644 --- a/app/api/service/statistics/CommissionData.php +++ b/app/api/service/statistics/CommissionData.php @@ -2,11 +2,19 @@ namespace app\api\service\statistics; +use app\api\model\dealer\Order; use app\common\service\BaseService; class CommissionData extends BaseService { - public function getCommissionData(): array + protected Order $dealerOrderModel; + + public function initialize() + { + parent::initialize(); // TODO: Change the autogenerated stub + $this->dealerOrderModel = new Order(); + } + public function getCommissionData($startDate = null, $endDate = null): array { return [ 'settleTotalMoney' => 0, diff --git a/app/api/service/statistics/Data.php b/app/api/service/statistics/Data.php index cd583309..8ef1fa27 100644 --- a/app/api/service/statistics/Data.php +++ b/app/api/service/statistics/Data.php @@ -17,7 +17,7 @@ class Data extends BaseService * @return mixed */ public function getOrderData($startDate = null, $endDate = null): array { - return (new OrderData())->getOrderData(); + return (new OrderData())->getOrderData($startDate = null, $endDate = null); } /** @@ -25,7 +25,7 @@ class Data extends BaseService * @return mixed */ public function getRefundData($startDate = null, $endDate = null): array { - return (new RefundData())->getRefundData(); + return (new RefundData())->getRefundData($startDate = null, $endDate = null); } /** @@ -33,7 +33,7 @@ class Data extends BaseService * @return mixed */ public function getUserData($startDate = null, $endDate = null): array { - return (new UserData())->getUserData(); + return (new UserData())->getUserData($startDate = null, $endDate = null); } /** @@ -41,6 +41,6 @@ class Data extends BaseService * @return mixed */ public function getCommissionData($startDate = null, $endDate = null) : array{ - return (new CommissionData())->getCommissionData(); + return (new CommissionData())->getCommissionData($startDate = null, $endDate = null); } } \ No newline at end of file diff --git a/app/api/service/statistics/OrderData.php b/app/api/service/statistics/OrderData.php index ad75c1c0..7dc3029e 100644 --- a/app/api/service/statistics/OrderData.php +++ b/app/api/service/statistics/OrderData.php @@ -2,19 +2,32 @@ namespace app\api\service\statistics; +use app\api\model\Order; +use app\common\enum\order\OrderStatus; +use app\common\enum\order\OrderStatus as OrderStatusEnum; +use app\common\enum\order\PayStatus as PayStatusEnum; use app\common\service\BaseService; class OrderData extends BaseService { - public function getOrderData(): array + //查询对象 + protected Order $orderModel; + + public function initialize() + { + parent::initialize(); + $this->orderModel = new Order(); + } + + public function getOrderData($startDate = null, $endDate = null): array { return [ //订单金额 - "orderMoney" => 0, - //订单数 - "orderCount" => 0, - //支持人数 - 'orderPayUser' => 0, + "orderMoney" => $this->getOrderTotalPrice($startDate, $endDate), + //下单总数 + "orderCount" => $this->getPayOrderTotal($startDate, $endDate), + //下单人数 + 'orderPayUser' => $this->getConsumeUsers($startDate, $endDate), //订单成本金额 'orderCostMoney' => 0, //预估利益 @@ -25,4 +38,75 @@ class OrderData extends BaseService 'payDealerCount' => 0 ]; } + + /** + * 获取某天的总销售额 + * @param null $startDate + * @param null $endDate + * @return float + */ + public function getOrderTotalPrice($startDate = null, $endDate = null): float + { + // 查询对象 + $query = $this->orderModel; + // 设置查询条件 + if (!is_null($startDate) && !is_null($endDate)) { + $query->where('pay_time', '>=', strtotime($startDate)) + ->where('pay_time', '<', strtotime($endDate) + 86400); + } + // 总销售额 + return $query->where('pay_status', '=', PayStatusEnum::SUCCESS) + ->where('order_status', '<>', OrderStatusEnum::CANCELLED) + ->where('is_delete', '=', 0) + ->sum('pay_price'); + } + + /** + * 消费人数 + * @param null $startDate + * @param null $endDate + * @return string + */ + public function getConsumeUsers($startDate = null, $endDate = null): string + { + // 检索查询条件 + $filter = []; + if (!is_null($startDate) && !is_null($endDate)) { + $filter[] = ['pay_time', '>=', strtotime($startDate)]; + $filter[] = ['pay_time', '<', strtotime($endDate) + 86400]; + } + // 查询总记录 + $value = $this->orderModel->field('user_id') + ->where($filter) + ->where('pay_status', '=', PayStatusEnum::SUCCESS) + // ->where('order_status', '<>', OrderStatusEnum::CANCELLED) + ->where('is_delete', '=', '0') + ->group('user_id') + ->count(); + return number_format($value); + } + + /** + * 获取已付款订单总数 (可指定某天) + * @param null $startDate + * @param null $endDate + * @return int + */ + public function getPayOrderTotal($startDate = null, $endDate = null): int + { + $filter = [ + ['pay_status', '=', PayStatusEnum::SUCCESS], + ['order_status', '<>', OrderStatusEnum::CANCELLED] + ]; + if (!is_null($startDate) && !is_null($endDate)) { + $filter[] = ['pay_time', '>=', strtotime($startDate)]; + $filter[] = ['pay_time', '<', strtotime($endDate) + 86400]; + } + // 获取订单总数量 + return $this->orderModel->where($filter) + ->where('is_delete', '=', 0) + ->count(); + } + + } \ No newline at end of file diff --git a/app/api/service/statistics/RefundData.php b/app/api/service/statistics/RefundData.php index 681d8e56..716a5099 100644 --- a/app/api/service/statistics/RefundData.php +++ b/app/api/service/statistics/RefundData.php @@ -2,11 +2,20 @@ namespace app\api\service\statistics; +use app\api\model\OrderRefund; use app\common\service\BaseService; class RefundData extends BaseService { - public function getRefundData(): array + protected OrderRefund $refundModel; + + public function initialize() + { + parent::initialize(); // TODO: Change the autogenerated stub + $this->refundModel = new OrderRefund(); + } + + public function getRefundData($startDate = null, $endDate = null): array { return [ 'refundCount' => 0, diff --git a/app/api/service/statistics/UserData.php b/app/api/service/statistics/UserData.php index 44bf0eab..1249f02e 100644 --- a/app/api/service/statistics/UserData.php +++ b/app/api/service/statistics/UserData.php @@ -2,11 +2,19 @@ namespace app\api\service\statistics; +use app\api\model\User; use app\common\service\BaseService; class UserData extends BaseService { - public function getUserData(): array + protected User $userModel; + + public function initialize() + { + parent::initialize(); // TODO: Change the autogenerated stub + $this->userModel = new User(); + } + public function getUserData($startDate = null, $endDate = null): array { return [ 'visitorCount' => 0, From dee8e4f863c08034929908d4c9ba3494bb4682d0 Mon Sep 17 00:00:00 2001 From: ztt <835303992@qq.com> Date: Tue, 27 Feb 2024 23:23:30 +0800 Subject: [PATCH 2/5] 1 --- app/api/service/statistics/OrderData.php | 20 ++++++++++++--- app/api/service/statistics/RefundData.php | 31 +++++++++++++++++++++-- app/api/service/statistics/UserData.php | 31 ++++++++++++++++++++++- 3 files changed, 76 insertions(+), 6 deletions(-) diff --git a/app/api/service/statistics/OrderData.php b/app/api/service/statistics/OrderData.php index 7dc3029e..e9c1005e 100644 --- a/app/api/service/statistics/OrderData.php +++ b/app/api/service/statistics/OrderData.php @@ -3,9 +3,11 @@ namespace app\api\service\statistics; use app\api\model\Order; +use app\api\model\user\IdentityOrder; use app\common\enum\order\OrderStatus; use app\common\enum\order\OrderStatus as OrderStatusEnum; use app\common\enum\order\PayStatus as PayStatusEnum; +use app\common\enum\user\IdentityEnum; use app\common\service\BaseService; class OrderData extends BaseService @@ -27,15 +29,15 @@ class OrderData extends BaseService //下单总数 "orderCount" => $this->getPayOrderTotal($startDate, $endDate), //下单人数 - 'orderPayUser' => $this->getConsumeUsers($startDate, $endDate), + 'orderPayUser' => $this->getConsumeUsers(), //订单成本金额 'orderCostMoney' => 0, //预估利益 'orderInterest' => 0, //付费会员数 - 'payMemberCount' => 0, + 'payMemberCount' => $this->getPayCount(IdentityEnum::MEMBER, $startDate, $endDate), //付费分销商数 - 'payDealerCount' => 0 + 'payDealerCount' => $this->getPayCount(IdentityEnum::DEALER, $startDate, $endDate) ]; } @@ -108,5 +110,17 @@ class OrderData extends BaseService ->count(); } + /** + * 付费会员数 + */ + public function getPayCount($order_type, $startDate = null, $endDate = null) : int { + $query = new IdentityOrder(); + if(!empty($startDate) && !empty($endDate)) { + $query->where('create_time', '>=', strtotime($startDate)) + ->where('create_time', '<', strtotime($endDate) + 86400); + } + return $query->where('order_type', '=', $order_type)->count(); + } + } \ No newline at end of file diff --git a/app/api/service/statistics/RefundData.php b/app/api/service/statistics/RefundData.php index 716a5099..2271a279 100644 --- a/app/api/service/statistics/RefundData.php +++ b/app/api/service/statistics/RefundData.php @@ -3,6 +3,7 @@ namespace app\api\service\statistics; use app\api\model\OrderRefund; +use app\common\enum\order\refund\RefundStatus; use app\common\service\BaseService; class RefundData extends BaseService @@ -18,8 +19,34 @@ class RefundData extends BaseService public function getRefundData($startDate = null, $endDate = null): array { return [ - 'refundCount' => 0, - 'refundTotalMoney' => 0 + 'refundCount' => $this->getRefundCount($startDate, $endDate), + 'refundTotalMoney' => $this->getRefundTotalMoney($startDate, $endDate) ]; } + + /** + * 退款总数 + */ + public function getRefundCount($startDate = null, $endDate = null): int + { + $query = $this->refundModel; + if(!empty($startDate) && !empty($endDate)) { + $query->where('create_time', '>=', strtotime($startDate)) + ->where('create_time', '<', strtotime($endDate) + 86400); + } + return $query->where('status', '=', RefundStatus::COMPLETED)->count(); + } + + /** + * 退款总金额 + */ + public function getRefundTotalMoney($startDate = null, $endDate = null): float { + $query = $this->refundModel; + if(!empty($startDate) && !empty($endDate)) { + $query->where('create_time', '>=', strtotime($startDate)) + ->where('create_time', '<', strtotime($endDate) + 86400); + } + // 总销售额 + return $query->where('status', '=', RefundStatus::COMPLETED)->sum('refund_money'); + } } \ No newline at end of file diff --git a/app/api/service/statistics/UserData.php b/app/api/service/statistics/UserData.php index 1249f02e..39622583 100644 --- a/app/api/service/statistics/UserData.php +++ b/app/api/service/statistics/UserData.php @@ -2,6 +2,7 @@ namespace app\api\service\statistics; +use app\api\model\GoodsBrowseLog; use app\api\model\User; use app\common\service\BaseService; @@ -18,8 +19,36 @@ class UserData extends BaseService { return [ 'visitorCount' => 0, - 'viewCount' => 0, + 'viewCount' => $this->getViewCount($startDate, $endDate), 'newUserCount' => 0, ]; } + + /** + * 用户访问总数 + */ + public function getVisitorCount() { + + } + + /** + * 用户浏览总数 + */ + public function getViewCount($startDate = null, $endDate = null): string + { + $query = new GoodsBrowseLog(); + if(!empty($startDate) && !empty($endDate)) { + $query->where('create_time', '>=', strtotime($startDate)) + ->where('create_time', '<', strtotime($endDate) + 86400); + } + $value = $query->group('user_id')->count(); + return number_format($value); + } + + /** + * 新用户数量 + */ + public function getNewUserCount() { + + } } \ No newline at end of file From 2924e4851f0b0b83f16bafd6f1bb3aacdfbcd289 Mon Sep 17 00:00:00 2001 From: ztt <835303992@qq.com> Date: Tue, 27 Feb 2024 23:25:44 +0800 Subject: [PATCH 3/5] 1 --- app/api/service/statistics/OrderData.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/api/service/statistics/OrderData.php b/app/api/service/statistics/OrderData.php index e9c1005e..149f5304 100644 --- a/app/api/service/statistics/OrderData.php +++ b/app/api/service/statistics/OrderData.php @@ -29,7 +29,7 @@ class OrderData extends BaseService //下单总数 "orderCount" => $this->getPayOrderTotal($startDate, $endDate), //下单人数 - 'orderPayUser' => $this->getConsumeUsers(), + 'orderPayUser' => $this->getConsumeUsers($startDate, $endDate), //订单成本金额 'orderCostMoney' => 0, //预估利益 From 6746ae8124d7fe9cf0f4af399d00c529466223f5 Mon Sep 17 00:00:00 2001 From: lqmac Date: Wed, 28 Feb 2024 00:47:00 +0800 Subject: [PATCH 4/5] 1 --- app/api/service/Goods.php | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/app/api/service/Goods.php b/app/api/service/Goods.php index 2cedcce0..2d49d698 100644 --- a/app/api/service/Goods.php +++ b/app/api/service/Goods.php @@ -215,24 +215,14 @@ class Goods extends GoodsService 'store_id' => $storeid, 'is_main' => 1, ])->field('shop_name,star,shop_hours,summary,phone, - province_id,city_id,region_id,shop_id,address,latitude,longitude,wechat_img_id,history1,history2,history3,remark')->find()->toArray(); + province_id,city_id,region_id,shop_id,address,latitude,longitude,wechat_img_id,history1,history2,history3,remark,history,parking_name,parking_desc,parking_latitude,parking_longitude')->find()->toArray(); //todo wmc - $info['remark'] = json_decode($info['remark']); + $info['remark'] = json_decode($info['remark'],true); $info['fuwu_hours'] = 5; $info['fuwu_num'] = 15; // $info['wechat'] = 'https://www.saas.njrenzhou.com/uploads/10001/20240127/12bb1b1747e652d258443247a5c4777c.png'; - $history = []; - if (!empty($info['history1'])) { - $history[] = json_decode($info['history1'], true); - } - if (!empty($info['history2'])) { - $history[] = json_decode($info['history2'], true); - } - if (!empty($info['history3'])) { - $history[] = json_decode($info['history3'], true); - } - $info['history'] = $history; - // $info['history'] = ['time' => '2023-01-01', 'contenmt' => 'yml上市']; + + $info['history'] = json_decode($info['history'], true); $info['evaluate'][] = [ 'image' => 'http://qiniu.shop.royaum.com.cn/10001/20240201/13f2e675794e25176352fc039dfb6dcb.jpg', 'nickname' => 'wmc', @@ -243,13 +233,6 @@ class Goods extends GoodsService 'http://qiniu.shop.royaum.com.cn/10001/20240201/13f2e675794e25176352fc039dfb6dcb.jpg' ]; - //读取门店停车场 - $parkingModel = new ParkingModel(); - $parkingInfo = $parkingModel::where(['shop_id' => $info['shop_id']])->find(); - $info['parking_name'] = $parkingInfo->parking_name ?? ''; - $info['parking_desc'] = $parkingInfo->desc ?? ''; - $info['parking_longitude'] = $parkingInfo->longitude ?? ''; - $info['parking_latitude'] = $parkingInfo->latitude ?? ''; return $info; } From 254873d3e7df85c2d04afaf7ef2b8d29dcdff8bb Mon Sep 17 00:00:00 2001 From: ztt <835303992@qq.com> Date: Wed, 28 Feb 2024 09:58:28 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=95=86=E5=93=81=E4=BB=B7=E6=A0=BC?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/model/Goods.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/api/model/Goods.php b/app/api/model/Goods.php index adbc58ac..2d568cf6 100644 --- a/app/api/model/Goods.php +++ b/app/api/model/Goods.php @@ -645,16 +645,24 @@ class Goods extends GoodsModel $this->error = "请补全信息"; return false; } - $detail = $this->with(['skuList']) - ->where('goods_id', '=', $data['id'])->find(); + $detail = $this->where('goods_id', '=', $data['id'])->find(); if ($detail->isEmpty()) { $this->error = "异常数据"; return false; } // 整理商品的价格 if ($detail['spec_type'] == GoodsSpecTypeEnum::MULTI) { - [$data['goods_price_min'], $data['goods_price_max']] = GoodsSkuModel::getGoodsPrices($detail['skuList']->toArray()); - [$data['line_price_min'], $data['line_price_max']] = GoodsSkuModel::getLinePrices($detail['skuList']->toArray()); + if(empty($data['sku_id'])) { + $this->error = "请输入sku_id"; + return false; + } + $skuData = GoodsSkuModel::get(['id' => $data['sku_id'],'goods_id' => $data['id']]); + if ($skuData) { + $skuData->save(['goods_price' => $data['goods_price'], 'line_price' => $data['line_price']]); + } + $skuList = GoodsSkuModel::getSkuList((int)$data['id']); + [$data['goods_price_min'], $data['goods_price_max']] = GoodsSkuModel::getGoodsPrices($skuList->toArray()); + [$data['line_price_min'], $data['line_price_max']] = GoodsSkuModel::getLinePrices($skuList->toArray()); } elseif ($detail['spec_type'] == GoodsSpecTypeEnum::SINGLE) { $data['goods_price_min'] = $data['goods_price_max'] = $data['goods_price']; $data['line_price_min'] = $data['line_price_max'] = $data['line_price'];