PosterController.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * 画册海报
  4. * @author system
  5. * @version 1.0
  6. * @date 2019-03-04 13:38:57
  7. *
  8. */
  9. namespace App\Http\Controllers\Admin\Album;
  10. use App\Http\Controllers\Admin\Controller;
  11. use Illuminate\Http\Request;
  12. use App\Repositories\Base\Criteria\OrderBy;
  13. use App\Repositories\Album\Criteria\MultiWhere;
  14. use App\Repositories\Album\PosterRepository;
  15. class PosterController extends Controller
  16. {
  17. private $repository;
  18. public function __construct(PosterRepository $repository)
  19. {
  20. if (!$this->repository) {
  21. $this->repository = $repository;
  22. }
  23. }
  24. /**
  25. * 修改
  26. */
  27. public function update(Request $request)
  28. {
  29. if ($request->method() == 'POST') {
  30. return $this->updateSave();
  31. }
  32. $data = $this->repository->findWhere(['store_id' => $this->getStoreId()])->toArray();
  33. if (!empty($data)) {
  34. $data = $data[0];
  35. $data['posters'] = json_decode($data['posters'], true);
  36. $data['words'] = json_decode($data['words'], true);
  37. }
  38. return view('admin.album.poster.edit', compact('data'));
  39. }
  40. /**
  41. * 保存修改
  42. */
  43. private function updateSave()
  44. {
  45. $data = (array) request('data');
  46. if (!empty($data['posters']['url'])) {
  47. foreach ($data['posters']['url'] as $key => $val) {
  48. $data['posters']['url'][$key] = $this->formatImgUrl($val);
  49. }
  50. $data['posters'] = json_encode($data['posters']['url']);
  51. }
  52. $data['share'] = $this->formatImgUrl($data['share']);
  53. $data['qrcode'] = $this->formatImgUrl($data['qrcode']);
  54. if (!empty($data['words'])) {
  55. $data['words'] = json_encode($data['words']);
  56. }
  57. $id = request('id');
  58. if (empty($id)) {
  59. $data['store_id'] = $this->getStoreId();
  60. $ok = $this->repository->create($data);
  61. } else {
  62. $ok = $this->repository->update($id, $data);
  63. }
  64. if ($ok) {
  65. $url[] = array('url' => U('Album/Poster/index'), 'title' => '返回列表');
  66. return $this->showMessage('操作成功', urldecode(request('_referer')));
  67. } else {
  68. $url[] = array('url' => U('Album/Poster/index'), 'title' => '返回列表');
  69. return $this->showWarning('操作失败', $url);
  70. }
  71. }
  72. }