Jelajahi Sumber

储值卡导出

gorden 5 hari lalu
induk
melakukan
8106b12574

+ 111 - 0
app/admin/controller/coupon/CardController.php

@@ -2,10 +2,12 @@
 
 namespace app\admin\controller\coupon;
 
+use app\admin\service\coupon\CardService;
 use app\admin\service\member\MemberService;
 use app\controller\Curd;
 use app\model\Card;
 use app\model\CardIssue;
+use app\model\CardMain;
 use app\model\MemberRole;
 use app\model\SysCategory;
 use app\model\SysUser;
@@ -34,9 +36,25 @@ class CardController extends Curd
      */
     public function select(Request $request): Response
     {
+        $cardMainName = $request->get('card_main_name');
+        $cardIssueName = $request->get('card_issue_name');
         [$where, $format, $limit, $field, $order] = $this->selectInput($request);
         $order = $request->get('order', 'desc');
         $field = $field ?? 'card_addtimes';
+
+        if (!empty($where['card_addtimes'])) {
+            $where['card_addtimes'][0] = strtotime($where['card_addtimes'][0]);
+            $where['card_addtimes'][1] = strtotime($where['card_addtimes'][1]);
+        }
+        if (!empty($cardMainName)) {
+            $cardMainIds = CardMain::where('card_main_name', 'like', '%' . $cardMainName . '%')->pluck('card_main_id')->toArray();
+            $where['join_card_main_id'] = ['in', $cardMainIds];
+        }
+        if (!empty($cardIssueName)) {
+            $cardIssueIds = CardIssue::where('card_issue_name', 'like', '%' . $cardIssueName . '%')->pluck('card_issue_id')->toArray();
+            $where['join_card_issue_id'] = ['in', $cardIssueIds];
+        }
+
         $query = $this->doSelect($where, $field, $order);
         return $this->doFormat($query, $format, $limit);
     }
@@ -361,4 +379,97 @@ class CardController extends Curd
             return json_fail('分配失败');
         }
     }
