Inviter.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 数据层模型
  15. */
  16. class Inviter extends BaseModel {
  17. public $page_info;
  18. /**
  19. * 增加帮助
  20. * @access public
  21. * @author csdeshang
  22. * @param type $inviter_array 帮助内容
  23. * @param type $upload_ids 更新ID
  24. * @return type
  25. */
  26. public function addInviter($inviter_array) {
  27. $inviter_id = Db::name('inviter')->insertGetId($inviter_array);
  28. return $inviter_id;
  29. }
  30. /**
  31. * 修改帮助记录
  32. * @access public
  33. * @author csdeshang
  34. * @param type $condition 条件
  35. * @param type $data 数据
  36. * @return boolean
  37. */
  38. public function editInviter($condition, $data) {
  39. if (empty($condition)) {
  40. return false;
  41. }
  42. if (is_array($data)) {
  43. $result = Db::name('inviter')->where($condition)->update($data);
  44. return $result;
  45. } else {
  46. return false;
  47. }
  48. }
  49. public function getInviterInfo($condition,$fields = 'm.member_name,i.*'){
  50. if (empty($condition)) {
  51. return false;
  52. }
  53. $result = Db::name('inviter')->alias('i')->join('member m', 'i.inviter_id=m.member_id')->field($fields)->where($condition)->find();
  54. return $result;
  55. }
  56. /**
  57. * 帮助记录
  58. * @access public
  59. * @author csdeshang
  60. * @param type $condition 条件
  61. * @param type $pagesize 分页
  62. * @param type $limit 限制
  63. * @param type $fields 字段
  64. * @return array
  65. */
  66. public function getInviterList($condition = array(), $pagesize = '', $limit = 0, $fields = '*') {
  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. $wx_error_msg = '';
  83. if(!file_exists(BASE_UPLOAD_PATH . '/' . ATTACH_INVITER . '/' . $member_info['member_id'] . '_weixin.png')){
  84. $config = model('wechat')->getOneWxconfig();
  85. $wechat=new \app\api\controller\WechatApi($config);
  86. $expire_time = $config['expires_in'];
  87. if($expire_time > TIMESTAMP){
  88. //有效期内
  89. $wechat->access_token_= $config['access_token'];
  90. }else{
  91. $access_token=$wechat->checkAuth();
  92. $web_expires = TIMESTAMP + 7000; // 提前200秒过期
  93. Db::name('wxconfig')->where(array('id'=>$config['id']))->update(array('access_token'=>$access_token,'expires_in'=>$web_expires));
  94. }
  95. $return=$wechat->getQRCode($member_info['member_id'], 1);
  96. if($return){
  97. $refer_qrcode_weixin=$wechat->getQRUrl($return['ticket']);
  98. if (!is_dir(BASE_UPLOAD_PATH . '/' . ATTACH_INVITER)) {
  99. mkdir(BASE_UPLOAD_PATH . '/' . ATTACH_INVITER, 0755, true);
  100. }
  101. copy($refer_qrcode_weixin,BASE_UPLOAD_PATH . '/' . ATTACH_INVITER . '/' . $member_info['member_id'] . '_weixin.png');
  102. }else{
  103. $refer_qrcode_weixin = '';
  104. $wx_error_msg = $wechat->errMsg;
  105. }
  106. }else{
  107. $refer_qrcode_weixin=UPLOAD_SITE_URL. '/' . ATTACH_INVITER . '/' . $member_info['member_id'] . '_weixin.png';
  108. }
  109. return array(
  110. 'refer_qrcode_weixin' =>$refer_qrcode_weixin,
  111. 'wx_error_msg'=>$wx_error_msg,
  112. );
  113. }
  114. /**
  115. * 生成URL推荐二维码
  116. * @param type $member_info
  117. * @return type
  118. */
  119. public function qrcode_logo($member_info){
  120. !is_dir(BASE_UPLOAD_PATH . '/' . ATTACH_INVITER) && mkdir(BASE_UPLOAD_PATH . '/' . ATTACH_INVITER, 0755, true);
  121. $qrcode_path = BASE_UPLOAD_PATH . '/' . ATTACH_INVITER . '/' . $member_info['member_id'] . '.png';
  122. $refer_qrcode_logo = BASE_UPLOAD_PATH . '/' . ATTACH_INVITER . '/' . $member_info['member_id'] . '_poster.png';
  123. if (!file_exists($qrcode_path)) {
  124. include_once root_path(). 'extend/qrcode/phpqrcode.php';
  125. \QRcode::png(config('ds_config.h5_site_url') . '/pages/home/memberregister/Register?inviter_id=' . $member_info['member_id'], $qrcode_path);
  126. }
  127. $qrcode = imagecreatefromstring(file_get_contents($qrcode_path));
  128. //背景图片
  129. $inviter_back = imagecreatefromstring(file_get_contents(ds_get_pic(ATTACH_COMMON,config('ds_config.inviter_back'))));
  130. $QR_width = imagesx($qrcode);
  131. $QR_height = imagesy($qrcode);
  132. imagecopyresampled($inviter_back, $qrcode, 100, 170, 0, 0, 160, 160, $QR_width, $QR_height);
  133. $portrait = imagecreatefromstring(file_get_contents(get_member_avatar_for_id($member_info['member_id'])));
  134. $QR_width2 = imagesx($portrait);
  135. $QR_height2 = imagesy($portrait);
  136. imagecopyresampled($inviter_back, $portrait, 170, 240, 0, 0, 20, 20, $QR_width2, $QR_height2);
  137. //此处是给图片载入文字
  138. /*
  139. $text = $member_info['member_id'];
  140. $textcolor = imagecolorallocate($inviter_back, 255, 50, 37);
  141. $text_x = 180-(strlen($text)*12)/2;//根据长度定义X轴
  142. imagefttext($inviter_back, 16, 0, $text_x, 145, $textcolor, PUBLIC_PATH . '/font/msyh.ttf', mb_convert_encoding($text, "html-entities", "utf-8"));
  143. */
  144. imagepng($inviter_back, $refer_qrcode_logo);
  145. }
  146. }