Fullorderexcel.php 85 KB

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