XrFlClass.php 2.4 KB

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