123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- namespace app\admin\controller;
- use ba\module\Server;
- use think\Exception;
- use ba\module\Manage;
- use ba\module\moduleException;
- use app\common\controller\Backend;
- class Module extends Backend
- {
- protected $noNeedPermission = ['state', 'dependentInstallComplete'];
- public function index()
- {
- $this->success('', [
- 'installed' => Server::installedList(root_path() . 'modules' . DIRECTORY_SEPARATOR),
- ]);
- }
- public function state()
- {
- $uid = $this->request->get("uid/s", '');
- if (!$uid) {
- $this->error(__('Parameter error'));
- }
- $this->success('', [
- 'state' => Manage::instance($uid)->getInstallState()
- ]);
- }
- public function install()
- {
- $uid = $this->request->get("uid/s", '');
- $token = $this->request->get("token/s", '');
- $orderId = $this->request->get("order_id/d", 0);
- if (!$uid) {
- $this->error(__('Parameter error'));
- }
- $res = [];
- try {
- $res = Manage::instance($uid)->install($token, $orderId);
- } catch (moduleException $e) {
- $this->error(__($e->getMessage()), $e->getData(), $e->getCode());
- } catch (Exception $e) {
- $this->error(__($e->getMessage()));
- }
- $this->success('', [
- 'data' => $res,
- ]);
- }
- public function dependentInstallComplete()
- {
- $uid = $this->request->get("uid/s", '');
- if (!$uid) {
- $this->error(__('Parameter error'));
- }
- try {
- Manage::instance($uid)->dependentInstallComplete('all');
- } catch (moduleException $e) {
- $this->error(__($e->getMessage()), $e->getData(), $e->getCode());
- } catch (Exception $e) {
- $this->error(__($e->getMessage()));
- }
- $this->success();
- }
- public function changeState()
- {
- $uid = $this->request->post("uid/s", '');
- $state = $this->request->post("state/b", false);
- if (!$uid) {
- $this->error(__('Parameter error'));
- }
- $info = [];
- try {
- $info = Manage::instance($uid)->changeState($state);
- } catch (moduleException $e) {
- $this->error(__($e->getMessage()), $e->getData(), $e->getCode());
- } catch (Exception $e) {
- $this->error(__($e->getMessage()));
- }
- $this->success('', [
- 'info' => $info,
- ]);
- }
- public function uninstall()
- {
- $uid = $this->request->get("uid/s", '');
- if (!$uid) {
- $this->error(__('Parameter error'));
- }
- try {
- Manage::instance($uid)->uninstall();
- } catch (moduleException $e) {
- $this->error(__($e->getMessage()), $e->getData(), $e->getCode());
- } catch (Exception $e) {
- $this->error(__($e->getMessage()));
- }
- $this->success();
- }
- public function update()
- {
- $uid = $this->request->get("uid/s", '');
- $token = $this->request->get("token/s", '');
- $orderId = $this->request->get("order_id/d", 0);
- if (!$token || !$uid) {
- $this->error(__('Parameter error'));
- }
- try {
- Manage::instance($uid)->update($token, $orderId);
- } catch (moduleException $e) {
- $this->error(__($e->getMessage()), $e->getData(), $e->getCode());
- } catch (Exception $e) {
- $this->error(__($e->getMessage()));
- }
- $this->success();
- }
- public function upload()
- {
- $file = $this->request->get("file/s", '');
- if (!$file) {
- $this->error(__('Parameter error'));
- }
- $info = [];
- try {
- $info = Manage::instance()->upload($file);
- } catch (moduleException $e) {
- $this->error(__($e->getMessage()), $e->getData(), $e->getCode());
- } catch (Exception $e) {
- $this->error(__($e->getMessage()));
- }
- $this->success('', [
- 'info' => $info
- ]);
- }
- }
|