AppointmentController.php 3.7 KB

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