Ver código fonte

Merge branch 'liuzj-1000954-dev' into test

liuzejian 1 ano atrás
pai
commit
74b1c12bf8

+ 1 - 0
modules/Common/Errors/Errors.php

@@ -16,6 +16,7 @@ class Errors
     public const  PAY_TEMPLATE_NOT_EXISTS_ERROR= [500008, '充值模板不存在'];
     public const  PAY_TEMPLATE_CONFLICT= [500008, '该档位已存在'];
     public const  PAY_TEMPLATE_OPTIONS_ERROR= [500009, '类型不存在'];
+    public const  SERIES_NAME_NOT_OK= [500010, '剧集命名不合规'];
     public const  UPLOAD_IMAGE_ERROR= [500006, '上传图片不成功'];
     public const  JULIANG_ACCOUNT_EXISTS= [500101, '巨量广告账户已经存在'];
     public const  CALLBACK_RATE_TIME_RANGE_ERROR= [500102, '回传比例时间区间不合法'];

+ 27 - 8
modules/Video/Http/Controllers/EpisodeController.php

@@ -6,6 +6,7 @@ use Catch\Base\CatchController;
 use Illuminate\Foundation\Validation\ValidatesRequests;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\DB;
+use Modules\Common\Errors\Errors;
 use Modules\Common\Exceptions\CommonBusinessException;
 use Modules\Common\Services\Qiniu\QiniuTokenService;
 use Modules\User\Http\Controllers\UserTrait;
@@ -47,6 +48,13 @@ class EpisodeController extends CatchController
     public function downloadList(Request $request) {
         return $this->list($request);
     }
+
+    /**
+     * 添加短剧剧集, 允许覆盖已经存在的播放地址
+     * @param Request $request
+     * @return int
+     * @throws \Illuminate\Validation\ValidationException
+     */
     public function add(Request $request) {
         $this->validate($request, [
             'video_id' => 'required',
@@ -60,11 +68,15 @@ class EpisodeController extends CatchController
         $data = [];
         $now = date('Y-m-d H:i:s');
         foreach ($videos as $item) {
-            $data[] = [
+            $sequence = intval(explode('_', $item['name'])[0]);
+            if($sequence <=0 ) {
+                CommonBusinessException::throwError(Errors::SERIES_NAME_NOT_OK);
+            }
+            $data[$sequence] = [
                 'video_id' => $request->input('video_id'),
                 'video_key' => $item['key'],
                 'series_name' => $item['name'],
-                'series_sequence' => intval(explode('_', $item['name'])[0]),
+                'series_sequence' => $sequence,
                 'duration' => $item['duration'],
                 'created_at' => $now,
                 'updated_at' => $now,
@@ -73,14 +85,21 @@ class EpisodeController extends CatchController
 
         $allSequence = DB::table('video_series')->where(['video_id' => $request->input('video_id')])
             ->select('series_sequence')->get()->pluck('series_sequence');
-        $alreadySeries = collect($data)->pluck('series_sequence')->intersect($allSequence)->map(function ($item) use ($data) {
-            return collect($data)->keyBy('series_sequence')->get($item)['series_name'];
-        });
-        if($alreadySeries->isNotEmpty()) {
-            CommonBusinessException::throwError([-2333, $alreadySeries->join(', ')]);
+
+        foreach ($data as $key=>$item) {
+            if($allSequence->contains($key)) {
+                DB::table('video_series')->where([
+                    'video_id' => $item['video_id'],
+                    'series_sequence' => $item['series_sequence']
+                ])->update([
+                    'video_key' => $item['video_key'], 'series_name' => $item['series_name'],
+                    'duration' => $item['duration'], 'updated_at' => $item['updated_at'],
+                ]);
+            } else {
+                DB::table('video_series')->insert($item);
+            }
         }
 
-        DB::table('video_series')->insert($data);
         DB::table('videos')
             ->where(['id' => $request->input('video_id')])
             ->update(['updated_episode_num' => DB::table('video_series')

+ 2 - 2
tests/UsedTestCase.php

@@ -13,11 +13,11 @@ abstract class UsedTestCase extends BaseTestCase
     {
         parent::setUp(); // TODO: Change the autogenerated stub
         $tokenInfo = $this->post('http://localhost/api/login', [
-//            'email' => 'catch@admin.com',
+            'email' => 'catch@admin.com',
             'remember' => false,
 //            'email' => 'xiaoli@qq.com',
             'password' => 'catchadmin',
-            'email' => 'aa4@test.com',
+//            'email' => 'aa4@test.com',
         ])->json();
         $this->token = $tokenInfo['data']['token'];
     }

+ 4 - 4
tests/Video/Http/Controllers/EpisodeControllerTest.php

@@ -27,10 +27,10 @@ class EpisodeControllerTest extends UsedTestCase
         ])->json('post','http://localhost/api/videoStock/episode/add', [
             'video_id' => 3,
             'videos' => [
-                ['name' => '01_xxx', 'duration' => 12342, 'key' => 'url1'],
-                ['name' => '02_xxx', 'duration' => 1222, 'key' => 'url2'],
-                ['name' => '03_xxx', 'duration' => 3342, 'key' => 'url3'],
-                ['name' => '04_xxx', 'duration' => 3342, 'key' => 'url3'],
+                ['name' => '01_xxx', 'duration' => 12342, 'key' => 'url1234'],
+                ['name' => '02_xxx', 'duration' => 1222, 'key' => 'url244'],
+                ['name' => '03_xxx', 'duration' => 3342, 'key' => 'url344'],
+                ['name' => '04_xxx', 'duration' => 3342, 'key' => 'url344'],
             ]
         ]);
 //        $this->dumpJson($res);