Fullorderexcel.php 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Fullorderexcel extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_fullorder','fullorder');
  7. $this->load->_model('Model_fullordertt','fullordertt');
  8. $this->load->_model('Model_fullorder_smt','fullorder_smt');
  9. $this->load->_model('Model_fullordersmt','fullordersmt');
  10. $this->load->_model('Model_fullorderexcel','fullorderexcel');
  11. $this->load->_model('Model_fullorderexcelclassid','fullorderexcelclassid');
  12. $this->load->_model('Model_shop','shop');
  13. $this->load->_model('Model_country','country');
  14. $this->load->_model('Model_warehouse','warehouse');
  15. $this->load->_model('Model_excel','excel');
  16. $this->load->_model('Model_notice','notice');
  17. $this->load->_model('Model_express','express');
  18. $this->load->_model('Model_api','api');
  19. $this->load->_model('Model_apismt','apismt');
  20. $this->load->_model('Model_usps','usps');
  21. $this->load->_model('Model_typeclass','typeclass');
  22. $this->load->_model('Model_systemwigsout','systemwigsout');
  23. $this->load->_model('Model_setting','setting');
  24. $this->load->_model('Model_customer','customer');
  25. $this->load->_model('Model_customersmt','customersmt');
  26. $this->load->_model('Model_orderurl','orderurl');
  27. $this->load->_model('Model_whlabel','whlabel');
  28. $this->load->_model('Model_whlabel_bh','whlabel_bh');
  29. $this->load->_model('Model_apiyy','apiyy');
  30. $this->load->_model('Model_classid','classid');
  31. $this->load->_model('Model_systemtransfer','systemtransfer');
  32. $this->load->_model('Model_transfer','transfer');
  33. $this->load->_model('Model_classid','classid');
  34. $this->load->_model('Model_whlabel_type','whlabel_type');
  35. }
  36. //定义方法的调用规则 获取URI第二段值
  37. public function _remap($arg,$arg_array)
  38. {
  39. if($arg == 'excel')
  40. {
  41. $this->_excel();
  42. }
  43. else if($arg == 'add')
  44. {
  45. $this->_add();
  46. }
  47. else if($arg == 'edit')
  48. {
  49. $this->_edit($arg_array);
  50. }
  51. else if($arg == 'del')
  52. {
  53. $this->_del();
  54. }
  55. else if($arg == 'rows')
  56. {
  57. $this->_rows();
  58. }
  59. else if($arg == 'waybill')
  60. {
  61. $this->_waybill($arg_array);
  62. }
  63. else if($arg == 'order')
  64. {
  65. $this->_order($arg_array);
  66. }
  67. else if($arg == 'xxpl')//线下批量导入
  68. {
  69. $this->_xxpl();
  70. }
  71. else if($arg == 'cs')
  72. {
  73. $this->_cs();
  74. }
  75. else if($arg == 'scwd')
  76. {
  77. $this->_scwd();
  78. }
  79. else if($arg == 'jmexcel')
  80. {
  81. $this->_jmexcel();
  82. }
  83. else if($arg == 'classid')
  84. {
  85. $this->_classid();
  86. }
  87. else if($arg == 'classidadd')
  88. {
  89. $this->_classidadd();
  90. }
  91. else if($arg == 'classidedit')
  92. {
  93. $this->_classidedit($arg_array);
  94. }
  95. else
  96. {
  97. $this->_index();
  98. }
  99. }
  100. //管理
  101. public function _index()
  102. {
  103. $post = $this->input->post(NULL, TRUE);
  104. if(isset($post['page']))
  105. {
  106. $page = $this->input->post('page',true);
  107. $perpage = $this->input->post('perpage',true);
  108. $type = $this->input->post('type',true);
  109. $where = "1=1 ";
  110. //数据排序
  111. $order_str = "id asc";
  112. if(empty($page))
  113. {
  114. $start = 0;
  115. $perpage = 1;
  116. }
  117. else
  118. {
  119. $start = ($page - 1)*$perpage;
  120. }
  121. if($type)
  122. {
  123. $where .= " and type = '$type'";
  124. }
  125. //取得信息列表
  126. $info_list = $this->fullorderexcel->find_all($where,'id,type,title',$order_str,$start,$perpage);
  127. foreach ($info_list as $k=>$v)
  128. {
  129. $classid = $this->fullorderexcelclassid->read($v['type']);
  130. $info_list[$k]['type'] = $classid['title'];
  131. }
  132. $total = $this->fullorderexcel->find_count($where);
  133. $pagenum = ceil($total/$perpage);
  134. $over = $total-($start+$perpage);
  135. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  136. echo json_encode($rows);exit;
  137. }
  138. $classid = $this->fullorderexcelclassid->find_all();
  139. $this->data['classid'] = $classid;
  140. $this->_Template('fullorderexcel',$this->data);
  141. }
  142. //添加
  143. public function _add()
  144. {
  145. $post = $this->input->post(NULL, TRUE);
  146. if(isset($post['title']))
  147. {
  148. $post['title'] = $this->input->post('title',true);
  149. $post['type'] = $this->input->post('type',true);
  150. $post['content'] = $this->input->post('content',true);
  151. $post['contentzh'] = $this->input->post('contentzh',true);
  152. if($this->fullorderexcel->insert($post))
  153. {
  154. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  155. }
  156. else
  157. {
  158. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  159. }
  160. }
  161. $classid = $this->fullorderexcelclassid->find_all();
  162. $this->data['classid'] = $classid;
  163. $this->_Template('fullorderexcel_add',$this->data);
  164. }
  165. //修改
  166. public function _edit($arg_array)
  167. {
  168. $post = $this->input->post(NULL, TRUE);
  169. if(isset($post['id']))
  170. {
  171. $id = $this->input->post('id',true);
  172. $post['title'] = $this->input->post('title',true);
  173. $post['type'] = $this->input->post('type',true);
  174. $post['content'] = $this->input->post('content',true);
  175. $post['contentzh'] = $this->input->post('contentzh',true);
  176. if($this->fullorderexcel->save($post,$id))
  177. {
  178. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  179. }
  180. else
  181. {
  182. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  183. }
  184. }
  185. $arg_array = $arg_array[0];
  186. $fullorderexcel = $this->fullorderexcel->read($arg_array);
  187. $this->data['fullorderexcel'] = $fullorderexcel;
  188. $classid = $this->fullorderexcelclassid->find_all();
  189. $this->data['classid'] = $classid;
  190. $this->_Template('fullorderexcel_edit',$this->data);
  191. }
  192. //删除
  193. public function _del()
  194. {
  195. $post = $this->input->post(NULL, TRUE);
  196. if(isset($post['s']))
  197. {
  198. $id_arr = $this->input->post('s');
  199. $id_arr = explode(',',$id_arr);
  200. if(!$id_arr)
  201. {
  202. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  203. }
  204. //循环删除记录
  205. foreach ($id_arr as $v)
  206. {
  207. $this->fullorderexcel->remove($v);
  208. }
  209. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  210. }
  211. }
  212. //获取数据
  213. public function _rows()
  214. {
  215. $post = $this->input->post(NULL, TRUE);
  216. if(isset($post['id']))
  217. {
  218. $id = $this->input->post('id',true);
  219. $fullorderexcel = $this->fullorderexcel->read($id);
  220. $content = explode('|',rtrim($fullorderexcel['content'],'|'));
  221. $contentzh = explode('|',rtrim($fullorderexcel['contentzh'],'|'));
  222. $data = array();
  223. for($i=0;$i<count($content);$i++)
  224. {
  225. $a = explode('-',$content[$i]);
  226. $b = explode('-',$contentzh[$i]);
  227. $data[] = array(0=>$a[1],1=>$b[1]);
  228. }
  229. echo json_encode(array('rows'=>($data),'success'=>true));
  230. }
  231. }
  232. //导出订单excel
  233. public function _excel()
  234. {
  235. if(isset($_SESSION['api']))
  236. {
  237. $user = $this->user->get_api($_SESSION['api']);
  238. $usp = $user;
  239. $fgshop = "";$sid = "";$excelshop="";
  240. $usersp = explode('|',trim($user['shop'],'|'));
  241. foreach ($usersp as $value)
  242. {
  243. $fgshop .= " shop = ".$value." or";
  244. $sid .= " id = ".$value." or";
  245. }
  246. $userexcel = explode('|',trim($user['excelshop'],'|'));
  247. foreach ($userexcel as $value)
  248. {
  249. $excelshop .= " shop = ".$value." or";
  250. }
  251. if($excelshop != "")
  252. {
  253. $excelshop = "(".rtrim($excelshop,'or').")";
  254. }
  255. }
  256. if(isset($_GET['fexcel']))
  257. {
  258. $typeclass = array();
  259. $tclass = $this->typeclass->find_all();
  260. foreach ($tclass as $v)
  261. {
  262. $typeclass[$v['id']] = $v;
  263. }
  264. $dowid = $this->input->get('a');
  265. $wid = "";
  266. if($dowid != "")
  267. {
  268. $id_arr = explode(',',rtrim($dowid,','));
  269. $wid .= " id = 0 or";
  270. foreach ($id_arr as $v)
  271. {
  272. $wid .= " id = '$v' or";
  273. }
  274. $wid = " and".rtrim($wid,'or');
  275. }
  276. $fexcel = $this->input->get('fexcel',true);
  277. $page = $this->input->get('page',true);
  278. $perpage = $this->input->get('perpage',true);
  279. $warehouse = $this->input->get('warehouse',true);
  280. $timetk = $this->input->get('timetk',true);
  281. $timetj = $this->input->get('timetj',true);
  282. $shop = $this->input->get('shop',true);
  283. $source = $this->input->get('source',true);
  284. $state = $this->input->get('state',true);
  285. $review = $this->input->get('review',true);
  286. $type = $this->input->get('type',true);
  287. $express = $this->input->get('express',true);
  288. $orderinfo = $this->input->get('orderinfo',true);
  289. $user = $this->input->get('user',true);
  290. $client = $this->input->get('name',true);
  291. $waybill = $this->input->get('waybill',true);
  292. $number = $this->input->get('number',true);
  293. $email = $this->input->get('email',true);
  294. $dlz = $this->input->get('dlz',true);
  295. $library = $this->input->get('library',true);
  296. $libraryconfirm = $this->input->get('libraryconfirm',true);
  297. $print = $this->input->get('print',true);
  298. $timetkk = $this->input->get('timetkk',true);
  299. $timetjj = $this->input->get('timetjj',true);
  300. $xztime = $this->input->get('xztime',true);
  301. $country = $this->input->get('country',true);
  302. $zf = $this->input->get('zf',true);
  303. $pay = $this->input->get('pay',true);
  304. $phone = $this->input->get('phone',true);
  305. $so = $this->input->get('so',true);
  306. $sfxh = $this->input->get('sfxh',true);
  307. $xdcs = $this->input->get('xdcs',true);
  308. $xdcs = $this->input->get('xdcs',true);
  309. $dbapi = $this->input->get('dbapi',true);
  310. $orderurl = $this->input->get('orderurl',true);
  311. $timetk = strtotime($timetk);
  312. $timetj = strtotime($timetj);
  313. $timetkk = strtotime($timetkk);
  314. $timetjj = strtotime($timetjj);
  315. $px = $this->input->get('px',true);
  316. $fexcel = $this->fullorderexcel->read($fexcel);
  317. $classid = $this->fullorderexcelclassid->read($fexcel['type']);
  318. $where = "mergeid = 0 and (".rtrim($fgshop,'or').")";
  319. if($warehouse)
  320. {
  321. $where .= " and type = '$warehouse'";
  322. }
  323. if($xztime)
  324. {
  325. if($timetk && $timetj)
  326. {
  327. $where .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
  328. }
  329. if($timetkk && $timetjj)
  330. {
  331. $where .= " and ".$xztime." > '$timetkk' and ".$xztime." < '$timetjj'";
  332. }
  333. }
  334. else
  335. {
  336. $where .= " and dtime > '$timetk' and dtime < '$timetj'";
  337. }
  338. if($library)
  339. {
  340. $where .= " and library = '$library'";
  341. }
  342. if($print)
  343. {
  344. $where .= " and print = '$print'";
  345. }
  346. if($shop)
  347. {
  348. $where .= " and shop = '$shop'";
  349. }
  350. if($source)
  351. {
  352. if($source == '2d')
  353. {
  354. $where .= " and source >= '2'";
  355. }
  356. else
  357. {
  358. $where .= " and source = '$source'";
  359. }
  360. }
  361. if($state)
  362. {
  363. $where .= " and state = '$state'";
  364. }
  365. if($review)
  366. {
  367. $where .= " and review = '$review'";
  368. }
  369. if($type)
  370. {
  371. $where .= " and type = '$type'";
  372. }
  373. if($express)
  374. {
  375. $where .= " and express = '$express'";
  376. }
  377. if($orderinfo)
  378. {
  379. $where .= " and orderinfo = '$orderinfo'";
  380. }
  381. if($user)
  382. {
  383. $where .= " and user = '$user'";
  384. }
  385. if($client)
  386. {
  387. $where .= " and client like '%$client%'";
  388. }
  389. if($waybill)
  390. {
  391. $where .= " and waybill = '$waybill'";
  392. }
  393. if($number)
  394. {
  395. $where .= " and number = '$number'";
  396. }
  397. if($email)
  398. {
  399. $where .= " and email = '$email'";
  400. }
  401. if($country)
  402. {
  403. $where .= " and country = '$country'";
  404. }
  405. if($dlz)
  406. {
  407. $where .= " and waybill != '' and dlz = 0";
  408. }
  409. if($libraryconfirm)
  410. {
  411. $where .= " and libraryconfirm = '$libraryconfirm'";
  412. }
  413. if($so)
  414. {
  415. $where .= " and shipremarks like '%$so%'";
  416. }
  417. if($pay)
  418. {
  419. $where .= " and pay = '$pay'";
  420. }
  421. if($phone)
  422. {
  423. $where .= " and phone = '$phone'";
  424. }
  425. if($sfxh != '')
  426. {
  427. $where .= " and sfxh = '$sfxh'";
  428. }
  429. if($orderurl)
  430. {
  431. $url = $this->orderurl->read($orderurl);
  432. $where .= " and link like '%".$url['url']."%'";
  433. }
  434. if($zf)
  435. {
  436. if($zf == 1)
  437. {
  438. $where .= " and paypal not like '%-%-%-%'";
  439. }
  440. else
  441. {
  442. $where .= " and paypal like '%-%-%-%'";
  443. }
  444. }
  445. $sj = $this->input->get('sj',true);
  446. if($sj)
  447. {
  448. $sj = $this->input->get('sj',true);
  449. }
  450. else
  451. {
  452. $sj = $classid['type'];
  453. }
  454. $fexceleq = explode("|",rtrim($fexcel['content'],'|'));
  455. foreach ($fexceleq as $k=>$v)
  456. {
  457. $fexceleq[$k] = explode('-',$v);
  458. $num[$k] = $fexceleq[$k][0];
  459. }
  460. //array_multisort($num,SORT_ASC,$fexceleq);//重新排序
  461. $feq = "";$kong = array();$sku9610 = '';
  462. foreach ($fexceleq as $k=>$v)
  463. {
  464. if(isset($v[1]))
  465. {
  466. if($v[1] == 'klarnabill' || $v[1] == 'klarnaship' || $v[1] == 'PPname' || $v[1] == 'PPaddress' || $v[1] == 'PPemail' || $v[1] == 'afterpayship' || $v[1] == 'afterpaybill')
  467. {
  468. $feq .= 'klarnadata,';
  469. }
  470. if($v[1] == 'ccfpdata' || $v[1] == 'cpfpdata' || $v[1] == 'dbapi' || $v[1] == 'scapi')
  471. {
  472. $feq .= 'fpdata,';
  473. }
  474. if($v[1] != 'kong')//空值去除
  475. {
  476. if($v[1] == '9610sku' || $v[1] == 'issku' || $v[1] == 'sku')
  477. {
  478. if($v[1] == '9610sku')
  479. {
  480. $sku9610 = 1;
  481. }
  482. if($sj == 'fullordersmt')
  483. {
  484. $v[1] = 'sku';
  485. }
  486. else
  487. {
  488. $v[1] = 'issku';
  489. }
  490. }
  491. $feq .= $v[1].',';
  492. }
  493. else
  494. {
  495. $kong[$v[0]] = 1;
  496. }
  497. }
  498. }
  499. $feq = rtrim($feq,',');
  500. $fexcelzhw = explode('|',rtrim($fexcel['contentzh'],'|'));
  501. foreach ($fexcelzhw as $k=>$v)
  502. {
  503. $fexcelzhw[$k] = explode('-',$v);
  504. $numb[$k] = $fexcelzhw[$k][0];
  505. }
  506. //array_multisort($numb,SORT_ASC,$fexcelzhw);//重新排序
  507. $fexcelzh = array();
  508. foreach ($fexcelzhw as $k=>$v)
  509. {
  510. $fexcelzh[] = $v[1];
  511. }
  512. if($px)
  513. {
  514. $order_str = $px." desc";
  515. }
  516. else
  517. {
  518. $order_str = "id desc";
  519. }
  520. //取得信息列表
  521. $info_list = $this->$sj->find_all($where.$wid.' and '.$excelshop,'id,'.$feq,$order_str);
  522. //格式化数据
  523. $i = 1;$shouldmoney = 0;$hl=1;
  524. foreach ($info_list as $key=>$value)
  525. {
  526. $data = $this->$sj->read($value['id']);
  527. if(isset($value['email']) && $usp['excelpass'] == '1')
  528. {
  529. $emailpass = $this->setting->get_excelpass($value['email']);
  530. $info_list[$key]['email'] = $emailpass;
  531. }
  532. if(isset($value['phone']) && $usp['excelpass'] == '1')
  533. {
  534. $phonepass = $this->setting->get_excelpass($value['phone']);
  535. $info_list[$key]['phone'] = $phonepass;
  536. }
  537. if(isset($value['currencytitle']))
  538. {
  539. if($value['currencytitle'] != "CNY")
  540. {
  541. $hl=$value['hl'];
  542. }
  543. $shouldmoney=$shouldmoney+($value['shouldmoney']*$hl);
  544. $budget=$budget+($value['budget']*$hl);
  545. $currency=$currency+(($value['shouldmoney']-$value['budget'])*$hl);
  546. $refund=$refund+($value['refund']*$hl);
  547. }
  548. if(isset($value['shop']))
  549. {
  550. $shop = $this->shop->read($value['shop']);
  551. $info_list[$key]['shop'] = $shop['shopname'];
  552. }
  553. if(isset($value['dtime']))
  554. {
  555. $info_list[$key]['dtime'] = date('Y-m-d H:i:s',$value['dtime']);
  556. }
  557. if(isset($value['printtime']))
  558. {
  559. if($value['printtime'] > 0)
  560. {
  561. $info_list[$key]['printtime'] = date('Y-m-d H:i:s',$value['printtime']);
  562. }
  563. }
  564. if(isset($value['sku']))
  565. {
  566. if($sku9610 == '1')
  567. {
  568. $aesku = explode(';',$value['sku']);
  569. $aesku = $aesku[0];
  570. $aesku = explode(':',$aesku);
  571. if(count($aesku) > 1)
  572. {
  573. $aesku = $aesku[1];
  574. $aesku = str_replace('--','~',$aesku);
  575. $aesku = explode('-',$aesku);
  576. $aesku = $aesku[0];
  577. $aesku = str_replace('~','--',$aesku);
  578. $info_list[$key]['sku'] = $aesku;
  579. }
  580. else
  581. {
  582. $info_list[$key]['sku'] = '';
  583. }
  584. }
  585. else
  586. {
  587. $info_list[$key]['sku'] = $value['sku'];
  588. }
  589. }
  590. if(isset($value['issku']))
  591. {
  592. $value['issku'] = str_replace(array('&lt;','&gt;'),array('<','>'),$value['issku']);
  593. if($sku9610 == '1')
  594. {
  595. $aesku = explode(';',$value['issku']);
  596. $aesku = $aesku[0];
  597. $aesku = str_replace('--','~',$aesku);
  598. $aesku = explode('-',$aesku);
  599. $aesku = $aesku[0];
  600. $aesku = str_replace('~','--',$aesku);
  601. $aesku = str_replace(array('<','>'),array('&lt;','&gt;'),$aesku);
  602. $info_list[$key]['issku'] = $aesku;
  603. }
  604. else
  605. {
  606. $value['issku'] = str_replace(array('<','>'),array('&lt;','&gt;'),$value['issku']);
  607. $info_list[$key]['issku'] = $value['issku'];
  608. }
  609. }
  610. if(isset($value['librarytime']))
  611. {
  612. if($value['librarytime'] > 0)
  613. {
  614. $info_list[$key]['librarytime'] = date('Y-m-d H:i:s',$value['librarytime']);
  615. }
  616. }
  617. if(isset($value['buytime']))
  618. {
  619. if($value['buytime'] > 0)
  620. {
  621. $info_list[$key]['buytime'] = date('Y-m-d H:i:s',$value['buytime']);
  622. }
  623. }
  624. if(isset($value['country']))
  625. {
  626. $country = $this->country->read($value['country']);
  627. $info_list[$key]['country'] = $country['name'];
  628. }
  629. if(isset($value['street']))//暂时用街道导出州二字码
  630. {
  631. if($data['country'] == 192)//如果是美国
  632. {
  633. $ToState = array('alabama'=>'AL','alaska'=>'AK','arizona'=>'AZ','arkansas'=>'AR','california'=>'CA','colorado'=>'CO','connecticut'=>'CT','delaware'=>'DE','florida'=>'FL','georgia'=>'GA','hawaii'=>'HI','idaho'=>'ID','illinois'=>'IL','indiana'=>'IN','iowa'=>'IA','kansas'=>'KS','kentucky'=>'KY','louisiana'=>'LA','maine'=>'ME','maryland'=>'MD','massachusetts'=>'MA','michigan'=>'MI','minnesota'=>'MN','mississippi'=>'MS','missouri'=>'MO','montana'=>'MT','nebraska'=>'NE','nevada'=>'NV','new hampshire'=>'NH','new jersey'=>'NJ','new mexico'=>'NM','new york'=>'NY','north carolina'=>'NC','north dakota'=>'ND','ohio'=>'OH','oklahoma'=>'OK','oregon'=>'OR','pennsylvania'=>'PA','rhode island'=>'RI','south carolina'=>'SC','south dakota'=>'SD','tennessee'=>'TN','texas'=>'TX','utah'=>'UT','vermont'=>'VT','virginia'=>'VA','washington'=>'WA','west virginia'=>'WV','wisconsin'=>'WI','wyoming'=>'WY','district of columbia'=>'DC','virgin islands'=>'VI');
  634. $data['province'] = preg_replace('/( | |\s)/',' ',$data['province']);
  635. $data['province'] = trim($data['province'],' ');
  636. if(isset($ToState[strtolower($data['province'])]))
  637. {
  638. $dataprovince = strlen($data['province'])==2?$data['province']:$ToState[strtolower($data['province'])];
  639. }
  640. else
  641. {
  642. $dataprovince = '';
  643. }
  644. $info_list[$key]['street'] = $dataprovince;
  645. }
  646. else
  647. {
  648. $info_list[$key]['street'] = '';
  649. }
  650. }
  651. if(isset($value['pay']))
  652. {
  653. $pay = $this->typeclass->read($value['pay']);
  654. $info_list[$key]['pay'] = $pay['title'];
  655. }
  656. if(isset($value['type']))
  657. {
  658. $type = $this->warehouse->read($value['type']);
  659. $info_list[$key]['type'] = $type['title'];
  660. }
  661. if(isset($value['express']))
  662. {
  663. $express = $this->express->read($value['express']);
  664. if($express)
  665. {
  666. $info_list[$key]['express'] = $express['servicename'];
  667. }
  668. else
  669. {
  670. $info_list[$key]['express'] = '未选择';
  671. }
  672. }
  673. if(isset($value['ccfpdata']))
  674. {
  675. $ccfpdata = explode(';',$value['fpdata']);
  676. $inc = 0;
  677. foreach ($ccfpdata as $v)
  678. {
  679. if(stripos($v,',') !== false)
  680. {
  681. $cc = explode(',',$v);
  682. $inctype = $this->typeclass->read($cc[0]);
  683. if(is_numeric($inctype['spare']))
  684. {
  685. if($inctype['spare'] > $inc)
  686. {
  687. $inc = $inctype['spare'];
  688. }
  689. }
  690. }
  691. }
  692. $info_list[$key]['ccfpdata'] = $inc.'inch';
  693. }
  694. if(isset($value['printtype']))
  695. {
  696. if($value['printtype'] == 1)
  697. {
  698. $info_list[$key]['printtype'] = '运单';
  699. }
  700. else if($value['printtype'] == 2)
  701. {
  702. $info_list[$key]['printtype'] = '发货单';
  703. }
  704. else if($value['printtype'] == 3)
  705. {
  706. $info_list[$key]['printtype'] = '不打印单据';
  707. }
  708. else
  709. {
  710. $info_list[$key]['printtype'] = '未选择';
  711. }
  712. }
  713. if(isset($value['exstate']))
  714. {
  715. if($value['exstate'] == '99')
  716. {
  717. $info_list[$key]['exstate'] = '未获取到物流信息';
  718. }
  719. else if($value['exstate'] == '1')
  720. {
  721. $info_list[$key]['exstate'] = '已揽收';
  722. }
  723. else if($value['exstate'] == '2')
  724. {
  725. $info_list[$key]['exstate'] = '在途中';
  726. }
  727. else if($value['exstate'] == '3')
  728. {
  729. $info_list[$key]['exstate'] = '派送中';
  730. }
  731. else if($value['exstate'] == '4')
  732. {
  733. $info_list[$key]['exstate'] = '已签收';
  734. }
  735. else if($value['exstate'] == '5')
  736. {
  737. $info_list[$key]['exstate'] = '派送异常';
  738. }
  739. else
  740. {
  741. $info_list[$key]['exstate'] = '';
  742. }
  743. }
  744. if(isset($value['link']))
  745. {
  746. if($value['link'] != '')
  747. {
  748. $link = explode(',',$value['link']);
  749. $info_list[$key]['link'] = $link[0];
  750. }
  751. else
  752. {
  753. $info_list[$key]['link'] = '';
  754. }
  755. }
  756. if(isset($value['klarnabill']))
  757. {
  758. $klarnadata = explode('|',$value['klarnadata']);
  759. if(isset($klarnadata[2]))
  760. {
  761. $info_list[$key]['klarnabill'] = $klarnadata[2];
  762. }
  763. else
  764. {
  765. $info_list[$key]['klarnabill'] = '';
  766. }
  767. }
  768. if(isset($value['klarnaship']))
  769. {
  770. $klarnadata = explode('|',$value['klarnadata']);
  771. if(isset($klarnadata[3]))
  772. {
  773. $info_list[$key]['klarnaship'] = $klarnadata[3];
  774. }
  775. else
  776. {
  777. $info_list[$key]['klarnaship'] = '';
  778. }
  779. }
  780. if(isset($value['afterpaybill']))
  781. {
  782. $klarnadata = explode('|',$value['klarnadata']);
  783. if(isset($klarnadata[1]))
  784. {
  785. $info_list[$key]['afterpaybill'] = $klarnadata[1];
  786. }
  787. else
  788. {
  789. $info_list[$key]['afterpaybill'] = '';
  790. }
  791. }
  792. if(isset($value['afterpayship']))
  793. {
  794. $klarnadata = explode('|',$value['klarnadata']);
  795. if(isset($klarnadata[2]))
  796. {
  797. $info_list[$key]['afterpayship'] = $klarnadata[2];
  798. }
  799. else
  800. {
  801. $info_list[$key]['afterpayship'] = '';
  802. }
  803. }
  804. if(isset($value['PPname']))
  805. {
  806. $info_list[$key]['PPname'] = '';
  807. $klarnadata = explode('|',$value['klarnadata']);
  808. if(isset($klarnadata[1]))
  809. {
  810. $klarnadata = json_decode($klarnadata[1],true);
  811. if(isset($klarnadata['name']))
  812. {
  813. $info_list[$key]['PPname'] = $klarnadata['name'];
  814. }
  815. }
  816. }
  817. if(isset($value['PPemail']))
  818. {
  819. $info_list[$key]['PPemail'] = '';
  820. $klarnadata = explode('|',$value['klarnadata']);
  821. if(isset($klarnadata[1]))
  822. {
  823. $klarnadata = json_decode($klarnadata[1],true);
  824. if(isset($klarnadata['email']))
  825. {
  826. if($usp['excelpass'] == '1')
  827. {
  828. $ppemailpass = $this->setting->get_excelpass($klarnadata['email']);
  829. }
  830. else
  831. {
  832. $ppemailpass = $klarnadata['email'];
  833. }
  834. $info_list[$key]['PPemail'] = $ppemailpass;
  835. }
  836. }
  837. }
  838. if(isset($value['PPaddress']))
  839. {
  840. $info_list[$key]['PPaddress'] = '';
  841. $klarnadata = explode('|',$value['klarnadata']);
  842. if(isset($klarnadata[1]))
  843. {
  844. $klarnadata = json_decode($klarnadata[1],true);
  845. if(isset($klarnadata['address']))
  846. {
  847. $info_list[$key]['PPaddress'] = $klarnadata['address'];
  848. }
  849. }
  850. }
  851. if(isset($value['klarnadata']))
  852. {
  853. unset($info_list[$key]['klarnadata']);
  854. }
  855. if(isset($value['shippingmethod']))
  856. {
  857. $tax = explode('Tax:',$value['shippingmethod']);
  858. $info_list[$key]['shippingmethod'] = (isset($tax[1]))?trim($tax[1],';'):'';
  859. }
  860. if(isset($value['systemwigsout']))
  861. {
  862. $out = $this->systemtransfer->find_all("number = '".$data['number']."'");
  863. $outread = '';
  864. if($out)
  865. {
  866. foreach ($out as $val)
  867. {
  868. $list = '';
  869. $rk = explode('|',trim($val['rk'],'|'));
  870. $rktime = explode('|',trim($val['rktime'],'|'));
  871. $zw = array();
  872. $t = $this->transfer->find_all("1=1");
  873. foreach ($t as $v)
  874. {
  875. $zw[$v['id']] = $v['title'];
  876. }
  877. if($val['rk'] != '' && count($rk) > 0)
  878. {
  879. for($i=0;$i<count($rk);$i++)
  880. {
  881. if(!isset($rktime[$i]))
  882. {
  883. $list .= $zw[$cz[$i]];
  884. }
  885. else
  886. {
  887. $list .= $zw[$rk[$i]].' :'.date('Y-m-d H:i',$rktime[$i]).',';
  888. }
  889. }
  890. }
  891. $outread .= '<span style="color:#f00">'.$val['pm'].'</span>:'.$list.'<br>';
  892. }
  893. }
  894. else
  895. {
  896. $systemwigsout = $this->systemwigsout->find_all("number = '".$data['number']."'");
  897. if($systemwigsout)
  898. {
  899. foreach ($systemwigsout as $v)
  900. {
  901. $outread = '';
  902. if($v['czwarehouse'] == 37)
  903. {
  904. $outread .= '华荣厂';
  905. }
  906. else if($v['czwarehouse'] == 0)
  907. {
  908. $outread .= '龙盈厂';
  909. }
  910. $cz = explode('|',trim($v['cz'],'|'));
  911. $cztime = explode('|',trim($v['cztime'],'|'));
  912. $zw = $this->transfer->get_list();
  913. if($v['cz'] != '' && count($cz) > 0)
  914. {
  915. for($i=0;$i<count($cz);$i++)
  916. {
  917. if(!isset($cztime[$i]))
  918. {
  919. $outread .= $zw[$cz[$i]].' -&gt; ';
  920. }
  921. else
  922. {
  923. $outread .= $zw[$cz[$i]].' :'.date('Y-m-d H:i',$cztime[$i]).' -&gt; ';
  924. }
  925. }
  926. $outread .= '<br>';
  927. }
  928. }
  929. }
  930. }
  931. $info_list[$key]['systemwigsout'] = $outread;
  932. }
  933. if(isset($value['sourcetype']))
  934. {
  935. if($value['sourcetype'] == '1')
  936. {
  937. $info_list[$key]['sourcetype'] = '网红单';
  938. }
  939. else if($value['sourcetype'] == '2')
  940. {
  941. $info_list[$key]['sourcetype'] = '批发单';
  942. }
  943. else if($value['sourcetype'] == '3')
  944. {
  945. $info_list[$key]['sourcetype'] = '线下单';
  946. }
  947. else if($value['sourcetype'] == '4')
  948. {
  949. $info_list[$key]['sourcetype'] = '售后单';
  950. }
  951. else if($value['sourcetype'] == '5')
  952. {
  953. $info_list[$key]['sourcetype'] = '其它';
  954. }
  955. else
  956. {
  957. $info_list[$key]['sourcetype'] = '';
  958. }
  959. }
  960. if(isset($value['js']))
  961. {
  962. if($value['js'] == '0')
  963. {
  964. $info_list[$key]['js'] = 'FIRST CLASS';
  965. }
  966. else if($value['js'] == '1')
  967. {
  968. $info_list[$key]['js'] = 'PRIORITY';
  969. }
  970. else if($value['js'] == '2')
  971. {
  972. $info_list[$key]['js'] = 'EXPRESS';
  973. }
  974. }
  975. if(isset($value['type']))
  976. {
  977. $type = $this->warehouse->read($value['type']);
  978. $info_list[$key]['type'] = $type['title'];
  979. }
  980. if(isset($value['xdcs']))
  981. {
  982. if($sj == 'fullorder')
  983. {
  984. $xdcs = $this->customer->get_email($data['email'],$data['shop']);
  985. }
  986. else
  987. {
  988. $xdcs = $this->customersmt->get_shopdata($data['shop'],$data['name'],$data['address']);
  989. }
  990. $info_list[$key]['xdcs'] = (isset($xdcs['num']))?(($xdcs['num']==0)?1:$xdcs['num']):1;
  991. }
  992. if(isset($value['dbapi']) || isset($value['scapi']))
  993. {
  994. $jmlist = '';$shuliang = '';
  995. $classid = $this->classid->sku();
  996. $dbapi = explode(';',trim($value['fpdata'],';'));
  997. foreach ($dbapi as $va)
  998. {
  999. $pm = $classid;
  1000. $jm = $classid;
  1001. $bmpx = array(13=>'',16=>'',18=>'',25=>'',26=>'',41=>'');
  1002. $features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$va);
  1003. $ts = explode('|',trim($features,'|'));
  1004. if(stripos($ts[0],',') !== false)
  1005. {
  1006. $ft = explode(',',$ts[0]);
  1007. $features = explode('-',trim($ft[1],'-'));
  1008. $features[] = $ft[0];
  1009. }
  1010. else
  1011. {
  1012. $features = explode('-',trim($ts[0],'-'));
  1013. }
  1014. foreach($features as $k=>$v)
  1015. {
  1016. if(isset($typeclass[$v]) && isset($bmpx[$typeclass[$v]['classid']]))
  1017. {
  1018. if($typeclass[$v]['bm'] != '')
  1019. {
  1020. $bmpx[$typeclass[$v]['classid']] = $typeclass[$v]['bm'];
  1021. }
  1022. }
  1023. if($v != 0 && isset($typeclass[$v]))
  1024. {
  1025. if($typeclass[$v]['classid'] == 13)
  1026. {
  1027. $dj = $typeclass[$v]['title'];
  1028. }
  1029. if($typeclass[$v]['classid'] == 8)
  1030. {
  1031. $ys = $typeclass[$v]['title'];
  1032. }
  1033. if($typeclass[$v]['classid'] == 15)
  1034. {
  1035. $hx = $typeclass[$v]['title'];
  1036. }
  1037. if(isset($pm[$typeclass[$v]['classid']]))
  1038. {
  1039. if($typeclass[$v]['title'] == '9A')
  1040. {
  1041. $pm[$typeclass[$v]['classid']] = '9A';
  1042. }
  1043. else if($typeclass[$v]['title'] == '10A')
  1044. {
  1045. $pm[$typeclass[$v]['classid']] = '10A';
  1046. }
  1047. else
  1048. {
  1049. $clzh = $typeclass[$v]['zh'];
  1050. if(stripos($typeclass[$v]['zh'],'|') !== false)
  1051. {
  1052. $clzh = explode('|',rtrim($typeclass[$v]['zh'],'|'));
  1053. $clzh = $clzh[0];
  1054. }
  1055. $pm[$typeclass[$v]['classid']] = $clzh;
  1056. }
  1057. }
  1058. if(isset($jm[$typeclass[$v]['classid']]))
  1059. {
  1060. if($typeclass[$v]['jm'])
  1061. {
  1062. $jm[$typeclass[$v]['classid']] = $typeclass[$v]['jm'];
  1063. }
  1064. }
  1065. }
  1066. }
  1067. $jm = array_filter($jm);//去除空值
  1068. $jm = implode("-",$jm);
  1069. $jmlist .= $jm.'<br>';
  1070. $shuliang .= (isset($ts[2])?$ts[2]:'未知').'<br>';
  1071. $pm = array_filter($pm);//去除空值
  1072. $zh = implode(" ",$pm);
  1073. $zh = preg_replace("/\r\n|\r|\n/",'',trim($zh,' '));
  1074. }
  1075. if(isset($value['dbapi']))
  1076. {
  1077. $info_list[$key]['dbapi'] = $jmlist;
  1078. }
  1079. else
  1080. {
  1081. $info_list[$key]['scapi'] = $shuliang;
  1082. }
  1083. }
  1084. if(isset($value['dbapi']) && isset($value['scapi']))
  1085. {
  1086. $jmlist = '';$shuliang = '';
  1087. $classid = $this->classid->sku();
  1088. $dbapi = explode(';',trim($value['fpdata'],';'));
  1089. foreach ($dbapi as $va)
  1090. {
  1091. $pm = $classid;
  1092. $jm = $classid;
  1093. $bmpx = array(13=>'',16=>'',18=>'',25=>'',26=>'',41=>'');
  1094. $features = str_replace(array('-163-','-164-','-165-','-166-'),'-',$va);
  1095. $ts = explode('|',trim($features,'|'));
  1096. if(stripos($ts[0],',') !== false)
  1097. {
  1098. $ft = explode(',',$ts[0]);
  1099. $features = explode('-',trim($ft[1],'-'));
  1100. $features[] = $ft[0];
  1101. }
  1102. else
  1103. {
  1104. $features = explode('-',trim($ts[0],'-'));
  1105. }
  1106. foreach($features as $k=>$v)
  1107. {
  1108. if(isset($typeclass[$v]) && isset($bmpx[$typeclass[$v]['classid']]))
  1109. {
  1110. if($typeclass[$v]['bm'] != '')
  1111. {
  1112. $bmpx[$typeclass[$v]['classid']] = $typeclass[$v]['bm'];
  1113. }
  1114. }
  1115. if($v != 0 && isset($typeclass[$v]))
  1116. {
  1117. if($typeclass[$v]['classid'] == 13)
  1118. {
  1119. $dj = $typeclass[$v]['title'];
  1120. }
  1121. if($typeclass[$v]['classid'] == 8)
  1122. {
  1123. $ys = $typeclass[$v]['title'];
  1124. }
  1125. if($typeclass[$v]['classid'] == 15)
  1126. {
  1127. $hx = $typeclass[$v]['title'];
  1128. }
  1129. if(isset($pm[$typeclass[$v]['classid']]))
  1130. {
  1131. if($typeclass[$v]['title'] == '9A')
  1132. {
  1133. $pm[$typeclass[$v]['classid']] = '9A';
  1134. }
  1135. else if($typeclass[$v]['title'] == '10A')
  1136. {
  1137. $pm[$typeclass[$v]['classid']] = '10A';
  1138. }
  1139. else
  1140. {
  1141. $clzh = $typeclass[$v]['zh'];
  1142. if(stripos($typeclass[$v]['zh'],'|') !== false)
  1143. {
  1144. $clzh = explode('|',rtrim($typeclass[$v]['zh'],'|'));
  1145. $clzh = $clzh[0];
  1146. }
  1147. $pm[$typeclass[$v]['classid']] = $clzh;
  1148. }
  1149. }
  1150. if(isset($jm[$typeclass[$v]['classid']]))
  1151. {
  1152. if($typeclass[$v]['jm'])
  1153. {
  1154. $jm[$typeclass[$v]['classid']] = $typeclass[$v]['jm'];
  1155. }
  1156. }
  1157. }
  1158. }
  1159. $jm = array_filter($jm);//去除空值
  1160. $jm = implode("-",$jm);
  1161. $jmlist .= $jm.'<br>';
  1162. $shuliang .= (isset($ts[2])?$ts[2]:'未知').'<br>';
  1163. $pm = array_filter($pm);//去除空值
  1164. $zh = implode(" ",$pm);
  1165. $zh = preg_replace("/\r\n|\r|\n/",'',trim($zh,' '));
  1166. }
  1167. $info_list[$key]['dbapi'] = $jmlist;
  1168. $info_list[$key]['scapi'] = $shuliang;
  1169. }
  1170. if(isset($value['cpfpdata']))
  1171. {
  1172. $fpread = '';
  1173. $cpfpdata = explode(';',trim($value['fpdata'],';'));
  1174. foreach ($cpfpdata as $v)
  1175. {
  1176. $va = explode('|',trim($v,'|'));
  1177. $fpread .= $va[1].'; ';
  1178. }
  1179. $info_list[$key]['cpfpdata'] = $fpread;
  1180. }
  1181. unset($info_list[$key]['id']);
  1182. unset($info_list[$key]['fpdata']);
  1183. }
  1184. $fzh = "";
  1185. foreach ($fexcelzh as $v)
  1186. {
  1187. $fzh .= "<td>".$v."</td>";
  1188. }
  1189. $data = array($shouldmoney.' CNY');
  1190. $title = $fexcel['title'].'-'.date('Ymd',time());
  1191. $titlename = "<table border=1>
  1192. <tr>"
  1193. .$fzh.
  1194. "</tr>
  1195. </table>";
  1196. $tail = "\n";
  1197. $filename = $title.".xls";
  1198. $this->excel->get_fz5($info_list,$titlename,$filename,$tail,$kong);
  1199. }
  1200. }
  1201. //上传运单
  1202. public function _waybill($arg_array)
  1203. {
  1204. $readid = $arg_array[0];
  1205. $dataorder = array();$datashop = array();$dataex = array();$datack = array();
  1206. /* 订单加入键值-k */
  1207. $fdata = $this->fullorder->find_all('shop = "'.$readid.'" and dtime > "'.(time()-30*24*3600).'" and review > 4 and dlz < 1 and state = 207');
  1208. foreach ($fdata as $v)
  1209. {
  1210. $dataorder[$v['orderinfo']] = $v;
  1211. }
  1212. $sdata = $this->fullordersmt->find_all('shop = "'.$readid.'" and dtime > "'.(time()-30*24*3600).'" and review > 4 and state = 207 and (dlz < 1 or dlz = 3)');
  1213. foreach ($sdata as $v)
  1214. {
  1215. $dataorder[$v['orderinfo']] = $v;
  1216. }
  1217. /* 订单加入键值-j */
  1218. /* 店铺加入键值-j */
  1219. $fshop = $this->shop->find_all('1=1');
  1220. foreach ($fshop as $v)
  1221. {
  1222. $datashop[$v['id']] = $v;
  1223. }
  1224. /* 店铺加入键值-k */
  1225. /* 快递加入键值-j */
  1226. $fex = $this->express->find_all('1=1');
  1227. foreach ($fex as $v)
  1228. {
  1229. $dataex[$v['id']] = $v;
  1230. }
  1231. /* 快递加入键值-k */
  1232. /* 仓库加入键值-k */
  1233. $fwh = $this->warehouse->find_all('1=1');
  1234. foreach ($fwh as $v)
  1235. {
  1236. $datack[$v['id']] = $v;
  1237. }
  1238. /* 仓库加入键值-j */
  1239. $fs = $this->notice->get_ordertatus(216);//216成功状态
  1240. if(is_numeric($readid) == false || $readid < 1)
  1241. {
  1242. echo json_encode(array('msg'=>'店铺信息错误!','success'=>true));exit;
  1243. }
  1244. $dir = '/data/excel/'.date('Ymd',time()).'/';
  1245. $config['upload_path'] = '.'.$dir ;
  1246. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  1247. $config['allowed_types'] = 'xls|xlsx|csv';
  1248. $config['max_size'] = 10240;
  1249. $this->load->library('upload', $config);
  1250. $this->upload->initialize($config);
  1251. if ($this->upload->do_upload('userfile'))
  1252. {
  1253. $full_path = $dir.$this->upload->data('file_name');
  1254. $fileName = '.' . $full_path;
  1255. if (!file_exists($fileName))
  1256. {
  1257. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  1258. }
  1259. else
  1260. {
  1261. require_once "./data/excel/PHPExcel/IOFactory.php";
  1262. $phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  1263. $phpExcel->setActiveSheetIndex(0);// 设置为默认表
  1264. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  1265. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  1266. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  1267. ++$column;//如果列数大于26行
  1268. $list = array();
  1269. for ($i = 2; $i <= $row; $i++) // 行数循环
  1270. {
  1271. $data = array();
  1272. for ($c = 'A'; $c != $column; $c++) // 列数循环
  1273. {
  1274. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  1275. }
  1276. $list[] = $data;
  1277. }
  1278. }
  1279. $i = 0;$j = 0;$ed = array();
  1280. foreach ($list as $key=>$value)
  1281. {
  1282. if($value['0'] == "")
  1283. {
  1284. continue;
  1285. }
  1286. $ddh = preg_replace('/\D/s','',$value['0']);
  1287. $ydh = preg_replace('/\W/s','',$value['1']);
  1288. $shop = $datashop[$readid];
  1289. if($shop['type'] == '269')
  1290. {
  1291. $orid = $readid.$ddh;
  1292. }
  1293. else
  1294. {
  1295. $orid = $ddh;
  1296. }
  1297. if(isset($dataorder[$orid]))
  1298. {
  1299. $sp = $this->shop->read($arg_array[0]);
  1300. if($sp['type'] == 269)//独立站前缀需要添加ID
  1301. {
  1302. $xg = $dataorder[$arg_array[0].$ddh];
  1303. $ex = $dataex[$xg['express']];
  1304. $warehouse = $datack[$xg['type']];
  1305. if($xg['source'] != 1 && $ex['iscode'] != 'Other' && $xg['state'] == '207')
  1306. {
  1307. //独立站地址更新订单状态、物流信息
  1308. $gx = $this->api->get_gx($ddh,$ydh,$xg,$shop,$ex,$xg['msg'],$xg['msg'],$dataorder[$orid]['shopify']);
  1309. if(!isset($gx['res']))
  1310. {
  1311. $ed[] = array($ddh.'-更新失败');
  1312. $j++;
  1313. continue;
  1314. }
  1315. $this->fullorder->save(array('waybill'=>$ydh,'dlz'=>$gx['res'],'state'=>$gx['state']),$xg['id']);
  1316. if($gx['res'] == 1 && $fs)
  1317. {
  1318. $ck = $this->_email($fs['content'],$xg,$warehouse['company']);
  1319. }
  1320. }
  1321. else if($xg['source'] == 1 && $xg['state'] == '207')
  1322. {
  1323. $this->fullorder->save(array('waybill'=>$ydh,'dlz'=>3,'state'=>216),$xg['id']);
  1324. if($fs)
  1325. {
  1326. $ck = $this->_email($fs['content'],$xg,$warehouse['company']);
  1327. }
  1328. }
  1329. else
  1330. {
  1331. $ed[] = array($ddh.'-状态错误');
  1332. $j++;
  1333. continue;
  1334. }
  1335. }
  1336. else if($sp['type'] == 270)//速卖通对接发货声明
  1337. {
  1338. $xg = $dataorder[$ddh];
  1339. $ex = $dataex[$xg['express']];
  1340. $warehouse = $datack[$xg['type']];
  1341. if($xg['source'] != 1 && $ex['aecode'] != 'Other' && $xg['library'] == 2 && ($xg['dlz'] == '0' || $xg['dlz'] == '2'))
  1342. {
  1343. $result = $this->apismt->get_out($ydh,'all',$xg['orderinfo'],$ex['aecode'],$sp['code']);
  1344. if(isset($result['result_success']) && $result['result_success'] == "true")
  1345. {
  1346. $this->fullordersmt->save(array('waybill'=>$ydh,'state'=>209,'dlz'=>1),$xg['id']);
  1347. /** 合并信息处理开始-发货声明 **/
  1348. if($xg['merge'] != '0')
  1349. {
  1350. $hdata = $this->fullordersmt->find_all("merge = '".$xg['merge']."' and id != '".$xg['id']."' and dlz = '0' and source != 1");$l=0;
  1351. foreach ($hdata as $v)
  1352. {
  1353. $result = $this->apismt->get_out($ydh,'all',$v['orderinfo'],$ex['aecode'],$sp['code']);
  1354. if(isset($result['result_success']) && $result['result_success'] == "true")
  1355. {
  1356. $this->fullordersmt->save(array('waybill'=>$ydh,'state'=>209,'dlz'=>1),$v['id']);
  1357. }
  1358. else
  1359. {
  1360. $ed[] = array($v['orderinfo'].'-合并单发货声明失败,请在ERP上手动操作此单');
  1361. $j++;
  1362. continue;
  1363. }
  1364. $l++;
  1365. if($l > 10)
  1366. {
  1367. break;
  1368. }
  1369. }
  1370. }
  1371. /** 合并信息处理结束开始 **/
  1372. }
  1373. else
  1374. {
  1375. $ed[] = array($ddh.'-发货声明失败');
  1376. $j++;
  1377. continue;
  1378. }
  1379. }
  1380. else if($xg['source'] != 1 && $ex['aecode'] != 'Other' && $xg['dlz'] == '1' && $xg['library'] == 2)//修改声明
  1381. {
  1382. $obtain = $this->apismt->get_obtain($xg['orderinfo'],$sp['code']);//修改声明先查询之前物流信息
  1383. if(isset($obtain['logistics_no']))
  1384. {
  1385. $result = $this->apismt->get_editout($obtain['logistics_no'],$ydh,'all',$xg['orderinfo'],$obtain['service_name'],$ex['aecode'],$sp['code']);
  1386. }
  1387. if(isset($result['result_success']) && $result['result_success'] == "true")
  1388. {
  1389. $this->fullordersmt->save(array('waybill'=>$ydh),$xg['id']);
  1390. /** 合并信息处理开始-修改声明 **/
  1391. if($xg['merge'] != '0')
  1392. {
  1393. $hdata = $this->fullordersmt->find_all("merge = '".$xg['merge']."' and id != '".$xg['id']."' and dlz != 1 and source != 1");$l=0;
  1394. foreach ($hdata as $v)
  1395. {
  1396. $obtain = $this->apismt->get_obtain($v['orderinfo'],$sp['code']);//修改声明先查询之前物流信息
  1397. if(isset($obtain['logistics_no']))
  1398. {
  1399. $result = $this->apismt->get_editout($obtain['logistics_no'],$ydh,'all',$v['orderinfo'],$obtain['service_name'],$ex['aecode'],$sp['code']);
  1400. }
  1401. if(isset($result['result_success']) && $result['result_success'] == "true")
  1402. {
  1403. $this->fullordersmt->save(array('waybill'=>$ydh),$v['id']);
  1404. }
  1405. else
  1406. {
  1407. $ed[] = array($v['orderinfo'].'-合并单修改发货声明失败,请在ERP上手动操作此单');
  1408. $j++;
  1409. continue;
  1410. }
  1411. $l++;
  1412. if($l > 10)
  1413. {
  1414. break;
  1415. }
  1416. }
  1417. }
  1418. /** 合并信息处理结束开始 **/
  1419. }
  1420. else
  1421. {
  1422. $ed[] = array($ddh.'-修改发货声明失败');
  1423. $j++;
  1424. continue;
  1425. }
  1426. }
  1427. else if($xg['source'] == 1 && $xg['state'] == '207')
  1428. {
  1429. $this->fullordersmt->save(array('waybill'=>$ydh,'dlz'=>3,'state'=>216),$xg['id']);
  1430. }
  1431. else
  1432. {
  1433. $this->fullordersmt->save(array('waybill'=>$ydh),$xg['id']);
  1434. }
  1435. }
  1436. }
  1437. else
  1438. {
  1439. $ed[] = array($ddh.'-单号错误或重复操作');
  1440. $i++;
  1441. continue;
  1442. }
  1443. sleep(1);//停留1秒
  1444. }
  1445. if($i+$j > 0)
  1446. {
  1447. $time = date('Ymd',time());
  1448. $title = '错误信息-'.$time;
  1449. $titlename = "<table border=1><tr><td>错误详情</td></tr></table>";
  1450. $tail = "\n";
  1451. $filename = $title.".xls";
  1452. $ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
  1453. $dir = '/data/excel/'.$time.'/';
  1454. $file_name = 'error_'.$time.rand(1000,9999);
  1455. if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
  1456. $myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
  1457. fwrite($myfile,$ecl);
  1458. fclose($myfile);
  1459. $error = $dir.$file_name.'.xls';
  1460. echo json_encode(array('msg'=>'添加成功,'.$i.'条异常,'.$j.'条失败','error'=>$error,'success'=>true));exit;
  1461. }
  1462. else
  1463. {
  1464. echo json_encode(array('msg'=>'添加成功!','error'=>1,'success'=>true));exit;
  1465. }
  1466. }
  1467. else
  1468. {
  1469. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  1470. }
  1471. }
  1472. //上传速卖通订单
  1473. public function _order($arg_array)
  1474. {
  1475. $dataorder = array();$datashop = array();$dataex = array();$datack = array();
  1476. /* 订单加入键值-k */
  1477. $fdata = $this->fullorder_smt->find_all('dtime >'.(time()-5*24*3600));
  1478. foreach ($fdata as $v)
  1479. {
  1480. $dataorder[$v['orderinfo']] = $v;
  1481. }
  1482. /* 订单加入键值-j */
  1483. $dir = '/data/excel/'.date('Ymd',time()).'/';
  1484. $config['upload_path'] = '.'.$dir ;
  1485. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  1486. $config['allowed_types'] = 'xls|xlsx|csv';
  1487. $config['max_size'] = 10240;
  1488. $this->load->library('upload', $config);
  1489. $this->upload->initialize($config);
  1490. if ($this->upload->do_upload('userfile'))
  1491. {
  1492. $full_path = $dir.$this->upload->data('file_name');
  1493. $fileName = '.' . $full_path;
  1494. if (!file_exists($fileName))
  1495. {
  1496. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  1497. }
  1498. else
  1499. {
  1500. require_once "./data/excel/PHPExcel/IOFactory.php";
  1501. $phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  1502. $phpExcel->setActiveSheetIndex(0);// 设置为默认表
  1503. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  1504. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  1505. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  1506. ++$column;//如果列数大于26行
  1507. $list = array();
  1508. for ($i = 2; $i <= $row; $i++) // 行数循环
  1509. {
  1510. $data = array();
  1511. for ($c = 'A'; $c != $column; $c++) // 列数循环
  1512. {
  1513. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  1514. }
  1515. $list[] = $data;
  1516. }
  1517. }
  1518. $i = 0;$j = 0;$ed = array();$tytime = time();
  1519. foreach ($list as $key=>$value)
  1520. {
  1521. $value['2'] = preg_replace('/\D/s','',$value['2']);
  1522. if($value['2'] && !isset($dataorder[$value['2']]))
  1523. {
  1524. $num = $this->fullorder_smt->find_count('gtime = "'.date('Ymd',time()).'"');
  1525. $post['source'] = 2;//订单类型:1.线下订单2.PC3.手机
  1526. $post['state'] = 207;//订单状态:207等待发货
  1527. $post['review'] = 6;//审核状态:1.未送审2.待审核3.不通过4取消重审5.审核通过6.自动通过
  1528. $post['reviewtime'] = $tytime;//审核时间
  1529. $post['print'] = 2;//打印状态:1.不可打印2.未打印3.已打印
  1530. $post['library'] = 1;//出库状态:1.未出库2.已出库3.已退库
  1531. $post['libraryconfirm'] = 1;//出库确认:1.不允许2.允许
  1532. if($post['print'] != 3)
  1533. {
  1534. $post['librarynot'] = "订单未打印,未审核或未通过";//不能出库原因
  1535. }
  1536. $value['1'] = trim($value['1'],' ');
  1537. $shortname = explode('-',$value['1']);
  1538. $shortname = $this->shop->get_shortname($shortname[0]);
  1539. if(!$shortname)
  1540. {
  1541. $ed[] = array($value['1'].'-编码有问题');
  1542. $i++;
  1543. continue;
  1544. }
  1545. $post['shop'] = $shortname['id']?$shortname['id']:0;//速卖通
  1546. $post['user'] = '无';
  1547. $post['number'] = $value['1'];//编号
  1548. $post['orderinfo'] = $value['2'];//订单号
  1549. $post['client'] = preg_replace('/( | | |\s)/',' ',$value['3']);//客户名称
  1550. $post['buytime'] = $tytime;//时间转UX
  1551. $post['dtime'] = $tytime;//订单时间
  1552. $post['gtime'] = date('Ymd',$tytime);//格式化时间
  1553. //$post['pay'] = $this->input->post('pay',true);//支付方式
  1554. $post['capital'] = 3;//资金状态
  1555. $post['type'] = 5;//发货仓库
  1556. $post['currency'] = 219;//币种
  1557. $post['currencytitle'] = 'USD';//币种名称
  1558. $post['freight'] = 0;//运费
  1559. $post['expressmoney'] = 0;//物流金额
  1560. $post['shouldmoney'] = 0;//应收金额
  1561. $post['budget'] = 0;//应到金额*店铺到帐金额比
  1562. $orderremarks = '';//订单备注
  1563. $post['shipremarks'] = $value['12'];//仓库品名
  1564. $post['email'] = '';//邮箱
  1565. $post['name'] = preg_replace('/( | | |\s)/',' ',$value['3']);//名字
  1566. $post['phone'] = $value['10'];//电话
  1567. $post['country'] = 192;//国家
  1568. $ct = $this->country->get_ename($value['9']);//国家
  1569. $post['al'] = $ct['lb'];//国家二字码
  1570. $post['province'] = $value['8'];//省、州
  1571. $post['city'] = $value['6'];//城市
  1572. $post['zipcode'] = $value['7'];//邮编
  1573. $post['address'] = $value['4'];//地址1
  1574. $post['address2'] = $value['5']?$value['5']:'';//地址2
  1575. $post['express'] = 2;//快递
  1576. $post['printtype'] = 1;//打印类型
  1577. $post['fpdata'] = '';//购买产品内容
  1578. $post['sbpm'] = 'Hair Sample';//申报品名
  1579. $post['zwpm'] = '假发';//中文品名
  1580. $post['ts'] = $value['17'];//条数
  1581. $post['dtsbjz'] = 15;//单条申报价
  1582. $post['zsbjz'] = 15;//总申报价
  1583. $post['zzl'] = 0.5;//总重量
  1584. $post['zjs'] = 1;//总件数
  1585. $post['quantity'] = 1;//数量
  1586. $post['paypal'] = '';//支付号
  1587. $post['guarantee'] = '';//卖家保障
  1588. $post['zzl'] = $value['13'];//总重量
  1589. $post['bx'] = $value['14'];//总重量
  1590. $post['qm'] = $value['15'];//总重量
  1591. $post['js'] = $value['16'];//总重量
  1592. $barcode = $this->usps->get_address(array('address'=>$value['4'],'address2'=>$value['5'],'city'=>$value['6'],'province'=>$value['8'],'zipcode'=>$value['7']));
  1593. if(isset($barcode['Address']['Error']['Description']))
  1594. {
  1595. $ed[] = array($value['1'].'-'.$barcode['Address']['Error']['Description']);
  1596. $i++;
  1597. }
  1598. else
  1599. {
  1600. $this->fullorder_smt->insert($post);
  1601. }
  1602. }
  1603. else
  1604. {
  1605. $ed[] = array($value['1'].'-单号错误或重复操作');
  1606. $i++;
  1607. }
  1608. sleep(2);//停留2秒
  1609. }
  1610. if($i+$j > 0)
  1611. {
  1612. $time = date('Ymd',time());
  1613. $title = '错误信息-'.$time;
  1614. $titlename = "<table border=1><tr><td>错误详情</td></tr></table>";
  1615. $tail = "\n";
  1616. $filename = $title.".xls";
  1617. $ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
  1618. $dir = '/data/excel/'.$time.'/';
  1619. $file_name = 'error_'.$time.rand(1000,9999);
  1620. if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
  1621. $myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
  1622. fwrite($myfile,$ecl);
  1623. fclose($myfile);
  1624. $error = $dir.$file_name.'.xls';
  1625. echo json_encode(array('msg'=>'添加成功,'.$i.'条异常,'.$j.'条失败','error'=>$error,'success'=>true));exit;
  1626. }
  1627. else
  1628. {
  1629. echo json_encode(array('msg'=>'添加成功!','error'=>1,'success'=>true));exit;
  1630. }
  1631. }
  1632. else
  1633. {
  1634. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  1635. }
  1636. }
  1637. public function _email($content,$data,$shopname)
  1638. {
  1639. $express = $this->express->read($data['express']);
  1640. $t= array('$userName','$orderid','$trackingNumber','$expressCompany','$contactPerson','$mobileNo','$zip','$recipientAddress');//需要被替换的内容
  1641. $h= array($data['client'],$data['orderinfo'],$data['waybill'],$express['servicename'],$data['name'],$data['phone'],$data['zipcode'],$data['address']);//替换的内容
  1642. $content = str_replace($t,$h,$content);
  1643. $this->load->library('email');
  1644. $config['protocol'] = 'smtp';
  1645. $config['smtp_host'] = 'smtpdm-ap-southeast-1.aliyun.com';
  1646. $config['smtp_port'] = 465;
  1647. $config['smtp_user'] = 'service@email.supernovahair.com';
  1648. $config['smtp_pass'] = 'LONGyihair374';
  1649. $config['smtp_crypto'] = 'ssl';
  1650. $config['crlf'] = "\r\n";
  1651. $config['newline'] = "\r\n";
  1652. $this->email->initialize($config);
  1653. $this->email->from('service@email.supernovahair.com',$shopname);
  1654. $this->email->to($data['email']);//收件
  1655. $this->email->subject('The product you purchased has a new progress');//标题
  1656. $this->email->message($content);//内容
  1657. if ( ! $this->email->send())
  1658. {
  1659. return 2;
  1660. }
  1661. else
  1662. {
  1663. return 1;
  1664. }
  1665. }
  1666. //导出订单excel
  1667. public function _cs()
  1668. {
  1669. if(isset($_GET['fexcel']))
  1670. {
  1671. if(isset($_SESSION['api']))
  1672. {
  1673. $user = $this->user->get_api($_SESSION['api']);
  1674. $usp = $user;
  1675. $fgshop = "";$sid = "";
  1676. $user = explode('|',trim($user['shop'],'|'));
  1677. foreach ($user as $value)
  1678. {
  1679. $fgshop .= " shop = ".$value." or";
  1680. $sid .= " id = ".$value." or";
  1681. }
  1682. }
  1683. $dowid = $this->input->get('a');
  1684. $wid = "";
  1685. if($dowid != "")
  1686. {
  1687. $id_arr = explode(',',rtrim($dowid,','));
  1688. foreach ($id_arr as $v)
  1689. {
  1690. $wid .= " id = 0 or";
  1691. $wid .= " id = '$v' or";
  1692. }
  1693. $wid = " and".rtrim($wid,'or');
  1694. }
  1695. $fexcel = $this->input->get('fexcel',true);
  1696. $page = $this->input->get('page',true);
  1697. $perpage = $this->input->get('perpage',true);
  1698. $warehouse = $this->input->get('warehouse',true);
  1699. $timetk = $this->input->get('timetk',true);
  1700. $timetj = $this->input->get('timetj',true);
  1701. $shop = $this->input->get('shop',true);
  1702. $source = $this->input->get('source',true);
  1703. $state = $this->input->get('state',true);
  1704. $review = $this->input->get('review',true);
  1705. $type = $this->input->get('type',true);
  1706. $express = $this->input->get('express',true);
  1707. $orderinfo = $this->input->get('orderinfo',true);
  1708. $user = $this->input->get('user',true);
  1709. $client = $this->input->get('name',true);
  1710. $waybill = $this->input->get('waybill',true);
  1711. $number = $this->input->get('number',true);
  1712. $email = $this->input->get('email',true);
  1713. $dlz = $this->input->get('dlz',true);
  1714. $library = $this->input->get('library',true);
  1715. $libraryconfirm = $this->input->get('libraryconfirm',true);
  1716. $print = $this->input->get('print',true);
  1717. $timetkk = $this->input->get('timetkk',true);
  1718. $timetjj = $this->input->get('timetjj',true);
  1719. $timetk = strtotime($timetk);
  1720. $timetj = strtotime($timetj);
  1721. $timetkk = strtotime($timetkk);
  1722. $timetjj = strtotime($timetjj);
  1723. $where = "mergeid = 0 and (".rtrim($fgshop,'or').")";
  1724. if($warehouse)
  1725. {
  1726. $where .= " and type = '$warehouse'";
  1727. }
  1728. if($timetk && $timetj)
  1729. {
  1730. $timetj = $timetj+24*3600;
  1731. $where .= " and dtime > '$timetk' and dtime < '$timetj'";
  1732. }
  1733. if($timetkk && $timetjj)
  1734. {
  1735. $where .= " and librarytime > '$timetkk' and librarytime < '$timetjj'";
  1736. }
  1737. if($library)
  1738. {
  1739. $where .= " and library = '$library'";
  1740. }
  1741. if($print)
  1742. {
  1743. $where .= " and print = '$print'";
  1744. }
  1745. if($shop)
  1746. {
  1747. $where .= " and shop = '$shop'";
  1748. }
  1749. if($source)
  1750. {
  1751. $where .= " and source = '$source'";
  1752. }
  1753. if($state)
  1754. {
  1755. $where .= " and state = '$state'";
  1756. }
  1757. if($review)
  1758. {
  1759. $where .= " and review = '$review'";
  1760. }
  1761. if($type)
  1762. {
  1763. $where .= " and type = '$type'";
  1764. }
  1765. if($express)
  1766. {
  1767. $where .= " and express = '$express'";
  1768. }
  1769. if($orderinfo)
  1770. {
  1771. $where .= " and orderinfo = '$orderinfo'";
  1772. }
  1773. if($user)
  1774. {
  1775. $where .= " and user = '$user'";
  1776. }
  1777. if($client)
  1778. {
  1779. $where .= " and client like '%$client%'";
  1780. }
  1781. if($waybill)
  1782. {
  1783. $where .= " and waybill = '$waybill'";
  1784. }
  1785. if($number)
  1786. {
  1787. $where .= " and number = '$number'";
  1788. }
  1789. if($email)
  1790. {
  1791. $where .= " and email = '$email'";
  1792. }
  1793. if($dlz)
  1794. {
  1795. $where .= " and waybill != '' and dlz = 0";
  1796. }
  1797. if($dlz)
  1798. {
  1799. $where .= " and libraryconfirm = '$libraryconfirm'";
  1800. }
  1801. $fexcel = $this->fullorderexcel->read($fexcel);
  1802. $fexceleq = explode("|",rtrim($fexcel['content'],'|'));
  1803. foreach ($fexceleq as $k=>$v)
  1804. {
  1805. $fexceleq[$k] = explode('-',$v);
  1806. $num[$k] = $fexceleq[$k][0];
  1807. }
  1808. //array_multisort($num,SORT_ASC,$fexceleq);//重新排序
  1809. $feq = "";
  1810. foreach ($fexceleq as $k=>$v)
  1811. {
  1812. $feq .= $v[1].',';
  1813. }
  1814. $feq = rtrim($feq,',');
  1815. $fexcelzhw = explode('|',rtrim($fexcel['contentzh'],'|'));
  1816. foreach ($fexcelzhw as $k=>$v)
  1817. {
  1818. $fexcelzhw[$k] = explode('-',$v);
  1819. $numb[$k] = $fexcelzhw[$k][0];
  1820. }
  1821. //array_multisort($numb,SORT_ASC,$fexcelzhw);//重新排序
  1822. $fexcelzh = array();
  1823. foreach ($fexcelzhw as $k=>$v)
  1824. {
  1825. $fexcelzh[] = $v[1];
  1826. }
  1827. //取得信息列表
  1828. $info_list = $this->fullorder->find_all($where.$wid,$feq,'id desc');
  1829. //格式化数据
  1830. $i = 1;$shouldmoney = 0;$hl=1;
  1831. foreach ($info_list as $key=>$value)
  1832. {
  1833. if(isset($value['currencytitle']))
  1834. {
  1835. if($value['currencytitle'] != "CNY")
  1836. {
  1837. $hl=$value['hl'];
  1838. }
  1839. $shouldmoney=$shouldmoney+($value['shouldmoney']*$hl);
  1840. $budget=$budget+($value['budget']*$hl);
  1841. $currency=$currency+(($value['shouldmoney']-$value['budget'])*$hl);
  1842. $refund=$refund+($value['refund']*$hl);
  1843. }
  1844. if(isset($value['shop']))
  1845. {
  1846. $shop = $this->shop->read($value['shop']);
  1847. $info_list[$key]['shop'] = $shop['shopname'];
  1848. }
  1849. if(isset($value['dtime']))
  1850. {
  1851. $info_list[$key]['dtime'] = date('Y-m-d H:i:s',$value['dtime']);
  1852. }
  1853. if(isset($value['country']))
  1854. {
  1855. $country = $this->country->read($value['country']);
  1856. $info_list[$key]['country'] = $country['name'];
  1857. }
  1858. if(isset($value['type']))
  1859. {
  1860. $type = $this->warehouse->read($value['type']);
  1861. $info_list[$key]['type'] = $type['title'];
  1862. }
  1863. if(isset($value['express']))
  1864. {
  1865. $express = $this->express->read($value['express']);
  1866. if($express)
  1867. {
  1868. $info_list[$key]['express'] = $express['servicename'];
  1869. }
  1870. else
  1871. {
  1872. $info_list[$key]['express'] = '未选择';
  1873. }
  1874. }
  1875. }
  1876. echo $timetkk;
  1877. }
  1878. }
  1879. public function _xxpl()
  1880. {
  1881. /* 订单加入键值-j */
  1882. $dir = '/data/excel/'.date('Ymd',time()).'/';
  1883. $config['upload_path'] = '.'.$dir ;
  1884. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  1885. $config['allowed_types'] = 'xls|xlsx|csv';
  1886. $config['max_size'] = 10240;
  1887. $this->load->library('upload', $config);
  1888. $this->upload->initialize($config);
  1889. if ($this->upload->do_upload('userfile'))
  1890. {
  1891. $full_path = $dir.$this->upload->data('file_name');
  1892. $fileName = '.' . $full_path;
  1893. if (!file_exists($fileName))
  1894. {
  1895. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  1896. }
  1897. else
  1898. {
  1899. require_once "./data/excel/PHPExcel/IOFactory.php";
  1900. @$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  1901. @$phpExcel->setActiveSheetIndex(0);// 设置为默认表
  1902. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  1903. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  1904. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  1905. ++$column;//如果列数大于26行
  1906. $list = array();
  1907. for ($i = 2; $i <= $row; $i++) // 行数循环
  1908. {
  1909. $data = array();
  1910. for ($c = 'A'; $c != $column; $c++) // 列数循环
  1911. {
  1912. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  1913. }
  1914. $list[] = $data;
  1915. }
  1916. }
  1917. $j = 0;$ed = array();
  1918. $wt = array();
  1919. $whlabel_type = $this->whlabel_type->find_all();
  1920. foreach ($whlabel_type as $v)
  1921. {
  1922. $wt[$v['title']] = $v['id'];
  1923. }
  1924. foreach ($list as $v)
  1925. {
  1926. $w = $this->whlabel->find_all("sku = '".$v[0]."' and warehouse = 5");
  1927. if($w && isset($wt[$v[1]]))
  1928. {
  1929. foreach ($w as $val)
  1930. {
  1931. $this->whlabel->save(array('type'=>$wt[$v[1]]),$val['id']);
  1932. }
  1933. }
  1934. else
  1935. {
  1936. $ed[] = array($v[0],$v[1]);
  1937. $j++;
  1938. }
  1939. }
  1940. if($j > 0)
  1941. {
  1942. $time = date('Ymd',time());
  1943. $title = '错误信息-'.$time;
  1944. $titlename = "<table border=1><tr><td>错误详情</td></tr></table>";
  1945. $tail = "\n";
  1946. $filename = $title.".xls";
  1947. @$ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
  1948. $dir = '/data/excel/'.$time.'/';
  1949. $file_name = 'error_'.$time.rand(1000,9999);
  1950. if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
  1951. $myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
  1952. fwrite($myfile,$ecl);
  1953. fclose($myfile);
  1954. $error = $dir.$file_name.'.xls';
  1955. echo json_encode(array('msg'=>$j.'条异常,','error'=>$error,'success'=>true));exit;
  1956. }
  1957. else
  1958. {
  1959. echo json_encode(array('msg'=>'添加成功!'.$i,'error'=>$cs,'success'=>true));exit;
  1960. }
  1961. }
  1962. else
  1963. {
  1964. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  1965. }
  1966. }
  1967. public function _xxpl_b()
  1968. {
  1969. $dataorder = array();$datashop = array();$dataex = array();$datack = array();
  1970. /* 订单加入键值-k */
  1971. $fdata = $this->fullordersmt->find_all('dtime >'.(time()-10*24*3600));
  1972. foreach ($fdata as $v)
  1973. {
  1974. $dataorder[$v['orderinfo']] = $v;
  1975. }
  1976. /* 订单加入键值-j */
  1977. $dir = '/data/excel/'.date('Ymd',time()).'/';
  1978. $config['upload_path'] = '.'.$dir ;
  1979. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  1980. $config['allowed_types'] = 'xls|xlsx|csv';
  1981. $config['max_size'] = 10240;
  1982. $this->load->library('upload', $config);
  1983. $this->upload->initialize($config);
  1984. if ($this->upload->do_upload('userfile'))
  1985. {
  1986. $full_path = $dir.$this->upload->data('file_name');
  1987. $fileName = '.' . $full_path;
  1988. if (!file_exists($fileName))
  1989. {
  1990. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  1991. }
  1992. else
  1993. {
  1994. require_once "./data/excel/PHPExcel/IOFactory.php";
  1995. @$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  1996. @$phpExcel->setActiveSheetIndex(0);// 设置为默认表
  1997. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  1998. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  1999. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  2000. ++$column;//如果列数大于26行
  2001. $list = array();
  2002. for ($i = 2; $i <= $row; $i++) // 行数循环
  2003. {
  2004. $data = array();
  2005. for ($c = 'A'; $c != $column; $c++) // 列数循环
  2006. {
  2007. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  2008. }
  2009. $list[] = $data;
  2010. }
  2011. }
  2012. $i = 0;$j = 0;$ed = array();$time = time();
  2013. foreach ($list as $key=>$value)
  2014. {
  2015. $shop = $this->shop->get_shopname($value['2']);//通过店铺名称查找店铺
  2016. if(!$shop)
  2017. {
  2018. $ed[] = array($value['0'].'-无此店铺');
  2019. $i++;continue;
  2020. }
  2021. $post['buytime'] = strtotime($value['6']);//付款时间
  2022. $value['0'] = preg_replace('/\D/s','',$value['0']);
  2023. if($value['0'] && !isset($dataorder[$value['0']]))
  2024. {
  2025. $post['source'] = 2;//订单类型:1.线下订单2.PC3.手机
  2026. $post['state'] = 207;//订单状态:207等待发货
  2027. $post['review'] = 6;//审核状态:1.未送审2.待审核3.不通过4取消重审5.审核通过6.自动通过
  2028. $post['reviewtime'] = $time;//审核时间
  2029. $post['print'] = 2;//打印状态:1.不可打印2.未打印3.已打印
  2030. $post['library'] = 1;//出库状态:1.未出库2.已出库3.已退库
  2031. $post['libraryconfirm'] = 1;//出库确认:1.不允许2.允许
  2032. $post['dtime'] = $time;//订单时间
  2033. $post['capital'] = 3;//资金状态
  2034. $post['currency'] = 219;//币种
  2035. $post['currencytitle'] = 'USD';//币种名称
  2036. $post['freight'] = 0;//运费
  2037. $post['expressmoney'] = 0;//物流金额
  2038. $post['shouldmoney'] = 0;//应收金额
  2039. if($post['print'] != 3)
  2040. {
  2041. $post['librarynot'] = "订单未打印";//不能出库原因
  2042. }
  2043. $post['gtime'] = date('Ymd',$post['buytime']);//格式化时间
  2044. $num = $this->fullordersmt->find_count('gtime = "'.date('Ymd',$post['buytime']).'" and shop = "'.$shop['id'].'"','id');
  2045. $post['number'] = $shop['shortname'].'-'.substr(date('ymd',$post['buytime']),1).'-'.(substr(strval($num+1+1000),1,3));//编号
  2046. $post['user'] = $shop['shopuser'];//店铺负责人
  2047. $post['orderinfo'] = $value['0'];//订单号
  2048. $post['type'] = $value['7'];//发货仓库
  2049. $post['shop'] = $shop['id'];//店铺
  2050. $post['shouldmoney'] = $value['3'];//订单金额
  2051. $post['product'] = $value['4']?$value['4']:'';//商品名称
  2052. $post['pay'] = $value['5'];//付款方式
  2053. $post['paypal'] = $value['1']?$value['1']:'';//交易号
  2054. $post['orderremarks'] = $value['8']?$value['8']:'';//订单备注
  2055. $post['shipremarks'] = $value['9'];//仓库品名
  2056. $post['client'] = preg_replace('/( | | | |\s)/',' ',$value['10']);//公司名
  2057. $post['name'] = preg_replace('/( | | | |\s)/',' ',$value['11']);//收货人
  2058. $post['phone'] = $value['12'];//电话
  2059. $ct = $this->country->get_ename(preg_replace('/( | | | |\s)/',' ',$value['13']));//国家
  2060. if(!$ct)
  2061. {
  2062. $ed[] = array($value['0'].'-无此国家');
  2063. $i++;continue;
  2064. }
  2065. $post['country'] = $ct['id'];//国家
  2066. $post['al'] = $ct['lb'];//国家二字码
  2067. $post['province'] = $value['14'];//省、州
  2068. $post['city'] = $value['15'];//城市
  2069. $post['zipcode'] = $value['16'];//邮编
  2070. $post['address'] = $value['17'];//地址1
  2071. $post['address2'] = $value['18']?$value['18']:'';//地址2
  2072. $yga = $value['3'];$ygb = $shop['estimaterate'];
  2073. $post['budget'] = eval("return $yga*1.$ygb;");//预估到帐金额
  2074. $post['sbpm'] = $value['19'];//申报品名
  2075. $post['zwpm'] = $value['20'];//中文品名
  2076. $post['ts'] = $value['21'];//条数
  2077. $post['dtsbjz'] = $value['22'];//单条申报价
  2078. $post['zsbjz'] = $value['23'];//总申报价
  2079. $post['zzl'] = $value['24'];//总重量
  2080. $post['zjs'] = $value['25'];//总件数
  2081. $express = $this->express->get_servicename(preg_replace('/( | | | |\s)/',' ',$value['26']));
  2082. if(!$express)
  2083. {
  2084. $ed[] = array($value['0'].'-无此快递方式');
  2085. $i++;continue;
  2086. }
  2087. $post['express'] = $express['id'];//快递
  2088. $post['printtype'] = 1;//打印类型 1.运单.2.发货单
  2089. $post['fpdata'] = '';//购买产品内容
  2090. $this->fullordersmt->insert($post);
  2091. }
  2092. else
  2093. {
  2094. $ed[] = array($value['0'].'-单号错误或重复操作');
  2095. $i++;
  2096. }
  2097. sleep(2);//停留2秒
  2098. }
  2099. if($i+$j > 0)
  2100. {
  2101. $time = date('Ymd',time());
  2102. $title = '错误信息-'.$time;
  2103. $titlename = "<table border=1><tr><td>错误详情</td></tr></table>";
  2104. $tail = "\n";
  2105. $filename = $title.".xls";
  2106. @$ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
  2107. $dir = '/data/excel/'.$time.'/';
  2108. $file_name = 'error_'.$time.rand(1000,9999);
  2109. if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
  2110. $myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
  2111. fwrite($myfile,$ecl);
  2112. fclose($myfile);
  2113. $error = $dir.$file_name.'.xls';
  2114. echo json_encode(array('msg'=>'添加成功,'.$i.'条异常,'.$j.'条失败','error'=>$error,'success'=>true));exit;
  2115. }
  2116. else
  2117. {
  2118. echo json_encode(array('msg'=>'添加成功!','error'=>1,'success'=>true));exit;
  2119. }
  2120. }
  2121. else
  2122. {
  2123. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  2124. }
  2125. }
  2126. public function _scwd()
  2127. {
  2128. $dir = '/data/excel/'.date('Ymd',time()).'/';
  2129. $config['upload_path'] = '.'.$dir ;
  2130. $config['allowed_types'] = '*';
  2131. $config['max_size'] = 102400;
  2132. $this->load->library('upload', $config);
  2133. $this->upload->initialize($config);
  2134. if ($this->upload->do_upload('userfile'))
  2135. {
  2136. $full_path = $dir.$this->upload->data('file_name');
  2137. echo json_encode(array('msg'=>'成功!','wdurl'=>$full_path,'success'=>true));exit;
  2138. }
  2139. else
  2140. {
  2141. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  2142. }
  2143. }
  2144. public function _jmexcel()
  2145. {
  2146. $setting = $this->setting->get_settings();
  2147. $excelpass = $setting['excelpass'];
  2148. $excelusernum = $setting['excelusernum'];
  2149. $exceljmnum = $setting['exceljmnum'];
  2150. $user = $this->user->get_api($_SESSION['api']);
  2151. if(!isset($user['exceltime']))
  2152. {
  2153. $this->session->sess_destroy();
  2154. header("Location:/");
  2155. }
  2156. $post = $this->input->post(NULL, TRUE);
  2157. if(isset($post['data']))
  2158. {
  2159. $data = $this->input->post('data',true);
  2160. $data = str_replace("\n",",",$data);;
  2161. $data = explode(',',trim($data,','));
  2162. $d = '';$i = 0;
  2163. foreach ($data as $v)
  2164. {
  2165. if($v == '')
  2166. {
  2167. continue;
  2168. }
  2169. $j = $this->setting->get_jmexcelpass($v);
  2170. if($j == '')
  2171. {
  2172. $j = $v.' 信息不正确';
  2173. }
  2174. $d .= $j."<br />";
  2175. $i++;
  2176. }
  2177. if($i > $exceljmnum)
  2178. {
  2179. echo json_encode(array('msg'=>'每次解密数量不可超出'.$exceljmnum.'条','success'=>false));exit;
  2180. }
  2181. if($user['exceltime'] != date('Ymd',time()))
  2182. {
  2183. $this->user->save(array('exceltime'=>date('Ymd',time()),'excelnum'=>1),$user['id']);
  2184. }
  2185. else
  2186. {
  2187. if($user['excelnum'] > $excelusernum)
  2188. {
  2189. echo json_encode(array('msg'=>'今日此账号解密次数已使用完毕','success'=>false));exit;
  2190. }
  2191. else
  2192. {
  2193. $this->user->save(array('excelnum'=>$user['excelnum']+1),$user['id']);
  2194. }
  2195. }
  2196. echo json_encode(array('msg'=>$d,'success'=>true));exit;
  2197. }
  2198. $this->data['excelpass'] = $excelpass;
  2199. $this->data['excelusernum'] = $excelusernum;
  2200. $this->data['exceljmnum'] = $exceljmnum;
  2201. $this->_Template('fullorderexcel_jmexcel',$this->data);
  2202. }
  2203. //管理
  2204. public function _classid()
  2205. {
  2206. $post = $this->input->post(NULL, TRUE);
  2207. if(isset($post['page']))
  2208. {
  2209. $page = $this->input->post('page',true);
  2210. $perpage = $this->input->post('perpage',true);
  2211. $type = $this->input->post('type',true);
  2212. $where = "1=1 ";
  2213. //数据排序
  2214. $order_str = "id asc";
  2215. if(empty($page))
  2216. {
  2217. $start = 0;
  2218. $perpage = 1;
  2219. }
  2220. else
  2221. {
  2222. $start = ($page - 1)*$perpage;
  2223. }
  2224. if($type)
  2225. {
  2226. $where .= " and type = '$type'";
  2227. }
  2228. //取得信息列表
  2229. $info_list = $this->fullorderexcelclassid->find_all($where,'id,title,type',$order_str,$start,$perpage);
  2230. $total = $this->fullorderexcelclassid->find_count($where);
  2231. $pagenum = ceil($total/$perpage);
  2232. $over = $total-($start+$perpage);
  2233. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  2234. echo json_encode($rows);exit;
  2235. }
  2236. $this->_Template('fullorderexcel_classid',$this->data);
  2237. }
  2238. //添加
  2239. public function _classidadd()
  2240. {
  2241. $post = $this->input->post(NULL, TRUE);
  2242. if(isset($post['title']))
  2243. {
  2244. if($this->fullorderexcelclassid->insert($post))
  2245. {
  2246. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  2247. }
  2248. else
  2249. {
  2250. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  2251. }
  2252. }
  2253. $this->_Template('fullorderexcel_classidadd',$this->data);
  2254. }
  2255. //修改
  2256. public function _classidedit($arg_array)
  2257. {
  2258. $post = $this->input->post(NULL, TRUE);
  2259. if(isset($post['id']))
  2260. {
  2261. $id = $this->input->post('id',true);
  2262. if($this->fullorderexcelclassid->save($post,$id))
  2263. {
  2264. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  2265. }
  2266. else
  2267. {
  2268. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  2269. }
  2270. }
  2271. $arg_array = $arg_array[0];
  2272. $fullorderexcelclassid = $this->fullorderexcelclassid->read($arg_array);
  2273. $this->data['fullorderexcelclassid'] = $fullorderexcelclassid;
  2274. $this->_Template('fullorderexcel_classidedit',$this->data);
  2275. }
  2276. }