Fullorderexcel.php 86 KB

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