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']; 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; } 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..149f5304 100644 --- a/app/api/service/statistics/OrderData.php +++ b/app/api/service/statistics/OrderData.php @@ -2,27 +2,125 @@ 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 { - 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, //预估利益 'orderInterest' => 0, //付费会员数 - 'payMemberCount' => 0, + 'payMemberCount' => $this->getPayCount(IdentityEnum::MEMBER, $startDate, $endDate), //付费分销商数 - 'payDealerCount' => 0 + 'payDealerCount' => $this->getPayCount(IdentityEnum::DEALER, $startDate, $endDate) + ]; + } + + /** + * 获取某天的总销售额 + * @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(); } + + /** + * 付费会员数 + */ + 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 681d8e56..2271a279 100644 --- a/app/api/service/statistics/RefundData.php +++ b/app/api/service/statistics/RefundData.php @@ -2,15 +2,51 @@ 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 { - 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, - '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 44bf0eab..39622583 100644 --- a/app/api/service/statistics/UserData.php +++ b/app/api/service/statistics/UserData.php @@ -2,16 +2,53 @@ namespace app\api\service\statistics; +use app\api\model\GoodsBrowseLog; +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, - '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