'红包', 'amount' => '5', 'miniCost' => '50', 'beginTime' => "+6 days", 'endTime' => "+7 days", ], [ 'name' => '红包', 'amount' => '10', 'miniCost' => '50', 'beginTime' => "+3 days", 'endTime' => "+7 days", ], [ 'name' => '红包', 'amount' => '15', 'miniCost' => '50', 'beginTime' => "+0 days", 'endTime' => "+7 days", ] ]; //充值发红包 ssh 20211002 public static function rechargeGiveCoupon($recharge) { $sjId = $recharge->sjId ?? 0; $shopId = $recharge->shopId ?? 0; $ghsId = $recharge->ghsId ?? 0; $hbAmount = $recharge->hbAmount ?? 0; $hbNum = $recharge->hbNum ?? 0; $valid = $recharge->valid ?? 0; $miniExpend = $recharge->miniExpend ?? 0; $amount = $recharge->amount ?? 0; $rechargeId = $recharge->id ?? 0; if ($hbNum <= 0) { noticeUtil::push("充值成功但红包没有发放成功,数量:{$hbNum} 金额:{$amount} rechargeId:{$rechargeId}", '15280215347'); return false; } $ghs = GhsClass::getById($ghsId, true); if (empty($ghs)) { noticeUtil::push("充值成功但红包没有发放成功,没有找到供货商,数量:{$hbNum} 金额:{$amount} rechargeId:{$rechargeId}", '15280215347'); return false; } $ghsName = $ghs->name ?? ''; $ghsAvatar = $ghs->avatar ?? ''; $ghsSjId = $ghs->sjId ?? 0; $ghsShopId = $ghs->shopId ?? 0; $customId = $ghs->customId ?? 0; $custom = CustomClass::getById($customId, true); if (empty($custom)) { noticeUtil::push("充值成功但红包没有发放成功,没有找到客户,数量:{$hbNum} 金额:{$amount} rechargeId:{$rechargeId}", '15280215347'); return false; } $customName = $custom->name ?? ''; $customPy = $custom->py ?? ''; $customAvatar = $custom->avatar ?? ''; $customSjId = $custom->sjId ?? 0; $customShopId = $custom->shopId ?? 0; for ($i = 0; $i < $hbNum; $i++) { $start = date("Y-m-d H:i:s"); $end = date("Y-m-d H:i:s", time() + $valid * 86400); $coupon = [ 'sjId' => $sjId, 'shopId' => $shopId, 'beginTime' => $start, 'endTime' => $end, 'name' => '红包', 'amount' => $hbAmount, 'miniCost' => $miniExpend, 'status' => HbClass::STATUS_UN_USE, 'ghsId' => $ghsId, 'ghsName' => $ghsName, 'ghsAvatar' => $ghsAvatar, 'ghsSjId' => $ghsSjId, 'ghsShopId' => $ghsShopId, 'customId' => $customId, 'customName' => $customName, 'customPy' => $customPy, 'customAvatar' => $customAvatar, 'customSjId' => $customSjId, 'customShopId' => $customShopId, 'from' => HbClass::FROM_RECHARGE, 'targetId' => $rechargeId, 'remark' => $start . "充值{$amount}元", ]; HbClass::add($coupon); } } public static function groupBaseInfo($list) { return $list; } // 赠送3张红包 public static function addDefaultCoupon($data) { $couponData = []; foreach (self::$defaultCoupon as $val) { $coupon = [ 'sjId' => $data['sjId'], 'shopId' => $data['shopId'], 'beginTime' => date('Y-m-d 00:00:00', strtotime($val['beginTime'])), 'endTime' => date('Y-m-d 00:00:00', strtotime($val['endTime'])), 'name' => $val['name'], 'amount' => $val['amount'], 'miniCost' => $val['miniCost'], 'status' => self::STATUS_UN_USE, ]; $couponData[] = $coupon; } return self::batchAdd($couponData); } public static function expire($coupon) { $coupon->status = ShopCouponClass::STATUS_EXPIRE; return $coupon->save(); } public static function ghsSendHb($shopId, $ghsId, $amount) { $current = date("Y-m-d H:i:s"); $list = self::getAllByCondition(['shopId' => $shopId, 'status' => ShopCouponClass::STATUS_UN_USE, 'ghsId' => $ghsId], null, '*', null, true); if (empty($list)) { return $list; } $arr = []; foreach ($list as $item) { if ($current >= $item->beginTime && $current < $item->endTime) { if ($item->miniCost <= $amount) { $arr[] = $item; } } } return $arr; } // 商家是否有可用红包 public static function hasValidCoupon($shopId, $ghsId) { } public static function valid($coupon, $shopId) { if (empty($coupon)) { util::fail('没有红包'); } if (isset($coupon->shopId) && $coupon->shopId != $shopId) { util::fail('不是您的红包'); } if ($coupon->status != self::STATUS_UN_USE) { util::fail('此红包无法使用'); } if (isset($coupon->take) && $coupon->take == self::TAKE_HAS) { util::fail('红包被占用'); } $current = date("Y-m-d H:i:s"); if ($coupon->endTime < $current) { util::fail('红包已过期'); } return true; } //红包回滚 ssh 2021.5.18 public static function rollback($coupon) { if (isset($coupon->take) && $coupon->take == self::TAKE_HAS) { $coupon->take = self::TAKE_UN; $coupon->save(); } } }