Browse Source

红包功能

gorden 2 months ago
parent
commit
32874ca590

+ 6 - 0
app/admin/controller/coupon/CouponPacketController.php

@@ -105,6 +105,10 @@ class CouponPacketController extends Curd
                     'dept_name' => "所有门店"
                 ];
             }
+            $item['used_total'] = CouponPacketSequence::where('join_sequence_coupon_packet_id',$item['coupon_packet_id'])
+                ->where('coupon_packet_sequence_status','USED')
+                ->count();
+            $item['unused_total'] = $item->coupon_packet_issue_num - $item['used_total'];
         }
 
         return $items;
@@ -363,6 +367,7 @@ class CouponPacketController extends Curd
             $this->generatePacket($packet);
 
             $packet->coupon_packet_status = 'ACTIVED';
+            $packet->coupon_packet_issue_datetime = date('Y-m-d H:i:s');
             $packet->save();
 
             Db::commit();
@@ -456,6 +461,7 @@ class CouponPacketController extends Curd
             // 生成红包记录
             $this->generatePacket($packet);
 
+            $packet->coupon_packet_issue_datetime = date('Y-m-d H:i:s');
             $packet->save();
 
             Db::commit();

+ 34 - 17
app/admin/controller/coupon/CouponPacketSequenceController.php

@@ -10,6 +10,8 @@ use app\model\CouponDetail;
 use app\model\CouponGoods;
 use app\model\CouponPacket;
 use app\model\CouponPacketSequence;
+use app\model\SysCategory;
+use app\model\SysDept;
 use support\Request;
 use support\Response;
 
@@ -47,8 +49,8 @@ class CouponPacketSequenceController extends Curd
     protected function doSelect(array $where, string $field = null, string $order = 'desc')
     {
         $model = $this->model->with([
-            'packet'=>function($query){
-                $query->select('coupon_packet_id','coupon_packet_name');
+            'packet' => function ($query) {
+                $query->select('coupon_packet_id', 'coupon_packet_name');
             },
             'member' => function ($query) {
                 $query->select('member_id', 'member_mobile');
@@ -157,22 +159,37 @@ class CouponPacketSequenceController extends Curd
      */
     public function info(Request $request): Response
     {
-        $detailId = $request->get('detail_id', '');
-        if (empty($detailId)) {
+        $packetSequenceId = $request->get('coupon_packet_sequence_id', '');
+        if (empty($packetSequenceId)) {
             return json_fail('参数异常');
         }
 
-        $detail = CouponDetail::where('coupon_detail_id', $detailId)
-            ->select('coupon_detail_id', 'coupon_detail_extend_json')
+        $sequence = CouponPacketSequence::with([
+            'packet' => function ($query) {
+                $query->select('coupon_packet_id', 'coupon_packet_name', 'join_coupon_packet_category_id', 'join_coupon_packet_dept_id', 'coupon_packet_status', 'coupon_packet_issue_num', 'coupon_packet_issue_datetime');
+            }
+        ])->where('coupon_packet_sequence_id', $packetSequenceId)
             ->first();
-        if (!empty($detail->coupon_detail_extend_json)) {
-            $couponDetailExtendJson = json_decode($detail->coupon_detail_extend_json, true);
-            if (isset($couponDetailExtendJson['from'])) {
-                $detail['from'] = MemberService::getMemberNameByMemberId($couponDetailExtendJson['from']);
+        if(!empty($sequence->packet)){
+            if ($sequence->packet->join_coupon_packet_dept_id == 0){
+                $sequence->packet->dept_name = '所有门店';
+            }else{
+                $sequence->packet->dept_nam = '';
+                $dept = SysDept::where('dept_id',$sequence->packet->join_coupon_packet_dept_id)->select('dept_id','dept_name')->first();
+                if (!empty($dept)){
+                    $sequence->packet->dept_name = $dept->dept_name;
+                }
+            }
+            if (!empty($sequence->packet->join_coupon_packet_category_id)){
+                $category = SysCategory::where('category_id',$sequence->packet->join_coupon_packet_category_id)
+                    ->first();
+                if (!empty($category->category_name)){
+                    $sequence->packet->category_name = $category->category_name;
+                }
             }
         }
 
-        return json_success('', $detail);
+        return json_success('', $sequence);
     }
 
     public function myCouponGrouping(Request $request)
@@ -201,12 +218,12 @@ class CouponPacketSequenceController extends Curd
             }
         ])->whereIn('join_detail_coupon_id', $couponIds)
             ->where('join_coupon_detail_member_id', $memberId);
-            if ($settlementNow == 'Y') {
-                $details = $details->whereIn('coupon_detail.coupon_detail_status', ['ACTIVED', 'WAITING']);
-            } else {
-                $details = $details->where('coupon_detail.coupon_detail_status', 'ACTIVED');
-            }
-            $details = $details->selectRaw('join_detail_coupon_id,join_coupon_detail_member_id,COUNT(*) as count')
+        if ($settlementNow == 'Y') {
+            $details = $details->whereIn('coupon_detail.coupon_detail_status', ['ACTIVED', 'WAITING']);
+        } else {
+            $details = $details->where('coupon_detail.coupon_detail_status', 'ACTIVED');
+        }
+        $details = $details->selectRaw('join_detail_coupon_id,join_coupon_detail_member_id,COUNT(*) as count')
             ->groupBy('join_detail_coupon_id', 'join_coupon_detail_member_id')
             ->get()
             ->toArray();