コード例 #1
0
 public function make_contract_pdf()
 {
     $taskModel = M('system_task');
     // 标记超时的任务为停止运行
     $taskModel->where(['is_run' => 1, 'updated' => ['elt', time() - 300]])->save(['is_run' => 0, 'remark' => '运行超时,自动终止!']);
     // 检测进程数是否已经满额
     $max_task = 1;
     if ($taskModel->where(['is_run' => 1])->count() >= $max_task) {
         return;
     }
     // 设置不超时
     set_time_limit(0);
     // 登记一下任务
     $task_id = $taskModel->add(['created' => time(), 'is_run' => 1]);
     // 开始工作
     $total = 0;
     $contractModel = new \Loan\Model\OrderContractModel();
     while (true) {
         // 处理任务
         $success_num = $contractModel->task();
         // 若没有任务可处理,则休眠5秒钟再重试
         if ($success_num < 1) {
             sleep(5);
         }
         $total += $success_num;
         // 任务被人为终止则退出循环
         if ($taskModel->where(['id' => $task_id, 'is_run' => 1])->save(['updated' => time(), 'total_success' => $total, 'remark' => '最后更新时间:' . date('Y-m-d H:i:s')]) == 0) {
             break;
         }
     }
     // 告个别
     $taskModel->where(['id' => $task_id])->save(['is_run' => 0, 'remark' => '任务手动退出']);
 }
コード例 #2
0
 public function index()
 {
     if (I('get.action') == 'remark') {
         M('loan_order_remark')->add(['order_id' => I('order_id'), 'created' => time(), 'uid' => $this->_user['uid'], 'uname' => $this->_user['uname'], 'content' => I('content')]);
         $this->success();
         exit;
     }
     if (I('get.action') == 'contract') {
         $model = new \Loan\Model\OrderContractModel();
         $url = $model->pdfUrl(I('id')) or $this->error($model->getError());
         header('Location: ' . $url);
         exit;
     }
     $id = I('get.id', 0, 'intval');
     $id && $this->_detail($id);
     // 显示正常的订单列表
     $model = D('Loan/order');
     $list = $this->lists($this->_table, $this->_getWhere(), $this->_list_order);
     foreach ($list as $key => $vo) {
         $list[$key]['url'] = $vo['url'] ?: ($vo['goods_id'] > 0 ? fenqi_host($vo['goods_id']) : '');
     }
     int_to_string($list, ['status' => $this->_status, 'type' => $this->_type, 'city_id' => $list ? M('common_region')->where(['id' => ['in', array_column($list, 'city_id')]])->getField('id,name_short') : [], 'campus_id' => $list ? M('university_campus')->where(['id' => ['in', array_column($list, 'campus_id')]])->getField('id,university_name') : []]);
     $this->assign('_list', $list);
     $this->assign('orderModel', $model);
     $this->meta_title = $this->_node_name . '信息';
     $this->display();
 }
コード例 #3
0
 public function download()
 {
     // 批量下载
     $config = C('UPLOAD_TYPE_CONFIG');
     $config['domain'] = '7xlf9w.com2.z0.glb.qiniucdn.com';
     $config['bucket'] = 'zjfq-contract';
     $qiniu = new \Common\Util\Qiniu($config);
     // 查询打包状态
     $pid = I('pid');
     if ($pid) {
         $ret = $qiniu->status($pid) or ajax_error('无法获取打包状态!');
         if ($ret['code'] == 1 || $ret['code'] == 2) {
             ajax_success();
         }
         if ($ret['code'] == 3) {
             ajax_error($ret['items'][0]['error']);
         } elseif ($ret['code'] == 0) {
             // 打包完成
             $row = M('loan_order_contract_download')->where(['qiniu_persistent_id' => $pid])->find();
             // 标识已下载
             M('loan_order_contract')->where(['order_id' => ['in', $row['order_ids']]])->save(['is_download' => 1, 'use_time' => time() - $row['created']]);
             // 标识所用时间
             M('loan_order_contract_download')->save(['id' => $row['id'], 'use_time' => time() - $row['created']]);
             // 返回下载地址
             $url = $qiniu->downLink($row['zip_file']);
             $url = $url . '?e=' . (time() + 60);
             $url .= '&token=' . $qiniu::sign($qiniu->sk, $qiniu->ak, $url);
             ajax_success($url);
         } else {
             system_warn('未知返回结果:' . print_r($ret, true));
             ajax_error('未知状态!');
         }
     }
     $ids = explode(',', I('get.ids')) or $this->error('参数错误!');
     $model = new \Loan\Model\OrderContractModel();
     if (count($ids) <= 1) {
         $id = $ids[0];
         $url = $model->pdfUrl(I('id')) or $this->error($model->getError());
         M('loan_order_contract')->save(['order_id' => $id, 'is_download' => 1]);
         header('Location: ' . $url);
         exit;
     }
     $orders = M('loan_order_contract')->where(['order_id' => ['in', $ids]])->field('order_id,url')->select() or $this->error('找不到此电子合同记录!');
     $urls = [];
     foreach ($orders as $key => $row) {
         $url = $row['url'] or $this->error('找不到订单的合同地址:' . $row['order_id']);
         $url = $url . '?e=' . (time() + 60);
         $urls[] = $url . '&token=' . $qiniu::sign($qiniu->sk, $qiniu->ak, $url);
     }
     $ret = $qiniu->mkzip($urls) or $this->error('无法请求七牛打包接口!');
     M('loan_order_contract_download')->add(['created' => time(), 'zip_file' => $ret['zip_file'], 'qiniu_persistent_id' => $ret['persistent_id'], 'order_ids' => implode(',', $ids), 'order_count' => count($ids)]);
     $this->success($ret['persistent_id']);
 }