CashSend.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * 下单行为类.
  4. * User: qissen
  5. * Date: 2018/2/19
  6. * Time: 13:59
  7. */
  8. namespace app\mobile\behavior;
  9. use app\core\model\Cash;
  10. use app\core\model\Cang;
  11. use app\core\model\User;
  12. use app\core\model\UserAccount;
  13. use app\core\service\Finance;
  14. use think\Db;
  15. use think\Exception;
  16. use think\Log;
  17. class CashSend
  18. {
  19. //下单成功
  20. public function run(&$params)
  21. {
  22. Log::write('CashSend', 'behavior');
  23. // 行为逻辑
  24. $cang = $params['cang'];
  25. $user = $params['user'];
  26. //如果是虚拟用户,则不执行
  27. if($user['isForged']) {
  28. return true;
  29. }
  30. $this->cashSendOnGuideForIntroduce($user);
  31. $this->cashSendOnCommissionForIntroduce($user, $cang);
  32. return true;
  33. }
  34. //邀请注册返现(引导)
  35. public function cashSendOnGuideForIntroduce($user) {
  36. $day = 30;//过了30天不投,gg
  37. $money = 100;//累计100000才能发
  38. $span = 1;//过几天发
  39. $sendMoney = 100;//给多少钱啊,嗯
  40. $sendMoney_bei = 100;
  41. if(
  42. $user['isForged'] ||//如果为虚拟用户
  43. $user['isIntroduceCashSend'] ||//如果已经发送就不发
  44. $user->getData('addTime') + $day * 86400 < THINK_START_TIME ||//如果已经过期了,不发
  45. $user->userAccount['hasInvestBenTotal'] < $money ||//如果没投到一定量,不发
  46. !$user['introduce']//如果没有邀请人,不发
  47. ) {
  48. Log::info($user['isForged'].'_'.$user['isIntroduceCashSend'].'_'.($user->getData('addTime') + $day * 86400).'_'.$user->userAccount['hasInvestBenTotal'].'_'.$user['introduce']);
  49. return;
  50. }
  51. $userFrom = User::get($user['introduce']);
  52. if(!$userFrom) {
  53. return;
  54. }
  55. //生成被邀请人(我)一个返现
  56. Cash::create([
  57. 'mode'=>Cash::MODE_INTRODUCE_BEI,
  58. 'modeID'=>$user['userID'],//被邀请人(我)
  59. 'outerNumber'=>'',
  60. 'userID'=>$userFrom['userID'],
  61. 'fromUser'=>'',
  62. 'money'=>$sendMoney_bei,
  63. 'estimateTime'=>THINK_START_TIME + $span * 86400
  64. ]);
  65. $userAccount = UserAccount::get([
  66. 'userID'=>$user['userID']
  67. ]);
  68. $userAccount['introduceMoney'] = $userAccount['introduceMoney'] + $sendMoney;
  69. $userAccount->allowField(['introduceMoney'])->save();
  70. //生成邀请人一个返现
  71. Cash::create([
  72. 'mode'=>Cash::MODE_INTRODUCE,
  73. 'modeID'=>$userFrom['userID'],//邀请人
  74. 'outerNumber'=>'',
  75. 'userID'=>$user['userID'],
  76. 'fromUser'=>'',
  77. 'money'=>$sendMoney_bei,
  78. 'estimateTime'=>THINK_START_TIME + $span * 86400
  79. ]);
  80. $userAccountFrom = UserAccount::get([
  81. 'userID'=>$userFrom['userID']
  82. ]);
  83. $userAccountFrom['introduceMoney'] = $userAccountFrom['introduceMoney'] + $sendMoney_bei;
  84. $userAccountFrom->allowField(['introduceMoney'])->save();
  85. $user['isIntroduceCashSend'] = 1;
  86. $user->allowField(['isIntroduceCashSend'])->save();
  87. return;
  88. }
  89. //邀请注册返现(提成)
  90. public function cashSendOnCommissionForIntroduce($user, $cang) {
  91. if( !$user['introduce']) {
  92. return;
  93. }
  94. if($user->getData('addTime') + 365 * 86400 < THINK_START_TIME) {
  95. return;
  96. }
  97. $userFrom = User::get($user['introduce']);
  98. if(!$userFrom) {
  99. return;
  100. }
  101. $span = 1;
  102. $year = 1;
  103. if($cang['moneySubject'] >= 0 && $cang['moneySubject'] < 5000) {
  104. $year = 1;
  105. }
  106. else if($cang['moneySubject'] >= 5000 && $cang['moneySubject'] < 30000) {
  107. $year = 3;
  108. }
  109. else if($cang['moneySubject'] >= 30000 && $cang['moneySubject'] < 100000) {
  110. $year = 5;
  111. }
  112. else if($cang['moneySubject'] >= 100000 && $cang['moneySubject'] < 200000) {
  113. $year = 10;
  114. }
  115. else if($cang['moneySubject'] >= 200000) {
  116. $year = 15;
  117. }
  118. $money = $cang['interest'] * $year / 100;
  119. //生成邀请人一个返现
  120. Cash::create([
  121. 'mode'=>Cash::MODE_INTRODUCE_COMMISSION,
  122. 'modeID'=>$cang['cangID'],//邀请人
  123. 'outerNumber'=>'',
  124. 'userID'=>$userFrom['userID'],
  125. 'fromUser'=>'',
  126. 'money'=>$money,
  127. 'estimateTime'=>THINK_START_TIME + $span * 86400
  128. ]);
  129. $userAccountFrom = $userFrom->userAccount;
  130. $userAccountFrom['introduceMoney'] = $userAccountFrom['introduceMoney'] + $money;
  131. $userAccountFrom->allowField(['introduceMoney'])->save();
  132. return;
  133. }
  134. }