FormContentService.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Form\Services;
  3. use App\Services\CommonUserBaseService;
  4. use App\Form\Facades\FormItemFacade;
  5. class FormContentService extends CommonUserBaseService
  6. {
  7. /**
  8. * 获取列表数据
  9. * @param array $recordId
  10. * @return array
  11. */
  12. public function getListByRecordIds(array $recordId)
  13. {
  14. $list = $this->model->alias('a')
  15. ->leftJoin('form_item as b', 'a.form_item_id', '=', 'b.id')
  16. ->whereIn('a.record_id',$recordId)
  17. ->orderBy('b.sort')->selectRaw('a.*')->get()->toArray();
  18. $formItemModel=FormItemFacade::getModel();
  19. if (!empty($list)) {
  20. $itemIds = array_column($list, 'form_item_id');
  21. $items=$formItemModel->whereIn('id',$itemIds)->selectRaw('id,name')->orderBy('sort')->get()->toArray();
  22. !empty($items) && $items = mapByKey($items, 'id');
  23. foreach ($list as &$v) {
  24. $v['item_name'] = isset($items[$v['form_item_id']]) ? $items[$v['form_item_id']]['name']: '';
  25. $v['content'] = json_decode($v['content'], true);
  26. }
  27. }
  28. $data = [];
  29. foreach ($list as $l) {
  30. $data[$l['record_id']][] = $l;
  31. }
  32. return $data;
  33. }
  34. }