InterviewController.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. namespace app\workerapi\controller;
  3. use think\Request;
  4. use app\workerapi\logic\MasterWorkerLogic;
  5. use app\workerapi\validate\MasterWokerValidate;
  6. use app\common\model\master_worker_register\MasterWorkerRegister;
  7. class InterviewController extends BaseApiController
  8. {
  9. public array $notNeedLogin = ['lists'];
  10. private array $list = [
  11. [
  12. 'id' => 1,
  13. 'title' => '请问您目前的工作状态是全职工作还是自由工作?',
  14. 'options' => [
  15. '全职工作',
  16. '自由工作'
  17. ],
  18. 'type' => 1,
  19. ],
  20. [
  21. 'id' => 2,
  22. 'title' => '请问您是否有独立上门给客户提供家电维修/清洗/安装的经验?',
  23. 'options' => [
  24. '有',
  25. '没有'
  26. ],
  27. 'type' => 1,
  28. ],
  29. [
  30. 'id' => 3,
  31. 'title' => '请问您有没有在其他同类型平台的工作经验?',
  32. 'options' => [
  33. '有',
  34. '没有'
  35. ],
  36. 'type' => 1,
  37. ],
  38. [
  39. 'id' => 4,
  40. 'title' => '请简要说明平台名称、工作时间年限、所服务的类目',
  41. 'type' => 3,
  42. ],
  43. [
  44. 'id' => 5,
  45. 'title' => '请选择您具备的经验?',
  46. 'options' => [
  47. '家电维修',
  48. '家电清洗',
  49. '家电安装',
  50. '不具备以上经验'
  51. ],
  52. 'type' => 1,
  53. ]
  54. ];
  55. private array $list2 = [
  56. [
  57. 'id' => 6,
  58. 'title' => '请选择您会的项目?最多选5个,最后会根据您所选的项目进行答题。',
  59. 'options' => [
  60. '空调加氟',
  61. '空调维修',
  62. '冰箱','制冷设备','油烟机','洗衣机','甩干机','燃气热水器','电热水器','燃气灶','干洗机',
  63. ],
  64. 'type' => 2,
  65. ],
  66. [
  67. 'id' => 7,
  68. 'title' => '请选择您会的项目?最多选5个,最后会根据您所选的项目进行答题。',
  69. 'options' => [
  70. '天井机','风管机','家用中央空调','空调','油烟机','洗衣机','热水器','燃气灶','冰箱'
  71. ],
  72. 'type' => 2,
  73. ],
  74. [
  75. 'id' => 8,
  76. 'title' => '请根据您的实际情况选择会哪些家电安装?',
  77. 'options' => [
  78. '空调','其他'
  79. ],
  80. 'type' => 1,
  81. ],
  82. ];
  83. private array $list3 = [
  84. [
  85. 'id' => 9,
  86. 'title' => '请选择您持有的证书?',
  87. 'options' => [
  88. '低压电工作业',
  89. '高压电工作业',
  90. '高处作业',
  91. '制冷与空调作业',
  92. '焊接与热切割作业',
  93. '无',
  94. ],
  95. 'type' => 1,
  96. ],
  97. [
  98. 'id' => 10,
  99. 'title' => '请简单描述您具备的其他技能?',
  100. 'type' => 3,
  101. ]
  102. ];
  103. public function lists(Request $request)
  104. {
  105. // 获取单个 POST 参数
  106. $worker_register_id = $request->post('worker_register_id');
  107. $step = $request->post('step');
  108. // 获取所有 POST 参数
  109. $data = $request->post('data');
  110. if ( !in_array($step, [1,2,3,4])) {
  111. return $this->fail('参数错误');
  112. }
  113. if ($step > 1 && (empty($data) || !is_array($data))) {
  114. return $this->fail('答案不可为空');
  115. }
  116. $worker_register_id = MasterWorkerRegister::where('id',$worker_register_id)->value('id');
  117. if (!$worker_register_id) {
  118. return $this->fail('ID有误');
  119. }
  120. $msg = '操作成功';
  121. $has_next = 1;
  122. $is_success = 0;
  123. $tmplist = array_column($list, null, 'step');
  124. if ($step == 1 ) {
  125. $result[] = $list;
  126. } elseif ($step == 2) {
  127. foreach($data as $item) {
  128. if (empty($item['id']) || ($item['id'] != 4 && empty($item['options']))) {
  129. return $this->fail('参数错误3');
  130. }
  131. if ($item['id'] == 5) {
  132. $options = $item['options'];
  133. }
  134. }
  135. if (empty($options)) {
  136. return $this->fail('请选择您具备的经验');
  137. }
  138. $key = array_search($options, $tmplist[5]['options']);
  139. if ($key === false || !isset($list2[$key])) {
  140. $msg = '很抱歉,您的测试未通过,感谢您的关注!';
  141. $has_next = 0;
  142. $result = [];
  143. } else {
  144. //根据上一步的选项判断
  145. $result[] = $list2[$key];
  146. }
  147. } elseif ($step == 3) {
  148. $data = $data[0];
  149. $id = empty($data['id']) ? 0 : $data['id'];
  150. if ($id == 6 || $id == 7) {
  151. $type = $id == 6 ? 2 : 1;
  152. $question = MasterWorkerLogic::getQuestion(['type' => $type, 'category' => $data['options']]);
  153. foreach($question['list'] as $key => $item) {
  154. $temp = [
  155. "id" => $item['id'],
  156. "title" => $item['title'],
  157. "options" => explode(",",$item['options']),
  158. "type" => strpos($item['title'], '多选题') !== false ? 2 : 1,
  159. ];
  160. $result[] = $temp;
  161. }
  162. } elseif ($id == 8) {
  163. if ($data['options'] == '空调') {
  164. $result[] = $list3;
  165. } else {
  166. $msg = '很抱歉,您的测试未通过,感谢您的关注!';
  167. $has_next = 0;
  168. $result = [];
  169. }
  170. } else {
  171. $msg = '很抱歉,您的测试未通过,感谢您的关注!';
  172. $has_next = 0;
  173. $result = [];
  174. }
  175. } else {
  176. $result[] = $list3[0];
  177. }
  178. return $this->success($msg, ['has_next' => $has_next,'is_success' => $is_success, 'list' => $result], 1, 1);
  179. }
  180. }