MiniProgramController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace backend\modules\mall\controllers;
  3. use backend\controllers\MallController;
  4. use backend\modules\mall\services\MiniProgramService;
  5. use Yii;
  6. /**
  7. * 微信小程序设置
  8. * MiniProgramController class
  9. */
  10. class MiniProgramController extends MallController
  11. {
  12. /**
  13. * 公众号设置
  14. *
  15. * @return mixed
  16. */
  17. public function actionEdit()
  18. {
  19. if (Yii::$app->request->isAjax) {
  20. $service = new MiniProgramService(['mall_id' => $this->mall_id]);
  21. if (Yii::$app->request->isGet) {
  22. $mini_program = $service->getMiniProgramConfig();
  23. return $this->success('获取成功', compact('mini_program'));
  24. } else {
  25. $params = Yii::$app->request->post('form');
  26. $res = Yii::$app->services->validate->validate($params, [
  27. [['app_id', 'secret', 'name', 'original_id'], 'required'],
  28. [['app_id', 'secret', 'name', 'original_id', 'version', 'desc', 'secret_key_file', 'postUrl', 'upload_secret_key','index_url'], 'string'],
  29. [['is_live'], 'integer'],
  30. ]);
  31. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  32. return $service->setMiniProgramConfig($params)
  33. ? $this->success('保存成功')
  34. : $this->error($service->getError());
  35. }
  36. }
  37. return $this->render($this->action->id);
  38. }
  39. /**
  40. * 提交至微信审核小程序
  41. *
  42. * @return mixed
  43. */
  44. public function actionUploadWechat()
  45. {
  46. $service = new MiniProgramService(['mall_id' => $this->mall_id]);
  47. return ($data = $service->uploadToWechat())
  48. ? $this->success('提交成功', $data)
  49. : $this->error($service->getError());
  50. }
  51. /**
  52. * 小程序上传
  53. *
  54. * @return mixed
  55. */
  56. public function actionTask()
  57. {
  58. if (Yii::$app->request->isAjax) {
  59. $service = new MiniProgramService(['mall_id' => $this->mall_id]);
  60. if (Yii::$app->request->isGet) {
  61. $params = Yii::$app->request->get();
  62. return $this->success('获取成功', $service->getTaskPageList($params));
  63. } else {
  64. $params = Yii::$app->request->post();
  65. $res = Yii::$app->services->validate->validate($params, [
  66. [['app_id', 'is_live', 'upload_secret_key', 'version', 'api_domain', 'static_domain', 'is_review'], 'required'],
  67. [['app_id', 'upload_secret_key', 'version', 'desc', 'api_domain', 'static_domain',], 'string'],
  68. [['is_live', 'is_review'], 'integer'],
  69. [['plugins'], 'safe'],
  70. ]);
  71. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  72. $params['mall_sign'] = $this->mall['mall_sign'];
  73. return $service->addTaskLog($params)
  74. ? $this->success('提交成功')
  75. : $this->error($service->getError());
  76. }
  77. }
  78. return $this->render($this->action->id);
  79. }
  80. //点击查看日志
  81. public function actionTaskLog()
  82. {
  83. $request = Yii::$app->request;
  84. if ($request->isGet) {
  85. $params = $request->get();
  86. $service = new MiniProgramService(['mall_id' => $this->mall_id]);
  87. return $this->success('获取成功', $service->getTaskLog($params));
  88. }
  89. }
  90. /**
  91. * 获取小程序配置
  92. *
  93. * @return mixed
  94. */
  95. public function actionGetMiniProgramConfig()
  96. {
  97. $service = new MiniProgramService(['mall_id' => $this->mall_id]);
  98. return $this->successStr('获取成功', $service->getTaskLogConfig());
  99. }
  100. /**
  101. * 修改状态
  102. *
  103. * @param integer $id
  104. * @return mixed
  105. */
  106. public function actionTaskChangeReview(int $id)
  107. {
  108. $service = new MiniProgramService(['mall_id' => $this->mall_id]);
  109. return $service->changeTaskReview($id)
  110. ? $this->success('修改成功')
  111. : $this->error($service->getError());
  112. }
  113. }