PortalController.php 8.8 KB
<?php
namespace api\portal\controller;
use think\Controller;
use think\Db;
use PHPExcel;

/**
 * @title  前台补充
 * @description 前台补充接口
 */
class PortalController extends Controller
{
    /**
 * @title 营销下单
 * @description
 * @author panhaowen
 * @url /portal/portal/marketOrderAdd
 * @param name:id type:int require:1 desc:营销id
 * @param name:file type:varchar require:1 desc:上传文件
 * @param name:money type:int require:1 desc:订单金额
 * @method POST
 */
    public function marketOrderAdd()
    {
        $param=$this->request->param();
        $user=$this->getUser();
        if ($user['money']<$param['money']){
            $this->error('账号余额不足');
        }
        foreach ($param['id'] as $v){
            $money=Db::name('market_business')->where('id',$v);
            Db::name('market_order')->insert(['market_business_id'=>$v,'create_time'=>time(),'order_sn'=>cmf_get_order_sn(),'more'=>$param['file'],'money'=>$money,'user_id'=>$user['id']]);
        }
        Db::name('user')->where('id',$user['id'])->setDec('money',$param['money']);
        Db::name('money_log')->insert(['type'=>3,'create_time'=>time(),'user_id'=>$user['id'],'money'=>$param['money'],'now_money'=>($user['money']-$param['money'])]);
        $this->success('操作成功');
    }

    /**
     * @title 新媒体下单
     * @description
     * @author panhaowen
     * @url /portal/portal/businessOrderAdd
     * @param name:business_id type:int require:1 desc:新媒体id
     * @param name:count type:varchar require:1 desc:购买数量
     * @param name:money type:int require:1 desc:订单金额
     * @param name:post_url type:varchar require:0 desc:文章地址
     * @param name:more type:varchar require:0 desc:文件上传
     * @param name:content   type:varchar require:0 desc:备注
     * @param name:liuyan type:varchar require:0 desc:留言
     * @method POST
     */
    public function businessOrderAdd()
    {
        $param=$this->request->param();
        $user=$this->getUser();
        if ($user['money']<$param['money']){
            $this->error('账号余额不足');
        }
        $param['create_time']=time();
        $param['create_time']=cmf_get_order_sn();
        $param['user_id']=$user['id'];
        Db::name('business_order')->insert($param);
        Db::name('user')->where('id',$user['id'])->setDec('money',$param['money']);
        Db::name('money_log')->insert(['type'=>2,'create_time'=>time(),'user_id'=>$user['id'],'money'=>$param['money'],'now_money'=>($user['money']-$param['money'])]);
        $this->success('操作成功');
    }

    /**
     * @title 订单列表种类
     * @description
     * @author panhaowen
     * @url /portal/portal/Order
     * @method POST
     */
    public function Order()
    {
        $data=Db::name('category')->select();
        $this->success('获取信息成功',$data);
    }


    /**
     * @title 营销订单查看(审核中),营销订单修改
     * @description
     * @author panhaowen
     * @url /portal/portal/MarketOrder1
     * @method POST
     * @param name:id type:int require:1 desc:营销订单id
     */
    public function MarketOrder1()
    {
        $param=$this->request->param();
        $data=cmf_get_file_download_url(Db::name('market_order')->where('id',$param['id'])->find()['more']);
        $this->success('获取信息成功',$data);
    }

    /**
     * @title 营销订单查看(已发布)
     * @description
     * @author panhaowen
     * @url /portal/portal/MarketOrder2
     * @method POST
     * @param name:id type:int require:1 desc:营销订单id
     */
    public function MarketOrder2()
    {
        $param=$this->request->param();
        $data=Db::name('market_order')->where('id',$param['id'])->find();
        if ($data['url']!=null) {
            $this->success('获取信息成功', $data['url']);
        }
        $this->success('获取信息成功', cmf_get_file_download_url($data['remark']));
    }


    /**
     * @title 营销订单重投
     * @description
     * @author panhaowen
     * @url /portal/portal/MarketOrderRe
     * @method POST
     * @param name:id type:int require:1 desc:营销订单id
     * @param name:file type:varchar require:1 desc:文件上传
     */
    public function MarketOrderRe()
    {
        $param=$this->request->param();
        $user=$this->getUser();
        $order=Db::name('market_order')->where('id',$param['id'])->find();
        if ($user['money']<$order['money']){
            $this->error('账户余额不足');
        }
        Db::name('market_order')->insert(['market_business_id'=>$order['market_business_id'],'create_time'=>time(),'order_sn'=>cmf_get_order_sn(),'more'=>$param['file'],'money'=>$order['money'],'user_id'=>$user['id']]);
        Db::name('user')->where('id',$user['id'])->setDec('money',$order['money']);
        Db::name('money_log')->insert(['type'=>3,'create_time'=>time(),'user_id'=>$user['id'],'money'=>$order['money'],'now_money'=>($user['money']-$order['money'])]);
        $this->success('操作成功');
    }

