Fullorderexcel.php 84 KB

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