where('category_id', '=', $category_id)->column("product_id"); if(!empty($product_ids)){ $model = new static(); //搜索时间段 if (!empty($postData['create_time'])) { $sta_time = array_shift($postData['create_time']); $end_time = array_pop($postData['create_time']); $model = $model->whereBetweenTime('order.create_time', $sta_time, date('Y-m-d 23:59:59', strtotime($end_time))); } return $model->alias('o_product') ->join('order', 'order.order_id = o_product.order_id') ->where('order.pay_status', '=', OrderPayStatusEnum::SUCCESS) ->where('order.order_status', '<>', OrderStatusEnum::CANCELLED) ->where('o_product.product_id', 'in', $product_ids) ->group('o_product.product_id') ->sum("total_num"); } return 0; } //获取某个分类的购买商品金额 public static function getSalesMoneyByCategory($category_id,$postData) { $product_ids = (new ProductModel())->where('category_id', '=', $category_id)->column("product_id"); if(!empty($product_ids)){ $model = new static(); //搜索时间段 if (!empty($postData['create_time'])) { $sta_time = array_shift($postData['create_time']); $end_time = array_pop($postData['create_time']); $model = $model->whereBetweenTime('order.create_time', $sta_time, date('Y-m-d 23:59:59', strtotime($end_time))); } return $model->alias('o_product') ->join('order', 'order.order_id = o_product.order_id') ->where('order.pay_status', '=', OrderPayStatusEnum::SUCCESS) ->where('order.order_status', '<>', OrderStatusEnum::CANCELLED) ->where('o_product.product_id', 'in', $product_ids) ->group('o_product.product_id') ->sum("total_pay_price"); } return 0; } //获取会员等级的购买商品数量 public static function getSalesNumByGrade($grade_id,$postData) { $user_ids = (new UserModel())->where('grade_id', '=', $grade_id)->column("user_id"); if(!empty($user_ids)){ $model = new static(); //搜索时间段 if (!empty($postData['create_time'])) { $sta_time = array_shift($postData['create_time']); $end_time = array_pop($postData['create_time']); $model = $model->whereBetweenTime('order.create_time', $sta_time, date('Y-m-d 23:59:59', strtotime($end_time))); } return $model->alias('o_product') ->join('order', 'order.order_id = o_product.order_id') ->where('order.pay_status', '=', OrderPayStatusEnum::SUCCESS) ->where('order.order_status', '<>', OrderStatusEnum::CANCELLED) ->where('o_product.user_id', 'in', $user_ids) ->group('o_product.product_id') ->sum("total_num"); } return 0; } //获取会员等级的购买商品数量 public static function getSalesMoneyByGrade($grade_id,$postData) { $user_ids = (new UserModel())->where('grade_id', '=', $grade_id)->column("user_id"); if(!empty($user_ids)){ $model = new static(); //搜索时间段 if (!empty($postData['create_time'])) { $sta_time = array_shift($postData['create_time']); $end_time = array_pop($postData['create_time']); $model = $model->whereBetweenTime('order.create_time', $sta_time, date('Y-m-d 23:59:59', strtotime($end_time))); } return $model->alias('o_product') ->join('order', 'order.order_id = o_product.order_id') ->where('order.pay_status', '=', OrderPayStatusEnum::SUCCESS) ->where('order.order_status', '<>', OrderStatusEnum::CANCELLED) ->where('o_product.user_id', 'in', $user_ids) ->group('o_product.product_id') ->sum("total_pay_price"); } return 0; } public static function getPurchaseCount($userId, $postData) { $model = new static(); //搜索时间段 if (!empty($postData['start_time'])) { $sta_time = $postData['start_time']; $end_time = $postData['end_time']; $model = $model->whereBetweenTime('order.create_time', strtotime($sta_time), strtotime($end_time)); } return $model->alias('o_product') ->join('order', 'order.order_id = o_product.order_id') ->where('order.pay_status', '=', OrderPayStatusEnum::SUCCESS) ->where('order.order_status', '<>', OrderStatusEnum::CANCELLED) ->where('o_product.user_id', '=', $userId) ->where('o_product.is_vip',1) ->group('o_product.product_id') ->sum("total_num"); } }