| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- /**
- * Created by PhpStorm.
- * User: linzhida
- * Date: 2024/6/4
- * Time: 5:11 下午
- */
- namespace backend\modules\mall\controllers;
- use backend\controllers\MallController;
- use common\helpers\StringHelper;
- use common\enums\AppTypeEnum;
- use common\enums\StatusEnum;
- use common\models\common\AppVersion;
- use Yii;
- use yii\db\Exception;
- class AppController extends MallController
- {
- /**
- * app版本列表
- */
- public function actionVersionList()
- {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- if ($request->isGet) {
- $params = Yii::$app->request->get();
- $where = [
- ['mall_id' => $this->mall_id],
- ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]],
- ];
- if (!empty($params['app_type'])) $where[] = ['app_type' => $params['app_type']];
- if (!empty($params['status']) || is_numeric($params['status'])) $where[] = ['status' => $params['status']];
- // print_r(111);exit;
- $data = AppVersion::listPage([
- 'where' => $where,
- 'order' => 'id desc',
- 'page' => $params['page'],
- 'limit' => $params['page_size'] ?? 15,
- ]);
- $appType = AppTypeEnum::getAppType();
- $data['type'] = $appType;
- $this->success('获取成功',$data);
- } else {
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['app_type', 'version', 'content','download_url', 'edition_force', 'package_type', 'version_num'], 'required'],
- [['app_type', 'version', 'content','download_url'], 'string'],
- [['edition_force', 'package_type', 'version_num'], 'number'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $params['mall_id'] = $this->mall_id;
- $params['status'] = StatusEnum::ENABLED;
- // $params['version_num'] = StringHelper::getVersionNum($params['version']);
- if (empty($params['version_num'])) return $this->error('版本号格式错误');
- $newVersionData = AppVersion::find()->select('version_num')->where(['status' => StatusEnum::ENABLED, 'mall_id' => $this->mall_id, 'app_type' => $params['app_type']])->orderBy('version_num desc')->scalar();
- if (!empty($newVersionData) && $params['version_num'] <= $newVersionData) return $this->error('上传app版本号不能低于已上传app版本号');
- $res = AppVersion::setData($params);
- if ($res) $this->success('操作成功');
- $this->error('操作失败');
- }
- // // return '1111';
- // $version = '1.0.1.1';
- // $version_num = self::getVersionNum($version);
- // return $version_num;
- }
- return $this->render($this->action->id);
- }
- /**
- * 修改app版本状态
- */
- public function actionDoHandle()
- {
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['id', 'type'], 'required'],
- [['id'], 'integer']
- ]);
- if ($res === false) $this->error(Yii::$app->services->validate->getErrorMessage());
-
- switch ($params['type']) {
- case 'enable':
- $status = 1;
- break;
-
- case 'disable':
- $status = 0;
- break;
- case 'delete':
- $status = -1;
- break;
- }
- if (empty($status) && !is_numeric($status)) $this->error('请选择操作类型');
- $res = AppVersion::updateAll(['status' => $status], ['id' => $params['id'], 'mall_id' => $this->mall_id]);
- if ($res) $this->success('操作成功');
- $this->error(AppVersion::getStaticError());
- }
-
- }
|