CommissionEvent.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace app\event\order;
  3. use app\model\Member;
  4. use app\model\MemberAccount;
  5. use app\model\MemberAccountList;
  6. use app\model\Order;
  7. use app\model\SysConfig;
  8. use support\Db;
  9. use support\exception\BusinessException;
  10. class CommissionEvent
  11. {
  12. //{
  13. //"config": {
  14. //"name": "名称",
  15. //"valid": 365, //有效天
  16. //"protocol": 229, //服务协议分类ID
  17. //"notice":["", ""] //注意事项数组
  18. //},
  19. //"goods": {
  20. // "goods_id": "", //产品ID
  21. // "goods_sku_id": 0, //产品SKUID
  22. // "amount": "goods_sales_price" //核算金额字段
  23. // },
  24. // "commission": {
  25. // "direct": 0.2, //直属提成
  26. // "indirect": 0.1, //间属提成
  27. // "relate-consum": 0.1, //消费关联提成 带客
  28. // "invite-non-identity": 0.05, //邀请人非身份会员达成提成
  29. // "agent-senior-join": 0.05, //中介加盟合伙人提成
  30. // "agent-senior-strategy": 0.05, //中介战略合伙人提成
  31. // "account":"CASH" //提成写入账户
  32. // },
  33. // "account": {
  34. // "account":"CASH", //达成金额进入账户 不则为空
  35. // "added":0.12 //达成金额增值 不则为0
  36. // },
  37. // "control": {
  38. // "notify": "procMemberPartnerExec", //回调函数
  39. // "if_installment": "N", //是否支持分期
  40. // "if_commission_out": "Y" //提成是否可提现
  41. // }
  42. //}
  43. public function order($params)
  44. {
  45. // 提成设置
  46. // $config = SysConfig::where('config_key', 'app-identity-partner-config')->first();
  47. // $configParams = json_decode($config->config_value_json, true);
  48. // Db::beginTransaction();
  49. // try {
  50. // $order = Order::where('order_id', $params['orderId'])->where('order_status_payment', 'SUCCESS')->first();
  51. // // 有传过来的
  52. // if (!empty($params['join_invite_member_id'])) {
  53. // $inviteMemberId = $params['join_invite_member_id'];
  54. // } else {
  55. // // 下单人
  56. // $member = Member::where('member_id', $order->join_order_member_id)->first();
  57. // if (empty($member->join_invite_member_id)) {
  58. // throw new BusinessException("没有直属上级");
  59. // }
  60. // $inviteMemberId = $member->join_invite_member_id;
  61. // }
  62. // // 上级
  63. // $memberUp = Member::where('member_id', $inviteMemberId)->first();
  64. // if ($memberUp->member_is_partner == 'Y') {
  65. // $identity = 'PARTNER';
  66. // } elseif ($memberUp->member_is_referrer == 'Y') {
  67. // $identity = 'REFERRER';
  68. // }else{
  69. // throw new BusinessException("直属上级非合伙人或者推荐官");
  70. // }
  71. // // 记录的JSON
  72. // $accountListJson = [
  73. // 'line' => 'relate-consum',
  74. // 'amount' => $order->order_amount_pay,
  75. // 'identity' => $identity,
  76. // 'order_id' => $order->order_id,
  77. // 'master_member_id' => $order->join_order_member_id
  78. // ];
  79. // // 提成
  80. // $this->commissionToMember($inviteMemberId, $accountListJson, round($configParams['commission']['relate-consum'] * $order->order_amount_pay, 2), '消费');
  81. //
  82. // Db::commit();
  83. // _syslog("提成", "计算提成成功");
  84. // } catch (BusinessException $e) {
  85. // Db::rollBack();
  86. // _syslog("提成", "计算提成失败:" . $e->getMessage());
  87. // } catch (\Exception $e) {
  88. // dump($e->getMessage());
  89. // Db::rollBack();
  90. // _syslog("提成", "计算提成失败");
  91. // }
  92. }
  93. /**
  94. * @Desc
  95. * @Author Gorden
  96. * @Date 2024/9/25 15:14
  97. *
  98. * @param $memberId
  99. * @param $accountListJson
  100. * @param $money
  101. * @return void
  102. */
  103. private function commissionToMember($memberId, $accountListJson, $money, $accountListCategory)
  104. {
  105. $account = MemberAccount::where('join_account_member_id', $memberId)->where('member_account_classify', 'CASH')->first();
  106. $account->member_account_income = $account->member_account_income + $money;
  107. $account->member_account_surplus = $account->member_account_surplus + $money;
  108. $account->save();
  109. MemberAccountList::insert([
  110. 'join_list_member_account_nbr' => $memberId . '-CASH',
  111. 'join_member_account_list_member_id' => $memberId,
  112. 'member_account_list_status' => 'ACTIVED',
  113. 'member_account_list_attr' => 'IN',
  114. 'member_account_list_classify' => $accountListJson['identity'],
  115. 'member_account_list_category' => $accountListCategory,
  116. 'member_account_list_datetime' => date('Y-m-d H:i:s'),
  117. 'member_account_list_amount' => $money,
  118. 'member_account_list_json' => json_encode($accountListJson),
  119. 'member_account_list_addtimes' => time()
  120. ]);
  121. }
  122. }