Fullorderexcel.php 85 KB

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