conditions = $conditions; parent::__construct(); } /** * @return Builder */ public function query() { $repository = app(OrderCardPartitionRepository::class); $select = [ 'sim', 'company_id', 'package_id', 'order_id', 'type', ]; $builder = $repository->select($select) ->withConditions($this->conditions) ->orderBy('id', 'desc'); return $builder; } public function headings(): array { return [ 'SIM', '运营商', '企业名称', '套餐名称', '套餐单价(元/月)', ]; } /** * @param mixed $row * * @return mixed */ public function rows($rows) { $carrierOperators = app(Dicts::class)->get('carrier_operator'); $rows->load('order:id,unit_price'); $rows->transform(function ($item) use ($carrierOperators) { $company = app(CompanyService::class)->load($item->company_id); $package = app(PackageService::class)->load($item->package_id); $month_price = $item->order['unit_price'] / $package['service_months']; return [ $item['sim'], $carrierOperators[$package['carrier_operator']], $company['name'], $package['name'], $month_price, ]; }); return $rows; } /** * @return array */ public function columnFormats(): array { return [ 'A' => NumberFormat::FORMAT_NUMBER, 'E' => NumberFormat::FORMAT_NUMBER_00, ]; } /** * 类型 * * @return void */ protected function tag() { if ((!$tag = self::$classes[get_class($this)]) || !self::$types[$this->conditions['type'][0]]) { throw new NotAllowedException('类型不允许'); } $tag = self::$types[$this->conditions['type'][0]] . $tag; return $tag; } }