Excel.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  1. <?php
  2. namespace Shop\Src;
  3. use Dever;
  4. set_time_limit(0);
  5. class Excel
  6. {
  7. # 门店零售单
  8. public function sell_order($data)
  9. {
  10. if (!$data) {
  11. Dever::alert('无导出数据');
  12. }
  13. $file = Dever::input('excel_name');
  14. $header = array('门店编号', '门店名称', '门店类型', '订单号', '购买人', '商品编码', '商品名称', '规格型号', '商品单价', '购买数量', '商品合计金额', '配送类型', '订单类型', '下单时间', '付款时间', '发货时间', '订单合计金额', '订单实付金额', '已退订单金额', '礼品卡金额', '钱包金额', '优惠券金额', '代理优惠金额', '支付渠道', '订单状态','礼品卡名称');
  15. $table = 'shop/info';
  16. $body = array();
  17. $status = Dever::db('shop/sell_order')->config['status_manage'];
  18. $method = Dever::db('shop/sell_order')->config['method'];
  19. $pay_method = Dever::db('shop/sell_order')->config['pay_method'];
  20. $pay_type = Dever::db('shop/sell_order')->config['pay_type'];
  21. $info_type = Dever::db($table)->config['config_type'];
  22. foreach ($data as $k => $v) {
  23. if (!is_array($v)) {
  24. continue;
  25. }
  26. $info = Dever::db($table)->find($v['shop_id']);
  27. $goods = Dever::db('shop/sell_order_goods')->select(array('order_id' => $v['id']));
  28. $ps = Dever::db('shop/sell_order_ps')->find(array('order_id' => $v['id']));
  29. $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
  30. $paydate = isset($v['paydate']) && $v['paydate'] ? date('Y-m-d H:i', $v['paydate']) : '-';
  31. $operdate = $v['cdate'] ? date('Y-m-d H:i',$v['cdate']) : '-';
  32. // $operdate = ($ps && $ps['cdate']) ? date('Y-m-d H:i', $ps['cdate']) : '-';
  33. $total_cash = Dever::load("shop/lib/manage.getTotalCash", $v['id']);
  34. $v['refund_cash'] = $v['refund_cash'] ? $v['refund_cash'] : 0;
  35. $user = Dever::load("shop/lib/manage.user", $v['id']);
  36. #礼品卡
  37. $card_name= '';
  38. $code = Dever::db('card/code')->find(array('id'=>$v['card_code_id']));
  39. if(isset($code) && $code && $code['card_id']){
  40. $card = Dever::db('card/info')->find(array('id'=>$code['card_id']));
  41. if(isset($card) && $card && $card['name']){
  42. $card_name = $card['name'];
  43. }
  44. }
  45. if (!$v['card_code_cash']) {
  46. $v['card_code_cash'] = 0;
  47. }
  48. if (!$v['coupon_cash']) {
  49. $v['coupon_cash'] = 0;
  50. }
  51. if (!$v['refund_cash']) {
  52. $v['refund_cash'] = 0;
  53. }
  54. foreach ($goods as $k1 => $v1) {
  55. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
  56. if (isset($goods_info['sku'])) {
  57. $sku = $goods_info['sku']['string'];
  58. } else {
  59. $sku = '';
  60. }
  61. if ($v['status'] >= 7) {
  62. $v['price'] = 0;
  63. }
  64. if ($v['status'] == 8 || $v1['status'] == 3) {
  65. $num = $v1['num'];
  66. $v['refund_cash'] = $v1['price']*$v1['num'];
  67. $refund_status = '已退款';
  68. } else {
  69. $num = '0';
  70. $v['refund_cash'] = '0';
  71. $refund_status = '未退款';
  72. }
  73. if ($k1 == 0) {
  74. $goods_price = $v['price'];
  75. $d_total_cash = round($total_cash, 2);
  76. $d_price = round($v['price'], 2);
  77. $d_refund_cash = round($v['refund_cash'], 2);
  78. $d_card_code_cash = round($v['card_code_cash'], 2);
  79. $d_wallet_cash = round($v['wallet_cash'], 2);
  80. $d_coupon_cash = round($v['coupon_cash'], 2);
  81. $d_discount_cash = round($v['discount_cash'], 2);
  82. } else {
  83. $goods_price = 0;
  84. $d_total_cash = 0;
  85. $d_price = 0;
  86. $d_refund_cash = 0;
  87. $d_card_code_cash = 0;
  88. $d_wallet_cash = 0;
  89. $d_coupon_cash = 0;
  90. $d_discount_cash = 0;
  91. }
  92. $d = array
  93. (
  94. $info['sid'],
  95. $info['name'],
  96. $info_type[$info['type']],
  97. $v['order_num'],
  98. $user,
  99. $goods_info['code'] . "\t",
  100. $goods_info['name'],
  101. $sku,
  102. round($v1['price'], 2),
  103. round($v1['num'], 2),
  104. round($v1['price']*$v1['num'], 2),
  105. $method[$v['method']],
  106. $pay_method[$v['pay_method']],
  107. $cdate,
  108. $paydate,
  109. $operdate,
  110. $d_total_cash,
  111. $d_price,
  112. $d_refund_cash,
  113. $d_card_code_cash,
  114. $d_wallet_cash,
  115. $d_coupon_cash,
  116. $d_discount_cash,
  117. $pay_type[$v['pay_type']],
  118. $status[$v['status']],
  119. $card_name,
  120. );
  121. $body[] = $d;
  122. if ($goods_info['price_type'] > 2 && isset($goods_info['goods']) && is_array($goods_info['goods'])) {
  123. foreach ($goods_info['goods'] as $v2) {
  124. if ($v2['code']) {
  125. //$v2['code'] = '-' . $v2['code'];
  126. }
  127. $p = $v2['price'];
  128. if (is_numeric($v2['num']) && is_numeric($v2['price'])) {
  129. $p = $v2['price']*$v2['num'];
  130. }
  131. $d = array
  132. (
  133. $info['sid'],
  134. $info['name'],
  135. $info_type[$info['type']],
  136. $v['order_num'],
  137. $user,
  138. $v2['code'] . "\t",
  139. $v2['name'] . '('.$goods_info['name'].')',
  140. $sku,
  141. round($v2['price'], 2),
  142. round($v2['num'], 2),
  143. $p,
  144. $method[$v['method']],
  145. $pay_method[$v['pay_method']],
  146. $cdate,
  147. $paydate,
  148. $operdate,
  149. '',
  150. '',
  151. '',
  152. '',
  153. '',
  154. '',
  155. '',
  156. $pay_type[$v['pay_type']],
  157. $status[$v['status']],
  158. $card_name,
  159. );
  160. $body[] = $d;
  161. }
  162. }
  163. }
  164. }
  165. return Dever::excelExport($body, $header, $file);
  166. }
  167. # 平台零售订单
  168. public function p_sell_order($data)
  169. {
  170. if (!$data) {
  171. Dever::alert('无导出数据');
  172. }
  173. $file = Dever::input('excel_name');
  174. $header = array('订单号', '收件人', '收件人手机', '收件人地址', '商品编码', '商品名称', '规格型号', '商品单价', '购买数量', '商品合计金额', '商品支付金额', '下单时间', '付款时间', '发货时间', '收货时间' , '订单总数量', '订单总金额', '订单实付金额', '礼品卡金额', '钱包金额', '优惠券金额', '代理优惠金额', '订单状态', '退款状态', '退款金额','礼品卡名称');
  175. $table = 'shop/info';
  176. $body = array();
  177. $status = Dever::db('shop/sell_order')->config['status_manage'];
  178. $info_type = Dever::db($table)->config['config_type'];
  179. foreach ($data as $k => $v) {
  180. if (!is_array($v)) {
  181. continue;
  182. }
  183. $info = Dever::db($table)->find($v['shop_id']);
  184. if ($v['store_id']) {
  185. $store = Dever::db('store/info')->find($v['store_id']);
  186. } else {
  187. $store['name'] = '';
  188. }
  189. $goods = Dever::db('shop/sell_order_goods')->select(array('order_id' => $v['id']));
  190. $ps = Dever::db('shop/sell_order_ps')->find(array('order_id' => $v['id']));
  191. $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
  192. $paydate = isset($v['paydate']) && $v['paydate'] ? date('Y-m-d H:i', $v['paydate']) : '-';
  193. $operdate = $v['fadate'] ? date('Y-m-d H:i',$v['fadate']) : '-';
  194. // $operdate = ($ps && $ps['cdate']) ? date('Y-m-d H:i', $ps['cdate']) : '-';
  195. if ($v['fdate']) {
  196. $fdate = strstr($v['fdate'], '-') ? $v['fdate'] : date('Y-m-d H:i', $v['fdate']);
  197. } else {
  198. $fdate = '-';
  199. }
  200. $refund_status = Dever::load("shop/lib/manage.buyInfoRefundStatus", $v['id'], 'sell_order');
  201. $total_cash = Dever::load("shop/lib/manage.getTotalCash", $v['id']);
  202. $v['refund_cash'] = $v['refund_cash'] ? $v['refund_cash'] : 0;
  203. $address = Dever::load('passport/address')->getOne($v['uid'], $v['address_id']);
  204. if (!$v['card_code_cash']) {
  205. $v['card_code_cash'] = 0;
  206. }
  207. if (!$v['coupon_cash']) {
  208. $v['coupon_cash'] = 0;
  209. }
  210. if (!$v['refund_cash']) {
  211. $v['refund_cash'] = 0;
  212. }
  213. #礼品卡
  214. $card_name= '';
  215. $code = Dever::db('card/code')->find(array('id'=>$v['card_code_id']));
  216. if(isset($code) && $code && $code['card_id']){
  217. $card = Dever::db('card/info')->find(array('id'=>$code['card_id']));
  218. if(isset($card) && $card && $card['name']){
  219. $card_name = $card['name'];
  220. }
  221. }
  222. foreach ($goods as $k1 => $v1) {
  223. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
  224. if (isset($goods_info['sku'])) {
  225. $sku = $goods_info['sku']['string'];
  226. } else {
  227. $sku = '';
  228. }
  229. if ($v['status'] >= 7) {
  230. $v['price'] = 0;
  231. }
  232. if ($v['status'] == 8 || $v1['status'] == 3) {
  233. $num = $v1['num'];
  234. $v['refund_cash'] = $v1['price']*$v1['num'];
  235. $refund_status = '已退款';
  236. } else {
  237. $num = '0';
  238. $v['refund_cash'] = '0';
  239. $refund_status = '未退款';
  240. }
  241. if ($k1 == 0) {
  242. $goods_price = $v['price'];
  243. $d_num = round($v['num'], 2);
  244. $d_total_cash = round($total_cash, 2);
  245. $d_price = round($v['price'], 2);
  246. $d_card_code_cash = round($v['card_code_cash'], 2);
  247. $d_wallet_cash = round($v['wallet_cash'], 2);
  248. $d_coupon_cash = round($v['coupon_cash'], 2);
  249. $d_discount_cash = round($v['discount_cash'], 2);
  250. } else {
  251. $goods_price = 0;
  252. $d_num = 0;
  253. $d_total_cash = 0;
  254. $d_price = 0;
  255. $d_card_code_cash = 0;
  256. $d_wallet_cash = 0;
  257. $d_coupon_cash = 0;
  258. $d_discount_cash = 0;
  259. }
  260. $d = array
  261. (
  262. $v['order_num'],
  263. isset($address['contact']) ? $address['contact'] : '',
  264. isset($address['mobile']) ? $address['mobile'] . "\t" : '',
  265. isset($address['address_info']) ? $address['address_info'] : '',
  266. //$store['name'],
  267. $goods_info['code'] . "\t",
  268. $goods_info['name'],
  269. $sku,
  270. round($v1['price'], 2),
  271. round($v1['num'], 2),
  272. round($v1['price']*$v1['num'], 2),
  273. round($goods_price, 2),
  274. $cdate,
  275. $paydate,
  276. $operdate,
  277. $fdate,
  278. $d_num,
  279. $d_total_cash,
  280. $d_price,
  281. $d_card_code_cash,
  282. $d_wallet_cash,
  283. $d_coupon_cash,
  284. $d_discount_cash,
  285. $status[$v['status']],
  286. $refund_status,
  287. round($v['refund_cash'], 2),
  288. $card_name,
  289. );
  290. $body[] = $d;
  291. if ($goods_info['price_type'] > 2 && isset($goods_info['goods']) && is_array($goods_info['goods'])) {
  292. foreach ($goods_info['goods'] as $k2 => $v2) {
  293. if ($v2['code']) {
  294. //$v2['code'] = '-' . $v2['code'];
  295. }
  296. $p = $v2['price'];
  297. if (is_numeric($v2['num']) && is_numeric($v2['price'])) {
  298. $p = $v2['price']*$v2['num'];
  299. }
  300. $goods_price1 = 0;
  301. $d = array
  302. (
  303. $v['order_num'],
  304. isset($address['contact']) ? $address['contact'] : '',
  305. isset($address['mobile']) ? $address['mobile'] . "\t" : '',
  306. isset($address['address_info']) ? $address['address_info'] : '',
  307. //$store['name'],
  308. $v2['code'] . "\t",
  309. $v2['name'] . '('.$goods_info['name'].')',
  310. $sku,
  311. round($v2['price'], 2),
  312. round($v2['num'], 2),
  313. $p,
  314. round($goods_price1, 2),
  315. $cdate,
  316. $paydate,
  317. $operdate,
  318. $fdate,
  319. '',
  320. '',
  321. '',
  322. '',
  323. '',
  324. '',
  325. '',
  326. $status[$v['status']],
  327. '',
  328. '',
  329. );
  330. $body[] = $d;
  331. }
  332. }
  333. }
  334. }
  335. return Dever::excelExport($body, $header, $file);
  336. }
  337. # 门店订货单
  338. public function buy_order($data)
  339. {
  340. if (!$data) {
  341. Dever::alert('无导出数据');
  342. }
  343. $file = Dever::input('excel_name');
  344. $header = array('门店编号', '门店名称', '门店类型', '供货商', '订货单号', '订货总数量', '订货单总金额', '商品编码', '商品名称', '规格型号', '订货单价', '订货数量', '商品合计金额', '订货日期', '发货日期', '订货单状态', '退款状态', '退款金额');
  345. $table = 'shop/info';
  346. $body = array();
  347. $status = Dever::db('shop/buy_order')->config['status'];
  348. //$refund_status = Dever::db('shop/buy_order')->config['refund_status'];
  349. $info_type = Dever::db($table)->config['config_type'];
  350. foreach ($data as $k => $v) {
  351. if (!is_array($v)) {
  352. continue;
  353. }
  354. $info = Dever::db($table)->find($v['type_id']);
  355. $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
  356. $ps = Dever::db('shop/buy_order_ps')->find(array('order_id' => $v['id']));
  357. $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
  358. $fdate = ($ps && $ps['cdate']) ? date('Y-m-d H:i', $ps['cdate']) : '-';
  359. $ydate = ($ps && $ps['ydate']) ? date('Y-m-d H:i', $ps['ydate']) : '-';
  360. $refund_status = Dever::load("shop/lib/manage.buyInfoRefundStatus", $v['id']);
  361. $source = Dever::load("shop/lib/manage.buyInfo", $v['source_type'], $v['source_id']);
  362. foreach ($goods as $k1 => $v1) {
  363. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
  364. if (isset($goods_info['sku'])) {
  365. $sku = $goods_info['sku']['string'];
  366. } else {
  367. $sku = '';
  368. }
  369. if ($v['status'] == 8 || $v1['status'] == 3) {
  370. $num = $v1['num'];
  371. $v['refund_cash'] = $v1['price']*$v1['num'];
  372. $refund_status = '已退款';
  373. } else {
  374. $num = '0';
  375. $v['refund_cash'] = '0';
  376. $refund_status = '未退款';
  377. }
  378. $d = array
  379. (
  380. $info['sid'],
  381. $info['name'],
  382. $info_type[$info['type']],
  383. $source,
  384. $v['order_num'],
  385. round($v['num'], 2),
  386. round($v['price'], 2),
  387. $goods_info['code'] . "\t",
  388. $goods_info['name'],
  389. $sku,
  390. round($v1['price'], 2),
  391. round($v1['num'], 2),
  392. round($v1['price']*$v1['num'], 2),
  393. $cdate,
  394. $fdate,
  395. $status[$v['status']],
  396. $refund_status,
  397. $v['refund_cash'],
  398. );
  399. $body[] = $d;
  400. }
  401. }
  402. return Dever::excelExport($body, $header, $file);
  403. }
  404. # 仓库订货单
  405. public function store_buy_order($data)
  406. {
  407. if (!$data) {
  408. Dever::alert('无导出数据');
  409. }
  410. $file = Dever::input('excel_name');
  411. $header = array('仓库名称', '供货商', '订货单号', '订货总数量', '入库单价', '商品编码', '商品名称', '规格型号', '商品订货数量', '订货日期', '发货日期', '收货日期', '订货单状态', '已退商品数量');
  412. $table = 'store/info';
  413. $body = array();
  414. $status = Dever::db('shop/buy_order')->config['status'];
  415. //$refund_status = Dever::db('shop/buy_order')->config['refund_status'];
  416. foreach ($data as $k => $v) {
  417. if (!is_array($v)) {
  418. continue;
  419. }
  420. $info = Dever::db($table)->find($v['type_id']);
  421. $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
  422. $ps = Dever::db('shop/buy_order_ps')->find(array('order_id' => $v['id']));
  423. $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
  424. $fdate = ($ps && $ps['cdate']) ? date('Y-m-d H:i', $ps['cdate']) : '-';
  425. $ydate = ($ps && $ps['ydate']) ? date('Y-m-d H:i', $ps['ydate']) : '-';
  426. $num = Dever::load("shop/lib/manage.buyInfoRefundNum", $v['id']);
  427. $refund_status = Dever::load("shop/lib/manage.buyInfoRefundStatus", $v['id']);
  428. $v['refund_cash'] = $v['refund_cash'] ? $v['refund_cash'] : 0;
  429. $source = Dever::load("shop/lib/manage.buyInfo", $v['source_type'], $v['source_id']);
  430. foreach ($goods as $k1 => $v1) {
  431. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
  432. if (isset($goods_info['sku'])) {
  433. $sku = $goods_info['sku']['string'];
  434. } else {
  435. $sku = '';
  436. }
  437. if ($v['status'] == 8 || $v1['status'] == 3) {
  438. $num = $v1['num'];
  439. $refund_status = '已退款';
  440. } else {
  441. $num = '0';
  442. $refund_status = '未退款';
  443. }
  444. if ($v['source_type'] == 2) {
  445. $v1['p_price'] = 0;
  446. }
  447. $d = array
  448. (
  449. $info['name'],
  450. $source,
  451. $v['order_num'],
  452. round($v['num'], 2),
  453. round($v1['p_price'], 2),
  454. $goods_info['code'] . "\t",
  455. $goods_info['name'],
  456. $sku,
  457. round($v1['num'], 2),
  458. $cdate,
  459. $fdate,
  460. $ydate,
  461. $status[$v['status']],
  462. $num,
  463. );
  464. $body[] = $d;
  465. }
  466. }
  467. return Dever::excelExport($body, $header, $file);
  468. }
  469. # 仓库发货单
  470. public function store_buy_order_fa($data)
  471. {
  472. if (!$data) {
  473. Dever::alert('无导出数据');
  474. }
  475. $file = Dever::input('excel_name');
  476. $header = array('仓库名称', '门店编号', '门店名称', '门店类型', '订货单号', '订货总数量', '订货单总金额', '商品编码', '商品名称', '规格型号', '订货单价', '订货数量', '商品合计金额', '订货日期', '发货日期', '订货单状态', '退款状态', '已退商品数量', '退款金额');
  477. $table = 'shop/info';
  478. $body = array();
  479. $status = Dever::db('shop/buy_order')->config['status'];
  480. //$refund_status = Dever::db('shop/buy_order')->config['refund_status'];
  481. $info_type = Dever::db($table)->config['config_type'];
  482. foreach ($data as $k => $v) {
  483. if (!is_array($v)) {
  484. continue;
  485. }
  486. $info = Dever::db($table)->find($v['type_id']);
  487. $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
  488. $ps = Dever::db('shop/buy_order_ps')->find(array('order_id' => $v['id']));
  489. $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
  490. $fdate = ($ps && $ps['cdate']) ? date('Y-m-d H:i', $ps['cdate']) : '-';
  491. $ydate = ($ps && $ps['ydate']) ? date('Y-m-d H:i', $ps['ydate']) : '-';
  492. $num = Dever::load("shop/lib/manage.buyInfoRefundNum", $v['id']);
  493. $refund_status = Dever::load("shop/lib/manage.buyInfoRefundStatus", $v['id']);
  494. $v['refund_cash'] = $v['refund_cash'] ? $v['refund_cash'] : 0;
  495. $source = Dever::load("shop/lib/manage.buyInfo", $v['source_type'], $v['source_id']);
  496. foreach ($goods as $k1 => $v1) {
  497. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
  498. if (isset($goods_info['sku'])) {
  499. $sku = $goods_info['sku']['string'];
  500. } else {
  501. $sku = '';
  502. }
  503. if ($v['status'] == 8 || $v1['status'] == 3) {
  504. $num = $v1['num'];
  505. $v['refund_cash'] = $v1['price']*$v1['num'];
  506. $refund_status = '已退款';
  507. } else {
  508. $num = '0';
  509. $v['refund_cash'] = '0';
  510. $refund_status = '未退款';
  511. }
  512. $d = array
  513. (
  514. $source,
  515. $info['sid'],
  516. $info['name'],
  517. $info_type[$info['type']],
  518. $v['order_num'],
  519. round($v['num'], 2),
  520. round($v['price'], 2),
  521. $goods_info['code'] . "\t",
  522. $goods_info['name'],
  523. $sku,
  524. round($v1['price'], 2),
  525. round($v1['num'], 2),
  526. round($v1['price']*$v1['num'], 2),
  527. $cdate,
  528. $fdate,
  529. $status[$v['status']],
  530. $refund_status,
  531. $num,
  532. round($v['refund_cash'], 2),
  533. );
  534. $body[] = $d;
  535. }
  536. }
  537. return Dever::excelExport($body, $header, $file);
  538. }
  539. # 仓库调拨单
  540. public function store_buy_order_diao($data)
  541. {
  542. if (!$data) {
  543. Dever::alert('无导出数据');
  544. }
  545. $file = Dever::input('excel_name');
  546. $header = array('发货仓库名称', '收货仓库名称', '订货单号', '订货总数量', '商品编码', '商品名称', '规格型号', '订货数量', '订货日期', '发货日期', '订货单状态', '退款状态', '已退商品数量');
  547. $table = 'store/info';
  548. $body = array();
  549. $status = Dever::db('shop/buy_order')->config['status'];
  550. //$refund_status = Dever::db('shop/buy_order')->config['refund_status'];
  551. foreach ($data as $k => $v) {
  552. if (!is_array($v)) {
  553. continue;
  554. }
  555. $info = Dever::db($table)->find($v['type_id']);
  556. $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
  557. $ps = Dever::db('shop/buy_order_ps')->find(array('order_id' => $v['id']));
  558. $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
  559. $fdate = ($ps && $ps['cdate']) ? date('Y-m-d H:i', $ps['cdate']) : '-';
  560. $ydate = ($ps && $ps['ydate']) ? date('Y-m-d H:i', $ps['ydate']) : '-';
  561. $num = Dever::load("shop/lib/manage.buyInfoRefundNum", $v['id']);
  562. $refund_status = Dever::load("shop/lib/manage.buyInfoRefundStatus", $v['id']);
  563. $v['refund_cash'] = $v['refund_cash'] ? $v['refund_cash'] : 0;
  564. $source = Dever::load("shop/lib/manage.buyInfo", $v['source_type'], $v['source_id']);
  565. foreach ($goods as $k1 => $v1) {
  566. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
  567. if (isset($goods_info['sku'])) {
  568. $sku = $goods_info['sku']['string'];
  569. } else {
  570. $sku = '';
  571. }
  572. if ($v['status'] == 8 || $v1['status'] == 3) {
  573. $num = $v1['num'];
  574. $v['refund_cash'] = $v1['price']*$v1['num'];
  575. $refund_status = '已退款';
  576. } else {
  577. $num = '0';
  578. $v['refund_cash'] = '0';
  579. $refund_status = '未退款';
  580. }
  581. $d = array
  582. (
  583. $source,
  584. $info['name'],
  585. $v['order_num'],
  586. round($v['num'], 2),
  587. $goods_info['code'] . "\t",
  588. $goods_info['name'],
  589. $sku,
  590. round($v1['num'], 2),
  591. $cdate,
  592. $fdate,
  593. $status[$v['status']],
  594. $refund_status,
  595. $num,
  596. );
  597. $body[] = $d;
  598. }
  599. }
  600. return Dever::excelExport($body, $header, $file);
  601. }
  602. # 工厂发货单
  603. public function factory_buy_order_fa($data)
  604. {
  605. if (!$data) {
  606. Dever::alert('无导出数据');
  607. }
  608. $file = Dever::input('excel_name');
  609. $header = array('工厂名称', '收件人名称', '收件人类型', '订货单号', '订货总数量', '订货单总金额', '商品编码', '商品名称', '规格型号', '商品进货单价', '订货数量', '商品合计金额', '订货日期', '发货日期', '订货单状态', '已退商品数量', '退款金额');
  610. $table = 'shop/info';
  611. $body = array();
  612. $status = Dever::db('shop/buy_order')->config['status'];
  613. //$refund_status = Dever::db('shop/buy_order')->config['refund_status'];
  614. $info_type = Dever::db($table)->config['config_type'];
  615. $order_type = Dever::db('shop/buy_order')->config['config_type'];
  616. foreach ($data as $k => $v) {
  617. if (!is_array($v)) {
  618. continue;
  619. }
  620. if ($v['type'] == 1) {
  621. $info = Dever::db('shop/info')->find($v['type_id']);
  622. } elseif ($v['type'] == 2) {
  623. $info = Dever::db('store/info')->find($v['type_id']);
  624. }
  625. $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
  626. $ps = Dever::db('shop/buy_order_ps')->find(array('order_id' => $v['id']));
  627. $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
  628. $fdate = ($ps && $ps['cdate']) ? date('Y-m-d H:i', $ps['cdate']) : '-';
  629. $ydate = ($ps && $ps['ydate']) ? date('Y-m-d H:i', $ps['ydate']) : '-';
  630. $num = Dever::load("shop/lib/manage.buyInfoRefundNum", $v['id']);
  631. $refund_status = Dever::load("shop/lib/manage.buyInfoRefundStatus", $v['id']);
  632. $v['refund_p_cash'] = $v['refund_p_cash'] ? $v['refund_p_cash'] : 0;
  633. $source = Dever::load("shop/lib/manage.buyInfo", $v['source_type'], $v['source_id']);
  634. foreach ($goods as $k1 => $v1) {
  635. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
  636. if (isset($goods_info['sku'])) {
  637. $sku = $goods_info['sku']['string'];
  638. } else {
  639. $sku = '';
  640. }
  641. if ($v['status'] == 8 || $v1['status'] == 3) {
  642. $num = $v1['num'];
  643. $v['refund_p_cash'] = $v1['p_price']*$v1['num'];
  644. } else {
  645. $num = '0';
  646. $v['refund_p_cash'] = '0';
  647. }
  648. $d = array
  649. (
  650. $source,
  651. $info['name'],
  652. $order_type[$v['type']],
  653. $v['order_num'],
  654. round($v['num'], 2),
  655. round($v['p_price'], 2),
  656. $goods_info['code'] . "\t",
  657. $goods_info['name'],
  658. $sku,
  659. round($v1['p_price'], 2),
  660. round($v1['num'], 2),
  661. round($v1['p_price']*$v1['num'], 2),
  662. $cdate,
  663. $fdate,
  664. $status[$v['status']],
  665. $num,
  666. round($v['refund_p_cash'], 2),
  667. );
  668. $body[] = $d;
  669. }
  670. }
  671. return Dever::excelExport($body, $header, $file);
  672. }
  673. # 门店出库单
  674. public function out_order($data)
  675. {
  676. if (!$data) {
  677. Dever::alert('无导出数据');
  678. }
  679. $file = Dever::input('excel_name');
  680. $header = array('门店编号', '门店名称', '门店类型', '出库单号', '出库总数量', '出库总金额', '商品编码', '商品名称', '规格型号', '订货单价', '订货数量', '商品合计金额', '出库日期', '出库类型', '出库状态');
  681. $table = 'shop/info';
  682. $body = array();
  683. $status = Dever::db('shop/out_order')->config['config_status'];
  684. $config_type = Dever::db('shop/out_order')->config['config_type'];
  685. $config_type = $config_type();
  686. $info_type = Dever::db($table)->config['config_type'];
  687. foreach ($data as $k => $v) {
  688. if (!is_array($v)) {
  689. continue;
  690. }
  691. $info = Dever::db($table)->find($v['type_id']);
  692. $goods = Dever::db('shop/out_order_goods')->select(array('order_id' => $v['id']));
  693. $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
  694. foreach ($goods as $k1 => $v1) {
  695. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
  696. if (isset($goods_info['sku'])) {
  697. $sku = $goods_info['sku']['string'];
  698. } else {
  699. $sku = '';
  700. }
  701. $d = array
  702. (
  703. $info['sid'],
  704. $info['name'],
  705. $info_type[$info['type']],
  706. $v['order_num'],
  707. round($v['num'], 2),
  708. round($v['price'], 2),
  709. $goods_info['code'] . "\t",
  710. $goods_info['name'],
  711. $sku,
  712. round($v1['price'], 2),
  713. round($v1['num'], 2),
  714. round($v1['price']*$v1['num'], 2),
  715. $cdate,
  716. $config_type[$v['out_type']]['name'],
  717. $status[$v['status']],
  718. );
  719. $body[] = $d;
  720. }
  721. }
  722. return Dever::excelExport($body, $header, $file);
  723. }
  724. # 仓库出库单
  725. public function store_out_order($data)
  726. {
  727. if (!$data) {
  728. Dever::alert('无导出数据');
  729. }
  730. $file = Dever::input('excel_name');
  731. $header = array('仓库名称', '出库单号', '出库总数量', '出库总金额', '商品编码', '商品名称', '规格型号', '门店进货单价', '订货数量', '商品合计金额', '出库日期', '出库类型', '出库状态');
  732. $table = 'store/info';
  733. $body = array();
  734. $status = Dever::db('shop/out_order')->config['config_status'];
  735. $config_type = Dever::db('shop/out_order')->config['config_type'];
  736. $config_type = $config_type();
  737. foreach ($data as $k => $v) {
  738. if (!is_array($v)) {
  739. continue;
  740. }
  741. $info = Dever::db($table)->find($v['type_id']);
  742. $goods = Dever::db('shop/out_order_goods')->select(array('order_id' => $v['id']));
  743. $cdate = strstr($v['cdate'], '-') ? $v['cdate'] : date('Y-m-d H:i', $v['cdate']);
  744. foreach ($goods as $k1 => $v1) {
  745. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
  746. if (isset($goods_info['sku'])) {
  747. $sku = $goods_info['sku']['string'];
  748. } else {
  749. $sku = '';
  750. }
  751. $d = array
  752. (
  753. $info['name'],
  754. $v['order_num'],
  755. round($v['num'], 2),
  756. round($v['price'], 2),
  757. $goods_info['code'] . "\t",
  758. $goods_info['name'],
  759. $sku,
  760. round($v1['price'], 2),
  761. round($v1['num'], 2),
  762. round($v1['price']*$v1['num'], 2),
  763. $cdate,
  764. $config_type[$v['out_type']]['name'],
  765. $status[$v['status']],
  766. );
  767. $body[] = $d;
  768. }
  769. }
  770. return Dever::excelExport($body, $header, $file);
  771. }
  772. public function goods_log()
  773. {
  774. //Array ( [search_option_state] => 1 [search_api_goods_id] => 猪肉 [search_api_goods-info-code] => [search_option_status] => 0 [search_option_store_id] => 6 [search_option_start_cdate] => [search_option_end_cdate] => [search_option_sday] => 0 )
  775. $data = Dever::input();
  776. $where = array();
  777. if (isset($data['search_option_store_id']) && $data['search_option_store_id']) {
  778. $where['store_id'] = $data['search_option_store_id'];
  779. }
  780. if (isset($data['search_option_status']) && $data['search_option_status']) {
  781. $where['status'] = $data['search_option_status'];
  782. }
  783. if (isset($data['search_option_start_cdate']) && $data['search_option_start_cdate']) {
  784. $where['start'] = $data['search_option_start_cdate'];
  785. }
  786. if (isset($data['search_option_end_cdate']) && $data['search_option_end_cdate']) {
  787. $where['end'] = $data['search_option_end_cdate'];
  788. }
  789. if (isset($data['search_api_goods_id']) && $data['search_api_goods_id']) {
  790. $goods_info = Dever::db('goods/info')->like(array('name' => $data['search_api_goods_id']));
  791. if ($goods_info) {
  792. $where['goods_id'] = array_keys($goods_info);
  793. }
  794. }
  795. if (isset($data['search_api_goods-info-code']) && $data['search_api_goods-info-code']) {
  796. $goods_sku = Dever::db('goods/info_sku')->like(array('code' => $data['search_api_goods-info-code']));
  797. if ($goods_sku) {
  798. $where['sku_id'] = array_keys($goods_sku);
  799. }
  800. }
  801. $goods = Dever::db('store/goods_log')->getDataByDate($where);
  802. $file = '仓库调整明细';
  803. $header = array('仓库名称', '商品编码', '商品名称', '规格型号', '当前库存', '占用库存', '在途库存', '总库存', '调整数量', '调整后库存', '调整后总库存', '调整时间');
  804. $body = array();
  805. if ($goods) {
  806. foreach ($goods as $k => $v) {
  807. $info = Dever::db('store/info')->find($v['store_id']);
  808. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']);
  809. if (isset($goods_info['sku'])) {
  810. $sku = $goods_info['sku']['string'];
  811. } else {
  812. $sku = '';
  813. }
  814. $cdate = date('Y-m-d H:i', $v['cdate']);
  815. $d = array
  816. (
  817. $info['name'],
  818. $goods_info['code'] . "\t",
  819. $goods_info['name'],
  820. $sku,
  821. round($v['cur_num'], 2),
  822. round($v['sell_num'], 2),
  823. round($v['online_num'], 2),
  824. round($v['total_num'], 2),
  825. round($v['num'], 2),
  826. round($v['after_cur_num'], 2),
  827. round($v['after_total_num'], 2),
  828. $cdate,
  829. );
  830. $body[] = $d;
  831. }
  832. } else {
  833. Dever::alert('无导出数据');
  834. }
  835. return Dever::excelExport($body, $header, $file);
  836. }
  837. #门店列表数据导出
  838. public function shop_info ($data)
  839. {
  840. $header = array('店铺id', '店铺编号-一般为5位数字,不能重复', '门店名称', '联系人姓名', '联系人电话', '营业状态', '门店类型-自营为平台店,当没有找到加盟店时,将自动获取平台店', '合作状态', '所属代理商名称', '所属代理商手机号', '分账商户号','录入时间');
  841. $body = array();
  842. if ($data) {
  843. $type = Dever::db('shop/info')->config['config_type'];
  844. foreach ($data as $k => $v) {
  845. if ($v['open'] == 1) {
  846. $open = '开启';
  847. } else {
  848. $open = '关闭';
  849. }
  850. if ($v['status'] == 1) {
  851. $status = '合作中';
  852. } else {
  853. $status = '已终止合作';
  854. }
  855. $member_name = '';
  856. $member_mobile = '';
  857. if ($v['agent_mid'] && $v['agent_mid']>0) {
  858. $member = Dever::db('agent/member')->find($v['agent_mid']);
  859. if ($member) {
  860. $member_name = $member['name'];
  861. $member_mobile = $member['mobile'];
  862. }
  863. }
  864. $d = array
  865. (
  866. $v['id'],
  867. $v['sid'],
  868. $v['name'],
  869. $v['truename'],
  870. $v['mobile'],
  871. $open,
  872. $type[$v['type']],
  873. $status,
  874. $member_name,
  875. $member_mobile,
  876. $v['mid'],
  877. date('Y-m-d H:i',$v['cdate']),
  878. );
  879. $body[] = $d;
  880. }
  881. } else {
  882. Dever::alert('无导出数据');
  883. }
  884. $file = Dever::input('excel_name');
  885. return Dever::excelExport($body, $header, $file);
  886. }
  887. }