| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\controllers\setting;
- use app\models\Cloud;
- use app\models\CloudSetting;
- use app\modules\admin\controllers\BaseController;
- use app\modules\admin\models\CloudForm;
- use yii\helpers\Json;
- class CloudController extends BaseController
- {
- /**
- * 获取云打印列表
- * @return \yii\web\Response
- */
- public function actionList()
- {
- $setting = CloudSetting::findOne(['store_id' => get_store_id(), 'mch_id' => get_mch_id()]);
- $cache_key_cloud_setting = 'admin_cloud_setting_' . get_store_id() . '_' . get_mch_id();
- if ($list = cache()->get($cache_key_cloud_setting)) {
- return $this->asJson([
- 'code' => 0,
- 'data' => [
- 'list' => $list,
- 'setting' => $setting
- ]
- ]);
- }
- $list = Cloud::find()->where(['is_delete' => 0, 'store_id' => get_store_id(), 'mch_id' => get_mch_id()])
- ->orderBy(['id' => SORT_DESC])->all();
- cache()->set($cache_key_cloud_setting, $list, 600);
- return $this->asJson([
- 'code' => 0,
- 'data' => [
- 'list' => $list,
- 'setting' => $setting
- ]
- ]);
- }
- /**
- * 获取详情
- */
- public function actionEdit($id = null)
- {
- return $this->asJson([
- 'code' => 0,
- 'data' => [
- 'model' => Cloud::findOne($id)
- ]
- ]);
- }
- /**
- * 保存
- */
- public function actionSave()
- {
- $form = new CloudForm();
- $form->attributes = post_params();
- return $this->asJson($form->save());
- }
- /**
- * 删除
- * @param $id
- * @return \yii\web\Response
- */
- public function actionDel($id)
- {
- $model = Cloud::findOne($id);
- if (empty($model)) {
- $res = ['code' => 1, 'msg' => '参数错误'];
- } else {
- $model->is_delete = 1;
- $res = $model->save() ? ['code' => 0, 'msg' => '保存成功'] : ['code' => 1, 'msg' => '保存失败'];
- }
- cache()->delete('admin_cloud_setting_' . get_store_id() . '_' . get_mch_id());
- return $this->asJson($res);
- }
- /**
- * 保存设置
- * @return \yii\web\Response
- */
- public function actionSaveSetting()
- {
- $model = CloudSetting::findOne(['store_id' => get_store_id(), 'mch_id' => get_mch_id()]) ?: new CloudSetting();
- $model->store_id = get_store_id();
- $model->cloud_id = post_params('cloud_id');
- $model->mch_id = get_mch_id();
- $model->type = Json::encode(post_params('type', []));
- $res = $model->save() ? ['code' => 0, 'msg' => '保存成功'] : ['code' => 1, 'msg' => '保存失败'];
- cache()->delete('admin_cloud_setting_' . get_store_id() . '_' . get_mch_id());
- return $this->asJson($res);
- }
- }
|