conditions = $conditions; parent::__construct(); } /** * @return Builder */ public function query() { if (!isset(self::$types[$this->conditions['type']])) { throw new NotAllowedException('统计类型不存在'); } $builder = app(OrderCardPartitionRepository::class)->forceNoReset()->withConditions($this->conditions)->applyConditions()->orderBy('sim'); return $builder; } public function headings(): array { $headings = [ 'SIM', '企业名称', '套餐名称', '套餐周期', '支付方式', '价格', '数量', '订单时间', ]; if (in_array($this->conditions['type'], [2, 3])) { array_splice($headings, 2, 0, '基础套餐'); } return $headings; } /** * @param mixed $row * * @return mixed */ public function rows($rows) { $rows = OrderService::detailTransformer(collect($rows)); $array = []; if (in_array($this->conditions['type'], [2, 3])) { $basePackages = app(OrderCardPartitionRepository::class)->getCardBasePackages(collect($rows)->pluck('sim')->toArray())->keyBy('sim')->toArray(); } foreach ($rows as $item) { $data = [ $item['sim'], $item['company_name'], $item['package_name'], $item['service_months'], $item['pay_channel_name'], $item['unit_price'], $item['counts'], $item['order_at'], ]; if (in_array($this->conditions['type'], [2, 3])) { array_splice($data, 2, 0, PackageService::load($basePackages[$item['sim']]['package_id'])['name']); } $array[] = $data; } return $array; } /** * @return array */ public function columnFormats(): array { return [ 'A' => NumberFormat::FORMAT_NUMBER, 'F' => NumberFormat::FORMAT_NUMBER_00, 'G' => NumberFormat::FORMAT_NUMBER, 'H' => NumberFormat::FORMAT_DATE_YYYYMMDD2, ]; } /** * 类型 * * @return void */ protected function tag() { if (!isset(self::$types[$this->conditions['type']])) { throw new NotAllowedException('类型不允许'); } $tag = self::$types[$this->conditions['type']] . $tag; return $tag; } }