ShareLogic.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\shopapi\logic;
  20. use app\common\{model\User, logic\BaseLogic, enum\ShopPageEnum, service\pay\ToutiaoPayService, service\WeChatService};
  21. use think\Exception;
  22. /**
  23. * 分享逻辑层
  24. * Class ShareLogic
  25. * @package app\shopapi\logic
  26. */
  27. class ShareLogic extends BaseLogic
  28. {
  29. /**
  30. * @notes 获取小程序码
  31. * @param int $userId
  32. * @return array
  33. * @author cjhao
  34. * @date 2021/9/11 16:35
  35. */
  36. public function getMnpQrCode(int $userId,array $params)
  37. {
  38. $id = $params['id'] ?? '';
  39. $user = User::where(['id'=>$userId])->field('id,nickname,code')->find();
  40. $mpParam['scene'] = 'invite_code='.$user['code'];
  41. $mpParam['page'] = $params['page'] ?? '';
  42. if(empty($mpParam['page'])){
  43. $mpParam['page'] = substr(ShopPageEnum::HOME_PAGE['mobile'],1);
  44. }
  45. if($id){
  46. $mpParam['scene'] .= '&id='.$id;
  47. }
  48. $res = WeChatService::makeMpQrCode($mpParam,'base64');
  49. return $res;
  50. }
  51. /**
  52. * @notes 分享砍价小程序码
  53. * @param int $userId
  54. * @param array $params
  55. * @return bool|mixed|string
  56. * @throws \think\db\exception\DataNotFoundException
  57. * @throws \think\db\exception\DbException
  58. * @throws \think\db\exception\ModelNotFoundException
  59. * @author Tab
  60. * @date 2021/9/28 17:28
  61. */
  62. public function getMnpQrCodeInitiate(int $userId,array $params)
  63. {
  64. $param['page'] = substr(ShopPageEnum::HOME_PAGE['mobile'],1);
  65. $param['scene'] = 'initiate_id='.$params['initiate_id'];
  66. $param['page'] = substr(ShopPageEnum::INITIATE['mobile'],1);
  67. $res = WeChatService::makeMpQrCode($param,'base64');
  68. return $res;
  69. }
  70. /**
  71. * @notes 获取今日头条小程序码
  72. * @param int $userId
  73. * @param array $params
  74. * @return bool
  75. * @throws \Exception
  76. * @author cjhao
  77. * @date 2021/11/25 9:59
  78. */
  79. public function getTouTiaoQrcode(int $userId,array $params){
  80. try{
  81. $id = $params['id'] ?? '';
  82. $user = User::where(['id'=>$userId])->field('id,nickname,code')->find();
  83. $mpParam['appname'] = $params['appname'];
  84. $mpParam['page'] = $params['page'] .'?'.'invite_code='.$user['code'].'&id='.$id;
  85. if($id){
  86. $mpParam['page'] .= '&id='.$id;
  87. }
  88. $toutiaoService = (new ToutiaoPayService());
  89. $res = $toutiaoService->getQrcode($mpParam);
  90. self::$returnData = $res;
  91. return true;
  92. }catch (Exception $e){
  93. self::$returnData = $e->getMessage();
  94. return false;
  95. }
  96. }
  97. }