Fullorderexcel.php 88 KB

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