AppointmentController.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. use think\facade\Cache;
  10. class AppointmentController extends RestUserBaseController
  11. {
  12. public function bind()
  13. {
  14. $data = $this->request->param();
  15. $verify = Cache::get('verify' . $this->userId);
  16. if (empty($verify)) {
  17. $this->error('验证码已过期,请重新获取');
  18. }
  19. if ($verify != $data['verify']) {
  20. $this->error('验证码错误');
  21. }
  22. $talent = TalentModel::where('name', $data['name'])->where('card_no', $data['card_no'])->find();
  23. if (empty($talent)) {
  24. $this->error('未找到人才信息,请重新信息是否输入有误');
  25. }
  26. $user = UserModel::where('talent_id', $talent['id'])->find();
  27. if (!empty($user)) {
  28. $this->error('该人才信息已被绑定,请联系管理员确认');
  29. }
  30. //手机号绑定
  31. $talent->mobile = $data['mobile'];
  32. $talent->save();
  33. $userId = $this->getUserId();
  34. UserModel::update(['talent_id' => $talent['id']], ['id' => $userId]);
  35. Cache::rm('verify' . $this->userId);
  36. $this->success();
  37. }
  38. public function upload()
  39. {
  40. $file = $this->request->file('file');
  41. $result = $file->validate([
  42. 'ext' => 'jpg,jpeg,png',
  43. 'size' => 1024 * 1024,
  44. ])->move(WEB_ROOT . 'upload' . DIRECTORY_SEPARATOR . 'watermark' . DIRECTORY_SEPARATOR);
  45. if ($result) {
  46. $avatarSaveName = str_replace('//', '/', str_replace('\\', '/', $result->getSaveName()));
  47. $url = cmf_get_image_url('watermark/' . $avatarSaveName);
  48. $this->success('上传成功', $url);
  49. } else {
  50. $this->error($file->getError());
  51. }
  52. }
  53. public function book()
  54. {
  55. $data = $this->request->param();
  56. //时间
  57. $date = $data['date'] . ' ' . $data['time'] . ':00';
  58. $out_date = $data['date'] . ' ' . $data['out_time'] . ':00';
  59. $start_time = strtotime($date);
  60. $out_time = strtotime($out_date);
  61. $time = time();
  62. if ($start_time - $time < 3600) {
  63. $this->error('只能预约一小时后的班次');
  64. }
  65. if ($out_time - $start_time > 0) {
  66. $this->error('到站时间必须早于出发时间');
  67. }
  68. //班次
  69. if (!empty($data['shift'])) {
  70. $shift_check = TalentAppointmentModel::where('talent_id',$this->user['talent_id'])->where('shift',$data['shift'])->find();
  71. if (!empty($shift_check)) {
  72. $this->error('您已预约过该班次,请勿重复预约');
  73. }
  74. }
  75. //预约成功和日志
  76. $appointment = TalentAppointmentModel::create([
  77. 'talent_id' => $this->user['talent_id'],
  78. 'shift' => $data['shift'],
  79. 'start_time' => $date,
  80. 'image' => $data['image'],
  81. 'create_time' => date('Y-m-d H:i:s'),
  82. 'out_time' => $out_date,
  83. 'companion_num' => $data['companion_num'],
  84. 'comment' => $data['comment'],
  85. ]);
  86. TalentAppointmentLogModel::create([
  87. 'appointment_id' => $appointment['id'],
  88. 'name' => '人才',
  89. 'content' => '提交了预约',
  90. 'create_time' => date('Y-m-d H:i:s'),
  91. ]);
  92. //短信
  93. $sms = new Sms();
  94. $option = cmf_get_option('talent_setting');
  95. $sms->send($option['mobile'], 'talent_appointment_submit');
  96. $this->success();
  97. }
  98. public function lists()
  99. {
  100. $page = empty($param['page']) ? 1 : $param['page'];
  101. $size = empty($param['size']) ? 10 : $param['size'];
  102. //搜索条件
  103. $where = [['talent_id', '=', $this->user['talent_id']]];
  104. $list = TalentAppointmentModel::where($where)
  105. ->order('start_time desc')
  106. ->page($page, $size)
  107. ->append(['status_text'])
  108. ->select();
  109. $this->success('成功', $list);
  110. }
  111. public function getAdminMobile()
  112. {
  113. $setting = cmf_get_option('talent_setting');
  114. $this->success('成功', $setting);
  115. }
  116. public function rate()
  117. {
  118. $data = $this->request->param();
  119. $data['status'] = 4;
  120. TalentAppointmentModel::update($data);
  121. TalentAppointmentLogModel::create([
  122. 'appointment_id' => $data['id'],
  123. 'name' => '人才',
  124. 'content' => '评价了服务',
  125. 'create_time' => date('Y-m-d H:i:s'),
  126. ]);
  127. $this->success('成功');
  128. }
  129. public function getVerify()
  130. {
  131. $data = $this->request->param();
  132. $verify = mt_rand(100000, 999999);
  133. Cache::set('verify' . $this->userId, $verify, 600);
  134. //短信
  135. $sms = new Sms();
  136. $sms->send($data['mobile'], 'verification_code', ['code' => $verify]);
  137. $this->success();
  138. }
  139. public function route()
  140. {
  141. $setting = cmf_get_option('talent_setting');
  142. $this->success('成功',['route_image'=>cmf_get_image_preview_url($setting['route_image'])]);
  143. }
  144. public function talentInfo()
  145. {
  146. $talent = TalentModel::where('id',$this->user['talent_id'])->find();
  147. $this->success('成功',$talent);
  148. }
  149. public function changeMobile()
  150. {
  151. $data = $this->request->param();
  152. $verify = Cache::get('verify' . $this->userId);
  153. if (empty($verify)) {
  154. $this->error('验证码已过期,请重新获取');
  155. }
  156. if ($verify != $data['verify']) {
  157. $this->error('验证码错误');
  158. }
  159. TalentModel::update(['mobile'=>$data['mobile']],['id'=>$this->user['talent_id']]);
  160. Cache::rm('verify' . $this->userId);
  161. $this->success();
  162. }
  163. }