Agreementyi.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use app\common\model\Admin;
  5. use app\common\service\PdfService;
  6. use app\main\constants\AdminConstants;
  7. use app\main\service\AdminService;
  8. use think\Controller;
  9. use think\Request;
  10. use ZipArchive;
  11. /**
  12. * 协议乙方
  13. *
  14. * @icon fa fa-circle-o
  15. */
  16. class Agreementyi extends Backend
  17. {
  18. /**
  19. * @var \app\admin\model\Agreementyi Agreementyi模型对象
  20. */
  21. protected $model = null;
  22. public function _initialize()
  23. {
  24. parent::_initialize();
  25. $this->model = model('Agreementyi');
  26. }
  27. /**
  28. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法
  29. * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑
  30. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  31. */
  32. /**
  33. * 查看
  34. */
  35. public function index()
  36. {
  37. //当前是否为关联查询
  38. $this->relationSearch = true;
  39. //设置过滤方法
  40. $this->request->filter(['strip_tags']);
  41. if ($this->request->isAjax()) {
  42. //如果发送的来源是Selectpage,则转发到Selectpage
  43. if ($this->request->request('pkey_name')) {
  44. return $this->selectpage();
  45. }
  46. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  47. $total = $this->model
  48. ->with('admin')
  49. ->where($where)
  50. ->order($sort, $order)
  51. ->count();
  52. $list = $this->model
  53. ->with('admin')
  54. ->where($where)
  55. ->order($sort, $order)
  56. ->limit($offset, $limit)
  57. ->select();
  58. /** @var \app\admin\model\Agreementjia $agJiaModel */
  59. $agJiaModel = model('agreementjia');
  60. $jiaList = $agJiaModel->field('id,jia')->order('id')->select();
  61. /** @var \app\admin\model\Agreementyi $row */
  62. foreach ($list as &$row) {
  63. $row->getRelation('admin')->visible(['username', 'nickname']);
  64. $row['jia'] = $jiaList;
  65. }
  66. $result = array("total" => $total, "rows" => $list);
  67. return json($result);
  68. }
  69. return $this->view->fetch();
  70. }
  71. /**
  72. * 添加
  73. */
  74. public function add()
  75. {
  76. /** @var \app\admin\model\Agreementjia $agJiaModel */
  77. $agJiaModel = model('agreementjia');
  78. $jiaInfo = $agJiaModel->field('id,jia,card_bank,card_num,start_date,seal')->order('id')->find();
  79. //获取佣金比例
  80. $adminExtendModel = AdminService::instance()->getAdminExtendModel();
  81. $adminExtendInfo = $adminExtendModel->getInfo($this->auth->id);
  82. $benefit = $adminExtendInfo['benefit'];
  83. if ($this->request->isPost()) {
  84. $params = $this->request->post("row/a");
  85. if ($params) {
  86. $params['admin_id'] = $this->auth->id;
  87. $params['benefit'] = $benefit;
  88. try {
  89. //是否采用模型验证
  90. if ($this->modelValidate) {
  91. $name = basename(str_replace('\\', '/', get_class($this->model)));
  92. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : true) : $this->modelValidate;
  93. $this->model->validate($validate);
  94. }
  95. $params['updatetime'] = time();
  96. /*if (isset($params['id']) && $params['id']) {
  97. //$result = $this->model->allowField(true)->update($params);
  98. @unlink(ROOT_PATH . 'public/uploads/agreementyi/' . $params['id'] . '_' . $jiaInfo['id'] . '.pdf');
  99. } else {*/
  100. $params['createtime'] = time();
  101. $result = $this->model->allowField(true)->insert($params);
  102. //}
  103. if ($result !== false) {
  104. $this->success('协议签署成功!页面跳转中~', 'withdraw/add');
  105. } else {
  106. $this->error('协议签署失败,请重试或联系客服处理!');
  107. }
  108. } catch (\think\exception\PDOException $e) {
  109. $this->error('协议签署失败,请重试或联系客服处理!msg:' . $e->getMessage());
  110. }
  111. }
  112. $this->error(__('Parameter %s can not be empty', ''));
  113. }
  114. $info = [];
  115. $info['action'] = 'add';
  116. $info['pt'] = config('site.agreement_platform_name'); //直接获取网站标题
  117. $info['start_date'] = 0;
  118. $info['brokerage'] = (1 - $benefit) * 100;
  119. /*$agYiInfo = $this->model->field('id')->where('admin_id', $this->auth->id)->find();
  120. if ($agYiInfo) {
  121. $info['id'] = $agYiInfo['id'];
  122. }*/
  123. $info['jia'] = $jiaInfo['jia'];
  124. // $info['start_date'] = $jiaInfo['start_date']; // 需要跟渠道提现时间做对比
  125. $info['seal'] = $jiaInfo['seal'];
  126. $info['jia_card_bank'] = $jiaInfo['card_bank'];
  127. $info['jia_card_num'] = $jiaInfo['card_num'];
  128. $info['date'] = date('Y年m月d日', strtotime($jiaInfo['start_date']));
  129. $info['mobile'] = $this->auth->mobile;
  130. $adminExtendModel = AdminService::instance()->getAdminExtendModel();
  131. $adminExtendInfo = $adminExtendModel->getInfo($this->auth->id);
  132. $info['card_holder'] = $adminExtendInfo['card_holder'];
  133. $info['card_num'] = $adminExtendInfo['card_num'];
  134. $info['card_bank'] = $adminExtendInfo['card_bank'];
  135. $info['idcard_no'] = $adminExtendInfo['idcard_no'];
  136. /** @var \app\admin\model\Agreementpay $agPayModel */
  137. $agPayModel = model('agreementpay');
  138. $agPayList = $agPayModel->field('pay')->order('id')->select();
  139. $payList = [];
  140. foreach ($agPayList as $agPayInfo) {
  141. $payList[] = $agPayInfo['pay'];
  142. }
  143. $info['pay'] = implode(',', $payList);
  144. /** @var \app\common\model\Withdraw $withdrawModel */
  145. $withdrawModel = model('withdraw');
  146. $ct = $withdrawModel->field('createtime')->where('admin_id', $this->auth->id)->order('id')->find();
  147. if ($ct) {
  148. $dt = date('Ymd', $ct['createtime']);
  149. $info['start_date'] = $dt;
  150. if ($dt > $jiaInfo['start_date']) {
  151. $info['date'] = date('Y年m月d日', $ct['createtime']);
  152. }
  153. }
  154. $this->assign('info', $info);
  155. $this->view->engine->layout(false); // 关闭模板布局
  156. return $this->view->fetch('pdf');
  157. }
  158. /**
  159. * 编辑
  160. * @param null $ids
  161. * @param null $jia
  162. * @param int $is_down
  163. * @param int $tech_type 是否技术服务合作协议 1=>米花 2=>汇聚
  164. * @return string
  165. * @throws \think\Exception
  166. */
  167. public function edit($ids = null, $jia = null, $is_down = 0, $tech_type = 0)
  168. {
  169. if ($this->group == AdminConstants::ADMIN_GROUP_ID_CHANNEL) {
  170. if($ids){
  171. $info = $this->model->where('admin_id', $this->auth->id)->where('id', $ids)->find();
  172. }else{
  173. $info = $this->model->where('admin_id', $this->auth->id)->find();
  174. }
  175. if (!$info) {
  176. $this->error('协议未签署!');
  177. }
  178. } elseif (!in_array($this->group, [
  179. AdminConstants::ADMIN_GROUP_ID_SUPER_ADMIN,
  180. AdminConstants::ADMIN_GROUP_ID_ADMIN,
  181. AdminConstants::ADMIN_GROUP_ID_CONFIG_MANAGER,
  182. AdminConstants::ADMIN_GROUP_ID_SETTLEMENT
  183. ])) {
  184. $this->error('没有权限查看!');
  185. } else {
  186. if (!$ids || !$jia) {
  187. $this->error('参数错误!');
  188. }
  189. $info = $this->model->where('id', $ids)->find();
  190. $jiaWhere = ['id' => $jia];
  191. }
  192. if ($info['benefit']) {
  193. $info['brokerage'] = (1 - $info['benefit']) * 100;
  194. } else {
  195. //获取佣金比例
  196. $adminExtendModel = AdminService::instance()->getAdminExtendModel();
  197. $adminExtendInfo = $adminExtendModel->getInfo($info['admin_id']);
  198. $info['brokerage'] = (1 - $adminExtendInfo['benefit']) * 100;
  199. }
  200. $info['action'] = 'edit';
  201. $info['pt'] = config('site.agreement_platform_name'); //直接获取网站标题
  202. /** @var \app\admin\model\Agreementjia $agJiaModel */
  203. $agJiaModel = model('agreementjia');
  204. if (isset($jiaWhere)) {
  205. $jiaInfo = $agJiaModel->where($jiaWhere)->find();
  206. } else {
  207. $jiaInfo = $agJiaModel->order('id')->find();
  208. }
  209. $info['jia'] = $jiaInfo['jia'];
  210. $info['seal'] = $jiaInfo['seal'];
  211. $info['jia_card_bank'] = $jiaInfo['card_bank'];
  212. $info['jia_card_num'] = $jiaInfo['card_num'];
  213. //$info['date'] = date('Y年m月d日',
  214. // strtotime($info['start_date'] > $jiaInfo['start_date'] ? $info['start_date'] : $jiaInfo['start_date']));
  215. $adminConfigYi = model('AdminConfig')->getAdminInfoAll($info['admin_id']);
  216. $yi_start_date = date('Ymd', $adminConfigYi['createtime']);
  217. $info['date'] = date('Y年m月d日', strtotime($yi_start_date > $jiaInfo['start_date'] ? $yi_start_date : $jiaInfo['start_date']));
  218. /** @var \app\admin\model\Agreementpay $agPayModel */
  219. $agPayModel = model('agreementpay');
  220. $agPayList = $agPayModel->field('pay')->order('id')->select();
  221. $payList = [];
  222. foreach ($agPayList as $agPayInfo) {
  223. $payList[] = $agPayInfo['pay'];
  224. }
  225. $info['pay'] = implode(',', $payList);
  226. $this->view->assign("info", $info);
  227. $this->view->engine->layout(false); // 关闭模板布局
  228. if($is_down){
  229. if($tech_type == 1){
  230. return $this->view->fetch('down_tech');
  231. }elseif ($tech_type == 2){
  232. return $this->view->fetch('down_huiju');
  233. }else{
  234. return $this->view->fetch('down');
  235. }
  236. }
  237. if ($tech_type == 1) {
  238. return $this->view->fetch('pdf_tech');
  239. } elseif ($tech_type == 2) {
  240. return $this->view->fetch('pdf_huiju');
  241. } else {
  242. return $this->view->fetch('pdf');
  243. }
  244. }
  245. public function export($ids = "")
  246. {
  247. $this->view->engine->layout(false);
  248. $ids = $ids ? $ids : $this->request->param("ids");
  249. if ($ids) {
  250. $yiList = $this->model->whereIn('id', $ids)->select();
  251. } else {
  252. $yiList = $this->model->select();
  253. }
  254. /** @var \app\admin\model\Agreementjia $agJiaModel */
  255. $agJiaModel = model('agreementjia');
  256. $ajJiaList = $agJiaModel->field('id,jia,card_bank,card_num,start_date,seal')->select();
  257. /** @var \app\admin\model\Agreementpay $agPayModel */
  258. $agPayModel = model('agreementpay');
  259. $agPayList = $agPayModel->field('pay')->order('id')->select();
  260. $payList = [];
  261. foreach ($agPayList as $agPayInfo) {
  262. $payList[] = $agPayInfo['pay'];
  263. }
  264. $pays = implode(',', $payList);
  265. $files = [];
  266. $path = ROOT_PATH . 'public/uploads/agreementyi/';
  267. if (!is_dir($path)) {
  268. mkdir($path, 0766, true);
  269. }
  270. $pathTmp = ROOT_PATH . 'public/uploads/agreementyi_tmp/';
  271. if (!is_dir($pathTmp)) {
  272. mkdir($pathTmp, 0766, true);
  273. }
  274. /** @var \app\admin\model\Agreementyi $yiInfo */
  275. foreach ($yiList as $yiInfo) {
  276. $info = $yiInfo;
  277. $info['action'] = 'export';
  278. $info['pt'] = config('site.agreement_platform_name'); //直接获取网站标题
  279. $info['pay'] = $pays;
  280. if ($info['benefit']) {
  281. $info['brokerage'] = (1 - $info['benefit']) * 100;
  282. } else {
  283. //获取佣金比例
  284. $adminExtendModel = AdminService::instance()->getAdminExtendModel();
  285. $adminExtendInfo = $adminExtendModel->getInfo($yiInfo['admin_id']);
  286. $info['brokerage'] = (1 - $adminExtendInfo['benefit']) * 100;
  287. }
  288. foreach ($ajJiaList as $jiaInfo) {
  289. //$file = $path . $ids . '_' . $jiaInfo['id'];
  290. $file = $path . $yiInfo['id'] . '_' . $yiInfo['admin_id'] . '_' . $jiaInfo['id'];
  291. if (is_file($file . '.pdf')) {
  292. $files[] = ["{$yiInfo['id']}_{$yiInfo['admin_id']}_{$jiaInfo['jia']}.pdf", $file . '.pdf'];
  293. $file_mihua = $path . $yiInfo['id'] . '_' . $yiInfo['admin_id'] . '_mihua';
  294. $files[] = ["{$yiInfo['id']}_{$yiInfo['admin_id']}_福建米花信息科技有限公司(乙方).pdf", $file_mihua . '.pdf'];
  295. $file_huiju = $path . $yiInfo['id'] . '_' . $yiInfo['admin_id'] . '_huiju';
  296. $files[] = ["{$yiInfo['id']}_{$yiInfo['admin_id']}_广州市汇聚支付电子科技有限公司(乙方).pdf", $file_huiju . '.pdf'];
  297. continue;
  298. }
  299. $info['jia'] = $jiaInfo['jia'];
  300. $info['seal'] = ROOT_PATH . 'public' . $jiaInfo['seal'];
  301. $info['jia_card_bank'] = $jiaInfo['card_bank'];
  302. $info['jia_card_num'] = $jiaInfo['card_num'];
  303. $info['date'] = date('Y年m月d日',
  304. strtotime($yiInfo['start_date'] > $jiaInfo['start_date'] ? $yiInfo['start_date'] : $jiaInfo['start_date']));
  305. $this->assign('info', $info);
  306. $content = $this->view->fetch('down');
  307. PdfService::instance()->mpdf($file, $content, '', 'F');
  308. $files[] = ["{$yiInfo['id']}_{$yiInfo['admin_id']}_{$jiaInfo['jia']}.pdf", $file . '.pdf'];
  309. $file_mihua = $path . $yiInfo['id'] . '_' . $yiInfo['admin_id'] . '_mihua';
  310. $this->assign('info', $info);
  311. $content_mihua = $this->view->fetch('down_tech');
  312. PdfService::instance()->mpdf($file_mihua, $content_mihua, '', 'F');
  313. $files[] = ["{$yiInfo['id']}_{$yiInfo['admin_id']}_福建米花信息科技有限公司(乙方).pdf", $file_mihua . '.pdf'];
  314. $file_huiju = $path . $yiInfo['id'] . '_' . $yiInfo['admin_id'] . '_huiju';
  315. $this->assign('info', $info);
  316. $content_huiju = $this->view->fetch('down_huiju');
  317. PdfService::instance()->mpdf($file_huiju, $content_huiju, '', 'F');
  318. $files[] = ["{$yiInfo['id']}_{$yiInfo['admin_id']}_广州市汇聚支付电子科技有限公司(乙方).pdf", $file_huiju . '.pdf'];
  319. }
  320. }
  321. $zip = new \ZipArchive();
  322. $zipName = date('YmdHis') . '_' . uniqid() . '.zip';
  323. $res = $zip->open($pathTmp . $zipName, \ZipArchive::CREATE);
  324. if ($res === TRUE) {
  325. foreach ($files as $file) {
  326. $zip->addFile($file[1], $file[0]);
  327. }
  328. } else {
  329. $this->error('Zip 压缩失败!');
  330. }
  331. $zip->close();
  332. header('location:/uploads/agreementyi_tmp/' . $zipName);
  333. }
  334. public function down($ids = null, $jia = null, $tech_type = 0)
  335. {
  336. $path = ROOT_PATH . 'public/uploads/agreementyi/';
  337. if (!is_dir($path)) {
  338. mkdir($path, 0766, true);
  339. }
  340. if($tech_type==1){
  341. $file = $path . $ids . '_' . $jia.'_tech';
  342. if (is_file($file . '.pdf')) {
  343. header('location:/uploads/agreementyi/' . $ids . '_' . $jia . '_tech.pdf');
  344. die;
  345. }
  346. $content = $this->edit($ids, $jia, 1, 1);
  347. } elseif ($tech_type ==2) {
  348. $file = $path . $ids . '_' . $jia . '_huiju';
  349. if (is_file($file . '.pdf')) {
  350. header('location:/uploads/agreementyi/' . $ids . '_' . $jia . '_huiju.pdf');
  351. die;
  352. }
  353. $content = $this->edit($ids, $jia, 1, 2);
  354. } else {
  355. $file = $path . $ids . '_' . $jia;
  356. if (is_file($file . '.pdf')) {
  357. header('location:/uploads/agreementyi/' . $ids . '_' . $jia . '.pdf');
  358. die;
  359. }
  360. $content = $this->edit($ids, $jia, 1);
  361. }
  362. PdfService::instance()->mpdf($file, $content, '', 'FD');
  363. }
  364. }