MediaFeeController.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\Fpdx\MediaModel;
  5. use App\Models\Fpdx\MediaFeeLogModel;
  6. use App\Models\Fpdx\MediaOrderModel;
  7. use Illuminate\Http\Request;
  8. class MediaFeeController extends Controller
  9. {
  10. public function getFeeLogs()
  11. {
  12. $data = array();
  13. $feelogModel = new MediaFeeLogModel();
  14. $feelogs = $feelogModel->groupBy('tag')->get(['tag']);
  15. foreach ($feelogs as $fee) {
  16. $data[$fee->tag] = $feelogModel->where('tag', $fee->tag)->get();
  17. }
  18. return response([
  19. 'code' => 200,
  20. 'message' => 'success',
  21. 'data' => $data
  22. ]);
  23. }
  24. public function createFee(Request $request)
  25. {
  26. $this->validate($request, [
  27. 'media_id' => 'required',
  28. 'tag' => 'required',
  29. 'fee' => 'required',
  30. ]);
  31. $data = $request->all();
  32. $media = MediaModel::where('media_id', $data['media_id'])->firstOrFail(['public_name']);
  33. $data['public_name'] = $media->public_name;
  34. \DB::beginTransaction();
  35. try {
  36. $mediaFee = MediaFeeLogModel::create($data);
  37. $media->increment('fpdx_money', $request->input('fee'));
  38. MediaOrderModel::create([
  39. 'media_id' => $request->media_id,
  40. 'type' => 'bonus',
  41. 'amount' => $request->fee * 100,
  42. 'tag' => '分配对象',
  43. 'describe' => "【奖金】分配对象活动"
  44. ]);
  45. \DB::commit();
  46. return response([
  47. 'code' => 200,
  48. 'message' => 'success',
  49. 'data' => $mediaFee
  50. ]);
  51. } catch (\Exception $e) {
  52. \DB::rollBack();
  53. return response([
  54. 'code' => 500,
  55. 'message' => $e->getMessage()
  56. ]);
  57. }
  58. }
  59. }