链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.5 KiB

  1. <?php
  2. namespace App\Admin\Common;
  3. use Dcat\Admin\Controllers\AdminController;
  4. use EasyWeChat\Factory;
  5. use Intervention\Image\ImageManager;
  6. class StoreQRCode extends AdminController
  7. {
  8. protected $images;
  9. protected $imageManager;
  10. public function __construct()
  11. {
  12. $this->images = new Images();
  13. // $this->imageManager = new ImageManager();
  14. }
  15. /**
  16. * 生成小程序码 永久 还没完成
  17. * @param $scene 参数
  18. * @param $optional
  19. */
  20. public function getUnlimited(string $scene, array $optional = [])
  21. {
  22. $wxCode = Factory::payment(config('wechat.mini_program.default'));
  23. $res = $wxCode->app_code->getUnlimited($scene,$optional);
  24. }
  25. /**
  26. * 生成店铺的微信小程序码
  27. */
  28. public function SetStoreWeChatCode($id)
  29. {
  30. $codeStore = $this->images->createQrCode($id,'zh_cjdianc/pages/takeout/takeoutindex');
  31. $storeImgPath = 'QR_code/code_store_img/wx_store_'.$id.'.jpg';
  32. $res = $this->images->uploadOss($codeStore,$storeImgPath);
  33. if($res){
  34. return ['status' => true ,'path' => $storeImgPath];
  35. }else{
  36. return ['status' => false ,'path' => ''];
  37. }
  38. }
  39. /**
  40. * 生成店铺收银的微信二维码
  41. */
  42. public function SetPayWeChatCode($id)
  43. {
  44. // $isCREATE = env('IS_CREATE_WECHAT_MINI_QR_CODE',1);
  45. // if($isCREATE == 0){
  46. $codeStore = $this->images->createQrCode($id,'zh_cjdianc/pages/seller/fukuan');
  47. $storeImgPath = 'QR_code/code_minipay_img/wx_minipay_'.$id.'.jpg';
  48. // }else{
  49. // $codeStore = $this->images->createWeChatQrCode('?scene='.$id,'zh_cjdianc/pages/seller/fukuan');
  50. // $storeImgPath = 'QR_code/code_pay_img/wx_pay_'.$id.'.jpg';
  51. // // 裁剪
  52. // }
  53. // 裁剪测试
  54. // $this->imageManager->make()->resize(270,270)->insert($codeStore);
  55. $res = $this->images->uploadOss($codeStore,$storeImgPath);
  56. if($res){
  57. return ['status' => true ,'path' => $storeImgPath];
  58. }else{
  59. return ['status' => false ,'path' => ''];
  60. }
  61. }
  62. /**
  63. * 店铺收银码裁剪
  64. */
  65. public function setStoreCodeImg($file_path,$storeId){
  66. $save_path = './QR_code/wx_store_pay_cut/wx_pay_'.$storeId.'.jpg';
  67. if(!file_exists($save_path)){
  68. //将图片进行裁剪
  69. if(file_exists($file_path)){
  70. $save_width = 270;
  71. $start_spot_x = 5;
  72. $start_spot_y = 5;
  73. $width = 270;
  74. $height = 270;
  75. $this->tailoringImg($save_path,$file_path,$save_width,$start_spot_x,$start_spot_y,$width,$height,1);
  76. }else{
  77. return '';
  78. }
  79. }
  80. return $save_path;
  81. }
  82. /**
  83. * 裁剪图片
  84. */
  85. public function tailoringImg($save_path,$file_path,$save_width,$start_spot_x,$start_spot_y,$width,$height,$display=1)
  86. {
  87. if(file_exists($file_path) && is_readable($file_path)){
  88. //从字符串中的图像流新建一图像
  89. $src = imagecreatefromstring(file_get_contents($file_path));
  90. //保存图片的高
  91. $save_height = round($save_width*$height/$width);
  92. //根据要保存的宽和高创建图片
  93. $new_image = imagecreatetruecolor($save_width, $save_height);
  94. //生成最后的图片
  95. imagecopyresampled($new_image, $src, 0, 0, $start_spot_x, $start_spot_y, $save_width, $save_height, $width, $height);
  96. // header('Content-Type: image/jpeg');
  97. imagejpeg($new_image,$save_path);
  98. imagedestroy($src);
  99. imagedestroy($new_image);
  100. }
  101. }
  102. }