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(), ] ]; } }