bill.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. <?php
  2. /**
  3. * 结算管理
  4. *
  5. *
  6. *
  7. ***/
  8. defined('InShopNC') or exit('Access Invalid!');
  9. class billControl extends SystemControl{
  10. /**
  11. * 每次导出订单数量
  12. * @var int
  13. */
  14. const EXPORT_SIZE = 1000;
  15. private $links = array(
  16. array('url'=>'act=bill&op=index','lang'=>'nc_manage'),
  17. );
  18. public function __construct(){
  19. parent::__construct();
  20. }
  21. /**
  22. * 所有月份销量账单
  23. *
  24. */
  25. public function indexOp(){
  26. //检查是否需要生成上月及更早结算单的程序不再执行,执行量较大,放到任务计划中触发
  27. $condition = array();
  28. if (preg_match('/^\d{4}$/',$_GET['query_year'],$match)) {
  29. $condition['os_year'] = $_GET['query_year'];
  30. }
  31. $model_bill = Model('bill');
  32. $bill_list = $model_bill->getOrderStatisList($condition,'*',12,'os_month desc');
  33. Tpl::output('bill_list',$bill_list);
  34. Tpl::output('show_page',$model_bill->showpage());
  35. //输出子菜单
  36. Tpl::output('top_link',$this->sublink($this->links,'index'));
  37. Tpl::showpage('bill_order_statis.index');
  38. }
  39. /**
  40. * 某月所有店铺销量账单
  41. *
  42. */
  43. public function show_statisOp(){
  44. if (!empty($_GET['os_month']) && !preg_match('/^20\d{4}$/',$_GET['os_month'],$match)) {
  45. showMessage('参数错误','','html','error');
  46. }
  47. $model_bill = Model('bill');
  48. $condtion = array();
  49. if (!empty($_GET['os_month'])) {
  50. $condition['os_month'] = intval($_GET['os_month']);
  51. }
  52. if (is_numeric($_GET['bill_state'])) {
  53. $condition['ob_state'] = intval($_GET['bill_state']);
  54. }
  55. if (preg_match('/^\d{1,8}$/',$_GET['query_store'])) {
  56. $condition['ob_store_id'] = $_GET['query_store'];
  57. }elseif ($_GET['query_store'] != ''){
  58. $condition['ob_store_name'] = $_GET['query_store'];
  59. }
  60. $bill_list = $model_bill->getOrderBillList($condition,'*',30,'ob_no desc');
  61. Tpl::output('bill_list',$bill_list);
  62. Tpl::output('show_page',$model_bill->showpage());
  63. //输出子菜单
  64. Tpl::output('top_link',$this->sublink($this->links,'index'));
  65. Tpl::showpage('bill_order_statis.show');
  66. }
  67. /**
  68. * 某店铺某月订单列表
  69. *
  70. */
  71. public function show_billOp(){
  72. if (!preg_match('/^20\d{5,12}$/',$_GET['ob_no'],$match)) {
  73. showMessage('参数错误','','html','error');
  74. }
  75. $model_bill = Model('bill');
  76. $bill_info = $model_bill->getOrderBillInfo(array('ob_no'=>$_GET['ob_no']));
  77. if (!$bill_info){
  78. showMessage('参数错误','','html','error');
  79. }
  80. $order_condition = array();
  81. $order_condition['order_state'] = ORDER_STATE_SUCCESS;
  82. $order_condition['store_id'] = $bill_info['ob_store_id'];
  83. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/',$_GET['query_start_date']);
  84. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/',$_GET['query_end_date']);
  85. $start_unixtime = $if_start_date ? strtotime($_GET['query_start_date']) : null;
  86. $end_unixtime = $if_end_date ? strtotime($_GET['query_end_date']) : null;
  87. $end_unixtime = $if_end_date ? $end_unixtime+86400-1 : null;
  88. if ($if_start_date || $if_end_date) {
  89. $order_condition['finnshed_time'] = array('between',"{$start_unixtime},{$end_unixtime}");
  90. } else {
  91. $order_condition['finnshed_time'] = array('between',"{$bill_info['ob_start_date']},{$bill_info['ob_end_date']}");
  92. }
  93. if ($_GET['query_type'] == 'refund') {
  94. //退款订单列表
  95. $model_refund = Model('refund_return');
  96. $refund_condition = array();
  97. $refund_condition['seller_state'] = 2;
  98. $refund_condition['store_id'] = $bill_info['ob_store_id'];
  99. $refund_condition['goods_id'] = array('gt',0);
  100. $refund_condition['admin_time'] = $order_condition['finnshed_time'];
  101. $refund_list = $model_refund->getRefundReturnList($refund_condition,20,'*,ROUND(refund_amount*commis_rate/100,2) as commis_amount');
  102. if (is_array($refund_list) && count($refund_list) == 1 && $refund_list[0]['refund_id'] == '') {
  103. $refund_list = array();
  104. }
  105. //取返还佣金
  106. Tpl::output('refund_list',$refund_list);
  107. Tpl::output('show_page',$model_refund->showpage());
  108. $sub_tpl_name = 'bill_order_bill.show.refund_list';
  109. } elseif ($_GET['query_type'] == 'cost') {
  110. //店铺费用
  111. $model_store_cost = Model('store_cost');
  112. $cost_condition = array();
  113. $cost_condition['cost_store_id'] = $bill_info['ob_store_id'];
  114. $cost_condition['cost_time'] = $order_condition['finnshed_time'];
  115. $store_cost_list = $model_store_cost->getStoreCostList($cost_condition,20);
  116. //取得店铺名字
  117. $store_info = Model('store')->getStoreInfoByID($bill_info['ob_store_id']);
  118. Tpl::output('cost_list',$store_cost_list);
  119. Tpl::output('store_info',$store_info);
  120. Tpl::output('show_page',$model_store_cost->showpage());
  121. $sub_tpl_name = 'bill_order_bill.show.cost_list';
  122. } else {
  123. //订单列表
  124. $model_order = Model('order');
  125. $order_list = $model_order->getOrderList($order_condition,20);
  126. //然后取订单商品佣金
  127. $order_id_array = array();
  128. if (is_array($order_list)) {
  129. foreach ($order_list as $order_info) {
  130. $order_id_array[] = $order_info['order_id'];
  131. }
  132. }
  133. $order_goods_condition = array();
  134. $order_goods_condition['order_id'] = array('in',$order_id_array);
  135. $field = 'SUM(ROUND(goods_pay_price*commis_rate/100,2)) as commis_amount,order_id';
  136. $commis_list = $model_order->getOrderGoodsList($order_goods_condition,$field,null,null,'','order_id','order_id');
  137. Tpl::output('commis_list',$commis_list);
  138. Tpl::output('order_list',$order_list);
  139. Tpl::output('show_page',$model_order->showpage());
  140. $sub_tpl_name = 'bill_order_bill.show.order_list';
  141. }
  142. Tpl::output('tpl_name',$sub_tpl_name);
  143. Tpl::output('bill_info',$bill_info);
  144. Tpl::showpage('bill_order_bill.show');
  145. }
  146. public function bill_checkOp(){
  147. if (!preg_match('/^20\d{5,12}$/',$_GET['ob_no'])) {
  148. showMessage('参数错误','','html','error');
  149. }
  150. $model_bill = Model('bill');
  151. $condition = array();
  152. $condition['ob_no'] = $_GET['ob_no'];
  153. $condition['ob_state'] = BILL_STATE_STORE_COFIRM;
  154. $update = $model_bill->editOrderBill(array('ob_state'=>BILL_STATE_SYSTEM_CHECK),$condition);
  155. if ($update){
  156. $this->log('审核账单,账单号:'.$_GET['ob_no'],1);
  157. showMessage('审核成功,账单进入付款环节');
  158. }else{
  159. $this->log('审核账单,账单号:'.$_GET['ob_no'],0);
  160. showMessage('审核失败','','html','error');
  161. }
  162. }
  163. /**
  164. * 账单付款
  165. *
  166. */
  167. public function bill_payOp(){
  168. if (!preg_match('/^20\d{5,12}$/',$_GET['ob_no'])) {
  169. showMessage('参数错误','','html','error');
  170. }
  171. $model_bill = Model('bill');
  172. $condition = array();
  173. $condition['ob_no'] = $_GET['ob_no'];
  174. $condition['ob_state'] = BILL_STATE_SYSTEM_CHECK;
  175. $bill_info = $model_bill->getOrderBillInfo($condition);
  176. if (!$bill_info){
  177. showMessage('参数错误','','html','error');
  178. }
  179. if (chksubmit()){
  180. if (!preg_match('/^20\d{2}-\d{2}-\d{2}$/',$_POST['pay_date'])) {
  181. showMessage('参数错误','','html','error');
  182. }
  183. $input = array();
  184. $input['ob_pay_content'] = $_POST['pay_content'];
  185. $input['ob_pay_date'] = strtotime($_POST['pay_date']);
  186. $input['ob_state'] = BILL_STATE_SUCCESS;
  187. $update = $model_bill->editOrderBill($input,$condition);
  188. if ($update){
  189. $model_store_cost = Model('store_cost');
  190. $cost_condition = array();
  191. $cost_condition['cost_store_id'] = $bill_info['ob_store_id'];
  192. $cost_condition['cost_state'] = 0;
  193. $cost_condition['cost_time'] = array('between',"{$bill_info['ob_start_date']},{$bill_info['ob_end_date']}");
  194. $model_store_cost->editStoreCost(array('cost_state'=>1),$cost_condition);
  195. // 发送店铺消息
  196. $param = array();
  197. $param['code'] = 'store_bill_gathering';
  198. $param['store_id'] = $bill_info['ob_store_id'];
  199. $param['param'] = array(
  200. 'bill_no' => $bill_info['ob_no']
  201. );
  202. QueueClient::push('sendStoreMsg', $param);
  203. $this->log('账单付款,账单号:'.$_GET['ob_no'],1);
  204. showMessage('保存成功','index.php?act=bill&op=show_statis&os_month='.$bill_info['os_month']);
  205. }else{
  206. $this->log('账单付款,账单号:'.$_GET['ob_no'],1);
  207. showMessage('保存失败','','html','error');
  208. }
  209. }else{
  210. Tpl::showpage('bill.pay');
  211. }
  212. }
  213. /**
  214. * 打印结算单
  215. *
  216. */
  217. public function bill_printOp(){
  218. if (!preg_match('/^20\d{5,12}$/',$_GET['ob_no'])) {
  219. showMessage('参数错误','','html','error');
  220. }
  221. $model_bill = Model('bill');
  222. $condition = array();
  223. $condition['ob_no'] = $_GET['ob_no'];
  224. $condition['ob_state'] = BILL_STATE_SUCCESS;
  225. $bill_info = $model_bill->getOrderBillInfo($condition);
  226. if (!$bill_info){
  227. showMessage('参数错误','','html','error');
  228. }
  229. Tpl::output('bill_info',$bill_info);
  230. Tpl::showpage('bill.print','null_layout');
  231. }
  232. /**
  233. * 导出平台月出账单表
  234. *
  235. */
  236. public function export_billOp(){
  237. if (!empty($_GET['os_month']) && !preg_match('/^20\d{4}$/',$_GET['os_month'],$match)) {
  238. showMessage('参数错误','','html','error');
  239. }
  240. $model_bill = Model('bill');
  241. $condition = array();
  242. if (!empty($_GET['os_month'])) {
  243. $condition['os_month'] = intval($_GET['os_month']);
  244. }
  245. if (is_numeric($_GET['bill_state'])) {
  246. $condition['ob_state'] = intval($_GET['bill_state']);
  247. }
  248. if (preg_match('/^\d{1,8}$/',$_GET['query_store'])) {
  249. $condition['ob_store_id'] = $_GET['query_store'];
  250. }elseif ($_GET['query_store'] != ''){
  251. $condition['ob_store_name'] = $_GET['query_store'];
  252. }
  253. if (!is_numeric($_GET['curpage'])){
  254. $count = $model_bill->getOrderBillCount($condition);
  255. $array = array();
  256. if ($count > self::EXPORT_SIZE ){
  257. //显示下载链接
  258. $page = ceil($count/self::EXPORT_SIZE);
  259. for ($i=1;$i<=$page;$i++){
  260. $limit1 = ($i-1)*self::EXPORT_SIZE + 1;
  261. $limit2 = $i*self::EXPORT_SIZE > $count ? $count : $i*self::EXPORT_SIZE;
  262. $array[$i] = $limit1.' ~ '.$limit2 ;
  263. }
  264. Tpl::output('list',$array);
  265. Tpl::output('murl','index.php?act=bill&op=index');
  266. Tpl::showpage('export.excel');
  267. exit();
  268. }else{
  269. //如果数量小,直接下载
  270. $data = $model_bill->getOrderBillList($condition,'*','','ob_no desc',self::EXPORT_SIZE);
  271. }
  272. }else{
  273. //下载
  274. $limit1 = ($_GET['curpage']-1) * self::EXPORT_SIZE;
  275. $limit2 = self::EXPORT_SIZE;
  276. $data = $model_bill->getOrderBillList($condition,'*','','ob_no desc',"{$limit1},{$limit2}");
  277. }
  278. $export_data = array();
  279. $export_data[0] = array('账单编号','开始日期','结束日期','订单金额','运费','佣金金额','退款金额','退还佣金','店铺费用','本期应结','出账日期','账单状态','店铺','店铺ID');
  280. $ob_order_totals = 0;
  281. $ob_shipping_totals = 0;
  282. $ob_commis_totals = 0;
  283. $ob_order_return_totals = 0;
  284. $ob_commis_return_totals = 0;
  285. $ob_store_cost_totals = 0;
  286. $ob_result_totals = 0;
  287. foreach ($data as $k => $v) {
  288. $export_data[$k+1][] = $v['ob_no'];
  289. $export_data[$k+1][] = date('Y-m-d',$v['ob_start_date']);
  290. $export_data[$k+1][] = date('Y-m-d',$v['ob_end_date']);
  291. $ob_order_totals += $export_data[$k+1][] = $v['ob_order_totals'];
  292. $ob_shipping_totals += $export_data[$k+1][] = $v['ob_shipping_totals'];
  293. $ob_commis_totals += $export_data[$k+1][] = $v['ob_commis_totals'];
  294. $ob_order_return_totals += $export_data[$k+1][] = $v['ob_order_return_totals'];
  295. $ob_commis_return_totals += $export_data[$k+1][] = $v['ob_commis_return_totals'];
  296. $ob_store_cost_totals += $export_data[$k+1][] = $v['ob_store_cost_totals'];
  297. $ob_result_totals += $export_data[$k+1][] = $v['ob_result_totals'];
  298. $export_data[$k+1][] = date('Y-m-d',$v['ob_create_date']);
  299. $export_data[$k+1][] = billState($v['ob_state']);
  300. $export_data[$k+1][] = $v['ob_store_name'];
  301. $export_data[$k+1][] = $v['ob_store_id'];
  302. }
  303. $count = count($export_data);
  304. $export_data[$count][] = '';
  305. $export_data[$count][] = '';
  306. $export_data[$count][] = '合计';
  307. $export_data[$count][] = $ob_order_totals;
  308. $export_data[$count][] = $ob_shipping_totals;
  309. $export_data[$count][] = $ob_commis_totals;
  310. $export_data[$count][] = $ob_order_return_totals;
  311. $export_data[$count][] = $ob_commis_return_totals;
  312. $export_data[$count][] = $ob_store_cost_totals;
  313. $export_data[$count][] = $ob_result_totals;
  314. $csv = new Csv();
  315. $export_data = $csv->charset($export_data,CHARSET,'gbk');
  316. $csv->filename = $csv->charset('账单-',CHARSET).$_GET['os_month'];
  317. $csv->export($export_data);
  318. }
  319. /**
  320. * 导出结算订单明细CSV
  321. *
  322. */
  323. public function export_orderOp(){
  324. if (!preg_match('/^20\d{5,12}$/',$_GET['ob_no'])) {
  325. showMessage('参数错误','','html','error');
  326. }
  327. $model_bill = Model('bill');
  328. $bill_info = $model_bill->getOrderBillInfo(array('ob_no'=>$_GET['ob_no']));
  329. if (!$bill_info){
  330. showMessage('参数错误','','html','error');
  331. }
  332. $model_order = Model('order');
  333. $condition = array();
  334. $condition['order_state'] = ORDER_STATE_SUCCESS;
  335. $condition['store_id'] = $bill_info['ob_store_id'];
  336. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/',$_GET['query_start_date']);
  337. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/',$_GET['query_end_date']);
  338. $start_unixtime = $if_start_date ? strtotime($_GET['query_start_date']) : null;
  339. $end_unixtime = $if_end_date ? strtotime($_GET['query_end_date']) : null;
  340. $end_unixtime = $if_end_date ? $end_unixtime+86400-1 : null;
  341. if ($if_start_date || $if_end_date) {
  342. $condition['finnshed_time'] = array('between',"{$start_unixtime},{$end_unixtime}");
  343. } else {
  344. $condition['finnshed_time'] = array('between',"{$bill_info['ob_start_date']},{$bill_info['ob_end_date']}");
  345. }
  346. if (!is_numeric($_GET['curpage'])){
  347. $count = $model_order->getOrderCount($condition);
  348. $array = array();
  349. if ($count > self::EXPORT_SIZE ){
  350. //显示下载链接
  351. $page = ceil($count/self::EXPORT_SIZE);
  352. for ($i=1;$i<=$page;$i++){
  353. $limit1 = ($i-1)*self::EXPORT_SIZE + 1;
  354. $limit2 = $i*self::EXPORT_SIZE > $count ? $count : $i*self::EXPORT_SIZE;
  355. $array[$i] = $limit1.' ~ '.$limit2 ;
  356. }
  357. Tpl::output('list',$array);
  358. Tpl::output('murl','index.php?act=bill&op=show_bill&ob_no='.$_GET['ob_no']);
  359. Tpl::showpage('export.excel');
  360. exit();
  361. }else{
  362. //如果数量小,直接下载
  363. $data = $model_order->getOrderList($condition,'','*','order_id desc',self::EXPORT_SIZE,array('order_goods'));
  364. }
  365. }else{
  366. //下载
  367. $limit1 = ($_GET['curpage']-1) * self::EXPORT_SIZE;
  368. $limit2 = self::EXPORT_SIZE;
  369. $data = $model_order->getOrderList($condition,'','*','order_id desc',"{$limit1},{$limit2}",array('order_goods'));
  370. }
  371. //订单商品表查询条件
  372. $order_id_array = array();
  373. if (is_array($data)) {
  374. foreach ($data as $order_info) {
  375. $order_id_array[] = $order_info['order_id'];
  376. }
  377. }
  378. $order_goods_condition = array();
  379. $order_goods_condition['order_id'] = array('in',$order_id_array);
  380. $export_data = array();
  381. $export_data[0] = array('订单编号','订单金额','运费','佣金','下单日期','成交日期','商家','商家编号','买家','买家编号','商品');
  382. $order_totals = 0;
  383. $shipping_totals = 0;
  384. $commis_totals = 0;
  385. $k = 0;
  386. foreach ($data as $v) {
  387. //该订单算佣金
  388. $field = 'SUM(ROUND(goods_pay_price*commis_rate/100,2)) as commis_amount,order_id';
  389. $commis_list = $model_order->getOrderGoodsList($order_goods_condition,$field,null,null,'','order_id','order_id');
  390. $export_data[$k+1][] = 'NC'.$v['order_sn'];
  391. $order_totals += $export_data[$k+1][] = $v['order_amount'];
  392. $shipping_totals += $export_data[$k+1][] = $v['shipping_fee'];
  393. $commis_totals += $export_data[$k+1][] = floatval($commis_list[$v['order_id']]['commis_amount']);
  394. $export_data[$k+1][] = date('Y-m-d',$v['add_time']);
  395. $export_data[$k+1][] = date('Y-m-d',$v['finnshed_time']);
  396. $export_data[$k+1][] = $v['store_name'];
  397. $export_data[$k+1][] = $v['store_id'];
  398. $export_data[$k+1][] = $v['buyer_name'];
  399. $export_data[$k+1][] = $v['buyer_id'];
  400. $goods_string = '';
  401. if (is_array($v['extend_order_goods'])) {
  402. foreach ($v['extend_order_goods'] as $v) {
  403. $goods_string .= $v['goods_name'].'|单价:'.$v['goods_price'].'|数量:'.$v['goods_num'].'|实际支付:'.$v['goods_pay_price'].'|佣金比例:'.$v['commis_rate'].'%';
  404. }
  405. }
  406. $export_data[$k+1][] = $goods_string;
  407. $k++;
  408. }
  409. $count = count($export_data);
  410. $export_data[$count][] = '合计';
  411. $export_data[$count][] = $order_totals;
  412. $export_data[$count][] = $shipping_totals;
  413. $export_data[$count][] = $commis_totals;
  414. $csv = new Csv();
  415. $export_data = $csv->charset($export_data,CHARSET,'gbk');
  416. $csv->filename = $csv->charset('订单明细-',CHARSET).$_GET['ob_no'];
  417. $csv->export($export_data);
  418. }
  419. /**
  420. * 导出结算退单明细CSV
  421. *
  422. */
  423. public function export_refund_orderOp(){
  424. if (!preg_match('/^20\d{5,12}$/',$_GET['ob_no'])) {
  425. showMessage('参数错误','','html','error');
  426. }
  427. $model_bill = Model('bill');
  428. $bill_info = $model_bill->getOrderBillInfo(array('ob_no'=>$_GET['ob_no']));
  429. if (!$bill_info){
  430. showMessage('参数错误','','html','error');
  431. }
  432. $model_refund = Model('refund_return');
  433. $condition = array();
  434. $condition['seller_state'] = 2;
  435. $condition['store_id'] = $bill_info['ob_store_id'];
  436. $condition['goods_id'] = array('gt',0);
  437. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/',$_GET['query_start_date']);
  438. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/',$_GET['query_end_date']);
  439. $start_unixtime = $if_start_date ? strtotime($_GET['query_start_date']) : null;
  440. $end_unixtime = $if_end_date ? strtotime($_GET['query_end_date']) : null;
  441. $end_unixtime = $if_end_date ? $end_unixtime+86400-1 : null;
  442. if ($if_start_date || $if_end_date) {
  443. $condition['finnshed_time'] = array('between',"{$start_unixtime},{$end_unixtime}");
  444. } else {
  445. $condition['finnshed_time'] = array('between',"{$bill_info['ob_start_date']},{$bill_info['ob_end_date']}");
  446. }
  447. if (!is_numeric($_GET['curpage'])){
  448. $count = $model_refund->getRefundReturn($condition);
  449. $array = array();
  450. if ($count > self::EXPORT_SIZE ){ //显示下载链接
  451. $page = ceil($count/self::EXPORT_SIZE);
  452. for ($i=1;$i<=$page;$i++){
  453. $limit1 = ($i-1)*self::EXPORT_SIZE + 1;
  454. $limit2 = $i*self::EXPORT_SIZE > $count ? $count : $i*self::EXPORT_SIZE;
  455. $array[$i] = $limit1.' ~ '.$limit2 ;
  456. }
  457. Tpl::output('list',$array);
  458. Tpl::output('murl','index.php?act=bill&op=show_bill&query_type=refund&ob_no='.$_GET['ob_no']);
  459. Tpl::showpage('export.excel');
  460. exit();
  461. }else{
  462. //如果数量小,直接下载
  463. $data = $model_refund->getRefundReturnList($condition,'','*,ROUND(refund_amount*commis_rate/100,2) as commis_amount',self::EXPORT_SIZE);
  464. }
  465. }else{
  466. //下载
  467. $limit1 = ($_GET['curpage']-1) * self::EXPORT_SIZE;
  468. $limit2 = self::EXPORT_SIZE;
  469. $data = $model_refund->getRefundReturnList(condition,'','*,ROUND(refund_amount*commis_rate/100,2) as commis_amount',"{$limit1},{$limit2}");
  470. }
  471. if (is_array($data) && count($data) == 1 && $data[0]['refund_id'] == '') {
  472. $refund_list = array();
  473. }
  474. $export_data = array();
  475. $export_data[0] = array('退单编号','订单编号','退单金额','退单佣金','类型','退款日期','商家','商家编号','买家','买家编号');
  476. $refund_amount = 0;
  477. $commis_totals = 0;
  478. $k = 0;
  479. foreach ($data as $v) {
  480. $export_data[$k+1][] = 'NC'.$v['refund_sn'];
  481. $export_data[$k+1][] = 'NC'.$v['order_sn'];
  482. $refund_amount += $export_data[$k+1][] = $v['refund_amount'];
  483. $commis_totals += $export_data[$k+1][] = ncPriceFormat($v['commis_amount']);
  484. $export_data[$k+1][] = str_replace(array(1,2),array('退款','退货'),$v['refund_type']);
  485. $export_data[$k+1][] = date('Y-m-d',$v['admin_time']);
  486. $export_data[$k+1][] = $v['store_name'];
  487. $export_data[$k+1][] = $v['store_id'];
  488. $export_data[$k+1][] = $v['buyer_name'];
  489. $export_data[$k+1][] = $v['buyer_id'];
  490. $k++;
  491. }
  492. $count = count($export_data);
  493. $export_data[$count][] = '';
  494. $export_data[$count][] = '合计';
  495. $export_data[$count][] = $refund_amount;
  496. $export_data[$count][] = $commis_totals;
  497. $csv = new Csv();
  498. $export_data = $csv->charset($export_data,CHARSET,'gbk');
  499. $csv->filename = $csv->charset('退单明细-',CHARSET).$_GET['ob_no'];
  500. $csv->export($export_data);
  501. }
  502. }