Fullorderexcel.php 85 KB

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