Fullorderexcel.php 87 KB

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