| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace biz\market\classes;
- use biz\base\classes\BaseClass;
- use biz\hb\classes\HbClass;
- use biz\shop\classes\ShopClass;
- use biz\wx\classes\WxMessageClass;
- use common\components\util;
- class XrFlClass extends BaseClass
- {
- public static $baseFile = '\biz\market\models\XrFl';
- //新人福利发红包 ssh 20211026
- public static function giveGift($ghs, $custom)
- {
- $shopId = $ghs->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);
- }
- }
|