Factory_excel.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. namespace Store\Admin;
  3. use Dever;
  4. class Factory_excel extends Core
  5. {
  6. public function out($id, $user, $data)
  7. {
  8. if (!$data) {
  9. Dever::alert('无导出数据');
  10. }
  11. $info = Dever::db('store/info')->find($id);
  12. if (!$info) {
  13. Dever::alert('操作失败');
  14. }
  15. $method = 'out_' . $info['out_template'];
  16. $file = '入库信息表';
  17. return $this->$method($file, $user, $data);
  18. }
  19. # 模板模板
  20. public function out_1($file, $user, $data)
  21. {
  22. Dever::load('mshop/lib/buy')->set(2, 1)->excel($data);
  23. }
  24. # 安鲜达模板
  25. public function out_2($file, $user, $data, $name = '')
  26. {
  27. $file = $name ? $name : '安鲜达入库信息表';
  28. $body_0 = $body_1 = array();
  29. $header_0 = array('客户入库单号', '业务单据类型', '预计入库时间', '备注', '发件人', '发件人手机', '发件人电话', '发件人省', '发件人城市', '发件人区县', '发件人详细地址');
  30. $header_1 = array('客户入库单号', '货品编码', '应收数量', '库存类型');
  31. foreach ($data as $k => $v) {
  32. if (!is_array($v)) {
  33. continue;
  34. }
  35. Dever::load('mshop/lib/buy')->setOutStatus($v['id'], 1);
  36. if ($v['ps_info'] && isset($v['ps_info']['ydate_day']) && $v['ps_info']['ydate_day']) {
  37. $ps_date = $v['ps_info']['ydate_day'];
  38. } else {
  39. $ps_date = '-';
  40. }
  41. $info = Dever::db('area/province')->find($v['source_info']['province']);
  42. $v['source_info']['province_name'] = $info['name'];
  43. $info = Dever::db('area/city')->find($v['source_info']['city']);
  44. $v['source_info']['city_name'] = $info['name'];
  45. if (isset($v['source_info']['county']) && $v['source_info']['county']) {
  46. $info = Dever::db('area/county')->find($v['source_info']['county']);
  47. $v['source_info']['county_name'] = $info['name'];
  48. } else {
  49. $v['source_info']['county_name'] = '';
  50. }
  51. $body_0[] = array
  52. (
  53. $v['order_num'],
  54. '入库单',
  55. $ps_date,
  56. $v['info'],
  57. $v['source_info']['name'],
  58. $v['source_info']['mobile'],
  59. $v['source_info']['mobile'],
  60. $v['source_info']['province_name'],
  61. $v['source_info']['city_name'],
  62. $v['source_info']['county_name'],
  63. $v['source_info']['address'],
  64. );
  65. foreach ($v['goods'] as $k1 => $v1) {
  66. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
  67. if (isset($goods_info['sku'])) {
  68. $sku = $goods_info['sku']['string'];
  69. } else {
  70. $sku = '';
  71. }
  72. $body_1[] = array
  73. (
  74. $v['order_num'],
  75. $goods_info['code'],
  76. $v1['num'],
  77. '正品',
  78. );
  79. }
  80. }
  81. $xls = Dever::excelExport($body_0, $header_0, $file, 0, '入库单主表', true);
  82. if ($xls) {
  83. Dever::excelExport($body_1, $header_1, $file, 1, '入库单明细', false, $xls);
  84. }
  85. }
  86. # 大连模板
  87. public function out_3($file, $user, $data, $name = '')
  88. {
  89. $header = array();
  90. $header = array('所属客户', '商品编码', '数量', '商品供应商', '计量单位', '重量(kg)', '批号', '体积(m3)', '备注');
  91. $file = $name ? $name : '大连仓入库信息表';
  92. $body = array();
  93. $i = 1;
  94. foreach ($data as $k => $v) {
  95. if (!is_array($v)) {
  96. continue;
  97. }
  98. Dever::load('mshop/lib/buy')->setOutStatus($v['id'], 1);
  99. if ($v['ps_info'] && $v['ps_info']['cdate_day']) {
  100. $ps_date = $v['ps_info']['cdate_day'];
  101. } else {
  102. $ps_date = '-';
  103. }
  104. if ($v['parent_type'] == 2) {
  105. $parent_order = Dever::db('shop/sell_order')->find($v['parent_order_id']);
  106. if ($parent_order && $parent_order['uid']) {
  107. if ($parent_order['address_id']) {
  108. $address = Dever::load('passport/address')->getOne($parent_order['uid'], $parent_order['address_id']);
  109. $v['type_info']['name'] = $address['contact'];
  110. $v['type_info']['mobile'] = $address['mobile'];
  111. $v['type_info']['address'] = $address['address_info'];
  112. } else {
  113. $address = Dever::db('passport/user')->find($parent_order['uid']);
  114. $v['type_info']['name'] = $address['username'];
  115. $v['type_info']['mobile'] = $address['mobile'];
  116. $v['type_info']['address'] = '';
  117. }
  118. }
  119. } elseif ($v['parent_type'] == 3) {
  120. $parent_order = Dever::db('agent/dh_order')->find($v['parent_order_id']);
  121. if ($parent_order && $parent_order['mid']) {
  122. if ($parent_order['address_id']) {
  123. $address = Dever::load('agent/address')->getOne($parent_order['mid'], $parent_order['address_id']);
  124. $v['type_info']['name'] = $address['contact'];
  125. $v['type_info']['mobile'] = $address['mobile'];
  126. $v['type_info']['address'] = $address['address_info'];
  127. } else {
  128. $address = Dever::db('agent/member')->find($parent_order['mid']);
  129. $v['type_info']['name'] = $address['name'];
  130. $v['type_info']['mobile'] = $address['mobile'];
  131. $v['type_info']['address'] = '';
  132. }
  133. }
  134. }
  135. if (!isset($v['type_info']['sid'])) {
  136. $v['type_info']['sid'] = '';
  137. }
  138. foreach ($v['goods'] as $k1 => $v1) {
  139. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
  140. if (isset($goods_info['sku'])) {
  141. $sku = $goods_info['sku']['string'];
  142. } else {
  143. $sku = '';
  144. }
  145. $d = array
  146. (
  147. '厨人易料',
  148. $goods_info['code'],
  149. $v1['num'],
  150. $v['source_info']['name'],
  151. $goods_info['unit'],
  152. $goods_info['weight'],
  153. '',
  154. '',
  155. $v['info'],
  156. );
  157. $body[] = $d;
  158. $i++;
  159. }
  160. }
  161. Dever::excelExport($body, $header, $file);
  162. }
  163. }