gorden 2 mesi fa
parent
commit
b35b8d1d05

+ 21 - 35
app/admin/controller/coupon/CouponPacketSequenceController.php

@@ -8,6 +8,7 @@ use app\controller\Curd;
 use app\model\Coupon;
 use app\model\CouponDetail;
 use app\model\CouponGoods;
+use app\model\CouponPacket;
 use app\model\CouponPacketSequence;
 use support\Request;
 use support\Response;
@@ -26,13 +27,10 @@ class CouponPacketSequenceController extends Curd
         $order = $request->get('order', 'desc');
         $field = $field ?? 'coupon_packet_sequence_addtimes';
 
-        $couponName = $request->get('coupon_name', '');
-        if (!empty($couponName)) {
-            $couponIds = Coupon::where('coupon_name', 'like', '%' . $couponName . '%')->pluck('coupon_id')->toArray();
-            if (empty($couponIds)) {
-                $couponIds = ['default'];
-            }
-            $where['join_detail_coupon_id'] = ['in', $couponIds];
+        $couponPacketName = $request->get('coupon_packet_name', '');
+        if (!empty($couponPacketName)) {
+            $packetIds = CouponPacket::where('coupon_packet_name', 'like', '%' . $couponPacketName . '%')->pluck('coupon_packet_id')->toArray();
+            $where['join_sequence_coupon_packet_id'] = ['in', $packetIds];
         }
         $addTimes = $request->get('coupon_packet_sequence_addtimes', []);
         if (!empty($addTimes)) {
@@ -49,8 +47,9 @@ class CouponPacketSequenceController extends Curd
     protected function doSelect(array $where, string $field = null, string $order = 'desc')
     {
         $model = $this->model->with([
-            'packet',
-//            'coupon',
+            'packet'=>function($query){
+                $query->select('coupon_packet_id','coupon_packet_name');
+            },
             'member' => function ($query) {
                 $query->select('member_id', 'member_mobile');
             },
@@ -100,32 +99,19 @@ class CouponPacketSequenceController extends Curd
 
     public function afterQuery($items)
     {
-//        foreach ($items as &$item) {
-//            $mobile = $certName = $nickname = '';
-//            if (!empty($item['member']) && !empty($item['member']['member_mobile'])) {
-//                $mobile = $item['member']['member_mobile'];
-//            }
-//            if (!empty($item['cert']) && !empty($item['cert']['member_cert_name'])) {
-//                $certName = $item['cert']['member_cert_name'];
-//            }
-//            if (!empty($item['info']) && !empty($item['info']['member_info_nickname'])) {
-//                $nickname = $item['info']['member_info_nickname'];
-//            }
-//            $item['member_name'] = MemberService::getMemberName($mobile, $certName, $nickname);
-//
-//            $item['member_used'] = 0;
-//            foreach ($item['detail'] as $detail) {
-//                if ($detail['coupon_detail_status'] == 'USED') {
-//                    $item['member_used'] += 1;
-//                }
-//            }
-//            if (!empty($item['coupon_detail_extend_json'])) {
-//                $couponDetailExtendJson = json_decode($item['coupon_detail_extend_json'], true);
-//                if (isset($couponDetailExtendJson['gettype'])) {
-//                    $item['gettype'] = $couponDetailExtendJson['gettype'];
-//                }
-//            }
-//        }
+        foreach ($items as &$item) {
+            $mobile = $certName = $nickname = '';
+            if (!empty($item['member']) && !empty($item['member']['member_mobile'])) {
+                $mobile = $item['member']['member_mobile'];
+            }
+            if (!empty($item['cert']) && !empty($item['cert']['member_cert_name'])) {
+                $certName = $item['cert']['member_cert_name'];
+            }
+            if (!empty($item['info']) && !empty($item['info']['member_info_nickname'])) {
+                $nickname = $item['info']['member_info_nickname'];
+            }
+            $item['member_name'] = MemberService::getMemberName($mobile, $certName, $nickname);
+        }
 
         return $items;
     }