AdminController.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. //短信
  49. $sms = new Sms();
  50. $sms->send($talent['mobile'],'talent_appointment_end');
  51. $this->success('成功', ['talent' => $talent, 'appointment' => $appointment]);
  52. }
  53. public function lists()
  54. {
  55. $data = $this->request->param();
  56. $page = empty($param['page']) ? 1 : $param['page'];
  57. $size = empty($param['size']) ? 10 : $param['size'];
  58. $where = [['status', '=', $data['status']]];
  59. if (!empty($data['keyword'])) {
  60. $where[] = ['shift','like',"%{$data['keyword']}%"];
  61. }
  62. //搜索条件
  63. $list = TalentAppointmentModel::with(['talent'])
  64. ->where($where)
  65. ->order('start_time desc')
  66. ->page($page, $size)
  67. ->append(['status_text'])
  68. ->select();
  69. $this->success('成功', $list);
  70. }
  71. public function confirm()
  72. {
  73. $data = $this->request->param();
  74. $talent_appointment = TalentAppointmentModel::get($data['id']);
  75. $talent_appointment->status = 2;
  76. $talent_appointment->apply_code = uniqid();
  77. $talent_appointment->save();
  78. //日志
  79. $admin = TalentAdminModel::get($data['admin_id']);
  80. TalentAppointmentLogModel::create([
  81. 'appointment_id' => $data['id'],
  82. 'name' => '工作人员(' . $admin['name'] . ')',
  83. 'content' => '确认了人才的预约',
  84. 'create_time' => date('Y-m-d H:i:s'),
  85. ]);
  86. //人才信息
  87. $talent = TalentModel::where('id',$talent_appointment['talent_id'])->find();
  88. //短信
  89. $sms = new Sms();
  90. $sms->send($talent['mobile'],'talent_appointment_confirm');
  91. $this->success();
  92. }
  93. public function applyByMobile()
  94. {
  95. $mobile = $this->request->param('mobile', '');
  96. $admin_id = $this->request->param('admin_id', 0);
  97. $id = $this->request->param('id',0);
  98. if (empty($admin_id)) {
  99. $this->error('暂无权限');
  100. }
  101. if (empty($mobile)) {
  102. $this->error('手机号错误');
  103. }
  104. $appointment = TalentAppointmentModel::with(['talent'])->where('id', $id)->find();
  105. if (empty($appointment)) {
  106. $this->error('系统异常,请联系管理员');
  107. }
  108. if ($appointment['status'] != 2) {
  109. $this->error('该预约已接站,请勿重复接站');
  110. }
  111. if ($appointment['talent']['mobile'] != $mobile) {
  112. $this->error('手机号输入错误');
  113. }
  114. $appointment->status = 3;
  115. $appointment->save();
  116. //日志
  117. $admin = TalentAdminModel::get($admin_id);
  118. TalentAppointmentLogModel::create([
  119. 'appointment_id' => $appointment['id'],
  120. 'name' => '工作人员(' . $admin['name'] . ')',
  121. 'content' => '通过手机号接站,接到了人才',
  122. 'create_time' => date('Y-m-d H:i:s'),
  123. ]);
  124. //短信
  125. $sms = new Sms();
  126. $sms->send($appointment['talent']['mobile'],'talent_appointment_end');
  127. $this->success('成功');
  128. }
  129. }