FootballSettlement.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\Order;
  5. class FootballSettlement extends Command
  6. {
  7. /**
  8. * 命令名称和签名
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'football:settlement';
  13. /**
  14. * 命令描述
  15. *
  16. * @var string
  17. */
  18. protected $description = '足球结算方法';
  19. /**
  20. * 执行命令
  21. *
  22. * @return int
  23. */
  24. public function handle()
  25. {
  26. $this->sportOrderSettlement();
  27. $function = 'MatchWinner';
  28. $params = [
  29. 'amount' => 10,
  30. 'score' => '1-1',
  31. 'detail' => [
  32. 'odds' => [
  33. [
  34. "id" => 1,
  35. "name" => "Match Winner",
  36. "values" => [
  37. [
  38. "value" => "Draw",
  39. "odd" => "3.30"
  40. ]
  41. ]
  42. ]
  43. ]
  44. ],
  45. ];
  46. $result = $this->doFunction($function, $params);
  47. print_r($result);die;
  48. return $result;
  49. }
  50. public function sportOrderSettlement(){
  51. $where = [
  52. 'status' => 1,
  53. 'pay_status' => 1,
  54. 'return_status' => 0,
  55. 'settlement_status' => 0,
  56. ];
  57. $list = Order::alias('o')
  58. ->join('sport s', 'o.data_id', '=', 's.data_id')
  59. ->where('s.state', 2)
  60. ->where($where)
  61. ->select('o.*', 's.score','s.half_score')
  62. ->get()->toArray();
  63. foreach($list as $item) {
  64. $detail = json_decode($item['detail'], true);
  65. $odd_id = $detail['odds'][0]['id'];
  66. $function = SportOdds::where('id',$odd_id)->value('function_name');
  67. $params = [
  68. 'score' => $item['score'],
  69. 'half_score' => $item['half_score'],
  70. 'data_id' => $item['data_id'],
  71. 'home_team_id' => $item['home_team_id'],
  72. 'guest_team_id' => $item['guest_team_id'],
  73. ];
  74. $result = $function($item['amount'], $detail, $params);
  75. print_r($result);die;
  76. }
  77. }
  78. }