Fullorderexcel.php 86 KB

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