MerchantController.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace backend\controllers;
  3. use common\models\xhShop;
  4. use common\services\xhShopService;
  5. use Yii;
  6. use common\services\xhWxOpenService;
  7. use common\services\xhAdminToMerchantService;
  8. use common\services\xhAdminService;
  9. use common\components\qrCodeUtil;
  10. use common\components\util;
  11. use common\components\weixinUtil;
  12. use common\components\configDict;
  13. use common\services\xhMerchantExtendService;
  14. use common\services\xhMerchantService;
  15. class MerchantController extends BackendController
  16. {
  17. public function actionIndex()
  18. {
  19. $admin = xhAdminToMerchantService::getAdminByMerchantId($this->merchantId);
  20. return $this->render('index', ['admin' => $admin, 'shop' => $this->merchant, 'shopAsset' => $this->merchantAsset, 'shopExtend' => $this->merchantExtend]);
  21. }
  22. public function actionGatheringUrl()
  23. {
  24. $wifiQrImg = '/qrcode/weixinQrcode/' . $shopId . '.jpg';
  25. $unique = configDict::getQrKey('gathering') . $this->merchantId;
  26. $gatheringQrcodeUrl = $this->merchant['gatheringQrcodeUrl'];
  27. $webRoot = Yii::getAlias('@webroot') . '/../../resource/images';
  28. $shop = xhShop::find()->where(['merchantId'=>$this->merchantId])->one();
  29. if(empty($shop)){
  30. throw new \Exception('没有门店信息');
  31. }
  32. $shopId = $shop->id;
  33. //合并后图片
  34. $mergeGatheringQrcodeUrl = $this->merchantExtend['mergeGatheringQrcodeUrl'];
  35. $mergeGatheringQrcodeUrlAlipay = $this->merchantExtend['mergeGatheringQrcodeUrlAlipay'];
  36. if (!empty($mergeGatheringQrcodeUrl)) {
  37. //有合并后的图片,则拼接完整地址
  38. $mergeGatheringQrcodeUrl = Yii::$app->params['imgUrl'] . $mergeGatheringQrcodeUrl;
  39. $mergeGatheringQrcodeUrlAlipay = Yii::$app->params['imgUrl'] . $mergeGatheringQrcodeUrlAlipay;
  40. }
  41. if (empty($gatheringQrcodeUrl) || file_exists($webRoot . $gatheringQrcodeUrl) == false) {
  42. $url = Yii::$app->params['frontUrl'] . '/pay/index?account=' . $this->merchant['id'] .'&shopId='.$shopId;
  43. $logo = !empty($this->merchant['logo']) ? $webRoot . $this->merchant['logo'] : '';
  44. $gatheringQrcodeUrl = qrCodeUtil::generate($url, $unique, $logo, 10);
  45. xhMerchantService::updateById($this->merchantId, ['gatheringQrcodeUrl' => $gatheringQrcodeUrl]);
  46. }
  47. $admin = xhAdminToMerchantService::getAdminByMerchantId($this->merchantId);
  48. return $this->render('gatheringUrl', [
  49. 'admin' => $admin,
  50. 'qrCodeUrl' => $gatheringQrcodeUrl,
  51. 'mergeQrCodeUrl' => $mergeGatheringQrcodeUrl,
  52. 'mergeQrCodeUrlAlipay' => $mergeGatheringQrcodeUrlAlipay,
  53. 'shopId' => $shopId,
  54. 'url' => $url,
  55. ]);
  56. }
  57. //lqh 合并微信支付图片 2017-05-05
  58. public function actionMergeWxImg()
  59. {
  60. /*$gatheringQrcodeUrl = $this->merchant['gatheringQrcodeUrl'];
  61. $webRoot = Yii::getAlias('@webroot') . '/../../../resource/images/';
  62. $gatheringQrcodeUrl = $webRoot.$gatheringQrcodeUrl; //完整地址二维码
  63. $background_img = Yii::getAlias('@webroot').'/images/merchant/wxPay.png'; //微信背景图
  64. $background_img_alipay = Yii::getAlias('@webroot').'/images/merchant/alipay.png'; //支付宝背景图
  65. //图片格式必须是png
  66. $merge_img_wx = util::mergeImg($background_img, $gatheringQrcodeUrl);
  67. $merge_img_alipay = util::mergeImg($background_img_alipay, $gatheringQrcodeUrl,'alipay');
  68. //保存到商户扩展表中
  69. $data['mergeGatheringQrcodeUrl'] = $merge_img_wx;
  70. $data['mergeGatheringQrcodeUrlAlipay'] = $merge_img_alipay;
  71. xhMerchantExtendService::updateByMerchantId($this->merchantId,$data);*/
  72. $shopId = Yii::$app->request->post('shopId');
  73. $saveQrCodeDir = dirname(Yii::$app->basePath) . '/images/qrcode/weixinQrcode/';
  74. $wifiQrImg = $saveQrCodeDir . $shopId . '.jpg';
  75. $gatheringQrcodeUrl = $this->merchant['gatheringQrcodeUrl'];
  76. $webRoot = Yii::getAlias('@webroot') . '/../../images/';
  77. $gatheringQrcodeUrl = $webRoot . $gatheringQrcodeUrl; //完整地址二维码
  78. $backgroundImg = Yii::getAlias('@webroot') . '/images/merchant/full.jpg'; //背景图
  79. $qrImg = [
  80. 'zhifubao' => $gatheringQrcodeUrl,
  81. 'weixin' => $gatheringQrcodeUrl,
  82. 'wifi' => $wifiQrImg,
  83. ];
  84. $fullMergeImg = util::mergeQrimg($backgroundImg, $qrImg);
  85. $data['mergeGatheringQrcodeUrl'] = $fullMergeImg;
  86. xhMerchantExtendService::updateByMerchantId($this->merchantId, $data);
  87. util::successInfo();
  88. }
  89. public function actionMergeImgDemo()
  90. {
  91. $gatheringQrcodeUrl = $this->merchant['gatheringQrcodeUrl'];
  92. $webRoot = Yii::getAlias('@webroot') . '/../../images/';
  93. $gatheringQrcodeUrl = $webRoot . $gatheringQrcodeUrl; //完整地址二维码
  94. $bcgImg = Yii::getAlias('@webroot') . '/images/merchant/full.jpg'; //背景图
  95. $qrImg = [
  96. 'zhifubao' => $gatheringQrcodeUrl,
  97. 'weixin' => $gatheringQrcodeUrl,
  98. 'wifi' => '',
  99. ];
  100. util::mergeQrimg($bcgImg, $qrImg);
  101. }
  102. /**
  103. * 上传店长微信二维码
  104. */
  105. public function actionDownloadAdminWxQrCode()
  106. {
  107. $get = Yii::$app->request->get();
  108. $mediaId = isset($get['mediaId']) ? $get['mediaId'] : '';
  109. $openMerchant = xhWxOpenService::getMerchant();
  110. $imgList = weixinUtil::downloadmediaIdImg($openMerchant, $mediaId, 'wxAdminImg');
  111. if (!empty($imgList)) {
  112. $img = $imgList['large'];
  113. $data = ['wxQrCode' => $img];
  114. $admin = xhAdminToMerchantService::getAdminByMerchantId($this->merchantId);
  115. $adminId = $admin['id'];
  116. xhAdminService::updateById($adminId, $data);
  117. util::successInfo('上传成功', 'A0001', $imgList);
  118. }
  119. util::failInfo();
  120. }
  121. }