Excel.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. namespace Active\Lib;
  3. use Dever;
  4. Class Excel {
  5. #活动订单的导出
  6. public function out_active_order($data){
  7. $header = array('订单单号', '姓名', '手机号', '活动名称', '购买数量', '使用数量','待核销数量','已核销数量','金额', '已退款数量', '已退款金额','支付状态', '支付类型','购买时间');
  8. $body = array();
  9. foreach ($data as $k => $v){
  10. $user = Dever::db('active/user')->find($v['uid']);
  11. $member = Dever::load('active/lib/user')->agent($user);
  12. $active = Dever::db('active/info')->find($v['active_id']);
  13. $member_name = '';
  14. $member_mobile = '';
  15. if($user){
  16. $member_name = $user['name'];
  17. $member_mobile = $user['mobile'];
  18. }
  19. $active_name = '';
  20. if($active && $active['name']){
  21. $active_name = $active['name'];
  22. }
  23. $config_status = Dever::db('active/order')->config['config_status'];
  24. $status = Dever::status($config_status,$v['status']);
  25. $config_pay_type = Dever::db('active/order')->config['config_pay_type'];
  26. $pay_type = Dever::status($config_pay_type,$v['pay_type']);
  27. $cdate = '';
  28. if($v['cdate']){
  29. $cdate = date('Y-m-d H:i',$v['cdate']);
  30. }
  31. $code_num = '';
  32. if ($v['code_num']<0){
  33. $code_num = 0;
  34. } else {
  35. $code_num = $v['code_num'];
  36. }
  37. $yhecode = Dever::db('active/code')->getExcel(array('order_id' => $v['id'],'status'=>2));
  38. $dhecode = Dever::db('active/code')->getExcel(array('order_id' => $v['id'],'status'=>1));
  39. $tui_num = 0;
  40. if ($v['refund_num']) {
  41. $tui_num = $v['refund_num'];
  42. }
  43. $tui_money = 0;
  44. $tui = Dever::db('active/info_refund')->getEmoney(array('order_id'=>$v['id'],'status'=>2));
  45. if ($tui && isset($tui['price']) && $tui['price']) {
  46. $tui_money = $tui['price'];
  47. }
  48. $d = array
  49. (
  50. $v['order_num'],
  51. $member_name,
  52. $member_mobile,
  53. $active_name,
  54. $v['num'],
  55. $code_num,
  56. $dhecode,
  57. $yhecode,
  58. $v['price'],
  59. $tui_num,
  60. $tui_money,
  61. $status,
  62. $pay_type,
  63. $cdate,
  64. );
  65. $body[] = $d;
  66. }
  67. $file = Dever::input('excel_name');
  68. return Dever::excelExport($body, $header, $file);
  69. }
  70. #活动核销码导出
  71. public function out_active_code($data)
  72. {
  73. $header = array('活动名称', '参加人姓名', '参加人手机号', '购买人姓名', '购买人手机号', '领取日期','座位号','核销状态');
  74. $body = array();
  75. foreach ($data as $k => $v) {
  76. $active_name = '';
  77. if ($v['active_id']) {
  78. $active = Dever::db('active/info')->find($v['active_id']);
  79. $active_name = $active['name'];
  80. }
  81. $join_name = '';
  82. $join_mobile = '';
  83. if ($v['join_uid']) {
  84. $user = Dever::db('active/user')->find($v['join_uid']);
  85. if ($user){
  86. $join_name = $user['name'];
  87. $join_mobile = $user['mobile'];
  88. }
  89. }
  90. $buy_name = '';
  91. $buy_mobile = '';
  92. if ($v['buy_uid']) {
  93. $user = Dever::db('active/user')->find($v['buy_uid']);
  94. if ($user){
  95. $buy_name = $user['name'];
  96. $buy_mobile = $user['mobile'];
  97. }
  98. }
  99. $cdate = '';
  100. if ($v['cdate']) {
  101. $cdate = date('Y-m-d H:i:s',$v['cdate']);
  102. }
  103. $seat_num = '';
  104. if ($v['seat_num']) {
  105. $seat_num = $v['seat_num'];
  106. }
  107. $status_name = '';
  108. if ($v['status'] == 1) {
  109. $status_name = '待核销';
  110. } elseif ($v['status'] == 2) {
  111. $status_name = '已核销';
  112. } elseif ($v['status'] == 3) {
  113. $status_name = '已作废';
  114. }
  115. $d = array
  116. (
  117. $active_name,
  118. $join_name,
  119. $join_mobile,
  120. $buy_name,
  121. $buy_mobile,
  122. $cdate,
  123. $seat_num,
  124. $status_name,
  125. );
  126. $body[] = $d;
  127. }
  128. $file = Dever::input('excel_name');
  129. return Dever::excelExport($body, $header, $file);
  130. }
  131. public function import($file)
  132. {
  133. $file = Dever::local($file);
  134. $data = Dever::excelImport($file,0);
  135. // print_R($data);die;
  136. if ($data) {
  137. $res = array();
  138. foreach($data as $k=>$v){
  139. if ($k>=2) {
  140. $active_name = $v['A'];
  141. $mobile = trim($v['C']);
  142. // $seat_num = $v['G'];
  143. if (isset($v['G']) && $v['G']) {
  144. $active = Dever::db('active/info')->find(array('name'=>$active_name));
  145. $user = Dever::db('active/user')->find(array('mobile'=>$mobile));
  146. $code = Dever::db('active/code')->find(array('active_id'=>$active['id'],'join_uid'=>$user['id']));
  147. $where['where_id'] = $code['id'];
  148. $where['seat_num'] = $v['G'];
  149. Dever::db('active/code')->update($where);
  150. }
  151. }
  152. }
  153. }
  154. }
  155. public function info_off($file)
  156. {
  157. $file = Dever::local($file);
  158. $data = Dever::excelImport($file,0);
  159. if ($data) {
  160. $res = array();
  161. foreach ($data as $k => $v) {
  162. if ($k >= 2) {
  163. $where['name'] = $v['A'];
  164. $where['mobile'] = $v['B'];
  165. if ($where['mobile']) {
  166. $where['pass'] = substr($where['mobile'],-6);
  167. }
  168. $info = Dever::db('active/info_off')->find(array('mobile'=>$where['mobile'],'clear'=>true));
  169. if (!$info){
  170. Dever::db('active/info_off')->insert($where);
  171. } else {
  172. if ($info && $info['pass'] != sha1(substr($info['mobile'],-6))) {
  173. $w['where_id'] = $info['id'];
  174. $w['pass'] = substr($info['mobile'],-6);
  175. Dever::db('active/info_off')->update($w);
  176. }
  177. }
  178. }
  179. }
  180. }
  181. }
  182. }