|
@@ -4,6 +4,7 @@ namespace app\admin\controller\member;
|
|
|
|
|
|
use app\admin\service\member\MemberService;
|
|
|
use app\admin\validate\member\MemberValidate;
|
|
|
+use app\model\Coupon;
|
|
|
use app\model\CouponDetail;
|
|
|
use app\model\Family;
|
|
|
use app\model\FamilyMember;
|
|
@@ -473,31 +474,31 @@ class MemberController
|
|
|
->select('coupon.coupon_name', 'coupon.coupon_classify')
|
|
|
->get()
|
|
|
->toArray();
|
|
|
- $data = ['manjian'=>0,'diyong'=>0,'zhekou'=>0,'lijian'=>0,'zengpin'=>0,'fuli'=>0,'nianka'=>0,'jika'=>0,'yueka'=>0];
|
|
|
+ $data = ['manjian' => 0, 'diyong' => 0, 'zhekou' => 0, 'lijian' => 0, 'zengpin' => 0, 'fuli' => 0, 'nianka' => 0, 'jika' => 0, 'yueka' => 0];
|
|
|
foreach ($coupons as $item) {
|
|
|
- if ($item['coupon_classify'] == '满减券'){
|
|
|
+ if ($item['coupon_classify'] == '满减券') {
|
|
|
$data['manjian'] += 1;
|
|
|
- }elseif ($item['coupon_classify'] == '抵用券'){
|
|
|
+ } elseif ($item['coupon_classify'] == '抵用券') {
|
|
|
$data['diyong'] += 1;
|
|
|
- }elseif ($item['coupon_classify'] == '折扣券'){
|
|
|
+ } elseif ($item['coupon_classify'] == '折扣券') {
|
|
|
$data['zhekou'] += 1;
|
|
|
- }elseif ($item['coupon_classify'] == '立减券'){
|
|
|
+ } elseif ($item['coupon_classify'] == '立减券') {
|
|
|
$data['lijian'] += 1;
|
|
|
- }elseif ($item['coupon_classify'] == '赠品券'){
|
|
|
+ } elseif ($item['coupon_classify'] == '赠品券') {
|
|
|
$data['zengpin'] += 1;
|
|
|
- }elseif ($item['coupon_classify'] == '福利券'){
|
|
|
+ } elseif ($item['coupon_classify'] == '福利券') {
|
|
|
$data['fuli'] += 1;
|
|
|
- }elseif ($item['coupon_classify'] == '年卡'){
|
|
|
+ } elseif ($item['coupon_classify'] == '年卡') {
|
|
|
$data['nianka'] += 1;
|
|
|
- }elseif ($item['coupon_classify'] == '季卡'){
|
|
|
+ } elseif ($item['coupon_classify'] == '季卡') {
|
|
|
$data['jika'] += 1;
|
|
|
- }elseif ($item['coupon_classify'] == '月卡'){
|
|
|
+ } elseif ($item['coupon_classify'] == '月卡') {
|
|
|
$data['yueka'] += 1;
|
|
|
}
|
|
|
}
|
|
|
- $data['total'] = $data['manjian']+$data['diyong']+$data['zhekou']+$data['lijian']+$data['zengpin']+$data['fuli']+$data['nianka']+$data['jika']+$data['yueka'];
|
|
|
+ $data['total'] = $data['manjian'] + $data['diyong'] + $data['zhekou'] + $data['lijian'] + $data['zengpin'] + $data['fuli'] + $data['nianka'] + $data['jika'] + $data['yueka'];
|
|
|
|
|
|
- return json_success('',$data);
|
|
|
+ return json_success('', $data);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -528,9 +529,16 @@ class MemberController
|
|
|
])
|
|
|
->leftJoin('coupon', 'coupon.coupon_id', '=', 'coupon_detail.join_detail_coupon_id')
|
|
|
->where('join_coupon_detail_member_id', $memberId)
|
|
|
- ->where('coupon.coupon_classify', $classify);
|
|
|
+ ->where('coupon.coupon_classify', $classify)
|
|
|
+ ->groupBy('join_coupon_detail_member_id', 'join_detail_coupon_id');
|
|
|
$total = $coupons->count();
|
|
|
- $rows = $coupons->select('coupon_detail.*', 'coupon.coupon_name', 'coupon.coupon_classify','coupon_value')
|
|
|
+ $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();
|
|
@@ -549,7 +557,71 @@ class MemberController
|
|
|
$item['member_name'] = MemberService::getMemberName($mobile, $certName, $nickname);
|
|
|
unset($item['member'], $item['cert'], $item['info']);
|
|
|
|
|
|
- $data[$item['coupon_classify']][] = $item;
|
|
|
+ $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
|
|
|
+ * @Date 2024/8/22 18:45
|
|
|
+ *
|
|
|
+ * @param Request $request
|
|
|
+ * @return \support\Response
|
|
|
+ */
|
|
|
+ public function couponDetail(Request $request)
|
|
|
+ {
|
|
|
+ $memberId = $request->get('member_id', '');
|
|
|
+ $couponId = $request->get('coupon_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)
|
|
|
+ ->where('coupon.coupon_id', $couponId);
|
|
|
+ $total = $coupons->count();
|
|
|
+ $rows = $coupons->select('coupon_detail.*', 'coupon.coupon_name', 'coupon.coupon_classify', 'coupon.coupon_value')
|
|
|
+ ->orderBy('coupon_detail_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']);
|
|
|
+ if (!empty($coupon) && !empty($coupon->category)) {
|
|
|
+ $item['category_name'] = $coupon->category->category_name;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return json_success('', compact('rows', 'page', 'pageSize', 'total'));
|