Application.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. ];
  32. $application = InspectionService::createApplication($this->auth->id, $data);
  33. $this->success('申请提交成功,请耐心等待审核', [
  34. 'id' => $application->id,
  35. 'audit_status' => $application->audit_status,
  36. 'audit_status_text' => $application->audit_status_text
  37. ]);
  38. }
  39. /**
  40. * 获取申请详情
  41. */
  42. public function detail()
  43. {
  44. // 验证请求参数
  45. $validate = new \app\api\validate\Inspection();
  46. $applicationId = $this->request->get('id/d');
  47. $params = ['id' => $applicationId];
  48. if (!$validate->scene('detail')->check($params)) {
  49. $this->error($validate->getError());
  50. }
  51. $application = InspectionService::getApplicationDetail($applicationId, $this->auth->id);
  52. if($application){
  53. $application->append(['audit_status_text', 'apply_time_text', 'audit_time_text', 'province_name', 'city_name', 'district_name']);
  54. $application->hidden(['createtime', 'updatetime', 'deletetime']);
  55. }
  56. $this->success('获取成功', $application);
  57. }
  58. /**
  59. * 获取申请列表
  60. */
  61. public function index()
  62. {
  63. $list = InspectionService::getApplicationList($this->auth->id);
  64. foreach ($list as $item) {
  65. $item->append(['audit_status_text', 'apply_time_text']);
  66. $item->visible(['id', 'name', 'phone', 'audit_status', 'audit_status_text', 'apply_time', 'apply_time_text', 'reject_reason']);
  67. }
  68. $this->success('获取成功', $list);
  69. }
  70. /**
  71. * 修改申请(仅审核中状态可修改)
  72. */
  73. public function update()
  74. {
  75. // 验证请求参数
  76. $validate = new \app\api\validate\Inspection();
  77. if (!$validate->scene('update')->check($this->request->post())) {
  78. $this->error($validate->getError());
  79. }
  80. $applicationId = $this->request->post('id/d');
  81. $data = [
  82. 'name' => $this->request->post('name', '', 'trim'),
  83. 'phone' => $this->request->post('phone', '', 'trim'),
  84. 'province_adcode' => $this->request->post('province_adcode', '', 'trim'),
  85. 'city_adcode' => $this->request->post('city_adcode', '', 'trim'),
  86. 'district_adcode' => $this->request->post('district_adcode', '', 'trim'),
  87. 'address' => $this->request->post('address', '', 'trim'),
  88. 'id_card_front' => $this->request->post('id_card_front', '', 'trim'),
  89. 'id_card_back' => $this->request->post('id_card_back', '', 'trim'),
  90. ];
  91. $application = InspectionService::updateApplication($applicationId, $this->auth->id, $data);
  92. $this->success('修改成功', [
  93. 'id' => $application->id,
  94. 'audit_status' => $application->audit_status,
  95. 'audit_status_text' => $application->audit_status_text
  96. ]);
  97. }
  98. /**
  99. * 检查申请资格
  100. */
  101. public function checkEligibility()
  102. {
  103. $result = InspectionService::checkEligibility($this->auth->id);
  104. $this->success('检查成功', $result);
  105. }
  106. }