Fullorderexcel.php 84 KB

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