InquiryAssignment.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace App\Admin\Forms;
  3. use Dcat\Admin\Contracts\LazyRenderable;
  4. use Dcat\Admin\Widgets\Form;
  5. use App\Admin\Repositories\DistInquiry;
  6. use App\Admin\Renderable\DistDistributorTable;
  7. use Dcat\Admin\Models\DistAdminUser;
  8. use Dcat\Admin\Traits\LazyWidget;
  9. use App\Models\DistAdminDistributor;
  10. class InquiryAssignment extends Form
  11. {
  12. // 处理请求
  13. public function handle(array $input)
  14. {
  15. $distId = $input['distId'] ?? null;
  16. $id = $input['id'] ?? null;
  17. if (empty($id)) {
  18. return $this->response()->error('No data selected!');
  19. }
  20. //检查数据是否可分配状态
  21. $ids = explode(',', $id);
  22. if (DistInquiry::assessTheStatus($ids) == false) {
  23. return $this->response()->error('The data cannot be assigned!');
  24. }
  25. //分配数据
  26. DistInquiry::assignData($ids, $distId);
  27. return $this->response()->success(admin_trans_label('update_success'))->refresh();
  28. }
  29. public function form()
  30. {
  31. $this->selectTable('distId', admin_trans_label('select_distributor'))
  32. ->title('distId')
  33. ->model(DistAdminDistributor::class, 'id', 'client_code')
  34. ->from(DistDistributorTable::make());
  35. // 设置隐藏表单,传递用户id
  36. $this->hidden('id')->attribute('id', 'inquiryIds');
  37. }
  38. }