Excel.php 20 KB

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