|
@@ -9,6 +9,7 @@ use app\model\Coupon;
|
|
|
use app\model\CouponDetail;
|
|
|
use app\model\CouponGoods;
|
|
|
use app\model\Member;
|
|
|
+use app\model\SysDept;
|
|
|
use support\Request;
|
|
|
use support\Response;
|
|
|
|
|
@@ -150,8 +151,8 @@ class CouponDetailController extends Curd
|
|
|
public function statistics(Request $request)
|
|
|
{
|
|
|
$total = CouponDetail::count('coupon_detail_id');
|
|
|
- $usedTotal = CouponDetail::where('coupon_detail_status','USED')->count('coupon_detail_id');
|
|
|
- $unUsedTotal = CouponDetail::whereIn('coupon_detail_status',['ACTIVED'])->count('coupon_detail_id');
|
|
|
+ $usedTotal = CouponDetail::where('coupon_detail_status', 'USED')->count('coupon_detail_id');
|
|
|
+ $unUsedTotal = CouponDetail::whereIn('coupon_detail_status', ['ACTIVED'])->count('coupon_detail_id');
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -285,4 +286,171 @@ class CouponDetailController extends Curd
|
|
|
|
|
|
return json_success('', $data);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Desc 导出优惠券明细
|
|
|
+ * @Author Gorden
|
|
|
+ * @Date 2024/11/1 9:19
|
|
|
+ *
|
|
|
+ * @param Request $request
|
|
|
+ * @return Response
|
|
|
+ */
|
|
|
+ public function export(Request $request)
|
|
|
+ {
|
|
|
+ $couponName = $request->get('coupon_name', '');
|
|
|
+ $couponClassify = $request->get('coupon_classify');
|
|
|
+ $getType = $request->get('get_type');
|
|
|
+ $couponDetailStatus = $request->get('coupon_detail_status');
|
|
|
+ $memberId = $request->get('join_coupon_detail_member_id');
|
|
|
+ $couponDetailAddtimes = $request->get('coupon_detail_addtimes');
|
|
|
+ $couponDetailIds = $request->get('coupon_detail_ids', []);
|
|
|
+
|
|
|
+ $model = CouponDetail::with([
|
|
|
+ 'member' => function ($query) {
|
|
|
+ $query->select('member_id', 'member_mobile', 'join_invite_member_id', 'member_extend_json');
|
|
|
+ },
|
|
|
+ 'cert' => function ($query) {
|
|
|
+ $query->select('join_cert_member_id', 'member_cert_name');
|
|
|
+ },
|
|
|
+ 'info' => function ($query) {
|
|
|
+ $query->select('join_info_member_id', 'member_info_business', 'member_info_service');
|
|
|
+ }
|
|
|
+ ])->leftJoin('coupon', 'coupon.coupon_id', '=', 'coupon_detail.join_detail_coupon_id')
|
|
|
+ ->select('coupon_detail.*', 'coupon.coupon_id', 'coupon.coupon_name', 'coupon.coupon_json', 'coupon.coupon_classify');
|
|
|
+
|
|
|
+ if ($couponClassify) {
|
|
|
+ $model = $model->where('coupon.coupon_classify', $couponClassify);
|
|
|
+ }
|
|
|
+ if (!empty($getType)) {
|
|
|
+ $model = $model->whereJsonContains("coupon_detail_extend_json->gettype", $getType);
|
|
|
+ }
|
|
|
+ if (!empty($couponDetailStatus)) {
|
|
|
+ $model = $model->where('coupon_detail_status', $couponDetailStatus);
|
|
|
+ }
|
|
|
+ if (!empty($memberId)) {
|
|
|
+ $model = $model->where('join_coupon_detail_member_id', $memberId);
|
|
|
+ }
|
|
|
+ if (!empty($couponDetailAddtimes)) {
|
|
|
+ $couponDetailAddtimes[0] = strtotime($couponDetailAddtimes[0]);
|
|
|
+ $couponDetailAddtimes[1] = strtotime($couponDetailAddtimes[1]);
|
|
|
+ $model = $model->whereBetween('coupon_detail_addtimes', $couponDetailAddtimes);
|
|
|
+ }
|
|
|
+ if (!empty($couponDetailIds)) {
|
|
|
+ $model = $model->whereIn('coupon_detail_id', $couponDetailIds);
|
|
|
+ }
|
|
|
+ if (!empty($couponName)) {
|
|
|
+ $couponIds = Coupon::where('coupon_name', 'like', '%' . $couponName . '%')->pluck('coupon_id')->toArray();
|
|
|
+ $model = $model->whereIn('join_detail_coupon_id', $couponIds);
|
|
|
+ }
|
|
|
+ $details = $model->get()->toArray();
|
|
|
+
|
|
|
+ // 查出所有门店
|
|
|
+ $depts = SysDept::where('dept_category', '营业场所')->pluck('dept_name', 'dept_id')->toArray();
|
|
|
+
|
|
|
+ $data = [];
|
|
|
+ foreach ($details as $detail) {
|
|
|
+ $mobile = !empty($detail['member']) ? $detail['member']['member_mobile'] : '';
|
|
|
+ $certName = !empty($detail['cert']) ? $detail['cert']['member_cert_name'] : '';
|
|
|
+ $business = !empty($detail['info']) ? $detail['info']['member_info_business'] : '';
|
|
|
+ $service = !empty($detail['info']) ? $detail['info']['member_info_service'] : '';
|
|
|
+ // 推荐人
|
|
|
+ if (!empty($detail['member']) && !empty($detail['member']['join_invite_member_id'])) {
|
|
|
+ $referrer = Member::with([
|
|
|
+ 'cert' => function ($query) {
|
|
|
+ $query->select('join_cert_member_id', 'member_cert_name');
|
|
|
+ }
|
|
|
+ ])->where('member_id', $detail['member']['join_invite_member_id'])
|
|
|
+ ->select('member_id', 'member_mobile')
|
|
|
+ ->first();
|
|
|
+ $referrerMobile = !empty($referrer->member_mobile) ? $referrer->member_mobile : '';
|
|
|
+ $referrerCertName = !empty($referrer->cert) ? $referrer->cert->member_cert_name : '';
|
|
|
+ $detail['referrer_name'] = MemberService::getMemberCertName($referrerMobile, $referrerCertName, '');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 顾问
|
|
|
+ if (!empty($detail['member']) && !empty($detail['member']['member_extend_json'])) {
|
|
|
+ $memberExtendJson = json_decode($detail['member']['member_extend_json'], true);
|
|
|
+ if (!empty($memberExtendJson['referee'])) {
|
|
|
+ $consultant = [];
|
|
|
+ foreach ($memberExtendJson['referee'] as $item) {
|
|
|
+ $consultant[] = $item;
|
|
|
+ }
|
|
|
+ $detail['consultant'] = implode(',', $consultant);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 门店
|
|
|
+ if (!empty($detail['coupon_json'])) {
|
|
|
+ $couponJson = json_decode($detail['coupon_json'], true);
|
|
|
+ if (!isset($couponJson['premises'])) {
|
|
|
+ $detail['premises'] = "所有门店";
|
|
|
+ } else {
|
|
|
+ $deptName = [];
|
|
|
+ foreach ($couponJson['premises'] as $premisesId) {
|
|
|
+ if (isset($depts[$premisesId]) && !in_array($depts[$premisesId], $deptName)) {
|
|
|
+ $deptName[] = $depts[$premisesId];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $detail['premises'] = implode(',', $deptName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 获得方式
|
|
|
+ if (!empty($detail['coupon_detail_extend_json'])) {
|
|
|
+ $couponDetailExtendsJson = json_decode($detail['coupon_detail_extend_json'], true);
|
|
|
+ if (isset($couponDetailExtendsJson['gettype'])) {
|
|
|
+ $detail['get_type'] = self::$getType[$couponDetailExtendsJson['gettype']] ?? '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 有效期限
|
|
|
+ $detail['coupon_detail_gain_datetime'] = !empty($detail['coupon_detail_gain_datetime']) ? date('Y/m/d H:i:s', strtotime($detail['coupon_detail_gain_datetime'])) : '';
|
|
|
+ $detail['coupon_detail_deadline_datetime'] = !empty($detail['coupon_detail_deadline_datetime']) ? date('Y/m/d H:i:s', strtotime($detail['coupon_detail_deadline_datetime'])) : '';
|
|
|
+
|
|
|
+ $data[] = [
|
|
|
+ 'member_name' => MemberService::getMemberCertName($mobile, $certName, ''),
|
|
|
+ 'referrer_name' => $detail['referrer_name'] ?? '',
|
|
|
+ 'coupon_name' => $detail['coupon_name'] ?? '',
|
|
|
+ 'coupon_classify' => $detail['coupon_classify'] ?? '',
|
|
|
+ 'premises' => $detail['premises'] ?? '',
|
|
|
+ 'get_type' => $detail['get_type'] ?? '',
|
|
|
+ 'status' => self::$detailStatus[$detail['coupon_detail_status']] ?? '',
|
|
|
+ 'coupon_detail_used_datetime' => $detail['coupon_detail_used_datetime'] ?? '',
|
|
|
+ 'valid_date' => !empty($detail['coupon_detail_gain_datetime']) ? $detail['coupon_detail_gain_datetime'] . ' - ' . $detail['coupon_detail_deadline_datetime'] : '',
|
|
|
+ 'coupon_detail_addtimes' => $detail['coupon_detail_addtimes'],
|
|
|
+ 'consultant' => $detail['consultant'] ?? '',
|
|
|
+ 'business' => $business,
|
|
|
+ 'service' => $service
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ return json_success('success', $data);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var string[]
|
|
|
+ */
|
|
|
+ public static $getType = [
|
|
|
+ 'VIP' => '购买VIP',
|
|
|
+ 'RECEIVE' => '领取',
|
|
|
+ 'SEND' => '后台发放',
|
|
|
+ 'GIVE' => '转增',
|
|
|
+ 'EXCHANGE' => '兑换',
|
|
|
+ 'COMBINE' => '新客专享',
|
|
|
+ 'ROLE' => '会员升级',
|
|
|
+ 'PARTNER' => '会员合伙人',
|
|
|
+ 'REFERRER' => '康养推荐官',
|
|
|
+ ];
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var string[]
|
|
|
+ */
|
|
|
+ public static $detailStatus = [
|
|
|
+ 'INIT' => '初始状态',
|
|
|
+ 'PENDING' => '待领取',
|
|
|
+ 'ACTIVED' => '可用',
|
|
|
+ 'WAITING' => '待完成',
|
|
|
+ 'USED' => '已使用',
|
|
|
+ 'DISABLED' => '禁用',
|
|
|
+ 'CANCEL' => '取消',
|
|
|
+ 'EXPIRED' => '过期',
|
|
|
+ ];
|
|
|
}
|