Customer.php 126 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Customer extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_customer','customer');
  7. $this->load->_model('Model_typeclass','typeclass');
  8. $this->load->_model('Model_shop','shop');
  9. $this->load->_model('Model_country','country');
  10. $this->load->_model('Model_express','express');
  11. $this->load->_model('Model_fullorder','fullorder');
  12. $this->load->_model('Model_fullordertt','fullordertt');
  13. $this->load->_model('Model_excel','excel');
  14. $this->load->_model('Model_whlabel','whlabel');
  15. $this->load->_model('Model_warehouse','warehouse');
  16. $this->load->_model('Model_specialstock','specialstock');
  17. $this->load->_model('Model_ck','ck');
  18. $this->load->_model('Model_weight','weight');
  19. $this->load->_model('Model_pay','pay');
  20. $this->load->_model('Model_setting','setting');
  21. $this->load->_model('Model_classid','classid');
  22. $this->load->_model('Model_apiyy','apiyy');
  23. $this->load->_model('Model_whlabel_fc','whlabel_fc');
  24. $this->load->_model('Model_hl','hl');
  25. $this->load->_model('Model_productdescribe','productdescribe');
  26. $this->load->_model('Model_shopsku','shopsku');
  27. $this->load->_model('Model_api','api');
  28. $this->load->_model("Model_logic_order","logic_order");
  29. }
  30. //定义方法的调用规则 获取URI第二段值
  31. public function _remap($arg,$arg_array)
  32. {
  33. if($arg == 'add')//添加
  34. {
  35. $this->_add();
  36. }
  37. else if($arg == 'edit')//修改
  38. {
  39. $this->_edit($arg_array);
  40. }
  41. else if($arg == 'del')//黑名单
  42. {
  43. $this->_del();
  44. }
  45. else if($arg == 'change')//更改名单状态
  46. {
  47. $this->_change();
  48. }
  49. else if($arg == 'mdedit')//修改
  50. {
  51. $this->_mdedit($arg_array);
  52. }
  53. else if($arg == 'black')//黑名单
  54. {
  55. $this->_black();
  56. }
  57. else if($arg == 'excela')
  58. {
  59. $this->_excela();
  60. }
  61. else if($arg == 'temuexcel')
  62. {
  63. $this->_temuexcel();
  64. }
  65. else if($arg == 'daifakehuexcel')
  66. {
  67. $this->_daifakehuexcel();
  68. }
  69. else if($arg == 'excel')//下载excel
  70. {
  71. $this->_excel();
  72. }
  73. else if($arg == 'indexexcel')//下载excel
  74. {
  75. $this->_indexexcel();
  76. }
  77. else if($arg == 'down')//黑名单
  78. {
  79. $this->_down();
  80. }
  81. else if($arg == 'bankdown')//下载客户
  82. {
  83. $this->_bankdown();
  84. }
  85. else if($arg == 'newold')//新老客户比
  86. {
  87. $this->_newold();
  88. }
  89. else if($arg == 'dgso')
  90. {
  91. $this->_dgso();
  92. }
  93. else if($arg == 'cx')
  94. {
  95. $this->_cx();
  96. }
  97. else
  98. {
  99. $this->_index();
  100. }
  101. }
  102. //管理
  103. public function _index_xxxxxx()//通过索引订单查询购买次数,太慢,暂时抛弃
  104. {
  105. $user = $this->user->get_api($_SESSION['api']);
  106. if($user)
  107. {
  108. $fgshop = "";$sid = "";
  109. $user = explode('|',trim($user['shop'],'|'));
  110. foreach ($user as $value)
  111. {
  112. $fgshop .= " shop = ".$value." or";
  113. $sid .= " id = ".$value." or";
  114. }
  115. }
  116. $post = $this->input->post(NULL, TRUE);
  117. if(isset($post['page']))
  118. {
  119. $page = $this->input->post('page',true);
  120. $perpage = $this->input->post('perpage',true);
  121. $shop = $this->input->post('shop',true);
  122. $numphone = $this->input->post('numphone',true);
  123. $name = $this->input->post('name',true);
  124. $email = $this->input->post('email',true);
  125. $address = $this->input->post('address',true);
  126. $level = $this->input->post('level',true);
  127. $num = $this->input->post('num',true);
  128. $timetk = $this->input->post('timetk',true);
  129. $timetj = $this->input->post('timetj',true);
  130. $timetk = strtotime($timetk);
  131. $timetj = strtotime($timetj);
  132. $where = "1=1 and type = 1 and (".rtrim($fgshop,'or').")";
  133. if($shop)
  134. {
  135. $where .= " and shop = '$shop'";
  136. }
  137. if($numphone)
  138. {
  139. $where .= " and numphone = '$numphone'";
  140. }
  141. if($name)
  142. {
  143. $where .= " and name like '%$name%'";
  144. }
  145. if($email)
  146. {
  147. $where .= " and email like '%$email%'";
  148. }
  149. if($level)
  150. {
  151. $where .= " and level = '$level'";
  152. }
  153. if($address)
  154. {
  155. $where .= " and address like '%$address%'";
  156. }
  157. if($timetk && $timetj)
  158. {
  159. //$where .= " and ((time > '$timetk' and time < '$timetj') or time = 0)";
  160. $where .= " and ((time > '$timetk' and time < '$timetj') or time = '0')";
  161. }
  162. //数据排序
  163. $order_str = "id desc";
  164. $numdata = array();
  165. if(empty($page))
  166. {
  167. $start = 0;
  168. $perpage = 1;
  169. }
  170. else
  171. {
  172. $start = ($page - 1)*$perpage;
  173. }
  174. //取得信息列表
  175. if($num > 0)
  176. {
  177. $info_list = $this->customer->find_all($where,'id,shop,source,name,email,country,level,money,num,time,count,type',$order_str);
  178. }
  179. else
  180. {
  181. $info_list = $this->customer->find_all($where,'id,shop,source,name,email,country,level,money,num,time,count,type',$order_str,$start,$perpage);
  182. }
  183. foreach ($info_list as $key=>$value)
  184. {
  185. $shop = $this->shop->read($value['shop']);
  186. $info_list[$key]['shop'] = $shop['shopname'];
  187. $source = $this->typeclass->read($value['source']);
  188. $info_list[$key]['source'] = $source['title'];
  189. if($value['email'] != '0' && $value['email'] != '' && $value['email'] != '无')
  190. {
  191. $gnum = $this->fullorder->find_count("email = '".$value['email']."' and shop = '".$value['shop']."' and mergeid = 0 and buytime > '$timetk' and buytime < '$timetj'");
  192. }
  193. else
  194. {
  195. $gnum = 0;
  196. }
  197. $info_list[$key]['num'] = $gnum;
  198. if($value['country'] != 0)
  199. {
  200. $country = $this->country->read($value['country']);
  201. $info_list[$key]['country'] = $country['name'];
  202. }
  203. else
  204. {
  205. $info_list[$key]['country'] = "未知";
  206. }
  207. if($value['level'] == 1)
  208. {
  209. $info_list[$key]['level'] = "网红";
  210. }
  211. else if($value['level'] == 2)
  212. {
  213. $info_list[$key]['level'] = "批发";
  214. }
  215. else if($value['level'] == 3)
  216. {
  217. $info_list[$key]['level'] = "店铺转线下";
  218. }
  219. else if($value['level'] == 4)
  220. {
  221. $info_list[$key]['level'] = "线下其他";
  222. }
  223. else if($value['level'] == 5)
  224. {
  225. $info_list[$key]['level'] = "店内客户";
  226. }
  227. if($value['time'] != 0)
  228. {
  229. $info_list[$key]['time'] = date('Y-m-d',$value['time']);
  230. }
  231. else
  232. {
  233. $info_list[$key]['time'] = "无";
  234. }
  235. $info_list[$key]['type'] = "<a href='javascript:void(0);' class='window' data-h='/customer/mdedit/".$value['id']."' data-t='客户下单'><b>下单</b></a>&nbsp;&nbsp;&nbsp;&nbsp;<a class='customer' data-type='2' data-t='yr' data-id='".$value['id']."' href='javascript:void(0);'>移入黑名单</a>";
  236. if($num >= '10' && $gnum >= '10')
  237. {
  238. $numdata[] = $info_list[$key];
  239. }
  240. else if ($num > '0' && $num < '10' && $gnum == $num)
  241. {
  242. $numdata[] = $info_list[$key];
  243. }
  244. }
  245. if($num > 0)
  246. {
  247. $info_list = array_slice($numdata,$start,$perpage);;
  248. $total = count($numdata);
  249. }
  250. else
  251. {
  252. $total = $this->customer->find_count($where);
  253. }
  254. $pagenum = ceil($total/$perpage);
  255. $over = $total-($start+$perpage);
  256. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  257. echo json_encode($rows);exit;
  258. }
  259. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  260. $this->data['wlshop'] = $wlshop;
  261. $this->_Template('customer',$this->data);
  262. }
  263. public function _index()//通过计数,2020/02/21已校准
  264. {
  265. $user = $this->user->get_api($_SESSION['api']);
  266. $lv_yjtj = 0;
  267. if($user)
  268. {
  269. $fgshop = "";$sid = "";
  270. $users = explode('|',trim($user['shop'],'|'));
  271. foreach ($users as $value)
  272. {
  273. $fgshop .= " shop = ".$value." or";
  274. $sid .= " id = ".$value." or";
  275. }
  276. if(in_array($user['id'],[53241,10])){
  277. $lv_yjtj = 1;
  278. }
  279. if($user['vip'] == 1)
  280. {
  281. $vip = 1;
  282. }
  283. else
  284. {
  285. $vip = 0;
  286. }
  287. }
  288. else
  289. {
  290. $vip = 0;
  291. header('Location: /');exit;
  292. }
  293. $post = $this->input->post(NULL, TRUE);
  294. if(isset($post['page']))
  295. {
  296. $page = $this->input->post('page',true);
  297. $perpage = $this->input->post('perpage',true);
  298. $shop = $this->input->post('shop',true);
  299. $numphone = $this->input->post('numphone',true);
  300. $name = $this->input->post('name',true);
  301. $email = $this->input->post('email',true);
  302. $address = $this->input->post('address',true);
  303. $country = $this->input->post('country',true);
  304. $level = $this->input->post('level',true);
  305. $num = $this->input->post('num',true);
  306. $timetk = $this->input->post('timetk',true);
  307. $timetj = $this->input->post('timetj',true);
  308. $timetk = strtotime($timetk);
  309. $timetj = strtotime($timetj);
  310. $where = "1=1 and type = 1 and (".rtrim($fgshop,'or').")";
  311. if($shop)
  312. {
  313. $where .= " and shop = '$shop'";
  314. }
  315. if($numphone != '')
  316. {
  317. if($numphone == '0')
  318. {
  319. $where .= " and phone = '$numphone'" ;
  320. }
  321. else
  322. {
  323. $where .= " and numphone = '$numphone' and phone != ''" ;
  324. }
  325. }
  326. if($name)
  327. {
  328. $where .= " and name like '%$name%'";
  329. }
  330. if($country)
  331. {
  332. $where .= " and country = '$country'";
  333. }
  334. if($email)
  335. {
  336. $where .= " and email like '%$email%'";
  337. }
  338. if($level != '')
  339. {
  340. $where .= " and level = '$level'";
  341. }
  342. if($address)
  343. {
  344. $where .= " and address like '%$address%'";
  345. }
  346. if($num > 0 && $num < 10 && $num != '2a')
  347. {
  348. $where .= " and num = '$num'";
  349. }
  350. else if($num > 9)
  351. {
  352. $where .= " and num > '9'";
  353. }
  354. else if($num == '2a')
  355. {
  356. $where .= " and num > '1'";
  357. }
  358. else if($num == '0')
  359. {
  360. $where .= " and num = '0'";
  361. }
  362. else
  363. {
  364. $where .= " and num >= '0'";
  365. }
  366. if($timetk && $timetj)
  367. {
  368. $where .= " and ((time > '$timetk' and time < '$timetj') or time = '0')";
  369. }
  370. //数据排序
  371. $order_str = "time desc";
  372. $numdata = array();
  373. if(empty($page))
  374. {
  375. $start = 0;
  376. $perpage = 1;
  377. }
  378. else
  379. {
  380. $start = ($page - 1)*$perpage;
  381. }
  382. //取得信息列表
  383. $info_list = $this->customer->find_all($where,'id,shop,source,name,email,phone,country,level,money,num,numphone,time,count,type',$order_str,$start,$perpage);
  384. // ========== 性能优化:全表缓存替代循环内逐条查询(消除N+1问题)==========
  385. // shop/country/typeclass 都是几百条的小表,直接全表查出来放内存,比逐条查或IN都高效
  386. // 全量加载shop表,构建 id => shopname 映射
  387. $shop_map = [];
  388. $shop_rows = $this->shop->find_all('1=1', 'id,shopname');
  389. foreach ($shop_rows as $row) {
  390. $shop_map[$row['id']] = $row['shopname'];
  391. }
  392. // 全量加载typeclass表,构建 id => title 映射
  393. $source_map = [];
  394. $source_rows = $this->typeclass->find_all('1=1', 'id,title');
  395. foreach ($source_rows as $row) {
  396. $source_map[$row['id']] = $row['title'];
  397. }
  398. // 全量加载country表,构建 id => name 映射
  399. $country_map = [];
  400. $country_rows = $this->country->find_all('1=1', 'id,name');
  401. foreach ($country_rows as $row) {
  402. $country_map[$row['id']] = $row['name'];
  403. }
  404. // level值映射表(替代原来的if-elseif链)
  405. $level_map = [
  406. 1 => '网红',
  407. 2 => '批发',
  408. 3 => '店铺转线下',
  409. 4 => '线下其他',
  410. 5 => '店内客户',
  411. ];
  412. // 循环内仅做内存字典查找,不再发起数据库查询
  413. foreach ($info_list as $key => $value)
  414. {
  415. // 店铺名称映射
  416. $info_list[$key]['shop'] = isset($shop_map[$value['shop']]) ? $shop_map[$value['shop']] : '';
  417. // 来源映射
  418. $info_list[$key]['source'] = isset($source_map[$value['source']]) ? $source_map[$value['source']] : '';
  419. // 国家映射
  420. if ($value['country'] != 0) {
  421. $info_list[$key]['country'] = isset($country_map[$value['country']]) ? $country_map[$value['country']] : '未知';
  422. } else {
  423. $info_list[$key]['country'] = "未知";
  424. }
  425. // 客户等级映射
  426. $info_list[$key]['level'] = isset($level_map[$value['level']]) ? $level_map[$value['level']] : '未定义';
  427. // 时间格式化
  428. if ($value['time'] != 0) {
  429. $info_list[$key]['time'] = date('Y-m-d', $value['time']);
  430. } else {
  431. $info_list[$key]['time'] = "无";
  432. }
  433. // ========== 以下为原代码(注释保留)==========
  434. // $shop = $this->shop->read($value['shop']);
  435. // $info_list[$key]['shop'] = $shop['shopname'];
  436. // $source = $this->typeclass->read($value['source']);
  437. // $info_list[$key]['source'] = $source['title'];
  438. // if($value['country'] != 0)
  439. // {
  440. // $country = $this->country->read($value['country']);
  441. // $info_list[$key]['country'] = $country['name'];
  442. // }
  443. // else
  444. // {
  445. // $info_list[$key]['country'] = "未知";
  446. // }
  447. // if($value['level'] == 1)
  448. // {
  449. // $info_list[$key]['level'] = "网红";
  450. // }
  451. // else if($value['level'] == 2)
  452. // {
  453. // $info_list[$key]['level'] = "批发";
  454. // }
  455. // else if($value['level'] == 3)
  456. // {
  457. // $info_list[$key]['level'] = "店铺转线下";
  458. // }
  459. // else if($value['level'] == 4)
  460. // {
  461. // $info_list[$key]['level'] = "线下其他";
  462. // }
  463. // else if($value['level'] == 5)
  464. // {
  465. // $info_list[$key]['level'] = "店内客户";
  466. // }
  467. // else
  468. // {
  469. // $info_list[$key]['level'] = "未定义";
  470. // }
  471. // if($value['time'] != 0)
  472. // {
  473. // $info_list[$key]['time'] = date('Y-m-d',$value['time']);
  474. // }
  475. // else
  476. // {
  477. // $info_list[$key]['time'] = "无";
  478. // }
  479. //$gmcs = $this->fullorder->find_count("email = '".$value['email']."' time > '$timetk' and time < '$timetj'");
  480. //$info_list[$key]['num'] = $gmcs;
  481. $info_list[$key]['numphone'] = ($value['num'] > 0)?sprintf("%01.2f",$value['money']/$value['num']):0;
  482. $info_list[$key]['type'] = "<p><a href='javascript:void(0);' class='window' data-h='/customer/mdedit/".$value['id']."' data-t='客户下单'><b>下单</b></a></p>";
  483. if($lv_yjtj == 1){
  484. $info_list[$key]['type'] .= "<p><a href='javascript:void(0);' class='window' data-h='/fullorderabf/yhtj_kh?cid=".$value['id']."' data-t='客户一键下单'><b>一键添加订单</b></a></p>";
  485. }
  486. $info_list[$key]['type'] .= "<a class='customer' data-type='2' data-t='yr' data-id='".$value['id']."' href='javascript:void(0);'>移入黑名单</a>";
  487. }
  488. $total = $this->customer->find_count($where);
  489. $pagenum = ceil($total/$perpage);
  490. $over = $total-($start+$perpage);
  491. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  492. echo json_encode($rows);exit;
  493. }
  494. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  495. $this->data['wlshop'] = $wlshop;
  496. $this->data['vip'] = $vip;
  497. $this->_Template('customer',$this->data);
  498. }
  499. public function _dgso——tmp()
  500. {
  501. $user = $this->user->get_api($_SESSION['api']);
  502. if($user)
  503. {
  504. $fgshop = "";$sid = "";
  505. $users = explode('|',trim($user['shop'],'|'));
  506. foreach ($users as $value)
  507. {
  508. $fgshop .= " shop = ".$value." or";
  509. $sid .= " id = ".$value." or";
  510. }
  511. if($user['vip'] == 1)
  512. {
  513. $vip = 1;
  514. }
  515. else
  516. {
  517. $vip = 0;
  518. }
  519. }
  520. else
  521. {
  522. $vip = 0;
  523. die("请先登录!!!");
  524. }
  525. $post = $this->input->post(NULL, TRUE);
  526. if(isset($post['page']))
  527. {
  528. $page = $this->input->post('page',true);
  529. $perpage = $this->input->post('perpage',true);
  530. $shop = $this->input->post('shop',true);
  531. $numphone = $this->input->post('numphone',true);
  532. $name = $this->input->post('name',true);
  533. $email = $this->input->post('email',true);
  534. $address = $this->input->post('address',true);
  535. $level = $this->input->post('level',true);
  536. $num = $this->input->post('num',true);
  537. $timetk = $this->input->post('timetk',true);
  538. $timetj = $this->input->post('timetj',true);
  539. $timetk = strtotime($timetk);
  540. $timetj = strtotime($timetj);
  541. $where = "1=1 and (".rtrim($fgshop,'or').")";
  542. if($numphone)
  543. {
  544. $where .= " and numphone = '$numphone'";
  545. }
  546. if($email)
  547. {
  548. $where .= " and email like '%$email%'";
  549. }
  550. if($address)
  551. {
  552. $where .= " and address like '%$address%'";
  553. }
  554. if($numphone || $email || $address)
  555. {
  556. $d = $this->customer->find_all($where);
  557. $data = $this->customer->find_all("address like '%".$d[0]['address']."%' or email like '%".$d[0]['email']."%' or numphone like '%".$d[0]['numphone']."%'",'id,shop,source,name,email,country,level,money,num,time,type,numphone,address');
  558. //$temp_key = array_column($data,'id'); //键值
  559. //$Newdata = array_combine($temp_key,$data) ;
  560. $cx = array();
  561. $info_list = $this->_dgcz($cx,$data);
  562. $info_list = array_values($info_list);
  563. $total = count($info_list);
  564. $pagenum = ceil($total/$perpage);
  565. $over = $total-$perpage;
  566. }
  567. else
  568. {
  569. //数据排序
  570. $order_str = "id desc";
  571. $numdata = array();
  572. if(empty($page))
  573. {
  574. $start = 0;
  575. $perpage = 1;
  576. }
  577. else
  578. {
  579. $start = ($page - 1)*$perpage;
  580. }
  581. //取得信息列表
  582. $info_list = $this->customer->find_all($where,'id,shop,source,name,email,country,level,money,num,time,type',$order_str,$start,$perpage);
  583. $total = $this->customer->find_count($where);
  584. $pagenum = ceil($total/$perpage);
  585. $over = $total-($start+$perpage);
  586. }
  587. foreach ($info_list as $key=>$value)
  588. {
  589. $shop = $this->shop->read($value['shop']);
  590. $info_list[$key]['shop'] = $shop['shopname'];
  591. $source = $this->typeclass->read($value['source']);
  592. $info_list[$key]['source'] = $source['title'];
  593. if($value['country'] != 0)
  594. {
  595. $country = $this->country->read($value['country']);
  596. $info_list[$key]['country'] = $country['name'];
  597. }
  598. else
  599. {
  600. $info_list[$key]['country'] = "未知";
  601. }
  602. if($value['level'] == 1)
  603. {
  604. $info_list[$key]['level'] = "网红";
  605. }
  606. else if($value['level'] == 2)
  607. {
  608. $info_list[$key]['level'] = "批发";
  609. }
  610. else if($value['level'] == 3)
  611. {
  612. $info_list[$key]['level'] = "店铺转线下";
  613. }
  614. else if($value['level'] == 4)
  615. {
  616. $info_list[$key]['level'] = "线下其他";
  617. }
  618. else if($value['level'] == 5)
  619. {
  620. $info_list[$key]['level'] = "店内客户";
  621. }
  622. if($value['time'] != 0)
  623. {
  624. $info_list[$key]['time'] = date('Y-m-d',$value['time']);
  625. }
  626. else
  627. {
  628. $info_list[$key]['time'] = "无";
  629. }
  630. if($value['type'] != 2)
  631. {
  632. $info_list[$key]['type'] = "<a href='javascript:void(0);' class='window' data-h='/customer/mdedit/".$value['id']."' data-t='客户下单'><b>下单</b></a>&nbsp;&nbsp;&nbsp;&nbsp;<a class='customer' data-type='2' data-t='yr' data-id='".$value['id']."' href='javascript:void(0);'>移入黑名单</a>";
  633. }
  634. else
  635. {
  636. $info_list[$key]['type'] = "黑名单客户";
  637. }
  638. unset($info_list[$key]['numphone']);
  639. unset($info_list[$key]['address']);
  640. }
  641. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  642. echo json_encode($rows);exit;
  643. }
  644. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  645. $this->data['wlshop'] = $wlshop;
  646. $this->data['vip'] = $vip;
  647. $this->_Template('customer_dgso',$this->data);
  648. }
  649. public function _dgcz($child,$data)
  650. {
  651. foreach ($data as $key => $value)
  652. {
  653. if (!isset($child[$value['id']]))
  654. {
  655. $child[$value['id']] = $value;
  656. $rows = $this->customer->find_all("address like '%".$value['address']."%' or email like '%".$value['email']."%' or numphone like '%".$value['numphone']."%'",'id,shop,source,name,email,country,level,money,num,time,type,numphone,address');
  657. $this->_dgcz($child,$rows);
  658. }
  659. }
  660. return $child;
  661. }
  662. //管理
  663. public function _black()
  664. {
  665. /**
  666. $user = $this->user->get_api($_SESSION['api']);
  667. if($user)
  668. {
  669. $fgshop = "";$sid = "";
  670. $user = explode('|',trim($user['shop'],'|'));
  671. foreach ($user as $value)
  672. {
  673. $fgshop .= " shop = ".$value." or";
  674. $sid .= " id = ".$value." or";
  675. }
  676. }
  677. **/
  678. $post = $this->input->post(NULL, TRUE);
  679. if(isset($post['page']))
  680. {
  681. $page = $this->input->post('page',true);
  682. $perpage = $this->input->post('perpage',true);
  683. $shop = $this->input->post('shop',true);
  684. $numphone = $this->input->post('numphone',true);
  685. $name = $this->input->post('name',true);
  686. $email = $this->input->post('email',true);
  687. $address = $this->input->post('address',true);
  688. $xtime = $this->input->post('xtime',true);
  689. //$where = "1=1 and type = 2 and (".rtrim($fgshop,'or').")";
  690. $timetk = $this->input->post('timetk',true);
  691. $timetj = $this->input->post('timetj',true);
  692. $timetk = strtotime($timetk);
  693. $timetj = strtotime($timetj);
  694. $where = "1=1 and type = 2";
  695. if($shop)
  696. {
  697. $where .= " and shop = '$shop'";
  698. }
  699. if($xtime)
  700. {
  701. $where .= " and typetime > '$timetk' and typetime < '$timetj'";
  702. }
  703. if($numphone != '')
  704. {
  705. if($numphone == '0')
  706. {
  707. $where .= " and phone = '$numphone'" ;
  708. }
  709. else
  710. {
  711. $where .= " and numphone = '$numphone' and phone != ''" ;
  712. }
  713. }
  714. if($name)
  715. {
  716. $where .= " and name like '%$name%'";
  717. }
  718. if($email)
  719. {
  720. $where .= " and email like '%$email%'";
  721. }
  722. $hmdaddress1 = str_replace(array(' parkway',' drive',' street',' road',' avenue',' boulevard',' alley',' court',' place',' lane',' manor',' terrace',' trail',' view',' cove'),array(' pkwy',' dr',' st',' rd',' av',' blvd',' aly',' ct',' pl',' ln',' mnr',' ter',' trl',' vw',' cv'),strtolower($address));
  723. $hmdaddress2 = str_replace(array(' pkwy',' dr',' st',' rd',' av',' blvd',' aly',' ct',' pl',' ln',' mnr',' ter',' trl',' vw',' cv'),array(' parkway',' drive',' street',' road',' avenue',' boulevard',' alley',' court',' place',' lane',' manor',' terrace',' trail',' view',' cove'),strtolower($address));
  724. $hmdaddress3 = str_replace(array(' avenue',' ave',' av'),array(' ave',' avenue',' ave'),strtolower($address));
  725. if($address)
  726. {
  727. $where .= " and (address like '%$address%' or address like '%$hmdaddress1%' or address like '%$hmdaddress2%' or address like '%$hmdaddress3%')";
  728. }
  729. //数据排序
  730. $order_str = "id desc";
  731. if(empty($page))
  732. {
  733. $start = 0;
  734. $perpage = 1;
  735. }
  736. else
  737. {
  738. $start = ($page - 1)*$perpage;
  739. }
  740. //取得信息列表
  741. $info_list = $this->customer->find_all($where,'id,shop,source,name,email,address,phone,count,typetime,type',$order_str,$start,$perpage);
  742. foreach ($info_list as $key=>$value)
  743. {
  744. $shop = $this->shop->read($value['shop']);
  745. $info_list[$key]['shop'] = $shop['shopname'];
  746. $source = $this->typeclass->read($value['source']);
  747. $info_list[$key]['source'] = $source['title'];
  748. if($value['typetime'] > 0)
  749. {
  750. $info_list[$key]['typetime'] = date('Y-m-d',$value['typetime']);
  751. }
  752. else
  753. {
  754. $info_list[$key]['typetime'] = '无';
  755. }
  756. $info_list[$key]['type'] = "<a class='customer' data-type='1' data-t='yc' data-id='".$value['id']."' href='javascript:void(0);'>移出</a>";
  757. }
  758. $total = $this->customer->find_count($where);
  759. $pagenum = ceil($total/$perpage);
  760. $over = $total-($start+$perpage);
  761. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'a'=>$hmdaddress1);
  762. echo json_encode($rows);exit;
  763. }
  764. if(isset($post['s']))
  765. {
  766. $id_arr = $this->input->post('s');
  767. $id_arr = explode(',',$id_arr);
  768. if(!$id_arr)
  769. {
  770. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  771. }
  772. //循环删除记录
  773. foreach ($id_arr as $v)
  774. {
  775. $this->customer->remove($v);
  776. }
  777. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));exit;
  778. }
  779. //$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  780. $wlshop = $this->shop->find_all('1=1');
  781. $this->data['wlshop'] = $wlshop;
  782. $this->_Template('customer_black',$this->data);
  783. }
  784. public function _cx()
  785. {
  786. $post = $this->input->post(NULL, TRUE);
  787. if(isset($post['page']))
  788. {
  789. $page = $this->input->post('page',true);
  790. $perpage = $this->input->post('perpage',true);
  791. $shop = $this->input->post('shop',true);
  792. $numphone = $this->input->post('numphone',true);
  793. $name = $this->input->post('name',true);
  794. $email = $this->input->post('email',true);
  795. $address = $this->input->post('address',true);
  796. $xtime = $this->input->post('xtime',true);
  797. //$where = "1=1 and type = 2 and (".rtrim($fgshop,'or').")";
  798. $timetk = $this->input->post('timetk',true);
  799. $timetj = $this->input->post('timetj',true);
  800. $timetk = strtotime($timetk);
  801. $timetj = strtotime($timetj);
  802. $where = "1=1 and type = 2";
  803. if($shop)
  804. {
  805. $where .= " and shop = '$shop'";
  806. }
  807. if($xtime)
  808. {
  809. $where .= " and typetime > '$timetk' and typetime < '$timetj'";
  810. }
  811. if($numphone)
  812. {
  813. $where .= " and numphone = '$numphone'";
  814. }
  815. if($name)
  816. {
  817. $where .= " and name like '%$name%'";
  818. }
  819. if($email)
  820. {
  821. $where .= " and email like '%$email%'";
  822. }
  823. $hmdaddress1 = str_replace(array(' parkway',' drive',' street',' road',' avenue',' boulevard',' alley',' court',' place',' lane',' manor',' terrace',' trail',' view',' cove'),array(' pkwy',' dr',' st',' rd',' av',' blvd',' aly',' ct',' pl',' ln',' mnr',' ter',' trl',' vw',' cv'),strtolower($address));
  824. $hmdaddress2 = str_replace(array(' pkwy',' dr',' st',' rd',' av',' blvd',' aly',' ct',' pl',' ln',' mnr',' ter',' trl',' vw',' cv'),array(' parkway',' drive',' street',' road',' avenue',' boulevard',' alley',' court',' place',' lane',' manor',' terrace',' trail',' view',' cove'),strtolower($address));
  825. $hmdaddress3 = str_replace(array(' avenue',' ave',' av'),array(' ave',' avenue',' ave'),strtolower($address));
  826. if($address)
  827. {
  828. $where .= " and (address like '%$address%' or address like '%$hmdaddress1%' or address like '%$hmdaddress2%' or address like '%$hmdaddress3%')";
  829. }
  830. //数据排序
  831. $order_str = "id desc";
  832. if(empty($page))
  833. {
  834. $start = 0;
  835. $perpage = 1;
  836. }
  837. else
  838. {
  839. $start = ($page - 1)*$perpage;
  840. }
  841. //取得信息列表
  842. $info_list = $this->customer->find_all($where,'id,shop,source,name,email,address,phone,count,typetime',$order_str,$start,$perpage);
  843. foreach ($info_list as $key=>$value)
  844. {
  845. $shop = $this->shop->read($value['shop']);
  846. $info_list[$key]['shop'] = $shop['shopname'];
  847. $source = $this->typeclass->read($value['source']);
  848. $info_list[$key]['source'] = $source['title'];
  849. if($value['typetime'] > 0)
  850. {
  851. $info_list[$key]['typetime'] = date('Y-m-d',$value['typetime']);
  852. }
  853. else
  854. {
  855. $info_list[$key]['typetime'] = '无';
  856. }
  857. }
  858. $total = $this->customer->find_count($where);
  859. $pagenum = ceil($total/$perpage);
  860. $over = $total-($start+$perpage);
  861. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'a'=>$hmdaddress1);
  862. echo json_encode($rows);exit;
  863. }
  864. if(isset($post['s']))
  865. {
  866. $id_arr = $this->input->post('s');
  867. $id_arr = explode(',',$id_arr);
  868. if(!$id_arr)
  869. {
  870. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  871. }
  872. //循环删除记录
  873. foreach ($id_arr as $v)
  874. {
  875. $this->customer->remove($v);
  876. }
  877. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));exit;
  878. }
  879. $wlshop = $this->shop->find_all('1=1');
  880. $this->data['wlshop'] = $wlshop;
  881. $this->_Template('customer_black_cx',$this->data);
  882. }
  883. //添加
  884. public function _add()
  885. {
  886. $user = $this->user->get_api($_SESSION['api']);
  887. if($user)
  888. {
  889. $fgshop = "";$sid = "";
  890. $user = explode('|',trim($user['shop'],'|'));
  891. foreach ($user as $value)
  892. {
  893. $fgshop .= " shop = ".$value." or";
  894. $sid .= " id = ".$value." or";
  895. }
  896. }
  897. $post = $this->input->post(NULL, TRUE);
  898. if(isset($post['shop']))
  899. {
  900. $post['shop'] = $this->input->post('shop',true);
  901. $post['source'] = $this->input->post('source',true);
  902. $post['level'] = $this->input->post('level',true);
  903. $post['country'] = $this->input->post('country',true);
  904. $name = $this->input->post('name',true);
  905. $post['name'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$name);
  906. $post['phone'] = $this->input->post('phone',true);
  907. $email = $this->input->post('email',true);
  908. $post['email'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$email);
  909. $post['province'] = $this->input->post('province',true);
  910. $post['city'] = $this->input->post('city',true);
  911. //$post['street'] = $this->input->post('street',true);
  912. $address = $this->input->post('address',true);
  913. $post['address'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$address);
  914. //$post['address2'] = $this->input->post('address2',true);
  915. $post['count'] = $this->input->post('count',true);
  916. $post['time'] = time();
  917. $str = $post['phone'];
  918. if(!$post['shop'])
  919. {
  920. echo json_encode(array('msg'=>'店铺不能为空!','success'=>false));exit;
  921. }
  922. preg_match_all('/[0-9]/u',$str,$result);
  923. $numphone = join('',$result[0]);
  924. $post['numphone'] = $numphone;
  925. $post['zhcx'] = $post['shop'].'-'.$post['email'];
  926. $kh = $this->customer->get_email($post['email'],$post['shop']);
  927. if($kh)
  928. {
  929. echo json_encode(array('msg'=>'此客户已存在!','success'=>false));exit;
  930. }
  931. if($this->customer->insert($post))
  932. {
  933. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  934. }
  935. else
  936. {
  937. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  938. }
  939. }
  940. $country = $this->country->find_all('1=1','id,name','name asc');
  941. $this->data['country'] = $country;
  942. $wlshop = $this->shop->find_all("(type = 269 or type = 2768)and (".rtrim($sid,'or').")");
  943. $this->data['wlshop'] = $wlshop;
  944. $this->_Template('customer_add',$this->data);
  945. }
  946. //修改
  947. public function _edit($arg_array)
  948. {
  949. $user = $this->user->get_api($_SESSION['api']);
  950. if($user)
  951. {
  952. $fgshop = "";$sid = "";
  953. $user = explode('|',trim($user['shop'],'|'));
  954. foreach ($user as $value)
  955. {
  956. $fgshop .= " shop = ".$value." or";
  957. $sid .= " id = ".$value." or";
  958. }
  959. }
  960. $post = $this->input->post(NULL, TRUE);
  961. if(isset($post['id']))
  962. {
  963. $id = $this->input->post('id',true);
  964. $us = $this->customer->read($id);
  965. $post['shop'] = $this->input->post('shop',true);
  966. $post['source'] = $this->input->post('source',true);
  967. $post['level'] = $this->input->post('level',true);
  968. $post['country'] = $this->input->post('country',true);
  969. $name = $this->input->post('name',true);
  970. $post['name'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$name);
  971. $post['phone'] = $this->input->post('phone',true);
  972. $email = $this->input->post('email',true);
  973. $post['email'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$email);
  974. $post['province'] = $this->input->post('province',true);
  975. $post['city'] = $this->input->post('city',true);
  976. //$post['street'] = $this->input->post('street',true);
  977. $address = $this->input->post('address',true);
  978. $post['address'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$address);
  979. //$post['address2'] = $this->input->post('address2',true);
  980. $post['type'] = $this->input->post('type',true);
  981. $post['count'] = $this->input->post('count',true);
  982. $str = $post['phone'];
  983. preg_match_all('/[0-9]/u',$str,$result);
  984. $numphone = join('',$result[0]);
  985. $post['numphone'] = $numphone;
  986. $post['zhcx'] = $post['shop'].'-'.$post['email'];
  987. if($this->customer->save($post,$id))
  988. {
  989. echo json_encode(array('msg'=>'操作成功!','success'=>true));exit;
  990. }
  991. else
  992. {
  993. echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
  994. }
  995. }
  996. $arg_array = $arg_array[0];
  997. $customer = $this->customer->read($arg_array);
  998. $this->data['customer'] = $customer;
  999. $country = $this->country->find_all('1=1','id,name','name asc');
  1000. $this->data['country'] = $country;
  1001. $wlshop = $this->shop->find_all("(type = 269 or type = 2768) and (".rtrim($sid,'or').")");
  1002. $this->data['wlshop'] = $wlshop;
  1003. if($customer['email'] != '0' && $customer['email'] != '' && $customer['email'] != '无')
  1004. {
  1005. $fdata = $this->fullorder->find_all('email = "'.$customer['email'].'" and shop = "'.$customer['shop'].'" and mergeid = 0','orderinfo,state,product,name,email,dtime,shouldmoney','id desc');
  1006. foreach ($fdata as $k=>$v)
  1007. {
  1008. $d = $this->fullorder->get_orderinfo($v['orderinfo']);
  1009. $fdata[$k]['orderinfo'] = "<a href='/fullorder/readonly/".$d['id']."'>".$v['orderinfo']."</a>";
  1010. $typeclass = $this->typeclass->read($v['state']);
  1011. $fdata[$k]['state'] = $typeclass['spare'];
  1012. $fdata[$k]['dtime'] = date('Y-m-d',$v['dtime']);
  1013. }
  1014. $this->data['data'] = $fdata;
  1015. }
  1016. $this->_Template('customer_edit',$this->data);
  1017. }
  1018. //删除
  1019. public function _del()
  1020. {
  1021. $post = $this->input->post(NULL, TRUE);
  1022. if(isset($post['s']))
  1023. {
  1024. $id_arr = $this->input->post('s');
  1025. $id_arr = explode(',',$id_arr);
  1026. if(!$id_arr)
  1027. {
  1028. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  1029. }
  1030. //循环删除记录
  1031. $a=0;
  1032. foreach ($id_arr as $v)
  1033. {
  1034. $customer = $this->customer->read($v);
  1035. if($customer['email'] != '0' && $customer['email'] != '' && $customer['email'] != '无')
  1036. {
  1037. $fdata = $this->fullorder->find_count('email = "'.$customer['email'].'" and shop = "'.$customer['shop'].'" and mergeid = 0');
  1038. }
  1039. if($fdata > 0)
  1040. {
  1041. $a++;
  1042. continue;
  1043. }
  1044. else
  1045. {
  1046. $this->customer->remove($v);
  1047. }
  1048. }
  1049. if($a > 0)
  1050. {
  1051. echo json_encode(array('del'=>$id_arr,'msg'=>'无订单客户删除成功,有订单的客户无法删除!','success'=>true));
  1052. }
  1053. else
  1054. {
  1055. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  1056. }
  1057. }
  1058. }
  1059. //操作
  1060. public function _change()
  1061. {
  1062. $post = $this->input->post(NULL, TRUE);
  1063. if(isset($post['type']))
  1064. {
  1065. $type = $this->input->post('type',true);
  1066. $id = $this->input->post('id',true);
  1067. $count = $this->input->post('count',true);
  1068. if($this->customer->save(array('type'=>$type,'count'=>$count,'typetime'=>time()),$id))
  1069. {
  1070. echo json_encode(array('msg'=>'操作成功!','success'=>true));exit;
  1071. }
  1072. else
  1073. {
  1074. echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
  1075. }
  1076. }
  1077. }
  1078. //修改客户分类
  1079. public function _mdedit_xxxxxbak($arg_array)
  1080. {
  1081. $user = $this->user->get_api($_SESSION['api']);
  1082. if($user)
  1083. {
  1084. $uu = $user;
  1085. $fgshop = "";$sid = "";
  1086. $u = $user;
  1087. $user = explode('|',trim($user['shop'],'|'));
  1088. foreach ($user as $value)
  1089. {
  1090. $fgshop .= " shop = ".$value." or";
  1091. $sid .= " id = ".$value." or";
  1092. }
  1093. }
  1094. $post = $this->input->post(NULL, TRUE);
  1095. if(isset($post['shop']))
  1096. {
  1097. $fpcount = $this->input->post('fpcount',true);
  1098. if(!$fpcount)
  1099. {
  1100. echo json_encode(array('msg'=>'需要先清理浏览器缓存,刷新当前页面后再试!','success'=>false));exit;
  1101. }
  1102. $customerid = $this->input->post('customerid',true);
  1103. $shop = $this->input->post('shop',true);
  1104. $sp = $this->shop->read($shop);
  1105. $num = $this->fullorder->find_count('shop = "'.$sp['id'].'" and gtime = "'.date('Ymd',time()).'"');
  1106. $post['source'] = 1;//订单类型:1.线下订单2.PC3.手机
  1107. $post['state'] = 207;//订单状态:207等待发货
  1108. $post['review'] = 2;//审核状态:1.未送审2.待审核3.不通过4取消重审5.审核通过6.自动通过
  1109. $post['print'] = 1;//打印状态:1.不可打印2.未打印3.已打印
  1110. $post['library'] = 1;//出库状态:1.未出库2.已出库3.已退库
  1111. $post['libraryconfirm'] = 1;//出库确认:1.不允许2.允许
  1112. $post['link'] = $sp['link'];
  1113. $post['issku'] = $sp['sku'];
  1114. if($post['print'] != 3)
  1115. {
  1116. $post['librarynot'] = "订单未打印,未审核或未通过";//不能出库原因
  1117. }
  1118. $orderinfo = $this->input->post('orderinfo',true);
  1119. $post['shop'] = $sp['id'];
  1120. $post['user'] = $sp['shopuser'];
  1121. $post['number'] = $sp['shortname'].'-'.date('ymd',time()).'-'.(substr(strval($num+1+1000),1,3));//编号
  1122. if($orderinfo != "")
  1123. {
  1124. $ordefin = $this->fullorder->get_orderinfo($orderinfo);
  1125. if($ordefin)
  1126. {
  1127. echo json_encode(array('msg'=>'订单号重复!','success'=>false));exit;
  1128. }
  1129. else
  1130. {
  1131. $post['orderinfo'] = $orderinfo;
  1132. }
  1133. }
  1134. else
  1135. {
  1136. $post['orderinfo'] = $sp['id'].date('ymdHis',time()).rand(0,1);//订单号
  1137. }
  1138. // if(empty($post['paypal'])){
  1139. // echo json_encode(array('msg'=>'交易号不可为空!','success'=>false));exit;
  1140. // }
  1141. if($post['paypal'] != '')
  1142. {
  1143. $pp = $this->fullorder->get_paypal($post['paypal']);
  1144. if($pp)
  1145. {
  1146. echo json_encode(array('msg'=>'此交易号的订单已存在!','success'=>false));exit;
  1147. }
  1148. }
  1149. $post['client'] = $this->input->post('client',true);//客户名称
  1150. $btime = $this->input->post('buytime',true);//付款时间
  1151. $post['buytime'] = strtotime($btime);//时间转UX
  1152. $post['dtime'] = time();//订单时间
  1153. $post['gtime'] = date('Ymd',time());//格式化时间
  1154. $post['pay'] = $this->input->post('pay',true);//支付方式
  1155. $post['capital'] = $this->input->post('capital',true);//资金状态
  1156. $post['type'] = $this->input->post('warehouse',true);//发货仓库
  1157. $post['currency'] = $this->input->post('currency',true);//币种
  1158. $currency = $this->typeclass->read($post['currency']);
  1159. $post['currencytitle'] = $currency['title'];//币种名称
  1160. $post['freight'] = $this->input->post('freight',true);//运费
  1161. $post['expressmoney'] = $this->input->post('expressmoney',true);//物流金额
  1162. $post['shouldmoney'] = $this->input->post('shouldmoney',true);//应收金额
  1163. $post['skje'] = $post['shouldmoney'];//收款金额
  1164. $product = $this->input->post('product');//产品名称
  1165. $product = str_replace(array('%26','%2B'),array('&','+'),$product);
  1166. $post['product'] = preg_replace('/( | | |\s)/',' ',$product);
  1167. $orderremarks = $this->input->post('orderremarks');//订单备注
  1168. $orderremarks = str_replace(array('%26','%2B'),array('&','+'),$orderremarks);
  1169. $post['orderremarks'] = preg_replace('/( | | |\s)/',' ',$orderremarks);
  1170. $shipremarks = $this->input->post('shipremarks');//仓库品名
  1171. $shipremarks = str_replace(array('%26','%2B'),array('&','+'),$shipremarks);//仓库品名
  1172. $post['shipremarks'] = preg_replace('/( | | |\s)/',' ',$shipremarks);
  1173. $post['email'] = $this->input->post('email',true);//邮箱
  1174. $name = $this->input->post('name',true);//名称
  1175. $post['name'] = preg_replace('/( | | |\s)/',' ',$name);
  1176. $post['phone'] = $this->input->post('phone',true);//电话
  1177. $post['phone'] = preg_replace('/\D/s','',$post['phone']);
  1178. $post['country'] = $this->input->post('country',true);//国家
  1179. $ct = $this->country->read($post['country']);//国家
  1180. $post['al'] = $ct['lb'];//国家二字码
  1181. $post['province'] = $this->input->post('province',true);//省、州
  1182. $post['province'] = preg_replace("/^[\s\v".chr(227).chr(128)."]+/","", $post['province']); //替换开头空字符
  1183. $post['province'] = preg_replace("/[\s\v".chr(227).chr(128)."]+$/","", $post['province']); //替换结尾空字符
  1184. $post['city'] = $this->input->post('city',true);//城市
  1185. $post['city'] = preg_replace("/^[\s\v".chr(227).chr(128)."]+/","", $post['city']); //替换开头空字符
  1186. $post['city'] = preg_replace("/[\s\v".chr(227).chr(128)."]+$/","", $post['city']); //替换结尾空字符
  1187. $post['zipcode'] = $this->input->post('zipcode',true);//邮编
  1188. $post['zipcode'] = preg_replace("/^[\s\v".chr(227).chr(128)."]+/","", $post['zipcode']); //替换开头空字符
  1189. $post['zipcode'] = preg_replace("/[\s\v".chr(227).chr(128)."]+$/","", $post['zipcode']); //替换结尾空字符
  1190. $post['address'] = $this->input->post('address',true);//地址
  1191. $post['printtype'] = $this->input->post('printtype',true);//打印类型
  1192. $fpdata = $this->input->post('fpdata');//购买产品内容
  1193. $fpdata = str_replace(array('%26','%2B'),array('&','+'),$fpdata);
  1194. $post['fpdata'] = $fpdata;
  1195. $post['sbpm'] = $this->input->post('sbpm',true);//申报品名
  1196. $post['zwpm'] = $this->input->post('zwpm',true);//中文品名
  1197. $post['ts'] = $this->input->post('ts',true);//条数
  1198. $post['dtsbjz'] = $this->input->post('dtsbjz',true);//单条申报价
  1199. $post['zsbjz'] = $this->input->post('zsbjz',true);//总申报价
  1200. $post['zzl'] = $this->input->post('zzl',true);//总重量
  1201. $post['zjs'] = $this->input->post('zjs',true);//总件数
  1202. $post['express'] = $this->input->post('express',true);//快递公司
  1203. $post['printtype'] = $this->input->post('printtype',true);//打印类型
  1204. $post['quantity'] = $this->input->post('quantity',true);//数量
  1205. $post['paypal'] = $this->input->post('paypal',true);//支付号
  1206. $post['guarantee'] = $this->input->post('guarantee',true);//卖家保障
  1207. $post['msg'] = $this->input->post('msg',true);//发送留言类型
  1208. $post['ioss'] = $this->input->post('ioss',true);
  1209. $post['sbpm'] = $this->input->post('sbpm',true);
  1210. $pay = $this->pay->get_typeclass($post['pay']);
  1211. $yga = $post['shouldmoney'];
  1212. $post['budget'] = 0;
  1213. if($pay)
  1214. {
  1215. $ygc = $pay['estimaterate'];//预估到账公式
  1216. $ifbudget = eval("return $yga*1.$ygc;");
  1217. $post['estimaterate'] = $pay['estimaterate'];
  1218. if($ifbudget > 0)
  1219. {
  1220. $post['budget'] = eval("return $yga*1.$ygc;");//预估到帐金额
  1221. }
  1222. }
  1223. else
  1224. {
  1225. $ygb = $sp['estimaterate'];//店铺默认到账公式
  1226. $ifbudget = eval("return $yga*1.$ygb;");
  1227. $post['estimaterate'] = $sp['estimaterate'];
  1228. if($ifbudget > 0)
  1229. {
  1230. $post['budget'] = eval("return $yga*1.$ygb;");//预估到帐金额
  1231. }
  1232. }
  1233. $baddress = $this->input->post('baddress',true);
  1234. $saddress = $this->input->post('saddress',true);
  1235. $baddress = array_reverse(explode(',',$baddress));
  1236. $saddress = array_reverse(explode(',',$saddress));
  1237. $bar = '';$sar = '';
  1238. $cr = $this->country->read($post['country']);
  1239. $baddress[1] = $cr['lb'];
  1240. $saddress[1] = $cr['lb'];
  1241. $baddress = array_reverse($baddress);
  1242. $saddress = array_reverse($saddress);
  1243. for($i=0;$i<count($baddress);$i++)
  1244. {
  1245. $bar .= $baddress[$i].',';
  1246. }
  1247. for($i=0;$i<count($saddress);$i++)
  1248. {
  1249. $sar .= $saddress[$i].',';
  1250. }
  1251. $post['baddress'] = rtrim($bar,',');//卖家保障
  1252. $post['saddress'] = rtrim($sar,',');//卖家保障
  1253. $whlabel = $this->input->post('whlabel',true);
  1254. if($post['express'] == 2 && (stripos($post['name'],'&') !== false || stripos($post['name'],"'") !== false))
  1255. {
  1256. echo json_encode(array('msg'=>'USPS收件人或公司名不可用特殊符号!','success'=>false));exit;
  1257. }
  1258. if(strlen($post['client']) > 35 || strlen($post['name']) > 35)//收件人姓名或公司名不允许超过35位
  1259. {
  1260. echo json_encode(array('msg'=>'收件人姓名或公司名不可超过35个字符!','success'=>false));exit;
  1261. }
  1262. if(($post['express'] == '5' || $post['express'] == '24' || $post['express'] == '42' || $post['express'] == '31') && $post['country'] != 192)
  1263. {
  1264. echo json_encode(array('msg'=>'非美国无法选择Fedex、DHL官方-美国!','success'=>false));exit;
  1265. }
  1266. if($post['express'] == '3' && $post['country'] != 192 && $post['country'] != 35)
  1267. {
  1268. echo json_encode(array('msg'=>'非美国和加拿大无法选择UPS!','success'=>false));exit;
  1269. }
  1270. if($post['express'] == '3' && $post['country'] == 35 && $post['zsbjz'] > 20)
  1271. {
  1272. echo json_encode(array('msg'=>'UPS加拿大最高申报不可超过20','success'=>false));exit;
  1273. }
  1274. if($post['express'] == '2' && $post['warehouse'] != 5)
  1275. {
  1276. echo json_encode(array('msg'=>'非美国仓无法选择USPS!','success'=>false));exit;
  1277. }
  1278. if($post['express'] == '99' && $post['bx'] > 0)
  1279. {
  1280. echo json_encode(array('msg'=>'此物流不允许购买保险','success'=>false));exit;
  1281. }
  1282. if($post['express'] == 42 && $post['sbpm'] != 'Human Hair Wigs' && $post['sbpm'] != 'Human Hair Goods')//$post['express'] == 3 ||
  1283. {
  1284. echo json_encode(array('msg'=>'此快递方式必须选择Human Hair Wigs/Human Hair Goods!','success'=>false));exit;
  1285. }
  1286. //
  1287. if($post['country'] != 192 && $post['express'] == 1 && $post['sbpm'] != 'Synthetic Hair Wigs' && $post['sbpm'] != 'Synthetic Hair Goods')//$post['express'] == 3 ||
  1288. {
  1289. echo json_encode(array('msg'=>'非美国选择官方DHL必须选择Synthetic Hair Wigs/Synthetic Hair Goods','success'=>false));exit;
  1290. }
  1291. if($post['pay'] == '22' && ($post['paypal'] == '' || $post['guarantee'] == ''))
  1292. {
  1293. echo json_encode(array('msg'=>'交易号和卖家保障必须填写','success'=>false));exit;
  1294. }
  1295. if($post['pay'] == '23' && $post['paypal'] == '')
  1296. {
  1297. echo json_encode(array('msg'=>'交易号必须填写','success'=>false));exit;
  1298. }
  1299. if(empty($post['paypal'])){
  1300. echo json_encode(array('msg'=>'交易号必须填写','success'=>false));exit;
  1301. }
  1302. $express = $this->express->read($post['express']);
  1303. if($post['zsbjz'] > $express['sbjz'])
  1304. {
  1305. echo json_encode(array('msg'=>'总申报价值不可超出'.$express['sbjz'],'success'=>false));exit;
  1306. }
  1307. if($post['shouldmoney'] > $express['shouldmoney'] && $express['shouldmoney'] != 0)
  1308. {
  1309. echo json_encode(array('msg'=>'订单金额不可超出'.$express['shouldmoney'],'success'=>false));exit;
  1310. }
  1311. if($express['ioss'] == 1 && $post['ioss'] == '')
  1312. {
  1313. echo json_encode(array('msg'=>'此快递方式必须选择IOSS!','success'=>false));exit;
  1314. }
  1315. if(strlen($post['address']) > $express['addresssize'] || strlen($post['address2']) > $express['addresssize'])
  1316. {
  1317. echo json_encode(array('msg'=>'此快递方地址不可超出'.$express['addresssize'].'个字符','success'=>false));exit;
  1318. }
  1319. if(strlen($post['address']) < 5)
  1320. {
  1321. echo json_encode(array('msg'=>'地址不可留空!','success'=>false));exit;
  1322. }
  1323. if($post['express'] == '2' && $post['zzl'] > '16' && $post['js'] == '0')
  1324. {
  1325. echo json_encode(array('msg'=>'重量大于16不可按Ground Advantage提交!','success'=>false));exit;
  1326. }
  1327. if($post['express'] == '2' && isset($post['js']) && $post['js'] == '0'&& $post['qm'] == '1')
  1328. {
  1329. echo json_encode(array('msg'=>'Ground Advantage不可使用签名服务!','success'=>false));exit;
  1330. }
  1331. if(($post['express'] == '3' || $post['express'] == '42' || $post['express'] == '24') && $post['shouldmoney'] < 1)
  1332. {
  1333. echo json_encode(array('msg'=>'零金额订单不可发 UPS/DHL官方-美国/Fedex(杭州)','success'=>false));exit;
  1334. }
  1335. if($post['express'] == '42' && $post['zsbjz'] < 1)
  1336. {
  1337. echo json_encode(array('msg'=>'零申报金额不可发 DHL官方-美国','success'=>false));exit;
  1338. }
  1339. if($post['express'] == '6' && $post['province'] == '')
  1340. {
  1341. echo json_encode(array('msg'=>'选择DPEX必须填写州信息','success'=>false));exit;
  1342. }
  1343. //仅独立站 地址美国对电话 10或者11位进行判断
  1344. if($post['country'] == 192){
  1345. if((strlen($post['phone'])!= 10) && (strlen($post['phone'])!= 11)){
  1346. echo json_encode(array('msg'=>'美国电话号码应为10/11位!','success'=>false));exit;
  1347. }
  1348. }
  1349. //减少代码复用吧
  1350. $lo_ret = $this->logic_order->checkEditCustomer($post);
  1351. if($lo_ret['code'] != 1){
  1352. echo json_encode(array('msg'=>$lo_ret['msg'],'success'=>false));exit;
  1353. }
  1354. /**
  1355. $post['saddress']
  1356. if($post['printtype'] == 1)//如果是运单
  1357. {
  1358. $post['productdescription'] = $this->input->post('productdescription',true);
  1359. $post['customs'] = $this->input->post('customs',true);
  1360. }
  1361. **/
  1362. //开始注释 xyxg
  1363. /**
  1364. $warehousenew = $this->warehouse->read($post['type']);
  1365. $ft = array();
  1366. $ftdata = explode('|',rtrim($fpcount,'|'));
  1367. foreach ($ftdata as $va)
  1368. {
  1369. $ftitle = '';
  1370. $va = explode('-',trim($va,'-'));
  1371. foreach ($va as $v)
  1372. {
  1373. $v = $this->typeclass->read($v);
  1374. $ftitle .= $v['title'].' ';
  1375. }
  1376. $ft[] = rtrim($ftitle,' ');
  1377. }
  1378. $kcyz = $this->whlabel->get_kc($post['state'],$post['state'],$warehousenew['zd'],$warehousenew['ys'],$post['type'],$whlabel,$fpcount,$ft,$post['number'],$shop);//新添加订单老状态state和新状态state一样,不用走删除占用步奏
  1379. if($kcyz['t'] > '0')
  1380. {
  1381. echo $kcyz['m'];exit;
  1382. }
  1383. else
  1384. {
  1385. if($this->fullorder->insert($post))
  1386. {
  1387. $cusnum = $this->customer->read($customerid);
  1388. $this->customer->save(array('num'=>$cusnum['num']+1,'time'=>$post['buytime']),$customerid);
  1389. echo json_encode(array('msg'=>'下单成功','success'=>true));exit;
  1390. }
  1391. else
  1392. {
  1393. echo json_encode(array('msg'=>'下单失败,请重试','success'=>false));exit;
  1394. }
  1395. }
  1396. //结束注释
  1397. **/
  1398. $dtctitle = array();
  1399. $dictionaries = $this->typeclass->find_all();
  1400. foreach ($dictionaries as $v)
  1401. {
  1402. $dtctitle[$v['id']] = array($v['title'],$v['bqsku']);
  1403. }
  1404. $fpdata = $post['fpdata'];
  1405. if(stripos($fpdata,'-128-') !== false || stripos($fpdata,'-127-') !== false)
  1406. {
  1407. $dfp = explode(';',trim($fpdata,';'));
  1408. $fdata = '';
  1409. foreach ($dfp as $k=>$v)
  1410. {
  1411. $ptitleb = '';
  1412. $fp = explode('|',trim($v,'|'));
  1413. $fp0 = explode(',',$fp[0]);
  1414. if(isset($fp0[1]))
  1415. {
  1416. $fp1 = explode('-',trim($fp0[1],'-'));
  1417. }
  1418. else
  1419. {
  1420. $fp1 = explode('-',trim($fp[0],'-'));
  1421. }
  1422. foreach ($fp1 as $vv)
  1423. {
  1424. $ptitleb .= isset($dtctitle[$vv])?$dtctitle[$vv][0].' ':'';
  1425. }
  1426. if(isset($fp0[1]))
  1427. {
  1428. $ptitleb .= $dtctitle[$fp0[0]][1].'inch ';
  1429. $fp[1] = $ptitleb;
  1430. }
  1431. $fdata .= implode("|",$fp).";";
  1432. }
  1433. $fpdata = $fdata;
  1434. }
  1435. $warehouse = $this->warehouse->read($post['type']);
  1436. if($warehouse['bdcountry'] != 0 && $post['country'] != $warehouse['bdcountry'])
  1437. {
  1438. echo json_encode(array('msg'=>'当前国家无法选择'.$warehouse['title'].'!','success'=>false));exit;
  1439. }
  1440. $kcyz = $this->ck->get_kc($post['state'],$warehouse,$post['shop'],$post['number'],$whlabel,$fpdata);
  1441. if($kcyz['t'] > '0')
  1442. {
  1443. echo $kcyz['m'];exit;
  1444. }
  1445. else if($kcyz['fpdata'] != '')
  1446. {
  1447. $post['whlabel'] = $kcyz['whlabel'];
  1448. $post['fpdata'] = $kcyz['fpdata'];
  1449. }
  1450. $fl = $this->ck->get_fl($warehouse['hz'],$whlabel,$fpdata);
  1451. $post['sfxh'] = $fl['sfxh'];
  1452. $post['ckfl'] = $fl['ckfl'];
  1453. //查询净重开始
  1454. $post['jweight'] = $this->weight->get_weightcx($post['fpdata']);
  1455. //查询净重结束
  1456. $cusnum = $this->customer->read($customerid);
  1457. $this->customer->save(array('num'=>$cusnum['num']+1,'time'=>$post['buytime']),$customerid);
  1458. unset($post['id']);
  1459. $this->fullorder->insert($post);
  1460. echo json_encode(array('msg'=>'下单成功','success'=>true));exit;
  1461. }
  1462. $arg_array = $arg_array[0];//用户ID
  1463. $customer = $this->customer->read($arg_array);//用户信息
  1464. $this->data['customer'] = $customer;
  1465. $country = $this->country->find_all('1=1','id,name','name asc');//国家
  1466. $this->data['country'] = $country;
  1467. $express = $this->express->find_all();//物流商
  1468. $this->data['express'] = $express;
  1469. $bm = $this->country->read($customer['country']);
  1470. $this->data['bm'] = $bm;
  1471. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  1472. $this->data['wlshop'] = $wlshop;
  1473. $this->data['user'] = $u['userid'];
  1474. $this->_Template('customer_mdedit',$this->data);
  1475. }
  1476. /**
  1477. * _mdeditv1 - 修复版线下单添加方法
  1478. * 解决: PHP Notice/Warning 污染 JSON 响应导致前端解析失败显示"超时"的问题
  1479. * 改进: ob_start 输出缓冲 + 防御性检查 + 安全预算计算 + insert 返回值检查
  1480. */
  1481. public function _mdedit($arg_array)
  1482. {
  1483. // 开启输出缓冲,捕获任何意外的 PHP 输出(Notice/Warning/Error)
  1484. ob_start();
  1485. $user = $this->user->get_api($_SESSION['api']);
  1486. if($user)
  1487. {
  1488. $uu = $user;
  1489. $fgshop = "";$sid = "";
  1490. $u = $user;
  1491. $user = explode('|',trim($user['shop'],'|'));
  1492. foreach ($user as $value)
  1493. {
  1494. $fgshop .= " shop = ".$value." or";
  1495. $sid .= " id = ".$value." or";
  1496. }
  1497. }
  1498. $post = $this->input->post(NULL, TRUE);
  1499. if(isset($post['shop']))
  1500. {
  1501. $fpcount = $this->input->post('fpcount',true);
  1502. if(!$fpcount)
  1503. {
  1504. ob_clean();
  1505. echo json_encode(array('msg'=>'需要先清理浏览器缓存,刷新当前页面后再试!','success'=>false));exit;
  1506. }
  1507. $customerid = $this->input->post('customerid',true);
  1508. $shop = $this->input->post('shop',true);
  1509. $sp = $this->shop->read($shop);
  1510. // 防御性检查:店铺信息读取失败
  1511. if(!$sp || !isset($sp['id']))
  1512. {
  1513. ob_clean();
  1514. echo json_encode(array('msg'=>'店铺信息不存在,请检查店铺选择!','success'=>false));exit;
  1515. }
  1516. $num = $this->fullorder->find_count('shop = "'.$sp['id'].'" and gtime = "'.date('Ymd',time()).'"');
  1517. $post['source'] = 1;//订单类型:1.线下订单2.PC3.手机
  1518. $post['state'] = 207;//订单状态:207等待发货
  1519. $post['review'] = 2;//审核状态:1.未送审2.待审核3.不通过4取消重审5.审核通过6.自动通过
  1520. $post['print'] = 1;//打印状态:1.不可打印2.未打印3.已打印
  1521. $post['library'] = 1;//出库状态:1.未出库2.已出库3.已退库
  1522. $post['libraryconfirm'] = 1;//出库确认:1.不允许2.允许
  1523. $post['link'] = isset($sp['link']) ? $sp['link'] : '';
  1524. $post['issku'] = isset($sp['sku']) ? $sp['sku'] : '';
  1525. if($post['print'] != 3)
  1526. {
  1527. $post['librarynot'] = "订单未打印,未审核或未通过";//不能出库原因
  1528. }
  1529. $orderinfo = $this->input->post('orderinfo',true);
  1530. $post['shop'] = $sp['id'];
  1531. $post['user'] = isset($sp['shopuser']) ? $sp['shopuser'] : '';
  1532. $post['number'] = (isset($sp['shortname']) ? $sp['shortname'] : '').'-'.date('ymd',time()).'-'.(substr(strval($num+1+1000),1,3));//编号
  1533. if($orderinfo != "")
  1534. {
  1535. $ordefin = $this->fullorder->get_orderinfo($orderinfo);
  1536. if($ordefin)
  1537. {
  1538. ob_clean();
  1539. echo json_encode(array('msg'=>'订单号重复!','success'=>false));exit;
  1540. }
  1541. else
  1542. {
  1543. $post['orderinfo'] = $orderinfo;
  1544. }
  1545. }
  1546. else
  1547. {
  1548. $post['orderinfo'] = (isset($sp['id']) ? $sp['id'] : '').date('ymdHis',time()).rand(0,1);//订单号
  1549. }
  1550. if($post['paypal'] != '')
  1551. {
  1552. $pp = $this->fullorder->get_paypal($post['paypal']);
  1553. if($pp)
  1554. {
  1555. ob_clean();
  1556. echo json_encode(array('msg'=>'此交易号的订单已存在!','success'=>false));exit;
  1557. }
  1558. }
  1559. $post['client'] = $this->input->post('client',true);//客户名称
  1560. $btime = $this->input->post('buytime',true);//付款时间
  1561. $post['buytime'] = strtotime($btime);//时间转UX
  1562. $post['dtime'] = time();//订单时间
  1563. $post['gtime'] = date('Ymd',time());//格式化时间
  1564. $post['pay'] = $this->input->post('pay',true);//支付方式
  1565. $post['capital'] = $this->input->post('capital',true);//资金状态
  1566. $post['type'] = $this->input->post('warehouse',true);//发货仓库
  1567. $post['currency'] = $this->input->post('currency',true);//币种
  1568. $currency = $this->typeclass->read($post['currency']);
  1569. // 防御性检查:币种信息读取失败
  1570. if(!$currency || !isset($currency['title']))
  1571. {
  1572. ob_clean();
  1573. echo json_encode(array('msg'=>'币种信息不存在,请检查币种选择!','success'=>false));exit;
  1574. }
  1575. $post['currencytitle'] = $currency['title'];//币种名称
  1576. $post['freight'] = $this->input->post('freight',true);//运费
  1577. $post['expressmoney'] = $this->input->post('expressmoney',true);//物流金额
  1578. $post['shouldmoney'] = $this->input->post('shouldmoney',true);//应收金额
  1579. $post['skje'] = $post['shouldmoney'];//收款金额
  1580. $product = $this->input->post('product');//产品名称
  1581. $product = str_replace(array('%26','%2B'),array('&','+'),$product);
  1582. $post['product'] = preg_replace('/( | | |\s)/',' ',$product);
  1583. $orderremarks = $this->input->post('orderremarks');//订单备注
  1584. $orderremarks = str_replace(array('%26','%2B'),array('&','+'),$orderremarks);
  1585. $post['orderremarks'] = preg_replace('/( | | |\s)/',' ',$orderremarks);
  1586. $shipremarks = $this->input->post('shipremarks');//仓库品名
  1587. $shipremarks = str_replace(array('%26','%2B'),array('&','+'),$shipremarks);//仓库品名
  1588. $post['shipremarks'] = preg_replace('/( | | |\s)/',' ',$shipremarks);
  1589. $post['email'] = $this->input->post('email',true);//邮箱
  1590. $name = $this->input->post('name',true);//名称
  1591. $post['name'] = preg_replace('/( | | |\s)/',' ',$name);
  1592. $post['phone'] = $this->input->post('phone',true);//电话
  1593. $post['phone'] = preg_replace('/\D/s','',$post['phone']);
  1594. $post['country'] = $this->input->post('country',true);//国家
  1595. $ct = $this->country->read($post['country']);//国家
  1596. // 防御性检查:国家信息读取失败
  1597. if(!$ct || !isset($ct['lb']))
  1598. {
  1599. ob_clean();
  1600. echo json_encode(array('msg'=>'国家信息不存在,请检查国家选择!','success'=>false));exit;
  1601. }
  1602. $post['al'] = $ct['lb'];//国家二字码
  1603. $post['province'] = $this->input->post('province',true);//省、州
  1604. $post['province'] = preg_replace("/^[\s\v".chr(227).chr(128)."]+/","", $post['province']); //替换开头空字符
  1605. $post['province'] = preg_replace("/[\s\v".chr(227).chr(128)."]+$/","", $post['province']); //替换结尾空字符
  1606. $post['city'] = $this->input->post('city',true);//城市
  1607. $post['city'] = preg_replace("/^[\s\v".chr(227).chr(128)."]+/","", $post['city']); //替换开头空字符
  1608. $post['city'] = preg_replace("/[\s\v".chr(227).chr(128)."]+$/","", $post['city']); //替换结尾空字符
  1609. $post['zipcode'] = $this->input->post('zipcode',true);//邮编
  1610. $post['zipcode'] = preg_replace("/^[\s\v".chr(227).chr(128)."]+/","", $post['zipcode']); //替换开头空字符
  1611. $post['zipcode'] = preg_replace("/[\s\v".chr(227).chr(128)."]+$/","", $post['zipcode']); //替换结尾空字符
  1612. $post['address'] = $this->input->post('address',true);//地址
  1613. $post['printtype'] = $this->input->post('printtype',true);//打印类型
  1614. $fpdata = $this->input->post('fpdata');//购买产品内容
  1615. $fpdata = str_replace(array('%26','%2B'),array('&','+'),$fpdata);
  1616. $post['fpdata'] = $fpdata;
  1617. $post['sbpm'] = $this->input->post('sbpm',true);//申报品名
  1618. $post['zwpm'] = $this->input->post('zwpm',true);//中文品名
  1619. $post['ts'] = $this->input->post('ts',true);//条数
  1620. $post['dtsbjz'] = $this->input->post('dtsbjz',true);//单条申报价
  1621. $post['zsbjz'] = $this->input->post('zsbjz',true);//总申报价
  1622. $post['zzl'] = $this->input->post('zzl',true);//总重量
  1623. $post['zjs'] = $this->input->post('zjs',true);//总件数
  1624. $post['express'] = $this->input->post('express',true);//快递公司
  1625. $post['printtype'] = $this->input->post('printtype',true);//打印类型
  1626. $post['quantity'] = $this->input->post('quantity',true);//数量
  1627. $post['paypal'] = $this->input->post('paypal',true);//支付号
  1628. $post['guarantee'] = $this->input->post('guarantee',true);//卖家保障
  1629. $post['msg'] = $this->input->post('msg',true);//发送留言类型
  1630. $post['ioss'] = $this->input->post('ioss',true);
  1631. $post['sbpm'] = $this->input->post('sbpm',true);
  1632. $pay = $this->pay->get_typeclass($post['pay']);
  1633. $yga = $post['shouldmoney'];
  1634. $post['budget'] = 0;
  1635. // 使用安全方法替代 eval(),避免公式字符串异常导致 Parse Error 污染 JSON
  1636. if($pay)
  1637. {
  1638. $ygc = isset($pay['estimaterate']) ? $pay['estimaterate'] : '';
  1639. $ifbudget = $this->_safeCalcBudget($yga, $ygc);
  1640. $post['estimaterate'] = isset($pay['estimaterate']) ? $pay['estimaterate'] : '';
  1641. if($ifbudget > 0)
  1642. {
  1643. $post['budget'] = $ifbudget;//预估到帐金额
  1644. }
  1645. }
  1646. else
  1647. {
  1648. $ygb = isset($sp['estimaterate']) ? $sp['estimaterate'] : '';//店铺默认到账公式
  1649. $ifbudget = $this->_safeCalcBudget($yga, $ygb);
  1650. $post['estimaterate'] = isset($sp['estimaterate']) ? $sp['estimaterate'] : '';
  1651. if($ifbudget > 0)
  1652. {
  1653. $post['budget'] = $ifbudget;//预估到帐金额
  1654. }
  1655. }
  1656. $baddress = $this->input->post('baddress',true);
  1657. $saddress = $this->input->post('saddress',true);
  1658. $baddress = array_reverse(explode(',',$baddress));
  1659. $saddress = array_reverse(explode(',',$saddress));
  1660. $bar = '';$sar = '';
  1661. $cr = $this->country->read($post['country']);
  1662. if($cr && isset($cr['lb']))
  1663. {
  1664. $baddress[1] = $cr['lb'];
  1665. $saddress[1] = $cr['lb'];
  1666. }
  1667. $baddress = array_reverse($baddress);
  1668. $saddress = array_reverse($saddress);
  1669. for($i=0;$i<count($baddress);$i++)
  1670. {
  1671. $bar .= $baddress[$i].',';
  1672. }
  1673. for($i=0;$i<count($saddress);$i++)
  1674. {
  1675. $sar .= $saddress[$i].',';
  1676. }
  1677. $post['baddress'] = rtrim($bar,',');//卖家保障
  1678. $post['saddress'] = rtrim($sar,',');//卖家保障
  1679. $whlabel = $this->input->post('whlabel',true);
  1680. if($post['express'] == 2 && (stripos($post['name'],'&') !== false || stripos($post['name'],"'") !== false))
  1681. {
  1682. ob_clean();
  1683. echo json_encode(array('msg'=>'USPS收件人或公司名不可用特殊符号!','success'=>false));exit;
  1684. }
  1685. if(strlen($post['client']) > 35 || strlen($post['name']) > 35)//收件人姓名或公司名不允许超过35位
  1686. {
  1687. ob_clean();
  1688. echo json_encode(array('msg'=>'收件人姓名或公司名不可超过35个字符!','success'=>false));exit;
  1689. }
  1690. if(($post['express'] == '5' || $post['express'] == '24' || $post['express'] == '42' || $post['express'] == '31') && $post['country'] != 192)
  1691. {
  1692. ob_clean();
  1693. echo json_encode(array('msg'=>'非美国无法选择Fedex、DHL官方-美国!','success'=>false));exit;
  1694. }
  1695. if($post['express'] == '3' && $post['country'] != 192 && $post['country'] != 35)
  1696. {
  1697. ob_clean();
  1698. echo json_encode(array('msg'=>'非美国和加拿大无法选择UPS!','success'=>false));exit;
  1699. }
  1700. if($post['express'] == '3' && $post['country'] == 35 && $post['zsbjz'] > 20)
  1701. {
  1702. ob_clean();
  1703. echo json_encode(array('msg'=>'UPS加拿大最高申报不可超过20','success'=>false));exit;
  1704. }
  1705. if($post['express'] == '2' && $post['warehouse'] != 5)
  1706. {
  1707. ob_clean();
  1708. echo json_encode(array('msg'=>'非美国仓无法选择USPS!','success'=>false));exit;
  1709. }
  1710. if($post['express'] == '99' && isset($post['bx']) && $post['bx'] > 0)
  1711. {
  1712. ob_clean();
  1713. echo json_encode(array('msg'=>'此物流不允许购买保险','success'=>false));exit;
  1714. }
  1715. if($post['express'] == 42 && $post['sbpm'] != 'Human Hair Wigs' && $post['sbpm'] != 'Human Hair Goods')
  1716. {
  1717. ob_clean();
  1718. echo json_encode(array('msg'=>'此快递方式必须选择Human Hair Wigs/Human Hair Goods!','success'=>false));exit;
  1719. }
  1720. if($post['country'] != 192 && $post['express'] == 1 && $post['sbpm'] != 'Synthetic Hair Wigs' && $post['sbpm'] != 'Synthetic Hair Goods')
  1721. {
  1722. ob_clean();
  1723. echo json_encode(array('msg'=>'非美国选择官方DHL必须选择Synthetic Hair Wigs/Synthetic Hair Goods','success'=>false));exit;
  1724. }
  1725. if($post['pay'] == '22' && ($post['paypal'] == '' || $post['guarantee'] == ''))
  1726. {
  1727. ob_clean();
  1728. echo json_encode(array('msg'=>'交易号和卖家保障必须填写','success'=>false));exit;
  1729. }
  1730. if($post['pay'] == '23' && $post['paypal'] == '')
  1731. {
  1732. ob_clean();
  1733. echo json_encode(array('msg'=>'交易号必须填写','success'=>false));exit;
  1734. }
  1735. if(empty($post['paypal'])){
  1736. ob_clean();
  1737. echo json_encode(array('msg'=>'交易号必须填写','success'=>false));exit;
  1738. }
  1739. $express = $this->express->read($post['express']);
  1740. // 防御性检查:快递公司信息读取失败
  1741. if(!$express)
  1742. {
  1743. ob_clean();
  1744. echo json_encode(array('msg'=>'快递公司信息不存在,请重新选择!','success'=>false));exit;
  1745. }
  1746. if($post['zsbjz'] > $express['sbjz'])
  1747. {
  1748. ob_clean();
  1749. echo json_encode(array('msg'=>'总申报价值不可超出'.$express['sbjz'],'success'=>false));exit;
  1750. }
  1751. if($post['shouldmoney'] > $express['shouldmoney'] && $express['shouldmoney'] != 0)
  1752. {
  1753. ob_clean();
  1754. echo json_encode(array('msg'=>'订单金额不可超出'.$express['shouldmoney'],'success'=>false));exit;
  1755. }
  1756. if($express['ioss'] == 1 && $post['ioss'] == '')
  1757. {
  1758. ob_clean();
  1759. echo json_encode(array('msg'=>'此快递方式必须选择IOSS!','success'=>false));exit;
  1760. }
  1761. if(strlen($post['address']) > $express['addresssize'] || (isset($post['address2']) && strlen($post['address2']) > $express['addresssize']))
  1762. {
  1763. ob_clean();
  1764. echo json_encode(array('msg'=>'此快递方地址不可超出'.$express['addresssize'].'个字符','success'=>false));exit;
  1765. }
  1766. if(strlen($post['address']) < 5)
  1767. {
  1768. ob_clean();
  1769. echo json_encode(array('msg'=>'地址不可留空!','success'=>false));exit;
  1770. }
  1771. if($post['express'] == '2' && $post['zzl'] > '16' && isset($post['js']) && $post['js'] == '0')
  1772. {
  1773. ob_clean();
  1774. echo json_encode(array('msg'=>'重量大于16不可按Ground Advantage提交!','success'=>false));exit;
  1775. }
  1776. if($post['express'] == '2' && isset($post['js']) && $post['js'] == '0' && isset($post['qm']) && $post['qm'] == '1')
  1777. {
  1778. ob_clean();
  1779. echo json_encode(array('msg'=>'Ground Advantage不可使用签名服务!','success'=>false));exit;
  1780. }
  1781. if(($post['express'] == '3' || $post['express'] == '42' || $post['express'] == '24') && $post['shouldmoney'] < 1)
  1782. {
  1783. ob_clean();
  1784. echo json_encode(array('msg'=>'零金额订单不可发 UPS/DHL官方-美国/Fedex(杭州)','success'=>false));exit;
  1785. }
  1786. if($post['express'] == '42' && $post['zsbjz'] < 1)
  1787. {
  1788. ob_clean();
  1789. echo json_encode(array('msg'=>'零申报金额不可发 DHL官方-美国','success'=>false));exit;
  1790. }
  1791. if($post['express'] == '6' && $post['province'] == '')
  1792. {
  1793. ob_clean();
  1794. echo json_encode(array('msg'=>'选择DPEX必须填写州信息','success'=>false));exit;
  1795. }
  1796. //仅独立站 地址美国对电话 10或者11位进行判断
  1797. if($post['country'] == 192){
  1798. if((strlen($post['phone'])!= 10) && (strlen($post['phone'])!= 11)){
  1799. ob_clean();
  1800. echo json_encode(array('msg'=>'美国电话号码应为10/11位!','success'=>false));exit;
  1801. }
  1802. }
  1803. //减少代码复用吧
  1804. $lo_ret = $this->logic_order->checkEditCustomer($post);
  1805. if($lo_ret['code'] != 1){
  1806. ob_clean();
  1807. echo json_encode(array('msg'=>$lo_ret['msg'],'success'=>false));exit;
  1808. }
  1809. $dtctitle = array();
  1810. $dictionaries = $this->typeclass->find_all();
  1811. foreach ($dictionaries as $v)
  1812. {
  1813. $dtctitle[$v['id']] = array($v['title'],$v['bqsku']);
  1814. }
  1815. $fpdata = $post['fpdata'];
  1816. if(stripos($fpdata,'-128-') !== false || stripos($fpdata,'-127-') !== false)
  1817. {
  1818. $dfp = explode(';',trim($fpdata,';'));
  1819. $fdata = '';
  1820. foreach ($dfp as $k=>$v)
  1821. {
  1822. $ptitleb = '';
  1823. $fp = explode('|',trim($v,'|'));
  1824. $fp0 = explode(',',$fp[0]);
  1825. if(isset($fp0[1]))
  1826. {
  1827. $fp1 = explode('-',trim($fp0[1],'-'));
  1828. }
  1829. else
  1830. {
  1831. $fp1 = explode('-',trim($fp[0],'-'));
  1832. }
  1833. foreach ($fp1 as $vv)
  1834. {
  1835. $ptitleb .= isset($dtctitle[$vv])?$dtctitle[$vv][0].' ':'';
  1836. }
  1837. if(isset($fp0[1]))
  1838. {
  1839. $ptitleb .= $dtctitle[$fp0[0]][1].'inch ';
  1840. $fp[1] = $ptitleb;
  1841. }
  1842. $fdata .= implode("|",$fp).";";
  1843. }
  1844. $fpdata = $fdata;
  1845. }
  1846. $warehouse = $this->warehouse->read($post['type']);
  1847. // 防御性检查:仓库信息读取失败
  1848. if(!$warehouse)
  1849. {
  1850. ob_clean();
  1851. echo json_encode(array('msg'=>'仓库信息不存在,请重新选择!','success'=>false));exit;
  1852. }
  1853. if($warehouse['bdcountry'] != 0 && $post['country'] != $warehouse['bdcountry'])
  1854. {
  1855. ob_clean();
  1856. echo json_encode(array('msg'=>'当前国家无法选择'.$warehouse['title'].'!','success'=>false));exit;
  1857. }
  1858. $kcyz = $this->ck->get_kc($post['state'],$warehouse,$post['shop'],$post['number'],$whlabel,$fpdata);
  1859. if($kcyz['t'] > '0')
  1860. {
  1861. // get_kc 内部已经输出 JSON,直接退出
  1862. ob_end_flush();
  1863. echo $kcyz['m'];exit;
  1864. }
  1865. else if($kcyz['fpdata'] != '')
  1866. {
  1867. $post['whlabel'] = $kcyz['whlabel'];
  1868. $post['fpdata'] = $kcyz['fpdata'];
  1869. }
  1870. $fl = $this->ck->get_fl($warehouse['hz'],$whlabel,$fpdata);
  1871. $post['sfxh'] = isset($fl['sfxh']) ? $fl['sfxh'] : '';
  1872. $post['ckfl'] = isset($fl['ckfl']) ? $fl['ckfl'] : '';
  1873. //查询净重开始
  1874. $post['jweight'] = $this->weight->get_weightcx($post['fpdata']);
  1875. //查询净重结束
  1876. $cusnum = $this->customer->read($customerid);
  1877. if($cusnum)
  1878. {
  1879. $this->customer->save(array('num'=>$cusnum['num']+1,'time'=>$post['buytime']),$customerid);
  1880. }
  1881. unset($post['id']);
  1882. // insert 操作并检查返回值
  1883. $insertResult = $this->fullorder->insert($post);
  1884. if(!$insertResult)
  1885. {
  1886. // 数据库写入失败,清理缓冲后返回明确错误
  1887. $dbError = $this->db->error();
  1888. ob_clean();
  1889. echo json_encode(array('msg'=>'下单失败,数据库写入错误,请重试!','success'=>false));exit;
  1890. }
  1891. // 成功:清理缓冲,确保只输出纯净 JSON
  1892. ob_end_clean();
  1893. echo json_encode(array('msg'=>'下单成功','success'=>true));exit;
  1894. }
  1895. // ========== 以下为模板渲染(非 POST 请求) ==========
  1896. $arg_array = $arg_array[0];//用户ID
  1897. $customer = $this->customer->read($arg_array);//用户信息
  1898. $this->data['customer'] = $customer;
  1899. $country = $this->country->find_all('1=1','id,name','name asc');//国家
  1900. $this->data['country'] = $country;
  1901. $express = $this->express->find_all();//物流商
  1902. $this->data['express'] = $express;
  1903. $bm = $this->country->read($customer['country']);
  1904. $this->data['bm'] = $bm;
  1905. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  1906. $this->data['wlshop'] = $wlshop;
  1907. $this->data['user'] = $u['userid'];
  1908. // 恢复输出缓冲,正常渲染模板
  1909. ob_end_flush();
  1910. $this->_Template('customer_mdedit',$this->data);
  1911. }
  1912. /**
  1913. * 安全预算计算 - 替代危险的 eval()
  1914. * 只允许数字、小数点、加减乘除、括号,防止非法公式导致 Parse Error
  1915. */
  1916. private function _safeCalcBudget($amount, $formula)
  1917. {
  1918. if (empty($formula) || !is_numeric($amount)) {
  1919. return 0;
  1920. }
  1921. $formula = trim($formula);
  1922. // 只允许安全的数学表达式字符
  1923. if (!preg_match('/^[0-9\.\+\-\*\/\(\)]+$/', $formula)) {
  1924. return 0;
  1925. }
  1926. $expression = "return {$amount}*1.{$formula};";
  1927. $result = @eval($expression);
  1928. return ($result !== false) ? $result : 0;
  1929. }
  1930. //上传excel
  1931. public function _excela()
  1932. {
  1933. $dir = '/data/excel/'.date('Ymd',time()).'/';
  1934. $config['upload_path'] = '.'.$dir ;
  1935. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  1936. $config['allowed_types'] = 'xls|xlsx';
  1937. $config['max_size'] = 10240;
  1938. $this->load->library('upload', $config);
  1939. $this->upload->initialize($config);
  1940. if ($this->upload->do_upload('userfile'))
  1941. {
  1942. $full_path = $dir.$this->upload->data('file_name');
  1943. $fileName = '.' . $full_path;
  1944. if (!file_exists($fileName))
  1945. {
  1946. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  1947. }
  1948. else
  1949. {
  1950. require_once "./data/excel/PHPExcel/IOFactory.php";
  1951. @$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  1952. @$phpExcel->setActiveSheetIndex(0);// 设置为默认表
  1953. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  1954. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  1955. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  1956. ++$column;//如果列数大于26行
  1957. $list = array();
  1958. for ($i = 2; $i <= $row; $i++) // 行数循环
  1959. {
  1960. $data = array();
  1961. for ($c = 'A'; $c != $column; $c++) // 列数循环
  1962. {
  1963. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  1964. }
  1965. $list[] = $data;
  1966. }
  1967. }
  1968. $i = 0;
  1969. $this->db->trans_begin();
  1970. foreach ($list as $key=>$value)
  1971. {
  1972. $value['1'] = $value['1']?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['1']):'';
  1973. $value['7'] = $value['7']?str_replace('/( | | |\s)/','',$value['7']):'';
  1974. if($value['7'] == "" || $value['11'] == "")
  1975. {
  1976. $i++;
  1977. continue;
  1978. }
  1979. else
  1980. {
  1981. $value['7'] = str_replace('/( | | |\s)/','',$value['7']);
  1982. }
  1983. $shop = $this->shop->get_name($value['9']);
  1984. if(!$shop)
  1985. {
  1986. $i++;
  1987. continue;
  1988. }
  1989. if($value['11'] == 2)
  1990. {
  1991. $repeat = $this->customer->get_address($value['1']);//只判断地址
  1992. }
  1993. else
  1994. {
  1995. $repeat = $this->customer->find_all('email = "'.$value[7].'" and shop = "'.$shop['id'].'"');//只判断邮箱
  1996. }
  1997. /* 判断邮箱和地址
  1998. if($value['1'] == "" || $value['1'] == " ")
  1999. {
  2000. if($value['7'] == "" || $value['7'] == " ")
  2001. {
  2002. $repeat = 1;
  2003. }
  2004. else
  2005. {
  2006. $repeat = $this->customer->get_email($value['7']);
  2007. }
  2008. }
  2009. else
  2010. {
  2011. $repeat = $this->customer->get_address($value['1']);
  2012. }
  2013. */
  2014. if(isset($repeat[0]['type']))
  2015. {
  2016. if($repeat[0]['type'] == $value['11'])
  2017. {
  2018. $i++;
  2019. }
  2020. else if($repeat[0]['type'] != $value['11'])
  2021. {
  2022. $this->customer->save(array('type'=>$value['11']),$repeat[0]['id']);
  2023. }
  2024. }
  2025. else
  2026. {
  2027. $source = $this->typeclass->get_title($value['10']);
  2028. if($source)
  2029. {
  2030. $post['name'] = ($value['0'] && $value['0'] != 'NULL')?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['0']):'';
  2031. $post['email'] = $value['7'];
  2032. if($value['5'] != '')
  2033. {
  2034. $country = $this->country->get_ename(str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['5']));
  2035. $post['country'] = $country['id'];
  2036. }
  2037. $post['level'] = $value['8']?$value['8']:5;
  2038. $post['phone'] = $value['6']?$value['6']:'';
  2039. $post['province'] = $value['3']?$value['3']:'';
  2040. $post['city'] = $value['2']?$value['2']:'';
  2041. $post['address'] = $value['1'];
  2042. $post['zipcode'] = $value['4']?$value['4']:'';
  2043. $post['shop'] = $shop['id'];
  2044. $post['source'] = $source['id'];
  2045. $post['type'] = $value['11'];
  2046. $val12 = $value['12']?$value['12']:'';
  2047. $post['count'] = $val12;
  2048. $str = $post['phone'];
  2049. preg_match_all('/[0-9]/u',$str,$result);
  2050. $numphone = join('',$result[0]);
  2051. $post['numphone'] = $numphone;
  2052. $this->customer->insert($post);
  2053. }
  2054. }
  2055. }
  2056. if ($this->db->trans_status() === FALSE)
  2057. {
  2058. $this->db->trans_commit();
  2059. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  2060. }
  2061. else
  2062. {
  2063. if(count($list) == $i)
  2064. {
  2065. $til = '导入全部失败!请检查导入信息';
  2066. }
  2067. else if(count($list) > $i && $i != 0)
  2068. {
  2069. $til = '部分导入成功!'.$i.'条信息有问题,请排查';
  2070. }
  2071. else if($i < 1)
  2072. {
  2073. $til = '导入成功!';
  2074. }
  2075. $this->db->trans_commit();
  2076. echo json_encode(array('msg'=>$til,'success'=>true));exit;
  2077. }
  2078. }
  2079. else
  2080. {
  2081. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  2082. }
  2083. }
  2084. public function _temuexcel()
  2085. {
  2086. $dir = '/data/excel/'.date('Ymd',time()).'/';
  2087. $config['upload_path'] = '.'.$dir ;
  2088. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  2089. $config['allowed_types'] = 'xls|xlsx';
  2090. $config['max_size'] = 10240;
  2091. $this->load->library('upload', $config);
  2092. $this->upload->initialize($config);
  2093. if ($this->upload->do_upload('userfile'))
  2094. {
  2095. $full_path = $dir.$this->upload->data('file_name');
  2096. $fileName = '.' . $full_path;
  2097. if (!file_exists($fileName))
  2098. {
  2099. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  2100. }
  2101. else
  2102. {
  2103. require_once "./data/excel/PHPExcel/IOFactory.php";
  2104. @$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  2105. @$phpExcel->setActiveSheetIndex(0);// 设置为默认表
  2106. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  2107. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  2108. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  2109. ++$column;//如果列数大于26行
  2110. $list = array();
  2111. for ($i = 2; $i <= $row; $i++) // 行数循环
  2112. {
  2113. $data = array();
  2114. for ($c = 'A'; $c != $column; $c++) // 列数循环
  2115. {
  2116. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  2117. }
  2118. $list[] = $data;
  2119. }
  2120. }
  2121. $i = 0;
  2122. $gethl = $this->hl->get_hl();//获取即时汇率
  2123. $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');
  2124. $dtc = array();
  2125. foreach ($dictionaries as $v)
  2126. {
  2127. if(stripos($v['spare'],'|') !== false)//如果有多个值
  2128. {
  2129. $v['spare'] = explode('|',$v['spare']);
  2130. foreach ($v['spare'] as $k=>$vs)
  2131. {
  2132. if(stripos($v['zh'],'|') !== false)
  2133. {
  2134. $vzh = explode('|',$v['zh']);
  2135. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$vzh[$k],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
  2136. }
  2137. else
  2138. {
  2139. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
  2140. }
  2141. }
  2142. }
  2143. else
  2144. {
  2145. $dtc[strtolower($v['spare'])] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$v['spare']);
  2146. }
  2147. }
  2148. $dk = array();
  2149. $dictionaries2 = $this->typeclass->find_all();
  2150. foreach ($dictionaries2 as $v)
  2151. {
  2152. $dtctitle[$v['id']] = $v['title'];
  2153. $dk[$v['id']] = $v['bqsku'];
  2154. }
  2155. /* 匹配结束 */
  2156. /* 价格加入 */
  2157. $money = array();
  2158. $productdescribe = $this->productdescribe->find_all('1=1');
  2159. foreach ($productdescribe as $v)
  2160. {
  2161. $money[$v['number']] = array();
  2162. }
  2163. /* 价格加入 */
  2164. /* 匹配ID加入 */
  2165. $int = array();
  2166. $intdata = $this->typeclass->find_all('classid=14','id,spare');
  2167. foreach ($intdata as $v)
  2168. {
  2169. $v['spare'] = explode('|',$v['spare']);
  2170. $int[$v['id']] = $v['spare'][0];
  2171. }
  2172. /* 匹配ID加入 */
  2173. $zjsku = array();
  2174. $shopsku = $this->shopsku->find_all();
  2175. foreach ($shopsku as $val)
  2176. {
  2177. $ss = explode(',',trim($val['shop'],','));
  2178. foreach ($ss as $v)
  2179. {
  2180. if(isset($zjsku[$v]))
  2181. {
  2182. $zjsku[$v] .= ','.trim($val['sku'],',');
  2183. }
  2184. else
  2185. {
  2186. $zjsku[$v] = trim($val['sku'],',');
  2187. }
  2188. }
  2189. }
  2190. /* 匹配ID结束 */
  2191. $this->db->trans_begin();
  2192. $error = "";
  2193. foreach ($list as $key=>$value)
  2194. {
  2195. $addtess = ($value['15']!='--'?$value['15'].' ':'').($value['14']!='--'?$value['14'].' ':'').$value['13'];
  2196. $addtess = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$addtess);
  2197. $repeat = $this->customer->find_all('phone = "'.$value[11].'" and address = "'.($value['15']!='--'?$value['15'].' ':'').($value['14']!='--'?$value['14'].' ':'').$value['13'].'" and shop = 19');//判断电话地址
  2198. $sku = $value['8'];
  2199. $je = (isset($value['28']))?$value['28']:0;
  2200. // $value['29'] = str_replace('/','-',$value['29']);
  2201. // $dtime = strtotime($value['29']);
  2202. if(!empty($value['29'])){
  2203. $value['29'] = str_replace('/','-',$value['29']);
  2204. $dtime = strtotime($value['29']);
  2205. if($dtime > time()){
  2206. $dtime = time();
  2207. }
  2208. if(empty($dtime)){
  2209. $dtime = time();
  2210. }
  2211. }else{
  2212. $dtime = time();
  2213. }
  2214. $post['name'] = ($value['10'] && $value['10'] != 'NULL')?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['10']):'';
  2215. $post['email'] = $value['12'];
  2216. $res = $this->logic_order->checkEmail($post['email']);
  2217. if(!$res){
  2218. $error .= "第".($key+2)."行邮箱格式错误;";
  2219. $i++;
  2220. continue;
  2221. }
  2222. if($value['20'] != '')
  2223. {
  2224. $country = $this->country->get_ename(str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['20']));
  2225. $post['country'] = $country['id'];
  2226. }
  2227. $post['level'] = 4;
  2228. $post['phone'] = $value['11']?$value['11']:'';
  2229. $post['province'] = $value['18']?$value['18']:'';
  2230. $post['city'] = $value['17']?$value['17']:'';
  2231. $post['address'] = $addtess;
  2232. $post['zipcode'] = $value['19']?$value['19']:'';
  2233. $post['shop'] = 19;
  2234. $post['source'] = 2;
  2235. $post['type'] = 1;
  2236. $post['count'] = '';
  2237. $post['time'] = $dtime;
  2238. $str = $post['phone'];
  2239. preg_match_all('/[0-9]/u',$str,$result);
  2240. $numphone = join('',$result[0]);
  2241. $post['numphone'] = $numphone;
  2242. if(!isset($repeat[0]))
  2243. {
  2244. $this->customer->insert($post);
  2245. }
  2246. else
  2247. {
  2248. $this->customer->save(array('num'=>$repeat[0]['num']+1),$repeat[0]['id']);
  2249. }
  2250. $sbsku = '';
  2251. $whlabel = $this->whlabel->get_sku($sku);
  2252. if($whlabel)
  2253. {
  2254. $w = explode('-',trim($whlabel['features'],'-'));
  2255. foreach ($w as $v)
  2256. {
  2257. if(isset($dk[$v]))
  2258. {
  2259. $sbsku .= $dk[$v].'-';
  2260. }
  2261. }
  2262. }
  2263. $sbsku = trim($sbsku,'-');
  2264. $time = time();
  2265. $shop = $this->shop->read(19);
  2266. $ddpost['orderremarks'] = isset($value['30'])?$value['30']:'';
  2267. $ddpost['shop'] = $shop['id'];//店铺ID
  2268. $ddpost['user'] = $shop['shopuser'];//店铺负责人
  2269. $orderid = 0;
  2270. $ddpost['orderid'] = 0;
  2271. $ddpost['product'] = '';//产品名称
  2272. $ddpost['link'] = '';//产品链接
  2273. $ddpost['issku'] = $sku;
  2274. $ddpost['quantity'] = rtrim($value['3'],';');
  2275. $ddpost['clientremarks'] = '';//客户备注
  2276. //$ddpost['paypal'] = '';//交易号
  2277. $ddpost['guarantee'] = '';//卖家保障
  2278. $ddpost['parameter'] = '';//属性
  2279. $ddpost['shippingmethod'] = '';//用户选择快递方式及运费金额
  2280. $ddpost['source'] = 2;//订单类型
  2281. $ddpost['type'] = 1;//发货仓库
  2282. $ddpost['capital'] = 3;//资金支付状况,全部付款
  2283. $num = $this->fullorder->find_count('gtime = "'.date('Ymd',$dtime).'" and shop = 19');
  2284. $ddpost['number'] = $shop['shortname'].'-'.date('ymd',$dtime).'-'.(substr(strval($num+1+1000),1,3));//编号
  2285. $ddpost['orderinfo'] = preg_replace('/[^0-9]/', '', $value['0']);//订单号
  2286. $d = $this->fullorder->get_orderinfo($ddpost['orderinfo']);
  2287. if(isset($d['id']))
  2288. {
  2289. $error .= "第".($key+2)."行订单号重复;";
  2290. $i++;
  2291. continue;
  2292. }
  2293. $ddpost['paypal'] = $ddpost['orderinfo'];
  2294. $ddpost['insurance'] = 0;//运输保险费用
  2295. $ddpost['baddress'] = '';
  2296. $ddpost['saddress'] = '';
  2297. $ddpost['country'] = $country['id'];//此国家的ID
  2298. $ddpost['al'] = $country['lb'];//联邦名称
  2299. $ddpost['bname'] = $post['name'];//名称
  2300. $ddpost['sname'] = $post['name'];//名称
  2301. $ddpost['client'] = $post['name'];//公司名称
  2302. $ddpost['name'] = $post['name'];//收件人名称
  2303. $ddpost['phone'] = $post['phone'];//收件人电话
  2304. $ddpost['email'] = $post['email'];//客户邮箱
  2305. $ddpost['zipcode'] = $post['zipcode'];//收件人邮编
  2306. $ddpost['province'] = $post['province'];//收件人省份
  2307. $ddpost['city'] = $post['city'];//收件人城市
  2308. $ddpost['address'] = $post['address'];//收件人地址
  2309. $ddpost['shouldmoney'] = $je;//应收金额
  2310. $ddpost['skje'] = $je;//收款金额
  2311. $ddpost['ismoney'] = '';//支付币种金额
  2312. $ddpost['shouldmoney'] = $je;//金额
  2313. $ddpost['budget'] = $je;//预估到帐金额
  2314. $ddpost['buytime'] = $dtime;//格式化付款时间
  2315. $ddpost['dtime'] = $dtime;//订单时间
  2316. $ddpost['gtime'] = date('Ymd',$dtime);//格式化订单时间
  2317. $ddpost['currencytitle'] = 'USD';//结算币种名称
  2318. $ddpost['currency'] = 219;//钱币ID
  2319. $ddpost['time'] = time();//同步时间
  2320. $ddpost['shopify'] = 0;//同步时间
  2321. $ddpost['hl'] = '6.4';//汇率
  2322. $matching = $this->api->matching($ddpost['quantity'],$sbsku,$dtc,$money,$int,$dtctitle,$shop);
  2323. $ddpost['shipremarks'] = $matching['title'];
  2324. $ddpost['cost'] = $matching['cost'];
  2325. $ddpost['purchase'] = $matching['purchase'];
  2326. $ddpost['fpdata'] = $matching['product'];
  2327. $ddpost['whlabel'] = $matching['whlabel'];
  2328. $ddpost['slpx'] = $matching['wcslpx'];
  2329. $ddpost['state'] = 207;
  2330. $ddpost['type'] = 17;
  2331. $this->fullorder->insert($ddpost);
  2332. }
  2333. if ($this->db->trans_status() === FALSE)
  2334. {
  2335. $this->db->trans_commit();
  2336. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  2337. }
  2338. else
  2339. {
  2340. if(count($list) == $i)
  2341. {
  2342. $til = '导入全部失败!请检查导入信息;'.$error;
  2343. }
  2344. else if(count($list) > $i && $i != 0)
  2345. {
  2346. $til = '部分导入成功!'.$i.'条信息有问题,请排查;'.$error;
  2347. }
  2348. else if($i < 1)
  2349. {
  2350. $til = '导入成功!';
  2351. }
  2352. $this->db->trans_commit();
  2353. echo json_encode(array('msg'=>$til,'success'=>true));exit;
  2354. }
  2355. }
  2356. else
  2357. {
  2358. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  2359. }
  2360. }
  2361. //代发客户导入
  2362. public function _daifakehuexcel()
  2363. {
  2364. $shopid = 0;
  2365. $user = $this->user->get_api($_SESSION['api']);
  2366. if($user)
  2367. {
  2368. $users = explode('|',trim($user['shop'],'|'));
  2369. if(count($users) == 1){
  2370. $shopid = $users[0];
  2371. }else{
  2372. echo json_encode(array('msg'=>"此账号不能用于该功能!",'success'=>true));exit;
  2373. }
  2374. }
  2375. if(empty($shopid)){
  2376. echo json_encode(array('msg'=>"系统无法识别店铺!",'success'=>true));exit;
  2377. }
  2378. $dir = '/data/excel/'.date('Ymd',time()).'/';
  2379. $config['upload_path'] = '.'.$dir ;
  2380. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  2381. $config['allowed_types'] = 'xls|xlsx';
  2382. $config['max_size'] = 10240;
  2383. $this->load->library('upload', $config);
  2384. $this->upload->initialize($config);
  2385. if ($this->upload->do_upload('userfile'))
  2386. {
  2387. $full_path = $dir.$this->upload->data('file_name');
  2388. $fileName = '.' . $full_path;
  2389. if (!file_exists($fileName))
  2390. {
  2391. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  2392. }
  2393. else
  2394. {
  2395. require_once "./data/excel/PHPExcel/IOFactory.php";
  2396. @$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  2397. @$phpExcel->setActiveSheetIndex(0);// 设置为默认表
  2398. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  2399. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  2400. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  2401. ++$column;//如果列数大于26行
  2402. $list = array();
  2403. for ($i = 2; $i <= $row; $i++) // 行数循环
  2404. {
  2405. $data = array();
  2406. for ($c = 'A'; $c != $column; $c++) // 列数循环
  2407. {
  2408. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  2409. }
  2410. $list[] = $data;
  2411. }
  2412. }
  2413. $i = 0;
  2414. $gethl = $this->hl->get_hl();//获取即时汇率
  2415. $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');
  2416. $dtc = array();
  2417. foreach ($dictionaries as $v)
  2418. {
  2419. if(stripos($v['spare'],'|') !== false)//如果有多个值
  2420. {
  2421. $v['spare'] = explode('|',$v['spare']);
  2422. foreach ($v['spare'] as $k=>$vs)
  2423. {
  2424. if(stripos($v['zh'],'|') !== false)
  2425. {
  2426. $vzh = explode('|',$v['zh']);
  2427. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$vzh[$k],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
  2428. }
  2429. else
  2430. {
  2431. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
  2432. }
  2433. }
  2434. }
  2435. else
  2436. {
  2437. $dtc[strtolower($v['spare'])] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$v['spare']);
  2438. }
  2439. }
  2440. $dk = array();
  2441. $dictionaries2 = $this->typeclass->find_all();
  2442. foreach ($dictionaries2 as $v)
  2443. {
  2444. $dtctitle[$v['id']] = $v['title'];
  2445. $dk[$v['id']] = $v['bqsku'];
  2446. }
  2447. /* 匹配结束 */
  2448. /* 价格加入 */
  2449. $money = array();
  2450. $productdescribe = $this->productdescribe->find_all('1=1');
  2451. foreach ($productdescribe as $v)
  2452. {
  2453. $money[$v['number']] = array();
  2454. }
  2455. /* 价格加入 */
  2456. /* 匹配ID加入 */
  2457. $int = array();
  2458. $intdata = $this->typeclass->find_all('classid=14','id,spare');
  2459. foreach ($intdata as $v)
  2460. {
  2461. $v['spare'] = explode('|',$v['spare']);
  2462. $int[$v['id']] = $v['spare'][0];
  2463. }
  2464. /* 匹配ID加入 */
  2465. $zjsku = array();
  2466. $shopsku = $this->shopsku->find_all();
  2467. foreach ($shopsku as $val)
  2468. {
  2469. $ss = explode(',',trim($val['shop'],','));
  2470. foreach ($ss as $v)
  2471. {
  2472. if(isset($zjsku[$v]))
  2473. {
  2474. $zjsku[$v] .= ','.trim($val['sku'],',');
  2475. }
  2476. else
  2477. {
  2478. $zjsku[$v] = trim($val['sku'],',');
  2479. }
  2480. }
  2481. }
  2482. /* 匹配ID结束 */
  2483. $this->db->trans_begin();
  2484. $error = "";
  2485. foreach ($list as $key=>$value)
  2486. {
  2487. if(empty($value[0])){
  2488. continue;
  2489. }
  2490. $addtess = $value[7].$value[6];
  2491. $addtess = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$addtess);
  2492. $repeat = $this->customer->find_all('phone = "'.$value[4].'" and address = "'.$addtess.'" and shop = '.$shopid);//判断电话地址
  2493. $sku = $value['2'];
  2494. $je = (isset($value['12']))?$value['12']:0;
  2495. if(!empty($value[13])){
  2496. $value['13'] = str_replace('/','-',$value['13']);
  2497. $dtime = strtotime($value['13']);
  2498. if(empty($dtime)){
  2499. $dtime = time();
  2500. }
  2501. }else{
  2502. $dtime = time();
  2503. }
  2504. $dtime = $dtime + $key;
  2505. $post['name'] = (!empty($value[3]))?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['3']):'';
  2506. $post['email'] = $value['5'];
  2507. $res = $this->logic_order->checkEmail($post['email']);
  2508. if(!$res){
  2509. $error .= '第'.($key+2).'行邮箱格式错误;';
  2510. $i++;
  2511. continue;
  2512. }
  2513. if($value['11'] != '')
  2514. {
  2515. $country = $this->country->get_ename(str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['11']));
  2516. $post['country'] = $country['id'];
  2517. }
  2518. $post['level'] = 4;
  2519. $post['phone'] = $value['4']?$value['4']:'';
  2520. $post['province'] = $value['9']?$value['9']:'';
  2521. $post['city'] = $value['8']?$value['8']:'';
  2522. $post['address'] = $addtess;
  2523. $post['zipcode'] = $value['10']?$value['10']:'';
  2524. $post['shop'] = $shopid;
  2525. $post['source'] = 10;
  2526. $post['type'] = 1;
  2527. $post['count'] = '';
  2528. $post['time'] = $dtime;
  2529. $str = $post['phone'];
  2530. preg_match_all('/[0-9]/u',$str,$result);
  2531. $numphone = join('',$result[0]);
  2532. $post['numphone'] = $numphone;
  2533. if(!isset($repeat[0]))
  2534. {
  2535. $post['num'] = 1;
  2536. $this->customer->insert($post);
  2537. }
  2538. else
  2539. {
  2540. $this->customer->save(array('num'=>$repeat[0]['num']+1),$repeat[0]['id']);
  2541. }
  2542. $sbsku = '';
  2543. $whlabel = $this->whlabel->get_sku($sku);
  2544. if($whlabel)
  2545. {
  2546. $w = explode('-',trim($whlabel['features'],'-'));
  2547. foreach ($w as $v)
  2548. {
  2549. if(isset($dk[$v]))
  2550. {
  2551. $sbsku .= $dk[$v].'-';
  2552. }
  2553. }
  2554. }
  2555. $sbsku = trim($sbsku,'-');
  2556. $time = time();
  2557. $shop = $this->shop->read($shopid);
  2558. $ddpost['orderremarks'] = '';
  2559. $ddpost['shop'] = $shop['id'];//店铺ID
  2560. $ddpost['user'] = $shop['shopuser'];//店铺负责人
  2561. $orderid = 0;
  2562. $ddpost['orderid'] = 0;
  2563. $ddpost['product'] = '';//产品名称
  2564. $ddpost['link'] = '';//产品链接
  2565. $ddpost['issku'] = $sku;
  2566. $ddpost['quantity'] = rtrim($value['1'],';');
  2567. $ddpost['clientremarks'] = '';//客户备注
  2568. $ddpost['guarantee'] = '';//卖家保障
  2569. $ddpost['parameter'] = '';//属性
  2570. $ddpost['shippingmethod'] = '';//用户选择快递方式及运费金额
  2571. $ddpost['source'] = 2;//订单类型
  2572. $ddpost['type'] = 1;//发货仓库
  2573. $ddpost['capital'] = 3;//资金支付状况,全部付款
  2574. $num = $this->fullorder->find_count('gtime = "'.date('Ymd',$dtime).'" and shop = '.$shopid);
  2575. $ddpost['number'] = $shop['shortname'].'-'.date('ymd',$dtime).'-'.(substr(strval($num+1+1000),1,3));//编号
  2576. $ddpost['orderinfo'] = $value['0'];//订单号
  2577. $d = $this->fullorder->get_orderinfo($ddpost['orderinfo']);
  2578. if(isset($d['id']))
  2579. {
  2580. $error .= '第'.($key+2).'行订单号重复;';
  2581. $i++;
  2582. continue;
  2583. }
  2584. $ddpost['paypal'] = $ddpost['orderinfo'];//交易号
  2585. $ddpost['insurance'] = 0;//运输保险费用
  2586. $ddpost['baddress'] = '';
  2587. $ddpost['saddress'] = '';
  2588. $ddpost['country'] = $country['id'];//此国家的ID
  2589. $ddpost['al'] = $country['lb'];//联邦名称
  2590. $ddpost['bname'] = $post['name'];//名称
  2591. $ddpost['sname'] = $post['name'];//名称
  2592. $ddpost['client'] = $post['name'];//公司名称
  2593. $ddpost['name'] = $post['name'];//收件人名称
  2594. $ddpost['phone'] = $post['phone'];//收件人电话
  2595. $ddpost['email'] = $post['email'];//客户邮箱
  2596. $ddpost['zipcode'] = $post['zipcode'];//收件人邮编
  2597. $ddpost['province'] = $post['province'];//收件人省份
  2598. $ddpost['city'] = $post['city'];//收件人城市
  2599. $ddpost['address'] = $post['address'];//收件人地址
  2600. $ddpost['shouldmoney'] = $je;//应收金额
  2601. $ddpost['skje'] = $je;//收款金额
  2602. $ddpost['ismoney'] = '';//支付币种金额
  2603. $ddpost['shouldmoney'] = $je;//金额
  2604. $ddpost['budget'] = $je;//预估到帐金额
  2605. $ddpost['buytime'] = $dtime;//格式化付款时间
  2606. $ddpost['dtime'] = $dtime;//订单时间
  2607. $ddpost['gtime'] = date('Ymd',$dtime);//格式化订单时间
  2608. $ddpost['currencytitle'] = 'USD';//结算币种名称
  2609. $ddpost['currency'] = 219;//钱币ID
  2610. $ddpost['time'] = time();//同步时间
  2611. $ddpost['shopify'] = 0;//同步时间
  2612. $ddpost['hl'] = '6.4';//汇率
  2613. $matching = $this->api->matching($ddpost['quantity'],$sbsku,$dtc,$money,$int,$dtctitle,$shop);
  2614. $ddpost['shipremarks'] = $matching['title'];
  2615. $ddpost['cost'] = $matching['cost'];
  2616. $ddpost['purchase'] = $matching['purchase'];
  2617. $ddpost['fpdata'] = $matching['product'];
  2618. $ddpost['whlabel'] = $matching['whlabel'];
  2619. $ddpost['slpx'] = $matching['wcslpx'];
  2620. $ddpost['state'] = 207;
  2621. $ddpost['type'] = 13;
  2622. $this->fullorder->insert($ddpost);
  2623. }
  2624. if ($this->db->trans_status() === FALSE)
  2625. {
  2626. $this->db->trans_commit();
  2627. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  2628. }
  2629. else
  2630. {
  2631. if(count($list) == $i)
  2632. {
  2633. $til = '导入全部失败!请检查导入信息;'.$error;
  2634. }
  2635. else if(count($list) > $i && $i != 0)
  2636. {
  2637. $til = '部分导入成功!'.$i.'条信息有问题,请排查;'.$error;
  2638. }
  2639. else if($i < 1)
  2640. {
  2641. $til = '导入成功!';
  2642. }
  2643. $this->db->trans_commit();
  2644. echo json_encode(array('msg'=>$til,'success'=>true));exit;
  2645. }
  2646. }
  2647. else
  2648. {
  2649. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  2650. }
  2651. }
  2652. public function _indexexcel()//通过计数,2020/02/21已校准
  2653. {
  2654. $user = $this->user->get_api($_SESSION['api']);
  2655. if($user)
  2656. {
  2657. $fgshop = "";$sid = "";
  2658. $users = explode('|',trim($user['shop'],'|'));
  2659. foreach ($users as $value)
  2660. {
  2661. $fgshop .= " shop = ".$value." or";
  2662. $sid .= " id = ".$value." or";
  2663. }
  2664. if($user['vip'] == 1)
  2665. {
  2666. $vip = 1;
  2667. }
  2668. else
  2669. {
  2670. $vip = 0;
  2671. }
  2672. }
  2673. else
  2674. {
  2675. $vip = 0;
  2676. }
  2677. $post = $this->input->post(NULL, TRUE);
  2678. if(isset($_GET['timetk']))
  2679. {
  2680. $shop = $this->input->get('shop',true);
  2681. $numphone = $this->input->get('numphone',true);
  2682. $name = $this->input->get('name',true);
  2683. $email = $this->input->get('email',true);
  2684. $address = $this->input->get('address',true);
  2685. $level = $this->input->get('level',true);
  2686. $num = $this->input->get('num',true);
  2687. $country = $this->input->get('country',true);
  2688. $excelid = $this->input->get('sid',true);
  2689. $timetk = $this->input->get('timetk',true);
  2690. $timetj = $this->input->get('timetj',true);
  2691. $timetk = strtotime($timetk);
  2692. $timetj = strtotime($timetj);
  2693. $where = "1=1 and type = 1 and (".rtrim($fgshop,'or').")";
  2694. if($shop)
  2695. {
  2696. $where .= " and shop = '$shop'";
  2697. }
  2698. if($numphone)
  2699. {
  2700. $where .= " and numphone = '$numphone'";
  2701. }
  2702. if($name)
  2703. {
  2704. $where .= " and name like '%$name%'";
  2705. }
  2706. if($email)
  2707. {
  2708. $where .= " and email like '%$email%'";
  2709. }
  2710. if($level)
  2711. {
  2712. $where .= " and level = '$level'";
  2713. }
  2714. if($country)
  2715. {
  2716. $where .= " and country = '$country'";
  2717. }
  2718. if($address)
  2719. {
  2720. $where .= " and address like '%$address%'";
  2721. }
  2722. if($num > 0 && $num < 10 && $num != '2a')
  2723. {
  2724. $where .= " and num = '$num'";
  2725. }
  2726. else if($num > 9)
  2727. {
  2728. $where .= " and num > '9'";
  2729. }
  2730. else if($num == '2a')
  2731. {
  2732. $where .= " and num > '1'";
  2733. }
  2734. else
  2735. {
  2736. $where .= " and num >= '0'";
  2737. }
  2738. if($timetk && $timetj)
  2739. {
  2740. $where .= " and ((time > '$timetk' and time < '$timetj') or time = '0')";
  2741. }
  2742. $xzid = '';
  2743. if($excelid)
  2744. {
  2745. $excelid = explode(',',trim($excelid,','));
  2746. foreach ($excelid as $key=>$value)
  2747. {
  2748. $xzid .= " id = ".$value." or";
  2749. }
  2750. $where .= " and (".rtrim($xzid,'or').")";;
  2751. }
  2752. //数据排序
  2753. $order_str = "id desc";
  2754. $numdata = array();
  2755. if(empty($page))
  2756. {
  2757. $start = 0;
  2758. $perpage = 1;
  2759. }
  2760. else
  2761. {
  2762. $start = ($page - 1)*$perpage;
  2763. }
  2764. //取得信息列表
  2765. $info_list = $this->customer->find_all($where,'shop,name,email,phone,address,city,province,zipcode,country,level,money,num,numphone,time,count',$order_str);
  2766. foreach ($info_list as $key=>$value)
  2767. {
  2768. $shop = $this->shop->read($value['shop']);
  2769. $info_list[$key]['shop'] = $shop['shopname'];
  2770. if($value['country'] != 0)
  2771. {
  2772. $country = $this->country->read($value['country']);
  2773. $info_list[$key]['country'] = $country['name'];
  2774. }
  2775. else
  2776. {
  2777. $info_list[$key]['country'] = "未知";
  2778. }
  2779. if($value['level'] == 1)
  2780. {
  2781. $info_list[$key]['level'] = "网红";
  2782. }
  2783. else if($value['level'] == 2)
  2784. {
  2785. $info_list[$key]['level'] = "批发";
  2786. }
  2787. else if($value['level'] == 3)
  2788. {
  2789. $info_list[$key]['level'] = "店铺转线下";
  2790. }
  2791. else if($value['level'] == 4)
  2792. {
  2793. $info_list[$key]['level'] = "线下其他";
  2794. }
  2795. else if($value['level'] == 5)
  2796. {
  2797. $info_list[$key]['level'] = "店内客户";
  2798. }
  2799. if($value['time'] != 0)
  2800. {
  2801. $info_list[$key]['time'] = date('Y-m-d',$value['time']);
  2802. }
  2803. else
  2804. {
  2805. $info_list[$key]['time'] = "无";
  2806. }
  2807. $info_list[$key]['numphone'] = ($value['num'] > 0 && $value['money'] > 0)?sprintf("%01.2f",$value['money']/$value['num']):0;
  2808. if(isset($value['email']) && $user['excelpass'] == '1')
  2809. {
  2810. $emailpass = $this->setting->get_excelpass($value['email']);
  2811. $info_list[$key]['email'] = $emailpass;
  2812. }
  2813. if(isset($value['phone']) && $user['excelpass'] == '1')
  2814. {
  2815. $phone = $this->setting->get_excelpass($value['phone']);
  2816. $info_list[$key]['phone'] = $phone;
  2817. }
  2818. }
  2819. $title = "按条件导出";
  2820. $titlename = "<table border=1>
  2821. <tr align='center'>
  2822. <td>店铺</td>
  2823. <td>名称</td>
  2824. <td>邮箱</td>
  2825. <td>电话</td>
  2826. <td>详细地址</td>
  2827. <td>城市</td>
  2828. <td>省/州</td>
  2829. <td>邮编</td>
  2830. <td>国家</td>
  2831. <td>类型</td>
  2832. <td>总额</td>
  2833. <td>成交次数</td>
  2834. <td>客单价</td>
  2835. <td>最后购买日期</td>
  2836. <td>备注</td>
  2837. </tr>
  2838. </table>";
  2839. $filename = $title.".xls";
  2840. $tail = "";
  2841. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  2842. }
  2843. }
  2844. //下载excel
  2845. public function _excel()
  2846. {
  2847. if(isset($_GET['excel']))
  2848. {
  2849. if(isset($_SESSION['api']))
  2850. {
  2851. $user = $this->user->get_api($_SESSION['api']);
  2852. $usp = $user;
  2853. $fgshop = "";$sid = "";
  2854. $user = explode('|',trim($user['shop'],'|'));
  2855. foreach ($user as $value)
  2856. {
  2857. $fgshop .= " shop = ".$value." or";
  2858. $sid .= " id = ".$value." or";
  2859. }
  2860. }
  2861. $dowid = $this->input->get('a');
  2862. $wid = "";
  2863. if($dowid != "")
  2864. {
  2865. $id_arr = explode(',',rtrim($dowid,','));
  2866. $wid .= " id = 0 or";
  2867. foreach ($id_arr as $v)
  2868. {
  2869. $wid .= " id = '$v' or";
  2870. }
  2871. $wid = " and".rtrim($wid,'or');
  2872. }
  2873. $excel = $this->input->get('excel',true);
  2874. $page = $this->input->get('page',true);
  2875. $perpage = $this->input->get('perpage',true);
  2876. $shop = $this->input->get('shop',true);
  2877. $name = $this->input->get('name',true);
  2878. $country = $this->input->get('country',true);
  2879. $email = $this->input->get('email',true);
  2880. $address = $this->input->get('address',true);
  2881. $level = $this->input->get('level',true);
  2882. $num = $this->input->get('num',true);
  2883. $timetk = $this->input->get('timetk',true);
  2884. $timetj = $this->input->get('timetj',true);
  2885. $timetk = strtotime($timetk);
  2886. $timetj = strtotime($timetj);
  2887. $where = "1 = 1 and (".rtrim($fgshop,'or').")";
  2888. if($shop)
  2889. {
  2890. $where .= " and shop = '$shop'";
  2891. }
  2892. if($name)
  2893. {
  2894. $where .= " and name like '%$name%'";
  2895. }
  2896. if($email)
  2897. {
  2898. $where .= " and email like '%$email%'";
  2899. }
  2900. if($country)
  2901. {
  2902. $where .= " and country = '$country'";
  2903. }
  2904. if($level)
  2905. {
  2906. $where .= " and level = '$level'";
  2907. }
  2908. if($num != '')
  2909. {
  2910. $nu = 1;
  2911. if($num > 9)
  2912. {
  2913. $where .= " and num > '9'";
  2914. }
  2915. else if($num == '2a')
  2916. {
  2917. $where .= " and num > '1'";
  2918. }
  2919. else
  2920. {
  2921. $where .= " and num = '$num'";
  2922. }
  2923. }
  2924. else
  2925. {
  2926. $nu = 2;
  2927. $where .= " and num >= '0'";
  2928. }
  2929. if($address)
  2930. {
  2931. $where .= " and address like '%$address%'";
  2932. }
  2933. if($timetk && $timetj)
  2934. {
  2935. $where .= " and time > '$timetk' and time < '$timetj'";
  2936. }
  2937. $where .= " and type = 1";//白名单用户
  2938. $info_list = array();
  2939. if($excel == 2) //老客户列表
  2940. {
  2941. //$where = str_replace("level = '$level'","level > '1'",$where);
  2942. $info_list = $this->customer->find_all($where.$wid,'name,email,country,time,num,money,numphone','time desc');
  2943. foreach ($info_list as $key=>$value)
  2944. {
  2945. $info_list[$key]['time'] = date('Y-m-d H:i:s',$value['time']);
  2946. if($value['country'] != 0)
  2947. {
  2948. $country = $this->country->read($value['country']);
  2949. $info_list[$key]['country'] = $country['ename'];
  2950. }
  2951. else
  2952. {
  2953. $info_list[$key]['country'] = '';
  2954. }
  2955. if($value['num'] > 0){
  2956. $info_list[$key]['numphone'] = sprintf("%01.2f",$value['money']/$value['num']);
  2957. }else{
  2958. $info_list[$key]['numphone'] = "<span style='color:red'>num异常".$value['num']."</span>";
  2959. }
  2960. if(isset($value['email']) && $usp['excelpass'] == '1')
  2961. {
  2962. $emailpass = $this->setting->get_excelpass($value['email']);
  2963. $info_list[$key]['email'] = $emailpass;
  2964. }
  2965. }
  2966. /**
  2967. foreach ($info_list as $key=>$value)
  2968. {
  2969. $value['time'] = date('Y-m-d H:i:s',$value['time']);
  2970. $d = $this->fullorder->find_count('email = "'.$value['email'].'" and shop = "'.$value['shop'].'" and mergeid = 0','orderinfo,state,product,name,email,dtime,shouldmoney','time desc');
  2971. if($d > 1)
  2972. {
  2973. $info_list[] = $v;
  2974. }
  2975. }
  2976. **/
  2977. $fzh = "<td>客户名</td><td>客户邮箱</td><td>客户国家</td><td>最近一次下单时间</td><td>购买次数</td><td>购买总金额</td><td>客单价</td>";
  2978. $title = "老客户列表";
  2979. }
  2980. else
  2981. {
  2982. $fdata = $this->customer->find_all($where.$wid,'email,shop','time desc');
  2983. foreach ($fdata as $key=>$value)
  2984. {
  2985. $d = $this->fullorder->find_all('email = "'.$value['email'].'" and shop = "'.$value['shop'].'" and mergeid = 0 and extra_status = 0 ','orderinfo,state,product,shipremarks,name,email,country,dtime,shouldmoney','time desc');
  2986. if($nu == 2)
  2987. {
  2988. if(count($d) > 1)
  2989. {
  2990. foreach ($d as $k=>$v)
  2991. {
  2992. $v['dtime'] = date('Y-m-d H:i:s',$v['dtime']);
  2993. $typeclass = $this->typeclass->read($v['state']);
  2994. $v['state'] = $typeclass['spare'];
  2995. if($v['country'] != 0)
  2996. {
  2997. $country = $this->country->read($v['country']);
  2998. $v['country'] = $country['ename'];
  2999. }
  3000. else
  3001. {
  3002. $v['country'] = '';
  3003. }
  3004. if(isset($v['email']) && $usp['excelpass'] == '1')
  3005. {
  3006. $emailpass = $this->setting->get_excelpass($v['email']);
  3007. $v['email'] = $emailpass;
  3008. }
  3009. $info_list[] = $v;
  3010. }
  3011. }
  3012. }
  3013. else
  3014. {
  3015. foreach ($d as $k=>$v)
  3016. {
  3017. $v['dtime'] = date('Y-m-d H:i:s',$v['dtime']);
  3018. $typeclass = $this->typeclass->read($v['state']);
  3019. $v['state'] = $typeclass['spare'];
  3020. if($v['country'] != 0)
  3021. {
  3022. $country = $this->country->read($v['country']);
  3023. $v['country'] = $country['ename'];
  3024. }
  3025. else
  3026. {
  3027. $v['country'] = '';
  3028. }
  3029. if(isset($v['email']) && $usp['excelpass'] == '1')
  3030. {
  3031. $emailpass = $this->setting->get_excelpass($v['email']);
  3032. $v['email'] = $emailpass;
  3033. }
  3034. $info_list[] = $v;
  3035. }
  3036. }
  3037. }
  3038. $fzh = "<td>订单号</td><td>订单状态</td><td>产品名</td><td>仓库品名</td><td>客户名</td><td>客户邮箱</td><td>客户国家</td><td>下单时间</td><td>订单金额</td>";
  3039. $title = "老客户订单列表";
  3040. }
  3041. $titlename = "<table border=1>
  3042. <tr>"
  3043. .$fzh.
  3044. "</tr>
  3045. </table>";
  3046. $tail = "\n";
  3047. $filename = $title.'-'.date('Ymd',time()).".xls";
  3048. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  3049. }
  3050. }
  3051. //下载excel模板
  3052. public function _bankdown()
  3053. {
  3054. if(isset($_GET['bankdown']))
  3055. {
  3056. $numphone = $this->input->post('numphone',true);
  3057. $xtime = $this->input->get('xtime',true);
  3058. //$where = "1=1 and type = 2 and (".rtrim($fgshop,'or').")";
  3059. $shop = $this->input->get('shop',true);
  3060. $name = $this->input->get('name',true);
  3061. $email = $this->input->get('email',true);
  3062. $address = $this->input->get('address',true);
  3063. $type = $this->input->get('type',true);
  3064. $id = $this->input->get('id',true);
  3065. $timetk = $this->input->get('timetk',true);
  3066. $timetj = $this->input->get('timetj',true);
  3067. $timetk = strtotime($timetk);
  3068. $timetj = strtotime($timetj);
  3069. if($type)
  3070. {
  3071. $where = "type = '$type'";
  3072. }
  3073. else
  3074. {
  3075. $where = "id != 0";
  3076. }
  3077. if($id)
  3078. {
  3079. $id = explode('|',trim($id,'|'));
  3080. $downid = '';
  3081. foreach ($id as $value)
  3082. {
  3083. $downid .= " id = ".$value." or";
  3084. }
  3085. $where .= " and (".rtrim($downid,'or').")";
  3086. }
  3087. if(!$shop)
  3088. {
  3089. $user = $this->user->get_api($_SESSION['api']);
  3090. $usp = $user;
  3091. $fgshop = "";$sid = "";
  3092. $user = explode('|',trim($user['shop'],'|'));
  3093. foreach ($user as $value)
  3094. {
  3095. $fgshop .= " shop = ".$value." or";
  3096. $sid .= " id = ".$value." or";
  3097. }
  3098. $where .= " and (".rtrim($fgshop,'or').")";
  3099. }
  3100. else
  3101. {
  3102. $where .= " and shop = '$shop'";
  3103. }
  3104. if($email)
  3105. {
  3106. $where .= " and email = '$email'";
  3107. }
  3108. if($name)
  3109. {
  3110. $where .= " and name = '$name'";
  3111. }
  3112. if($address)
  3113. {
  3114. $where .= " and address = '$address'";
  3115. }
  3116. if($xtime)
  3117. {
  3118. $where .= " and typetime > '$timetk' and typetime < '$timetj'";
  3119. }
  3120. $info_list = $this->customer->find_all($where,'name,address,city,province,zipcode,country,phone,email,level,shop,source,type,count,typetime');
  3121. foreach ($info_list as $key=>$v)
  3122. {
  3123. $country = $this->country->read($v['country']);
  3124. $info_list[$key]['country'] = $country['ename'];
  3125. if($v['level'] == 1)
  3126. {
  3127. $info_list[$key]['level'] = '网红';
  3128. }
  3129. else if($v['level'] == 2)
  3130. {
  3131. $info_list[$key]['level'] = '批发';
  3132. }
  3133. else if($v['level'] == 3)
  3134. {
  3135. $info_list[$key]['level'] = '店铺转线下';
  3136. }
  3137. else if($v['level'] == 4)
  3138. {
  3139. $info_list[$key]['level'] = '线下其他';
  3140. }
  3141. else if($v['level'] == 5)
  3142. {
  3143. $info_list[$key]['level'] = '店内';
  3144. }
  3145. else
  3146. {
  3147. $info_list[$key]['level'] = '未知';
  3148. }
  3149. if($v['typetime'] != 0)
  3150. {
  3151. $info_list[$key]['typetime'] = date('Y-m-d',$v['typetime']);
  3152. }
  3153. else
  3154. {
  3155. $info_list[$key]['typetime'] = "无";
  3156. }
  3157. $shop = $this->shop->read($v['shop']);
  3158. $info_list[$key]['shop'] = $shop['shopname'];
  3159. $source = $this->typeclass->read($v['source']);
  3160. $info_list[$key]['source'] = $source['title'];
  3161. }
  3162. $titledata = array('姓名','详细地址','城市','省/州','邮编','国家','电话','邮箱','类型(1:网红2:批发3:店铺转线下4:线下其他5:店内)','所属店铺(必须ERP已有店铺)','来源(数据字典的户来源需存在)','黑白名单(白名单填1或黑名单填2)','备注','客户分类时间');
  3163. $fzh = "";
  3164. foreach ($titledata as $v)
  3165. {
  3166. $fzh .= "<td>".$v."</td>";
  3167. }
  3168. $title = "客户导出";
  3169. $titlename = "<table border=1>
  3170. <tr>"
  3171. .$fzh.
  3172. "</tr>
  3173. </table>";
  3174. $tail = "\n";
  3175. $filename = $title.".xls";
  3176. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  3177. }
  3178. }
  3179. //下载excel模板
  3180. public function _down()
  3181. {
  3182. if(isset($_GET['excela']))
  3183. {
  3184. $title = "客户导入模板";
  3185. $titledata = array(array('姓名','详细地址','城市','省/州','邮编','国家','电话','邮箱','类型(1:网红2:批发3:店铺转线下4:线下其他5:店内)','所属店铺(必须ERP已有店铺)','来源(数据字典的户来源需存在)','黑白名单(白名单填1或黑名单填2)','备注'),array('lekia waites','700 Sandy Plains rd suite b14','marietta','Georgia','30066','United States','4047322519','lwaites@ccccare.com','5','supernovahair','独立站','1','备注'));
  3186. $filename = $title.".xls";
  3187. $this->customer->get_excel($titledata,$filename);
  3188. }
  3189. }
  3190. public function _newold()
  3191. {
  3192. if(isset($_SESSION['api']))
  3193. {
  3194. $user = $this->user->get_api($_SESSION['api']);
  3195. $usp = $user;
  3196. $fgshop = "";$sid = "";
  3197. $usersp = explode('|',trim($user['shop'],'|'));
  3198. foreach ($usersp as $value)
  3199. {
  3200. $fgshop .= " shop = ".$value." or";
  3201. $sid .= " id = ".$value." or";
  3202. }
  3203. }
  3204. $post = $this->input->post(NULL, TRUE);
  3205. if(isset($post['timek']))
  3206. {
  3207. $new = array();$old = array();$time=array();
  3208. $timek = $this->input->post('timek',true);
  3209. $timej = $this->input->post('timej',true);
  3210. $k = strtotime($timek)-24*3600;//少一天为增加选择开始天时间
  3211. $j = strtotime($timej);
  3212. $n = ($j-$k)/(24*3600);
  3213. if($n < 1)
  3214. {
  3215. $n = 1;
  3216. }
  3217. for($i=1;$i<$n;$i++)
  3218. {
  3219. $nnum = 0;$onum = 0;
  3220. $t = $j-($n*24*60*60)+($i*24*60*60);
  3221. $time[] = date('Y-m-d',$t);
  3222. $ct = strtotime(date('Ymd',$t));
  3223. $ctj = strtotime(date('Ymd',$t+24*3600));
  3224. $info_list = $this->fullorder->find_all("mergeid = '0' and dtime > '$ct' and dtime < '$ctj' and (".rtrim($fgshop,'or').")");
  3225. foreach ($info_list as $value)
  3226. {
  3227. if($value['email'] != '0' && $value['email'] != '' && $value['email'] != '无')
  3228. {
  3229. $gnum = $this->fullorder->find_count("email = '".$value['email']."' and shop = '".$value['shop']."' and mergeid = 0");
  3230. if($gnum >1)
  3231. {
  3232. $onum += 1;
  3233. }
  3234. else
  3235. {
  3236. $nnum += 1;
  3237. }
  3238. }
  3239. else
  3240. {
  3241. $nnum += 1;
  3242. }
  3243. }
  3244. $new[] = $nnum;
  3245. $old[] = $onum;
  3246. }
  3247. echo @json_encode(array('time'=>$time,'cnew'=>$new,'cold'=>$old,'success'=>true));exit;
  3248. }
  3249. $this->_Template('customer_newold',$this->data);
  3250. }
  3251. /**
  3252. * _dgsov1 - 优化版的_dgso方法
  3253. * 改进点:
  3254. * 1. 修复SQL注入漏洞,使用escape转义
  3255. * 2. 修复$d[0]越界问题
  3256. * 3. _dgcz改用BFS非递归算法,避免递归爆炸
  3257. * 4. 批量预加载关联数据,解决N+1查询
  3258. * 5. 修复特殊搜索路径的分页逻辑
  3259. * 6. 使用map映射替代硬编码if-else
  3260. * 7. 添加输入参数校验
  3261. * 8. 未使用的筛选参数(shop/name/level/时间范围)添加为实际筛选条件
  3262. */
  3263. public function _dgso()
  3264. {
  3265. $user = $this->user->get_api($_SESSION['api']);
  3266. if (!$user)
  3267. {
  3268. $vip = 0;
  3269. die("请先登录!!!");
  3270. }
  3271. $fgshop = "";
  3272. $sid = "";
  3273. $users = explode('|', trim($user['shop'], '|'));
  3274. foreach ($users as $value)
  3275. {
  3276. $fgshop .= " shop = " . intval($value) . " or";
  3277. $sid .= " id = " . intval($value) . " or";
  3278. }
  3279. $vip = ($user['vip'] == 1) ? 1 : 0;
  3280. $post = $this->input->post(NULL, TRUE);
  3281. if (!isset($post['page']))
  3282. {
  3283. $wlshop = $this->shop->find_all('1=1 and ' . rtrim($sid, 'or'));
  3284. $this->data['wlshop'] = $wlshop;
  3285. $this->data['vip'] = $vip;
  3286. $this->_Template('customer_dgso', $this->data);
  3287. return;
  3288. }
  3289. // 输入校验:page和perpage必须是正整数
  3290. $page = max(1, intval($this->input->post('page', true)));
  3291. $perpage = max(1, min(200, intval($this->input->post('perpage', true))));
  3292. // 获取搜索参数
  3293. $shop = intval($this->input->post('shop', true));
  3294. $numphone = $this->input->post('numphone', true);
  3295. $name = trim($this->input->post('name', true));
  3296. $email = trim($this->input->post('email', true));
  3297. $address = trim($this->input->post('address', true));
  3298. $level = intval($this->input->post('level', true));
  3299. $num = intval($this->input->post('num', true));
  3300. $timetk = $this->input->post('timetk', true);
  3301. $timetj = $this->input->post('timetj', true);
  3302. $timetk = strtotime($timetk);
  3303. $timetj = strtotime($timetj);
  3304. // 构建WHERE条件,使用escape防SQL注入
  3305. $where = "1=1 and (" . rtrim($fgshop, 'or') . ")";
  3306. if ($numphone)
  3307. {
  3308. $where .= " and numphone = " . $this->db->escape($numphone);
  3309. }
  3310. if ($email)
  3311. {
  3312. $where .= " and email like '%" . $this->db->escape_like_str($email) . "%'";
  3313. }
  3314. if ($address)
  3315. {
  3316. $where .= " and address like '%" . $this->db->escape_like_str($address) . "%'";
  3317. }
  3318. if ($shop)
  3319. {
  3320. $where .= " and shop = " . intval($shop);
  3321. }
  3322. if ($name)
  3323. {
  3324. $where .= " and name like '%" . $this->db->escape_like_str($name) . "%'";
  3325. }
  3326. if ($level)
  3327. {
  3328. $where .= " and level = " . intval($level);
  3329. }
  3330. if ($num)
  3331. {
  3332. $where .= " and num = " . intval($num);
  3333. }
  3334. if ($timetk && $timetj)
  3335. {
  3336. $where .= " and time >= " . intval($timetk) . " and time <= " . intval($timetj);
  3337. }
  3338. $fields = 'id,shop,source,name,email,country,level,money,num,time,type,numphone,address';
  3339. if ($numphone || $email || $address)
  3340. {
  3341. // 特殊搜索路径:通过地址/邮箱/电话查找关联客户
  3342. $d = $this->customer->find_all($where);
  3343. // 修复:判断$d是否为空,避免越界
  3344. if (empty($d))
  3345. {
  3346. echo json_encode(array('total' => 0, 'over' => 0, 'pagenum' => 0, 'rows' => array()));
  3347. exit;
  3348. }
  3349. // 使用BFS非递归算法查找所有关联客户
  3350. $cx = array();
  3351. $info_list = $this->_dgczv1($cx, $d);
  3352. $info_list = array_values($info_list);
  3353. $total = count($info_list);
  3354. $pagenum = ceil($total / $perpage);
  3355. // 修复:根据当前页码做切片分页
  3356. $start = ($page - 1) * $perpage;
  3357. $over = $total - ($start + $perpage);
  3358. $info_list = array_slice($info_list, $start, $perpage);
  3359. }
  3360. else
  3361. {
  3362. // 正常搜索路径
  3363. $order_str = "id desc";
  3364. $start = ($page - 1) * $perpage;
  3365. $info_list = $this->customer->find_all($where, 'id,shop,source,name,email,country,level,money,num,time,type', $order_str, $start, $perpage);
  3366. $total = $this->customer->find_count($where);
  3367. $pagenum = ceil($total / $perpage);
  3368. $over = $total - ($start + $perpage);
  3369. }
  3370. // 批量预加载关联数据,避免N+1查询
  3371. $shopIds = array();
  3372. $sourceIds = array();
  3373. $countryIds = array();
  3374. foreach ($info_list as $value)
  3375. {
  3376. if (!empty($value['shop'])) $shopIds[$value['shop']] = true;
  3377. if (!empty($value['source'])) $sourceIds[$value['source']] = true;
  3378. if (!empty($value['country'])) $countryIds[$value['country']] = true;
  3379. }
  3380. $shopMap = array();
  3381. if (!empty($shopIds))
  3382. {
  3383. $idList = implode(',', array_map('intval', array_keys($shopIds)));
  3384. $shopData = $this->shop->find_all("id in ($idList)", 'id,shopname');
  3385. foreach ($shopData as $row)
  3386. {
  3387. $shopMap[$row['id']] = $row['shopname'];
  3388. }
  3389. }
  3390. $sourceMap = array();
  3391. if (!empty($sourceIds))
  3392. {
  3393. $idList = implode(',', array_map('intval', array_keys($sourceIds)));
  3394. $sourceData = $this->typeclass->find_all("id in ($idList)", 'id,title');
  3395. foreach ($sourceData as $row)
  3396. {
  3397. $sourceMap[$row['id']] = $row['title'];
  3398. }
  3399. }
  3400. $countryMap = array();
  3401. if (!empty($countryIds))
  3402. {
  3403. $idList = implode(',', array_map('intval', array_keys($countryIds)));
  3404. $countryData = $this->country->find_all("id in ($idList)", 'id,name');
  3405. foreach ($countryData as $row)
  3406. {
  3407. $countryMap[$row['id']] = $row['name'];
  3408. }
  3409. }
  3410. // Level映射表
  3411. $levelMap = array(
  3412. 1 => '网红',
  3413. 2 => '批发',
  3414. 3 => '店铺转线下',
  3415. 4 => '线下其他',
  3416. 5 => '店内客户',
  3417. );
  3418. // 数据后处理
  3419. foreach ($info_list as $key => $value)
  3420. {
  3421. // 使用预加载的map赋值,避免逐条查询
  3422. $info_list[$key]['shop'] = isset($shopMap[$value['shop']]) ? $shopMap[$value['shop']] : '';
  3423. $info_list[$key]['source'] = isset($sourceMap[$value['source']]) ? $sourceMap[$value['source']] : '';
  3424. if ($value['country'] != 0)
  3425. {
  3426. $info_list[$key]['country'] = isset($countryMap[$value['country']]) ? $countryMap[$value['country']] : '未知';
  3427. }
  3428. else
  3429. {
  3430. $info_list[$key]['country'] = '未知';
  3431. }
  3432. // 使用map映射替代if-else链
  3433. $info_list[$key]['level'] = isset($levelMap[$value['level']]) ? $levelMap[$value['level']] : '未知';
  3434. if ($value['time'] != 0)
  3435. {
  3436. $info_list[$key]['time'] = date('Y-m-d', $value['time']);
  3437. }
  3438. else
  3439. {
  3440. $info_list[$key]['time'] = '无';
  3441. }
  3442. if ($value['type'] != 2)
  3443. {
  3444. $info_list[$key]['type'] = "<a href='javascript:void(0);' class='window' data-h='/customer/mdedit/" . $value['id'] . "' data-t='客户下单'><b>下单</b></a>&nbsp;&nbsp;&nbsp;&nbsp;<a class='customer' data-type='2' data-t='yr' data-id='" . $value['id'] . "' href='javascript:void(0);'>移入黑名单</a>";
  3445. }
  3446. else
  3447. {
  3448. $info_list[$key]['type'] = '黑名单客户';
  3449. }
  3450. unset($info_list[$key]['numphone']);
  3451. unset($info_list[$key]['address']);
  3452. }
  3453. $rows = array('total' => $total, 'over' => $over, 'pagenum' => $pagenum, 'rows' => ($info_list));
  3454. echo json_encode($rows);
  3455. exit;
  3456. }
  3457. /**
  3458. * _dgczv1 - 优化版的_dgcz方法
  3459. * 使用BFS广度优先搜索替代递归,避免递归爆炸和栈溢出
  3460. * 每一层合并所有搜索条件为一次查询,大幅减少数据库请求
  3461. */
  3462. public function _dgczv1($child, $data)
  3463. {
  3464. // 初始化已处理集合
  3465. foreach ($data as $value)
  3466. {
  3467. if (!isset($child[$value['id']]))
  3468. {
  3469. $child[$value['id']] = $value;
  3470. }
  3471. }
  3472. $fields = 'id,shop,source,name,email,country,level,money,num,time,type,numphone,address';
  3473. // BFS广度优先搜索
  3474. $queue = $data;
  3475. $maxIterations = 50; // 安全上限,防止无限循环
  3476. while (!empty($queue) && $maxIterations > 0)
  3477. {
  3478. $maxIterations--;
  3479. // 收集当前层所有不重复的搜索词
  3480. $addressSet = array();
  3481. $emailSet = array();
  3482. $numphoneSet = array();
  3483. foreach ($queue as $row)
  3484. {
  3485. if (!empty($row['address']))
  3486. {
  3487. $addressSet[$row['address']] = true;
  3488. }
  3489. if (!empty($row['email']))
  3490. {
  3491. $emailSet[$row['email']] = true;
  3492. }
  3493. if (!empty($row['numphone']))
  3494. {
  3495. $numphoneSet[$row['numphone']] = true;
  3496. }
  3497. }
  3498. $queue = array(); // 清空当前层,准备下一层
  3499. // 构建合并后的查询条件
  3500. $conditions = array();
  3501. foreach (array_keys($addressSet) as $addr)
  3502. {
  3503. $conditions[] = "address like '%" . $this->db->escape_like_str($addr) . "%'";
  3504. }
  3505. foreach (array_keys($emailSet) as $em)
  3506. {
  3507. $conditions[] = "email like '%" . $this->db->escape_like_str($em) . "%'";
  3508. }
  3509. foreach (array_keys($numphoneSet) as $np)
  3510. {
  3511. $conditions[] = "numphone like '%" . $this->db->escape_like_str($np) . "%'";
  3512. }
  3513. if (empty($conditions))
  3514. {
  3515. break;
  3516. }
  3517. // 一次查询获取所有匹配记录
  3518. $where = implode(' or ', $conditions);
  3519. $rows = $this->customer->find_all($where, $fields);
  3520. foreach ($rows as $row)
  3521. {
  3522. if (!isset($child[$row['id']]))
  3523. {
  3524. $child[$row['id']] = $row;
  3525. $queue[] = $row; // 新发现的节点加入下一层搜索
  3526. }
  3527. }
  3528. }
  3529. return $child;
  3530. }
  3531. }