=', strtotime($get['start_time']) ]; } if(isset($get['end_time']) && !empty($get['end_time'])) { $where[] = ['o.create_time', '<=', strtotime($get['end_time']) ]; } return $where; } /** * @notes 发票列表 * @param $get * @param $shop_id * @return array * @author 段誉 * @date 2022/4/12 17:56 */ public static function getInvoiceLists($get, $shop_id) { $where = self::getListsCondition($get, $shop_id); $field = ['i.*', 'o.order_sn', 'o.order_amount', 'order_status','o.create_time' => 'order_create_time']; $model = new OrderInvoice(); $lists = $model->alias('i')->field($field) ->join('order o', 'o.id = i.order_id') ->order('i.id desc') ->where($where) ->append(['type_text', 'header_type_text', 'status_text']) ->paginate([ 'page' => $get['page'] ?? 1, 'list_rows' => $get['limit'] ?? 10, 'var_page' => 'page' ])->toArray(); foreach ($lists['data'] as &$item) { $item['order_status'] = Order::getOrderStatus($item['order_status']); $item['order_create_time'] = date('Y-m-d h:i:s', $item['order_create_time']); } return ['count'=>$lists['total'], 'lists'=>$lists['data']]; } /** * @notes 开票 * @param $params * @author 段誉 * @date 2022/4/12 18:58 */ public static function setInvoice($params) { OrderInvoice::update([ 'id' => $params['id'], 'status' => $params['status'], 'invoice_number' => $params['invoice_number'], 'invoice_time' => time(), ]); } /** * @notes 发票详情 * @param $id * @return array * @author 段誉 * @date 2022/4/12 18:55 */ public static function detail($id) { $invoice = OrderInvoice::with(['order_data']) ->append(['type_text', 'header_type_text', 'status_text']) ->findOrEmpty($id) ->toArray(); return $invoice; } /** * @notes 导出Excel * @param array $condition * @return array|false * @author 段誉 * @date 2022/4/24 10:10 */ public static function export($get, $shop_id) { try { $where = self::getListsCondition($get, $shop_id); $field = ['i.*', 'o.order_sn', 'o.order_amount', 'order_status','o.create_time' => 'order_create_time']; $lists = (new OrderInvoice())->alias('i') ->field($field) ->join('order o', 'o.id = i.order_id') ->order('i.id desc') ->where($where) ->append(['type_text', 'header_type_text', 'status_text']) ->select()->toArray(); foreach ($lists as &$item) { $item['order_status'] = Order::getOrderStatus($item['order_status']); $item['order_create_time'] = date('Y-m-d h:i:s', $item['order_create_time']); } $excelFields = [ 'order_sn' => '订单编号', 'order_amount' => '订单金额', 'order_status' => '订单状态', 'order_create_time' => '下单时间', 'type_text' => '发票类型', 'header_type_text' => '抬头类型', 'name' => '发票抬头', 'duty_number' => '税号', 'email' => '邮箱', 'status_text' => '开票状态', 'invoice_number' => '发票编号', ]; $export = new ExportExcelServer(); $export->setFileName('发票'); $export->setExportNumber(['invoice_number']); $result = $export->createExcel($excelFields, $lists); return ['url' => $result]; } catch (\Exception $e) { self::$error = $e->getMessage(); return false; } } }