Withdraw_rule.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: scstf
  5. * Date: 2018/9/25
  6. * Time: 18:09
  7. */
  8. namespace App\Api\Model;
  9. use \System\Model;
  10. class Withdraw_rule extends Model
  11. {
  12. protected $table = 'withdraw_rule';
  13. public static function setRule($idd, $startTime, $endTime, $bettingMoney, $needBettingMoney)
  14. {
  15. $data = [
  16. 'account_identity' => $idd,
  17. 'start_time' => is_int ($startTime) ? $startTime : strtotime ($startTime) ?? time (),
  18. 'end_time' => is_int ($endTime) ? $endTime : strtotime ($endTime) ?? time (),
  19. 'bettingMoney' => $bettingMoney,
  20. 'updated_at' => date ('Y-m-d H:i:s'),
  21. 'needBettingMoney' => $needBettingMoney,
  22. 'donate_start' => date ('Y-m-d H:i:s'),
  23. ];
  24. return self::insertGetId ($data);
  25. }
  26. /**
  27. * 更新用户增量流水
  28. * @param string $idd 用户账户UUID
  29. * @param $money 父订单金额
  30. * @param int $rate 增量倍数
  31. * @return int
  32. */
  33. function updateRule($idd, $money, $rate)
  34. {
  35. $withdrawRule = new self();
  36. $with = $withdrawRule->where ('account_identity', $idd)->first ();
  37. $time = date ('Y-m-d H:i:s');
  38. $ret = 1;
  39. $need = (float)$money * ($rate - 1);//目标流水差额
  40. if (!$with) {
  41. self::setRule ($idd, $time, $time, 0, $need);
  42. } else {
  43. $with->increment ('needBettingMoney', $need);//目标流水差额
  44. $with->updated_at = date ('Y-m-d H:i:s');
  45. $ret = $with->update ();
  46. }
  47. return $ret;
  48. }
  49. /**
  50. * 提现时验证用户的流水记录
  51. * @param string $idd 用户账户编号uuid
  52. * @return null 没有记录返回NULL,成功返回用户当前有效下注总流水和目标总流水
  53. */
  54. function check($idd)
  55. {
  56. $where = ['account_identity' => $idd];
  57. $data = self::where ($where)->first (['bettingMoney', 'needBettingMoney', 'donate_start']);
  58. if (!$data) return null;
  59. $time = $data->donate_start;
  60. $bet = (new MoneyBuy())->getBetMoney ($time, $idd);//常规投注
  61. $sixBet = (new SixMoneyBuy())::getBetMoney ($time, $idd);//六合投注
  62. $data->bettingMoney = $bet + $sixBet;//总投注流水
  63. $recharge = Money_recharge::where ('account_identity', $idd)
  64. ->where ('complete_time', '>=', $time) //首笔金额发生时间
  65. ->where ('status', 1) //订单状态为成功
  66. //->whereIn ('trade_type', [11, 14])
  67. ->sum (DB::Raw ('money * rate'));//资金表中的流水倍数和
  68. $data->needBettingMoney += $recharge;//差额流水+资金表中流水要求=总目标流水
  69. return $data;
  70. }
  71. public static function rmRule($idd)
  72. {
  73. return self::where ('account_identity', $idd)->delete ();
  74. }
  75. public static function getRule($id)
  76. {
  77. return self::where ('id', $id)->first ();
  78. }
  79. }