StreamBusiness.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\business;
  3. use Illuminate\Support\Arr;
  4. use support\Db;
  5. use support\Redis;
  6. class StreamBusiness
  7. {
  8. /** 新增金额
  9. * @param $uid
  10. * @param $money
  11. * @param $type
  12. * @param $mold
  13. * @param $mold_filed
  14. * @param $source_id
  15. * @return void
  16. * @throws \Exception
  17. */
  18. static public function addStream($uid, $money, $type, $mold, $mold_filed, $source_id = 0)
  19. {
  20. try {
  21. $userData = Db::table('wa_users')->where('id', $uid)->first();
  22. Db::table('wa_users')->where('id', $uid)->increment($mold_filed, $money);
  23. $total_money = bcadd($userData->$mold_filed, $money, 2);
  24. Db::table('wa_stream')->insert([
  25. 'user_id' => $uid,
  26. 'money' => $money,
  27. 'total_money' => $total_money,
  28. 'type' => $type,
  29. 'mold' => $mold,
  30. 'source_id' => $source_id,
  31. 'add_time' => time(),
  32. 'created_at' => date('Y-m-d H:i:s'),
  33. 'updated_at' => date('Y-m-d H:i:s'),
  34. ]);
  35. } catch (\Throwable $exception) {
  36. throw new \Exception($exception->getMessage());
  37. }
  38. }
  39. /** 扣除金额
  40. * @param $uid
  41. * @param $money
  42. * @param $type
  43. * @param $mold
  44. * @param $mold_filed
  45. * @param $source_id
  46. * @return void
  47. * @throws \Exception
  48. */
  49. static public function delStream($uid, $money, $type, $mold, $mold_filed, $source_id = 0)
  50. {
  51. try {
  52. $userData = Db::table('wa_users')->where('id', $uid)->first();
  53. Db::table('wa_users')->where('id', $uid)->decrement($mold_filed, $money);
  54. $total_money = bcsub($userData->$mold_filed, $money, 2);
  55. if($type == 25 || $type == 21 || $type == 27 || $type == 28){
  56. }else{
  57. if ($total_money < 0) {
  58. throw new \Exception('您余额不足!');
  59. }
  60. }
  61. Db::table('wa_stream')->insert([
  62. 'user_id' => $uid,
  63. 'money' => '-' . $money,
  64. 'consume_money' => $money,
  65. 'total_money' => $total_money,
  66. 'income' => 2,
  67. 'type' => $type,
  68. 'mold' => $mold,
  69. 'source_id' => $source_id,
  70. 'add_time' => time(),
  71. 'created_at' => date('Y-m-d H:i:s'),
  72. 'updated_at' => date('Y-m-d H:i:s'),
  73. ]);
  74. } catch (\Throwable $exception) {
  75. throw new \Exception($exception->getMessage());
  76. }
  77. }
  78. }