Ver Fonte

用户海报

lizhen_gitee há 1 ano atrás
pai
commit
de1bea8707

+ 79 - 0
addons/poster/library/Image.php

@@ -95,6 +95,85 @@ class Image
         $posterLog->save($params);
         return $this->poster_url;
     }
+    /**
+     * 创建海报
+     * @author Created by Xing <464401240@qq.com>
+     */
+    public function createPosterImage_user($poster, $member)
+    {
+        $path = $this->model->getDirs($poster['id']);
+        if (!is_dir($path)) {
+            $this->mkdirs($path);
+        }
+        $md5 = md5(json_encode(array(
+            'user_id'   => $member['id'],
+            'bg'        => $poster['bg_image'],
+            'data'      => $poster['data'],
+            'poster_id' => $poster['id']
+        )));
+        $file = $md5 . '.png';
+        $this->poster_url = $path . $file;
+        if (is_file($this->poster_url)) {
+            //return $this->poster_url; //文件存在则直接返回
+        }
+
+        set_time_limit(0);
+        @ini_set('memory_limit', '256M');
+        $this->target = imagecreatetruecolor(633, 926);
+
+        $white = imagecolorallocate($this->target, 255, 255, 255);
+        imagefill($this->target, 0, 0, $white);
+        $bg = $this->createImage($poster['bg_image']);
+        if (!empty($bg)) {
+            $bgWidth = imagesx($bg);
+            $bgHeight = imagesy($bg);
+            $ratio = 640 / $bgWidth;
+            $newWidth = imagesx($bg) * $ratio;
+            $newHeight = imagesy($bg) * $ratio;
+
+            $bgClone = imagecreatetruecolor($newWidth, $newHeight);
+            imagecopyresampled($bgClone, $bg, 0, 0, 0, 0, $newWidth, $newHeight, $bgWidth, $bgHeight);
+
+            imagecopy($this->target, $bgClone, 0, 0, 0, 0, $newWidth, $newHeight);
+
+            imagedestroy($bg);
+            imagedestroy($bgClone);
+        }
+        $data = json_decode(str_replace('&quot;', '\'', $poster['data']), true);
+
+        foreach ($data as $d) {
+            $d = $this->getRealData($d);
+            if ($d['type'] == 'head') {
+                $avatar = preg_replace('/\\/0$/i', '/96', $member['avatar']);
+                $this->mergeImage($d, $avatar);
+            } elseif ($d['type'] == 'img' && isset($d['src'])) {
+                $this->mergeImage($d, $d['src']);
+            } elseif ($d['type'] == 'qr' && isset($d['qr_table']) && isset($d['qr_relation']) && isset($d['qr_field'])) {
+                $exist = Db::query('show tables like "' . $d['qr_table'] . '"');
+                if ($exist) {
+                    $fields = Db::getConnection()->getFields($d['qr_table']); //传入数据表名称 $tablename
+                    if (isset($fields[$d['qr_relation']])) {
+                        $qrimg = Db::table($d['qr_table'])->where([$d['qr_relation'] => $member['id']])->value($d['qr_field']);
+                        $this->mergeImage($d, $qrimg);
+                    }
+                }
+            } elseif ($d['type'] == 'nickname') {
+//                $this->mergeText($d, $member['nickname']);
+                $this->mergeText($d, $d['content']);
+            }
+        }
+
+        header("Content-Type:image/png");
+        imagepng($this->target, $path . $file);
+        imagedestroy($this->target);
+
+        $params['poster_id'] = $poster['id'];
+        $params['user_id'] = $member['id'];
+        $params['image'] = $this->poster_url;
+        $posterLog = new \app\admin\model\PosterLog();
+        $posterLog->save($params);
+        return $this->poster_url;
+    }
 
     public function mergeImage($data, $imgurl)
     {

+ 179 - 0
application/api/controller/Money.php

@@ -0,0 +1,179 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+
+/**
+ * 会员中心
+ */
+class Money extends Api
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = '*';
+
+    //提现账号添加
+    public function bankadd() {
+        $realname = input('realname', '', 'trim'); //账户真实姓名
+        $banknumber = input('banknumber', '', 'trim'); //卡号或账号
+        $bankname = input('bankname', '', 'trim'); //银行名称
+
+
+        if ($realname === '' || iconv_strlen($realname, 'utf-8') > 30) {
+            $this->error('账号姓名1-30位');
+        }
+        if ($banknumber === '' || iconv_strlen($banknumber, 'utf-8') > 50) {
+            $this->error('账号1-50位');
+        }
+        if ($bankname === '' || iconv_strlen($bankname, 'utf-8') > 50) {
+            $this->error('银行名称1-50位');
+        }
+
+        //添加
+        $count = Db::name('user_bank')->where(['user_id' => $this->auth->id])->count('id');
+        if ($count) {
+            $this->error('您已经拥有该类型账号,不能再添加');
+        }
+
+        $data['user_id'] = $this->auth->id;
+        $data['realname'] = $realname;
+        $data['banknumber'] = $banknumber;
+        $data['bankname'] = $bankname;
+        $data['createtime'] = time();
+
+        $rs = Db::name('user_bank')->insertGetId($data);
+        if (!$rs) {
+            $this->error('添加失败');
+        }
+
+        $this->success('添加成功');
+    }
+
+    //提现账号编辑
+    public function bankedit(){
+        $id = input('id', 0, 'intval'); //账号id
+        $realname = input('realname', '', 'trim'); //账户真实姓名
+        $banknumber = input('banknumber', '', 'trim'); //卡号或账号
+        $bankname = input('bankname', '', 'trim'); //银行名称
+
+
+        if ($realname === '' || iconv_strlen($realname, 'utf-8') > 30) {
+            $this->error('账号姓名1-30位');
+        }
+        if ($banknumber === '' || iconv_strlen($banknumber, 'utf-8') > 50) {
+            $this->error('账号1-50位');
+        }
+        if ($bankname === '' || iconv_strlen($bankname, 'utf-8') > 50) {
+            $this->error('银行名称1-50位');
+        }
+
+        //查询账号是否存在
+        $info = Db::name('user_bank')->where(['id' => $id, 'user_id' => $this->auth->id])->find();
+        if (!$info) {
+            $this->error('账号不存在');
+        }
+
+        $data['realname'] = $realname;
+        $data['banknumber'] = $banknumber;
+        $data['bankname'] = $bankname;
+        $data['updatetime'] = time();
+
+        $rs = Db::name('user_bank')->where(['id' => $id])->update($data);
+        if ($rs === false) {
+            $this->error('修改失败');
+        }
+
+        $this->success('修改成功');
+    }
+
+    //提现账号信息
+    public function bankinfo() {
+
+        $info = Db::name('user_bank')->where(['user_id' => $this->auth->id])->find();
+        if (!$info) {
+            $info = (object)[];
+        }
+
+        $this->success('账户信息', $info);
+    }
+
+    //提现
+    public function moneywithdraw() {
+        $id = input('id', 0, 'intval'); //提现账号id
+        $money = input('money', '', 'trim');
+        if (!$id) {
+            $this->error('请选择提现账号');
+        }
+        $bankinfo = Db::name('user_bank')->where(['id' => $id, 'user_id' => $this->auth->id])->find();
+        if (!$bankinfo) {
+            $this->error('账号不存在');
+        }
+        if (!preg_match('/^[0-9]+(.[0-9]{1,8})?$/', $money) || $money <= 0) {
+            $this->error('请输入正确提现金额');
+        }
+
+        //余额查询
+        $user_money = model('wallet')->getWallet($this->auth->id,'money');
+        if ($user_money < $money) {
+            $this->error('余额不足');
+        }
+
+        //查询最低最高提现金额
+        $min_withdrawal_money = config('site.min_withdrawal_money') ? config('site.min_withdrawal_money') : 1;
+        $max_withdrawal_money = config('site.max_withdrawal_money') ? config('site.max_withdrawal_money') : 50000;
+        if ($money < $min_withdrawal_money) {
+            $this->error('最低提现金额' . $min_withdrawal_money . '元');
+        }
+        if ($money > $max_withdrawal_money) {
+            $this->error('最高提现金额' . $max_withdrawal_money . '元');
+        }
+
+        //查询提现手续费百分比
+        $withdrawal_service_fee = (int)config('site.withdrawal_service_fee') ? : 0;
+        if ($withdrawal_service_fee < 0 || $withdrawal_service_fee >= 100) {
+            $this->error('提现手续费异常');
+        }
+
+        $real_money = bcdiv(bcmul($money,bcsub(100,$withdrawal_service_fee)),100);
+
+        $data['order_no'] = createUniqueNo('T',$this->auth->id);
+        $data['user_id'] = $this->auth->id;
+        $data['amount'] = $money;
+        $data['money'] = $real_money;
+        $data['user_bank_id'] = $id;
+        $data['realname'] = $bankinfo['realname'];
+        $data['banknumber'] = $bankinfo['banknumber'];
+        $data['bankname'] = $bankinfo['bankname'];
+        $data['status'] = 0;
+        $data['createtime'] = time();
+
+        //开启事务
+        Db::startTrans();
+        //添加提现记录
+        $log_id = Db::name('user_withdraw')->insertGetId($data);
+        if (!$log_id) {
+            Db::rollback();
+            $this->error('申请提现失败');
+        }
+
+        $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,'money',$money,4,'提现','user_withdraw',$log_id);
+        if ($rs_wallet['status'] == false) {
+            $this->error($rs_wallet['msg']);
+            Db::rollback();
+        }
+
+        Db::commit();
+        $this->success('申请提现成功,请等待审核');
+    }
+
+    //用户钱包流水
+    public function moneylog(){
+        $list = Db::name('user_money_log')->field('id,change_value,log_type,createtime')->where('user_id',$this->auth->id)->page($this->page,$this->listrow)->select();
+        foreach($list as $key => &$val){
+            $val['log_type_text'] = model('wallet')->getlogtype($val['log_type']);
+        }
+
+        $this->success('success',$list);
+    }
+}

