shopId ?? 0; $flData = self::getAllByCondition(['shopId' => $shopId, 'delStatus' => 0], null, '*', null, true); if (empty($flData)) { util::fail('红包发完了'); } $ghsId = $ghs->id ?? 0; $ghsName = $ghs->name ?? ''; $ghsAvatar = $ghs->avatar ?? ''; $ghsSjId = $ghs->sjId ?? 0; $ghsShopId = $ghs->shopId ?? 0; $customId = $ghs->customId ?? 0; $ghsShop = ShopClass::getById($ghsShopId, true); $customName = $custom->name ?? ''; $customPy = $custom->py ?? ''; $customAvatar = $custom->avatar ?? ''; $customSjId = $custom->sjId ?? 0; $customShopId = $custom->shopId ?? 0; $sjId = $custom->sjId ?? 0; $shopId = $custom->shopId ?? 0; foreach ($flData as $item) { $hbAmount = $item->hbAmount ?? 0; $hbNum = $item->num ?? 0; $valid = $item->valid ?? 0; $miniExpend = $item->miniExpend ?? 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_NEW, 'remark' => "新人红包", ]; HbClass::add($coupon); } } $ghs->sendNewGift = 1; $ghs->save(); $custom->getNewGift = 1; $custom->save(); WxMessageClass::ghsCustomGetNewGiftInform($ghsShop, $custom); } }