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