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); } }