Fullorderexcel.php 86 KB

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