Cards.php 5.5 KB
<?php
/**
 * Created by PhpStorm.
 * User: 86132
 * Date: 2020/11/19
 * Time: 8:35
 */

namespace app\api\controller;

use EasyWeChat\Foundation\Application;
use app\common\controller\Api;
use think\Db;

/**
 * 海报分享接口
 */
class Cards extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];


    /**
     * 海报分享接口
     * @ApiTitle    (转发好友)
     * @ApiSummary  (转发好友)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Cards/MiniAppOtherFriend)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="Goods_id", type="integer", required=true, description="商品ID")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    "data":
    })
     */
    public function MiniAppOtherFriend()
    {
        $UserId = $this->is_token($this->request->header());
        $params = $this->request->param();
        $GoodsArray = Db::name('goods')->where('id', $params['Goods_id'])->find();
        if (empty($GoodsArray)) {
            $this->error('分享错误', 0);
            die;
        }
        $data = [
            'Goods_id' => $GoodsArray['id'],
            'User_id' => $UserId,
            'Title' => $GoodsArray['title'],
            'Image' => cdnurl($GoodsArray['image']),
        ];
        $this->success('成功', $data);
    }


    /**
     * 海报分享接口
     * @ApiTitle    (商品详情生成海报)
     * @ApiSummary  (商品详情生成海报)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Cards/GoodsConNewsPaper)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="Goods_id", type="integer", required=true, description="商品ID")
     * @ApiParams   (name="path", type="integer", required=true, description="路径")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    "data":
    })
     */
    public function GoodsConNewsPaper()
    {
        $UserId = $this->is_token($this->request->header());
        $params = $this->request->param();
        $GoodsArray = Db::name('goods')->where('id', $params['Goods_id'])->find();
        if (empty($GoodsArray)) {
            $this->error('分享错误', 0);
            die;
        }
        $UserInfo = Db::name('user')->where('id', $UserId)->find();
        //小程序码
        $MiniAppQrcodeUrl = $this->InserMiniAppQrCode($GoodsArray['id'], $UserId, $params['path']);
        $data = [
            'Avatar' => $UserInfo['avatar'],
            'Nickname' => $UserInfo['nickname'],
            'Goods_id' => $GoodsArray['id'],
            'User_id' => $UserId,
            'Title' => $GoodsArray['title'],
            'Price' => $GoodsArray['price'],
            'DeletePrice' => $GoodsArray['delete_price'],
            'Image' => cdnurl($GoodsArray['image']),
            'MiniAppQrcodeUrl' => $MiniAppQrcodeUrl
        ];
        $this->success('成功', $data);
    }


    /**
     * 海报分享接口
     * @ApiTitle    (邀请好友/测试题/名片海报)
     * @ApiSummary  (邀请好友/测试题/名片海报)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Cards/CardsPaper)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="path", type="integer", required=true, description="路径")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    "data":
    })
     */
    public function CardsPaper()
    {
        $UserId = $this->is_token($this->request->header());
        $params = $this->request->param();
        $UserInfo = Db::name('user')->where('id', $UserId)->find();
//        $is_invite_code = './MiniAppQrCode/' . $UserId . '.png';
//        if (file_exists($is_invite_code) == true) {
//            $MiniAppQrcodeUrl = $this->request->domain() . '/MiniAppQrCode/' . $UserId . '.png';
//        } else {
            //小程序码
//            $MiniAppQrcodeUrl = $this->UserInserMiniAppQrCode($UserId, $params['path']);
//        }
        $MiniAppQrcodeUrl = $this->InserMiniAppQrCode(0, $UserId, $params['path']);
        $data = [
            'Avatar' => $UserInfo['avatar'],
            'Nickname' => $UserInfo['nickname'],
            'User_id' => $UserId,
            'MiniAppQrcodeUrl' => $MiniAppQrcodeUrl
        ];
        $this->success('成功', $data);
    }


    /**
     * 海报分享接口
     * @ApiTitle    (分享)
     * @ApiSummary  (分享))
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Cards/MiniAppFriends)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    "data":
    })
     */
    public function MiniAppFriends()
    {
        $Array = Db::name('miniappfriends')->where('id', 1)->find();
        $data = [
            'Title' => $Array['title'],
            'Image' => cdnurl($Array['image']),
        ];
        $this->success('成功', $data);
    }
}