    /**
     * @title 新媒体订单查看内容
     * @description
     * @author panhaowen
     * @url /portal/portal/BusinessOrder
     * @method POST
     * @param name:id type:int require:1 desc:新媒体订单id
     */
    public function BusinessOrder()
    {
        $param=$this->request->param();
        $data=Db::name('business_order')->where('id',$param['id'])->find();
        if ($data['post_url']!=null) {
            $this->success('获取信息成功', $data['post_url']);
        }
        $this->success('获取信息成功', cmf_get_file_download_url($data['remark']));
    }

    /**
     * @title 新媒体订单退款
     * @description
     * @author panhaowen
     * @url /portal/portal/BusinessOrderReturn
     * @method POST
     * @param name:id type:int require:1 desc:新媒体订单id
     */
    public function BusinessOrderReturn()
    {
        $param=$this->request->param();
        $user=$this->getUser();
        $order=Db::name('business_order')->where('id',$param['id'])->find();
        Db::name('business_order')->where('id',$param['id'])->update(['status'=>3]);
        Db::name('user')->where('id',$user)->setInc('money',$order['money']);
        Db::name('money_log')->insert(['create_time'=>time(),'user_id'=>$user['id'],'money'=>$order['money'],'now_money'=>$user['money']+$order['money'],'type'=>5]);
        $this->success('操作成功');
    }

    /**
     * @title excel表格导出
     * @description
     * @author panhaowen
     * @url /portal/portal/BusinessOrderReturn
     * @method POST
     * @param name:market_id type:int require:1 desc:营销分类id
     * @param name:param type:varchar require:1 desc:筛选参数
     */
    //导出数据
    public function excel()
    {
        $param=$this->request->param();
        $selected=Db::name('market')->where('id',$param['market_id'])->find()['selected'];
        $classify=Db::name('classify')->where('id','in',explode(',',$selected))->select();
        $this->success('1',$classify);
        $where=[];
        $list=Db::name('market_business')->where('market_id',$param['market_id']);
        $path = ROOT_PATH . '/public/upload/'; //找到当前脚本所在路径
        $PHPExcel = new PHPExcel(); //实例化PHPExcel类,类似于在桌面上新建一个Excel表格
        $PHPSheet = $PHPExcel->getActiveSheet(); //获得当前活动sheet的操作对象
        $PHPSheet->setTitle('表单信息'); //给当前活动sheet设置名称
        $PHPSheet->setCellValue('A1', 'ID')
            ->setCellValue('B1', '微信名')
            ->setCellValue('C1', '手机号')
            ->setCellValue('D1', '餐谱');
        foreach ($list as $k => $v) {
            $n = $k + 2;

            $PHPSheet->setCellValue("A$n", $v['id'])
                ->setCellValue("B$n", "$v[user_nickname]")
                ->setCellValue("C$n", "$v[mobile]")
                ->setCellValue("D$n", "$v[cook]");
        }
        $PHPExcel->getActiveSheet()->getDefaultColumnDimension()->setWidth(20);//设置默认宽度
        $PHPWriter = PHPExcel_IOFactory::createWriter($PHPExcel,'Excel2007');//按照指定格式生成Excel文件,‘Excel2007'表示生成2007版本的xlsx,
        $file_name='/'.date('Y-m-d',time()).'表单信息.xlsx';
        $PHPWriter->save($path.$file_name); //表示在$path路径下面生成demo.xlsx文件
        $filename ='./upload'.$file_name;
        ob_end_clean();
        $file=cmf_get_file_download_url(date('Y-m-d',time()).'表单信息.xlsx');
        header("Location: $file");
        //下载文件需要用到的头
//        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
//        header('Content-Description: File Transfer');
//        header('Content-Type: application/octet-stream');
//        header('Content-Length: ' . filesize($filename));
//        header('Content-Disposition: attachment; filename=' . basename($filename));
//        readfile($filename);
        exit;
    }
}