AggregateSaasQrcodeController.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\controllers;
  8. use app\models\AggregateSaasQrcode as AggregateQrcode;
  9. use app\modules\admin\models\AggregateSaasQrcodeForm as AggregateQrcodeForm;
  10. use app\modules\client\models\v1\NewSalesmanForm;
  11. use app\utils\QrCode;
  12. use app\modules\alliance\models\ShareQrcodeForm;
  13. use app\models\WechatConfig;
  14. class AggregateSaasQrcodeController extends BaseController
  15. {
  16. //创建url
  17. public function actionCreateUrl()
  18. {
  19. $form = new AggregateQrcodeForm();
  20. $form->number = post_params('number');
  21. $res = $form->createdUrl();
  22. return $this->asJson($res);
  23. }
  24. //展示列表
  25. public function actionQrcodeList()
  26. {
  27. $form = new AggregateQrcodeForm();
  28. $form->name = get_params('name');
  29. $form->salesman_name = get_params('salesman_name');
  30. $form->status = get_params('status');
  31. $res = $form->qrcodeList();
  32. return $this->asJson($res);
  33. }
  34. //生成二维码
  35. public function actionQrcodeCreate()
  36. {
  37. if (empty(post_params('ids'))) {
  38. return [
  39. 'code' => 1,
  40. 'msg' => '没有选择数据'
  41. ];
  42. }
  43. $ids = post_params('ids');
  44. $img = [];
  45. foreach ($ids as $index => $item) {
  46. $filename = md5(date('Ym') . $item);
  47. $path = \Yii::$app->runtimePath . '/image/' . $filename . '.jpg';
  48. $pic_url = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/' . $filename . '.jpg');
  49. // if (file_exists($path)) {
  50. // $img[] = $pic_url;
  51. // continue;
  52. // }
  53. $ag = AggregateQrcode::find()->where(['id' => $item])->select('store_id, param_url, id, qrcode_url')->one();
  54. if (empty($ag->qrcode_url) || !file_exists(str_replace(\Yii::$app->request->hostInfo, \Yii::$app->basePath, $ag->qrcode_url))) {
  55. if (!empty($ag->param_url)) {
  56. $text = $ag->param_url;
  57. QrCode::image($text, 500, false, 'L', 'JPEG', 0, ['255,255,255', '0,0,0'], 1, false, $path);
  58. $business_no = null;
  59. $wechatConfig = WechatConfig::find()->where(['store_id' => $ag->store_id])->select('mch_id')->one();
  60. if ($wechatConfig) {
  61. $business_no = $wechatConfig->mch_id;
  62. }
  63. $form = new ShareQrcodeForm();
  64. $form->store_id = $ag->store_id;
  65. $formRes = $form->aggregateSaasQrcode($path, $business_no);
  66. if($formRes['code'] == 0){
  67. $pic_url = $formRes['data']['pic_url'];
  68. }
  69. // var_dump($formRes);die;
  70. $img[] = $pic_url;
  71. $ag->qrcode_url = $pic_url;
  72. $ag->save();
  73. }
  74. } else {
  75. $img[] = $ag->qrcode_url;
  76. }
  77. }
  78. return $this->asJson([
  79. 'code' => 0,
  80. 'msg' => '',
  81. 'data' => $img
  82. ]);
  83. }
  84. //删除
  85. public function actionDelUrl()
  86. {
  87. $form = new AggregateQrcodeForm();
  88. $form->ids = post_params('ids');
  89. $res = $form->urlDel();
  90. return $this->asJson($res);
  91. }
  92. //手动绑定商城
  93. public function actionBindQrcode()
  94. {
  95. $form = new AggregateQrcodeForm();
  96. $form->store_id = post_params("store_id");
  97. $form->id = post_params("id");
  98. $form->salesman_id = post_params("salesman_id");
  99. $res = $form->bindStore();
  100. return $this->asJson($res);
  101. }
  102. //绑定普通二维码
  103. public function actionBindMini()
  104. {
  105. $form = new NewSalesmanForm();
  106. $form->type = post_params("type", 'weixin');
  107. $form->mini_id = post_params("id");
  108. $res = $form->bindPayQrcode();
  109. return $this->asJson($res);
  110. }
  111. //小程序绑定信息
  112. public function actionMiniInfo()
  113. {
  114. $form = new AggregateQrcodeForm();
  115. $res = $form->qrcodeBindInfo();
  116. return $this->asJson($res);
  117. }
  118. //获取新的二维码信息
  119. public function actionShowQrcode()
  120. {
  121. $form = new AggregateQrcodeForm();
  122. $res = $form->showQrcode();
  123. return $this->asJson($res);
  124. }
  125. }