Excel.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. <?php
  2. namespace Store\Admin;
  3. use Dever;
  4. class 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. $this->out_3($file, $user, $data, $file);
  23. }
  24. # 安鲜达模板
  25. public function out_2($file, $user, $data, $name = '')
  26. {
  27. $file = $name ? $name : '安鲜达发货信息表';
  28. $body_0 = $body_1 = array();
  29. $type = Dever::input('type');
  30. $parent_type = Dever::input('parent_type');
  31. $source_type = Dever::input('source_type');
  32. if ($type == 1 && $parent_type != 1) {
  33. $file .= '-平台商城订单';
  34. $header_0 = array('客户订单编号', '收件人姓名', '收件人手机', '收件省份(直辖市)', '收件市(州)', '收件区(县,县级市)', '收件详细地址', '收件人备注', '订单备注', '相关单号', '订单来源');
  35. $header_1 = array('客户订单编号', '客户货品编码', '销售平台货品编码', '数量', '备注');
  36. foreach ($data as $k => $v) {
  37. if (!is_array($v)) {
  38. continue;
  39. }
  40. Dever::load('mshop/lib/buy')->setOutStatus($v['id'], 2);
  41. if ($v['ps_info'] && $v['ps_info']['cdate_day']) {
  42. $ps_date = $v['ps_info']['cdate_day'];
  43. } else {
  44. $ps_date = '-';
  45. }
  46. if ($v['parent_type'] == 2) {
  47. $parent_order = Dever::db('shop/sell_order')->find($v['parent_order_id']);
  48. if ($parent_order && $parent_order['uid']) {
  49. if ($parent_order['address_id']) {
  50. $address = Dever::load('passport/address')->getOne($parent_order['uid'], $parent_order['address_id']);
  51. $v['type_info']['name'] = $address['contact'];
  52. $v['type_info']['mobile'] = $address['mobile'];
  53. $v['type_info']['address'] = $address['address_info'];
  54. $v['type_info']['province_name'] = $address['province_name'];
  55. $v['type_info']['city_name'] = $address['city_name'];
  56. $v['type_info']['county_name'] = $address['county_name'];
  57. } else {
  58. $address = Dever::db('passport/user')->find($parent_order['uid']);
  59. $v['type_info']['name'] = $address['username'];
  60. $v['type_info']['mobile'] = $address['mobile'];
  61. $v['type_info']['address'] = '';
  62. $v['type_info']['province_name'] = $v['type_info']['city_name'] = $v['type_info']['county_name'] = '';
  63. }
  64. }
  65. } elseif ($v['parent_type'] == 3) {
  66. $parent_order = Dever::db('agent/dh_order')->find($v['parent_order_id']);
  67. if ($parent_order && $parent_order['mid']) {
  68. if ($parent_order['address_id']) {
  69. $address = Dever::load('agent/address')->getOne($parent_order['mid'], $parent_order['address_id']);
  70. $v['type_info']['name'] = $address['contact'];
  71. $v['type_info']['mobile'] = $address['mobile'];
  72. $v['type_info']['address'] = $address['address_info'];
  73. $v['type_info']['province_name'] = $address['province_name'];
  74. $v['type_info']['city_name'] = $address['city_name'];
  75. $v['type_info']['county_name'] = $address['county_name'];
  76. } else {
  77. $address = Dever::db('agent/member')->find($parent_order['mid']);
  78. $v['type_info']['name'] = $address['name'];
  79. $v['type_info']['mobile'] = $address['mobile'];
  80. $v['type_info']['address'] = '';
  81. $v['type_info']['province_name'] = $v['type_info']['city_name'] = $v['type_info']['county_name'] = '';
  82. }
  83. }
  84. } else {
  85. $info = Dever::db('area/province')->find($v['type_info']['province']);
  86. $v['type_info']['province_name'] = $info['name'];
  87. $info = Dever::db('area/city')->find($v['type_info']['city']);
  88. $v['type_info']['city_name'] = $info['name'];
  89. $info = Dever::db('area/county')->find($v['type_info']['county']);
  90. $v['type_info']['county_name'] = $info['name'];
  91. }
  92. $body_0[] = array
  93. (
  94. $v['order_num'],
  95. $v['type_info']['name'],
  96. $v['type_info']['mobile'],
  97. $v['type_info']['province_name'],
  98. $v['type_info']['city_name'],
  99. $v['type_info']['county_name'],
  100. $v['type_info']['address'],
  101. '',
  102. $v['info'],
  103. '',
  104. '',
  105. );
  106. foreach ($v['goods'] as $k1 => $v1) {
  107. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
  108. if (isset($goods_info['sku'])) {
  109. $sku = $goods_info['sku']['string'];
  110. } else {
  111. $sku = '';
  112. }
  113. if ($goods_info['price_type'] > 2 && isset($goods_info['goods']) && is_array($goods_info['goods'])) {
  114. foreach ($goods_info['goods'] as $v2) {
  115. $p = $v2['price'];
  116. if (is_numeric($v2['num']) && is_numeric($v2['price'])) {
  117. $p = $v2['price']*$v2['num'];
  118. }
  119. $body_1[] = array
  120. (
  121. $v['order_num'],
  122. $v2['code'],
  123. $v2['name'],
  124. $v2['num'],
  125. '',
  126. );
  127. }
  128. } else {
  129. $body_1[] = array
  130. (
  131. $v['order_num'],
  132. $goods_info['code'],
  133. $goods_info['name'] . ' ' . $sku,
  134. $v1['num'],
  135. '',
  136. );
  137. }
  138. }
  139. }
  140. $xls = Dever::excelExport($body_0, $header_0, $file, 0, '订单主信息', true);
  141. if ($xls) {
  142. return Dever::excelExport($body_1, $header_1, $file, 1, '订单货品明细', false, $xls);
  143. }
  144. } else {
  145. $header_0 = array('客户出库单号', '业务单据类型', '预计出库时间', '备注', '门店名称', '收件人', '收件人手机', '收件人电话', '收件人省份', '收件人城市', '收件人区县', '收件人详细地址');
  146. $header_1 = array('客户出库单号', '货品编码', '应出数量', '库存类型', '批次号');
  147. if ($type == 2 && $source_type == 2) {
  148. $file .= '-仓库调拨订单';
  149. $header_0[4] = '仓库名称';
  150. } else {
  151. $file .= '-门店订单';
  152. }
  153. foreach ($data as $k => $v) {
  154. if (!is_array($v)) {
  155. continue;
  156. }
  157. Dever::load('mshop/lib/buy')->setOutStatus($v['id'], 2);
  158. if ($v['ps_info'] && $v['ps_info']['cdate_day']) {
  159. $ps_date = $v['ps_info']['cdate_day'];
  160. } else {
  161. $ps_date = '-';
  162. }
  163. $info = Dever::db('area/province')->find($v['type_info']['province']);
  164. $v['type_info']['province_name'] = $info['name'];
  165. $info = Dever::db('area/city')->find($v['type_info']['city']);
  166. $v['type_info']['city_name'] = $info['name'];
  167. $v['type_info']['county_name'] = '';
  168. if (isset($v['type_info']['county']) && $v['type_info']['county']) {
  169. $info = Dever::db('area/county')->find($v['type_info']['county']);
  170. if ($info) {
  171. $v['type_info']['county_name'] = $info['name'];
  172. }
  173. }
  174. $body_0[] = array
  175. (
  176. $v['order_num'],
  177. '出库单',
  178. $ps_date,
  179. $v['info'],
  180. $v['type_info']['name'],
  181. $v['type_info']['truename'],
  182. $v['type_info']['mobile'],
  183. $v['type_info']['mobile'],
  184. $v['type_info']['province_name'],
  185. $v['type_info']['city_name'],
  186. $v['type_info']['county_name'],
  187. $v['type_info']['address'],
  188. );
  189. foreach ($v['goods'] as $k1 => $v1) {
  190. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
  191. if (isset($goods_info['sku'])) {
  192. $sku = $goods_info['sku']['string'];
  193. } else {
  194. $sku = '';
  195. }
  196. if ($goods_info['price_type'] > 2 && isset($goods_info['goods']) && is_array($goods_info['goods'])) {
  197. foreach ($goods_info['goods'] as $v2) {
  198. $p = $v2['price'];
  199. if (is_numeric($v2['num']) && is_numeric($v2['price'])) {
  200. $p = $v2['price']*$v2['num'];
  201. }
  202. $body_1[] = array
  203. (
  204. $v['order_num'],
  205. $v2['code'],
  206. $v2['num'],
  207. '',
  208. '',
  209. );
  210. }
  211. } else {
  212. $body_1[] = array
  213. (
  214. $v['order_num'],
  215. $goods_info['code'],
  216. $v1['num'],
  217. '',
  218. '',
  219. );
  220. }
  221. }
  222. }
  223. $xls = Dever::excelExport($body_0, $header_0, $file, 0, '出库单主表', true);
  224. if ($xls) {
  225. return Dever::excelExport($body_1, $header_1, $file, 1, '出库单明细', false, $xls);
  226. }
  227. }
  228. }
  229. # 大连模板
  230. public function out_3($file, $user, $data, $name = '')
  231. {
  232. $header = array();
  233. $header = array('所属客户', '所属仓库', '出库时间', '收货人编码', '包装箱数', '备注', '货位编码', '商品编码', '计量单位', '批号', '数量', '明细备注');
  234. $file = $name ? $name : '大连仓发货信息表';
  235. $body = array();
  236. $i = 1;
  237. foreach ($data as $k => $v) {
  238. if (!is_array($v)) {
  239. continue;
  240. }
  241. Dever::load('mshop/lib/buy')->setOutStatus($v['id'], 2);
  242. if ($v['ps_info'] && $v['ps_info']['cdate_day']) {
  243. $ps_date = $v['ps_info']['cdate_day'];
  244. } else {
  245. $ps_date = '-';
  246. }
  247. if ($v['parent_type'] == 2) {
  248. $parent_order = Dever::db('shop/sell_order')->find($v['parent_order_id']);
  249. if ($parent_order && $parent_order['uid']) {
  250. if ($parent_order['address_id']) {
  251. $address = Dever::load('passport/address')->getOne($parent_order['uid'], $parent_order['address_id']);
  252. $v['type_info']['name'] = $address['contact'];
  253. $v['type_info']['mobile'] = $address['mobile'];
  254. $v['type_info']['address'] = $address['address_info'];
  255. } else {
  256. $address = Dever::db('passport/user')->find($parent_order['uid']);
  257. $v['type_info']['name'] = $address['username'];
  258. $v['type_info']['mobile'] = $address['mobile'];
  259. $v['type_info']['address'] = '';
  260. }
  261. }
  262. } elseif ($v['parent_type'] == 3) {
  263. $parent_order = Dever::db('agent/dh_order')->find($v['parent_order_id']);
  264. if ($parent_order && $parent_order['mid']) {
  265. if ($parent_order['address_id']) {
  266. $address = Dever::load('agent/address')->getOne($parent_order['mid'], $parent_order['address_id']);
  267. $v['type_info']['name'] = $address['contact'];
  268. $v['type_info']['mobile'] = $address['mobile'];
  269. $v['type_info']['address'] = $address['address_info'];
  270. } else {
  271. $address = Dever::db('agent/member')->find($parent_order['mid']);
  272. $v['type_info']['name'] = $address['name'];
  273. $v['type_info']['mobile'] = $address['mobile'];
  274. $v['type_info']['address'] = '';
  275. }
  276. }
  277. }
  278. if (!isset($v['type_info']['sid'])) {
  279. $v['type_info']['sid'] = '';
  280. }
  281. foreach ($v['goods'] as $k1 => $v1) {
  282. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
  283. if (isset($goods_info['sku'])) {
  284. $sku = $goods_info['sku']['string'];
  285. } else {
  286. $sku = '';
  287. }
  288. if ($goods_info['price_type'] > 2 && isset($goods_info['goods']) && is_array($goods_info['goods'])) {
  289. foreach ($goods_info['goods'] as $v2) {
  290. $p = $v2['price'];
  291. if (is_numeric($v2['num']) && is_numeric($v2['price'])) {
  292. $p = $v2['price']*$v2['num'];
  293. }
  294. $d = array
  295. (
  296. '简单生活(中食)有限公司',
  297. $v['type_info']['name'],
  298. $ps_date,
  299. $v['type_info']['sid'],
  300. '',
  301. $v['info'],
  302. '',
  303. $v2['code'],
  304. $v2['unit'],
  305. '',
  306. $v2['num'],
  307. $v2['name'],
  308. );
  309. $body[] = $d;
  310. }
  311. } else {
  312. $d = array
  313. (
  314. '简单生活(中食)有限公司',
  315. $v['type_info']['name'],
  316. $ps_date,
  317. $v['type_info']['sid'],
  318. '',
  319. $v['info'],
  320. '',
  321. $goods_info['code'],
  322. $goods_info['unit'],
  323. '',
  324. $v1['num'],
  325. $goods_info['name'] . ' ' . $sku,
  326. );
  327. $body[] = $d;
  328. }
  329. $i++;
  330. }
  331. }
  332. return Dever::excelExport($body, $header, $file);
  333. }
  334. # 九阳模板
  335. public function out_4($file, $user, $data, $name = '')
  336. {
  337. $header = array();
  338. $header_0 = array('序号', '申请发货时间', '申请人', '产品名称', '数量', '订单号', '收件人姓名', '收件人电话', '收件地址', '发货时间', '发件物流', '运单编号', '备注');
  339. $header_1 = array('商品条码(必填)', '商品名称', '申请数量(必填)', '配销价(元)');
  340. $file = $name ? $name : '中食民安&九阳发货信息表';
  341. $body_0 = $body_1 = array();
  342. $i = 1;
  343. foreach ($data as $k => $v) {
  344. if (!is_array($v)) {
  345. continue;
  346. }
  347. Dever::load('mshop/lib/buy')->setOutStatus($v['id'], 2);
  348. if ($v['ps_info'] && $v['ps_info']['cdate_day']) {
  349. $ps_date = $v['ps_info']['cdate_day'];
  350. } else {
  351. $ps_date = '-';
  352. }
  353. $service_name = array();
  354. $service_num = array();
  355. if (isset($v['ps_info']['service']) && $v['ps_info']['service']) {
  356. foreach ($v['ps_info']['service'] as $k1 => $v1) {
  357. $service_name[] = $v1['service_name'];
  358. $service_num[] = $v1['order_num'];
  359. }
  360. }
  361. $service_name = implode(',', $service_name);
  362. $service_num = implode(',', $service_num);
  363. if ($v['parent_type'] == 2) {
  364. $parent_order = Dever::db('shop/sell_order')->find($v['parent_order_id']);
  365. if ($parent_order && $parent_order['uid']) {
  366. if ($parent_order['address_id']) {
  367. $address = Dever::load('passport/address')->getOne($parent_order['uid'], $parent_order['address_id']);
  368. $v['type_info']['name'] = $address['contact'];
  369. $v['type_info']['mobile'] = $address['mobile'];
  370. $v['type_info']['address'] = $address['address_info'];
  371. } else {
  372. $address = Dever::db('passport/user')->find($parent_order['uid']);
  373. $v['type_info']['name'] = $address['username'];
  374. $v['type_info']['mobile'] = $address['mobile'];
  375. $v['type_info']['address'] = '';
  376. }
  377. }
  378. } elseif ($v['parent_type'] == 3) {
  379. $parent_order = Dever::db('agent/dh_order')->find($v['parent_order_id']);
  380. if ($parent_order && $parent_order['mid']) {
  381. if ($parent_order['address_id']) {
  382. $address = Dever::load('agent/address')->getOne($parent_order['mid'], $parent_order['address_id']);
  383. $v['type_info']['name'] = $address['contact'];
  384. $v['type_info']['mobile'] = $address['mobile'];
  385. $v['type_info']['address'] = $address['address_info'];
  386. } else {
  387. $address = Dever::db('agent/member')->find($parent_order['mid']);
  388. $v['type_info']['name'] = $address['name'];
  389. $v['type_info']['mobile'] = $address['mobile'];
  390. $v['type_info']['address'] = '';
  391. }
  392. }
  393. }
  394. foreach ($v['goods'] as $k1 => $v1) {
  395. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
  396. if (isset($goods_info['sku'])) {
  397. $sku = $goods_info['sku']['string'];
  398. } else {
  399. $sku = '';
  400. }
  401. if ($goods_info['price_type'] > 2 && isset($goods_info['goods']) && is_array($goods_info['goods'])) {
  402. foreach ($goods_info['goods'] as $v2) {
  403. $p = $v2['price'];
  404. if (is_numeric($v2['num']) && is_numeric($v2['price'])) {
  405. $p = $v2['price']*$v2['num'];
  406. }
  407. $body_0[] = array
  408. (
  409. $i,
  410. $v['operdate_day'],
  411. $user['name'],
  412. $v2['name'],
  413. $v2['num'] * $v1['num'],
  414. $v['order_num'],
  415. $v['type_info']['name'],
  416. $v['type_info']['mobile'],
  417. $v['type_info']['address'],
  418. $ps_date,
  419. $service_name,
  420. $service_num,
  421. $v['info'],
  422. );
  423. $body_1[] = array
  424. (
  425. $v2['code'],
  426. $v2['name'],
  427. $v2['num'] * $v1['num'],
  428. round($v2['price'] * $v1['num'], 2),
  429. );
  430. // $body[] = $d;
  431. }
  432. } else {
  433. $body_0[] = array
  434. (
  435. $i,
  436. $v['operdate_day'],
  437. $user['name'],
  438. $goods_info['name'] . ' ' . $sku,
  439. $v1['num'],
  440. $v['order_num'],
  441. $v['type_info']['name'],
  442. $v['type_info']['mobile'],
  443. $v['type_info']['address'],
  444. $ps_date,
  445. $service_name,
  446. $service_num,
  447. $v['info'],
  448. );
  449. $body_1[] = array
  450. (
  451. $goods_info['code'],
  452. $goods_info['name'],
  453. $v1['num'],
  454. $v1['price'],
  455. );
  456. // $body[] = $d;
  457. }
  458. $i++;
  459. }
  460. }
  461. $xls = Dever::excelExport($body_0, $header_0, $file, 0, '发货主信息', true);
  462. if($xls){
  463. return Dever::excelExport($body_1, $header_1, $file, 1 , '要货模板', false, $xls);
  464. }
  465. // return Dever::excelExport($body, $header, $file);
  466. }
  467. }