Inviter.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 数据层模型
  10. */
  11. class Inviter extends BaseModel
  12. {
  13. public $page_info;
  14. /**
  15. * 增加帮助
  16. * @access public
  17. * @author csdeshang
  18. * @param type $inviter_array 帮助内容
  19. * @param type $upload_ids 更新ID
  20. * @return type
  21. */
  22. public function addInviter($inviter_array)
  23. {
  24. $inviter_id = Db::name('inviter')->insertGetId($inviter_array);
  25. return $inviter_id;
  26. }
  27. /**
  28. * 修改帮助记录
  29. * @access public
  30. * @author csdeshang
  31. * @param type $condition 条件
  32. * @param type $data 数据
  33. * @return boolean
  34. */
  35. public function editInviter($condition, $data)
  36. {
  37. if (empty($condition)) {
  38. return false;
  39. }
  40. if (is_array($data)) {
  41. $result = Db::name('inviter')->where($condition)->update($data);
  42. return $result;
  43. } else {
  44. return false;
  45. }
  46. }
  47. public function getInviterInfo($condition, $fields = 'm.member_name,i.*')
  48. {
  49. if (empty($condition)) {
  50. return false;
  51. }
  52. $result = Db::name('inviter')->alias('i')->join('member m', 'i.inviter_id=m.member_id')->field($fields)->where($condition)->find();
  53. return $result;
  54. }
  55. /**
  56. * 帮助记录
  57. * @access public
  58. * @author csdeshang
  59. * @param type $condition 条件
  60. * @param type $pagesize 分页
  61. * @param type $limit 限制
  62. * @param type $fields 字段
  63. * @return array
  64. */
  65. public function getInviterList($condition = array(), $pagesize = '', $limit = 0, $fields = '*')
  66. {
  67. if ($pagesize) {
  68. $res = Db::name('inviter')->alias('i')->join('member m', 'i.inviter_id=m.member_id')->field($fields)->where($condition)->order('inviter_applytime desc')->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  69. $this->page_info = $res;
  70. $result = $res->items();
  71. } else {
  72. $result = Db::name('inviter')->alias('i')->join('member m', 'i.inviter_id=m.member_id')->field($fields)->where($condition)->limit($limit)->order('inviter_applytime desc')->select()->toArray();
  73. }
  74. return $result;
  75. }
  76. /**
  77. * 生成微信推荐二维码
  78. * @param type $member_info
  79. * @return type
  80. */
  81. public function qrcode_weixin($member_info)
  82. {
  83. $wx_error_msg = '';
  84. if (!file_exists(BASE_UPLOAD_PATH . '/' . ATTACH_INVITER . '/' . $member_info['member_id'] . '_weixin.png')) {
  85. $config = model('wechat')->getOneWxconfig();
  86. $wechat = new \app\api\controller\WechatApi($config);
  87. $expire_time = $config['expires_in'];
  88. if ($expire_time > TIMESTAMP) {
  89. //有效期内
  90. $wechat->access_token_ = $config['access_token'];
  91. } else {
  92. $access_token = $wechat->checkAuth();
  93. $web_expires = TIMESTAMP + 7000; // 提前200秒过期
  94. Db::name('wxconfig')->where(array('id' => $config['id']))->update(array('access_token' => $access_token, 'expires_in' => $web_expires));
  95. }
  96. $return = $wechat->getQRCode($member_info['member_id'], 1);
  97. if ($return) {
  98. $refer_qrcode_weixin = $wechat->getQRUrl($return['ticket']);
  99. if (!is_dir(BASE_UPLOAD_PATH . '/' . ATTACH_INVITER)) {
  100. mkdir(BASE_UPLOAD_PATH . '/' . ATTACH_INVITER, 0755, true);
  101. }
  102. copy($refer_qrcode_weixin, BASE_UPLOAD_PATH . '/' . ATTACH_INVITER . '/' . $member_info['member_id'] . '_weixin.png');
  103. } else {
  104. $refer_qrcode_weixin = '';
  105. $wx_error_msg = $wechat->errMsg;
  106. }
  107. } else {
  108. $refer_qrcode_weixin = UPLOAD_SITE_URL . '/' . ATTACH_INVITER . '/' . $member_info['member_id'] . '_weixin.png';
  109. }
  110. return array(
  111. 'refer_qrcode_weixin' => $refer_qrcode_weixin,
  112. 'wx_error_msg' => $wx_error_msg,
  113. );
  114. }
  115. /**
  116. * 生成URL推荐二维码
  117. * @param type $member_info
  118. * @return type
  119. */
  120. public function qrcode_logo($member_info)
  121. {
  122. !is_dir(BASE_UPLOAD_PATH . '/' . ATTACH_INVITER) && mkdir(BASE_UPLOAD_PATH . '/' . ATTACH_INVITER, 0755, true);
  123. $qrcode_path = BASE_UPLOAD_PATH . '/' . ATTACH_INVITER . '/' . $member_info['member_id'] . '.png';
  124. $refer_qrcode_logo = BASE_UPLOAD_PATH . '/' . ATTACH_INVITER . '/' . $member_info['member_id'] . '_poster.png';
  125. if (!file_exists($qrcode_path)) {
  126. include_once root_path() . 'extend/qrcode/phpqrcode.php';
  127. \QRcode::png(config('ds_config.h5_site_url') . '/pages/home/memberregister/Register?inviter_id=' . $member_info['member_id'], $qrcode_path);
  128. }
  129. $qrcode = imagecreatefromstring(file_get_contents($qrcode_path));
  130. //背景图片
  131. $inviter_back = imagecreatefromstring(file_get_contents(ds_get_pic(ATTACH_COMMON, config('ds_config.inviter_back'))));
  132. $QR_width = imagesx($qrcode);
  133. $QR_height = imagesy($qrcode);
  134. imagecopyresampled($inviter_back, $qrcode, 100, 170, 0, 0, 160, 160, $QR_width, $QR_height);
  135. $portrait = imagecreatefromstring(file_get_contents(get_member_avatar_for_id($member_info['member_id'])));
  136. $QR_width2 = imagesx($portrait);
  137. $QR_height2 = imagesy($portrait);
  138. imagecopyresampled($inviter_back, $portrait, 170, 240, 0, 0, 20, 20, $QR_width2, $QR_height2);
  139. //此处是给图片载入文字
  140. /*
  141. $text = $member_info['member_id'];
  142. $textcolor = imagecolorallocate($inviter_back, 255, 50, 37);
  143. $text_x = 180-(strlen($text)*12)/2;//根据长度定义X轴
  144. imagefttext($inviter_back, 16, 0, $text_x, 145, $textcolor, PUBLIC_PATH . '/font/msyh.ttf', mb_convert_encoding($text, "html-entities", "utf-8"));
  145. */
  146. imagepng($inviter_back, $refer_qrcode_logo);
  147. }
  148. }