|
@@ -613,6 +613,78 @@ class MemberController
|
|
|
return json_success('', compact('rows', 'page', 'pageSize', 'total'));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @Desc 我的卡券
|
|
|
+ * @Author Gorden
|
|
|
+ * @Date 2024/8/22 18:45
|
|
|
+ *
|
|
|
+ * @param Request $request
|
|
|
+ * @return \support\Response
|
|
|
+ */
|
|
|
+ public function allCoupon(Request $request)
|
|
|
+ {
|
|
|
+ $memberId = $request->get('member_id', '');
|
|
|
+ $page = $request->get('page', 1);
|
|
|
+ $pageSize = $request->get('pageSize', 20);
|
|
|
+
|
|
|
+ $coupons = CouponDetail::with([
|
|
|
+ 'member' => function ($query) {
|
|
|
+ $query->select('member_id', 'member_mobile');
|
|
|
+ },
|
|
|
+ 'cert' => function ($query) {
|
|
|
+ $query->select('join_cert_member_id', 'member_cert_name');
|
|
|
+ },
|
|
|
+ 'info' => function ($query) {
|
|
|
+ $query->select('join_info_member_id', 'member_info_nickname');
|
|
|
+ }
|
|
|
+ ])
|
|
|
+ ->leftJoin('coupon', 'coupon.coupon_id', '=', 'coupon_detail.join_detail_coupon_id')
|
|
|
+ ->where('join_coupon_detail_member_id', $memberId)
|
|
|
+ ->groupBy('join_coupon_detail_member_id', 'join_detail_coupon_id');
|
|
|
+// $total = $coupons->count();
|
|
|
+ $totalModel = Db::select("select count(a.join_detail_coupon_id) as total from (select join_detail_coupon_id from app_coupon_detail as d left join app_coupon as c ON d.join_detail_coupon_id = c.coupon_id where d.join_coupon_detail_member_id='" . $memberId . "' group by d.join_coupon_detail_member_id,d.join_detail_coupon_id) as a");
|
|
|
+ $total = 0;
|
|
|
+ if (!empty($totalModel) && !empty($totalModel[0])) {
|
|
|
+ $total = $totalModel[0]->total;
|
|
|
+ }
|
|
|
+ $rows = $coupons->select('coupon_detail.join_coupon_detail_member_id', 'coupon_detail.join_detail_coupon_id'
|
|
|
+ , 'coupon.coupon_name', 'coupon.coupon_classify', 'coupon.coupon_value')
|
|
|
+ ->selectRaw('COUNT(1) as total,
|
|
|
+ COUNT(IF(app_coupon_detail.coupon_detail_status="USED",1,NULL)) as used_total,
|
|
|
+ COUNT(IF(app_coupon_detail.coupon_detail_status="ACTIVED" or app_coupon_detail.coupon_detail_status="WAITING",1,NULL)) as unused_total,
|
|
|
+ MAX(app_coupon_detail.coupon_detail_deadline_datetime) as deadline_datetime')
|
|
|
+ ->orderBy('deadline_datetime', 'DESC')
|
|
|
+ ->forPage($page, $pageSize)
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ foreach ($rows 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);
|
|
|
+ unset($item['member'], $item['cert'], $item['info']);
|
|
|
+
|
|
|
+ $item['invalid_total'] = $item['total'] - $item['used_total'] - $item['unused_total'];
|
|
|
+ // 优惠券分类
|
|
|
+ $coupon = Coupon::with('category')->where('coupon_id', $item['join_detail_coupon_id'])
|
|
|
+ ->select('coupon_id', 'join_coupon_category_id')
|
|
|
+ ->first();
|
|
|
+ if (!empty($coupon) && !empty($coupon->category)) {
|
|
|
+ $item['category_name'] = $coupon->category->category_name;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return json_success('', compact('rows', 'page', 'pageSize', 'total'));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @Desc 我的卡券 领取记录
|
|
|
* @Author Gorden
|