| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- /**
- * 支付宝小程序
- * User: zmz
- * Date: 2022/12/19
- * Time: 14:01
- */
- namespace backend\modules\mall\controllers;
- use backend\controllers\MallController;
- use common\helpers\CurlHelper;
- use Yii;
- use yii\db\Exception;
- class AlipayMiniController extends MallController
- {
- /**
- * 设置
- * @return mixed|string|void
- * @throws Exception
- */
- public function actionEdit()
- {
- $code = 'alipay_mini';
- $request = Yii::$app->request;
- if ($request->isAjax) {
- if ($request->isGet) {
- $mini_program = Yii::$app->services->setting->mall->get($this->mall_id, $code);
- if(!isset($mini_program['version'])) $mini_program['version'] = '';
- if(!isset($mini_program['desc'])) $mini_program['desc'] = '';
- if(!isset($mini_program['secret_key_file'])) $mini_program['secret_key_file'] = '';
- $this->success('获取成功', compact('mini_program'));
- } else {
- $params = Yii::$app->request->post('form');
- $res = Yii::$app->services->validate->validate($params, [
- [['app_id', 'merchantPrivateKey', 'name', 'mch_id'], 'required'],
- [['is_use_cert'], 'integer'],
- [['merchantCertPath', 'alipayPublicKey', 'alipayRootCertPath','alipayCertPath','merchantPrivateKey','encryptKey'], 'string'],
- [['can_auth_phone'],'integer']
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- // 保存数据
- $trans = Yii::$app->db->beginTransaction();
- $res = Yii::$app->services->setting->mall->set($this->mall_id, [$code => $params]);
- $trans->commit();
- if ($res === false) $this->error('保存失败');
- $this->success('保存成功');
- }
- }
- return $this->render($this->action->id);
- }
- }
|