Customer.php 98 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838
  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()
  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. }