AggregateQrcodeController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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\AggregateQrcode;
  9. use app\modules\admin\models\AggregateQrcodeForm;
  10. use app\modules\client\models\v1\NewSalesmanForm;
  11. use app\utils\QrCode;
  12. class AggregateQrcodeController extends BaseController
  13. {
  14. //创建url
  15. public function actionCreateUrl(){
  16. $form = new AggregateQrcodeForm();
  17. $form->number = post_params('number');
  18. $res = $form->createdUrl();
  19. return $this->asJson($res);
  20. }
  21. //展示列表
  22. public function actionQrcodeList(){
  23. $form = new AggregateQrcodeForm();
  24. $form->name = get_params('name');
  25. $form->salesman_name = get_params('salesman_name');
  26. $form->status = get_params('status');
  27. $res = $form->qrcodeList();
  28. return $this->asJson($res);
  29. }
  30. //生成二维码
  31. public function actionQrcodeCreate(){
  32. if(empty(post_params('ids'))){
  33. return [
  34. 'code'=>1,
  35. 'msg'=>'没有选择数据'
  36. ];
  37. }
  38. $ids = post_params('ids');
  39. $img = [];
  40. foreach ($ids as $index=>$item){
  41. $filename = md5(date('Ym').$item);
  42. $path = \Yii::$app->runtimePath . '/image/' . $filename . '.jpg';
  43. $pic_url = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/' . $filename . '.jpg');
  44. if (file_exists($path)) {
  45. $img[]= $pic_url;
  46. continue;
  47. }
  48. $ag = AggregateQrcode::find()->where(['id'=>$item])->select('param_url,id,qrcode_url')->one();
  49. if(empty($ag->qrcode_url) || !file_exists(str_replace(\Yii::$app->request->hostInfo,\Yii::$app->basePath,$ag->qrcode_url))){
  50. if(!empty($ag->param_url)){
  51. $text = $ag->param_url;
  52. QrCode::image($text, 500, false, 'L', 'JPEG', 0, ['255,255,255', '0,0,0'], 1, false, $path);
  53. $img[]= $pic_url;
  54. $ag->qrcode_url = $pic_url;
  55. $ag->save();
  56. }
  57. }else{
  58. $img[]= $ag->qrcode_url;
  59. }
  60. }
  61. return $this->asJson([
  62. 'code'=>0,
  63. 'msg'=>'',
  64. 'data'=>$img
  65. ]);
  66. }
  67. //删除
  68. public function actionDelUrl(){
  69. $form = new AggregateQrcodeForm();
  70. $form->ids = post_params('ids');
  71. $res = $form->urlDel();
  72. return $this->asJson($res);
  73. }
  74. //手动绑定商城
  75. public function actionBindQrcode(){
  76. $form = new AggregateQrcodeForm();
  77. $form->store_id = post_params("store_id");
  78. $form->id = post_params("id");
  79. $form->salesman_id = post_params("salesman_id");
  80. $res = $form->bindStore();
  81. return $this->asJson($res);
  82. }
  83. //手动绑定微信/支付宝
  84. public function actionBindQrcodeOnline(){
  85. $form = new AggregateQrcodeForm();
  86. $form->id = post_params("id");
  87. $form->type = post_params("type");
  88. $res = $form->bindQrcode();
  89. return $this->asJson($res);
  90. }
  91. //绑定普通二维码
  92. public function actionBindMini(){
  93. $form = new NewSalesmanForm();
  94. $form->type = post_params("type",'weixin');
  95. $form->mini_id = post_params("id");
  96. $res = $form->bindPayQrcode();
  97. return $this->asJson($res);
  98. }
  99. //小程序绑定信息
  100. public function actionMiniInfo(){
  101. $form = new AggregateQrcodeForm();
  102. $res = $form->qrcodeBindInfo();
  103. return $this->asJson($res);
  104. }
  105. }