Volunteer.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use liuniu\UtilService;
  5. use think\Exception;
  6. use think\Request;
  7. use app\common\model\Volunteer as VolunteerModel;
  8. class Volunteer extends Api
  9. {
  10. protected $noNeedRight = ['*'];
  11. public function apply(Request $request)
  12. {
  13. $where = UtilService::postMore(
  14. [
  15. ['name', ''],
  16. ['phone', ''],
  17. ['sex', 0],
  18. ['birth', ''],
  19. ['image', ''],
  20. ['certificateimage', ''],
  21. ['email', ''],
  22. ['address', ''],
  23. ['work', ''],
  24. ['specialty', ''],
  25. ['education', 0],
  26. ['is_vol', 0],
  27. ['is_experience', 0],
  28. ['start_hour', 7],
  29. ['end_hour', 22],
  30. ['work_week', '1'],
  31. ['taste', ''],
  32. ['taste_title', ''],
  33. ['speciali', ''],
  34. ['speciali_title', ''],
  35. ], $request
  36. );
  37. // if ($where['name'] == '') $this->error('姓名不能为空');
  38. // if ($where['phone'] == '') $this->error('电话不能为空');
  39. // if ($where['address'] == '') $this->error('地址信息不能为空');
  40. // if ($where['image'] == '') $this->error('照片不能为空');
  41. // if ($where['birth'] == '') $this->error('生日不能为空');
  42. $where['cid'] = $this->cid;
  43. $where['user_id'] = $this->auth->getUserinfo()['id'];
  44. if (VolunteerModel::where('user_id', $where['user_id'])->where('status', '>', -1)->find()) $this->error('已经存,不能重复申请');
  45. try {
  46. if (!VolunteerModel::create($where)) {
  47. $this->error(VolunteerModel::getErrorInfo());
  48. }
  49. $this->success('创建成功');
  50. } catch (Exception $e) {
  51. $this->error($e->getMessage());
  52. }
  53. }
  54. public function lst()
  55. {
  56. $this->success('获取成功', VolunteerModel::where('cid', $this->cid)->where('user_id', $this->auth->getUserinfo()['id'])->select());
  57. }
  58. }