| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\controllers;
- use app\models\AggregateSaasQrcode as AggregateQrcode;
- use app\modules\admin\models\AggregateSaasQrcodeForm as AggregateQrcodeForm;
- use app\modules\client\models\v1\NewSalesmanForm;
- use app\utils\QrCode;
- use app\modules\alliance\models\ShareQrcodeForm;
- use app\models\WechatConfig;
- class AggregateSaasQrcodeController extends BaseController
- {
- //创建url
- public function actionCreateUrl()
- {
- $form = new AggregateQrcodeForm();
- $form->number = post_params('number');
- $res = $form->createdUrl();
- return $this->asJson($res);
- }
- //展示列表
- public function actionQrcodeList()
- {
- $form = new AggregateQrcodeForm();
- $form->name = get_params('name');
- $form->salesman_name = get_params('salesman_name');
- $form->status = get_params('status');
- $res = $form->qrcodeList();
- return $this->asJson($res);
- }
- //生成二维码
- public function actionQrcodeCreate()
- {
- if (empty(post_params('ids'))) {
- return [
- 'code' => 1,
- 'msg' => '没有选择数据'
- ];
- }
- $ids = post_params('ids');
- $img = [];
- foreach ($ids as $index => $item) {
- $filename = md5(date('Ym') . $item);
- $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)) {
- // $img[] = $pic_url;
- // continue;
- // }
- $ag = AggregateQrcode::find()->where(['id' => $item])->select('store_id, 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;
- QrCode::image($text, 500, false, 'L', 'JPEG', 0, ['255,255,255', '0,0,0'], 1, false, $path);
- $business_no = null;
- $wechatConfig = WechatConfig::find()->where(['store_id' => $ag->store_id])->select('mch_id')->one();
- if ($wechatConfig) {
- $business_no = $wechatConfig->mch_id;
- }
- $form = new ShareQrcodeForm();
- $form->store_id = $ag->store_id;
- $formRes = $form->aggregateSaasQrcode($path, $business_no);
- if($formRes['code'] == 0){
- $pic_url = $formRes['data']['pic_url'];
- }
- // var_dump($formRes);die;
- $img[] = $pic_url;
- $ag->qrcode_url = $pic_url;
- $ag->save();
- }
- } else {
- $img[] = $ag->qrcode_url;
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '',
- 'data' => $img
- ]);
- }
- //删除
- public function actionDelUrl()
- {
- $form = new AggregateQrcodeForm();
- $form->ids = post_params('ids');
- $res = $form->urlDel();
- return $this->asJson($res);
- }
- //手动绑定商城
- public function actionBindQrcode()
- {
- $form = new AggregateQrcodeForm();
- $form->store_id = post_params("store_id");
- $form->id = post_params("id");
- $form->salesman_id = post_params("salesman_id");
- $res = $form->bindStore();
- return $this->asJson($res);
- }
- //绑定普通二维码
- public function actionBindMini()
- {
- $form = new NewSalesmanForm();
- $form->type = post_params("type", 'weixin');
- $form->mini_id = post_params("id");
- $res = $form->bindPayQrcode();
- return $this->asJson($res);
- }
- //小程序绑定信息
- public function actionMiniInfo()
- {
- $form = new AggregateQrcodeForm();
- $res = $form->qrcodeBindInfo();
- return $this->asJson($res);
- }
- //获取新的二维码信息
- public function actionShowQrcode()
- {
- $form = new AggregateQrcodeForm();
- $res = $form->showQrcode();
- return $this->asJson($res);
- }
- }
|