Fullorderexcel.php 86 KB

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