Application.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace app\api\controller\inspection;
  3. use app\api\controller\Base;
  4. use app\common\Service\InspectionService;
  5. use app\common\model\inspection\InspectionApplication;
  6. /**
  7. * 验货员申请接口
  8. */
  9. class Application extends Base
  10. {
  11. protected $noNeedLogin = [];
  12. /**
  13. * 提交验货员申请
  14. */
  15. public function create()
  16. {
  17. // 验证请求参数
  18. $validate = new \app\api\validate\Inspection();
  19. if (!$validate->scene('create')->check($this->request->post())) {
  20. $this->error($validate->getError());
  21. }
  22. $data = [
  23. 'name' => $this->request->post('name', '', 'trim'),
  24. 'phone' => $this->request->post('phone', '', 'trim'),
  25. 'province_adcode' => $this->request->post('province_adcode', '', 'trim'),
  26. 'city_adcode' => $this->request->post('city_adcode', '', 'trim'),
  27. 'district_adcode' => $this->request->post('district_adcode', '', 'trim'),
  28. 'address' => $this->request->post('address', '', 'trim'),
  29. 'id_card_front' => $this->request->post('id_card_front', '', 'trim'),
  30. 'id_card_back' => $this->request->post('id_card_back', '', 'trim'),
  31. 'id_card' => $this->request->post('id_card', '', 'trim'),
  32. ];
  33. $application = InspectionService::createApplication($this->auth->id, $data);
  34. $this->success('申请提交成功,请耐心等待审核', [
  35. 'id' => $application->id,
  36. 'audit_status' => $application->audit_status,
  37. 'audit_status_text' => $application->audit_status_text
  38. ]);
  39. }
  40. /**
  41. * 获取申请详情
  42. */
  43. public function detail()
  44. {
  45. // 验证请求参数
  46. $validate = new \app\api\validate\Inspection();
  47. $applicationId = $this->request->get('id/d');
  48. $params = ['id' => $applicationId];
  49. if (!$validate->scene('detail')->check($params)) {
  50. $this->error($validate->getError());
  51. }
  52. $application = InspectionService::getApplicationDetail($applicationId, $this->auth->id);
  53. if($application){
  54. $application->append(['audit_status_text', 'apply_time_text', 'audit_time_text', 'province_name', 'city_name', 'district_name']);
  55. $application->hidden(['createtime', 'updatetime', 'deletetime']);
  56. }
  57. $this->success('获取成功', $application);
  58. }
  59. /**
  60. * 获取申请列表
  61. */
  62. public function index()
  63. {
  64. $list = InspectionService::getApplicationList($this->auth->id);
  65. foreach ($list as $item) {
  66. $item->append(['audit_status_text', 'apply_time_text']);
  67. $item->visible(['id', 'name', 'phone', 'audit_status', 'audit_status_text', 'apply_time', 'apply_time_text', 'reject_reason']);
  68. }
  69. $this->success('获取成功', $list);
  70. }
  71. /**
  72. * 修改申请(仅审核中状态可修改)
  73. */
  74. public function update()
  75. {
  76. // 验证请求参数
  77. $validate = new \app\api\validate\Inspection();
  78. if (!$validate->scene('update')->check($this->request->post())) {
  79. $this->error($validate->getError());
  80. }
  81. $applicationId = $this->request->post('id/d');
  82. $data = [
  83. 'name' => $this->request->post('name', '', 'trim'),
  84. 'phone' => $this->request->post('phone', '', 'trim'),
  85. 'province_adcode' => $this->request->post('province_adcode', '', 'trim'),
  86. 'city_adcode' => $this->request->post('city_adcode', '', 'trim'),
  87. 'district_adcode' => $this->request->post('district_adcode', '', 'trim'),
  88. 'address' => $this->request->post('address', '', 'trim'),
  89. 'id_card_front' => $this->request->post('id_card_front', '', 'trim'),
  90. 'id_card_back' => $this->request->post('id_card_back', '', 'trim'),
  91. ];
  92. $application = InspectionService::updateApplication($applicationId, $this->auth->id, $data);
  93. $this->success('修改成功', [
  94. 'id' => $application->id,
  95. 'audit_status' => $application->audit_status,
  96. 'audit_status_text' => $application->audit_status_text
  97. ]);
  98. }
  99. /**
  100. * 检查申请资格
  101. */
  102. public function checkEligibility()
  103. {
  104. $result = InspectionService::checkEligibility($this->auth->id);
  105. $this->success('检查成功', $result);
  106. }
  107. }