conditions = $conditions; parent::__construct(); } /** * @return Builder */ public function query() { if (!$class = OrderService::$classes[$this->conditions['type']]) { throw new NotAllowedException('统计类型不存在'); } $repository = app($class); $builder = $repository->withConditions($this->conditions)->applyConditions()->getModel(); return $builder; } public function headings(): array { return [ 'SIM', '企业名称', '套餐名称', '套餐周期', '支付方式', '价格', '订单时间', ]; } /** * @param mixed $row * * @return mixed */ public function rows($rows) { $rows = OrderService::detailTransformer($rows); $rows->transform(function ($item) { return [ $item['sim'], $item['company_name'], $item['package_name'], $item['service_months'], $item['pay_channel_name'], $item['unit_price'], $item['order_at'], ]; }); return $rows; } /** * @return array */ public function columnFormats(): array { return [ 'A' => NumberFormat::FORMAT_NUMBER, 'F' => NumberFormat::FORMAT_NUMBER_00, ]; } /** * 类型 * * @return void */ protected function tag() { if ((!$tag = self::$classes[get_class($this)]) || !self::$types[$this->conditions['type']]) { throw new NotAllowedException('类型不允许'); } $tag = self::$types[$this->conditions['type']] . $tag; return $tag; } }