+ 64 - 148
application/api/controller/Usercenter.php

@@ -13,167 +13,83 @@ class Usercenter extends Api
     protected $noNeedLogin = [];
     protected $noNeedRight = '*';
 
-    //提现账号添加
-    public function bankadd() {
-        $realname = input('realname', '', 'trim'); //账户真实姓名
-        $banknumber = input('banknumber', '', 'trim'); //卡号或账号
-        $bankname = input('bankname', '', 'trim'); //银行名称
-
-
-        if ($realname === '' || iconv_strlen($realname, 'utf-8') > 30) {
-            $this->error('账号姓名1-30位');
-        }
-        if ($banknumber === '' || iconv_strlen($banknumber, 'utf-8') > 50) {
-            $this->error('账号1-50位');
-        }
-        if ($bankname === '' || iconv_strlen($bankname, 'utf-8') > 50) {
-            $this->error('银行名称1-50位');
-        }
-
-        //添加
-        $count = Db::name('user_bank')->where(['user_id' => $this->auth->id])->count('id');
-        if ($count) {
-            $this->error('您已经拥有该类型账号,不能再添加');
-        }
-
-        $data['user_id'] = $this->auth->id;
-        $data['realname'] = $realname;
-        $data['banknumber'] = $banknumber;
-        $data['bankname'] = $bankname;
-        $data['createtime'] = time();
-
-        $rs = Db::name('user_bank')->insertGetId($data);
-        if (!$rs) {
-            $this->error('添加失败');
-        }
-
-        $this->success('添加成功');
+    //生成我的视频海报
+    //生成邀请码二维码图片
+    public function inviteimage($introcode) {
+        $params['text'] = config('h5_url') . '/#/pages/home/index?introcode=' . $introcode;
+        $qrcode_service = \addons\qrcode\library\Service::qrcode($params);
+//        $mimetype = 'image/png';
+//        $response = Response::create()->header("Content-Type", $mimetype);
+
+        // 直接显示二维码
+//        header('Content-Type: ' . $qrcode_service->getContentType());
+//        $response->content($qrcode_service->writeString());
+        $qrcodePath = ROOT_PATH . 'public/uploads/qrcode/';
+        if (!is_dir($qrcodePath)) {
+            @mkdir($qrcodePath);
+        }
+        if (is_really_writable($qrcodePath)) {
+            $filename = md5(implode('', $params)) . '.png';
+            $filePath = $qrcodePath . $filename;
+            $qrcode_service->writeFile($filePath);
+        }
+
+        return '/uploads/qrcode/' . $filename;
     }
 
-    //提现账号编辑
-    public function bankedit(){
-        $id = input('id', 0, 'intval'); //账号id
-        $realname = input('realname', '', 'trim'); //账户真实姓名
-        $banknumber = input('banknumber', '', 'trim'); //卡号或账号
-        $bankname = input('bankname', '', 'trim'); //银行名称
-
-
-        if ($realname === '' || iconv_strlen($realname, 'utf-8') > 30) {
-            $this->error('账号姓名1-30位');
-        }
-        if ($banknumber === '' || iconv_strlen($banknumber, 'utf-8') > 50) {
-            $this->error('账号1-50位');
-        }
-        if ($bankname === '' || iconv_strlen($bankname, 'utf-8') > 50) {
-            $this->error('银行名称1-50位');
-        }
-
-        //查询账号是否存在
-        $info = Db::name('user_bank')->where(['id' => $id, 'user_id' => $this->auth->id])->find();
-        if (!$info) {
-            $this->error('账号不存在');
-        }
-
-        $data['realname'] = $realname;
-        $data['banknumber'] = $banknumber;
-        $data['bankname'] = $bankname;
-        $data['updatetime'] = time();
+    //生成视频分享海报
+    public function shareposter() {
 
-        $rs = Db::name('user_bank')->where(['id' => $id])->update($data);
-        if ($rs === false) {
-            $this->error('修改失败');
-        }
+        $inviteimage = $this->inviteimage($this->auth->introcode);
 
-        $this->success('修改成功');
-    }
+        $data = [
 
-    //提现账号信息
-    public function bankinfo() {
-
-        $info = Db::name('user_bank')->where(['user_id' => $this->auth->id])->find();
-        if (!$info) {
-            $info = (object)[];
-        }
+            [
+                "left"=> "100px",
+                "top"=> "424px",
+                "type"=> "nickname",
+                "width"=> "166px",
+                "height"=> "38px",
+                "size"=> "11px",
+                "color"=> "#333333",
+                "content" => '邀请码:'.$this->auth->introcode,
+            ],
+            [
+                "left"=> "90px",
+                "top"=> "260px",
+                "type"=> "img",
+                "width"=> "140px",
+                "height"=> "140px",
+                "src"=> httpurllocal($inviteimage)//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
+            ],
 
-        $this->success('账户信息', $info);
-    }
-
-    //提现
-    public function moneywithdraw() {
-        $id = input('id', 0, 'intval'); //提现账号id
-        $money = input('money', '', 'trim');
-        if (!$id) {
-            $this->error('请选择提现账号');
-        }
-        $bankinfo = Db::name('user_bank')->where(['id' => $id, 'user_id' => $this->auth->id])->find();
-        if (!$bankinfo) {
-            $this->error('账号不存在');
-        }
-        if (!preg_match('/^[0-9]+(.[0-9]{1,8})?$/', $money) || $money <= 0) {
-            $this->error('请输入正确提现金额');
-        }
+        ];
 
-        //余额查询
-        $user_money = model('wallet')->getWallet($this->auth->id,'money');
-        if ($user_money < $money) {
-            $this->error('余额不足');
-        }
 
-        //查询最低最高提现金额
-        $min_withdrawal_money = config('site.min_withdrawal_money') ? config('site.min_withdrawal_money') : 1;
-        $max_withdrawal_money = config('site.max_withdrawal_money') ? config('site.max_withdrawal_money') : 50000;
-        if ($money < $min_withdrawal_money) {
-            $this->error('最低提现金额' . $min_withdrawal_money . '元');
-        }
-        if ($money > $max_withdrawal_money) {
-            $this->error('最高提现金额' . $max_withdrawal_money . '元');
-        }
+        $data = json_encode($data, 320);
 
-        //查询提现手续费百分比
-        $withdrawal_service_fee = (int)config('site.withdrawal_service_fee') ? : 0;
-        if ($withdrawal_service_fee < 0 || $withdrawal_service_fee >= 100) {
-            $this->error('提现手续费异常');
-        }
+        $poster = [
+            'id' => 1,
+            'title' => '测试',
+            'waittext' => '您的专属海报正在拼命生成中,请等待片刻...',
+            'bg_image' => '/assets/img/posteruserbg.png',
+            'data' => $data,
+            'status' => 'normal',
+            'weigh' => 0,
+            'createtime' => 1653993709,
+            'updatetime' => 1653994259,
+        ];
 
-        $real_money = bcdiv(bcmul($money,bcsub(100,$withdrawal_service_fee)),100);
-
-        $data['order_no'] = createUniqueNo('T',$this->auth->id);
-        $data['user_id'] = $this->auth->id;
-        $data['amount'] = $money;
-        $data['money'] = $real_money;
-        $data['user_bank_id'] = $id;
-        $data['realname'] = $bankinfo['realname'];
-        $data['banknumber'] = $bankinfo['banknumber'];
-        $data['bankname'] = $bankinfo['bankname'];
-        $data['status'] = 0;
-        $data['createtime'] = time();
-
-        //开启事务
-        Db::startTrans();
-        //添加提现记录
-        $log_id = Db::name('user_withdraw')->insertGetId($data);
-        if (!$log_id) {
-            Db::rollback();
-            $this->error('申请提现失败');
-        }
+        $image = new \addons\poster\library\Image();
+        $imgurl = $image->createPosterImage_user($poster, $this->auth->getUser());
 
-        $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,'money',$money,4,'提现','user_withdraw',$log_id);
-        if ($rs_wallet['status'] == false) {
-            $this->error($rs_wallet['msg']);
-            Db::rollback();
+        if (!$imgurl) {
+            $this->error('生成海报出错');
         }
+        $imgurl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"] . '/' . $imgurl;
 
-        Db::commit();
-        $this->success('申请提现成功,请等待审核');
-    }
-
-    //用户钱包流水
-    public function moneylog(){
-        $list = Db::name('user_money_log')->field('id,change_value,log_type,createtime')->where('user_id',$this->auth->id)->page($this->page,$this->listrow)->select();
-        foreach($list as $key => &$val){
-            $val['log_type_text'] = model('wallet')->getlogtype($val['log_type']);
-        }
+        //echo '<html><body><img src="'.$imgurl.'"></body></html>';
 
-        $this->success('success',$list);
+        $this->success('', $imgurl);
     }
 }

BIN
public/assets/img/posteruserbg.png