| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\plugins\scanCodePay\controllers;
- use app\models\AggregateQrcode;
- use app\models\AggregateSaasQrcode;
- use app\models\Option;
- use app\models\Store;
- use app\plugins\scanCodePay\models\form\ScanCodePaySettingForm;
- use app\utils\QrCode;
- use app\utils\ShareQrcode;
- class IndexController
- {
- public function actionSetting ()
- {
- $form = new ScanCodePaySettingForm();
- $form->store_id = get_store_id();
- $form->mch = 0;
- if (\Yii::$app->request->isPost) {
- $form->setScenario('save');
- $form->attributes= post_params();
- $res = $form->save();
- return $res;
- }
- $form->setScenario('search');
- $data = $form->search();
- return [
- 'code' => 0,
- 'data' => $data
- ];
- }
- public function actionDownQr()
- {
- $store_id = get_store_id();
- $mch_id = intval(get_mch_id());
- $filename = md5('scan_' . $store_id . '_mch_' . $mch_id);
- $ag = AggregateQrcode::findOne(['store_id' => $store_id]);
- $store = Store::findOne($store_id);
- $self_mini = Option::get('self_mini', $store_id, 'store', 0)['value'];
- $data = [];
- if (!\Yii::$app->isSaas()) {
- $data['mini_url'] = '/face-pay/face-pay/payOut';
- $data['param_url'] = 'https://' . \Yii::$app->request->hostName . '/web/face/pay/' . $store_id. '?mch_id=' . $mch_id;
- }
- if (!empty($store) && ((int)$store->business_model !== 1 || (\Yii::$app->prod_is_dandianpu()) && !$self_mini)) {
- $asg = AggregateSaasQrcode::findOne(['store_id' => $store_id]);
- //先查询聚合表
- if(empty($asg->qrcode_url) || !file_exists(str_replace(\Yii::$app->request->hostInfo,\Yii::$app->basePath,$asg->qrcode_url))){
- if(!empty($asg->param_url)){
- $path = \Yii::$app->runtimePath . '/image/' . $filename . '.jpg';
- $pic_url = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/' . $filename . '.jpg');
- $text = $asg->param_url . '?mch_id=' . $mch_id;
- QrCode::image($text, 500, false, 'L', 'JPEG', 0, ['255,255,255', '0,0,0'], 1, false, $path);
- $asg->qrcode_url = $pic_url;
- $asg->save();
- return [
- 'code' => 0,
- 'data' => [
- 'qr_url' => $pic_url,
- 'business_model' => $store->business_model,
- 'is_saas' => (int)\Yii::$app->isSaas(),
- 'data' => [
- 'param_url' => $pic_url
- ]
- ]
- ];
- }
- }
- $path = \Yii::$app->runtimePath . '/image/' . $filename . '.jpg';
- $pic_url = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/' . $filename . '.jpg');
- if (file_exists($path)) {
- return [
- 'code' => 0,
- 'data' => [
- 'qr_url' => $pic_url,
- 'business_model' => $store->business_model,
- 'is_saas' => (int)\Yii::$app->isSaas(),
- 'data' => [
- 'param_url' => $pic_url
- ]
- ]
- ];
- }
- $text = 'store_id:'. $store_id . ',mch_id:'. $mch_id;
- $app = ShareQrcode::setBussinessWechat();
- $response = $app->getUnlimit($text, [
- 'width' => 500,
- 'page' => "face-pay/face-pay/payOut"
- ]);
- if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
- $filename = $response->save(\Yii::$app->runtimePath . '/image/', $filename);
- $pic_url = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/dy_qrcode/' . $filename);
- } else {
- return [
- 'code' => 1,
- 'data' => [
- 'response' => $response,
- 'business_model' => $store->business_model,
- ]
- ];
- }
- return [
- 'code' => 0,
- 'data' => [
- 'qr_url' => $pic_url,
- 'business_model' => $store->business_model,
- 'is_saas' => (int)\Yii::$app->isSaas(),
- 'data' => [
- 'param_url' => $pic_url
- ]
- ]
- ];
- } else if (empty($ag->param_url)) {
- $path = \Yii::$app->runtimePath . '/image/' . $filename . '.jpg';
- $pic_url = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/' . $filename . '.jpg');
- if (file_exists($path)) {
- return [
- 'code' => 0,
- 'data' => [
- 'qr_url' => $pic_url,
- 'business_model' => $store->business_model,
- 'is_saas' => (int)\Yii::$app->isSaas(),
- 'data' => $data
- ]
- ];
- }
- //$text = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/scan/' . $store_id);
- $text = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/web/face/pay/' . $store_id);
- QrCode::image($text, 500, false, 'L', 'JPEG', 0, ['255,255,255', '0,0,0'], 1, false, $path);
- } else {
- //同步后端的聚合码
- $filename = md5(date('YmdHis') . $ag->id);
- $path = \Yii::$app->runtimePath . '/image/' . $filename . '.jpg';
- $pic_url = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/' . $filename . '.jpg');
- $ag = AggregateQrcode::find()->where(['id' => $ag->id])->select('param_url,id,qrcode_url')->one();
- if(empty($ag->qrcode_url) || !file_exists(str_replace(\Yii::$app->request->hostInfo,\Yii::$app->basePath,$ag->qrcode_url))) {
- if (!empty($ag->param_url)) {
- $text = $ag->param_url . '?mch_id=' . $mch_id;
- QrCode::image($text, 500, false, 'L', 'JPEG', 0, ['255,255,255', '0,0,0'], 1, false, $path);
- }
- }
- }
- // Todo 待添加背景
- // $goods_qrcode = new \claviska\SimpleImage($path);
- // $bgPath = \Yii::$app->basePath . '/web/v1/statics/images/alipay-bg.png';
- // $bg = new \claviska\SimpleImage($bgPath);
- // $bg->overlay($goods_qrcode, 'top left', 1, 200, 350);
- // $bg->toFile($path, 'image/jpeg', 85);
- return [
- 'code' => 0,
- 'data' => [
- 'qr_url' => $pic_url,
- 'business_model' => $store->business_model,
- 'data' => [
- 'param_url' => $pic_url,
- ],
- 'is_saas' => (int)\Yii::$app->isSaas(),
- ]
- ];
- }
- }
|