Finance.php 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Finance extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_finance','finance');
  7. $this->load->_model('Model_fullorder','fullorder');
  8. $this->load->_model('Model_fullordertt','fullordertt');
  9. $this->load->_model('Model_fullordersmt','fullordersmt');
  10. $this->load->_model('Model_shop','shop');
  11. $this->load->_model('Model_typeclass','typeclass');
  12. $this->load->_model('Model_express','express');
  13. $this->load->_model('Model_country','country');
  14. $this->load->_model('Model_productdescribe','productdescribe');
  15. $this->load->_model('Model_customs','customs');
  16. $this->load->_model('Model_detailed','detailed');
  17. $this->load->_model('Model_productdescription','productdescription');
  18. $this->load->_model('Model_logistics','logistics');
  19. $this->load->_model('Model_hl','hl');
  20. $this->load->_model('Model_excel','excel');
  21. $this->load->_model('Model_warehouse','warehouse');
  22. $this->load->_model('Model_systemwigsout','systemwigsout');
  23. $this->load->_model('Model_classid','classid');
  24. }
  25. //定义方法的调用规则 获取URI第二段值
  26. public function _remap($arg,$arg_array)
  27. {
  28. if($arg == 'excel')
  29. {
  30. $this->_excel();
  31. }
  32. else if($arg == 'ckexcel')
  33. {
  34. $this->_ckexcel();
  35. }
  36. else if($arg == 'caiwu')
  37. {
  38. $this->_caiwu($arg_array);
  39. }
  40. else if($arg == 'ckcaiwu')
  41. {
  42. $this->_ckcaiwu();
  43. }
  44. else if($arg == 'product')
  45. {
  46. $this->_product($arg_array);
  47. }
  48. else if($arg == 'dhlfp')
  49. {
  50. $this->_dhlfp();
  51. }
  52. else if($arg == 'ouout')
  53. {
  54. $this->_ouout();
  55. }
  56. else if($arg == 'cksize')
  57. {
  58. $this->_cksize();
  59. }
  60. else
  61. {
  62. $this->_index($arg);
  63. }
  64. }
  65. //店铺统计
  66. public function _index($arg)
  67. {
  68. $fu = (isset($arg))?($arg=="smt"?"fullordersmt":"fullorder"):"fullorder";
  69. $user = $this->user->get_api($_SESSION['api']);
  70. if($user)
  71. {
  72. $fgshop = "";$sid = "";
  73. $user = explode('|',trim($user['shop'],'|'));
  74. foreach ($user as $value)
  75. {
  76. $fgshop .= " shop = ".$value." or";
  77. $sid .= " id = ".$value." or";
  78. }
  79. }
  80. $post = $this->input->post(NULL, TRUE);
  81. if(isset($post['page']))
  82. {
  83. $page = $this->input->post('page',true);
  84. $perpage = $this->input->post('perpage',true);
  85. $timetk = $this->input->post('timetk',true);
  86. $timetj = $this->input->post('timetj',true);
  87. $shop = $this->input->post('shop',true);
  88. $source = $this->input->post('source',true);
  89. $library = $this->input->post('library',true);
  90. $warehouse = $this->input->post('warehouse',true);
  91. $orderinfo = $this->input->post('orderinfo',true);
  92. $user = $this->input->post('user',true);
  93. $name = $this->input->post('name',true);
  94. $timetk = strtotime($timetk);
  95. $timetj = strtotime($timetj);
  96. $where = "mergeid = 0";
  97. if($timetk && $timetj)
  98. {
  99. $where .= " and librarytime > '$timetk' and librarytime < '$timetj'";
  100. }
  101. if($shop)
  102. {
  103. $where .= " and shop = '$shop'";
  104. }
  105. if($source)
  106. {
  107. $where .= " and source = '$source'";
  108. }
  109. if($library)
  110. {
  111. $where .= " and library = '$library'";
  112. }
  113. if($warehouse)
  114. {
  115. $where .= " and type = '$warehouse'";
  116. }
  117. if($orderinfo)
  118. {
  119. $where .= " and orderinfo = '$orderinfo'";
  120. }
  121. if($user)
  122. {
  123. $where .= " and user = '$user'";
  124. }
  125. if($name)
  126. {
  127. $where .= " and name = '$name'";
  128. }
  129. //数据排序
  130. $order_str = "id desc";
  131. if(empty($page))
  132. {
  133. $start = 0;
  134. $perpage = 1;
  135. }
  136. else
  137. {
  138. $start = ($page - 1)*$perpage;
  139. }
  140. $shouldmoney=0;$expressmoney=0;$budget=0;$refundj=0;
  141. //取得信息列表
  142. $info_list = $this->$fu->find_all($where,'id,shop,user,type,orderinfo,shouldmoney,budget,expressmoney,refundj,orderremarks,hl',$order_str,$start,$perpage);
  143. //格式化数据
  144. foreach ($info_list as $key=>$value)
  145. {
  146. $order = $this->$fu->read($value['id']);
  147. $order['hl'] = $order['hl']!=0?$order['hl']:6.71;
  148. $shop = $this->shop->read($value['shop']);
  149. $info_list[$key]['shop'] = $shop['shopname'];
  150. $info_list[$key]['user'] = $shop['shopuser'];
  151. $warehouse = $this->warehouse->read($value['type']);
  152. $info_list[$key]['type'] = $warehouse['title'];
  153. $info_list[$key]['shouldmoney'] = ($order['currencytitle']=='CNY')?sprintf("%.2f",$order['shouldmoney']/$order['hl']):$value['shouldmoney'];
  154. $shouldmoney += $info_list[$key]['shouldmoney'];
  155. $expressmoney += $info_list[$key]['expressmoney'];
  156. $info_list[$key]['budget'] = ($order['currencytitle']=='CNY')?sprintf("%.2f",$order['budget']/$order['hl']):$value['budget'];
  157. $budget += $info_list[$key]['budget'];
  158. $refundj += $info_list[$key]['refundj'];
  159. }
  160. $money = $this->$fu->find_all($where);
  161. $shouldmoney = sprintf("%.2f",$shouldmoney);
  162. $expressmoney = sprintf("%.2f",$expressmoney);
  163. $budget = sprintf("%.2f",$budget);
  164. $refundj = sprintf("%.2f",$refundj);
  165. $total = $this->$fu->find_count($where);
  166. $pagenum = ceil($total/$perpage);
  167. $over = $total-($start+$perpage);
  168. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'money'=>(array($shouldmoney,$budget,$expressmoney,$refundj)));
  169. echo json_encode($rows);exit;
  170. }
  171. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  172. $this->data['wlshop'] = $wlshop;
  173. $this->data['arg'] = $arg;
  174. $this->_Template('finance',$this->data);
  175. }
  176. public function _caiwu($arg_array)
  177. {
  178. $user = $this->user->get_api($_SESSION['api']);
  179. if($user)
  180. {
  181. $fgshop = "";$sid = "";
  182. $user = explode('|',trim($user['shop'],'|'));
  183. foreach ($user as $value)
  184. {
  185. $fgshop .= " shop = ".$value." or";
  186. $sid .= " id = ".$value." or";
  187. }
  188. }
  189. $post = $this->input->post(NULL, TRUE);
  190. if(isset($post['page']))
  191. {
  192. $page = $this->input->post('page',true);
  193. $perpage = $this->input->post('perpage',true);
  194. $timetk = $this->input->post('timetk',true);
  195. $timetj = $this->input->post('timetj',true);
  196. $shop = $this->input->post('shop',true);
  197. $source = $this->input->post('source',true);
  198. $library = $this->input->post('library',true);
  199. $warehouse = $this->input->post('warehouse',true);
  200. $orderinfo = $this->input->post('orderinfo',true);
  201. $number = $this->input->post('number',true);
  202. $user = $this->input->post('user',true);
  203. $name = $this->input->post('name',true);
  204. $xztime = $this->input->post('xztime',true);
  205. $country = $this->input->post('country',true);
  206. $paypal = $this->input->post('paypal',true);
  207. $fullorder = $this->input->post('fullorder',true);
  208. $timetk = strtotime($timetk);
  209. $timetj = strtotime($timetj);
  210. $where = "mergeid = 0";
  211. if($timetk && $timetj)
  212. {
  213. $where .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
  214. }
  215. if($shop)
  216. {
  217. $where .= " and shop = '$shop'";
  218. }
  219. if($source)
  220. {
  221. $where .= " and source = '$source'";
  222. }
  223. if($library)
  224. {
  225. $where .= " and library = '$library'";
  226. }
  227. if($warehouse)
  228. {
  229. $where .= " and type = '$warehouse'";
  230. }
  231. if($orderinfo)
  232. {
  233. $where .= " and orderinfo = '$orderinfo'";
  234. }
  235. if($number)
  236. {
  237. $where .= " and number = '$number'";
  238. }
  239. if($user)
  240. {
  241. $where .= " and user = '$user'";
  242. }
  243. if($name)
  244. {
  245. $where .= " and name = '$name'";
  246. }
  247. if($country)
  248. {
  249. $where .= " and country = '$country'";
  250. }
  251. if($paypal)
  252. {
  253. $where .= " and paypal = '$paypal'";
  254. }
  255. //数据排序
  256. $order_str = "id desc";
  257. if(empty($page))
  258. {
  259. $start = 0;
  260. $perpage = 1;
  261. }
  262. else
  263. {
  264. $start = ($page - 1)*$perpage;
  265. }
  266. $shouldmoney=0;$expressmoney=0;$budget=0;$refundj=0;$cost=0;$lr=0;
  267. //取得信息列表
  268. if($fullorder == 'fullordersmt')
  269. {
  270. $info_list = $this->fullordersmt->find_all($where,'id,shop,user,type,orderinfo,shouldmoney,budget,expressmoney,refundj,cost,merge,currencytitle,orderremarks,hl',$order_str,$start,$perpage);
  271. $total = $this->fullordersmt->find_count($where);
  272. }
  273. else if($fullorder == 'fullorder')
  274. {
  275. $info_list = $this->fullorder->find_all($where,'id,shop,user,type,orderinfo,shouldmoney,budget,expressmoney,refundj,cost,merge,currencytitle,orderremarks,hl',$order_str,$start,$perpage);
  276. $total = $this->fullorder->find_count($where);
  277. }
  278. else if($fullorder == 'fullordertt')
  279. {
  280. $info_list = $this->fullordertt->find_all($where,'id,shop,user,type,orderinfo,shouldmoney,budget,expressmoney,refundj,cost,merge,currencytitle,orderremarks,hl',$order_str,$start,$perpage);
  281. $total = $this->fullordertt->find_count($where);
  282. }
  283. else
  284. {
  285. $info_lista = $this->fullordersmt->find_all($where,'id,shop,user,type,orderinfo,shouldmoney,budget,expressmoney,refundj,cost,merge,currencytitle,orderremarks,hl',$order_str,$start,$perpage);
  286. $info_listb = $this->fullorder->find_all($where,'id,shop,user,type,orderinfo,shouldmoney,budget,expressmoney,refundj,cost,merge,currencytitle,orderremarks,hl',$order_str,$start,$perpage);
  287. $info_listc = $this->fullordertt->find_all($where,'id,shop,user,type,orderinfo,shouldmoney,budget,expressmoney,refundj,cost,merge,currencytitle,orderremarks,hl',$order_str,$start,$perpage);
  288. $info_list = array_merge($info_lista,$info_listb);
  289. $total = $this->fullordersmt->find_count($where);
  290. $total += $this->fullorder->find_count($where);
  291. $total += $this->fullordertt->find_count($where);
  292. }
  293. //格式化数据
  294. foreach ($info_list as $key=>$value)
  295. {
  296. $shop = $this->shop->read($value['shop']);
  297. $fu = ($shop['type'] == "269")?'fullorder':'fullordersmt';
  298. $order = $this->$fu->read($value['id']);
  299. $order['hl'] = $order['hl']!=0?$order['hl']:6.71;
  300. $info_list[$key]['shop'] = $shop['shopname'];
  301. $info_list[$key]['user'] = $shop['shopuser'];
  302. $warehouse = $this->warehouse->read($value['type']);
  303. $info_list[$key]['type'] = $warehouse['title'];
  304. $merge = $info_list[$key]['budget']-$info_list[$key]['refundj']-$info_list[$key]['cost']/$order['hl']-$info_list[$key]['expressmoney'];
  305. $info_list[$key]['merge'] = sprintf("%.2f",$merge);//利润
  306. $currencytitle = ($merge!=0 && $info_list[$key]['budget']!=0)?$merge/$info_list[$key]['budget']*100:0;
  307. $info_list[$key]['currencytitle'] = $currencytitle==0?'0'.'%':sprintf("%.2f",$currencytitle)."%";//利润百分比
  308. $info_list[$key]['shouldmoney'] = ($order['currencytitle']=='CNY')?sprintf("%.2f",$order['shouldmoney']/$order['hl']):$value['shouldmoney'];
  309. $shouldmoney += $info_list[$key]['shouldmoney'];
  310. $expressmoney += $info_list[$key]['expressmoney'];
  311. $info_list[$key]['budget'] = ($order['currencytitle']=='CNY')?sprintf("%.2f",$order['budget']/$order['hl']):$value['budget'];
  312. $budget += $info_list[$key]['budget'];
  313. $refundj += $info_list[$key]['refundj'];
  314. $cost += $info_list[$key]['cost'];
  315. $lr += $merge;
  316. }
  317. $shouldmoney = sprintf("%.2f",$shouldmoney);
  318. $expressmoney = sprintf("%.2f",$expressmoney);
  319. $budget = sprintf("%.2f",$budget);
  320. $refundj = sprintf("%.2f",$refundj);
  321. $cost = sprintf("%.2f",$cost);
  322. $lr = sprintf("%.2f",$lr);
  323. $pagenum = ceil($total/$perpage);
  324. $over = $total-($start+$perpage);
  325. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'money'=>(array($shouldmoney,$budget,$expressmoney,$refundj,$cost,$lr)));
  326. echo json_encode($rows);exit;
  327. }
  328. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  329. $this->data['wlshop'] = $wlshop;
  330. if(isset($arg_array[0]))
  331. {
  332. $is = ($arg_array[0] == 'dlz')?'1':'2';
  333. $arg = $arg_array[0];
  334. }
  335. else
  336. {
  337. $is = '1';
  338. $arg = 'dlz';
  339. }
  340. $this->data['is'] = $is;
  341. $this->data['arg'] =$arg;
  342. $this->_Template('finance_cw',$this->data);
  343. }
  344. public function _ckcaiwu()//仓库财务
  345. {
  346. $user = $this->user->get_api($_SESSION['api']);
  347. if($user)
  348. {
  349. $fgshop = "";$sid = "";
  350. $user = explode('|',trim($user['shop'],'|'));
  351. foreach ($user as $value)
  352. {
  353. $fgshop .= " shop = ".$value." or";
  354. $sid .= " id = ".$value." or";
  355. }
  356. }
  357. $post = $this->input->post(NULL, TRUE);
  358. if(isset($post['page']))
  359. {
  360. $page = $this->input->post('page',true);
  361. $perpage = $this->input->post('perpage',true);
  362. $timetk = $this->input->post('timetk',true);
  363. $timetj = $this->input->post('timetj',true);
  364. $shop = $this->input->post('shop',true);
  365. $source = $this->input->post('source',true);
  366. $library = $this->input->post('library',true);
  367. $warehouse = $this->input->post('warehouse',true);
  368. $orderinfo = $this->input->post('orderinfo',true);
  369. $user = $this->input->post('user',true);
  370. $name = $this->input->post('name',true);
  371. $timetk = strtotime($timetk);
  372. $timetj = strtotime($timetj);
  373. $fullorder = $this->input->post('fullorder',true);
  374. $where = "mergeid = 0";
  375. if($timetk && $timetj)
  376. {
  377. $where .= " and librarytime > '$timetk' and librarytime < '$timetj'";
  378. }
  379. if($shop)
  380. {
  381. $where .= " and shop = '$shop'";
  382. }
  383. if($source)
  384. {
  385. $where .= " and source = '$source'";
  386. }
  387. if($library)
  388. {
  389. $where .= " and library = '$library'";
  390. }
  391. if($warehouse)
  392. {
  393. $where .= " and type = '$warehouse'";
  394. }
  395. if($orderinfo)
  396. {
  397. $where .= " and orderinfo = '$orderinfo'";
  398. }
  399. if($user)
  400. {
  401. $where .= " and user = '$user'";
  402. }
  403. if($name)
  404. {
  405. $where .= " and name = '$name'";
  406. }
  407. //数据排序
  408. $order_str = "id desc";
  409. if(empty($page))
  410. {
  411. $start = 0;
  412. $perpage = 1;
  413. }
  414. else
  415. {
  416. $start = ($page - 1)*$perpage;
  417. }
  418. $shouldmoney=0;$expressmoney=0;$budget=0;$refundj=0;$purchase=0;$lr=0;
  419. //取得信息列表
  420. $info_list = $this->$fullorder->find_all($where,'id,shop,user,type,orderinfo,shouldmoney,budget,expressmoney,refundj,purchase,merge,currencytitle,orderremarks,hl',$order_str,$start,$perpage);
  421. //格式化数据
  422. foreach ($info_list as $key=>$value)
  423. {
  424. $order = $this->$fullorder->read($value['id']);
  425. $order['hl'] = $order['hl']!=0?$order['hl']:6.71;
  426. $shop = $this->shop->read($value['shop']);
  427. $info_list[$key]['shop'] = $shop['shopname'];
  428. $info_list[$key]['user'] = $shop['shopuser'];
  429. $warehouse = $this->warehouse->read($value['type']);
  430. $info_list[$key]['type'] = $warehouse['title'];
  431. $merge = $info_list[$key]['budget']-$info_list[$key]['refundj']-$info_list[$key]['purchase']/$order['hl']-$info_list[$key]['expressmoney'];
  432. $info_list[$key]['merge'] = sprintf("%.2f",$merge);//利润
  433. $currencytitle = ($merge!=0 && $info_list[$key]['budget']!=0)?$merge/$info_list[$key]['budget']*100:0;
  434. $info_list[$key]['currencytitle'] = $currencytitle==0?'0'.'%':sprintf("%.2f",$currencytitle)."%";//利润百分比
  435. $info_list[$key]['shouldmoney'] = ($order['currencytitle']=='CNY')?sprintf("%.2f",$order['shouldmoney']/$order['hl']):$value['shouldmoney'];
  436. $shouldmoney += $info_list[$key]['shouldmoney'];
  437. $expressmoney += $info_list[$key]['expressmoney'];
  438. $info_list[$key]['budget'] = ($order['currencytitle']=='CNY')?sprintf("%.2f",$order['budget']/$order['hl']):$value['budget'];
  439. $budget += $info_list[$key]['budget'];
  440. $refundj += $info_list[$key]['refundj'];
  441. $purchase += $info_list[$key]['purchase'];
  442. $lr += $merge;
  443. }
  444. $money = $this->$fullorder->find_all($where);
  445. $shouldmoney = sprintf("%.2f",$shouldmoney);
  446. $expressmoney = sprintf("%.2f",$expressmoney);
  447. $budget = sprintf("%.2f",$budget);
  448. $refundj = sprintf("%.2f",$refundj);
  449. $purchase = sprintf("%.2f",$purchase);
  450. $lr = sprintf("%.2f",$lr);
  451. $total = $this->$fullorder->find_count($where);
  452. $pagenum = ceil($total/$perpage);
  453. $over = $total-($start+$perpage);
  454. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'money'=>(array($shouldmoney,$budget,$expressmoney,$refundj,$purchase,$lr)));
  455. echo json_encode($rows);exit;
  456. }
  457. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  458. $this->data['wlshop'] = $wlshop;
  459. $this->_Template('finance_ckcw',$this->data);
  460. }
  461. //导出资金统计excel
  462. public function _excel()
  463. {
  464. if(isset($_GET['excel']))
  465. {
  466. $timetk = $this->input->get('timetk',true);
  467. $timetj = $this->input->get('timetj',true);
  468. $shop = $this->input->get('shop',true);
  469. $source = $this->input->get('source',true);
  470. $library = $this->input->get('library',true);
  471. $warehouse = $this->input->get('warehouse',true);
  472. $orderinfo = $this->input->get('orderinfo',true);
  473. $user = $this->input->get('user',true);
  474. $name = $this->input->get('name',true);
  475. $xztime = $this->input->get('xztime',true);
  476. $country = $this->input->get('country',true);
  477. $fullorder = $this->input->get('fullorder',true);
  478. $timetk = strtotime($timetk);
  479. $timetj = strtotime($timetj);
  480. $where = "mergeid = 0";
  481. if($timetk && $timetj)
  482. {
  483. $where .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
  484. }
  485. if($shop)
  486. {
  487. $where .= " and shop = '$shop'";
  488. }
  489. if($source)
  490. {
  491. $where .= " and source = '$source'";
  492. }
  493. if($library)
  494. {
  495. $where .= " and library = '$library'";
  496. }
  497. if($warehouse)
  498. {
  499. $where .= " and type = '$warehouse'";
  500. }
  501. if($orderinfo)
  502. {
  503. $where .= " and orderinfo = '$orderinfo'";
  504. }
  505. if($user)
  506. {
  507. $where .= " and user = '$user'";
  508. }
  509. if($name)
  510. {
  511. $where .= " and name = '$name'";
  512. }
  513. if($country)
  514. {
  515. $where .= " and country = '$country'";
  516. }
  517. /* 匹配ID加入 */
  518. $tc = array();$typeclass = array();
  519. $tclass = $this->typeclass->find_all();
  520. foreach ($tclass as $v)
  521. {
  522. $tc[$v['id']] = $v['title'];
  523. $typeclass[$v['id']] = $v;
  524. }
  525. $shouldmoney=0;$expressmoney=0;$budget=0;$refundj=0;$refundj=0;$cost=0;$lr=0;
  526. //取得信息列表
  527. if($fullorder == 'fullordersmt')
  528. {
  529. $info_list = $this->fullordersmt->find_all($where,'id,shop,user,type,client,orderinfo,number,shouldmoney,budget,expressmoney,cost,refundj,refundy,rpaypal,paypal,rtext,merge,mergeid,orderremarks,clientremarks,shipremarks,country,express,librarytime,fpdata,hl,currencytitle');
  530. }
  531. else if($fullorder == 'fullorder')
  532. {
  533. $info_list = $this->fullorder->find_all($where,'id,shop,user,type,client,orderinfo,number,shouldmoney,budget,expressmoney,cost,refundj,refundy,rpaypal,paypal,rtext,merge,mergeid,orderremarks,clientremarks,shipremarks,country,express,librarytime,fpdata,hl,currencytitle');
  534. }
  535. else if($fullorder == 'fullordertt')
  536. {
  537. $info_list = $this->fullordertt->find_all($where,'id,shop,user,type,client,orderinfo,number,shouldmoney,budget,expressmoney,cost,refundj,refundy,rpaypal,paypal,rtext,merge,mergeid,orderremarks,clientremarks,shipremarks,country,express,librarytime,fpdata,hl,currencytitle');
  538. }
  539. else
  540. {
  541. $info_lista = $this->fullordersmt->find_all($where,'id,shop,user,type,client,orderinfo,number,shouldmoney,budget,expressmoney,cost,refundj,refundy,rpaypal,paypal,rtext,merge,mergeid,orderremarks,clientremarks,shipremarks,country,express,librarytime,fpdata,hl,currencytitle');
  542. $info_listb = $this->fullorder->find_all($where,'id,shop,user,type,client,orderinfo,number,shouldmoney,budget,expressmoney,cost,refundj,refundy,rpaypal,paypal,rtext,merge,mergeid,orderremarks,clientremarks,shipremarks,country,express,librarytime,fpdata,hl,currencytitle');
  543. $info_listc = $this->fullordertt->find_all($where,'id,shop,user,type,client,orderinfo,number,shouldmoney,budget,expressmoney,cost,refundj,refundy,rpaypal,paypal,rtext,merge,mergeid,orderremarks,clientremarks,shipremarks,country,express,librarytime,fpdata,hl,currencytitle');
  544. $info_list = array_merge($info_lista,$info_listb,$info_listc);
  545. }
  546. //格式化数据
  547. $i = 0;
  548. $classid = $this->classid->sku();
  549. foreach ($info_list as $key=>$value)
  550. {
  551. $value['hl'] = $value['hl']!=0?$value['hl']:6.71;
  552. $shop = $this->shop->read($value['shop']);
  553. $info_list[$key]['shop'] = $shop['shopname'];
  554. $info_list[$key]['user'] = $shop['shopuser'];
  555. $warehouse = $this->warehouse->read($value['type']);
  556. $info_list[$key]['type'] = $warehouse['title'];
  557. $country = $this->country->read($value['country']);
  558. $info_list[$key]['country'] = $country['ename'];
  559. $express = $this->express->read($value['express']);
  560. $info_list[$key]['express'] = $express['servicename'];
  561. $merge = $info_list[$key]['budget']-$info_list[$key]['refundj']-$info_list[$key]['cost']/$value['hl']-$info_list[$key]['expressmoney'];
  562. $info_list[$key]['merge'] = sprintf("%.2f",$merge);//利润
  563. $mergeid = ($value['budget']!=0)?$merge/$info_list[$key]['budget']*100:0;
  564. $info_list[$key]['mergeid'] = sprintf("%.2f",$mergeid)."%";//利润百分比
  565. $info_list[$key]['shouldmoney'] = ($value['currencytitle']=='CNY')?sprintf("%.2f",$value['shouldmoney']/$value['hl']):$value['shouldmoney'];
  566. $shouldmoney += $info_list[$key]['shouldmoney'];
  567. $expressmoney += $info_list[$key]['expressmoney'];
  568. $info_list[$key]['budget'] = ($value['currencytitle']=='CNY')?sprintf("%.2f",$value['budget']/$value['hl']):$value['budget'];
  569. $budget += $info_list[$key]['budget'];
  570. $refundj += $info_list[$key]['refundj'];
  571. $cost += $info_list[$key]['cost'];
  572. $lr += $info_list[$key]['merge'];
  573. $info_list[$key]['librarytime'] = date('Y-m-d H:i:s',$value['librarytime']);
  574. $fpdata = array();
  575. if(stripos($value['fpdata'],';') !== false)
  576. {
  577. $fpdata = explode(';',rtrim($value['fpdata'],';'));
  578. foreach ($fpdata as $ke=>$va)
  579. {
  580. $dj = '';$ys = '';$hx = '';
  581. $pm = $classid;
  582. $jm = $classid;
  583. $bmpx = array(13=>'',16=>'',18=>'',25=>'',26=>'',41=>'');
  584. $features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$va);
  585. $ts = explode('|',trim($features,'|'));
  586. if(stripos($ts[0],',') !== false)
  587. {
  588. $ft = explode(',',$ts[0]);
  589. $features = explode('-',trim($ft[1],'-'));
  590. $features[] = $ft[0];
  591. }
  592. else
  593. {
  594. $features = explode('-',trim($ts[0],'-'));
  595. }
  596. foreach($features as $k=>$v)
  597. {
  598. if(isset($typeclass[$v]) && isset($bmpx[$typeclass[$v]['classid']]))
  599. {
  600. if($typeclass[$v]['bm'] != '')
  601. {
  602. $bmpx[$typeclass[$v]['classid']] = $typeclass[$v]['bm'];
  603. }
  604. }
  605. if($v != 0)
  606. {
  607. if($typeclass[$v]['classid'] == 13)
  608. {
  609. $dj = $typeclass[$v]['title'];
  610. }
  611. if($typeclass[$v]['classid'] == 8)
  612. {
  613. $ys = $typeclass[$v]['title'];
  614. }
  615. if($typeclass[$v]['classid'] == 15)
  616. {
  617. $hx = $typeclass[$v]['title'];
  618. }
  619. if(isset($pm[$typeclass[$v]['classid']]))
  620. {
  621. if($typeclass[$v]['title'] == '9A')
  622. {
  623. $pm[$typeclass[$v]['classid']] = '9A';
  624. }
  625. else if($typeclass[$v]['title'] == '10A')
  626. {
  627. $pm[$typeclass[$v]['classid']] = '10A';
  628. }
  629. else
  630. {
  631. $clzh = $typeclass[$v]['zh'];
  632. if(stripos($typeclass[$v]['zh'],'|') !== false)
  633. {
  634. $clzh = explode('|',rtrim($typeclass[$v]['zh'],'|'));
  635. $clzh = $clzh[0];
  636. }
  637. $pm[$typeclass[$v]['classid']] = $clzh;
  638. }
  639. }
  640. if(isset($jm[$typeclass[$v]['classid']]))
  641. {
  642. if($typeclass[$v]['jm'])
  643. {
  644. $jm[$typeclass[$v]['classid']] = $typeclass[$v]['jm'];
  645. }
  646. }
  647. }
  648. }
  649. $jm = array_filter($jm);//去除空值
  650. $jm = implode("-",$jm);
  651. $pm = array_filter($pm);//去除空值
  652. $zh = implode(" ",$pm);
  653. $zh = preg_replace("/\r\n|\r|\n/",'',trim($zh,' '));
  654. $fpdata[$ke] = array($ts[5],$dj,$ys,$hx,$jm,'03'.implode("",$bmpx),$ts[2]);//内容,尺寸,等级,颜色,数量
  655. }
  656. }
  657. $info_list[$key]['fpdata'] = $fpdata;
  658. $i++;
  659. }
  660. $shouldmoney = sprintf("%.2f",$shouldmoney);
  661. $expressmoney = sprintf("%.2f",$expressmoney);
  662. $budget = sprintf("%.2f",$budget);
  663. $refundj = sprintf("%.2f",$refundj);
  664. $cost = sprintf("%.2f",$cost);
  665. $lr = sprintf("%.2f",$lr);
  666. $data = array($shouldmoney.' USD',$budget.' USD',$expressmoney.' USD',$cost.' CNY',$refundj.' USD',$lr.' USD');
  667. $title = "财务统计信息";
  668. $titlename = "<table border=1>
  669. <tr><th colspan='25' align='left'><h3>".$title."<h3></th></tr>
  670. <tr>
  671. <td>NO.</td>
  672. <td>店铺名称</td>
  673. <td>负责人</td>
  674. <td>发货仓库</td>
  675. <td>客户名称</td>
  676. <td>订单号</td>
  677. <td>编号</td>
  678. <td>订单金额 USD</td>
  679. <td>预估金额 USD</td>
  680. <td>运费 USD</td>
  681. <td>成本 CNY</td>
  682. <td>补/退原额 USD</td>
  683. <td>补/退净额 USD</td>
  684. <td>补/退款交易号</td>
  685. <td>线下交易号</td>
  686. <td>原因</td>
  687. <td>利润 USD</td>
  688. <td>利润率</td>
  689. <td>订单备注</td>
  690. <td>客户备注</td>
  691. <td>发货备注</td>
  692. <td>国家</td>
  693. <td>物流</td>
  694. <td>出库时间</td>
  695. <td>
  696. <table border=1>
  697. <tr><td colspan='5' align='center'>订单产品信息</td></tr>
  698. <tr>
  699. <td>尺寸</td>
  700. <td>等级</td>
  701. <td>颜色</td>
  702. <td>花型</td>
  703. <td>料号</td>
  704. <td>编码</td>
  705. <td>数量</td>
  706. </tr>
  707. </table>
  708. </td>
  709. <td>总条数</td>
  710. </tr>
  711. </table>";
  712. $filename = $title.".xls";
  713. $tail = "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td>合计:</td><td>".$data[0]."</td><td>".$data[1]."</td><td>".$data[2]."</td><td>".$data[3]."</td><td>".$data[4]."</td><td></td><td></td><td></td><td></td><td>".$data[5]."</td><td></td><td></td></tr>\n";
  714. $this->excel->get_fz($info_list,$titlename,$filename,$tail);
  715. }
  716. }
  717. //仓库导出资金统计excel
  718. public function _ckexcel()
  719. {
  720. if(isset($_GET['excel']))
  721. {
  722. $timetk = $this->input->get('timetk',true);
  723. $timetj = $this->input->get('timetj',true);
  724. $shop = $this->input->get('shop',true);
  725. $source = $this->input->get('source',true);
  726. $library = $this->input->get('library',true);
  727. $warehouse = $this->input->get('warehouse',true);
  728. $orderinfo = $this->input->get('orderinfo',true);
  729. $user = $this->input->get('user',true);
  730. $name = $this->input->get('name',true);
  731. $timetk = strtotime($timetk);
  732. $timetj = strtotime($timetj);
  733. $fullorder = $this->input->get('fullorder',true);
  734. $where = "mergeid = 0";
  735. if($timetk && $timetj)
  736. {
  737. $where .= " and librarytime > '$timetk' and librarytime < '$timetj'";
  738. }
  739. if($shop)
  740. {
  741. $where .= " and shop = '$shop'";
  742. }
  743. if($source)
  744. {
  745. $where .= " and source = '$source'";
  746. }
  747. if($library)
  748. {
  749. $where .= " and library = '$library'";
  750. }
  751. if($warehouse)
  752. {
  753. $where .= " and type = '$warehouse'";
  754. }
  755. if($orderinfo)
  756. {
  757. $where .= " and orderinfo = '$orderinfo'";
  758. }
  759. if($user)
  760. {
  761. $where .= " and user = '$user'";
  762. }
  763. if($name)
  764. {
  765. $where .= " and name = '$name'";
  766. }
  767. /* 匹配ID加入 */
  768. $tc = array();
  769. $typeclass = $this->typeclass->find_all();
  770. foreach ($typeclass as $v)
  771. {
  772. if($_GET['excel'] == 2)
  773. {
  774. if($v['zh'] == '')
  775. {
  776. $tc[$v['id']] = $v['title'];
  777. }
  778. else
  779. {
  780. $tc[$v['id']] = $v['zh'];
  781. }
  782. }
  783. else
  784. {
  785. $tc[$v['id']] = $v['title'];
  786. }
  787. }
  788. $purchase=0;$cost=0;$lr=0;
  789. //取得信息列表
  790. $info_list = $this->$fullorder->find_all($where,'id,type,orderinfo,number,purchase,cost,merge,shipremarks,fpdata,hl,currencytitle');
  791. //格式化数据
  792. $i = 0;
  793. foreach ($info_list as $key=>$value)
  794. {
  795. $order = $this->$fullorder->read($value['id']);
  796. $warehouse = $this->warehouse->read($value['type']);
  797. $info_list[$key]['type'] = $warehouse['title'];
  798. $merge = $info_list[$key]['cost']-$info_list[$key]['purchase'];
  799. $info_list[$key]['merge'] = sprintf("%.2f",$merge);//利润
  800. $purchase += $info_list[$key]['purchase'];
  801. $cost += $info_list[$key]['cost'];
  802. $lr += $info_list[$key]['merge'];
  803. $fpdata = array();
  804. if(stripos($value['fpdata'],';') !== false)
  805. {
  806. $fpdata = explode(';',rtrim($value['fpdata'],';'));
  807. foreach ($fpdata as $ke=>$va)
  808. {
  809. $title = '';
  810. $fg = explode('|',$va);
  811. $fg[0] = str_replace(array('163-','164-','165-','166-','-0-'),array('','','','','-'),$fg[0]);
  812. $cp = explode('-',rtrim($fg[0],'-'));
  813. $dj = (isset($cp[2]) && isset($tc[$cp[2]]))?$tc[$cp[2]]:'0';
  814. $ys = isset($cp[3])?(isset($tc[$cp[3]])?$tc[$cp[3]]:'没有此颜色'):'0';
  815. unset($cp[0],$cp[1],$cp[2],$cp[3]);
  816. foreach ($cp as $v)
  817. {
  818. if(isset($tc[$v]))
  819. {
  820. $title .= $tc[$v].' ';
  821. }
  822. }
  823. $fpdata[$ke] = array($fg[5],$dj,$ys,$title,$fg[2]);//内容,尺寸,等级,颜色,数量
  824. }
  825. }
  826. $info_list[$key]['fpdata'] = $fpdata;
  827. $i++;
  828. }
  829. $purchase = sprintf("%.2f",$purchase);
  830. $cost = sprintf("%.2f",$cost);
  831. $lr = sprintf("%.2f",$lr);
  832. $data = array($purchase.' CNY',$cost.' CNY',$lr.' CNY');
  833. $title = "财务统计信息";
  834. $titlename = "<table border=1>
  835. <tr><th colspan='10' align='left'><h3>".$title."<h3></th></tr>
  836. <tr>
  837. <td>NO.</td>
  838. <td>发货仓库</td>
  839. <td>订单号</td>
  840. <td>编号</td>
  841. <td>成本</td>
  842. <td>外贸成本</td>
  843. <td>利润</td>
  844. <td>发货备注</td>
  845. <td>
  846. <table border=1>
  847. <tr><td colspan='5' align='center'>订单产品信息</td></tr>
  848. <tr>
  849. <td>尺寸</td>
  850. <td>等级</td>
  851. <td>颜色</td>
  852. <td>花型</td>
  853. <td>数量</td>
  854. </tr>
  855. </table>
  856. </td>
  857. <td>总条数</td>
  858. </tr>
  859. </table>";
  860. $filename = $title.".xls";
  861. $tail = "<tr><td></td><td></td><td></td><td>合计:</td><td>".$data[0]."</td><td>".$data[1]."</td><td>".$data[2]."</td><td></td><td></td><td></td></tr>\n";
  862. $this->excel->get_fz($info_list,$titlename,$filename,$tail);
  863. }
  864. }
  865. //导出DHL发货清单统计excel
  866. public function _dhlfp()
  867. {
  868. if(isset($_GET['excel']))
  869. {
  870. $timetk = $this->input->get('timetk',true);
  871. $timetj = $this->input->get('timetj',true);
  872. $timetk = strtotime($timetk);
  873. $timetj = strtotime($timetj);
  874. $fullorder = $this->input->get('fullorder',true);
  875. $where = "mergeid = 0 and express = 1 and printtype = 1 and library = 2 and print = 3";
  876. if($timetk && $timetj)
  877. {
  878. $where .= " and librarytime > '$timetk' and librarytime < '$timetj'";
  879. }
  880. //取得信息列表
  881. $info_list = $this->$fullorder->find_all($where,'id,librarytime,waybill,country,al,zwpm,zsbjz');
  882. //格式化数据
  883. $i = 1;
  884. foreach ($info_list as $key=>$value)
  885. {
  886. $country = $this->country->read($value['country']);
  887. $info_list[$key]['country'] = $country['zname'];
  888. $info_list[$key]['id'] = $i;
  889. $info_list[$key]['librarytime'] = date('Y-m-d H:i:s',$value['librarytime']);
  890. $i++;
  891. }
  892. $title = "CN PLT- 发票导出清单";
  893. $titlename = "<table border=1>
  894. <tr>
  895. <td>序号</td>
  896. <td>业务日期</td>
  897. <td>转单号码</td>
  898. <td>目的地</td>
  899. <td>二字码</td>
  900. <td>中文品名</td>
  901. <td>申报价</td>
  902. </table>";
  903. $filename = $title.".xls";
  904. $tail = "";
  905. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  906. }
  907. }
  908. public function _product($arg_array)
  909. {
  910. $post = $this->input->post(NULL, TRUE);
  911. if(isset($post['id']))
  912. {
  913. $id = $this->input->post('id',true);
  914. $post['fpdata'] = $this->input->post('fpdata');
  915. $post['expressmoney'] = $this->input->post('expressmoney',true);
  916. $post['cost'] = $this->input->post('cost',true);
  917. $post['purchase'] = $this->input->post('purchase',true);
  918. $fullorder = $this->input->post('fullorder',true);
  919. /**
  920. if($post['state'] == 216 && $ud['state'] != 216)
  921. {
  922. echo json_encode(array('msg'=>'不可修改为完成状态','success'=>false));exit;
  923. }
  924. **/
  925. if($this->$fullorder->save($post,$id))
  926. {
  927. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  928. }
  929. else
  930. {
  931. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  932. }
  933. }
  934. $fullorder = $arg_array[0];
  935. $is = ($fullorder == 'fullorder')?'1':'2';
  936. $fpdata = array();
  937. $fullorder = $this->$fullorder->read($arg_array[1]);
  938. $fullorder['parameter'] = str_replace(",","---",$fullorder['parameter']);
  939. $e = $fullorder['express'];//快递信息
  940. $c = $fullorder['country'];//国家信息
  941. $data = $this->logistics->find_all('express = "'.$e.'" and country = "'.$c.'"');
  942. if($data)
  943. {
  944. $fullorder['expressmoney'] = sprintf("%.2f",$data[0]['firstmoney']);
  945. }
  946. $this->data['fullorder'] = $fullorder;
  947. $this->data['countrys'] = $this->country->find_all();
  948. $this->data['express'] = $this->express->find_all();
  949. if(stripos($fullorder['fpdata'],';') !== false)
  950. {
  951. $fpdata = explode(';',rtrim($fullorder['fpdata'],';'));
  952. foreach ($fpdata as $k=>$v)
  953. {
  954. $fpdata[$k] = explode('|',$v);
  955. }
  956. }
  957. $this->data['fpdata'] = $fpdata;
  958. $shop = $this->shop->read($fullorder['shop']);
  959. $this->data['et'] = $shop['estimaterate'];//此店铺配置预计到帐金额比例
  960. //单项开始
  961. $warehouse = $this->warehouse->read($fullorder['warehouse']);//发货仓库
  962. $state = $this->typeclass->read($fullorder['state']);//订单状态
  963. $country = $this->country->read($fullorder['country']);//国家
  964. if($fullorder['capital'] == 1)
  965. {
  966. $capital = '暂未支付';
  967. }
  968. else if($fullorder['capital'] == 2)
  969. {
  970. $capital = '部分支付';
  971. }
  972. else if($fullorder['capital'] == 3)
  973. {
  974. $capital = '全部支付';
  975. }
  976. if($fullorder['printtype'] == 1)
  977. {
  978. $printtype = '运单';
  979. }
  980. else if($fullorder['printtype'] == 2)
  981. {
  982. $printtype = '发货单';
  983. }
  984. else if($fullorder['printtype'] == 3)
  985. {
  986. $printtype = '不打印单据';
  987. }
  988. else
  989. {
  990. $printtype = '未选择';
  991. }
  992. $this->data['warehouse'] = $warehouse['title'];
  993. $this->data['state'] = $state['title'];
  994. $this->data['capital'] = $capital;
  995. $this->data['country'] = $country['ename'];
  996. $this->data['printtype'] = $printtype;
  997. $this->data['is'] = $is;
  998. $systemwigsout = $this->systemwigsout->get_number($fullorder['number']);
  999. $wigsout = array();
  1000. if($systemwigsout)
  1001. {
  1002. $cz = explode('|',trim($systemwigsout['cz'],'|'));
  1003. $cztime = explode('|',trim($systemwigsout['cztime'],'|'));
  1004. $zw = array(1=>'配货',2=>'高针',3=>'完成',4=>'曲发',5=>'前处理',6=>'后处理',7=>'发型师',8=>'包装');
  1005. if($systemwigsout['cz'] != '' && count($cz) > 0)
  1006. {
  1007. for($i=0;$i<count($cz);$i++)
  1008. {
  1009. if(!isset($cztime[$i]))
  1010. {
  1011. $wigsout[] = $zw[$cz[$i]];
  1012. }
  1013. else
  1014. {
  1015. $wigsout[] = $zw[$cz[$i]].' :'.date('Y-m-d H:i',$cztime[$i]);
  1016. }
  1017. }
  1018. }
  1019. }
  1020. $this->data['systemwigsout'] = $wigsout;
  1021. //单项结束
  1022. $this->_Template('finance_product',$this->data);
  1023. }
  1024. public function _ouout() //财务汇总导出
  1025. {
  1026. if(isset($_GET['excel']))
  1027. {
  1028. $timetk = $this->input->get('timetk',true);
  1029. $timetj = $this->input->get('timetj',true);
  1030. $shop = $this->input->get('shop',true);
  1031. $source = $this->input->get('source',true);
  1032. $library = $this->input->get('library',true);
  1033. $warehouse = $this->input->get('warehouse',true);
  1034. $orderinfo = $this->input->get('orderinfo',true);
  1035. $user = $this->input->get('user',true);
  1036. $name = $this->input->get('name',true);
  1037. $xztime = $this->input->get('xztime',true);
  1038. $country = $this->input->get('country',true);
  1039. $fullorder = $this->input->get('fullorder',true);
  1040. $timetk = strtotime($timetk);
  1041. $timetj = strtotime($timetj);
  1042. $where = "mergeid = 0";
  1043. if($timetk && $timetj)
  1044. {
  1045. $where .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
  1046. }
  1047. if($fullorder == 'sd')
  1048. {
  1049. echo '此功能只能单独导出独立站或速卖通数据';exit;
  1050. }
  1051. if($shop)
  1052. {
  1053. $where .= " and shop = '$shop'";
  1054. }
  1055. if($source)
  1056. {
  1057. $where .= " and source = '$source'";
  1058. }
  1059. if($library)
  1060. {
  1061. $where .= " and library = '$library'";
  1062. }
  1063. if($warehouse)
  1064. {
  1065. $where .= " and type = '$warehouse'";
  1066. }
  1067. if($orderinfo)
  1068. {
  1069. $where .= " and orderinfo = '$orderinfo'";
  1070. }
  1071. if($user)
  1072. {
  1073. $where .= " and user = '$user'";
  1074. }
  1075. if($name)
  1076. {
  1077. $where .= " and name = '$name'";
  1078. }
  1079. if($country)
  1080. {
  1081. $where .= " and country = '$country'";
  1082. }
  1083. //数据排序
  1084. $order_str = "id desc";
  1085. if(empty($page))
  1086. {
  1087. $start = 0;
  1088. $perpage = 1;
  1089. }
  1090. else
  1091. {
  1092. $start = ($page - 1)*$perpage;
  1093. }
  1094. //取得信息列表
  1095. $info_list = $this->$fullorder->find_all($where,'fpdata,library');
  1096. $rowsc = array();$rowst = array();
  1097. foreach ($info_list as $key=>$value)
  1098. {
  1099. $fpdata = explode(';',rtrim($value['fpdata'],';'));
  1100. foreach ($fpdata as $va)
  1101. {
  1102. $fpdatason = explode('|',$va);
  1103. $fpdatason[1] = rtrim($fpdatason[1],' ');
  1104. str_replace(array('Peruvian','Indian','Brazilian','Malaysian'),array('','','',''),$fpdatason[1]);
  1105. if($value['library'] == 2)
  1106. {
  1107. $c = 1; $t = 0;
  1108. }
  1109. else
  1110. {
  1111. $c = 0; $t = 1;
  1112. }
  1113. if(isset($rows[$fpdatason[1]]))
  1114. {
  1115. $rows[$fpdatason[1]]['c'] += $c;
  1116. $rows[$fpdatason[1]]['t'] += $t;
  1117. }
  1118. else
  1119. {
  1120. $rows[$fpdatason[1]]['a'] = $fpdatason[1];
  1121. $rows[$fpdatason[1]]['c'] = $c;
  1122. $rows[$fpdatason[1]]['t'] = $t;
  1123. }
  1124. }
  1125. }
  1126. $title = date('Y-m-d',$timetk).'至'.date('Y-m-d',$timetj).'汇总详情';
  1127. $titlename = "<table border=1>
  1128. <tr><th colspan='3' align='center'><h3>".$title."<h3></th></tr>
  1129. <tr align='center'>
  1130. <td>产品名称</td>
  1131. <td>销售数量</td>
  1132. <td>退货数量</td>
  1133. </tr>
  1134. </table>";
  1135. $filename = $title.".xls";
  1136. $tail = "";
  1137. $this->excel->get_fz2($rows,$titlename,$filename,$tail);
  1138. }
  1139. }
  1140. public function _cksize()
  1141. {
  1142. if(isset($_GET['excel']))
  1143. {
  1144. $type = $this->input->get('excel',true);
  1145. $category = $this->input->get('category',true);
  1146. $size = $this->input->get('size',true);
  1147. $grade = $this->input->get('grade',true);
  1148. $color = $this->input->get('color',true);
  1149. $lowe = $this->input->get('lowe',true);
  1150. $sku = $this->input->get('sku',true);
  1151. $warehouse = $this->input->get('warehouse',true);
  1152. $shop = $this->input->get('shop',true);
  1153. $sid = $this->input->get('sid',true);
  1154. $ktime = $this->input->get('ktime',true);
  1155. $jtime = $this->input->get('jtime',true);
  1156. $ktime = strtotime($ktime);
  1157. $jtime = strtotime($jtime);
  1158. $where = "1=1 and shop != 9 and shop != 26";$gj = "";$ck = "";
  1159. if($category)
  1160. {
  1161. $where .= " and fpdata like '%-$category-%'";
  1162. }
  1163. if($size)
  1164. {
  1165. $where .= " and fpdata like '%-$size-%'";
  1166. }
  1167. if($grade)
  1168. {
  1169. $where .= " and fpdata like '%-$grade-%'";
  1170. }
  1171. if($color)
  1172. {
  1173. $where .= " and fpdata like '%-$color-%'";
  1174. }
  1175. if($lowe)
  1176. {
  1177. $where .= " and fpdata like '%-$lowe-%'";
  1178. }
  1179. if($shop)
  1180. {
  1181. $shopdata = '';
  1182. $sd = explode(',',rtrim($shop,','));
  1183. foreach ($sd as $v)
  1184. {
  1185. $shopdata .= "shop = '$v' or ";
  1186. }
  1187. $where .= " and (".rtrim($shopdata,'or ').")";
  1188. }
  1189. if($warehouse)
  1190. {
  1191. $warehousedata = '';
  1192. $wd = explode(',',rtrim($warehouse,','));
  1193. foreach ($wd as $v)
  1194. {
  1195. $warehousedata .= "warehouse = '$v' or ";
  1196. }
  1197. $where .= " and (".rtrim($warehousedata,'or ').")";
  1198. }
  1199. if($sku)
  1200. {
  1201. $where .= " and sku like '%$sku%'";
  1202. }
  1203. if($ktime && $jtime)
  1204. {
  1205. $where .= " and librarytime > '$ktime' and librarytime < '$jtime'";
  1206. }
  1207. $sidwhere = '';
  1208. if($sid)
  1209. {
  1210. $sd = "";
  1211. $s = explode(',',trim($sid,','));
  1212. foreach ($s as $value)
  1213. {
  1214. $sd .= " id = ".$value." or";
  1215. }
  1216. $sidwhere .= " and (".rtrim($sd,'or').")";
  1217. }
  1218. $typeclass = array();
  1219. $tc = $this->typeclass->find_all();
  1220. foreach ($tc as $v)
  1221. {
  1222. $typeclass[$v['id']] = array('ae'=>$v['spare'],'zh'=>$v['zh']);
  1223. }
  1224. //取得信息列表
  1225. $timeread = $ktime;
  1226. $timenum = ceil(($jtime - $ktime) / (24*3600));
  1227. $timelist = array();
  1228. for($i=4;$i<41;$i++)
  1229. {
  1230. if ($i%2==0)
  1231. {
  1232. $timelist[$i] = 0;
  1233. }
  1234. }
  1235. $info_lista = $this->fullorder->find_all($where.$sidwhere,'fpdata,number');
  1236. $info_listb = $this->fullordersmt->find_all($where.$sidwhere,'fpdata,number');
  1237. $info_listc = $this->fullordertt->find_all($where.$sidwhere,'fpdata,number');
  1238. $info_list = array_merge($info_lista,$info_listb,$info_listc);
  1239. //echo "<pre>";
  1240. //print_r($info_list);
  1241. //exit();
  1242. $rows = array();$list = array();$cw = array();
  1243. foreach ($info_list as $key=>$value)
  1244. {
  1245. $thistime = $timelist;
  1246. $zdata = explode(';',trim($value['fpdata'],';'));
  1247. foreach ($zdata as $v)
  1248. {
  1249. if(stripos($v,'-131-') !== false || ($category != '' && stripos($v,'-'.$category.'-') === false))
  1250. {
  1251. continue;
  1252. }
  1253. $fpdata = explode('|',trim($v,'|'));
  1254. $xqdata = explode(',',trim($fpdata[0],','));
  1255. $cc = $typeclass[$xqdata[0]]['ae'];
  1256. if(!isset($xqdata[1]))
  1257. {
  1258. $cw[] = array($value['fpdata'],$value['number']);
  1259. }
  1260. $sku = $xqdata[1];
  1261. if(isset($rows[$sku]))
  1262. {
  1263. $rows[$sku][2][$cc] += 1;
  1264. }
  1265. else
  1266. {
  1267. $zh = '';
  1268. $zhdata = explode('-',trim($sku,'-'));
  1269. foreach ($zhdata as $kk => $vv)
  1270. {
  1271. if(isset($typeclass[$vv]['zh']) && $kk != 0)
  1272. {
  1273. $zh .= $typeclass[$vv]['zh'].' ';
  1274. }
  1275. }
  1276. $rows[$sku][0] = preg_replace('/ (\d+)inch/','',$fpdata[1]);
  1277. $rows[$sku][1] = trim($zh,' ');
  1278. $rows[$sku][2] = $thistime;
  1279. $rows[$sku][2][$cc] += 1;
  1280. }
  1281. }
  1282. }
  1283. $str = "<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">
  1284. <head>
  1285. <!--[if gte mso 9]><xml>
  1286. <x:ExcelWorkbook>
  1287. <x:ExcelWorksheets>
  1288. <x:ExcelWorksheet>
  1289. <x:Name>EXCEL</x:Name>
  1290. <x:WorksheetOptions>
  1291. <x:Print>
  1292. <x:ValidPrinterInfo />
  1293. </x:Print>
  1294. </x:WorksheetOptions>
  1295. </x:ExcelWorksheet>
  1296. </x:ExcelWorksheets>
  1297. </x:ExcelWorkbook>
  1298. </xml>
  1299. <![endif]-->
  1300. </head><body>";
  1301. $str .= "<table border=1><tr>";
  1302. $str .="<td>英文</td>";
  1303. $str .="<td>中文</td>";
  1304. foreach ($timelist as $k=>$v)
  1305. {
  1306. $str .="<td>".$k."</td>";
  1307. }
  1308. $str .= "</tr></table>";
  1309. $str .= "<table border=1 style='font-family: Microsoft Yahei;font-size: 13px;'>";
  1310. foreach ($rows as $key=>$val)
  1311. {
  1312. $str .= "<tr><td>".$val[0]."</td>";
  1313. $str .= "<td>".$val[1]."</td>";
  1314. foreach ($val[2] as $k=>$v)
  1315. {
  1316. $str .= "<td>".$v."</td>";
  1317. }
  1318. $str .= "</tr>";
  1319. }
  1320. $str .= "</table>";
  1321. $str .= "</body></html>";
  1322. header( "Content-Type: application/vnd.ms-excel; name='excel'" );
  1323. header( "Content-type: application/octet-stream" );
  1324. header( "Content-Disposition: attachment; filename=".time().'.xls' );
  1325. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  1326. header( "Pragma: no-cache" );
  1327. header( "Expires: 0" );
  1328. exit($str);
  1329. }
  1330. if(isset($_SESSION['api']))
  1331. {
  1332. $user = $this->user->get_api($_SESSION['api']);
  1333. $usp = $user;
  1334. $fgshop = "";$sid = "";
  1335. $usersp = explode('|',trim($user['shop'],'|'));
  1336. foreach ($usersp as $value)
  1337. {
  1338. $fgshop .= " shop = ".$value." or";
  1339. $sid .= " id = ".$value." or";
  1340. }
  1341. }
  1342. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  1343. $this->data['wlshop'] = $wlshop;
  1344. $this->_Template('finance_cksize',$this->data);
  1345. }
  1346. }