AuditMediaController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace App\Http\Controllers\Admin\AuditMedia;
  3. use App\Events\AuditMediaDeal;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\Media\MediaSecure;
  6. use App\Models\Media\MediaSecureImage;
  7. use App\Models\Media\MediaSecureOther;
  8. use App\Models\Media\MediaSecureText;
  9. use App\Models\Media\MediaSecureVoice;
  10. use Illuminate\Http\Request;
  11. class AuditMediaController extends Controller
  12. {
  13. public function listImage(Request $request)
  14. {
  15. $pages = array(
  16. 'last_id' => $request->get('last_id', 1),
  17. 'limit' => $request->get('limit', 20),
  18. 'page' => $request->get('page', 1)
  19. );
  20. $field = $request->get('field');
  21. $build = MediaSecureImage::when($field, function ($query) use ($field) {
  22. return $query->ofField($field);
  23. })->when($request->filled('uid'), function ($query) use ($request) {
  24. return $query->where('uid', $request->uid);
  25. })->when($request->filled('result'), function ($query) use ($request) {
  26. return $query->where('result', $request->get('result'));
  27. })->when($request->filled('audit_suggestion'), function ($query) use ($request) {
  28. return $query->where('audit_suggestion', $request->get('audit_suggestion'));
  29. });
  30. $pages['total'] = $build->count();
  31. $list = $build->where('id', '>', $pages['last_id'])
  32. ->skip(($pages['page'] - 1) * $pages['limit'])
  33. ->take($pages['limit'])
  34. ->get();
  35. return array(
  36. 'page' => $pages,
  37. 'list' => $list
  38. );
  39. }
  40. public function listText(Request $request)
  41. {
  42. $pages = array(
  43. 'last_id' => $request->get('last_id', 1),
  44. 'limit' => $request->get('limit', 20),
  45. 'page' => $request->get('page', 1)
  46. );
  47. $field = $request->get('field');
  48. $build = MediaSecureText::when($field, function ($query) use ($field) {
  49. return $query->ofField($field);
  50. })->when($request->filled('uid'), function ($query) use ($request) {
  51. return $query->where('uid', $request->uid);
  52. })->when($request->filled('result'), function ($query) use ($request) {
  53. return $query->where('result', $request->get('result'));
  54. })->when($request->filled('audit_suggestion'), function ($query) use ($request) {
  55. return $query->where('audit_suggestion', $request->get('audit_suggestion'));
  56. });
  57. $pages['total'] = $build->count();
  58. $list = $build->where('id', '>', $pages['last_id'])
  59. ->skip(($pages['page'] - 1) * $pages['limit'])
  60. ->take($pages['limit'])
  61. ->get();
  62. return array(
  63. 'page' => $pages,
  64. 'list' => $list
  65. );
  66. }
  67. public function listVoice(Request $request)
  68. {
  69. $pages = array(
  70. 'last_id' => $request->get('last_id', 1),
  71. 'limit' => $request->get('limit', 20),
  72. 'page' => $request->get('page', 1)
  73. );
  74. $field = $request->get('field');
  75. $build = MediaSecureVoice::when($field, function ($query) use ($field) {
  76. return $query->ofField($field);
  77. })->when($request->filled('uid'), function ($query) use ($request) {
  78. return $query->where('uid', $request->uid);
  79. })->when($request->filled('result'), function ($query) use ($request) {
  80. return $query->where('result', $request->get('result'));
  81. })->when($request->filled('audit_suggestion'), function ($query) use ($request) {
  82. return $query->where('audit_suggestion', $request->get('audit_suggestion'));
  83. });
  84. $pages['total'] = $build->count();
  85. $list = $build->where('id', '>', $pages['last_id'])
  86. ->skip(($pages['page'] - 1) * $pages['limit'])
  87. ->take($pages['limit'])
  88. ->get();
  89. return array(
  90. 'page' => $pages,
  91. 'list' => $list
  92. );
  93. }
  94. public function audit(Request $request)
  95. {
  96. $type = $request->get('audit_type', 'text');
  97. $deals = $request->post();
  98. switch ($type) {
  99. case "text":
  100. $storage = new MediaSecureText();
  101. break;
  102. case "image":
  103. $storage = new MediaSecureImage();
  104. break;
  105. case "voice":
  106. $storage = new MediaSecureVoice();
  107. break;
  108. default:
  109. $storage = new MediaSecureOther();
  110. break;
  111. }
  112. foreach ($deals as $deal) {
  113. $media = $storage->find($deal['id']);
  114. $media->result = $deal['result'];
  115. $media->channel = MediaSecure::CHANNEL_MANUAL;
  116. $media->save();
  117. event(new AuditMediaDeal($media));
  118. }
  119. return array(
  120. 'code' => 200,
  121. 'message' => 'success'
  122. );
  123. }
  124. }