GroupTherapyService.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Services;
  3. use App\Models\GroupTherapyRecord;
  4. use App\Models\UserLectureRelation;
  5. use App\Models\WorkstationLectureRelation;
  6. use App\Models\Lecture; // 确保引入 Lecture 模型
  7. use App\Traits\PageTrait;
  8. class GroupTherapyService
  9. {
  10. use PageTrait;
  11. public function getList($condition, $sort = 'id', $sortable = 'desc')
  12. {
  13. $query = GroupTherapyRecord::query();
  14. $query->select(
  15. 'id',
  16. 'open_vc_id',
  17. 'type',
  18. 'customer_data',
  19. 'created_at',
  20. 'workstation_name',
  21. 'workstation_id',
  22. 'open_vt_id',
  23. 'vt_title'
  24. );
  25. // 使用 whereIn 方法筛选 lecture_id 在 $lectureIdArr 数组中的记录
  26. // 搜索
  27. if (isset($condition['keywords']) && $condition['keywords']) {
  28. $query->where('customer_data', 'like', '%' . $condition['keywords'] . '%');
  29. }
  30. // 排序
  31. $query->orderBy($sort, $sortable);
  32. // 执行查询并返回结果
  33. return self::JsonPage($query);
  34. }
  35. public function report($data)
  36. {
  37. if($data['customer_data']) {
  38. $customerData = json_decode($data['customer_data'], true);
  39. foreach($customerData as $v){
  40. $insertData[]=[
  41. 'open_vc_id' =>$v['open_vc_id'],
  42. 'type' =>$data['type'],
  43. 'customer_data' =>json_encode($v),
  44. 'created_at' =>date('Y-m-d H:i:s'),
  45. 'updated_at' =>date('Y-m-d H:i:s'),
  46. 'workstation_id'=>auth('grider')->user()->workstation_id,
  47. 'workstation_name'=>auth('grider')->user()->workstation_name,
  48. 'open_vt_id' => $v['vt_id'],
  49. 'vt_title' => $v['vt_title'],
  50. ];
  51. }
  52. $res = GroupTherapyRecord::insert($insertData);
  53. return $res;
  54. }
  55. return true;
  56. }
  57. }