123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- <?php
- // +----------------------------------------------------------------------
- // | likeshop开源商城系统
- // +----------------------------------------------------------------------
- // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
- // | gitee下载:https://gitee.com/likeshop_gitee
- // | github下载:https://github.com/likeshop-github
- // | 访问官网:https://www.likeshop.cn
- // | 访问社区:https://home.likeshop.cn
- // | 访问手册:http://doc.likeshop.cn
- // | 微信公众号:likeshop技术社区
- // | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
- // | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
- // | 禁止对系统程序代码以任何目的,任何形式的再发布
- // | likeshop团队版权所有并拥有最终解释权
- // +----------------------------------------------------------------------
- // | author: likeshop.cn.team
- // +----------------------------------------------------------------------
-
-
- namespace app\shop\logic\order;
-
-
- use app\common\basics\Logic;
- use app\common\model\order\Order;
- use app\common\model\order\OrderInvoice;
- use app\common\server\ExportExcelServer;
-
-
- /**
- * 发票管理-逻辑
- * Class InvoiceLogic
- * @package app\shop\logic\order
- */
- class InvoiceLogic extends Logic
- {
-
- /**
- * @notes 列表条件
- * @param $get
- * @param $shop_id
- * @return array
- * @author 段誉
- * @date 2022/4/24 11:05
- */
- public static function getListsCondition($get, $shop_id)
- {
- $where[] = ['o.shop_id', '=', $shop_id];
- if (isset($get['status']) && is_numeric($get['status']) && $get['status'] != '') {
- $where[] = ['i.status', '=', (int)$get['status']];
- }
-
- if (!empty($get['order_sn']) && $get['order_sn'] != '') {
- $where[] = ['order_sn', 'like', '%'.$get['order_sn'].'%'];
- }
-
- if (isset($get['order_status']) && $get['order_status'] != '') {
- $where[] = ['order_status', '=', $get['order_status']];
- }
-
- // 创建时间
- if(isset($get['start_time']) && !empty($get['start_time'])) {
- $where[] = ['o.create_time', '>=', 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;
- }
- }
-
- }
|