| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- /**
- * 画册海报
- * @author system
- * @version 1.0
- * @date 2019-03-04 13:38:57
- *
- */
- namespace App\Http\Controllers\Admin\Album;
- use App\Http\Controllers\Admin\Controller;
- use Illuminate\Http\Request;
- use App\Repositories\Base\Criteria\OrderBy;
- use App\Repositories\Album\Criteria\MultiWhere;
- use App\Repositories\Album\PosterRepository;
- class PosterController extends Controller
- {
- private $repository;
- public function __construct(PosterRepository $repository)
- {
- if (!$this->repository) {
- $this->repository = $repository;
- }
- }
- /**
- * 修改
- */
- public function update(Request $request)
- {
- if ($request->method() == 'POST') {
- return $this->updateSave();
- }
- $data = $this->repository->findWhere(['store_id' => $this->getStoreId()])->toArray();
- if (!empty($data)) {
- $data = $data[0];
- $data['posters'] = json_decode($data['posters'], true);
- $data['words'] = json_decode($data['words'], true);
- }
- return view('admin.album.poster.edit', compact('data'));
- }
- /**
- * 保存修改
- */
- private function updateSave()
- {
- $data = (array) request('data');
- if (!empty($data['posters']['url'])) {
- foreach ($data['posters']['url'] as $key => $val) {
- $data['posters']['url'][$key] = $this->formatImgUrl($val);
- }
- $data['posters'] = json_encode($data['posters']['url']);
- }
- if (empty($data['share']) || empty($data['qrcode'])) {
- return $this->showMessage('分享海报或者二维码不能为空!');
- }
- $data['share'] = $this->formatImgUrl($data['share']);
- $data['qrcode'] = $this->formatImgUrl($data['qrcode']);
- if (!empty($data['words'])) {
- $data['words'] = json_encode($data['words']);
- }
- $id = request('id');
- if (empty($id)) {
- $data['store_id'] = $this->getStoreId();
- $ok = $this->repository->create($data);
- } else {
- $ok = $this->repository->update($id, $data);
- }
- if ($ok) {
- return $this->showMessage('操作成功');
- } else {
- return $this->showMessage('操作失败');
- }
- }
- public function viewPoster(Request $request)
- {
- $img = '/base/img/poster.jpg';
- return view('admin.album.poster.view', compact('img'));
- }
- public function viewShare(Request $request)
- {
- $img = '/base/img/share.jpg';
- return view('admin.album.poster.view', compact('img'));
- }
- }
|