Manage.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. <?php
  2. namespace Service\Lib;
  3. use Dever;
  4. Dever::apply('src/PHPExcel', 'excel');
  5. class Manage
  6. {
  7. /**
  8. * 得到视频地址
  9. *
  10. * @return mixed
  11. */
  12. public function video($id, $name, $data)
  13. {
  14. $link = Dever::param('link', $data);
  15. $video = $this->decode($link);
  16. if ($video) {
  17. Dever::db('service/video')->update(array('where_id' => $id, 'video' => $video));
  18. }
  19. }
  20. public function showOrderStatus($id)
  21. {
  22. $info = Dever::db('service/order')->one($id);
  23. if ($info) {
  24. if ($info['status'] == 1) {
  25. #return '*已支付';
  26. return '待支付';
  27. } elseif ($info['status'] == 2) {
  28. return '已支付';
  29. } elseif ($info['status'] == 3) {
  30. return '支付失败';
  31. } elseif ($info['status'] == 5) {
  32. $table['状态'] = '已退款';
  33. $manage = Dever::db('manage/admin')->one($info['tk_admin']);
  34. $table['备注'] = $info['tk_desc'];
  35. $table['退款时间'] = date('Y-m-d H:i:s', $info['tk_time']);
  36. $table['操作人'] = $manage['username'];
  37. return Dever::table($table);
  38. }
  39. }
  40. }
  41. /**
  42. * 得到订单时间
  43. *
  44. * @return mixed
  45. */
  46. public function showOrderTime($id)
  47. {
  48. $info = Dever::db('service/order')->one($id);
  49. if ($info) {
  50. $table = array();
  51. $update = array();
  52. $table['订单创建时间'] = date("Y-m-d H:i:s", $info['cdate']);
  53. if (!$info['survey_date']) {
  54. $user = Dever::db('survey/user_answer')->getOldOne(array('order_id' => $id));
  55. if ($user) {
  56. $table['填写问卷时间'] = date("Y-m-d H:i:s", $user['cdate']);
  57. $update['survey_date'] = $user['cdate'];
  58. }
  59. } else {
  60. $table['填写问卷时间'] = date("Y-m-d H:i:s", $info['survey_date']);
  61. }
  62. if ($info['feedback_status'] >= 3) {
  63. if (!$info['survey_end_date']) {
  64. $user = Dever::db('survey/user_answer')->getNewOne(array('order_id' => $id));
  65. if ($user) {
  66. $table['问卷提交时间'] = date("Y-m-d H:i:s", $user['cdate']);
  67. $update['survey_end_date'] = $user['cdate'];
  68. }
  69. } else {
  70. $table['问卷提交时间'] = date("Y-m-d H:i:s", $info['survey_end_date']);
  71. }
  72. }
  73. if ($info['feedback_status'] == 4) {
  74. if (!$info['feedback_date']) {
  75. /*
  76. $feedback = Dever::db('service/feedback')->one(array('order_id' => $id));
  77. if ($feedback) {
  78. $table['反馈问卷时间'] = date("Y-m-d H:i:s", $feedback['cdate']);
  79. $update['feedback_date'] = $feedback['cdate'];
  80. }
  81. */
  82. } else {
  83. $table['反馈问卷时间'] = date("Y-m-d H:i:s", $info['feedback_date']);
  84. }
  85. }
  86. if ($update) {
  87. $update['where_id'] = $id;
  88. Dever::db('service/order')->update($update);
  89. }
  90. return Dever::table($table);
  91. }
  92. return '';
  93. }
  94. # 显示反馈方案的状态
  95. public function showFeedbackStatus($id)
  96. {
  97. $info = Dever::db('service/order')->one($id);
  98. $html = '';
  99. if ($info) {
  100. $config = Dever::db('service/order')->config['feedback_status'];
  101. if (isset($config[$info['feedback_status']])) {
  102. $html = $config[$info['feedback_status']];
  103. }
  104. $info = Dever::db('service/feedback')->one(array('order_id' => $id));
  105. if ($info && $info['pdf']) {
  106. $html .= '<br><a href="javascript:;" onclick="window.open(\''.$info['pdf'].'\')">[查看软装服务设计方案]</a>';
  107. }
  108. }
  109. return $html;
  110. }
  111. /**
  112. * 设计反馈之后,发送短信 (已废弃)
  113. *
  114. * @return mixed
  115. */
  116. public function order($id, $name, $data)
  117. {
  118. # 更改退款状态
  119. $status = Dever::param('status', $data);
  120. $tk_desc = Dever::param('tk_desc', $data);
  121. if ($tk_desc && $tk_desc != 'null') {
  122. $admin = Dever::load('manage/auth.info');
  123. $update['where_id'] = $id;
  124. $update['tk_admin'] = $admin['id'];
  125. $update['tk_time'] = time();
  126. $update['status'] = 5;
  127. Dever::db('service/order')->update($update);
  128. } else {
  129. $update['where_id'] = $id;
  130. $update['status'] = 2;
  131. Dever::db('service/order')->update($update);
  132. }
  133. /*
  134. if ($feedback_status == 2) {
  135. $order = Dever::db('service/order')->one($id);
  136. $user = Dever::db('passport/user')->one($order['id']);
  137. if ($user['mobile'] && $order['order_id']) {
  138. Dever::load('passport/applet')->send($user['mobile'], $order['order_id']);
  139. }
  140. }
  141. */
  142. }
  143. /**
  144. * 完成反馈,发送短信 已废弃
  145. *
  146. * @return mixed
  147. *
  148. public function feedback($id, $name, $data)
  149. {
  150. $order_id = Dever::param('order_id', $data);
  151. $info = Dever::db('service/feedback')->one($id);
  152. $order = Dever::db('service/order')->one($order_id);
  153. $status = Dever::param('status', $data);
  154. if ($status == 1) {
  155. if ($order && $order['feedback_status'] == 3) {
  156. Dever::db('service/order')->update(array('where_id' => $order_id, 'feedback_status' => 4));
  157. $user = Dever::db('passport/user')->one($order['uid']);
  158. if ($user['mobile'] && $order['order_id']) {
  159. $skin = 'order';
  160. # 判断是否二次修改
  161. $sms = Dever::param('sms', $data);
  162. if ($sms == 2) {
  163. $skin = 'feedback';
  164. }
  165. Dever::setInput('skin', $skin);
  166. Dever::load('passport/applet')->send($user['mobile'], $order['order_id']);
  167. }
  168. }
  169. } else {
  170. if ($order) {
  171. Dever::db('service/order')->update(array('where_id' => $order_id, 'feedback_status' => 3));
  172. }
  173. }
  174. # 生成产品的链接
  175. //Dever::daemon('spider/handle.createProduct?id=' . $id, 'service');
  176. //Dever::load('service/spider/handle.createProduct?id=' . $id);
  177. }
  178. */
  179. public function showQuestion($uid, $product_id, $order_id, $feedback_status)
  180. {
  181. $link = Dever::url('api.view&uid='.$uid.'&product_id=' . $product_id . '&order_id=' . $order_id, 'survey');
  182. if ($feedback_status == 1) {
  183. $html = '';
  184. } else {
  185. $html = '<a href="javascript:;" onclick="window.open(\''.$link.'\')">查看</a>';
  186. }
  187. return $html;
  188. }
  189. public function showOrderUser($id)
  190. {
  191. $info = Dever::db('service/order')->one($id);
  192. $table = array();
  193. $user = Dever::db('passport/user')->one($info['uid']);
  194. $table['订单号'] = $info['order_id'];
  195. $table['用户名'] = $user['username'];
  196. $table['手机号'] = $user['mobile'];
  197. $table['产品名'] = $info['name'];
  198. if ($info['type'] == 1) {
  199. $table['支付方式'] = '购买';
  200. $table['支付金额'] = $info['cash'];
  201. } else {
  202. $table['支付方式'] = '兑换';
  203. $table['兑换码'] = $info['code'];
  204. }
  205. $feedback = Dever::db('service/feedback')->one(array('order_id' => $id));
  206. if($feedback && $feedback['num']) {
  207. $table['用户评分'] = $feedback['num'];
  208. if ($feedback['msg']) {
  209. $table['用户建议'] = $feedback['msg'];
  210. }
  211. }
  212. return Dever::table($table);
  213. }
  214. /**
  215. * 导出成excel
  216. *
  217. * @return mixed
  218. */
  219. public function out_api()
  220. {
  221. $product = Dever::db('service/product')->state();
  222. $header = array();
  223. foreach ($product as $k => $v) {
  224. $product[$k]['answer'] = array();
  225. $product[$k]['data'] = array();
  226. $product[$k]['header'] = array();
  227. $product[$k]['header'][0] = '订单号';
  228. $product[$k]['question'] = array
  229. (
  230. 0 => array
  231. (
  232. 'id' => 0,
  233. 'name' => $product[$k]['header'][0],
  234. ),
  235. );
  236. $product[$k]['question'] += Dever::db('survey/info')->getData(array('product_id' => $v['id']));
  237. if ($product[$k]['question']) {
  238. foreach ($product[$k]['question'] as $k1 => $v1) {
  239. if (isset($v1['type'])) {
  240. if ($v1['type'] == 12 || $v1['type'] == 13) {
  241. $product[$k]['question'][$k1]['content'] = Dever::array_decode($v1['content']);
  242. } else {
  243. $product[$k]['question'][$k1]['content'] = array();
  244. }
  245. }
  246. $product[$k]['header'][$k1] = $v1['name'];
  247. }
  248. }
  249. $tjr = -10000;
  250. $product[$k]['header'][$tjr] = '提交人';
  251. $product[$k]['question'][$tjr] = array
  252. (
  253. 'id' => $tjr,
  254. 'name' => $product[$k]['header'][$tjr],
  255. );
  256. $tjsj = $tjr + 1;
  257. $product[$k]['header'][$tjsj] = '提交时间';
  258. $product[$k]['question'][$tjsj] = array
  259. (
  260. 'id' => $tjsj,
  261. 'name' => $product[$k]['header'][$tjsj]
  262. );
  263. $where['product_id'] = $v['id'];
  264. $where['feedback_status'] = 3;
  265. $product[$k]['order'] = Dever::db('service/order')->getYes($where);
  266. if ($product[$k]['order']) {
  267. foreach ($product[$k]['order'] as $k1 => $v1) {
  268. $user = Dever::db('passport/user')->one($v1['uid']);
  269. $answer = Dever::db('survey/user_answer')->getData(array('uid' => $v1['uid'], 'product_id' => $v['id'], 'order_id' => $v1['id']));
  270. if ($answer) {
  271. $product[$k]['answer'][$k1][0] = $v1['order_id'] ? $v1['order_id'] : $v1['id'];
  272. $product[$k]['order'][$k1]['answer'][0] = $product[$k]['answer'][$k1][0];
  273. $time = '';
  274. foreach ($answer as $k2 => $v2) {
  275. $product[$k]['answer'][$k1][$v2['info_id']] = $v2['value'];
  276. if (isset($product[$k]['question'][$v2['info_id']]['content']) && $product[$k]['question'][$v2['info_id']]['content']) {
  277. $temp = explode(',', $v2['value']);
  278. $vvn = array();
  279. $vvp = array();
  280. foreach ($temp as $k3 => $v3) {
  281. $d3 = '';
  282. if (strstr($v3, '$$$')) {
  283. $t11 = explode('$$$', $v3);
  284. $v3 = $t11[0];
  285. $d3 = $t11[1];
  286. }
  287. $v3 = $v3-1;
  288. if (isset($product[$k]['question'][$v2['info_id']]['content'][$v3])) {
  289. $t1 = $product[$k]['question'][$v2['info_id']]['content'][$v3];
  290. if (isset($t1['desc']) && $t1['desc']) {
  291. $t1['title'] .= '('.$t1['desc'].')';
  292. }
  293. $vvn[$k3] = $t1['title'];
  294. if (isset($t1['pic']) && $t1['pic']) {
  295. $vvp[$k3] = $t1['pic'];
  296. }
  297. if ($d3) {
  298. $vvn[$k3] .= ':' . $d3;
  299. }
  300. }
  301. }
  302. $product[$k]['answer'][$k1][$v2['info_id']] = implode("\r\n", $vvn);
  303. if ($vvp) {
  304. $product[$k]['answer'][$k1][$v2['info_id']] .= '||' . implode(',', $vvp);
  305. }
  306. }
  307. $product[$k]['order'][$k1]['answer'][$v2['info_id']] = $product[$k]['answer'][$k1][$v2['info_id']];
  308. $time = date('Y-m-d H:i', $v2['cdate']);
  309. }
  310. $product[$k]['answer'][$k1][$tjr] = $user['username'];
  311. $product[$k]['order'][$k1]['answer'][$tjr] = $product[$k]['answer'][$k1][$tjr];
  312. $product[$k]['answer'][$k1][$tjsj] = $time;
  313. $product[$k]['order'][$k1]['answer'][$tjsj] = $product[$k]['answer'][$k1][$tjsj];
  314. foreach ($product[$k]['header'] as $k4 => $v4) {
  315. if (isset($product[$k]['answer'][$k1][$k4])) {
  316. $product[$k]['data'][$k1][$k4] = $product[$k]['answer'][$k1][$k4];
  317. } else {
  318. $product[$k]['data'][$k1][$k4] = '';
  319. }
  320. }
  321. }
  322. }
  323. }
  324. }
  325. $time = date('Y-m-d H:i');
  326. $name = '订单列表';
  327. $file = $time . '_' . $name;
  328. $test = Dever::input('test');
  329. $sheet = 0;
  330. $xls = true;
  331. if ($test == 1) {
  332. print_r($product);die;
  333. }
  334. //
  335. foreach ($product as $k => $v) {
  336. $header = $v['header'];
  337. $data = $v['data'];
  338. $sheetName = $v['name'];
  339. $xls = Dever::excelExport($data, $header, $file, $sheet, $sheetName, $xls);
  340. $sheet++;
  341. }
  342. Dever::excelExport(false, false, $file, 0, false, $xls);
  343. die;
  344. if (!$test) {
  345. ob_get_clean();
  346. ob_start();
  347. $data = Dever::render('excel', array('product' => $product));
  348. echo $data;
  349. header('Content-Disposition: attachment; filename='.$file . '.xls');
  350. header('Accept-Ranges:bytes');
  351. header('Content-Length:' . ob_get_length());
  352. header('Content-Type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  353. ob_end_flush();
  354. die;
  355. }
  356. if ($test == 1) {
  357. return Dever::render('excel', array('product' => $product));
  358. } elseif ($test == 2) {
  359. print_r($product);die;
  360. }
  361. return;
  362. $where['feedback_status'] = 3;
  363. $order = Dever::db('service/order')->getYes($where);
  364. $i = 0;
  365. foreach ($order as $k => $v) {
  366. if ($v && $v['uid']) {
  367. $product = Dever::db('service/product')->one($v['product_id']);
  368. $user = Dever::db('passport/user')->one($v['uid']);
  369. $v['content'] = $this->question(Dever::load('survey/api.view', $v['uid'], $v['product_id'], $v['id'], true));
  370. if ($v['type'] == 1) {
  371. $v['status'] = '已购买';
  372. } else {
  373. $v['status'] = '已兑换';
  374. $v['cash'] = $v['code'];
  375. }
  376. $data[$i] = array
  377. (
  378. $v['order_id'],
  379. $product['name'],
  380. $user['username'],
  381. $user['mobile'],
  382. $v['status'],
  383. $v['cash'],
  384. $v['content'],
  385. );
  386. $i++;
  387. }
  388. }
  389. $header = array
  390. (
  391. '订单号', '产品名', '用户名', '用户手机号', '支付状态', '支付金额/兑换码', '问卷内容'
  392. );
  393. $time = date('Y-m-d H:i');
  394. $name = '订单列表';
  395. $file = $time . '_' . $name;
  396. $test = Dever::input('test');
  397. if (!$test) {
  398. header('Content-Type: application/vnd.ms-excel');
  399. header('Content-Disposition: attachment;filename="'.$file.'.xls"');
  400. header('Cache-Control: max-age=0');
  401. }
  402. if ($test == 1) {
  403. return Dever::render('excel', array('header' => $header, 'data' => $data));
  404. } elseif ($test == 2) {
  405. print_r($header);
  406. print_r($data);die;
  407. }
  408. //Dever::excelExport($data, $header, $file, $sheet = 0, $sheetName = $name);
  409. return;
  410. }
  411. private function question($data)
  412. {
  413. $html = array();
  414. if (isset($data['question'])) {
  415. foreach ($data['question'] as $k => $v) {
  416. $html[$k] = '第' . $k . '题' . '、'. $v['name'];
  417. if (isset($v['content']) && $v['content']) {
  418. if (is_numeric($v['answer']) && $v['answer'] != '未作答') {
  419. $temp = explode(',', $v['answer']);
  420. $html[$k] .= "<br/>" . '答:';
  421. $j = 0;
  422. foreach ($temp as $k1 => $v1) {
  423. $v1 = $v1 - 1;
  424. if ($j > 0) {
  425. $html[$k] .= '、';
  426. }
  427. if (isset($v['content'][$v1]) && $v['content'][$v1]) {
  428. $html[$k] .= $v['content'][$v1]['title'];
  429. if (isset($v['content'][$v1]['desc']) && $v['content'][$v1]['desc']) {
  430. $html[$k] .= '(' . $v['content'][$v1]['desc'] . ')';
  431. }
  432. $j++;
  433. }
  434. }
  435. }
  436. } else {
  437. $html[$k] .= "<br/>" . '答:' . $v['answer'];
  438. }
  439. }
  440. $html = implode("<br/>", $html);
  441. }
  442. return $html;
  443. }
  444. # 发送方案 并发送短信
  445. public function sendFeedback_api()
  446. {
  447. $id = Dever::input('id');
  448. $order = Dever::db('service/order')->one($id);
  449. if ($order) {
  450. $info = Dever::db('service/feedback')->one(array('order_id' => $id));
  451. $status = 1;
  452. if ($status == 1) {
  453. if ($order['feedback_status'] == 3) {
  454. Dever::db('service/order')->update(array('where_id' => $id, 'feedback_status' => 4, 'feedback_date' => time()));
  455. $user = Dever::db('passport/user')->one($order['uid']);
  456. if ($user['mobile'] && $order['order_id']) {
  457. $skin = 'order';
  458. Dever::setInput('skin', $skin);
  459. Dever::load('passport/applet')->send($user['mobile'], $order['order_id']);
  460. }
  461. }
  462. } else {
  463. if ($order) {
  464. Dever::db('service/order')->update(array('where_id' => $order_id, 'feedback_status' => 3));
  465. }
  466. }
  467. }
  468. Dever::alert('发送成功');
  469. }
  470. # 发送短信
  471. public function sendFeedbackSms_api()
  472. {
  473. $id = Dever::input('id');
  474. $order = Dever::db('service/order')->one($id);
  475. if ($order && $order['feedback_status'] == 4) {
  476. $user = Dever::db('passport/user')->one($order['uid']);
  477. if ($user['mobile'] && $order['order_id']) {
  478. $skin = 'feedback';
  479. Dever::setInput('skin', $skin);
  480. Dever::load('passport/applet')->send($user['mobile'], $order['order_id']);
  481. }
  482. }
  483. Dever::alert('发送成功');
  484. }
  485. }