Inviter.php 6.5 KB

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