CloudController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\controllers\setting;
  8. use app\models\Cloud;
  9. use app\models\CloudSetting;
  10. use app\modules\admin\controllers\BaseController;
  11. use app\modules\admin\models\CloudForm;
  12. use yii\helpers\Json;
  13. class CloudController extends BaseController
  14. {
  15. /**
  16. * 获取云打印列表
  17. * @return \yii\web\Response
  18. */
  19. public function actionList()
  20. {
  21. $setting = CloudSetting::findOne(['store_id' => get_store_id(), 'mch_id' => get_mch_id()]);
  22. $cache_key_cloud_setting = 'admin_cloud_setting_' . get_store_id() . '_' . get_mch_id();
  23. if ($list = cache()->get($cache_key_cloud_setting)) {
  24. return $this->asJson([
  25. 'code' => 0,
  26. 'data' => [
  27. 'list' => $list,
  28. 'setting' => $setting
  29. ]
  30. ]);
  31. }
  32. $list = Cloud::find()->where(['is_delete' => 0, 'store_id' => get_store_id(), 'mch_id' => get_mch_id()])
  33. ->orderBy(['id' => SORT_DESC])->all();
  34. cache()->set($cache_key_cloud_setting, $list, 600);
  35. return $this->asJson([
  36. 'code' => 0,
  37. 'data' => [
  38. 'list' => $list,
  39. 'setting' => $setting
  40. ]
  41. ]);
  42. }
  43. /**
  44. * 获取详情
  45. */
  46. public function actionEdit($id = null)
  47. {
  48. return $this->asJson([
  49. 'code' => 0,
  50. 'data' => [
  51. 'model' => Cloud::findOne($id)
  52. ]
  53. ]);
  54. }
  55. /**
  56. * 保存
  57. */
  58. public function actionSave()
  59. {
  60. $form = new CloudForm();
  61. $form->attributes = post_params();
  62. return $this->asJson($form->save());
  63. }
  64. /**
  65. * 删除
  66. * @param $id
  67. * @return \yii\web\Response
  68. */
  69. public function actionDel($id)
  70. {
  71. $model = Cloud::findOne($id);
  72. if (empty($model)) {
  73. $res = ['code' => 1, 'msg' => '参数错误'];
  74. } else {
  75. $model->is_delete = 1;
  76. $res = $model->save() ? ['code' => 0, 'msg' => '保存成功'] : ['code' => 1, 'msg' => '保存失败'];
  77. }
  78. cache()->delete('admin_cloud_setting_' . get_store_id() . '_' . get_mch_id());
  79. return $this->asJson($res);
  80. }
  81. /**
  82. * 保存设置
  83. * @return \yii\web\Response
  84. */
  85. public function actionSaveSetting()
  86. {
  87. $model = CloudSetting::findOne(['store_id' => get_store_id(), 'mch_id' => get_mch_id()]) ?: new CloudSetting();
  88. $model->store_id = get_store_id();
  89. $model->cloud_id = post_params('cloud_id');
  90. $model->mch_id = get_mch_id();
  91. $model->type = Json::encode(post_params('type', []));
  92. $res = $model->save() ? ['code' => 0, 'msg' => '保存成功'] : ['code' => 1, 'msg' => '保存失败'];
  93. cache()->delete('admin_cloud_setting_' . get_store_id() . '_' . get_mch_id());
  94. return $this->asJson($res);
  95. }
  96. }