AppointmentController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace api\talent\controller;
  3. use api\applet\model\UserModel;
  4. use app\talent\model\TalentAppointmentLogModel;
  5. use app\talent\model\TalentAppointmentModel;
  6. use app\talent\model\TalentModel;
  7. use cmf\controller\RestUserBaseController;
  8. class AppointmentController extends RestUserBaseController
  9. {
  10. public function bind()
  11. {
  12. $data = $this->request->param();
  13. $talent = TalentModel::where('name', $data['name'])->where('card_no', $data['card_no'])->find();
  14. if (empty($talent)) {
  15. $this->error('未找到人才信息,请重新信息是否输入有误');
  16. }
  17. $user = UserModel::where('talent_id', $talent['id'])->find();
  18. if (!empty($user)) {
  19. $this->error('该人才信息已被绑定,请联系管理员确认');
  20. }
  21. $userId = $this->getUserId();
  22. UserModel::update(['talent_id' => $talent['id']], ['id' => $userId]);
  23. $this->success();
  24. }
  25. public function upload()
  26. {
  27. $file = $this->request->file('file');
  28. $result = $file->validate([
  29. 'ext' => 'jpg,jpeg,png',
  30. 'size' => 1024 * 1024,
  31. ])->move(WEB_ROOT . 'upload' . DIRECTORY_SEPARATOR . 'watermark' . DIRECTORY_SEPARATOR);
  32. if ($result) {
  33. $avatarSaveName = str_replace('//', '/', str_replace('\\', '/', $result->getSaveName()));
  34. $url = cmf_get_image_url('watermark/' . $avatarSaveName);
  35. $this->success('上传成功', $url);
  36. } else {
  37. $this->error($file->getError());
  38. }
  39. }
  40. public function book()
  41. {
  42. $data = $this->request->param();
  43. $date = $data['date'] . ' ' . $data['time'] . ':00';
  44. $start_time = strtotime($date);
  45. $time = time();
  46. if ($start_time - $time < 3600) {
  47. $this->error('只能预约一小时后的班次');
  48. }
  49. $appointment = TalentAppointmentModel::create([
  50. 'talent_id' => $this->user['talent_id'],
  51. 'shift' => $data['shift'],
  52. 'start_time' => $date,
  53. 'image' => $data['image'],
  54. 'create_time' => date('Y-m-d H:i:s'),
  55. ]);
  56. TalentAppointmentLogModel::create([
  57. 'appointment_id' => $appointment['id'],
  58. 'name' => '人才',
  59. 'content' => '提交了预约',
  60. 'create_time' => date('Y-m-d H:i:s'),
  61. ]);
  62. $this->success();
  63. }
  64. public function lists()
  65. {
  66. $page = empty($param['page']) ? 1 : $param['page'];
  67. $size = empty($param['size']) ? 10 : $param['size'];
  68. //搜索条件
  69. $where = [['talent_id', '=', $this->user['talent_id']]];
  70. $list = TalentAppointmentModel::where($where)
  71. ->order('start_time desc')
  72. ->page($page, $size)
  73. ->append(['status_text'])
  74. ->select();
  75. $this->success('成功', $list);
  76. }
  77. public function getAdminMobile()
  78. {
  79. $setting = cmf_get_option('talent_setting');
  80. $this->success('成功', $setting);
  81. }
  82. public function rate()
  83. {
  84. $data = $this->request->param();
  85. $data['status'] = 4;
  86. TalentAppointmentModel::update($data);
  87. TalentAppointmentLogModel::create([
  88. 'appointment_id' => $data['id'],
  89. 'name' => '人才',
  90. 'content' => '评价了服务',
  91. 'create_time' => date('Y-m-d H:i:s'),
  92. ]);
  93. $this->success('成功');
  94. }
  95. }