SmmUserAccountController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace App\Distributor\Controllers;
  3. use App\Distributor\Actions\SmmAddAccount;
  4. use App\Distributor\Repositories\SmmUserAccount;
  5. use App\Services\SmmService;
  6. use Dcat\Admin\Form;
  7. use Dcat\Admin\Grid;
  8. use Dcat\Admin\Show;
  9. use Dcat\Admin\Http\Controllers\AdminController;
  10. use Dcat\Admin\Layout\Content;
  11. use Dcat\Admin\Admin;
  12. use Illuminate\Http\Request;
  13. class SmmUserAccountController extends AdminController
  14. {
  15. /**
  16. * page index
  17. */
  18. public function index(Content $content)
  19. {
  20. return $content
  21. ->header('帐号管理')
  22. ->description('全部')
  23. ->body($this->grid());
  24. }
  25. /**
  26. * Make a grid builder.
  27. *
  28. * @return Grid
  29. */
  30. protected function grid()
  31. {
  32. return Grid::make(new SmmUserAccount(), function (Grid $grid) {
  33. $grid->column('id')->sortable();
  34. $grid->column('title')->tree();
  35. $grid->column('access_token');
  36. $grid->column('created_at');
  37. $grid->column('updated_at')->sortable();
  38. $grid->filter(function (Grid\Filter $filter) {
  39. $filter->panel();
  40. $filter->expand();
  41. $filter->like('user_name')->width(2);
  42. });
  43. // 传入数组
  44. $grid->rightTools([
  45. // new SmmAddAccount(),
  46. ]);
  47. $grid->actions(function (Grid\Displayers\Actions $actions) {
  48. $actions->disableEdit();
  49. $actions->disableQuickEdit();
  50. $actions->disableView();
  51. $dist_id = $actions->row->dist_id;
  52. if ($dist_id == 0) {
  53. $actions->append(new SmmAddAccount());
  54. $actions->disableDelete();
  55. }
  56. });
  57. $grid->disableCreateButton();
  58. $grid->disableEditButton();
  59. $grid->disableViewButton();
  60. $grid->model()->whereIn('dist_id', [0,getDistributorId()])->orderBy('title', 'asc')->orderBy('id', 'desc');
  61. });
  62. }
  63. /*
  64. * 社媒回调接口
  65. */
  66. public function callback($mediaName,Request $request)
  67. {
  68. try {
  69. $ssmService = new SmmService($mediaName);
  70. $result = $ssmService->loginCallback($request);
  71. dd($result);
  72. if ($result['status']) {
  73. $accessToken = $result['data']['access_token'];
  74. $userName = $result['data']['user_name'];
  75. $userId = $result['data']['user_id'];
  76. SmmUserAccount::createAccountIfMediaExists($mediaName, $userId,$userName, $accessToken);
  77. return response()->json(['code' => 1, 'msg' => 'success']);
  78. } else {
  79. return response()->json(['code' => 0,'msg' => $result['data']]);
  80. }
  81. } catch (\Exception $e) {
  82. return response()->json(['code' => 0,'msg' => 'error'.$e->getMessage()]);
  83. }
  84. }
  85. }