Fullorderexcel.php 86 KB

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