AdminController.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. namespace api\talent\controller;
  3. use api\common\Sms;
  4. use app\talent\model\TalentAdminModel;
  5. use app\talent\model\TalentAppointmentLogModel;
  6. use app\talent\model\TalentAppointmentModel;
  7. use app\talent\model\TalentModel;
  8. use cmf\controller\RestUserBaseController;
  9. class AdminController extends RestUserBaseController
  10. {
  11. public function login()
  12. {
  13. $data = $this->request->param();
  14. $admin = TalentAdminModel::where('account', $data['account'])->where('password', $data['password'])->find();
  15. if (empty($admin)) {
  16. $this->error('账号或密码错误');
  17. }
  18. $this->success('成功', $admin['id']);
  19. }
  20. public function scan()
  21. {
  22. $code = $this->request->param('code', '');
  23. $admin_id = $this->request->param('admin_id', 0);
  24. if (empty($admin_id)) {
  25. $this->error('暂无权限');
  26. }
  27. if (empty($code)) {
  28. $this->error('二维码错误');
  29. }
  30. $appointment = TalentAppointmentModel::where('apply_code', $code)->find();
  31. if (empty($appointment)) {
  32. $this->error('二维码错误');
  33. }
  34. if ($appointment['status'] != 2) {
  35. $this->error('该预约已接站,请勿重复扫码');
  36. }
  37. $appointment->status = 3;
  38. $appointment->save();
  39. //日志
  40. $admin = TalentAdminModel::get($admin_id);
  41. TalentAppointmentLogModel::create([
  42. 'appointment_id' => $appointment['id'],
  43. 'name' => '工作人员(' . $admin['name'] . ')',
  44. 'content' => '通过扫码接站,接到了人才',
  45. 'create_time' => date('Y-m-d H:i:s'),
  46. ]);
  47. $talent = TalentModel::get($appointment['talent_id']);
  48. $this->success('成功', ['talent' => $talent, 'appointment' => $appointment]);
  49. }
  50. public function lists()
  51. {
  52. $data = $this->request->param();
  53. $page = empty($param['page']) ? 1 : $param['page'];
  54. $size = empty($param['size']) ? 10 : $param['size'];
  55. $where = [['status', '=', $data['status']]];
  56. if (!empty($data['keyword'])) {
  57. $where[] = ['shift', 'like', "%{$data['keyword']}%"];
  58. }
  59. //搜索条件
  60. $list = TalentAppointmentModel::with(['talent'])
  61. ->where($where)
  62. ->order('start_time desc')
  63. ->page($page, $size)
  64. ->append(['status_text'])
  65. ->select();
  66. $this->success('成功', $list);
  67. }
  68. public function confirm()
  69. {
  70. $data = $this->request->param();
  71. $talent_appointment = TalentAppointmentModel::get($data['id']);
  72. $talent_appointment->status = 2;
  73. $talent_appointment->apply_code = uniqid();
  74. $talent_appointment->save();
  75. //日志
  76. $admin = TalentAdminModel::get($data['admin_id']);
  77. TalentAppointmentLogModel::create([
  78. 'appointment_id' => $data['id'],
  79. 'name' => '工作人员(' . $admin['name'] . ')',
  80. 'content' => '确认了人才的预约',
  81. 'create_time' => date('Y-m-d H:i:s'),
  82. ]);
  83. //人才信息
  84. $talent = TalentModel::where('id', $talent_appointment['talent_id'])->find();
  85. //短信
  86. $sms = new Sms();
  87. $sms->send($talent['mobile'], 'talent_appointment_confirm');
  88. $this->success();
  89. }
  90. public function applyByMobile()
  91. {
  92. $mobile = $this->request->param('mobile', '');
  93. $admin_id = $this->request->param('admin_id', 0);
  94. $id = $this->request->param('id', 0);
  95. if (empty($admin_id)) {
  96. $this->error('暂无权限');
  97. }
  98. if (empty($mobile)) {
  99. $this->error('手机号错误');
  100. }
  101. $appointment = TalentAppointmentModel::with(['talent'])->where('id', $id)->find();
  102. if (empty($appointment)) {
  103. $this->error('系统异常,请联系管理员');
  104. }
  105. if ($appointment['status'] != 2) {
  106. $this->error('该预约已接站,请勿重复接站');
  107. }
  108. if ($appointment['talent']['mobile'] != $mobile) {
  109. $this->error('手机号输入错误');
  110. }
  111. $appointment->status = 3;
  112. $appointment->save();
  113. //日志
  114. $admin = TalentAdminModel::get($admin_id);
  115. TalentAppointmentLogModel::create([
  116. 'appointment_id' => $appointment['id'],
  117. 'name' => '工作人员(' . $admin['name'] . ')',
  118. 'content' => '通过手机号接站,接到了人才',
  119. 'create_time' => date('Y-m-d H:i:s'),
  120. ]);
  121. $this->success('成功');
  122. }
  123. public function getScheduling()
  124. {
  125. $today = date('Y-m-d');
  126. $list = TalentAppointmentModel::with(['talent'])
  127. ->where('out_time', 'between', [$today . ' 00:00:00', $today . ' 23:59:59'])
  128. ->where('status',2)
  129. ->order('out_time asc')
  130. ->append(['status_text'])
  131. ->select();
  132. if ($list->isEmpty()) {
  133. $this->success('', []);
  134. }
  135. $res = [];
  136. foreach ($list as $v) {
  137. $hour = date('H:00', strtotime($v['out_time']));
  138. if (empty($res[$hour])) {
  139. $res[$hour] = [
  140. 'hour' => $hour,
  141. 'list' => [],
  142. ];
  143. }
  144. $res[$hour]['list'][] = $v->toArray();
  145. }
  146. $this->success('成功', array_values($res));
  147. }
  148. }