SelectorController.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace addons\Wechat\merchant\controllers;
  3. use Yii;
  4. use yii\helpers\Json;
  5. use common\helpers\ArrayHelper;
  6. use common\helpers\ResultHelper;
  7. use addons\Wechat\common\enums\AttachmentTypeEnum;
  8. /**
  9. * 微信资源选择器
  10. *
  11. * Class SelectorController
  12. * @package addons\Wechat\merchant\controllers
  13. * @author jianyan74 <751393839@qq.com>
  14. */
  15. class SelectorController extends BaseController
  16. {
  17. /**
  18. * 获取图片/视频/音频/图文
  19. *
  20. * @param bool $json 返回json格式
  21. * @return array|string
  22. */
  23. public function actionList($json = false)
  24. {
  25. $keyword = Yii::$app->request->get('keyword');
  26. $media_type = Yii::$app->request->get('media_type');
  27. $year = Yii::$app->request->get('year', '');
  28. $month = Yii::$app->request->get('month', '');
  29. if ($media_type == AttachmentTypeEnum::NEWS) {
  30. $models = Yii::$app->wechatService->attachmentNews->getFirstListPage($year, $month, $keyword);
  31. } else {
  32. $models = Yii::$app->wechatService->attachment->getListPage($media_type, $year, $month, $keyword);
  33. }
  34. if ($json == true) {
  35. return ResultHelper::json(200, '获取成功', $models);
  36. }
  37. return $this->renderAjax('selector', [
  38. 'models' => Json::encode($models),
  39. 'media_type' => $media_type,
  40. 'boxId' => Yii::$app->request->get('boxId'),
  41. 'year' => ArrayHelper::numBetween(2014, date('Y')),
  42. 'month' => ArrayHelper::numBetween(1, 12),
  43. ]);
  44. }
  45. }
粤ICP备19079148号