WriterController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace api\controllers;
  3. use app\common\controllers\AController;
  4. use app\modules\admin\models\Attachment;
  5. use app\modules\admin\models\AttachmentTrash;
  6. use app\modules\doc\models\Doc;
  7. use app\modules\doc\models\DocData;
  8. use app\modules\doc\models\DocPackfile;
  9. use app\modules\doc\models\DocReal;
  10. use app\modules\doc\models\DocRealData;
  11. use Yii;
  12. class WriterController extends AController
  13. {
  14. public function init()
  15. {
  16. parent::init();
  17. }
  18. //删除文档草稿箱
  19. public function actionDeldraftdoc()
  20. {
  21. $ids = Yii::$app->request->get('ids');
  22. $ids = !empty($ids)?explode(",",$ids):[$this->get['id']];
  23. if(!empty($ids)){
  24. foreach($ids as $id){
  25. $model = Doc::findOne($id);
  26. $modelData = DocData::findOne($id);
  27. if($model&&$modelData)
  28. {
  29. //判断有无操作权限
  30. $checkResult = $this->checkRights($this->user_id,$model);
  31. if($checkResult['error']==1)continue;
  32. $imgcode = string2array($modelData->imgcode);
  33. $h5code = string2array($modelData->h5code);
  34. $file = $modelData->file;
  35. $path = getFileWorkPath($file);
  36. if($model->delete()&&$modelData->delete())
  37. {
  38. Attachment::releaseAttachmentByTable($id,$model->shortTableName(),'thumb');
  39. Attachment::releaseAttachmentByTable($id,$modelData->shortTableName(),'file');
  40. $trash = new AttachmentTrash();
  41. $trash->file_path = $path;
  42. $trash->is_oss = Yii::$app->params['oss']['OPEN_OSS'];
  43. $trash->create_time = TIMESTAMP;
  44. $trash->save();
  45. if(is_array($imgcode))foreach($imgcode as $img)
  46. {
  47. $trash = new AttachmentTrash();
  48. $trash->file_path = $img;
  49. $trash->is_oss = Yii::$app->params['oss']['OPEN_OSS'];
  50. $trash->create_time = TIMESTAMP;
  51. $trash->save();
  52. }
  53. if(is_array($h5code))foreach($h5code as $h5)
  54. {
  55. $trash = new AttachmentTrash();
  56. $trash->file_path = $h5;
  57. $trash->is_oss = Yii::$app->params['oss']['OPEN_OSS'];
  58. $trash->create_time = TIMESTAMP;
  59. $trash->save();
  60. }
  61. $packFileList = DocPackfile::find()->where("doc_id=$id")->all();
  62. if(is_array($packFileList))foreach($packFileList as $packFile)
  63. {
  64. $trash = new AttachmentTrash();
  65. $trash->file_path = $packFile->path;
  66. $trash->is_oss = Yii::$app->params['oss']['OPEN_OSS'];
  67. $trash->create_time = TIMESTAMP;
  68. $trash->save();
  69. }
  70. }
  71. }
  72. }
  73. return [
  74. 'error' => 0,
  75. 'msg' => '操作成功',
  76. 'data' => [],
  77. 'code'=>200
  78. ];
  79. }
  80. else
  81. {
  82. return [
  83. 'error' => 1,
  84. 'msg' => '操作失败',
  85. 'data' => [],
  86. 'code'=>200
  87. ];
  88. }
  89. }
  90. //删除文档
  91. public function actionDeldoc()
  92. {
  93. $ids = Yii::$app->request->get('ids');
  94. $ids = !empty($ids)?explode(",",$ids):[$this->get['id']];
  95. if(!empty($ids)){
  96. foreach($ids as $id){
  97. $model = DocReal::findOne($id);
  98. $modelData = DocRealData::findOne($id);
  99. if($model&&$modelData)
  100. {
  101. //判断有无操作权限
  102. $checkResult = $this->checkRights($this->user_id,$model);
  103. if($checkResult['error']==1)continue;
  104. $model->is_delete = 1;
  105. $model->save();
  106. }
  107. }
  108. return [
  109. 'error' => 0,
  110. 'msg' => '操作成功',
  111. 'data' => [],
  112. 'code'=>200
  113. ];
  114. }
  115. else
  116. {
  117. return [
  118. 'error' => 1,
  119. 'msg' => '操作失败',
  120. 'data' => [],
  121. 'code'=>200
  122. ];
  123. }
  124. }
  125. }