123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570 |
- <?php
- namespace Service\Lib;
- use Dever;
- Dever::apply('src/PHPExcel', 'excel');
- class Manage
- {
- /**
- * 得到视频地址
- *
- * @return mixed
- */
- public function video($id, $name, $data)
- {
- $link = Dever::param('link', $data);
- $video = $this->decode($link);
- if ($video) {
- Dever::db('service/video')->update(array('where_id' => $id, 'video' => $video));
- }
- }
- public function showOrderStatus($id)
- {
- $info = Dever::db('service/order')->one($id);
- if ($info) {
- if ($info['status'] == 1) {
- #return '*已支付';
- return '待支付';
- } elseif ($info['status'] == 2) {
- return '已支付';
- } elseif ($info['status'] == 3) {
- return '支付失败';
- } elseif ($info['status'] == 5) {
- $table['状态'] = '已退款';
- $manage = Dever::db('manage/admin')->one($info['tk_admin']);
- $table['备注'] = $info['tk_desc'];
- $table['退款时间'] = date('Y-m-d H:i:s', $info['tk_time']);
- $table['操作人'] = $manage['username'];
- return Dever::table($table);
- }
- }
- }
- /**
- * 得到订单时间
- *
- * @return mixed
- */
- public function showOrderTime($id)
- {
- $info = Dever::db('service/order')->one($id);
- if ($info) {
- $table = array();
- $update = array();
- $table['订单创建时间'] = date("Y-m-d H:i:s", $info['cdate']);
-
- if (!$info['survey_date']) {
- $user = Dever::db('survey/user_answer')->getOldOne(array('order_id' => $id));
- if ($user) {
- $table['填写问卷时间'] = date("Y-m-d H:i:s", $user['cdate']);
- $update['survey_date'] = $user['cdate'];
- }
- } else {
- $table['填写问卷时间'] = date("Y-m-d H:i:s", $info['survey_date']);
- }
- if ($info['feedback_status'] >= 3) {
- if (!$info['survey_end_date']) {
- $user = Dever::db('survey/user_answer')->getNewOne(array('order_id' => $id));
- if ($user) {
- $table['问卷提交时间'] = date("Y-m-d H:i:s", $user['cdate']);
- $update['survey_end_date'] = $user['cdate'];
- }
- } else {
- $table['问卷提交时间'] = date("Y-m-d H:i:s", $info['survey_end_date']);
- }
- }
-
- if ($info['feedback_status'] == 4) {
- if (!$info['feedback_date']) {
- /*
- $feedback = Dever::db('service/feedback')->one(array('order_id' => $id));
- if ($feedback) {
- $table['反馈问卷时间'] = date("Y-m-d H:i:s", $feedback['cdate']);
- $update['feedback_date'] = $feedback['cdate'];
- }
- */
- } else {
- $table['反馈问卷时间'] = date("Y-m-d H:i:s", $info['feedback_date']);
- }
- }
- if ($update) {
- $update['where_id'] = $id;
- Dever::db('service/order')->update($update);
- }
-
- return Dever::table($table);
- }
- return '';
- }
- # 显示反馈方案的状态
- public function showFeedbackStatus($id)
- {
- $info = Dever::db('service/order')->one($id);
- $html = '';
- if ($info) {
-
- $config = Dever::db('service/order')->config['feedback_status'];
- if (isset($config[$info['feedback_status']])) {
- $html = $config[$info['feedback_status']];
- }
- $info = Dever::db('service/feedback')->one(array('order_id' => $id));
- if ($info && $info['pdf']) {
- $html .= '<br><a href="javascript:;" onclick="window.open(\''.$info['pdf'].'\')">[查看软装服务设计方案]</a>';
- }
- }
- return $html;
- }
- /**
- * 设计反馈之后,发送短信 (已废弃)
- *
- * @return mixed
- */
- public function order($id, $name, $data)
- {
- # 更改退款状态
- $status = Dever::param('status', $data);
- $tk_desc = Dever::param('tk_desc', $data);
- if ($tk_desc && $tk_desc != 'null') {
- $admin = Dever::load('manage/auth.info');
- $update['where_id'] = $id;
- $update['tk_admin'] = $admin['id'];
- $update['tk_time'] = time();
- $update['status'] = 5;
- Dever::db('service/order')->update($update);
- } else {
- $update['where_id'] = $id;
- $update['status'] = 2;
- Dever::db('service/order')->update($update);
- }
- /*
- if ($feedback_status == 2) {
- $order = Dever::db('service/order')->one($id);
- $user = Dever::db('passport/user')->one($order['id']);
- if ($user['mobile'] && $order['order_id']) {
- Dever::load('passport/applet')->send($user['mobile'], $order['order_id']);
- }
- }
- */
- }
- /**
- * 完成反馈,发送短信 已废弃
- *
- * @return mixed
- *
- public function feedback($id, $name, $data)
- {
- $order_id = Dever::param('order_id', $data);
- $info = Dever::db('service/feedback')->one($id);
- $order = Dever::db('service/order')->one($order_id);
- $status = Dever::param('status', $data);
-
- if ($status == 1) {
- if ($order && $order['feedback_status'] == 3) {
- Dever::db('service/order')->update(array('where_id' => $order_id, 'feedback_status' => 4));
- $user = Dever::db('passport/user')->one($order['uid']);
- if ($user['mobile'] && $order['order_id']) {
- $skin = 'order';
- # 判断是否二次修改
- $sms = Dever::param('sms', $data);
- if ($sms == 2) {
- $skin = 'feedback';
- }
- Dever::setInput('skin', $skin);
- Dever::load('passport/applet')->send($user['mobile'], $order['order_id']);
- }
- }
- } else {
- if ($order) {
- Dever::db('service/order')->update(array('where_id' => $order_id, 'feedback_status' => 3));
- }
- }
- # 生成产品的链接
- //Dever::daemon('spider/handle.createProduct?id=' . $id, 'service');
- //Dever::load('service/spider/handle.createProduct?id=' . $id);
- }
- */
- public function showQuestion($uid, $product_id, $order_id, $feedback_status)
- {
- $link = Dever::url('api.view&uid='.$uid.'&product_id=' . $product_id . '&order_id=' . $order_id, 'survey');
- if ($feedback_status == 1) {
- $html = '';
- } else {
- $html = '<a href="javascript:;" onclick="window.open(\''.$link.'\')">查看</a>';
- }
-
- return $html;
-
- }
- public function showOrderUser($id)
- {
- $info = Dever::db('service/order')->one($id);
- $table = array();
- $user = Dever::db('passport/user')->one($info['uid']);
- $table['订单号'] = $info['order_id'];
- $table['用户名'] = $user['username'];
- $table['手机号'] = $user['mobile'];
- $table['产品名'] = $info['name'];
- if ($info['type'] == 1) {
- $table['支付方式'] = '购买';
- $table['支付金额'] = $info['cash'];
- } else {
- $table['支付方式'] = '兑换';
- $table['兑换码'] = $info['code'];
- }
- $feedback = Dever::db('service/feedback')->one(array('order_id' => $id));
- if($feedback && $feedback['num']) {
- $table['用户评分'] = $feedback['num'];
- if ($feedback['msg']) {
- $table['用户建议'] = $feedback['msg'];
- }
- }
- return Dever::table($table);
- }
- /**
- * 导出成excel
- *
- * @return mixed
- */
- public function out_api()
- {
- $product = Dever::db('service/product')->state();
- $header = array();
- foreach ($product as $k => $v) {
- $product[$k]['answer'] = array();
- $product[$k]['data'] = array();
- $product[$k]['header'] = array();
- $product[$k]['header'][0] = '订单号';
- $product[$k]['question'] = array
- (
- 0 => array
- (
- 'id' => 0,
- 'name' => $product[$k]['header'][0],
- ),
- );
- $product[$k]['question'] += Dever::db('survey/info')->getData(array('product_id' => $v['id']));
- if ($product[$k]['question']) {
- foreach ($product[$k]['question'] as $k1 => $v1) {
- if (isset($v1['type'])) {
- if ($v1['type'] == 12 || $v1['type'] == 13) {
- $product[$k]['question'][$k1]['content'] = Dever::array_decode($v1['content']);
- } else {
- $product[$k]['question'][$k1]['content'] = array();
- }
- }
- $product[$k]['header'][$k1] = $v1['name'];
- }
- }
- $tjr = -10000;
- $product[$k]['header'][$tjr] = '提交人';
- $product[$k]['question'][$tjr] = array
- (
- 'id' => $tjr,
- 'name' => $product[$k]['header'][$tjr],
- );
- $tjsj = $tjr + 1;
- $product[$k]['header'][$tjsj] = '提交时间';
- $product[$k]['question'][$tjsj] = array
- (
- 'id' => $tjsj,
- 'name' => $product[$k]['header'][$tjsj]
- );
- $where['product_id'] = $v['id'];
- $where['feedback_status'] = 3;
- $product[$k]['order'] = Dever::db('service/order')->getYes($where);
- if ($product[$k]['order']) {
- foreach ($product[$k]['order'] as $k1 => $v1) {
- $user = Dever::db('passport/user')->one($v1['uid']);
- $answer = Dever::db('survey/user_answer')->getData(array('uid' => $v1['uid'], 'product_id' => $v['id'], 'order_id' => $v1['id']));
- if ($answer) {
- $product[$k]['answer'][$k1][0] = $v1['order_id'] ? $v1['order_id'] : $v1['id'];
- $product[$k]['order'][$k1]['answer'][0] = $product[$k]['answer'][$k1][0];
- $time = '';
- foreach ($answer as $k2 => $v2) {
- $product[$k]['answer'][$k1][$v2['info_id']] = $v2['value'];
- if (isset($product[$k]['question'][$v2['info_id']]['content']) && $product[$k]['question'][$v2['info_id']]['content']) {
- $temp = explode(',', $v2['value']);
- $vvn = array();
- $vvp = array();
- foreach ($temp as $k3 => $v3) {
- $d3 = '';
- if (strstr($v3, '$$$')) {
- $t11 = explode('$$$', $v3);
- $v3 = $t11[0];
- $d3 = $t11[1];
- }
- $v3 = $v3-1;
- if (isset($product[$k]['question'][$v2['info_id']]['content'][$v3])) {
- $t1 = $product[$k]['question'][$v2['info_id']]['content'][$v3];
- if (isset($t1['desc']) && $t1['desc']) {
- $t1['title'] .= '('.$t1['desc'].')';
- }
- $vvn[$k3] = $t1['title'];
- if (isset($t1['pic']) && $t1['pic']) {
- $vvp[$k3] = $t1['pic'];
- }
- if ($d3) {
- $vvn[$k3] .= ':' . $d3;
- }
- }
- }
- $product[$k]['answer'][$k1][$v2['info_id']] = implode("\r\n", $vvn);
- if ($vvp) {
- $product[$k]['answer'][$k1][$v2['info_id']] .= '||' . implode(',', $vvp);
- }
- }
- $product[$k]['order'][$k1]['answer'][$v2['info_id']] = $product[$k]['answer'][$k1][$v2['info_id']];
- $time = date('Y-m-d H:i', $v2['cdate']);
- }
- $product[$k]['answer'][$k1][$tjr] = $user['username'];
- $product[$k]['order'][$k1]['answer'][$tjr] = $product[$k]['answer'][$k1][$tjr];
- $product[$k]['answer'][$k1][$tjsj] = $time;
- $product[$k]['order'][$k1]['answer'][$tjsj] = $product[$k]['answer'][$k1][$tjsj];
- foreach ($product[$k]['header'] as $k4 => $v4) {
- if (isset($product[$k]['answer'][$k1][$k4])) {
- $product[$k]['data'][$k1][$k4] = $product[$k]['answer'][$k1][$k4];
- } else {
- $product[$k]['data'][$k1][$k4] = '';
- }
- }
- }
- }
- }
- }
- $time = date('Y-m-d H:i');
- $name = '订单列表';
- $file = $time . '_' . $name;
- $test = Dever::input('test');
- $sheet = 0;
- $xls = true;
- if ($test == 1) {
- print_r($product);die;
- }
- //
- foreach ($product as $k => $v) {
- $header = $v['header'];
- $data = $v['data'];
- $sheetName = $v['name'];
- $xls = Dever::excelExport($data, $header, $file, $sheet, $sheetName, $xls);
- $sheet++;
- }
- Dever::excelExport(false, false, $file, 0, false, $xls);
- die;
- if (!$test) {
- ob_get_clean();
- ob_start();
- $data = Dever::render('excel', array('product' => $product));
- echo $data;
- header('Content-Disposition: attachment; filename='.$file . '.xls');
- header('Accept-Ranges:bytes');
- header('Content-Length:' . ob_get_length());
- header('Content-Type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
- ob_end_flush();
- die;
- }
- if ($test == 1) {
- return Dever::render('excel', array('product' => $product));
- } elseif ($test == 2) {
- print_r($product);die;
- }
- return;
- $where['feedback_status'] = 3;
- $order = Dever::db('service/order')->getYes($where);
- $i = 0;
- foreach ($order as $k => $v) {
- if ($v && $v['uid']) {
- $product = Dever::db('service/product')->one($v['product_id']);
- $user = Dever::db('passport/user')->one($v['uid']);
- $v['content'] = $this->question(Dever::load('survey/api.view', $v['uid'], $v['product_id'], $v['id'], true));
- if ($v['type'] == 1) {
- $v['status'] = '已购买';
- } else {
- $v['status'] = '已兑换';
- $v['cash'] = $v['code'];
- }
- $data[$i] = array
- (
- $v['order_id'],
- $product['name'],
- $user['username'],
- $user['mobile'],
- $v['status'],
- $v['cash'],
- $v['content'],
- );
- $i++;
- }
- }
- $header = array
- (
- '订单号', '产品名', '用户名', '用户手机号', '支付状态', '支付金额/兑换码', '问卷内容'
- );
- $time = date('Y-m-d H:i');
- $name = '订单列表';
- $file = $time . '_' . $name;
- $test = Dever::input('test');
- if (!$test) {
- header('Content-Type: application/vnd.ms-excel');
- header('Content-Disposition: attachment;filename="'.$file.'.xls"');
- header('Cache-Control: max-age=0');
- }
- if ($test == 1) {
- return Dever::render('excel', array('header' => $header, 'data' => $data));
- } elseif ($test == 2) {
- print_r($header);
- print_r($data);die;
- }
-
- //Dever::excelExport($data, $header, $file, $sheet = 0, $sheetName = $name);
- return;
- }
- private function question($data)
- {
- $html = array();
- if (isset($data['question'])) {
- foreach ($data['question'] as $k => $v) {
- $html[$k] = '第' . $k . '题' . '、'. $v['name'];
- if (isset($v['content']) && $v['content']) {
- if (is_numeric($v['answer']) && $v['answer'] != '未作答') {
- $temp = explode(',', $v['answer']);
- $html[$k] .= "<br/>" . '答:';
- $j = 0;
- foreach ($temp as $k1 => $v1) {
- $v1 = $v1 - 1;
- if ($j > 0) {
- $html[$k] .= '、';
- }
- if (isset($v['content'][$v1]) && $v['content'][$v1]) {
- $html[$k] .= $v['content'][$v1]['title'];
- if (isset($v['content'][$v1]['desc']) && $v['content'][$v1]['desc']) {
- $html[$k] .= '(' . $v['content'][$v1]['desc'] . ')';
- }
- $j++;
- }
- }
- }
-
-
- } else {
- $html[$k] .= "<br/>" . '答:' . $v['answer'];
- }
- }
- $html = implode("<br/>", $html);
- }
- return $html;
- }
- # 发送方案 并发送短信
- public function sendFeedback_api()
- {
- $id = Dever::input('id');
- $order = Dever::db('service/order')->one($id);
- if ($order) {
- $info = Dever::db('service/feedback')->one(array('order_id' => $id));
-
- $status = 1;
- if ($status == 1) {
- if ($order['feedback_status'] == 3) {
- Dever::db('service/order')->update(array('where_id' => $id, 'feedback_status' => 4, 'feedback_date' => time()));
- $user = Dever::db('passport/user')->one($order['uid']);
- if ($user['mobile'] && $order['order_id']) {
- $skin = 'order';
- Dever::setInput('skin', $skin);
- Dever::load('passport/applet')->send($user['mobile'], $order['order_id']);
- }
- }
- } else {
- if ($order) {
- Dever::db('service/order')->update(array('where_id' => $order_id, 'feedback_status' => 3));
- }
- }
- }
- Dever::alert('发送成功');
- }
- # 发送短信
- public function sendFeedbackSms_api()
- {
- $id = Dever::input('id');
- $order = Dever::db('service/order')->one($id);
- if ($order && $order['feedback_status'] == 4) {
- $user = Dever::db('passport/user')->one($order['uid']);
- if ($user['mobile'] && $order['order_id']) {
- $skin = 'feedback';
- Dever::setInput('skin', $skin);
- Dever::load('passport/applet')->send($user['mobile'], $order['order_id']);
- }
- }
- Dever::alert('发送成功');
- }
- }
|