hasOne(OrderInquiry::class, 'order_id', 'order_id'); } /** * 关联服务包订单表 */ public function OrderServicePackage(): HasOne { return $this->hasOne(OrderServicePackage::class, 'order_id', 'order_id'); } /** * 获取信息-单条 * @param array $params * @param array $fields * @return object|null */ public static function getOne(array $params, array $fields = ['*']): object|null { return self::where($params)->first($fields); } /** * 多条 * @param array $params * @param array $fields * @return Collection|array */ public static function getList(array $params, array $fields = ['*']): Collection|array { return self::where($params)->get($fields); } /** * 新增 * @param array $data * @return Order|\Hyperf\Database\Model\Model */ public static function addOrder(array $data): \Hyperf\Database\Model\Model|Order { return self::create($data); } /** * 修改 * @param array $params * @param array $data * @return int */ public static function edit(array $params = [], array $data = []): int { return self::where($params)->update($data); } /** * 获取医生某一时间段收益明细分页数据 * @param array $params * @param array $date_params 时间区间 * @param string|int $is_platform_deep_cooperation * @param array $fields * @param int|null $page * @param int|null $per_page * @return array */ public static function getDoctorCreatedDateOrderInquiryPage(array $params, array $date_params,string|int $is_platform_deep_cooperation,array $fields = ["*"], int $page = null, ?int $per_page = 10): array { $query = self::with(['OrderInquiry', 'OrderServicePackage']) ->whereIn('order_type',[1,4,5]) ->where($params); // 问诊订单 $query = $query->where(function ($query) use ($date_params,$is_platform_deep_cooperation){ $query->whereExists(function ($subQuery) use ($date_params,$is_platform_deep_cooperation){ $subQuery->from('order_inquiry'); if ($is_platform_deep_cooperation == 1){ $subQuery->whereNotIn('inquiry_type', [2,4]); } $subQuery->whereNotIn('inquiry_mode', [7,8,9]) ->whereIn('inquiry_status', [4,5,6,7]) ->whereBetween('reception_time', $date_params) ->whereRaw('gdxz_order.order_id = gdxz_order_inquiry.order_id'); }) ->orWhereExists(function ($subQuery) use ($date_params) { $subQuery->from('order_service_package') ->whereRaw('gdxz_order.order_id = gdxz_order_service_package.order_id') ->whereIn('order_service_status', [4,5,6,7]) ->whereBetween('start_time', $date_params); }); }); $result = $query->paginate($per_page, $fields, "page", $page); $data = array(); $data['current_page'] = $result->currentPage();// 当前页码 $data['total'] = $result->total();//数据总数 $data['data'] = $result->items();//数据 $data['per_page'] = $result->perPage();//每页个数 $data['last_page'] = $result->lastPage();//最后一页 return $data; } /** * 获取医生当日预计的订单金额 * @param array $params * @param array $date_params 时间区间 * @param string|int $is_platform_deep_cooperation * @return int|null|string */ public static function getDoctorDayAmountTotal(array $params, array $date_params,string|int $is_platform_deep_cooperation): int|null|string { $query = self::where($params) ->whereIn('order_type',[1,4,5]); // 问诊订单 $query = $query->where(function ($query) use ($date_params,$is_platform_deep_cooperation){ $query->whereExists(function ($subQuery) use ($date_params,$is_platform_deep_cooperation){ $subQuery->from('order_inquiry'); if ($is_platform_deep_cooperation == 1){ $subQuery->whereNotIn('inquiry_type', [2,4]); } $subQuery->whereNotIn('inquiry_mode', [7,8,9]) ->whereIn('inquiry_status', [4,5]) ->whereBetween('reception_time', $date_params) ->where('inquiry_refund_status', 0) ->where('inquiry_pay_status', 2) ->where('is_withdrawal', 0) ->whereRaw('gdxz_order.order_id = gdxz_order_inquiry.order_id'); }) ->orWhereExists(function ($subQuery) use ($date_params) { $subQuery->from('order_service_package') ->whereRaw('gdxz_order.order_id = gdxz_order_service_package.order_id') ->whereIn('order_service_status', [3]) ->whereBetween('start_time', $date_params) ->where('refund_status', 0) ->where('pay_status', 2); }); }); $result = $query->orderBy('created_at') ->sum("amount_total");; return $result; } /** * 获取医生当日已完成待入帐的订单金额 * @param array $params * @param array $date_params 时间区间 * @param string|int $is_platform_deep_cooperation * @return int|null|string */ public static function getDoctorDayCompletedAmountTotal(array $params, array $date_params,string|int $is_platform_deep_cooperation): int|null|string { $query = self::where($params) ->whereIn('order_type',[1,4,5]); // 问诊订单 $query = $query->where(function ($query) use ($date_params,$is_platform_deep_cooperation){ $query->whereExists(function ($subQuery) use ($date_params,$is_platform_deep_cooperation){ $subQuery->from('order_inquiry'); if ($is_platform_deep_cooperation == 1){ $subQuery->whereNotIn('inquiry_type', [2,4]); } $subQuery->whereNotIn('inquiry_mode', [7,8,9]) ->whereIn('inquiry_status', [5]) ->whereBetween('reception_time', $date_params) ->where('inquiry_refund_status', 0) ->where('inquiry_pay_status', 2) ->where('is_withdrawal', 0) ->whereRaw('gdxz_order.order_id = gdxz_order_inquiry.order_id'); }) ->orWhereExists(function ($subQuery) use ($date_params) { $subQuery->from('order_service_package') ->whereRaw('gdxz_order.order_id = gdxz_order_service_package.order_id') ->whereIn('order_service_status', [3]) ->where('finish_time','>', $date_params[0]) ->where('refund_status', 0) ->where('pay_status', 2); }); }); $result = $query->orderBy('created_at') ->sum("amount_total");; return $result; } /** * 获取可提现订单列表 * @param array $params * @param string|int $is_platform_deep_cooperation * @param array $fields * @param int|null $page * @param int|null $per_page * @return array */ public static function getDoctorWithdrawalOrderList(array $params, string|int $is_platform_deep_cooperation,array $fields = ["*"], int $page = null, ?int $per_page = 10): array { $query = self::with(['OrderInquiry', 'OrderServicePackage']) ->where($params) ->whereIn('order_type',[1,4,5]); // 问诊订单 $query = $query->where(function ($query) use ($is_platform_deep_cooperation){ $query->whereExists(function ($subQuery) use ($is_platform_deep_cooperation){ $subQuery->from('order_inquiry'); if ($is_platform_deep_cooperation == 1){ $subQuery->whereNotIn('inquiry_type', [2,4]); } $subQuery->whereNotIn('inquiry_mode', [7,8,9]) ->whereIn('inquiry_status', [6]) ->whereIn('inquiry_refund_status', [0,3]) ->whereRaw('gdxz_order.order_id = gdxz_order_inquiry.order_id'); }) ->orWhereExists(function ($subQuery) { $subQuery->from('order_service_package') ->whereRaw('gdxz_order.order_id = gdxz_order_service_package.order_id') ->whereIn('refund_status', [0,3]) ->where('pay_status', 2) ->where('start_time', 2) ->whereIn('order_service_status', [4,5]) ->WhereExists(function ($subQuery){ $subQuery->from("order_service_package_inquiry") ->whereRaw('gdxz_order_service_package.order_service_id = gdxz_order_service_package_inquiry.order_service_id'); }); }); }); $result = $query->paginate($per_page, $fields, "page", $page); $data = array(); $data['current_page'] = $result->currentPage();// 当前页码 $data['total'] = $result->total();//数据总数 $data['data'] = $result->items();//数据 $data['per_page'] = $result->perPage();//每页个数 $data['last_page'] = $result->lastPage();//最后一页 return $data; } }