User.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace app\admin\controller\user;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. use app\common\library\Wechat;
  6. /**
  7. * 会员管理
  8. *
  9. * @icon fa fa-user
  10. */
  11. class User extends Backend
  12. {
  13. /**
  14. * User模型对象
  15. * @var \app\admin\model\User
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new \app\admin\model\User;
  22. $this->view->assign("statusList", $this->model->getStatusList());
  23. }
  24. /**
  25. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  26. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  27. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  28. */
  29. /**
  30. * 查看
  31. */
  32. public function index()
  33. {
  34. //当前是否为关联查询
  35. $this->relationSearch = true;
  36. //设置过滤方法
  37. $this->request->filter(['strip_tags', 'trim']);
  38. if ($this->request->isAjax()) {
  39. //如果发送的来源是Selectpage,则转发到Selectpage
  40. if ($this->request->request('keyField')) {
  41. return $this->selectpage();
  42. }
  43. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  44. $list = $this->model
  45. ->with(['group'])
  46. ->where($where)
  47. ->order($sort, $order)
  48. ->paginate($limit);
  49. foreach ($list as $row) {
  50. $row->getRelation('group')->visible(['name']);
  51. }
  52. $result = array("total" => $list->total(), "rows" => $list->items());
  53. return json($result);
  54. }
  55. return $this->view->fetch();
  56. }
  57. /**
  58. * 地推码
  59. */
  60. public function dtqrcode(){
  61. $id = input('id',0);
  62. $row = Db::name('user')->where('id',$id)->find();
  63. $site = 'home';
  64. $product_id = '';
  65. $codeurl = '';
  66. if(request()->isPost()){
  67. $site = input('site','home');
  68. if($site == 'home'){
  69. $page = 'pages/home/home';
  70. $scene = 'share_uid='.$id;
  71. $product_id = '';
  72. }
  73. if($site == 'product'){
  74. $page = 'pages/home/detail';
  75. $product_id = input('product_id',0);
  76. $scene = 'id='.$product_id.'&share_uid='.$id;
  77. }
  78. $codeurl = $this->getMiniCode($page,$scene);
  79. $codeurl = $codeurl.'?v='.time();
  80. }
  81. $this->view->assign('chosesite', $site);
  82. $this->view->assign('product_id', $product_id);
  83. $this->view->assign('codeurl', $codeurl);
  84. $this->view->assign('row', $row);
  85. return $this->view->fetch();
  86. }
  87. //仅返回套餐二维码
  88. //https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/qrcode-link/qr-code/getUnlimitedQRCode.html
  89. private function getMiniCode($page,$scene)
  90. {
  91. $httpStr = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'];
  92. //if (empty($package) || empty($package['mini_code'])) {
  93. $wechat_config = config('wxMiniProgram');
  94. $wechat = new Wechat($wechat_config['appid'],$wechat_config['secret']);
  95. $tk = $wechat->getPublicAccessToken();
  96. $miniCodeConfig = config('mini_code');
  97. $miniCodeConfig['scene'] = $scene;
  98. $miniCodeConfig['page'] = $page;
  99. $res2 = curl_post('https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token='.$tk,json_encode($miniCodeConfig));
  100. $fileName = md5($scene);
  101. $fileUrl = '/uploads/product/'.$fileName.'.png';
  102. $code = $res2;
  103. file_put_contents(ROOT_PATH.'/public'.$fileUrl,$code);
  104. $miniCode = $httpStr.$fileUrl;
  105. /*} else {
  106. $miniCode = $httpStr.$package['mini_code'];
  107. }*/
  108. return $miniCode;
  109. }
  110. }