ReferrerEvent.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace app\event\order;
  3. use app\admin\service\coupon\CouponService;
  4. use app\admin\service\order\CommissionService;
  5. use app\model\Goods;
  6. use app\model\Member;
  7. use app\model\MemberAccount;
  8. use app\model\PayDetail;
  9. use app\model\SysConfig;
  10. use support\Db;
  11. use support\exception\BusinessException;
  12. use support\Log;
  13. class ReferrerEvent
  14. {
  15. public function grant($params)
  16. {
  17. try {
  18. Log::info("进入推荐官事件", $params);
  19. $config = SysConfig::where('config_key', 'app-identity-referrer-config')->first();
  20. $configParams = json_decode($config->config_value_json, true);
  21. // 更新身份{"duedate": "2025-09-26", "datetime": "2024-09-27 14:40:51", "order_id": "OD2409271440L951"}
  22. $memberUpdateData = [
  23. 'member_referrer_json' => json_encode([
  24. 'datetime' => date('Y-m-d H:i:s'),
  25. 'duedate' => date('Y-m-d', strtotime("+" . ($configParams['config']['valid']-1) . ' day')),
  26. 'order_id' => $params['orderId'],
  27. ]),
  28. 'member_is_referrer' => 'Y',
  29. ];
  30. Member::where('member_id', $params['member_id'])->update($memberUpdateData);
  31. // 给上级提成
  32. CommissionService::commission($configParams, $params['member_id'], $params['orderId'], $params['order_amount_pay'], '推荐康养推荐官');
  33. //发放优惠券
  34. $params['gettype'] = 'REFERRER';
  35. CouponService::autoSendCouponByGoods($params);
  36. } catch (BusinessException $e) {
  37. _syslog('会员合伙人', '推荐官处理失败:' . $e->getMessage());
  38. throw new BusinessException("推荐官处理失败");
  39. } catch (\Exception $e) {
  40. Log::info('PARTNER_DISPOSE_ERROR:' . $e->getMessage(), $params);
  41. _syslog('会员合伙人', '推荐官处理失败');
  42. throw new BusinessException("推荐官处理失败");
  43. }
  44. }
  45. }