XrFlClass.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace biz\market\classes;
  3. use biz\base\classes\BaseClass;
  4. use biz\hb\classes\HbClass;
  5. use biz\shop\classes\ShopClass;
  6. use biz\wx\classes\WxMessageClass;
  7. use common\components\util;
  8. class XrFlClass extends BaseClass
  9. {
  10. public static $baseFile = '\biz\market\models\XrFl';
  11. //新人福利发红包 ssh 20211026
  12. public static function giveGift($ghs, $custom)
  13. {
  14. $shopId = $ghs->shopId ?? 0;
  15. $flData = self::getAllByCondition(['shopId' => $shopId, 'delStatus' => 0], null, '*', null, true);
  16. if (empty($flData)) {
  17. util::fail('红包发完了');
  18. }
  19. $ghsId = $ghs->id ?? 0;
  20. $ghsName = $ghs->name ?? '';
  21. $ghsAvatar = $ghs->avatar ?? '';
  22. $ghsSjId = $ghs->sjId ?? 0;
  23. $ghsShopId = $ghs->shopId ?? 0;
  24. $customId = $ghs->customId ?? 0;
  25. $ghsShop = ShopClass::getById($ghsShopId, true);
  26. $customName = $custom->name ?? '';
  27. $customPy = $custom->py ?? '';
  28. $customAvatar = $custom->avatar ?? '';
  29. $customSjId = $custom->sjId ?? 0;
  30. $customShopId = $custom->shopId ?? 0;
  31. $sjId = $custom->sjId ?? 0;
  32. $shopId = $custom->shopId ?? 0;
  33. foreach ($flData as $item) {
  34. $hbAmount = $item->hbAmount ?? 0;
  35. $hbNum = $item->num ?? 0;
  36. $valid = $item->valid ?? 0;
  37. $miniExpend = $item->miniExpend ?? 0;
  38. for ($i = 0; $i < $hbNum; $i++) {
  39. $start = date("Y-m-d H:i:s");
  40. $end = date("Y-m-d H:i:s", time() + $valid * 86400);
  41. $coupon = [
  42. 'sjId' => $sjId,
  43. 'shopId' => $shopId,
  44. 'beginTime' => $start,
  45. 'endTime' => $end,
  46. 'name' => '红包',
  47. 'amount' => $hbAmount,
  48. 'miniCost' => $miniExpend,
  49. 'status' => HbClass::STATUS_UN_USE,
  50. 'ghsId' => $ghsId,
  51. 'ghsName' => $ghsName,
  52. 'ghsAvatar' => $ghsAvatar,
  53. 'ghsSjId' => $ghsSjId,
  54. 'ghsShopId' => $ghsShopId,
  55. 'customId' => $customId,
  56. 'customName' => $customName,
  57. 'customPy' => $customPy,
  58. 'customAvatar' => $customAvatar,
  59. 'customSjId' => $customSjId,
  60. 'customShopId' => $customShopId,
  61. 'from' => HbClass::FROM_NEW,
  62. 'remark' => "新人红包",
  63. ];
  64. HbClass::add($coupon);
  65. }
  66. }
  67. $ghs->sendNewGift = 1;
  68. $ghs->save();
  69. $custom->getNewGift = 1;
  70. $custom->save();
  71. WxMessageClass::ghsCustomGetNewGiftInform($ghsShop, $custom);
  72. }
  73. }