ChannelController.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Support\Facades\Log;
  5. use Illuminate\Support\Arr;
  6. use Illuminate\Support\Facades\DB;
  7. use App\Models\Channel;
  8. use App\Models\Sentence;
  9. use App\Models\DhammaTerm;
  10. use App\Models\WbwBlock;
  11. use App\Models\PaliSentence;
  12. use App\Models\CustomBook;
  13. use App\Http\Controllers\AuthController;
  14. use App\Http\Resources\ChannelResource;
  15. use App\Http\Api\AuthApi;
  16. use App\Http\Api\StudioApi;
  17. use App\Http\Api\ShareApi;
  18. use App\Http\Api\PaliTextApi;
  19. use App\Http\Api\ChannelApi;
  20. class ChannelController extends Controller
  21. {
  22. /**
  23. * Display a listing of the resource.
  24. *
  25. * @return \Illuminate\Http\Response
  26. */
  27. public function index(Request $request)
  28. {
  29. //
  30. $result=false;
  31. $indexCol = ['uid','name','summary',
  32. 'type','owner_uid','lang',
  33. 'status','is_system','updated_at','created_at'];
  34. switch ($request->get('view')) {
  35. case 'public':
  36. $table = Channel::select($indexCol)
  37. ->where('status',30);
  38. break;
  39. case 'studio':
  40. # 获取studio内所有channel
  41. $user = AuthApi::current($request);
  42. if(!$user){
  43. return $this->error(__('auth.failed'));
  44. }
  45. //判断当前用户是否有指定的studio的权限
  46. $studioId = StudioApi::getIdByName($request->get('name'));
  47. if($user['user_uid'] !== $studioId){
  48. return $this->error(__('auth.failed'));
  49. }
  50. $table = Channel::select($indexCol);
  51. if($request->get('view2','my')==='my'){
  52. $table = $table->where('owner_uid', $studioId);
  53. }else{
  54. //协作
  55. $resList = ShareApi::getResList($studioId,2);
  56. $resId=[];
  57. foreach ($resList as $res) {
  58. $resId[] = $res['res_id'];
  59. }
  60. $table = $table->whereIn('uid', $resId);
  61. if($request->get('collaborator','all') !== 'all'){
  62. $table = $table->where('owner_uid', $request->get('collaborator'));
  63. }else{
  64. $table = $table->where('owner_uid','<>', $studioId);
  65. }
  66. }
  67. break;
  68. case 'studio-all':
  69. /**
  70. * studio 的和协作的
  71. */
  72. #获取user所有有权限的channel列表
  73. $user = AuthApi::current($request);
  74. if(!$user){
  75. return $this->error(__('auth.failed'));
  76. }
  77. //判断当前用户是否有指定的studio的权限
  78. if($user['user_uid'] !== StudioApi::getIdByName($request->get('name'))){
  79. return $this->error(__('auth.failed'));
  80. }
  81. $channelById = [];
  82. $channelId = [];
  83. //获取共享channel
  84. $allSharedChannels = ShareApi::getResList($user['user_uid'],2);
  85. foreach ($allSharedChannels as $key => $value) {
  86. # code...
  87. $channelId[] = $value['res_id'];
  88. $channelById[$value['res_id']] = $value;
  89. }
  90. $table = Channel::select($indexCol)
  91. ->whereIn('uid', $channelId)
  92. ->orWhere('owner_uid',$user['user_uid']);
  93. break;
  94. case 'user-edit':
  95. /**
  96. * 某用户有编辑权限的
  97. */
  98. #获取user所有有权限的channel列表
  99. $user = AuthApi::current($request);
  100. if(!$user){
  101. return $this->error(__('auth.failed'));
  102. }
  103. $channelById = [];
  104. $channelId = [];
  105. //获取共享channel
  106. $allSharedChannels = ShareApi::getResList($user['user_uid'],2);
  107. foreach ($allSharedChannels as $key => $value) {
  108. # code...
  109. if($value['power']>=20){
  110. $channelId[] = $value['res_id'];
  111. $channelById[$value['res_id']] = $value;
  112. }
  113. }
  114. $table = Channel::select($indexCol)
  115. ->whereIn('uid', $channelId)
  116. ->orWhere('owner_uid',$user['user_uid']);
  117. break;
  118. case 'user-in-chapter':
  119. #获取user 在某章节 所有有权限的channel列表
  120. $user = AuthApi::current($request);
  121. if(!$user){
  122. return $this->error(__('auth.failed'));
  123. }
  124. $channelById = [];
  125. $channelId = [];
  126. //获取共享channel
  127. $allSharedChannels = ShareApi::getResList($user['user_uid'],2);
  128. foreach ($allSharedChannels as $key => $value) {
  129. # code...
  130. $channelId[] = $value['res_id'];
  131. $channelById[$value['res_id']] = $value;
  132. }
  133. //获取全网公开channel
  134. $chapter = PaliTextApi::getChapterStartEnd($request->get('book'),$request->get('para'));
  135. $publicChannelsWithContent = Sentence::where('book_id',$request->get('book'))
  136. ->whereBetween('paragraph',$chapter)
  137. ->where('strlen','>',0)
  138. ->where('status',30)
  139. ->groupBy('channel_uid')
  140. ->select('channel_uid')
  141. ->get();
  142. foreach ($publicChannelsWithContent as $key => $value) {
  143. # code...
  144. $value['res_id']=$value->channel_uid;
  145. $value['power'] = 10;
  146. $value['type'] = 2;
  147. if(!isset($channelById[$value['res_id']])){
  148. $channelId[] = $value['res_id'];
  149. $channelById[$value['res_id']] = $value;
  150. }
  151. }
  152. $table = Channel::select($indexCol)
  153. ->whereIn('uid', $channelId)
  154. ->orWhere('owner_uid',$user['user_uid']);
  155. break;
  156. case 'system':
  157. $table = Channel::select($indexCol)
  158. ->where('owner_uid',config("mint.admin.root_uuid"));
  159. break;
  160. }
  161. //处理搜索
  162. if(!empty($request->get("search"))){
  163. $table = $table->where('name', 'like', "%".$request->get("search")."%");
  164. }
  165. if($request->has("type")){
  166. $table = $table->where('type', $request->get("type"));
  167. }
  168. if($request->has("updated_at")){
  169. $table = $table->where('updated_at','>', $request->get("updated_at"));
  170. }
  171. if($request->has("created_at")){
  172. $table = $table->where('created_at','>', $request->get("created_at"));
  173. }
  174. //获取记录总条数
  175. $count = $table->count();
  176. //处理排序
  177. $table = $table->orderBy($request->get("order",'created_at'),
  178. $request->get("dir",'desc'));
  179. //处理分页
  180. $table = $table->skip($request->get("offset",0))
  181. ->take($request->get("limit",200));
  182. //获取数据
  183. $result = $table->get();
  184. //TODO 将下面代码转移到resource
  185. if($result){
  186. if($request->has('progress')){
  187. //获取进度
  188. //获取单句长度
  189. $sentLen = PaliSentence::where('book',$request->get('book'))
  190. ->whereBetween('paragraph',$chapter)
  191. ->orderBy('word_begin')
  192. ->select(['book','paragraph','word_begin','word_end','length'])
  193. ->get();
  194. }
  195. foreach ($result as $key => $value) {
  196. if($request->has('progress')){
  197. //获取进度
  198. $finalTable = Sentence::where('book_id',$request->get('book'))
  199. ->whereBetween('paragraph',$chapter)
  200. ->where('channel_uid',$value->uid)
  201. ->where('strlen','>',0)
  202. ->select(['strlen','book_id','paragraph','word_start','word_end']);
  203. if($finalTable->count()>0){
  204. $finished = $finalTable->get();
  205. $final=[];
  206. foreach ($sentLen as $sent) {
  207. # code...
  208. $first = Arr::first($finished, function ($value, $key) use($sent) {
  209. return ($value->book_id==$sent->book &&
  210. $value->paragraph==$sent->paragraph &&
  211. $value->word_start==$sent->word_begin &&
  212. $value->word_end==$sent->word_end);
  213. });
  214. $final[] = [$sent->length,$first?true:false];
  215. }
  216. $value['final'] = $final;
  217. }
  218. }
  219. //角色
  220. if(isset($user['user_uid'])){
  221. if($value->owner_uid===$user['user_uid']){
  222. $value['role'] = 'owner';
  223. }else{
  224. if(isset($channelById[$value->uid])){
  225. switch ($channelById[$value->uid]['power']) {
  226. case 10:
  227. # code...
  228. $value['role'] = 'member';
  229. break;
  230. case 20:
  231. $value['role'] = 'editor';
  232. break;
  233. case 30:
  234. $value['role'] = 'owner';
  235. break;
  236. default:
  237. # code...
  238. $value['role'] = $channelById[$value->uid]['power'];
  239. break;
  240. }
  241. }
  242. }
  243. }
  244. # 获取studio信息
  245. $value->studio = StudioApi::getById($value->owner_uid);
  246. }
  247. return $this->ok(["rows"=>$result,"count"=>$count]);
  248. }else{
  249. return $this->error("没有查询到数据");
  250. }
  251. }
  252. /**
  253. * 获取我的,和协作channel数量
  254. *
  255. * @return \Illuminate\Http\Response
  256. */
  257. public function showMyNumber(Request $request){
  258. $user = AuthApi::current($request);
  259. if(!$user){
  260. return $this->error(__('auth.failed'));
  261. }
  262. //判断当前用户是否有指定的studio的权限
  263. $studioId = StudioApi::getIdByName($request->get('studio'));
  264. if($user['user_uid'] !== $studioId){
  265. return $this->error(__('auth.failed'));
  266. }
  267. //我的
  268. $my = Channel::where('owner_uid', $studioId)->count();
  269. //协作
  270. $resList = ShareApi::getResList($studioId,2);
  271. $resId=[];
  272. foreach ($resList as $res) {
  273. $resId[] = $res['res_id'];
  274. }
  275. $collaboration = Channel::whereIn('uid', $resId)->where('owner_uid','<>', $studioId)->count();
  276. return $this->ok(['my'=>$my,'collaboration'=>$collaboration]);
  277. }
  278. /**
  279. * 获取章节的进度
  280. *
  281. * @param \Illuminate\Http\Request $request
  282. * @return \Illuminate\Http\Response
  283. */
  284. public function progress(Request $request){
  285. $indexCol = ['uid','name','summary','type','owner_uid','lang','status','updated_at','created_at'];
  286. $sent = $request->get('sentence') ;
  287. $query = [];
  288. $queryWithChannel = [];
  289. $sentContainer = [];
  290. $sentLenContainer = [];
  291. $paliChannel = ChannelApi::getSysChannel('_System_Pali_VRI_');
  292. $customBookChannel = array();
  293. foreach ($sent as $value) {
  294. $ids = explode('-',$value);
  295. $idWithChannel = $ids;
  296. if(count($ids)===4){
  297. if($ids[0] < 1000){
  298. $idWithChannel[] = $paliChannel;
  299. }else{
  300. if(!isset($customBookChannel[$ids[0]])){
  301. $cbChannel = CustomBook::where('book_id',$ids[0])->value('channel_id');
  302. if($cbChannel){
  303. $customBookChannel[$ids[0]] = $cbChannel;
  304. }else{
  305. $customBookChannel[$ids[0]] = $paliChannel;
  306. }
  307. }
  308. $idWithChannel[] = $customBookChannel[$ids[0]];
  309. }
  310. $sentContainer[$value] = false;
  311. $query[] = $ids;
  312. $queryWithChannel[] = $idWithChannel;
  313. }
  314. }
  315. //获取单句长度
  316. if(count($query)>0){
  317. $table = Sentence::whereIns(['book_id','paragraph','word_start','word_end','channel_uid'],$queryWithChannel)
  318. ->select(['book_id','paragraph','word_start','word_end','strlen']);
  319. $sentLen = $table->get();
  320. foreach ($sentLen as $value) {
  321. $strlen = $value->strlen;
  322. if(empty($strlen)){
  323. $strlen = 0;
  324. }
  325. $sentId = "{$value->book_id}-{$value->paragraph}-{$value->word_start}-{$value->word_end}";
  326. $sentLenContainer[$sentId] = $strlen;
  327. }
  328. }
  329. $channelById = [];
  330. $channelId = [];
  331. //获取全网公开的有译文的channel
  332. if($request->get('owner')==='all' || $request->get('owner')==='public'){
  333. if(count($query)>0){
  334. $publicChannelsWithContent = Sentence::whereIns(['book_id','paragraph','word_start','word_end'],$query)
  335. ->where('strlen','>',0)
  336. ->where('status',30)
  337. ->groupBy('channel_uid')
  338. ->select('channel_uid')
  339. ->get();
  340. foreach ($publicChannelsWithContent as $key => $value) {
  341. # code...
  342. $value['res_id']=$value->channel_uid;
  343. $value['power'] = 10;
  344. $value['type'] = 2;
  345. if(!isset($channelById[$value['res_id']])){
  346. $channelId[] = $value['res_id'];
  347. $channelById[$value['res_id']] = $value;
  348. }
  349. }
  350. }
  351. }
  352. #获取 user 在某章节 所有有权限的 channel 列表
  353. $user = AuthApi::current($request);
  354. if($user !== false){
  355. //我自己的
  356. if($request->get('owner')==='all' || $request->get('owner')==='my'){
  357. $my = Channel::select($indexCol)->where('owner_uid', $user['user_uid'])->get();
  358. foreach ($my as $key => $value) {
  359. $channelId[] = $value->uid;
  360. $channelById[$value->uid] = ['res_id'=>$value->uid,
  361. 'power'=>30,
  362. 'type'=>2,
  363. ];
  364. }
  365. }
  366. //获取共享channel
  367. if($request->get('owner')==='all' || $request->get('owner')==='collaborator'){
  368. $allSharedChannels = ShareApi::getResList($user['user_uid'],2);
  369. foreach ($allSharedChannels as $key => $value) {
  370. # code...
  371. if(!in_array($value['res_id'],$channelId)){
  372. $channelId[] = $value['res_id'];
  373. $channelById[$value['res_id']] = $value;
  374. }
  375. }
  376. }
  377. }
  378. //所有有这些句子译文的channel
  379. if(count($query) > 0){
  380. $allChannels = Sentence::whereIns(['book_id','paragraph','word_start','word_end'],$query)
  381. ->where('strlen','>',0)
  382. ->groupBy('channel_uid')
  383. ->select('channel_uid')
  384. ->get();
  385. }
  386. //所有需要查询的channel
  387. $table = Channel::select(['uid','name','summary','type','owner_uid','lang','status','updated_at','created_at'])
  388. ->whereIn('uid', $channelId);
  389. if($user !== false){
  390. $table->orWhere('owner_uid',$user['user_uid']);
  391. }
  392. $result = $table->get();
  393. foreach ($result as $key => $value) {
  394. //角色
  395. if($user!==false && $value->owner_uid===$user['user_uid']){
  396. $value['role'] = 'owner';
  397. }else{
  398. if(isset($channelById[$value->uid])){
  399. switch ($channelById[$value->uid]['power']) {
  400. case 10:
  401. # code...
  402. $value['role'] = 'member';
  403. break;
  404. case 20:
  405. $value['role'] = 'editor';
  406. break;
  407. case 30:
  408. $value['role'] = 'owner';
  409. break;
  410. default:
  411. # code...
  412. $value['role'] = $channelById[$value->uid]['power'];
  413. break;
  414. }
  415. }
  416. }
  417. # 获取studio信息
  418. $result[$key]["studio"] = \App\Http\Api\StudioApi::getById($value->owner_uid);
  419. //获取进度
  420. if(count($query) > 0){
  421. $currChannelId = $value->uid;
  422. $hasContent = Arr::first($allChannels, function ($value, $key) use($currChannelId) {
  423. return ($value->channel_uid===$currChannelId);
  424. });
  425. if($hasContent && count($query)>0){
  426. $finalTable = Sentence::whereIns(['book_id','paragraph','word_start','word_end'],$query)
  427. ->where('channel_uid',$currChannelId)
  428. ->where('strlen','>',0)
  429. ->select(['strlen','book_id','paragraph','word_start','word_end','created_at','updated_at']);
  430. $created_at = time();
  431. $edit_at = 0;
  432. if($finalTable->count()>0){
  433. $finished = $finalTable->get();
  434. $currChannel = [];
  435. foreach ($finished as $rowFinish) {
  436. $createTime = strtotime($rowFinish->created_at);
  437. $updateTime = strtotime($rowFinish->updated_at);
  438. if($createTime < $created_at){
  439. $created_at = $createTime;
  440. }
  441. if($updateTime > $edit_at){
  442. $edit_at = $updateTime;
  443. }
  444. $currChannel["{$rowFinish->book_id}-{$rowFinish->paragraph}-{$rowFinish->word_start}-{$rowFinish->word_end}"] = 1;
  445. }
  446. $final=[];
  447. foreach ($sentContainer as $sentId=>$rowSent) {
  448. # code...
  449. if(isset($currChannel[$sentId])){
  450. $final[] = [$sentLenContainer[$sentId],true];
  451. }else{
  452. $final[] = [$sentLenContainer[$sentId],false];
  453. }
  454. }
  455. $result[$key]['final'] = $final;
  456. $result[$key]['content_created_at'] = date('Y-m-d H:i:s',$created_at);
  457. $result[$key]['content_updated_at'] = date('Y-m-d H:i:s',$edit_at);
  458. }
  459. }
  460. }
  461. }
  462. return $this->ok(["rows"=>$result,count($result)]);
  463. }
  464. /**
  465. * Store a newly created resource in storage.
  466. *
  467. * @param \Illuminate\Http\Request $request
  468. * @return \Illuminate\Http\Response
  469. */
  470. public function store(Request $request)
  471. {
  472. //
  473. $user = AuthApi::current($request);
  474. if(!$user){
  475. return $this->error(__('auth.failed'),401,401);
  476. }
  477. //判断当前用户是否有指定的studio的权限
  478. $studioId = StudioApi::getIdByName($request->get('studio'));
  479. if($user['user_uid'] !== $studioId){
  480. return $this->error(__('auth.failed'),403,403);
  481. }
  482. $studio = StudioApi::getById($studioId);
  483. //查询是否重复
  484. if(Channel::where('name',$request->get('name'))
  485. ->where('owner_uid',$user['user_uid'])
  486. ->exists()){
  487. return $this->error(__('validation.exists',['name']),200,200);
  488. }
  489. $channel = new Channel;
  490. $channel->id = app('snowflake')->id();
  491. $channel->name = $request->get('name');
  492. $channel->owner_uid = $user['user_uid'];
  493. $channel->type = $request->get('type');
  494. $channel->lang = $request->get('lang');
  495. $channel->editor_id = $user['user_id'];
  496. if(isset($studio['roles'])){
  497. if(in_array('basic',$studio['roles'])){
  498. $channel->status = 5;
  499. }
  500. }
  501. $channel->create_time = time()*1000;
  502. $channel->modify_time = time()*1000;
  503. $channel->save();
  504. return $this->ok($channel);
  505. }
  506. /**
  507. * Display the specified resource.
  508. *
  509. * @param int $id
  510. * @return \Illuminate\Http\Response
  511. */
  512. public function show($id)
  513. {
  514. //
  515. $indexCol = ['uid','name','summary','type','owner_uid','lang','is_system','status','updated_at','created_at'];
  516. $channel = Channel::where("uid",$id)->select($indexCol)->first();
  517. $studio = StudioApi::getById($channel->owner_uid);
  518. $channel->studio = $studio;
  519. $channel->owner_info = ['nickname'=>$studio['nickName'],'username'=>$studio['realName']];
  520. return $this->ok($channel);
  521. }
  522. /**
  523. * Display the specified resource.
  524. *
  525. * @param string $name
  526. * @return \Illuminate\Http\Response
  527. */
  528. public function showByName(string $name)
  529. {
  530. //
  531. $indexCol = ['uid','name','summary','type','owner_uid','lang','is_system','status','updated_at','created_at'];
  532. $channel = Channel::where("name",$name)->select($indexCol)->first();
  533. if($channel){
  534. return $this->ok(new ChannelResource($channel));
  535. }else{
  536. return $this->error('no channel');
  537. }
  538. }
  539. /**
  540. * Update the specified resource in storage.
  541. *
  542. * @param \Illuminate\Http\Request $request
  543. * @param \App\Models\Channel $channel
  544. * @return \Illuminate\Http\Response
  545. */
  546. public function update(Request $request, Channel $channel)
  547. {
  548. //鉴权
  549. $user = AuthApi::current($request);
  550. if(!$user){
  551. return $this->error(__('auth.failed'),401,401);
  552. }
  553. if($channel->is_system){
  554. return $this->error('system channel',403,403);
  555. }
  556. if($channel->owner_uid !== $user["user_uid"]){
  557. //判断是否为协作
  558. $power = ShareApi::getResPower($user["user_uid"],$request->get('id'));
  559. if($power < 30){
  560. return $this->error(__('auth.failed'),403,403);
  561. }
  562. }
  563. $channel->name = $request->get('name');
  564. $channel->type = $request->get('type');
  565. $channel->summary = $request->get('summary');
  566. $channel->lang = $request->get('lang');
  567. $channel->status = $request->get('status');
  568. $channel->save();
  569. return $this->ok($channel);
  570. }
  571. /**
  572. * patch the specified resource in storage.
  573. *
  574. * @param \Illuminate\Http\Request $request
  575. * @param \App\Models\Channel $channel
  576. * @return \Illuminate\Http\Response
  577. */
  578. public function patch(Request $request, Channel $channel)
  579. {
  580. //鉴权
  581. $user = AuthApi::current($request);
  582. if(!$user){
  583. return $this->error(__('auth.failed'),[],401);
  584. }
  585. if($channel->is_system){
  586. return $this->error('system channel',403,403);
  587. }
  588. if($channel->owner_uid !== $user["user_uid"]){
  589. //判断是否为协作
  590. $power = ShareApi::getResPower($user["user_uid"],$request->get('id'));
  591. if($power < 30){
  592. return $this->error(__('auth.failed'),[],403);
  593. }
  594. }
  595. if($request->has('name')){$channel->name = $request->get('name');}
  596. if($request->has('type')){$channel->type = $request->get('type');}
  597. if($request->has('summary')){$channel->summary = $request->get('summary');}
  598. if($request->has('lang')){$channel->lang = $request->get('lang');}
  599. if($request->has('status')){$channel->status = $request->get('status');}
  600. if($request->has('config')){$channel->status = $request->get('config');}
  601. $channel->save();
  602. return $this->ok($channel);
  603. }
  604. /**
  605. * Remove the specified resource from storage.
  606. * @param \Illuminate\Http\Request $request
  607. * @param \App\Models\Channel $channel
  608. * @return \Illuminate\Http\Response
  609. */
  610. public function destroy(Request $request,Channel $channel)
  611. {
  612. //
  613. $user = AuthApi::current($request);
  614. if(!$user){
  615. return $this->error(__('auth.failed'));
  616. }
  617. //判断当前用户是否有指定的studio的权限
  618. if($user['user_uid'] !== $channel->owner_uid){
  619. return $this->error(__('auth.failed'));
  620. }
  621. //查询其他资源
  622. if(Sentence::where("channel_uid",$channel->uid)->exists()){
  623. return $this->error("译文有数据无法删除");
  624. }
  625. if(DhammaTerm::where("channal",$channel->uid)->exists()){
  626. return $this->error("术语有数据无法删除");
  627. }
  628. if(WbwBlock::where("channel_uid",$channel->uid)->exists()){
  629. return $this->error("逐词解析有数据无法删除");
  630. }
  631. $delete = 0;
  632. DB::transaction(function() use($channel,$delete){
  633. //TODO 删除相关资源
  634. $delete = $channel->delete();
  635. });
  636. return $this->ok($delete);
  637. }
  638. }