TuodanController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. namespace App\Http\Controllers\Experience;
  3. use App\Models\Wechat\FormIdModel;
  4. use Illuminate\Http\Request;
  5. use App\Http\Controllers\Controller;
  6. class TuodanController extends Controller
  7. {
  8. //
  9. public function index(Request $request)
  10. {
  11. $openid = $request->openid;
  12. $options = $request->options;
  13. $score = $this->option($options);
  14. $data = $this->result($score);
  15. \DB::table('kdgx_mini_tuodan')->insert([
  16. 'openid' => $openid,
  17. 'created_at' => time(),
  18. 'updated_at' => time(),
  19. 'data' => json_encode($data)
  20. ]);
  21. return [
  22. 'code' => 200,
  23. 'message' => 'OK',
  24. 'data' => $data
  25. ];
  26. }
  27. /**
  28. * 计算选项得分
  29. */
  30. private function option(array $options)
  31. {
  32. $score = 0;
  33. foreach ($options as $key => $option) {
  34. switch ($key) {
  35. case '1':
  36. switch ($option) {
  37. case '0':
  38. case '1':
  39. break;
  40. }
  41. break;
  42. case '2':
  43. switch ($option) {
  44. case '0':
  45. case '1':
  46. case '2':
  47. case '3':
  48. case '4':
  49. case '5':
  50. break;
  51. }
  52. break;
  53. case '3':
  54. switch ($option) {
  55. case '0':
  56. $score += 30;
  57. break;
  58. case '1':
  59. $score += 10;
  60. break;
  61. }
  62. break;
  63. case '4':
  64. switch ($option) {
  65. case '0':
  66. $score += 10;
  67. break;
  68. case '1':
  69. $score += 30;
  70. break;
  71. }
  72. break;
  73. case '5':
  74. switch ($option) {
  75. case '0':
  76. break;
  77. case '1':
  78. $score += 30;
  79. break;
  80. }
  81. break;
  82. case '6':
  83. switch ($option) {
  84. case '0':
  85. case '1':
  86. break;
  87. }
  88. break;
  89. }
  90. }
  91. return $score;
  92. }
  93. public function result(int $score)
  94. {
  95. switch ($score) {
  96. case '20':
  97. $type = rand(2, 4);
  98. $day = 0;
  99. break;
  100. case '40':
  101. case '30':
  102. $type = 1;
  103. $day = rand(361, 1800);
  104. break;
  105. case '60':
  106. case '70':
  107. $type = 1;
  108. $day = rand(31, 360);
  109. break;
  110. case '90':
  111. $type = 1;
  112. $day = rand(1, 30);
  113. break;
  114. default:
  115. $type = rand(2, 4);
  116. $day = 0;
  117. }
  118. $list = array("游戏里", "聚会", "婚礼", "健身房", "美食街", "学校", "旅行中", "商场", "咖啡厅", "公园", "公交车", "地铁里");
  119. $key = array_rand($list);
  120. $place = $list[$key];
  121. return [
  122. 'type' => $type,
  123. 'day' => $day,
  124. 'place' => $place
  125. ];
  126. }
  127. /**
  128. * 几率formId
  129. * @param Request $request
  130. * @return array
  131. */
  132. public function form(Request $request)
  133. {
  134. $this->validate($request, [
  135. 'form_id' => 'required',
  136. 'openid' => 'required',
  137. 'public_id' => 'required',
  138. ]);
  139. FormIdModel::create($request->all());
  140. return [
  141. 'code' => 200,
  142. 'message' => 'OK'
  143. ];
  144. }
  145. public function info()
  146. {
  147. return [
  148. 'code' => 200,
  149. 'message' => 'OK',
  150. 'data' => [
  151. 'is_qrcode' => 0,
  152. ]
  153. ];
  154. }
  155. }