Customer.php 107 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157
  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($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. //上传excel
  1477. public function _excela()
  1478. {
  1479. $dir = '/data/excel/'.date('Ymd',time()).'/';
  1480. $config['upload_path'] = '.'.$dir ;
  1481. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  1482. $config['allowed_types'] = 'xls|xlsx';
  1483. $config['max_size'] = 10240;
  1484. $this->load->library('upload', $config);
  1485. $this->upload->initialize($config);
  1486. if ($this->upload->do_upload('userfile'))
  1487. {
  1488. $full_path = $dir.$this->upload->data('file_name');
  1489. $fileName = '.' . $full_path;
  1490. if (!file_exists($fileName))
  1491. {
  1492. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  1493. }
  1494. else
  1495. {
  1496. require_once "./data/excel/PHPExcel/IOFactory.php";
  1497. @$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  1498. @$phpExcel->setActiveSheetIndex(0);// 设置为默认表
  1499. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  1500. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  1501. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  1502. ++$column;//如果列数大于26行
  1503. $list = array();
  1504. for ($i = 2; $i <= $row; $i++) // 行数循环
  1505. {
  1506. $data = array();
  1507. for ($c = 'A'; $c != $column; $c++) // 列数循环
  1508. {
  1509. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  1510. }
  1511. $list[] = $data;
  1512. }
  1513. }
  1514. $i = 0;
  1515. $this->db->trans_begin();
  1516. foreach ($list as $key=>$value)
  1517. {
  1518. $value['1'] = $value['1']?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['1']):'';
  1519. $value['7'] = $value['7']?str_replace('/( | | |\s)/','',$value['7']):'';
  1520. if($value['7'] == "" || $value['11'] == "")
  1521. {
  1522. $i++;
  1523. continue;
  1524. }
  1525. else
  1526. {
  1527. $value['7'] = str_replace('/( | | |\s)/','',$value['7']);
  1528. }
  1529. $shop = $this->shop->get_name($value['9']);
  1530. if(!$shop)
  1531. {
  1532. $i++;
  1533. continue;
  1534. }
  1535. if($value['11'] == 2)
  1536. {
  1537. $repeat = $this->customer->get_address($value['1']);//只判断地址
  1538. }
  1539. else
  1540. {
  1541. $repeat = $this->customer->find_all('email = "'.$value[7].'" and shop = "'.$shop['id'].'"');//只判断邮箱
  1542. }
  1543. /* 判断邮箱和地址
  1544. if($value['1'] == "" || $value['1'] == " ")
  1545. {
  1546. if($value['7'] == "" || $value['7'] == " ")
  1547. {
  1548. $repeat = 1;
  1549. }
  1550. else
  1551. {
  1552. $repeat = $this->customer->get_email($value['7']);
  1553. }
  1554. }
  1555. else
  1556. {
  1557. $repeat = $this->customer->get_address($value['1']);
  1558. }
  1559. */
  1560. if(isset($repeat[0]['type']))
  1561. {
  1562. if($repeat[0]['type'] == $value['11'])
  1563. {
  1564. $i++;
  1565. }
  1566. else if($repeat[0]['type'] != $value['11'])
  1567. {
  1568. $this->customer->save(array('type'=>$value['11']),$repeat[0]['id']);
  1569. }
  1570. }
  1571. else
  1572. {
  1573. $source = $this->typeclass->get_title($value['10']);
  1574. if($source)
  1575. {
  1576. $post['name'] = ($value['0'] && $value['0'] != 'NULL')?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['0']):'';
  1577. $post['email'] = $value['7'];
  1578. if($value['5'] != '')
  1579. {
  1580. $country = $this->country->get_ename(str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['5']));
  1581. $post['country'] = $country['id'];
  1582. }
  1583. $post['level'] = $value['8']?$value['8']:5;
  1584. $post['phone'] = $value['6']?$value['6']:'';
  1585. $post['province'] = $value['3']?$value['3']:'';
  1586. $post['city'] = $value['2']?$value['2']:'';
  1587. $post['address'] = $value['1'];
  1588. $post['zipcode'] = $value['4']?$value['4']:'';
  1589. $post['shop'] = $shop['id'];
  1590. $post['source'] = $source['id'];
  1591. $post['type'] = $value['11'];
  1592. $val12 = $value['12']?$value['12']:'';
  1593. $post['count'] = $val12;
  1594. $str = $post['phone'];
  1595. preg_match_all('/[0-9]/u',$str,$result);
  1596. $numphone = join('',$result[0]);
  1597. $post['numphone'] = $numphone;
  1598. $this->customer->insert($post);
  1599. }
  1600. }
  1601. }
  1602. if ($this->db->trans_status() === FALSE)
  1603. {
  1604. $this->db->trans_commit();
  1605. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  1606. }
  1607. else
  1608. {
  1609. if(count($list) == $i)
  1610. {
  1611. $til = '导入全部失败!请检查导入信息';
  1612. }
  1613. else if(count($list) > $i && $i != 0)
  1614. {
  1615. $til = '部分导入成功!'.$i.'条信息有问题,请排查';
  1616. }
  1617. else if($i < 1)
  1618. {
  1619. $til = '导入成功!';
  1620. }
  1621. $this->db->trans_commit();
  1622. echo json_encode(array('msg'=>$til,'success'=>true));exit;
  1623. }
  1624. }
  1625. else
  1626. {
  1627. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  1628. }
  1629. }
  1630. public function _temuexcel()
  1631. {
  1632. $dir = '/data/excel/'.date('Ymd',time()).'/';
  1633. $config['upload_path'] = '.'.$dir ;
  1634. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  1635. $config['allowed_types'] = 'xls|xlsx';
  1636. $config['max_size'] = 10240;
  1637. $this->load->library('upload', $config);
  1638. $this->upload->initialize($config);
  1639. if ($this->upload->do_upload('userfile'))
  1640. {
  1641. $full_path = $dir.$this->upload->data('file_name');
  1642. $fileName = '.' . $full_path;
  1643. if (!file_exists($fileName))
  1644. {
  1645. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  1646. }
  1647. else
  1648. {
  1649. require_once "./data/excel/PHPExcel/IOFactory.php";
  1650. @$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  1651. @$phpExcel->setActiveSheetIndex(0);// 设置为默认表
  1652. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  1653. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  1654. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  1655. ++$column;//如果列数大于26行
  1656. $list = array();
  1657. for ($i = 2; $i <= $row; $i++) // 行数循环
  1658. {
  1659. $data = array();
  1660. for ($c = 'A'; $c != $column; $c++) // 列数循环
  1661. {
  1662. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  1663. }
  1664. $list[] = $data;
  1665. }
  1666. }
  1667. $i = 0;
  1668. $gethl = $this->hl->get_hl();//获取即时汇率
  1669. $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');
  1670. $dtc = array();
  1671. foreach ($dictionaries as $v)
  1672. {
  1673. if(stripos($v['spare'],'|') !== false)//如果有多个值
  1674. {
  1675. $v['spare'] = explode('|',$v['spare']);
  1676. foreach ($v['spare'] as $k=>$vs)
  1677. {
  1678. if(stripos($v['zh'],'|') !== false)
  1679. {
  1680. $vzh = explode('|',$v['zh']);
  1681. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$vzh[$k],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
  1682. }
  1683. else
  1684. {
  1685. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
  1686. }
  1687. }
  1688. }
  1689. else
  1690. {
  1691. $dtc[strtolower($v['spare'])] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$v['spare']);
  1692. }
  1693. }
  1694. $dk = array();
  1695. $dictionaries2 = $this->typeclass->find_all();
  1696. foreach ($dictionaries2 as $v)
  1697. {
  1698. $dtctitle[$v['id']] = $v['title'];
  1699. $dk[$v['id']] = $v['bqsku'];
  1700. }
  1701. /* 匹配结束 */
  1702. /* 价格加入 */
  1703. $money = array();
  1704. $productdescribe = $this->productdescribe->find_all('1=1');
  1705. foreach ($productdescribe as $v)
  1706. {
  1707. $money[$v['number']] = array();
  1708. }
  1709. /* 价格加入 */
  1710. /* 匹配ID加入 */
  1711. $int = array();
  1712. $intdata = $this->typeclass->find_all('classid=14','id,spare');
  1713. foreach ($intdata as $v)
  1714. {
  1715. $v['spare'] = explode('|',$v['spare']);
  1716. $int[$v['id']] = $v['spare'][0];
  1717. }
  1718. /* 匹配ID加入 */
  1719. $zjsku = array();
  1720. $shopsku = $this->shopsku->find_all();
  1721. foreach ($shopsku as $val)
  1722. {
  1723. $ss = explode(',',trim($val['shop'],','));
  1724. foreach ($ss as $v)
  1725. {
  1726. if(isset($zjsku[$v]))
  1727. {
  1728. $zjsku[$v] .= ','.trim($val['sku'],',');
  1729. }
  1730. else
  1731. {
  1732. $zjsku[$v] = trim($val['sku'],',');
  1733. }
  1734. }
  1735. }
  1736. /* 匹配ID结束 */
  1737. $this->db->trans_begin();
  1738. $error = "";
  1739. foreach ($list as $key=>$value)
  1740. {
  1741. $addtess = ($value['15']!='--'?$value['15'].' ':'').($value['14']!='--'?$value['14'].' ':'').$value['13'];
  1742. $addtess = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$addtess);
  1743. $repeat = $this->customer->find_all('phone = "'.$value[11].'" and address = "'.($value['15']!='--'?$value['15'].' ':'').($value['14']!='--'?$value['14'].' ':'').$value['13'].'" and shop = 19');//判断电话地址
  1744. $sku = $value['8'];
  1745. $je = (isset($value['28']))?$value['28']:0;
  1746. // $value['29'] = str_replace('/','-',$value['29']);
  1747. // $dtime = strtotime($value['29']);
  1748. if(!empty($value['29'])){
  1749. $value['29'] = str_replace('/','-',$value['29']);
  1750. $dtime = strtotime($value['29']);
  1751. if($dtime > time()){
  1752. $dtime = time();
  1753. }
  1754. if(empty($dtime)){
  1755. $dtime = time();
  1756. }
  1757. }else{
  1758. $dtime = time();
  1759. }
  1760. $post['name'] = ($value['10'] && $value['10'] != 'NULL')?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['10']):'';
  1761. $post['email'] = $value['12'];
  1762. $res = $this->logic_order->checkEmail($post['email']);
  1763. if(!$res){
  1764. $error .= "第".($key+2)."行邮箱格式错误;";
  1765. $i++;
  1766. continue;
  1767. }
  1768. if($value['20'] != '')
  1769. {
  1770. $country = $this->country->get_ename(str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['20']));
  1771. $post['country'] = $country['id'];
  1772. }
  1773. $post['level'] = 4;
  1774. $post['phone'] = $value['11']?$value['11']:'';
  1775. $post['province'] = $value['18']?$value['18']:'';
  1776. $post['city'] = $value['17']?$value['17']:'';
  1777. $post['address'] = $addtess;
  1778. $post['zipcode'] = $value['19']?$value['19']:'';
  1779. $post['shop'] = 19;
  1780. $post['source'] = 2;
  1781. $post['type'] = 1;
  1782. $post['count'] = '';
  1783. $post['time'] = $dtime;
  1784. $str = $post['phone'];
  1785. preg_match_all('/[0-9]/u',$str,$result);
  1786. $numphone = join('',$result[0]);
  1787. $post['numphone'] = $numphone;
  1788. if(!isset($repeat[0]))
  1789. {
  1790. $this->customer->insert($post);
  1791. }
  1792. else
  1793. {
  1794. $this->customer->save(array('num'=>$repeat[0]['num']+1),$repeat[0]['id']);
  1795. }
  1796. $sbsku = '';
  1797. $whlabel = $this->whlabel->get_sku($sku);
  1798. if($whlabel)
  1799. {
  1800. $w = explode('-',trim($whlabel['features'],'-'));
  1801. foreach ($w as $v)
  1802. {
  1803. if(isset($dk[$v]))
  1804. {
  1805. $sbsku .= $dk[$v].'-';
  1806. }
  1807. }
  1808. }
  1809. $sbsku = trim($sbsku,'-');
  1810. $time = time();
  1811. $shop = $this->shop->read(19);
  1812. $ddpost['orderremarks'] = isset($value['30'])?$value['30']:'';
  1813. $ddpost['shop'] = $shop['id'];//店铺ID
  1814. $ddpost['user'] = $shop['shopuser'];//店铺负责人
  1815. $orderid = 0;
  1816. $ddpost['orderid'] = 0;
  1817. $ddpost['product'] = '';//产品名称
  1818. $ddpost['link'] = '';//产品链接
  1819. $ddpost['issku'] = $sku;
  1820. $ddpost['quantity'] = rtrim($value['3'],';');
  1821. $ddpost['clientremarks'] = '';//客户备注
  1822. //$ddpost['paypal'] = '';//交易号
  1823. $ddpost['guarantee'] = '';//卖家保障
  1824. $ddpost['parameter'] = '';//属性
  1825. $ddpost['shippingmethod'] = '';//用户选择快递方式及运费金额
  1826. $ddpost['source'] = 2;//订单类型
  1827. $ddpost['type'] = 1;//发货仓库
  1828. $ddpost['capital'] = 3;//资金支付状况,全部付款
  1829. $num = $this->fullorder->find_count('gtime = "'.date('Ymd',$dtime).'" and shop = 19');
  1830. $ddpost['number'] = $shop['shortname'].'-'.date('ymd',$dtime).'-'.(substr(strval($num+1+1000),1,3));//编号
  1831. $ddpost['orderinfo'] = preg_replace('/[^0-9]/', '', $value['0']);//订单号
  1832. $d = $this->fullorder->get_orderinfo($ddpost['orderinfo']);
  1833. if(isset($d['id']))
  1834. {
  1835. $error .= "第".($key+2)."行订单号重复;";
  1836. $i++;
  1837. continue;
  1838. }
  1839. $ddpost['paypal'] = $ddpost['orderinfo'];
  1840. $ddpost['insurance'] = 0;//运输保险费用
  1841. $ddpost['baddress'] = '';
  1842. $ddpost['saddress'] = '';
  1843. $ddpost['country'] = $country['id'];//此国家的ID
  1844. $ddpost['al'] = $country['lb'];//联邦名称
  1845. $ddpost['bname'] = $post['name'];//名称
  1846. $ddpost['sname'] = $post['name'];//名称
  1847. $ddpost['client'] = $post['name'];//公司名称
  1848. $ddpost['name'] = $post['name'];//收件人名称
  1849. $ddpost['phone'] = $post['phone'];//收件人电话
  1850. $ddpost['email'] = $post['email'];//客户邮箱
  1851. $ddpost['zipcode'] = $post['zipcode'];//收件人邮编
  1852. $ddpost['province'] = $post['province'];//收件人省份
  1853. $ddpost['city'] = $post['city'];//收件人城市
  1854. $ddpost['address'] = $post['address'];//收件人地址
  1855. $ddpost['shouldmoney'] = $je;//应收金额
  1856. $ddpost['skje'] = $je;//收款金额
  1857. $ddpost['ismoney'] = '';//支付币种金额
  1858. $ddpost['shouldmoney'] = $je;//金额
  1859. $ddpost['budget'] = $je;//预估到帐金额
  1860. $ddpost['buytime'] = $dtime;//格式化付款时间
  1861. $ddpost['dtime'] = $dtime;//订单时间
  1862. $ddpost['gtime'] = date('Ymd',$dtime);//格式化订单时间
  1863. $ddpost['currencytitle'] = 'USD';//结算币种名称
  1864. $ddpost['currency'] = 219;//钱币ID
  1865. $ddpost['time'] = time();//同步时间
  1866. $ddpost['shopify'] = 0;//同步时间
  1867. $ddpost['hl'] = '6.4';//汇率
  1868. $matching = $this->api->matching($ddpost['quantity'],$sbsku,$dtc,$money,$int,$dtctitle,$shop);
  1869. $ddpost['shipremarks'] = $matching['title'];
  1870. $ddpost['cost'] = $matching['cost'];
  1871. $ddpost['purchase'] = $matching['purchase'];
  1872. $ddpost['fpdata'] = $matching['product'];
  1873. $ddpost['whlabel'] = $matching['whlabel'];
  1874. $ddpost['slpx'] = $matching['wcslpx'];
  1875. $ddpost['state'] = 207;
  1876. $ddpost['type'] = 17;
  1877. $this->fullorder->insert($ddpost);
  1878. }
  1879. if ($this->db->trans_status() === FALSE)
  1880. {
  1881. $this->db->trans_commit();
  1882. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  1883. }
  1884. else
  1885. {
  1886. if(count($list) == $i)
  1887. {
  1888. $til = '导入全部失败!请检查导入信息;'.$error;
  1889. }
  1890. else if(count($list) > $i && $i != 0)
  1891. {
  1892. $til = '部分导入成功!'.$i.'条信息有问题,请排查;'.$error;
  1893. }
  1894. else if($i < 1)
  1895. {
  1896. $til = '导入成功!';
  1897. }
  1898. $this->db->trans_commit();
  1899. echo json_encode(array('msg'=>$til,'success'=>true));exit;
  1900. }
  1901. }
  1902. else
  1903. {
  1904. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  1905. }
  1906. }
  1907. //代发客户导入
  1908. public function _daifakehuexcel()
  1909. {
  1910. $shopid = 0;
  1911. $user = $this->user->get_api($_SESSION['api']);
  1912. if($user)
  1913. {
  1914. $users = explode('|',trim($user['shop'],'|'));
  1915. if(count($users) == 1){
  1916. $shopid = $users[0];
  1917. }else{
  1918. echo json_encode(array('msg'=>"此账号不能用于该功能!",'success'=>true));exit;
  1919. }
  1920. }
  1921. if(empty($shopid)){
  1922. echo json_encode(array('msg'=>"系统无法识别店铺!",'success'=>true));exit;
  1923. }
  1924. $dir = '/data/excel/'.date('Ymd',time()).'/';
  1925. $config['upload_path'] = '.'.$dir ;
  1926. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  1927. $config['allowed_types'] = 'xls|xlsx';
  1928. $config['max_size'] = 10240;
  1929. $this->load->library('upload', $config);
  1930. $this->upload->initialize($config);
  1931. if ($this->upload->do_upload('userfile'))
  1932. {
  1933. $full_path = $dir.$this->upload->data('file_name');
  1934. $fileName = '.' . $full_path;
  1935. if (!file_exists($fileName))
  1936. {
  1937. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  1938. }
  1939. else
  1940. {
  1941. require_once "./data/excel/PHPExcel/IOFactory.php";
  1942. @$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  1943. @$phpExcel->setActiveSheetIndex(0);// 设置为默认表
  1944. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  1945. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  1946. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  1947. ++$column;//如果列数大于26行
  1948. $list = array();
  1949. for ($i = 2; $i <= $row; $i++) // 行数循环
  1950. {
  1951. $data = array();
  1952. for ($c = 'A'; $c != $column; $c++) // 列数循环
  1953. {
  1954. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  1955. }
  1956. $list[] = $data;
  1957. }
  1958. }
  1959. $i = 0;
  1960. $gethl = $this->hl->get_hl();//获取即时汇率
  1961. $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');
  1962. $dtc = array();
  1963. foreach ($dictionaries as $v)
  1964. {
  1965. if(stripos($v['spare'],'|') !== false)//如果有多个值
  1966. {
  1967. $v['spare'] = explode('|',$v['spare']);
  1968. foreach ($v['spare'] as $k=>$vs)
  1969. {
  1970. if(stripos($v['zh'],'|') !== false)
  1971. {
  1972. $vzh = explode('|',$v['zh']);
  1973. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$vzh[$k],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
  1974. }
  1975. else
  1976. {
  1977. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
  1978. }
  1979. }
  1980. }
  1981. else
  1982. {
  1983. $dtc[strtolower($v['spare'])] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$v['spare']);
  1984. }
  1985. }
  1986. $dk = array();
  1987. $dictionaries2 = $this->typeclass->find_all();
  1988. foreach ($dictionaries2 as $v)
  1989. {
  1990. $dtctitle[$v['id']] = $v['title'];
  1991. $dk[$v['id']] = $v['bqsku'];
  1992. }
  1993. /* 匹配结束 */
  1994. /* 价格加入 */
  1995. $money = array();
  1996. $productdescribe = $this->productdescribe->find_all('1=1');
  1997. foreach ($productdescribe as $v)
  1998. {
  1999. $money[$v['number']] = array();
  2000. }
  2001. /* 价格加入 */
  2002. /* 匹配ID加入 */
  2003. $int = array();
  2004. $intdata = $this->typeclass->find_all('classid=14','id,spare');
  2005. foreach ($intdata as $v)
  2006. {
  2007. $v['spare'] = explode('|',$v['spare']);
  2008. $int[$v['id']] = $v['spare'][0];
  2009. }
  2010. /* 匹配ID加入 */
  2011. $zjsku = array();
  2012. $shopsku = $this->shopsku->find_all();
  2013. foreach ($shopsku as $val)
  2014. {
  2015. $ss = explode(',',trim($val['shop'],','));
  2016. foreach ($ss as $v)
  2017. {
  2018. if(isset($zjsku[$v]))
  2019. {
  2020. $zjsku[$v] .= ','.trim($val['sku'],',');
  2021. }
  2022. else
  2023. {
  2024. $zjsku[$v] = trim($val['sku'],',');
  2025. }
  2026. }
  2027. }
  2028. /* 匹配ID结束 */
  2029. $this->db->trans_begin();
  2030. $error = "";
  2031. foreach ($list as $key=>$value)
  2032. {
  2033. if(empty($value[0])){
  2034. continue;
  2035. }
  2036. $addtess = $value[7].$value[6];
  2037. $addtess = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$addtess);
  2038. $repeat = $this->customer->find_all('phone = "'.$value[4].'" and address = "'.$addtess.'" and shop = '.$shopid);//判断电话地址
  2039. $sku = $value['2'];
  2040. $je = (isset($value['12']))?$value['12']:0;
  2041. if(!empty($value[13])){
  2042. $value['13'] = str_replace('/','-',$value['13']);
  2043. $dtime = strtotime($value['13']);
  2044. if(empty($dtime)){
  2045. $dtime = time();
  2046. }
  2047. }else{
  2048. $dtime = time();
  2049. }
  2050. $dtime = $dtime + $key;
  2051. $post['name'] = (!empty($value[3]))?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['3']):'';
  2052. $post['email'] = $value['5'];
  2053. $res = $this->logic_order->checkEmail($post['email']);
  2054. if(!$res){
  2055. $error .= '第'.($key+2).'行邮箱格式错误;';
  2056. $i++;
  2057. continue;
  2058. }
  2059. if($value['11'] != '')
  2060. {
  2061. $country = $this->country->get_ename(str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['11']));
  2062. $post['country'] = $country['id'];
  2063. }
  2064. $post['level'] = 4;
  2065. $post['phone'] = $value['4']?$value['4']:'';
  2066. $post['province'] = $value['9']?$value['9']:'';
  2067. $post['city'] = $value['8']?$value['8']:'';
  2068. $post['address'] = $addtess;
  2069. $post['zipcode'] = $value['10']?$value['10']:'';
  2070. $post['shop'] = $shopid;
  2071. $post['source'] = 10;
  2072. $post['type'] = 1;
  2073. $post['count'] = '';
  2074. $post['time'] = $dtime;
  2075. $str = $post['phone'];
  2076. preg_match_all('/[0-9]/u',$str,$result);
  2077. $numphone = join('',$result[0]);
  2078. $post['numphone'] = $numphone;
  2079. if(!isset($repeat[0]))
  2080. {
  2081. $post['num'] = 1;
  2082. $this->customer->insert($post);
  2083. }
  2084. else
  2085. {
  2086. $this->customer->save(array('num'=>$repeat[0]['num']+1),$repeat[0]['id']);
  2087. }
  2088. $sbsku = '';
  2089. $whlabel = $this->whlabel->get_sku($sku);
  2090. if($whlabel)
  2091. {
  2092. $w = explode('-',trim($whlabel['features'],'-'));
  2093. foreach ($w as $v)
  2094. {
  2095. if(isset($dk[$v]))
  2096. {
  2097. $sbsku .= $dk[$v].'-';
  2098. }
  2099. }
  2100. }
  2101. $sbsku = trim($sbsku,'-');
  2102. $time = time();
  2103. $shop = $this->shop->read($shopid);
  2104. $ddpost['orderremarks'] = '';
  2105. $ddpost['shop'] = $shop['id'];//店铺ID
  2106. $ddpost['user'] = $shop['shopuser'];//店铺负责人
  2107. $orderid = 0;
  2108. $ddpost['orderid'] = 0;
  2109. $ddpost['product'] = '';//产品名称
  2110. $ddpost['link'] = '';//产品链接
  2111. $ddpost['issku'] = $sku;
  2112. $ddpost['quantity'] = rtrim($value['1'],';');
  2113. $ddpost['clientremarks'] = '';//客户备注
  2114. $ddpost['guarantee'] = '';//卖家保障
  2115. $ddpost['parameter'] = '';//属性
  2116. $ddpost['shippingmethod'] = '';//用户选择快递方式及运费金额
  2117. $ddpost['source'] = 2;//订单类型
  2118. $ddpost['type'] = 1;//发货仓库
  2119. $ddpost['capital'] = 3;//资金支付状况,全部付款
  2120. $num = $this->fullorder->find_count('gtime = "'.date('Ymd',$dtime).'" and shop = '.$shopid);
  2121. $ddpost['number'] = $shop['shortname'].'-'.date('ymd',$dtime).'-'.(substr(strval($num+1+1000),1,3));//编号
  2122. $ddpost['orderinfo'] = $value['0'];//订单号
  2123. $d = $this->fullorder->get_orderinfo($ddpost['orderinfo']);
  2124. if(isset($d['id']))
  2125. {
  2126. $error .= '第'.($key+2).'行订单号重复;';
  2127. $i++;
  2128. continue;
  2129. }
  2130. $ddpost['paypal'] = $ddpost['orderinfo'];//交易号
  2131. $ddpost['insurance'] = 0;//运输保险费用
  2132. $ddpost['baddress'] = '';
  2133. $ddpost['saddress'] = '';
  2134. $ddpost['country'] = $country['id'];//此国家的ID
  2135. $ddpost['al'] = $country['lb'];//联邦名称
  2136. $ddpost['bname'] = $post['name'];//名称
  2137. $ddpost['sname'] = $post['name'];//名称
  2138. $ddpost['client'] = $post['name'];//公司名称
  2139. $ddpost['name'] = $post['name'];//收件人名称
  2140. $ddpost['phone'] = $post['phone'];//收件人电话
  2141. $ddpost['email'] = $post['email'];//客户邮箱
  2142. $ddpost['zipcode'] = $post['zipcode'];//收件人邮编
  2143. $ddpost['province'] = $post['province'];//收件人省份
  2144. $ddpost['city'] = $post['city'];//收件人城市
  2145. $ddpost['address'] = $post['address'];//收件人地址
  2146. $ddpost['shouldmoney'] = $je;//应收金额
  2147. $ddpost['skje'] = $je;//收款金额
  2148. $ddpost['ismoney'] = '';//支付币种金额
  2149. $ddpost['shouldmoney'] = $je;//金额
  2150. $ddpost['budget'] = $je;//预估到帐金额
  2151. $ddpost['buytime'] = $dtime;//格式化付款时间
  2152. $ddpost['dtime'] = $dtime;//订单时间
  2153. $ddpost['gtime'] = date('Ymd',$dtime);//格式化订单时间
  2154. $ddpost['currencytitle'] = 'USD';//结算币种名称
  2155. $ddpost['currency'] = 219;//钱币ID
  2156. $ddpost['time'] = time();//同步时间
  2157. $ddpost['shopify'] = 0;//同步时间
  2158. $ddpost['hl'] = '6.4';//汇率
  2159. $matching = $this->api->matching($ddpost['quantity'],$sbsku,$dtc,$money,$int,$dtctitle,$shop);
  2160. $ddpost['shipremarks'] = $matching['title'];
  2161. $ddpost['cost'] = $matching['cost'];
  2162. $ddpost['purchase'] = $matching['purchase'];
  2163. $ddpost['fpdata'] = $matching['product'];
  2164. $ddpost['whlabel'] = $matching['whlabel'];
  2165. $ddpost['slpx'] = $matching['wcslpx'];
  2166. $ddpost['state'] = 207;
  2167. $ddpost['type'] = 13;
  2168. $this->fullorder->insert($ddpost);
  2169. }
  2170. if ($this->db->trans_status() === FALSE)
  2171. {
  2172. $this->db->trans_commit();
  2173. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  2174. }
  2175. else
  2176. {
  2177. if(count($list) == $i)
  2178. {
  2179. $til = '导入全部失败!请检查导入信息;'.$error;
  2180. }
  2181. else if(count($list) > $i && $i != 0)
  2182. {
  2183. $til = '部分导入成功!'.$i.'条信息有问题,请排查;'.$error;
  2184. }
  2185. else if($i < 1)
  2186. {
  2187. $til = '导入成功!';
  2188. }
  2189. $this->db->trans_commit();
  2190. echo json_encode(array('msg'=>$til,'success'=>true));exit;
  2191. }
  2192. }
  2193. else
  2194. {
  2195. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  2196. }
  2197. }
  2198. public function _indexexcel()//通过计数,2020/02/21已校准
  2199. {
  2200. $user = $this->user->get_api($_SESSION['api']);
  2201. if($user)
  2202. {
  2203. $fgshop = "";$sid = "";
  2204. $users = explode('|',trim($user['shop'],'|'));
  2205. foreach ($users as $value)
  2206. {
  2207. $fgshop .= " shop = ".$value." or";
  2208. $sid .= " id = ".$value." or";
  2209. }
  2210. if($user['vip'] == 1)
  2211. {
  2212. $vip = 1;
  2213. }
  2214. else
  2215. {
  2216. $vip = 0;
  2217. }
  2218. }
  2219. else
  2220. {
  2221. $vip = 0;
  2222. }
  2223. $post = $this->input->post(NULL, TRUE);
  2224. if(isset($_GET['timetk']))
  2225. {
  2226. $shop = $this->input->get('shop',true);
  2227. $numphone = $this->input->get('numphone',true);
  2228. $name = $this->input->get('name',true);
  2229. $email = $this->input->get('email',true);
  2230. $address = $this->input->get('address',true);
  2231. $level = $this->input->get('level',true);
  2232. $num = $this->input->get('num',true);
  2233. $country = $this->input->get('country',true);
  2234. $excelid = $this->input->get('sid',true);
  2235. $timetk = $this->input->get('timetk',true);
  2236. $timetj = $this->input->get('timetj',true);
  2237. $timetk = strtotime($timetk);
  2238. $timetj = strtotime($timetj);
  2239. $where = "1=1 and type = 1 and (".rtrim($fgshop,'or').")";
  2240. if($shop)
  2241. {
  2242. $where .= " and shop = '$shop'";
  2243. }
  2244. if($numphone)
  2245. {
  2246. $where .= " and numphone = '$numphone'";
  2247. }
  2248. if($name)
  2249. {
  2250. $where .= " and name like '%$name%'";
  2251. }
  2252. if($email)
  2253. {
  2254. $where .= " and email like '%$email%'";
  2255. }
  2256. if($level)
  2257. {
  2258. $where .= " and level = '$level'";
  2259. }
  2260. if($country)
  2261. {
  2262. $where .= " and country = '$country'";
  2263. }
  2264. if($address)
  2265. {
  2266. $where .= " and address like '%$address%'";
  2267. }
  2268. if($num > 0 && $num < 10 && $num != '2a')
  2269. {
  2270. $where .= " and num = '$num'";
  2271. }
  2272. else if($num > 9)
  2273. {
  2274. $where .= " and num > '9'";
  2275. }
  2276. else if($num == '2a')
  2277. {
  2278. $where .= " and num > '1'";
  2279. }
  2280. else
  2281. {
  2282. $where .= " and num >= '0'";
  2283. }
  2284. if($timetk && $timetj)
  2285. {
  2286. $where .= " and ((time > '$timetk' and time < '$timetj') or time = '0')";
  2287. }
  2288. $xzid = '';
  2289. if($excelid)
  2290. {
  2291. $excelid = explode(',',trim($excelid,','));
  2292. foreach ($excelid as $key=>$value)
  2293. {
  2294. $xzid .= " id = ".$value." or";
  2295. }
  2296. $where .= " and (".rtrim($xzid,'or').")";;
  2297. }
  2298. //数据排序
  2299. $order_str = "id desc";
  2300. $numdata = array();
  2301. if(empty($page))
  2302. {
  2303. $start = 0;
  2304. $perpage = 1;
  2305. }
  2306. else
  2307. {
  2308. $start = ($page - 1)*$perpage;
  2309. }
  2310. //取得信息列表
  2311. $info_list = $this->customer->find_all($where,'shop,name,email,phone,address,city,province,zipcode,country,level,money,num,numphone,time,count',$order_str);
  2312. foreach ($info_list as $key=>$value)
  2313. {
  2314. $shop = $this->shop->read($value['shop']);
  2315. $info_list[$key]['shop'] = $shop['shopname'];
  2316. if($value['country'] != 0)
  2317. {
  2318. $country = $this->country->read($value['country']);
  2319. $info_list[$key]['country'] = $country['name'];
  2320. }
  2321. else
  2322. {
  2323. $info_list[$key]['country'] = "未知";
  2324. }
  2325. if($value['level'] == 1)
  2326. {
  2327. $info_list[$key]['level'] = "网红";
  2328. }
  2329. else if($value['level'] == 2)
  2330. {
  2331. $info_list[$key]['level'] = "批发";
  2332. }
  2333. else if($value['level'] == 3)
  2334. {
  2335. $info_list[$key]['level'] = "店铺转线下";
  2336. }
  2337. else if($value['level'] == 4)
  2338. {
  2339. $info_list[$key]['level'] = "线下其他";
  2340. }
  2341. else if($value['level'] == 5)
  2342. {
  2343. $info_list[$key]['level'] = "店内客户";
  2344. }
  2345. if($value['time'] != 0)
  2346. {
  2347. $info_list[$key]['time'] = date('Y-m-d',$value['time']);
  2348. }
  2349. else
  2350. {
  2351. $info_list[$key]['time'] = "无";
  2352. }
  2353. $info_list[$key]['numphone'] = ($value['num'] > 0 && $value['money'] > 0)?sprintf("%01.2f",$value['money']/$value['num']):0;
  2354. if(isset($value['email']) && $user['excelpass'] == '1')
  2355. {
  2356. $emailpass = $this->setting->get_excelpass($value['email']);
  2357. $info_list[$key]['email'] = $emailpass;
  2358. }
  2359. if(isset($value['phone']) && $user['excelpass'] == '1')
  2360. {
  2361. $phone = $this->setting->get_excelpass($value['phone']);
  2362. $info_list[$key]['phone'] = $phone;
  2363. }
  2364. }
  2365. $title = "按条件导出";
  2366. $titlename = "<table border=1>
  2367. <tr align='center'>
  2368. <td>店铺</td>
  2369. <td>名称</td>
  2370. <td>邮箱</td>
  2371. <td>电话</td>
  2372. <td>详细地址</td>
  2373. <td>城市</td>
  2374. <td>省/州</td>
  2375. <td>邮编</td>
  2376. <td>国家</td>
  2377. <td>类型</td>
  2378. <td>总额</td>
  2379. <td>成交次数</td>
  2380. <td>客单价</td>
  2381. <td>最后购买日期</td>
  2382. <td>备注</td>
  2383. </tr>
  2384. </table>";
  2385. $filename = $title.".xls";
  2386. $tail = "";
  2387. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  2388. }
  2389. }
  2390. //下载excel
  2391. public function _excel()
  2392. {
  2393. if(isset($_GET['excel']))
  2394. {
  2395. if(isset($_SESSION['api']))
  2396. {
  2397. $user = $this->user->get_api($_SESSION['api']);
  2398. $usp = $user;
  2399. $fgshop = "";$sid = "";
  2400. $user = explode('|',trim($user['shop'],'|'));
  2401. foreach ($user as $value)
  2402. {
  2403. $fgshop .= " shop = ".$value." or";
  2404. $sid .= " id = ".$value." or";
  2405. }
  2406. }
  2407. $dowid = $this->input->get('a');
  2408. $wid = "";
  2409. if($dowid != "")
  2410. {
  2411. $id_arr = explode(',',rtrim($dowid,','));
  2412. $wid .= " id = 0 or";
  2413. foreach ($id_arr as $v)
  2414. {
  2415. $wid .= " id = '$v' or";
  2416. }
  2417. $wid = " and".rtrim($wid,'or');
  2418. }
  2419. $excel = $this->input->get('excel',true);
  2420. $page = $this->input->get('page',true);
  2421. $perpage = $this->input->get('perpage',true);
  2422. $shop = $this->input->get('shop',true);
  2423. $name = $this->input->get('name',true);
  2424. $country = $this->input->get('country',true);
  2425. $email = $this->input->get('email',true);
  2426. $address = $this->input->get('address',true);
  2427. $level = $this->input->get('level',true);
  2428. $num = $this->input->get('num',true);
  2429. $timetk = $this->input->get('timetk',true);
  2430. $timetj = $this->input->get('timetj',true);
  2431. $timetk = strtotime($timetk);
  2432. $timetj = strtotime($timetj);
  2433. $where = "1 = 1 and (".rtrim($fgshop,'or').")";
  2434. if($shop)
  2435. {
  2436. $where .= " and shop = '$shop'";
  2437. }
  2438. if($name)
  2439. {
  2440. $where .= " and name like '%$name%'";
  2441. }
  2442. if($email)
  2443. {
  2444. $where .= " and email like '%$email%'";
  2445. }
  2446. if($country)
  2447. {
  2448. $where .= " and country = '$country'";
  2449. }
  2450. if($level)
  2451. {
  2452. $where .= " and level = '$level'";
  2453. }
  2454. if($num != '')
  2455. {
  2456. $nu = 1;
  2457. if($num > 9)
  2458. {
  2459. $where .= " and num > '9'";
  2460. }
  2461. else if($num == '2a')
  2462. {
  2463. $where .= " and num > '1'";
  2464. }
  2465. else
  2466. {
  2467. $where .= " and num = '$num'";
  2468. }
  2469. }
  2470. else
  2471. {
  2472. $nu = 2;
  2473. $where .= " and num >= '0'";
  2474. }
  2475. if($address)
  2476. {
  2477. $where .= " and address like '%$address%'";
  2478. }
  2479. if($timetk && $timetj)
  2480. {
  2481. $where .= " and time > '$timetk' and time < '$timetj'";
  2482. }
  2483. $where .= " and type = 1";//白名单用户
  2484. $info_list = array();
  2485. if($excel == 2) //老客户列表
  2486. {
  2487. //$where = str_replace("level = '$level'","level > '1'",$where);
  2488. $info_list = $this->customer->find_all($where.$wid,'name,email,country,time,num,money,numphone','time desc');
  2489. foreach ($info_list as $key=>$value)
  2490. {
  2491. $info_list[$key]['time'] = date('Y-m-d H:i:s',$value['time']);
  2492. if($value['country'] != 0)
  2493. {
  2494. $country = $this->country->read($value['country']);
  2495. $info_list[$key]['country'] = $country['ename'];
  2496. }
  2497. else
  2498. {
  2499. $info_list[$key]['country'] = '';
  2500. }
  2501. if($value['num'] > 0){
  2502. $info_list[$key]['numphone'] = sprintf("%01.2f",$value['money']/$value['num']);
  2503. }else{
  2504. $info_list[$key]['numphone'] = "<span style='color:red'>num异常".$value['num']."</span>";
  2505. }
  2506. if(isset($value['email']) && $usp['excelpass'] == '1')
  2507. {
  2508. $emailpass = $this->setting->get_excelpass($value['email']);
  2509. $info_list[$key]['email'] = $emailpass;
  2510. }
  2511. }
  2512. /**
  2513. foreach ($info_list as $key=>$value)
  2514. {
  2515. $value['time'] = date('Y-m-d H:i:s',$value['time']);
  2516. $d = $this->fullorder->find_count('email = "'.$value['email'].'" and shop = "'.$value['shop'].'" and mergeid = 0','orderinfo,state,product,name,email,dtime,shouldmoney','time desc');
  2517. if($d > 1)
  2518. {
  2519. $info_list[] = $v;
  2520. }
  2521. }
  2522. **/
  2523. $fzh = "<td>客户名</td><td>客户邮箱</td><td>客户国家</td><td>最近一次下单时间</td><td>购买次数</td><td>购买总金额</td><td>客单价</td>";
  2524. $title = "老客户列表";
  2525. }
  2526. else
  2527. {
  2528. $fdata = $this->customer->find_all($where.$wid,'email,shop','time desc');
  2529. foreach ($fdata as $key=>$value)
  2530. {
  2531. $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');
  2532. if($nu == 2)
  2533. {
  2534. if(count($d) > 1)
  2535. {
  2536. foreach ($d as $k=>$v)
  2537. {
  2538. $v['dtime'] = date('Y-m-d H:i:s',$v['dtime']);
  2539. $typeclass = $this->typeclass->read($v['state']);
  2540. $v['state'] = $typeclass['spare'];
  2541. if($v['country'] != 0)
  2542. {
  2543. $country = $this->country->read($v['country']);
  2544. $v['country'] = $country['ename'];
  2545. }
  2546. else
  2547. {
  2548. $v['country'] = '';
  2549. }
  2550. if(isset($v['email']) && $usp['excelpass'] == '1')
  2551. {
  2552. $emailpass = $this->setting->get_excelpass($v['email']);
  2553. $v['email'] = $emailpass;
  2554. }
  2555. $info_list[] = $v;
  2556. }
  2557. }
  2558. }
  2559. else
  2560. {
  2561. foreach ($d as $k=>$v)
  2562. {
  2563. $v['dtime'] = date('Y-m-d H:i:s',$v['dtime']);
  2564. $typeclass = $this->typeclass->read($v['state']);
  2565. $v['state'] = $typeclass['spare'];
  2566. if($v['country'] != 0)
  2567. {
  2568. $country = $this->country->read($v['country']);
  2569. $v['country'] = $country['ename'];
  2570. }
  2571. else
  2572. {
  2573. $v['country'] = '';
  2574. }
  2575. if(isset($v['email']) && $usp['excelpass'] == '1')
  2576. {
  2577. $emailpass = $this->setting->get_excelpass($v['email']);
  2578. $v['email'] = $emailpass;
  2579. }
  2580. $info_list[] = $v;
  2581. }
  2582. }
  2583. }
  2584. $fzh = "<td>订单号</td><td>订单状态</td><td>产品名</td><td>仓库品名</td><td>客户名</td><td>客户邮箱</td><td>客户国家</td><td>下单时间</td><td>订单金额</td>";
  2585. $title = "老客户订单列表";
  2586. }
  2587. $titlename = "<table border=1>
  2588. <tr>"
  2589. .$fzh.
  2590. "</tr>
  2591. </table>";
  2592. $tail = "\n";
  2593. $filename = $title.'-'.date('Ymd',time()).".xls";
  2594. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  2595. }
  2596. }
  2597. //下载excel模板
  2598. public function _bankdown()
  2599. {
  2600. if(isset($_GET['bankdown']))
  2601. {
  2602. $numphone = $this->input->post('numphone',true);
  2603. $xtime = $this->input->get('xtime',true);
  2604. //$where = "1=1 and type = 2 and (".rtrim($fgshop,'or').")";
  2605. $shop = $this->input->get('shop',true);
  2606. $name = $this->input->get('name',true);
  2607. $email = $this->input->get('email',true);
  2608. $address = $this->input->get('address',true);
  2609. $type = $this->input->get('type',true);
  2610. $id = $this->input->get('id',true);
  2611. $timetk = $this->input->get('timetk',true);
  2612. $timetj = $this->input->get('timetj',true);
  2613. $timetk = strtotime($timetk);
  2614. $timetj = strtotime($timetj);
  2615. if($type)
  2616. {
  2617. $where = "type = '$type'";
  2618. }
  2619. else
  2620. {
  2621. $where = "id != 0";
  2622. }
  2623. if($id)
  2624. {
  2625. $id = explode('|',trim($id,'|'));
  2626. $downid = '';
  2627. foreach ($id as $value)
  2628. {
  2629. $downid .= " id = ".$value." or";
  2630. }
  2631. $where .= " and (".rtrim($downid,'or').")";
  2632. }
  2633. if(!$shop)
  2634. {
  2635. $user = $this->user->get_api($_SESSION['api']);
  2636. $usp = $user;
  2637. $fgshop = "";$sid = "";
  2638. $user = explode('|',trim($user['shop'],'|'));
  2639. foreach ($user as $value)
  2640. {
  2641. $fgshop .= " shop = ".$value." or";
  2642. $sid .= " id = ".$value." or";
  2643. }
  2644. $where .= " and (".rtrim($fgshop,'or').")";
  2645. }
  2646. else
  2647. {
  2648. $where .= " and shop = '$shop'";
  2649. }
  2650. if($email)
  2651. {
  2652. $where .= " and email = '$email'";
  2653. }
  2654. if($name)
  2655. {
  2656. $where .= " and name = '$name'";
  2657. }
  2658. if($address)
  2659. {
  2660. $where .= " and address = '$address'";
  2661. }
  2662. if($xtime)
  2663. {
  2664. $where .= " and typetime > '$timetk' and typetime < '$timetj'";
  2665. }
  2666. $info_list = $this->customer->find_all($where,'name,address,city,province,zipcode,country,phone,email,level,shop,source,type,count,typetime');
  2667. foreach ($info_list as $key=>$v)
  2668. {
  2669. $country = $this->country->read($v['country']);
  2670. $info_list[$key]['country'] = $country['ename'];
  2671. if($v['level'] == 1)
  2672. {
  2673. $info_list[$key]['level'] = '网红';
  2674. }
  2675. else if($v['level'] == 2)
  2676. {
  2677. $info_list[$key]['level'] = '批发';
  2678. }
  2679. else if($v['level'] == 3)
  2680. {
  2681. $info_list[$key]['level'] = '店铺转线下';
  2682. }
  2683. else if($v['level'] == 4)
  2684. {
  2685. $info_list[$key]['level'] = '线下其他';
  2686. }
  2687. else if($v['level'] == 5)
  2688. {
  2689. $info_list[$key]['level'] = '店内';
  2690. }
  2691. else
  2692. {
  2693. $info_list[$key]['level'] = '未知';
  2694. }
  2695. if($v['typetime'] != 0)
  2696. {
  2697. $info_list[$key]['typetime'] = date('Y-m-d',$v['typetime']);
  2698. }
  2699. else
  2700. {
  2701. $info_list[$key]['typetime'] = "无";
  2702. }
  2703. $shop = $this->shop->read($v['shop']);
  2704. $info_list[$key]['shop'] = $shop['shopname'];
  2705. $source = $this->typeclass->read($v['source']);
  2706. $info_list[$key]['source'] = $source['title'];
  2707. }
  2708. $titledata = array('姓名','详细地址','城市','省/州','邮编','国家','电话','邮箱','类型(1:网红2:批发3:店铺转线下4:线下其他5:店内)','所属店铺(必须ERP已有店铺)','来源(数据字典的户来源需存在)','黑白名单(白名单填1或黑名单填2)','备注','客户分类时间');
  2709. $fzh = "";
  2710. foreach ($titledata as $v)
  2711. {
  2712. $fzh .= "<td>".$v."</td>";
  2713. }
  2714. $title = "客户导出";
  2715. $titlename = "<table border=1>
  2716. <tr>"
  2717. .$fzh.
  2718. "</tr>
  2719. </table>";
  2720. $tail = "\n";
  2721. $filename = $title.".xls";
  2722. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  2723. }
  2724. }
  2725. //下载excel模板
  2726. public function _down()
  2727. {
  2728. if(isset($_GET['excela']))
  2729. {
  2730. $title = "客户导入模板";
  2731. $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','备注'));
  2732. $filename = $title.".xls";
  2733. $this->customer->get_excel($titledata,$filename);
  2734. }
  2735. }
  2736. public function _newold()
  2737. {
  2738. if(isset($_SESSION['api']))
  2739. {
  2740. $user = $this->user->get_api($_SESSION['api']);
  2741. $usp = $user;
  2742. $fgshop = "";$sid = "";
  2743. $usersp = explode('|',trim($user['shop'],'|'));
  2744. foreach ($usersp as $value)
  2745. {
  2746. $fgshop .= " shop = ".$value." or";
  2747. $sid .= " id = ".$value." or";
  2748. }
  2749. }
  2750. $post = $this->input->post(NULL, TRUE);
  2751. if(isset($post['timek']))
  2752. {
  2753. $new = array();$old = array();$time=array();
  2754. $timek = $this->input->post('timek',true);
  2755. $timej = $this->input->post('timej',true);
  2756. $k = strtotime($timek)-24*3600;//少一天为增加选择开始天时间
  2757. $j = strtotime($timej);
  2758. $n = ($j-$k)/(24*3600);
  2759. if($n < 1)
  2760. {
  2761. $n = 1;
  2762. }
  2763. for($i=1;$i<$n;$i++)
  2764. {
  2765. $nnum = 0;$onum = 0;
  2766. $t = $j-($n*24*60*60)+($i*24*60*60);
  2767. $time[] = date('Y-m-d',$t);
  2768. $ct = strtotime(date('Ymd',$t));
  2769. $ctj = strtotime(date('Ymd',$t+24*3600));
  2770. $info_list = $this->fullorder->find_all("mergeid = '0' and dtime > '$ct' and dtime < '$ctj' and (".rtrim($fgshop,'or').")");
  2771. foreach ($info_list as $value)
  2772. {
  2773. if($value['email'] != '0' && $value['email'] != '' && $value['email'] != '无')
  2774. {
  2775. $gnum = $this->fullorder->find_count("email = '".$value['email']."' and shop = '".$value['shop']."' and mergeid = 0");
  2776. if($gnum >1)
  2777. {
  2778. $onum += 1;
  2779. }
  2780. else
  2781. {
  2782. $nnum += 1;
  2783. }
  2784. }
  2785. else
  2786. {
  2787. $nnum += 1;
  2788. }
  2789. }
  2790. $new[] = $nnum;
  2791. $old[] = $onum;
  2792. }
  2793. echo @json_encode(array('time'=>$time,'cnew'=>$new,'cold'=>$old,'success'=>true));exit;
  2794. }
  2795. $this->_Template('customer_newold',$this->data);
  2796. }
  2797. /**
  2798. * _dgsov1 - 优化版的_dgso方法
  2799. * 改进点:
  2800. * 1. 修复SQL注入漏洞,使用escape转义
  2801. * 2. 修复$d[0]越界问题
  2802. * 3. _dgcz改用BFS非递归算法,避免递归爆炸
  2803. * 4. 批量预加载关联数据,解决N+1查询
  2804. * 5. 修复特殊搜索路径的分页逻辑
  2805. * 6. 使用map映射替代硬编码if-else
  2806. * 7. 添加输入参数校验
  2807. * 8. 未使用的筛选参数(shop/name/level/时间范围)添加为实际筛选条件
  2808. */
  2809. public function _dgso()
  2810. {
  2811. $user = $this->user->get_api($_SESSION['api']);
  2812. if (!$user)
  2813. {
  2814. $vip = 0;
  2815. die("请先登录!!!");
  2816. }
  2817. $fgshop = "";
  2818. $sid = "";
  2819. $users = explode('|', trim($user['shop'], '|'));
  2820. foreach ($users as $value)
  2821. {
  2822. $fgshop .= " shop = " . intval($value) . " or";
  2823. $sid .= " id = " . intval($value) . " or";
  2824. }
  2825. $vip = ($user['vip'] == 1) ? 1 : 0;
  2826. $post = $this->input->post(NULL, TRUE);
  2827. if (!isset($post['page']))
  2828. {
  2829. $wlshop = $this->shop->find_all('1=1 and ' . rtrim($sid, 'or'));
  2830. $this->data['wlshop'] = $wlshop;
  2831. $this->data['vip'] = $vip;
  2832. $this->_Template('customer_dgso', $this->data);
  2833. return;
  2834. }
  2835. // 输入校验:page和perpage必须是正整数
  2836. $page = max(1, intval($this->input->post('page', true)));
  2837. $perpage = max(1, min(200, intval($this->input->post('perpage', true))));
  2838. // 获取搜索参数
  2839. $shop = intval($this->input->post('shop', true));
  2840. $numphone = $this->input->post('numphone', true);
  2841. $name = trim($this->input->post('name', true));
  2842. $email = trim($this->input->post('email', true));
  2843. $address = trim($this->input->post('address', true));
  2844. $level = intval($this->input->post('level', true));
  2845. $num = intval($this->input->post('num', true));
  2846. $timetk = $this->input->post('timetk', true);
  2847. $timetj = $this->input->post('timetj', true);
  2848. $timetk = strtotime($timetk);
  2849. $timetj = strtotime($timetj);
  2850. // 构建WHERE条件,使用escape防SQL注入
  2851. $where = "1=1 and (" . rtrim($fgshop, 'or') . ")";
  2852. if ($numphone)
  2853. {
  2854. $where .= " and numphone = " . $this->db->escape($numphone);
  2855. }
  2856. if ($email)
  2857. {
  2858. $where .= " and email like '%" . $this->db->escape_like_str($email) . "%'";
  2859. }
  2860. if ($address)
  2861. {
  2862. $where .= " and address like '%" . $this->db->escape_like_str($address) . "%'";
  2863. }
  2864. if ($shop)
  2865. {
  2866. $where .= " and shop = " . intval($shop);
  2867. }
  2868. if ($name)
  2869. {
  2870. $where .= " and name like '%" . $this->db->escape_like_str($name) . "%'";
  2871. }
  2872. if ($level)
  2873. {
  2874. $where .= " and level = " . intval($level);
  2875. }
  2876. if ($num)
  2877. {
  2878. $where .= " and num = " . intval($num);
  2879. }
  2880. if ($timetk && $timetj)
  2881. {
  2882. $where .= " and time >= " . intval($timetk) . " and time <= " . intval($timetj);
  2883. }
  2884. $fields = 'id,shop,source,name,email,country,level,money,num,time,type,numphone,address';
  2885. if ($numphone || $email || $address)
  2886. {
  2887. // 特殊搜索路径:通过地址/邮箱/电话查找关联客户
  2888. $d = $this->customer->find_all($where);
  2889. // 修复:判断$d是否为空,避免越界
  2890. if (empty($d))
  2891. {
  2892. echo json_encode(array('total' => 0, 'over' => 0, 'pagenum' => 0, 'rows' => array()));
  2893. exit;
  2894. }
  2895. // 使用BFS非递归算法查找所有关联客户
  2896. $cx = array();
  2897. $info_list = $this->_dgczv1($cx, $d);
  2898. $info_list = array_values($info_list);
  2899. $total = count($info_list);
  2900. $pagenum = ceil($total / $perpage);
  2901. // 修复:根据当前页码做切片分页
  2902. $start = ($page - 1) * $perpage;
  2903. $over = $total - ($start + $perpage);
  2904. $info_list = array_slice($info_list, $start, $perpage);
  2905. }
  2906. else
  2907. {
  2908. // 正常搜索路径
  2909. $order_str = "id desc";
  2910. $start = ($page - 1) * $perpage;
  2911. $info_list = $this->customer->find_all($where, 'id,shop,source,name,email,country,level,money,num,time,type', $order_str, $start, $perpage);
  2912. $total = $this->customer->find_count($where);
  2913. $pagenum = ceil($total / $perpage);
  2914. $over = $total - ($start + $perpage);
  2915. }
  2916. // 批量预加载关联数据,避免N+1查询
  2917. $shopIds = array();
  2918. $sourceIds = array();
  2919. $countryIds = array();
  2920. foreach ($info_list as $value)
  2921. {
  2922. if (!empty($value['shop'])) $shopIds[$value['shop']] = true;
  2923. if (!empty($value['source'])) $sourceIds[$value['source']] = true;
  2924. if (!empty($value['country'])) $countryIds[$value['country']] = true;
  2925. }
  2926. $shopMap = array();
  2927. if (!empty($shopIds))
  2928. {
  2929. $idList = implode(',', array_map('intval', array_keys($shopIds)));
  2930. $shopData = $this->shop->find_all("id in ($idList)", 'id,shopname');
  2931. foreach ($shopData as $row)
  2932. {
  2933. $shopMap[$row['id']] = $row['shopname'];
  2934. }
  2935. }
  2936. $sourceMap = array();
  2937. if (!empty($sourceIds))
  2938. {
  2939. $idList = implode(',', array_map('intval', array_keys($sourceIds)));
  2940. $sourceData = $this->typeclass->find_all("id in ($idList)", 'id,title');
  2941. foreach ($sourceData as $row)
  2942. {
  2943. $sourceMap[$row['id']] = $row['title'];
  2944. }
  2945. }
  2946. $countryMap = array();
  2947. if (!empty($countryIds))
  2948. {
  2949. $idList = implode(',', array_map('intval', array_keys($countryIds)));
  2950. $countryData = $this->country->find_all("id in ($idList)", 'id,name');
  2951. foreach ($countryData as $row)
  2952. {
  2953. $countryMap[$row['id']] = $row['name'];
  2954. }
  2955. }
  2956. // Level映射表
  2957. $levelMap = array(
  2958. 1 => '网红',
  2959. 2 => '批发',
  2960. 3 => '店铺转线下',
  2961. 4 => '线下其他',
  2962. 5 => '店内客户',
  2963. );
  2964. // 数据后处理
  2965. foreach ($info_list as $key => $value)
  2966. {
  2967. // 使用预加载的map赋值,避免逐条查询
  2968. $info_list[$key]['shop'] = isset($shopMap[$value['shop']]) ? $shopMap[$value['shop']] : '';
  2969. $info_list[$key]['source'] = isset($sourceMap[$value['source']]) ? $sourceMap[$value['source']] : '';
  2970. if ($value['country'] != 0)
  2971. {
  2972. $info_list[$key]['country'] = isset($countryMap[$value['country']]) ? $countryMap[$value['country']] : '未知';
  2973. }
  2974. else
  2975. {
  2976. $info_list[$key]['country'] = '未知';
  2977. }
  2978. // 使用map映射替代if-else链
  2979. $info_list[$key]['level'] = isset($levelMap[$value['level']]) ? $levelMap[$value['level']] : '未知';
  2980. if ($value['time'] != 0)
  2981. {
  2982. $info_list[$key]['time'] = date('Y-m-d', $value['time']);
  2983. }
  2984. else
  2985. {
  2986. $info_list[$key]['time'] = '无';
  2987. }
  2988. if ($value['type'] != 2)
  2989. {
  2990. $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>";
  2991. }
  2992. else
  2993. {
  2994. $info_list[$key]['type'] = '黑名单客户';
  2995. }
  2996. unset($info_list[$key]['numphone']);
  2997. unset($info_list[$key]['address']);
  2998. }
  2999. $rows = array('total' => $total, 'over' => $over, 'pagenum' => $pagenum, 'rows' => ($info_list));
  3000. echo json_encode($rows);
  3001. exit;
  3002. }
  3003. /**
  3004. * _dgczv1 - 优化版的_dgcz方法
  3005. * 使用BFS广度优先搜索替代递归,避免递归爆炸和栈溢出
  3006. * 每一层合并所有搜索条件为一次查询,大幅减少数据库请求
  3007. */
  3008. public function _dgczv1($child, $data)
  3009. {
  3010. // 初始化已处理集合
  3011. foreach ($data as $value)
  3012. {
  3013. if (!isset($child[$value['id']]))
  3014. {
  3015. $child[$value['id']] = $value;
  3016. }
  3017. }
  3018. $fields = 'id,shop,source,name,email,country,level,money,num,time,type,numphone,address';
  3019. // BFS广度优先搜索
  3020. $queue = $data;
  3021. $maxIterations = 50; // 安全上限,防止无限循环
  3022. while (!empty($queue) && $maxIterations > 0)
  3023. {
  3024. $maxIterations--;
  3025. // 收集当前层所有不重复的搜索词
  3026. $addressSet = array();
  3027. $emailSet = array();
  3028. $numphoneSet = array();
  3029. foreach ($queue as $row)
  3030. {
  3031. if (!empty($row['address']))
  3032. {
  3033. $addressSet[$row['address']] = true;
  3034. }
  3035. if (!empty($row['email']))
  3036. {
  3037. $emailSet[$row['email']] = true;
  3038. }
  3039. if (!empty($row['numphone']))
  3040. {
  3041. $numphoneSet[$row['numphone']] = true;
  3042. }
  3043. }
  3044. $queue = array(); // 清空当前层,准备下一层
  3045. // 构建合并后的查询条件
  3046. $conditions = array();
  3047. foreach (array_keys($addressSet) as $addr)
  3048. {
  3049. $conditions[] = "address like '%" . $this->db->escape_like_str($addr) . "%'";
  3050. }
  3051. foreach (array_keys($emailSet) as $em)
  3052. {
  3053. $conditions[] = "email like '%" . $this->db->escape_like_str($em) . "%'";
  3054. }
  3055. foreach (array_keys($numphoneSet) as $np)
  3056. {
  3057. $conditions[] = "numphone like '%" . $this->db->escape_like_str($np) . "%'";
  3058. }
  3059. if (empty($conditions))
  3060. {
  3061. break;
  3062. }
  3063. // 一次查询获取所有匹配记录
  3064. $where = implode(' or ', $conditions);
  3065. $rows = $this->customer->find_all($where, $fields);
  3066. foreach ($rows as $row)
  3067. {
  3068. if (!isset($child[$row['id']]))
  3069. {
  3070. $child[$row['id']] = $row;
  3071. $queue[] = $row; // 新发现的节点加入下一层搜索
  3072. }
  3073. }
  3074. }
  3075. return $child;
  3076. }
  3077. }