UserBill.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * @Created by PhpStorm
  4. * @author: Kirin
  5. * @day: 2024/12/16
  6. * @time: 10:43
  7. */
  8. namespace app\controller\api\user;
  9. use app\common\ApiBaseController;
  10. use app\services\system\attachment\SystemAttachmentServices;
  11. use app\services\system\QrcodeServices;
  12. use think\db\exception\DataNotFoundException;
  13. use think\db\exception\DbException;
  14. use think\db\exception\ModelNotFoundException;
  15. class UserBill extends ApiBaseController
  16. {
  17. /**
  18. * 获取海报详细信息
  19. * @return mixed
  20. * @throws DataNotFoundException
  21. * @throws DbException
  22. * @throws ModelNotFoundException
  23. */
  24. public function getSpreadInfo()
  25. {
  26. $spreadBanner = sys_config('spread_banner', []);
  27. $bannerCount = count($spreadBanner);
  28. $routineSpreadBanner = [];
  29. if ($bannerCount) {
  30. foreach ($spreadBanner as $item) {
  31. $routineSpreadBanner[] = ['pic' => $item];
  32. }
  33. }
  34. $uid = (int)$this->request->uid();
  35. /** @var QrcodeServices $qrcodeService */
  36. $qrcodeService = app()->make(QrcodeServices::class);
  37. if ($this->request->isRoutine()) {
  38. $user = $this->request->user();
  39. $uid = (int)$this->request->uid();
  40. /** @var SystemAttachmentServices $systemAttachment */
  41. $systemAttachment = app()->make(SystemAttachmentServices::class);
  42. //小程序
  43. $name = $user['uid'] . '_' . $user['is_promoter'] . '_user_routine.jpg';
  44. $imageInfo = $systemAttachment->getInfo(['name' => $name]);
  45. //检测远程文件是否存在
  46. if (isset($imageInfo['att_dir']) && strstr($imageInfo['att_dir'], 'http') !== false && curl_file_exist($imageInfo['att_dir']) === false) {
  47. $imageInfo = null;
  48. $systemAttachment->delete(['name' => $name]);
  49. }
  50. $siteUrl = sys_config('site_url');
  51. if (!$imageInfo) {
  52. //生成小程序地址
  53. $qrcode = $qrcodeService->getRoutineQrcode($uid, $name);
  54. } else {
  55. $qrcode = $imageInfo['att_dir'];
  56. if ($imageInfo['image_type'] == 1) $qrcode = $siteUrl . $qrcode;
  57. }
  58. } else {
  59. if (sys_config('share_qrcode', 0) && $this->request->isWechat()) {
  60. if (sys_config('spread_share_forever', 0)) {
  61. $qrcode = $qrcodeService->getForeverQrcode('spread-' . $uid, $uid)->url;
  62. } else {
  63. $qrcode = $qrcodeService->getTemporaryQrcode('spread-' . $uid, $uid)->url;
  64. }
  65. } else {
  66. $qrcode = '';
  67. }
  68. }
  69. return app('json')->success([
  70. 'images' => $routineSpreadBanner,
  71. 'qrcode' => $qrcode,
  72. 'avatar' => $this->request->user('avatar'),
  73. 'nickname' => $this->request->user('nickname'),
  74. 'site_name' => sys_config('site_name')
  75. ]);
  76. }
  77. }