KfaccountController.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Models\Common\KfaccountModel;
  4. use App\Models\Common\MediaModel;
  5. use Illuminate\Http\Request;
  6. use App\Http\Controllers\Controller;
  7. class KfaccountController extends Controller
  8. {
  9. public function index(Request $request)
  10. {
  11. $build = KfaccountModel::when($request->filled('wxid'), function ($query) use ($request) {
  12. return $query->where('wxid', $request->wxid);
  13. })->when($request->filled('nickname'), function ($query) use ($request) {
  14. return $query->where('nickname', 'like', "%" . $request->nickname . "%");
  15. });
  16. $kfaccounts = $build->get();
  17. $total = $kfaccounts->count();
  18. return response()->json([
  19. 'code' => 200,
  20. 'message' => 'OK',
  21. 'data' => [
  22. 'data' => $kfaccounts,
  23. 'total' => $total,
  24. ]
  25. ]);
  26. }
  27. public function update(Request $request, $id)
  28. {
  29. $kfaccount = KfaccountModel::findOrFail($id);
  30. $kfaccount->fill($request->all());
  31. $kfaccount->save();
  32. if ($request->filled('qrcode')) {
  33. MediaModel::updateOrCreate(
  34. ['key' => $kfaccount->wxid],
  35. ['url' => $request->qrcode, 'public_id' => 'gh_01c089b58dda', 'updated_at' => 0]
  36. );
  37. }
  38. return response()->json([
  39. 'code' => 200,
  40. 'message' => 'OK',
  41. 'data' => $kfaccount
  42. ]);
  43. }
  44. }