TjFlClass.php 2.5 KB

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