+
+    /**
+     * @Desc 导出储值卡
+     * @Author Gorden
+     * @Date 2024/11/21 13:03
+     *
+     * @param Request $request
+     * @return Response
+     */
+    public function exportCard(Request $request)
+    {
+        $cardStatus = $request->get('card_status');
+        $isIssue = $request->get('is_issue');
+        $cardMainName = $request->get('card_main_name');
+        $cardIssueName = $request->get('card_issue_name');
+        $deptId = $request->get('join_card_dept_id');
+        $cardAddtimes = $request->get('card_addtimes');
+        $cardIds = $request->get('card_ids');
+
+        $cards = Card::with([
+            'member' => function ($query) {
+                $query->select('member_id', 'member_mobile');
+            },
+            'cert' => function ($query) {
+                $query->select('join_cert_member_id', 'member_cert_name');
+            },
+            'dept',
+            'user',
+            'main' => function ($query) {
+                $query->select('card_main_id', 'card_main_name', 'card_main_amount', 'card_main_valid_mode');
+            },
+            'issue' => function ($query) {
+                $query->select('card_issue_id', 'card_issue_name');
+            }
+        ])->when(!empty($cardStatus), function ($query) use ($cardStatus) {
+            $query->where('card_status', $cardStatus);
+        })->when(!empty($isIssue), function ($query) use ($isIssue) {
+            $query->where('is_issue', $isIssue);
+        })->when(!empty($deptId), function ($query) use ($deptId) {
+            $query->where('join_card_dept_id', $deptId);
+        })->when(!empty($cardAddtimes), function ($query) use ($cardAddtimes) {
+            $cardAddtimes[0] = strtotime($cardAddtimes[0]);
+            $cardAddtimes[1] = strtotime($cardAddtimes[1]);
+            $query->whereBetween('card_addtimes', $cardAddtimes);
+        })->when(!empty($cardIds), function ($query) use ($cardIds) {
+            $query->whereIn('card_id', $cardIds);
+        })->when(!empty($cardMainName), function ($query) use ($cardMainName) {
+            $cardMainIds = CardMain::where('card_main_name', 'like', '%' . $cardMainName . '%')->pluck('card_main_id')->toArray();
+            $query->whereIn('join_card_main_id', $cardMainIds);
+        })->when(!empty($cardIssueName), function ($query) use ($cardIssueName) {
+            $cardIssueIds = CardIssue::where('card_issue_name', 'like', '%' . $cardIssueName . '%')->pluck('card_issue_id')->toArray();
+            $query->whereIn('join_card_issue_id', $cardIssueIds);
+        })->orderByDesc('card_addtimes')
+            ->get()
+            ->toArray();
+        $data = [];
+        foreach ($cards as $item) {
+            $mobile = $item['member']['member_mobile'] ?? '';
+            $certName = $item['cert']['member_cert_name'] ?? '';
+            $item['member_name'] = MemberService::getMemberCertName($mobile, $certName, '');
+            if (!empty($item['main']['card_main_valid_mode'])) {
+                if ($item['main']['card_main_valid_mode'] == 'LONG') {
+                    $item['valid_datetime'] = '长期有效';
+                } else if (!empty($item['card_deadline_datetime'])) {
+                    $item['valid_datetime'] = date('Y/m/d H:i:s', strtotime($item['card_assign_datetime'])) . '-' . date('Y/m/d H:i:s', strtotime($item['card_deadline_datetime']));
+                }
+            }
+            $cardExtendJson = [];
+            if (!empty($item['card_extend_json'])) {
+                $cardExtendJson = json_decode($item['card_extend_json'], true);
+            }
+            if (!empty($cardExtendJson['issue_datetime'])) {
+                $item['issue_datetime'] = $cardExtendJson['issue_datetime'];
+            }
+
+            $data[] = [
+                'card_id' => $item['card_id'],
+                'main_name' => !empty($item['main']['card_main_name']) ? $item['main']['card_main_name'] : '--',
+                'issue_name' => !empty($item['issue']['card_issue_name']) ? $item['issue']['card_issue_name'] : '--',
+                'main_amount' => !empty($item['main']['card_main_amount']) ? $item['main']['card_main_amount'] : '--',
+                'dept_name' => !empty($item['dept']['dept_name']) ? $item['dept']['dept_name'] : '--',
+                'member_name' => $item['member_name'] ?? '--',
+                'valid_datetime' => $item['valid_datetime'] ?? '--',
+                'status' => CardService::$status[$item['card_status']],
+                'is_issue' => $item['is_issue'] == 'Y' ? '已发行' : '未发行',
+                'issue_datetime' => $item['issue_datetime'] ?? '--',
+                'card_addtimes' => $item['card_addtimes']
+            ];
+
+        }
+
+        return json_success("success", $data);
+    }
 }

+ 16 - 0
app/admin/service/coupon/CardService.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace app\admin\service\coupon;
+
+class CardService
+{
+    public static $status = [
+        'INIT' => '待分配',
+        'WAITING' => '已分配,待售',
+        'PENDING' => '已售,待激活',
+        'USED' => '已激活',
+        'DONE' => '使用完成',
+        'EXPIRED' => '已过期',
+        'PAUSED' => '冻结'
+    ];
+}

+ 1 - 0
route/admin.php

@@ -1093,6 +1093,7 @@ Route::group('/admin', function () {
         Route::group('', function () {
             Route::get('/list', [\app\admin\controller\coupon\CardController::class, 'select']);
             Route::get('/info', [\app\admin\controller\coupon\CardController::class, 'info']);
+            Route::get('/export', [\app\admin\controller\coupon\CardController::class, 'exportCard']);
             Route::get('/getCardIdsByMainId', [\app\admin\controller\coupon\CardController::class, 'getCardIdsByMainId']);
             Route::post('/add', [\app\admin\controller\coupon\CardController::class, 'insert']);
             Route::post('/update', [\app\admin\controller\coupon\CardController::class, 'update']);