123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use app\common\model\Admin;
- use app\common\service\PdfService;
- use app\main\constants\AdminConstants;
- use app\main\service\AdminService;
- use think\Controller;
- use think\Request;
- use ZipArchive;
- /**
- * 协议乙方
- *
- * @icon fa fa-circle-o
- */
- class Agreementyi extends Backend
- {
- /**
- * @var \app\admin\model\Agreementyi Agreementyi模型对象
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model('Agreementyi');
- }
- /**
- * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法
- * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑
- * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
- */
- /**
- * 查看
- */
- public function index()
- {
- //当前是否为关联查询
- $this->relationSearch = true;
- //设置过滤方法
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax()) {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('pkey_name')) {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $total = $this->model
- ->with('admin')
- ->where($where)
- ->order($sort, $order)
- ->count();
- $list = $this->model
- ->with('admin')
- ->where($where)
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->select();
- /** @var \app\admin\model\Agreementjia $agJiaModel */
- $agJiaModel = model('agreementjia');
- $jiaList = $agJiaModel->field('id,jia')->order('id')->select();
- /** @var \app\admin\model\Agreementyi $row */
- foreach ($list as &$row) {
- $row->getRelation('admin')->visible(['username', 'nickname']);
- $row['jia'] = $jiaList;
- }
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 添加
- */
- public function add()
- {
- /** @var \app\admin\model\Agreementjia $agJiaModel */
- $agJiaModel = model('agreementjia');
- $jiaInfo = $agJiaModel->field('id,jia,card_bank,card_num,start_date,seal')->order('id')->find();
- //获取佣金比例
- $adminExtendModel = AdminService::instance()->getAdminExtendModel();
- $adminExtendInfo = $adminExtendModel->getInfo($this->auth->id);
- $benefit = $adminExtendInfo['benefit'];
- if ($this->request->isPost()) {
- $params = $this->request->post("row/a");
- if ($params) {
- $params['admin_id'] = $this->auth->id;
- $params['benefit'] = $benefit;
- try {
- //是否采用模型验证
- if ($this->modelValidate) {
- $name = basename(str_replace('\\', '/', get_class($this->model)));
- $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate;
- $this->model->validate($validate);
- }
- $params['updatetime'] = time();
- /*if (isset($params['id']) && $params['id']) {
- //$result = $this->model->allowField(true)->update($params);
- @unlink(ROOT_PATH . 'public/uploads/agreementyi/' . $params['id'] . '_' . $jiaInfo['id'] . '.pdf');
- } else {*/
- $params['createtime'] = time();
- $result = $this->model->allowField(true)->insert($params);
- //}
- if ($result !== false) {
- $this->success('协议签署成功!页面跳转中~', 'withdraw/add');
- } else {
- $this->error('协议签署失败,请重试或联系客服处理!');
- }
- } catch (\think\exception\PDOException $e) {
- $this->error('协议签署失败,请重试或联系客服处理!msg:' . $e->getMessage());
- }
- }
- $this->error(__('Parameter %s can not be empty', ''));
- }
- $info = [];
- $info['action'] = 'add';
- $info['pt'] = config('site.agreement_platform_name'); //直接获取网站标题
- $info['start_date'] = 0;
- $info['brokerage'] = (1 - $benefit) * 100;
- /*$agYiInfo = $this->model->field('id')->where('admin_id', $this->auth->id)->find();
- if ($agYiInfo) {
- $info['id'] = $agYiInfo['id'];
- }*/
- $info['jia'] = $jiaInfo['jia'];
- // $info['start_date'] = $jiaInfo['start_date']; // 需要跟渠道提现时间做对比
- $info['seal'] = $jiaInfo['seal'];
- $info['jia_card_bank'] = $jiaInfo['card_bank'];
- $info['jia_card_num'] = $jiaInfo['card_num'];
- $info['date'] = date('Y年m月d日', strtotime($jiaInfo['start_date']));
- $info['mobile'] = $this->auth->mobile;
- $adminExtendModel = AdminService::instance()->getAdminExtendModel();
- $adminExtendInfo = $adminExtendModel->getInfo($this->auth->id);
- $info['card_holder'] = $adminExtendInfo['card_holder'];
- $info['card_num'] = $adminExtendInfo['card_num'];
- $info['card_bank'] = $adminExtendInfo['card_bank'];
- $info['idcard_no'] = $adminExtendInfo['idcard_no'];
- /** @var \app\admin\model\Agreementpay $agPayModel */
- $agPayModel = model('agreementpay');
- $agPayList = $agPayModel->field('pay')->order('id')->select();
- $payList = [];
- foreach ($agPayList as $agPayInfo) {
- $payList[] = $agPayInfo['pay'];
- }
- $info['pay'] = implode(',', $payList);
- /** @var \app\common\model\Withdraw $withdrawModel */
- $withdrawModel = model('withdraw');
- $ct = $withdrawModel->field('createtime')->where('admin_id', $this->auth->id)->order('id')->find();
- if ($ct) {
- $dt = date('Ymd', $ct['createtime']);
- $info['start_date'] = $dt;
- if ($dt > $jiaInfo['start_date']) {
- $info['date'] = date('Y年m月d日', $ct['createtime']);
- }
- }
- $this->assign('info', $info);
- $this->view->engine->layout(false); // 关闭模板布局
- return $this->view->fetch('pdf');
- }
- /**
- * 编辑
- * @param null $ids
- * @param null $jia
- * @param int $is_down
- * @param int $tech_type 是否技术服务合作协议 1=>米花 2=>汇聚
- * @return string
- * @throws \think\Exception
- */
- public function edit($ids = null, $jia = null, $is_down = 0, $tech_type = 0)
- {
- if ($this->group == AdminConstants::ADMIN_GROUP_ID_CHANNEL) {
- if($ids){
- $info = $this->model->where('admin_id', $this->auth->id)->where('id', $ids)->find();
- }else{
- $info = $this->model->where('admin_id', $this->auth->id)->find();
- }
- if (!$info) {
- $this->error('协议未签署!');
- }
- } elseif (!in_array($this->group, [
- AdminConstants::ADMIN_GROUP_ID_SUPER_ADMIN,
- AdminConstants::ADMIN_GROUP_ID_ADMIN,
- AdminConstants::ADMIN_GROUP_ID_CONFIG_MANAGER,
- AdminConstants::ADMIN_GROUP_ID_SETTLEMENT
- ])) {
- $this->error('没有权限查看!');
- } else {
- if (!$ids || !$jia) {
- $this->error('参数错误!');
- }
- $info = $this->model->where('id', $ids)->find();
- $jiaWhere = ['id' => $jia];
- }
- if ($info['benefit']) {
- $info['brokerage'] = (1 - $info['benefit']) * 100;
- } else {
- //获取佣金比例
- $adminExtendModel = AdminService::instance()->getAdminExtendModel();
- $adminExtendInfo = $adminExtendModel->getInfo($info['admin_id']);
- $info['brokerage'] = (1 - $adminExtendInfo['benefit']) * 100;
- }
- $info['action'] = 'edit';
- $info['pt'] = config('site.agreement_platform_name'); //直接获取网站标题
- /** @var \app\admin\model\Agreementjia $agJiaModel */
- $agJiaModel = model('agreementjia');
- if (isset($jiaWhere)) {
- $jiaInfo = $agJiaModel->where($jiaWhere)->find();
- } else {
- $jiaInfo = $agJiaModel->order('id')->find();
- }
- $info['jia'] = $jiaInfo['jia'];
- $info['seal'] = $jiaInfo['seal'];
- $info['jia_card_bank'] = $jiaInfo['card_bank'];
- $info['jia_card_num'] = $jiaInfo['card_num'];
- //$info['date'] = date('Y年m月d日',
- // strtotime($info['start_date'] > $jiaInfo['start_date'] ? $info['start_date'] : $jiaInfo['start_date']));
- $adminConfigYi = model('AdminConfig')->getAdminInfoAll($info['admin_id']);
- $yi_start_date = date('Ymd', $adminConfigYi['createtime']);
- $info['date'] = date('Y年m月d日', strtotime($yi_start_date > $jiaInfo['start_date'] ? $yi_start_date : $jiaInfo['start_date']));
- /** @var \app\admin\model\Agreementpay $agPayModel */
- $agPayModel = model('agreementpay');
- $agPayList = $agPayModel->field('pay')->order('id')->select();
- $payList = [];
- foreach ($agPayList as $agPayInfo) {
- $payList[] = $agPayInfo['pay'];
- }
- $info['pay'] = implode(',', $payList);
- $this->view->assign("info", $info);
- $this->view->engine->layout(false); // 关闭模板布局
- if($is_down){
- if($tech_type == 1){
- return $this->view->fetch('down_tech');
- }elseif ($tech_type == 2){
- return $this->view->fetch('down_huiju');
- }else{
- return $this->view->fetch('down');
- }
- }
- if ($tech_type == 1) {
- return $this->view->fetch('pdf_tech');
- } elseif ($tech_type == 2) {
- return $this->view->fetch('pdf_huiju');
- } else {
- return $this->view->fetch('pdf');
- }
- }
- public function export($ids = "")
- {
- $this->view->engine->layout(false);
- $ids = $ids ? $ids : $this->request->param("ids");
- if ($ids) {
- $yiList = $this->model->whereIn('id', $ids)->select();
- } else {
- $yiList = $this->model->select();
- }
- /** @var \app\admin\model\Agreementjia $agJiaModel */
- $agJiaModel = model('agreementjia');
- $ajJiaList = $agJiaModel->field('id,jia,card_bank,card_num,start_date,seal')->select();
- /** @var \app\admin\model\Agreementpay $agPayModel */
- $agPayModel = model('agreementpay');
- $agPayList = $agPayModel->field('pay')->order('id')->select();
- $payList = [];
- foreach ($agPayList as $agPayInfo) {
- $payList[] = $agPayInfo['pay'];
- }
- $pays = implode(',', $payList);
- $files = [];
- $path = ROOT_PATH . 'public/uploads/agreementyi/';
- if (!is_dir($path)) {
- mkdir($path, 0766, true);
- }
- $pathTmp = ROOT_PATH . 'public/uploads/agreementyi_tmp/';
- if (!is_dir($pathTmp)) {
- mkdir($pathTmp, 0766, true);
- }
- /** @var \app\admin\model\Agreementyi $yiInfo */
- foreach ($yiList as $yiInfo) {
- $info = $yiInfo;
- $info['action'] = 'export';
- $info['pt'] = config('site.agreement_platform_name'); //直接获取网站标题
- $info['pay'] = $pays;
- if ($info['benefit']) {
- $info['brokerage'] = (1 - $info['benefit']) * 100;
- } else {
- //获取佣金比例
- $adminExtendModel = AdminService::instance()->getAdminExtendModel();
- $adminExtendInfo = $adminExtendModel->getInfo($yiInfo['admin_id']);
- $info['brokerage'] = (1 - $adminExtendInfo['benefit']) * 100;
- }
- foreach ($ajJiaList as $jiaInfo) {
- //$file = $path . $ids . '_' . $jiaInfo['id'];
- $file = $path . $yiInfo['id'] . '_' . $yiInfo['admin_id'] . '_' . $jiaInfo['id'];
- if (is_file($file . '.pdf')) {
- $files[] = ["{$yiInfo['id']}_{$yiInfo['admin_id']}_{$jiaInfo['jia']}.pdf", $file . '.pdf'];
- $file_mihua = $path . $yiInfo['id'] . '_' . $yiInfo['admin_id'] . '_mihua';
- $files[] = ["{$yiInfo['id']}_{$yiInfo['admin_id']}_福建米花信息科技有限公司(乙方).pdf", $file_mihua . '.pdf'];
- $file_huiju = $path . $yiInfo['id'] . '_' . $yiInfo['admin_id'] . '_huiju';
- $files[] = ["{$yiInfo['id']}_{$yiInfo['admin_id']}_广州市汇聚支付电子科技有限公司(乙方).pdf", $file_huiju . '.pdf'];
- continue;
- }
- $info['jia'] = $jiaInfo['jia'];
- $info['seal'] = ROOT_PATH . 'public' . $jiaInfo['seal'];
- $info['jia_card_bank'] = $jiaInfo['card_bank'];
- $info['jia_card_num'] = $jiaInfo['card_num'];
- $info['date'] = date('Y年m月d日',
- strtotime($yiInfo['start_date'] > $jiaInfo['start_date'] ? $yiInfo['start_date'] : $jiaInfo['start_date']));
- $this->assign('info', $info);
- $content = $this->view->fetch('down');
- PdfService::instance()->mpdf($file, $content, '', 'F');
- $files[] = ["{$yiInfo['id']}_{$yiInfo['admin_id']}_{$jiaInfo['jia']}.pdf", $file . '.pdf'];
- $file_mihua = $path . $yiInfo['id'] . '_' . $yiInfo['admin_id'] . '_mihua';
- $this->assign('info', $info);
- $content_mihua = $this->view->fetch('down_tech');
- PdfService::instance()->mpdf($file_mihua, $content_mihua, '', 'F');
- $files[] = ["{$yiInfo['id']}_{$yiInfo['admin_id']}_福建米花信息科技有限公司(乙方).pdf", $file_mihua . '.pdf'];
- $file_huiju = $path . $yiInfo['id'] . '_' . $yiInfo['admin_id'] . '_huiju';
- $this->assign('info', $info);
- $content_huiju = $this->view->fetch('down_huiju');
- PdfService::instance()->mpdf($file_huiju, $content_huiju, '', 'F');
- $files[] = ["{$yiInfo['id']}_{$yiInfo['admin_id']}_广州市汇聚支付电子科技有限公司(乙方).pdf", $file_huiju . '.pdf'];
- }
- }
- $zip = new \ZipArchive();
- $zipName = date('YmdHis') . '_' . uniqid() . '.zip';
- $res = $zip->open($pathTmp . $zipName, \ZipArchive::CREATE);
- if ($res === TRUE) {
- foreach ($files as $file) {
- $zip->addFile($file[1], $file[0]);
- }
- } else {
- $this->error('Zip 压缩失败!');
- }
- $zip->close();
- header('location:/uploads/agreementyi_tmp/' . $zipName);
- }
- public function down($ids = null, $jia = null, $tech_type = 0)
- {
- $path = ROOT_PATH . 'public/uploads/agreementyi/';
- if (!is_dir($path)) {
- mkdir($path, 0766, true);
- }
- if($tech_type==1){
- $file = $path . $ids . '_' . $jia.'_tech';
- if (is_file($file . '.pdf')) {
- header('location:/uploads/agreementyi/' . $ids . '_' . $jia . '_tech.pdf');
- die;
- }
- $content = $this->edit($ids, $jia, 1, 1);
- } elseif ($tech_type ==2) {
- $file = $path . $ids . '_' . $jia . '_huiju';
- if (is_file($file . '.pdf')) {
- header('location:/uploads/agreementyi/' . $ids . '_' . $jia . '_huiju.pdf');
- die;
- }
- $content = $this->edit($ids, $jia, 1, 2);
- } else {
- $file = $path . $ids . '_' . $jia;
- if (is_file($file . '.pdf')) {
- header('location:/uploads/agreementyi/' . $ids . '_' . $jia . '.pdf');
- die;
- }
- $content = $this->edit($ids, $jia, 1);
- }
- PdfService::instance()->mpdf($file, $content, '', 'FD');
- }
- }
|