Group.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. namespace backend\server;
  3. use backend\base\Help;
  4. use Yii;
  5. use common\models\GroupPurchase;
  6. class Group
  7. {
  8. public function StateAndDel($type)
  9. {
  10. $model = new GroupPurchase();
  11. $input = Yii::$app->request->post();
  12. $row = $model->FindById($input['id']);
  13. switch ($type)
  14. {
  15. case 1:
  16. if($row->is_view == 1)
  17. {
  18. $row->is_view = 2;
  19. }
  20. else if($row->is_view == 2)
  21. {
  22. $row->is_view = 1;
  23. }
  24. break;
  25. case 2:
  26. $row->del = 2;
  27. break;
  28. }
  29. if($row->save() == true) return true;
  30. }
  31. public function GroupEdit()
  32. {
  33. $model = new GroupPurchase();
  34. $validateData = $model->Authenticator(Yii::$app->request->post());
  35. if(is_object($validateData))
  36. {
  37. $row = $model->FindById(Yii::$app->request->post('id'));
  38. if($row != null)
  39. {
  40. $delIdentifying = false;
  41. $row['many_img'] = json_decode($row['many_img'],true);
  42. $delimg = Yii::$app->request->post('delimg'); //需要删除的数组
  43. $ImgUrl = Yii::$app->params['img_url']['group'];
  44. $arrImg = [];
  45. if(!empty($delimg))
  46. {
  47. $arrImg = array_diff($row['many_img'],$delimg); //需要保留的数组 如果删除全部图片 返回空数组
  48. if(empty($arrImg))
  49. {
  50. $delIdentifying = true; //标识是否删除所有图片
  51. }
  52. foreach ($delimg as $val)
  53. {
  54. UploadFile::delImg($ImgUrl,$val);
  55. }
  56. }
  57. else
  58. {
  59. $arrImg = $row['many_img'];
  60. }
  61. $imgArr = \backend\server\UploadFile::InstancesImgName('img',$ImgUrl);
  62. if(is_array($imgArr))
  63. {
  64. $arrImg = array_merge($imgArr,$arrImg);
  65. if(Yii::$app->request->post('thumb_watermark') == 1 )
  66. {
  67. $ImgSet = new SetUploadImg();
  68. $ImgSet->SetImgWatermark($imgArr,$ImgUrl);
  69. }
  70. //压缩图片
  71. $compressParams = [];
  72. $compressParams['data']['imgname'] = $imgArr;;
  73. $compressParams['data']['url'] = $ImgUrl;
  74. $this->onCompress($compressParams);
  75. }
  76. $setAttr = Help::SetAttr(Yii::$app->request->post(),$validateData,$row);
  77. if(!empty($arrImg) || $delIdentifying == true)
  78. {
  79. $setAttr->many_img = json_encode($arrImg);
  80. }
  81. else
  82. {
  83. $setAttr->many_img = json_encode($setAttr->many_img); //没有修改图片的情况下
  84. }
  85. $img_mobile = UploadFile::InstanceImgName('img_mobile',$ImgUrl);
  86. $img_pc = UploadFile::InstanceImgName('img_pc',$ImgUrl);
  87. if($img_mobile != false)
  88. {
  89. UploadFile::delImg($ImgUrl,$row['img_mobile']);
  90. $setAttr->img_mobile = $img_mobile;
  91. }
  92. if($img_pc != false)
  93. {
  94. UploadFile::delImg($ImgUrl,$row['img_pc']);
  95. $setAttr->img_pc = $img_pc;
  96. }
  97. if($setAttr->update() == true) return true;
  98. }
  99. }
  100. return $validateData;
  101. }
  102. public function GroupAdd()
  103. {
  104. $model = new GroupPurchase();
  105. $auth = $model->Authenticator(Yii::$app->request->post());
  106. if(is_object($auth))
  107. {
  108. $url = Yii::$app->params['img_url']['group'];
  109. $img_mobile = UploadFile::InstanceImgName('img_mobile',$url);
  110. $img_pc = UploadFile::InstanceImgName('img_pc',$url);
  111. //处理多图图片
  112. $row = \backend\server\UploadFile::InstancesImgName('img',$url);
  113. if(is_array($row)){
  114. $model->many_img = json_encode($row);
  115. }
  116. if($img_mobile != false)
  117. {
  118. $auth->img_mobile = $img_mobile;
  119. }
  120. if($img_pc != false)
  121. {
  122. $auth->img_pc = $img_pc;
  123. }
  124. return $auth->save(false);
  125. }
  126. return false;
  127. }
  128. //压缩图片
  129. private function onCompress($data)
  130. {
  131. $model = new \backend\event\TinifyEvent();
  132. $model->CompressImg($data);
  133. }
  134. }