Customer.php 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138
  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. }
  25. //定义方法的调用规则 获取URI第二段值
  26. public function _remap($arg,$arg_array)
  27. {
  28. if($arg == 'add')//添加
  29. {
  30. $this->_add();
  31. }
  32. else if($arg == 'edit')//修改
  33. {
  34. $this->_edit($arg_array);
  35. }
  36. else if($arg == 'del')//黑名单
  37. {
  38. $this->_del();
  39. }
  40. else if($arg == 'change')//更改名单状态
  41. {
  42. $this->_change();
  43. }
  44. else if($arg == 'mdedit')//修改
  45. {
  46. $this->_mdedit($arg_array);
  47. }
  48. else if($arg == 'black')//黑名单
  49. {
  50. $this->_black();
  51. }
  52. else if($arg == 'excela')
  53. {
  54. $this->_excela();
  55. }
  56. else if($arg == 'excel')//下载excel
  57. {
  58. $this->_excel();
  59. }
  60. else if($arg == 'indexexcel')//下载excel
  61. {
  62. $this->_indexexcel();
  63. }
  64. else if($arg == 'down')//黑名单
  65. {
  66. $this->_down();
  67. }
  68. else if($arg == 'bankdown')//下载客户
  69. {
  70. $this->_bankdown();
  71. }
  72. else if($arg == 'newold')//新老客户比
  73. {
  74. $this->_newold();
  75. }
  76. else if($arg == 'dgso')
  77. {
  78. $this->_dgso();
  79. }
  80. else if($arg == 'cx')
  81. {
  82. $this->_cx();
  83. }
  84. else
  85. {
  86. $this->_index();
  87. }
  88. }
  89. //管理
  90. public function _index_xxxxxx()//通过索引订单查询购买次数,太慢,暂时抛弃
  91. {
  92. $user = $this->user->get_api($_SESSION['api']);
  93. if($user)
  94. {
  95. $fgshop = "";$sid = "";
  96. $user = explode('|',trim($user['shop'],'|'));
  97. foreach ($user as $value)
  98. {
  99. $fgshop .= " shop = ".$value." or";
  100. $sid .= " id = ".$value." or";
  101. }
  102. }
  103. $post = $this->input->post(NULL, TRUE);
  104. if(isset($post['page']))
  105. {
  106. $page = $this->input->post('page',true);
  107. $perpage = $this->input->post('perpage',true);
  108. $shop = $this->input->post('shop',true);
  109. $numphone = $this->input->post('numphone',true);
  110. $name = $this->input->post('name',true);
  111. $email = $this->input->post('email',true);
  112. $address = $this->input->post('address',true);
  113. $level = $this->input->post('level',true);
  114. $num = $this->input->post('num',true);
  115. $timetk = $this->input->post('timetk',true);
  116. $timetj = $this->input->post('timetj',true);
  117. $timetk = strtotime($timetk);
  118. $timetj = strtotime($timetj);
  119. $where = "1=1 and type = 1 and (".rtrim($fgshop,'or').")";
  120. if($shop)
  121. {
  122. $where .= " and shop = '$shop'";
  123. }
  124. if($numphone)
  125. {
  126. $where .= " and numphone = '$numphone'";
  127. }
  128. if($name)
  129. {
  130. $where .= " and name like '%$name%'";
  131. }
  132. if($email)
  133. {
  134. $where .= " and email like '%$email%'";
  135. }
  136. if($level)
  137. {
  138. $where .= " and level = '$level'";
  139. }
  140. if($address)
  141. {
  142. $where .= " and address like '%$address%'";
  143. }
  144. if($timetk && $timetj)
  145. {
  146. //$where .= " and ((time > '$timetk' and time < '$timetj') or time = 0)";
  147. $where .= " and ((time > '$timetk' and time < '$timetj') or time = '0')";
  148. }
  149. //数据排序
  150. $order_str = "id desc";
  151. $numdata = array();
  152. if(empty($page))
  153. {
  154. $start = 0;
  155. $perpage = 1;
  156. }
  157. else
  158. {
  159. $start = ($page - 1)*$perpage;
  160. }
  161. //取得信息列表
  162. if($num > 0)
  163. {
  164. $info_list = $this->customer->find_all($where,'id,shop,source,name,email,country,level,money,num,time,count,type',$order_str);
  165. }
  166. else
  167. {
  168. $info_list = $this->customer->find_all($where,'id,shop,source,name,email,country,level,money,num,time,count,type',$order_str,$start,$perpage);
  169. }
  170. foreach ($info_list as $key=>$value)
  171. {
  172. $shop = $this->shop->read($value['shop']);
  173. $info_list[$key]['shop'] = $shop['shopname'];
  174. $source = $this->typeclass->read($value['source']);
  175. $info_list[$key]['source'] = $source['title'];
  176. if($value['email'] != '0' && $value['email'] != '' && $value['email'] != '无')
  177. {
  178. $gnum = $this->fullorder->find_count("email = '".$value['email']."' and shop = '".$value['shop']."' and mergeid = 0 and buytime > '$timetk' and buytime < '$timetj'");
  179. }
  180. else
  181. {
  182. $gnum = 0;
  183. }
  184. $info_list[$key]['num'] = $gnum;
  185. if($value['country'] != 0)
  186. {
  187. $country = $this->country->read($value['country']);
  188. $info_list[$key]['country'] = $country['name'];
  189. }
  190. else
  191. {
  192. $info_list[$key]['country'] = "未知";
  193. }
  194. if($value['level'] == 1)
  195. {
  196. $info_list[$key]['level'] = "网红";
  197. }
  198. else if($value['level'] == 2)
  199. {
  200. $info_list[$key]['level'] = "批发";
  201. }
  202. else if($value['level'] == 3)
  203. {
  204. $info_list[$key]['level'] = "店铺转线下";
  205. }
  206. else if($value['level'] == 4)
  207. {
  208. $info_list[$key]['level'] = "线下其他";
  209. }
  210. else if($value['level'] == 5)
  211. {
  212. $info_list[$key]['level'] = "店内客户";
  213. }
  214. if($value['time'] != 0)
  215. {
  216. $info_list[$key]['time'] = date('Y-m-d',$value['time']);
  217. }
  218. else
  219. {
  220. $info_list[$key]['time'] = "无";
  221. }
  222. $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>";
  223. if($num >= '10' && $gnum >= '10')
  224. {
  225. $numdata[] = $info_list[$key];
  226. }
  227. else if ($num > '0' && $num < '10' && $gnum == $num)
  228. {
  229. $numdata[] = $info_list[$key];
  230. }
  231. }
  232. if($num > 0)
  233. {
  234. $info_list = array_slice($numdata,$start,$perpage);;
  235. $total = count($numdata);
  236. }
  237. else
  238. {
  239. $total = $this->customer->find_count($where);
  240. }
  241. $pagenum = ceil($total/$perpage);
  242. $over = $total-($start+$perpage);
  243. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  244. echo json_encode($rows);exit;
  245. }
  246. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  247. $this->data['wlshop'] = $wlshop;
  248. $this->_Template('customer',$this->data);
  249. }
  250. public function _index()//通过计数,2020/02/21已校准
  251. {
  252. $user = $this->user->get_api($_SESSION['api']);
  253. if($user)
  254. {
  255. $fgshop = "";$sid = "";
  256. $users = explode('|',trim($user['shop'],'|'));
  257. foreach ($users as $value)
  258. {
  259. $fgshop .= " shop = ".$value." or";
  260. $sid .= " id = ".$value." or";
  261. }
  262. if($user['vip'] == 1)
  263. {
  264. $vip = 1;
  265. }
  266. else
  267. {
  268. $vip = 0;
  269. }
  270. }
  271. else
  272. {
  273. $vip = 0;
  274. }
  275. $post = $this->input->post(NULL, TRUE);
  276. if(isset($post['page']))
  277. {
  278. $page = $this->input->post('page',true);
  279. $perpage = $this->input->post('perpage',true);
  280. $shop = $this->input->post('shop',true);
  281. $numphone = $this->input->post('numphone',true);
  282. $name = $this->input->post('name',true);
  283. $email = $this->input->post('email',true);
  284. $address = $this->input->post('address',true);
  285. $country = $this->input->post('country',true);
  286. $level = $this->input->post('level',true);
  287. $num = $this->input->post('num',true);
  288. $timetk = $this->input->post('timetk',true);
  289. $timetj = $this->input->post('timetj',true);
  290. $timetk = strtotime($timetk);
  291. $timetj = strtotime($timetj);
  292. $where = "1=1 and type = 1 and (".rtrim($fgshop,'or').")";
  293. if($shop)
  294. {
  295. $where .= " and shop = '$shop'";
  296. }
  297. if($numphone != '')
  298. {
  299. if($numphone == '0')
  300. {
  301. $where .= " and phone = '$numphone'" ;
  302. }
  303. else
  304. {
  305. $where .= " and numphone = '$numphone' and phone != ''" ;
  306. }
  307. }
  308. if($name)
  309. {
  310. $where .= " and name like '%$name%'";
  311. }
  312. if($country)
  313. {
  314. $where .= " and country = '$country'";
  315. }
  316. if($email)
  317. {
  318. $where .= " and email like '%$email%'";
  319. }
  320. if($level != '')
  321. {
  322. $where .= " and level = '$level'";
  323. }
  324. if($address)
  325. {
  326. $where .= " and address like '%$address%'";
  327. }
  328. if($num > 0 && $num < 10 && $num != '2a')
  329. {
  330. $where .= " and num = '$num'";
  331. }
  332. else if($num > 9)
  333. {
  334. $where .= " and num > '9'";
  335. }
  336. else if($num == '2a')
  337. {
  338. $where .= " and num > '1'";
  339. }
  340. else if($num == '0')
  341. {
  342. $where .= " and num = '0'";
  343. }
  344. else
  345. {
  346. $where .= " and num >= '0'";
  347. }
  348. if($timetk && $timetj)
  349. {
  350. $where .= " and ((time > '$timetk' and time < '$timetj') or time = '0')";
  351. }
  352. //数据排序
  353. $order_str = "time desc";
  354. $numdata = array();
  355. if(empty($page))
  356. {
  357. $start = 0;
  358. $perpage = 1;
  359. }
  360. else
  361. {
  362. $start = ($page - 1)*$perpage;
  363. }
  364. //取得信息列表
  365. $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);
  366. foreach ($info_list as $key=>$value)
  367. {
  368. $shop = $this->shop->read($value['shop']);
  369. $info_list[$key]['shop'] = $shop['shopname'];
  370. $source = $this->typeclass->read($value['source']);
  371. $info_list[$key]['source'] = $source['title'];
  372. if($value['country'] != 0)
  373. {
  374. $country = $this->country->read($value['country']);
  375. $info_list[$key]['country'] = $country['name'];
  376. }
  377. else
  378. {
  379. $info_list[$key]['country'] = "未知";
  380. }
  381. if($value['level'] == 1)
  382. {
  383. $info_list[$key]['level'] = "网红";
  384. }
  385. else if($value['level'] == 2)
  386. {
  387. $info_list[$key]['level'] = "批发";
  388. }
  389. else if($value['level'] == 3)
  390. {
  391. $info_list[$key]['level'] = "店铺转线下";
  392. }
  393. else if($value['level'] == 4)
  394. {
  395. $info_list[$key]['level'] = "线下其他";
  396. }
  397. else if($value['level'] == 5)
  398. {
  399. $info_list[$key]['level'] = "店内客户";
  400. }
  401. else
  402. {
  403. $info_list[$key]['level'] = "未定义";
  404. }
  405. if($value['time'] != 0)
  406. {
  407. $info_list[$key]['time'] = date('Y-m-d',$value['time']);
  408. }
  409. else
  410. {
  411. $info_list[$key]['time'] = "无";
  412. }
  413. //$gmcs = $this->fullorder->find_count("email = '".$value['email']."' time > '$timetk' and time < '$timetj'");
  414. //$info_list[$key]['num'] = $gmcs;
  415. $info_list[$key]['numphone'] = ($value['num'] > 0)?sprintf("%01.2f",$value['money']/$value['num']):0;
  416. $info_list[$key]['type'] = "<p><a href='javascript:void(0);' class='window' data-h='/customer/mdedit/".$value['id']."' data-t='客户下单'><b>下单</b></a></p><a class='customer' data-type='2' data-t='yr' data-id='".$value['id']."' href='javascript:void(0);'>移入黑名单</a>";
  417. }
  418. $total = $this->customer->find_count($where);
  419. $pagenum = ceil($total/$perpage);
  420. $over = $total-($start+$perpage);
  421. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  422. echo json_encode($rows);exit;
  423. }
  424. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  425. $this->data['wlshop'] = $wlshop;
  426. $this->data['vip'] = $vip;
  427. $this->_Template('customer',$this->data);
  428. }
  429. public function _dgso()
  430. {
  431. $user = $this->user->get_api($_SESSION['api']);
  432. if($user)
  433. {
  434. $fgshop = "";$sid = "";
  435. $users = explode('|',trim($user['shop'],'|'));
  436. foreach ($users as $value)
  437. {
  438. $fgshop .= " shop = ".$value." or";
  439. $sid .= " id = ".$value." or";
  440. }
  441. if($user['vip'] == 1)
  442. {
  443. $vip = 1;
  444. }
  445. else
  446. {
  447. $vip = 0;
  448. }
  449. }
  450. else
  451. {
  452. $vip = 0;
  453. }
  454. $post = $this->input->post(NULL, TRUE);
  455. if(isset($post['page']))
  456. {
  457. $page = $this->input->post('page',true);
  458. $perpage = $this->input->post('perpage',true);
  459. $shop = $this->input->post('shop',true);
  460. $numphone = $this->input->post('numphone',true);
  461. $name = $this->input->post('name',true);
  462. $email = $this->input->post('email',true);
  463. $address = $this->input->post('address',true);
  464. $level = $this->input->post('level',true);
  465. $num = $this->input->post('num',true);
  466. $timetk = $this->input->post('timetk',true);
  467. $timetj = $this->input->post('timetj',true);
  468. $timetk = strtotime($timetk);
  469. $timetj = strtotime($timetj);
  470. $where = "1=1 and (".rtrim($fgshop,'or').")";
  471. if($numphone)
  472. {
  473. $where .= " and numphone = '$numphone'";
  474. }
  475. if($email)
  476. {
  477. $where .= " and email like '%$email%'";
  478. }
  479. if($address)
  480. {
  481. $where .= " and address like '%$address%'";
  482. }
  483. if($numphone || $email || $address)
  484. {
  485. $d = $this->customer->find_all($where);
  486. $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');
  487. //$temp_key = array_column($data,'id'); //键值
  488. //$Newdata = array_combine($temp_key,$data) ;
  489. $cx = array();
  490. $info_list = $this->_dgcz($cx,$data);
  491. $info_list = array_values($info_list);
  492. $total = count($info_list);
  493. $pagenum = ceil($total/$perpage);
  494. $over = $total-$perpage;
  495. }
  496. else
  497. {
  498. //数据排序
  499. $order_str = "id desc";
  500. $numdata = array();
  501. if(empty($page))
  502. {
  503. $start = 0;
  504. $perpage = 1;
  505. }
  506. else
  507. {
  508. $start = ($page - 1)*$perpage;
  509. }
  510. //取得信息列表
  511. $info_list = $this->customer->find_all($where,'id,shop,source,name,email,country,level,money,num,time,type',$order_str,$start,$perpage);
  512. $total = $this->customer->find_count($where);
  513. $pagenum = ceil($total/$perpage);
  514. $over = $total-($start+$perpage);
  515. }
  516. foreach ($info_list as $key=>$value)
  517. {
  518. $shop = $this->shop->read($value['shop']);
  519. $info_list[$key]['shop'] = $shop['shopname'];
  520. $source = $this->typeclass->read($value['source']);
  521. $info_list[$key]['source'] = $source['title'];
  522. if($value['country'] != 0)
  523. {
  524. $country = $this->country->read($value['country']);
  525. $info_list[$key]['country'] = $country['name'];
  526. }
  527. else
  528. {
  529. $info_list[$key]['country'] = "未知";
  530. }
  531. if($value['level'] == 1)
  532. {
  533. $info_list[$key]['level'] = "网红";
  534. }
  535. else if($value['level'] == 2)
  536. {
  537. $info_list[$key]['level'] = "批发";
  538. }
  539. else if($value['level'] == 3)
  540. {
  541. $info_list[$key]['level'] = "店铺转线下";
  542. }
  543. else if($value['level'] == 4)
  544. {
  545. $info_list[$key]['level'] = "线下其他";
  546. }
  547. else if($value['level'] == 5)
  548. {
  549. $info_list[$key]['level'] = "店内客户";
  550. }
  551. if($value['time'] != 0)
  552. {
  553. $info_list[$key]['time'] = date('Y-m-d',$value['time']);
  554. }
  555. else
  556. {
  557. $info_list[$key]['time'] = "无";
  558. }
  559. if($value['type'] != 2)
  560. {
  561. $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>";
  562. }
  563. else
  564. {
  565. $info_list[$key]['type'] = "黑名单客户";
  566. }
  567. unset($info_list[$key]['numphone']);
  568. unset($info_list[$key]['address']);
  569. }
  570. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  571. echo json_encode($rows);exit;
  572. }
  573. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  574. $this->data['wlshop'] = $wlshop;
  575. $this->data['vip'] = $vip;
  576. $this->_Template('customer_dgso',$this->data);
  577. }
  578. public function _dgcz($child,$data)
  579. {
  580. foreach ($data as $key => $value)
  581. {
  582. if (!isset($child[$value['id']]))
  583. {
  584. $child[$value['id']] = $value;
  585. $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');
  586. $this->_dgcz($child,$rows);
  587. }
  588. }
  589. return $child;
  590. }
  591. //管理
  592. public function _black()
  593. {
  594. /**
  595. $user = $this->user->get_api($_SESSION['api']);
  596. if($user)
  597. {
  598. $fgshop = "";$sid = "";
  599. $user = explode('|',trim($user['shop'],'|'));
  600. foreach ($user as $value)
  601. {
  602. $fgshop .= " shop = ".$value." or";
  603. $sid .= " id = ".$value." or";
  604. }
  605. }
  606. **/
  607. $post = $this->input->post(NULL, TRUE);
  608. if(isset($post['page']))
  609. {
  610. $page = $this->input->post('page',true);
  611. $perpage = $this->input->post('perpage',true);
  612. $shop = $this->input->post('shop',true);
  613. $numphone = $this->input->post('numphone',true);
  614. $name = $this->input->post('name',true);
  615. $email = $this->input->post('email',true);
  616. $address = $this->input->post('address',true);
  617. $xtime = $this->input->post('xtime',true);
  618. //$where = "1=1 and type = 2 and (".rtrim($fgshop,'or').")";
  619. $timetk = $this->input->post('timetk',true);
  620. $timetj = $this->input->post('timetj',true);
  621. $timetk = strtotime($timetk);
  622. $timetj = strtotime($timetj);
  623. $where = "1=1 and type = 2";
  624. if($shop)
  625. {
  626. $where .= " and shop = '$shop'";
  627. }
  628. if($xtime)
  629. {
  630. $where .= " and typetime > '$timetk' and typetime < '$timetj'";
  631. }
  632. if($numphone != '')
  633. {
  634. if($numphone == '0')
  635. {
  636. $where .= " and phone = '$numphone'" ;
  637. }
  638. else
  639. {
  640. $where .= " and numphone = '$numphone' and phone != ''" ;
  641. }
  642. }
  643. if($name)
  644. {
  645. $where .= " and name like '%$name%'";
  646. }
  647. if($email)
  648. {
  649. $where .= " and email like '%$email%'";
  650. }
  651. $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));
  652. $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));
  653. $hmdaddress3 = str_replace(array(' avenue',' ave',' av'),array(' ave',' avenue',' ave'),strtolower($address));
  654. if($address)
  655. {
  656. $where .= " and (address like '%$address%' or address like '%$hmdaddress1%' or address like '%$hmdaddress2%' or address like '%$hmdaddress3%')";
  657. }
  658. //数据排序
  659. $order_str = "id desc";
  660. if(empty($page))
  661. {
  662. $start = 0;
  663. $perpage = 1;
  664. }
  665. else
  666. {
  667. $start = ($page - 1)*$perpage;
  668. }
  669. //取得信息列表
  670. $info_list = $this->customer->find_all($where,'id,shop,source,name,email,address,phone,count,typetime,type',$order_str,$start,$perpage);
  671. foreach ($info_list as $key=>$value)
  672. {
  673. $shop = $this->shop->read($value['shop']);
  674. $info_list[$key]['shop'] = $shop['shopname'];
  675. $source = $this->typeclass->read($value['source']);
  676. $info_list[$key]['source'] = $source['title'];
  677. if($value['typetime'] > 0)
  678. {
  679. $info_list[$key]['typetime'] = date('Y-m-d',$value['typetime']);
  680. }
  681. else
  682. {
  683. $info_list[$key]['typetime'] = '无';
  684. }
  685. $info_list[$key]['type'] = "<a class='customer' data-type='1' data-t='yc' data-id='".$value['id']."' href='javascript:void(0);'>移出</a>";
  686. }
  687. $total = $this->customer->find_count($where);
  688. $pagenum = ceil($total/$perpage);
  689. $over = $total-($start+$perpage);
  690. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'a'=>$hmdaddress1);
  691. echo json_encode($rows);exit;
  692. }
  693. if(isset($post['s']))
  694. {
  695. $id_arr = $this->input->post('s');
  696. $id_arr = explode(',',$id_arr);
  697. if(!$id_arr)
  698. {
  699. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  700. }
  701. //循环删除记录
  702. foreach ($id_arr as $v)
  703. {
  704. $this->customer->remove($v);
  705. }
  706. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));exit;
  707. }
  708. //$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  709. $wlshop = $this->shop->find_all('1=1');
  710. $this->data['wlshop'] = $wlshop;
  711. $this->_Template('customer_black',$this->data);
  712. }
  713. public function _cx()
  714. {
  715. $post = $this->input->post(NULL, TRUE);
  716. if(isset($post['page']))
  717. {
  718. $page = $this->input->post('page',true);
  719. $perpage = $this->input->post('perpage',true);
  720. $shop = $this->input->post('shop',true);
  721. $numphone = $this->input->post('numphone',true);
  722. $name = $this->input->post('name',true);
  723. $email = $this->input->post('email',true);
  724. $address = $this->input->post('address',true);
  725. $xtime = $this->input->post('xtime',true);
  726. //$where = "1=1 and type = 2 and (".rtrim($fgshop,'or').")";
  727. $timetk = $this->input->post('timetk',true);
  728. $timetj = $this->input->post('timetj',true);
  729. $timetk = strtotime($timetk);
  730. $timetj = strtotime($timetj);
  731. $where = "1=1 and type = 2";
  732. if($shop)
  733. {
  734. $where .= " and shop = '$shop'";
  735. }
  736. if($xtime)
  737. {
  738. $where .= " and typetime > '$timetk' and typetime < '$timetj'";
  739. }
  740. if($numphone)
  741. {
  742. $where .= " and numphone = '$numphone'";
  743. }
  744. if($name)
  745. {
  746. $where .= " and name like '%$name%'";
  747. }
  748. if($email)
  749. {
  750. $where .= " and email like '%$email%'";
  751. }
  752. $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));
  753. $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));
  754. $hmdaddress3 = str_replace(array(' avenue',' ave',' av'),array(' ave',' avenue',' ave'),strtolower($address));
  755. if($address)
  756. {
  757. $where .= " and (address like '%$address%' or address like '%$hmdaddress1%' or address like '%$hmdaddress2%' or address like '%$hmdaddress3%')";
  758. }
  759. //数据排序
  760. $order_str = "id desc";
  761. if(empty($page))
  762. {
  763. $start = 0;
  764. $perpage = 1;
  765. }
  766. else
  767. {
  768. $start = ($page - 1)*$perpage;
  769. }
  770. //取得信息列表
  771. $info_list = $this->customer->find_all($where,'id,shop,source,name,email,address,phone,count,typetime',$order_str,$start,$perpage);
  772. foreach ($info_list as $key=>$value)
  773. {
  774. $shop = $this->shop->read($value['shop']);
  775. $info_list[$key]['shop'] = $shop['shopname'];
  776. $source = $this->typeclass->read($value['source']);
  777. $info_list[$key]['source'] = $source['title'];
  778. if($value['typetime'] > 0)
  779. {
  780. $info_list[$key]['typetime'] = date('Y-m-d',$value['typetime']);
  781. }
  782. else
  783. {
  784. $info_list[$key]['typetime'] = '无';
  785. }
  786. }
  787. $total = $this->customer->find_count($where);
  788. $pagenum = ceil($total/$perpage);
  789. $over = $total-($start+$perpage);
  790. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'a'=>$hmdaddress1);
  791. echo json_encode($rows);exit;
  792. }
  793. if(isset($post['s']))
  794. {
  795. $id_arr = $this->input->post('s');
  796. $id_arr = explode(',',$id_arr);
  797. if(!$id_arr)
  798. {
  799. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  800. }
  801. //循环删除记录
  802. foreach ($id_arr as $v)
  803. {
  804. $this->customer->remove($v);
  805. }
  806. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));exit;
  807. }
  808. $wlshop = $this->shop->find_all('1=1');
  809. $this->data['wlshop'] = $wlshop;
  810. $this->_Template('customer_black_cx',$this->data);
  811. }
  812. //添加
  813. public function _add()
  814. {
  815. $user = $this->user->get_api($_SESSION['api']);
  816. if($user)
  817. {
  818. $fgshop = "";$sid = "";
  819. $user = explode('|',trim($user['shop'],'|'));
  820. foreach ($user as $value)
  821. {
  822. $fgshop .= " shop = ".$value." or";
  823. $sid .= " id = ".$value." or";
  824. }
  825. }
  826. $post = $this->input->post(NULL, TRUE);
  827. if(isset($post['shop']))
  828. {
  829. $post['shop'] = $this->input->post('shop',true);
  830. $post['source'] = $this->input->post('source',true);
  831. $post['level'] = $this->input->post('level',true);
  832. $post['country'] = $this->input->post('country',true);
  833. $name = $this->input->post('name',true);
  834. $post['name'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$name);
  835. $post['phone'] = $this->input->post('phone',true);
  836. $email = $this->input->post('email',true);
  837. $post['email'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$email);
  838. $post['province'] = $this->input->post('province',true);
  839. $post['city'] = $this->input->post('city',true);
  840. //$post['street'] = $this->input->post('street',true);
  841. $address = $this->input->post('address',true);
  842. $post['address'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$address);
  843. //$post['address2'] = $this->input->post('address2',true);
  844. $post['count'] = $this->input->post('count',true);
  845. $str = $post['phone'];
  846. if(!$post['shop'])
  847. {
  848. echo json_encode(array('msg'=>'店铺不能为空!','success'=>false));exit;
  849. }
  850. preg_match_all('/[0-9]/u',$str,$result);
  851. $numphone = join('',$result[0]);
  852. $post['numphone'] = $numphone;
  853. $post['zhcx'] = $post['shop'].'-'.$post['email'];
  854. $kh = $this->customer->get_email($post['email'],$post['shop']);
  855. if($kh)
  856. {
  857. echo json_encode(array('msg'=>'此客户已存在!','success'=>false));exit;
  858. }
  859. if($this->customer->insert($post))
  860. {
  861. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  862. }
  863. else
  864. {
  865. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  866. }
  867. }
  868. $country = $this->country->find_all('1=1','id,name','name asc');
  869. $this->data['country'] = $country;
  870. $wlshop = $this->shop->find_all("type = 269 and (".rtrim($sid,'or').")");
  871. $this->data['wlshop'] = $wlshop;
  872. $this->_Template('customer_add',$this->data);
  873. }
  874. //修改
  875. public function _edit($arg_array)
  876. {
  877. $user = $this->user->get_api($_SESSION['api']);
  878. if($user)
  879. {
  880. $fgshop = "";$sid = "";
  881. $user = explode('|',trim($user['shop'],'|'));
  882. foreach ($user as $value)
  883. {
  884. $fgshop .= " shop = ".$value." or";
  885. $sid .= " id = ".$value." or";
  886. }
  887. }
  888. $post = $this->input->post(NULL, TRUE);
  889. if(isset($post['id']))
  890. {
  891. $id = $this->input->post('id',true);
  892. $us = $this->customer->read($id);
  893. $post['shop'] = $this->input->post('shop',true);
  894. $post['source'] = $this->input->post('source',true);
  895. $post['level'] = $this->input->post('level',true);
  896. $post['country'] = $this->input->post('country',true);
  897. $name = $this->input->post('name',true);
  898. $post['name'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$name);
  899. $post['phone'] = $this->input->post('phone',true);
  900. $email = $this->input->post('email',true);
  901. $post['email'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$email);
  902. $post['province'] = $this->input->post('province',true);
  903. $post['city'] = $this->input->post('city',true);
  904. //$post['street'] = $this->input->post('street',true);
  905. $address = $this->input->post('address',true);
  906. $post['address'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$address);
  907. //$post['address2'] = $this->input->post('address2',true);
  908. $post['type'] = $this->input->post('type',true);
  909. $post['count'] = $this->input->post('count',true);
  910. $str = $post['phone'];
  911. preg_match_all('/[0-9]/u',$str,$result);
  912. $numphone = join('',$result[0]);
  913. $post['numphone'] = $numphone;
  914. $post['zhcx'] = $post['shop'].'-'.$post['email'];
  915. if($this->customer->save($post,$id))
  916. {
  917. echo json_encode(array('msg'=>'操作成功!','success'=>true));exit;
  918. }
  919. else
  920. {
  921. echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
  922. }
  923. }
  924. $arg_array = $arg_array[0];
  925. $customer = $this->customer->read($arg_array);
  926. $this->data['customer'] = $customer;
  927. $country = $this->country->find_all('1=1','id,name','name asc');
  928. $this->data['country'] = $country;
  929. $wlshop = $this->shop->find_all("type = 269 and (".rtrim($sid,'or').")");
  930. $this->data['wlshop'] = $wlshop;
  931. if($customer['email'] != '0' && $customer['email'] != '' && $customer['email'] != '无')
  932. {
  933. $fdata = $this->fullorder->find_all('email = "'.$customer['email'].'" and shop = "'.$customer['shop'].'" and mergeid = 0','orderinfo,state,product,name,email,dtime,shouldmoney','id desc');
  934. foreach ($fdata as $k=>$v)
  935. {
  936. $d = $this->fullorder->get_orderinfo($v['orderinfo']);
  937. $fdata[$k]['orderinfo'] = "<a href='/fullorder/readonly/".$d['id']."'>".$v['orderinfo']."</a>";
  938. $typeclass = $this->typeclass->read($v['state']);
  939. $fdata[$k]['state'] = $typeclass['spare'];
  940. $fdata[$k]['dtime'] = date('Y-m-d',$v['dtime']);
  941. }
  942. $this->data['data'] = $fdata;
  943. }
  944. $this->_Template('customer_edit',$this->data);
  945. }
  946. //删除
  947. public function _del()
  948. {
  949. $post = $this->input->post(NULL, TRUE);
  950. if(isset($post['s']))
  951. {
  952. $id_arr = $this->input->post('s');
  953. $id_arr = explode(',',$id_arr);
  954. if(!$id_arr)
  955. {
  956. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  957. }
  958. //循环删除记录
  959. $a=0;
  960. foreach ($id_arr as $v)
  961. {
  962. $customer = $this->customer->read($v);
  963. if($customer['email'] != '0' && $customer['email'] != '' && $customer['email'] != '无')
  964. {
  965. $fdata = $this->fullorder->find_count('email = "'.$customer['email'].'" and shop = "'.$customer['shop'].'" and mergeid = 0');
  966. }
  967. if($fdata > 0)
  968. {
  969. $a++;
  970. continue;
  971. }
  972. else
  973. {
  974. $this->customer->remove($v);
  975. }
  976. }
  977. if($a > 0)
  978. {
  979. echo json_encode(array('del'=>$id_arr,'msg'=>'无订单客户删除成功,有订单的客户无法删除!','success'=>true));
  980. }
  981. else
  982. {
  983. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  984. }
  985. }
  986. }
  987. //操作
  988. public function _change()
  989. {
  990. $post = $this->input->post(NULL, TRUE);
  991. if(isset($post['type']))
  992. {
  993. $type = $this->input->post('type',true);
  994. $id = $this->input->post('id',true);
  995. $count = $this->input->post('count',true);
  996. if($this->customer->save(array('type'=>$type,'count'=>$count,'typetime'=>time()),$id))
  997. {
  998. echo json_encode(array('msg'=>'操作成功!','success'=>true));exit;
  999. }
  1000. else
  1001. {
  1002. echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
  1003. }
  1004. }
  1005. }
  1006. //修改客户分类
  1007. public function _mdedit($arg_array)
  1008. {
  1009. $user = $this->user->get_api($_SESSION['api']);
  1010. if($user)
  1011. {
  1012. $uu = $user;
  1013. $fgshop = "";$sid = "";
  1014. $u = $user;
  1015. $user = explode('|',trim($user['shop'],'|'));
  1016. foreach ($user as $value)
  1017. {
  1018. $fgshop .= " shop = ".$value." or";
  1019. $sid .= " id = ".$value." or";
  1020. }
  1021. }
  1022. $post = $this->input->post(NULL, TRUE);
  1023. if(isset($post['shop']))
  1024. {
  1025. $fpcount = $this->input->post('fpcount',true);
  1026. if(!$fpcount)
  1027. {
  1028. echo json_encode(array('msg'=>'需要先清理浏览器缓存,刷新当前页面后再试!','success'=>false));exit;
  1029. }
  1030. $customerid = $this->input->post('customerid',true);
  1031. $shop = $this->input->post('shop',true);
  1032. $sp = $this->shop->read($shop);
  1033. $num = $this->fullorder->find_count('shop = "'.$sp['id'].'" and gtime = "'.date('Ymd',time()).'"');
  1034. $post['source'] = 1;//订单类型:1.线下订单2.PC3.手机
  1035. $post['state'] = 207;//订单状态:207等待发货
  1036. $post['review'] = 2;//审核状态:1.未送审2.待审核3.不通过4取消重审5.审核通过6.自动通过
  1037. $post['print'] = 1;//打印状态:1.不可打印2.未打印3.已打印
  1038. $post['library'] = 1;//出库状态:1.未出库2.已出库3.已退库
  1039. $post['libraryconfirm'] = 1;//出库确认:1.不允许2.允许
  1040. $post['link'] = $sp['link'];
  1041. $post['issku'] = $sp['sku'];
  1042. if($post['print'] != 3)
  1043. {
  1044. $post['librarynot'] = "订单未打印,未审核或未通过";//不能出库原因
  1045. }
  1046. $orderinfo = $this->input->post('orderinfo',true);
  1047. $post['shop'] = $sp['id'];
  1048. $post['user'] = $sp['shopuser'];
  1049. $post['number'] = $sp['shortname'].'-'.substr(date('ymd',time()),1).'-'.(substr(strval($num+1+1000),1,3));//编号
  1050. if($orderinfo != "")
  1051. {
  1052. $ordefin = $this->fullorder->get_orderinfo($orderinfo);
  1053. if($ordefin)
  1054. {
  1055. echo json_encode(array('msg'=>'订单号重复!','success'=>false));exit;
  1056. }
  1057. else
  1058. {
  1059. $post['orderinfo'] = $orderinfo;
  1060. }
  1061. }
  1062. else
  1063. {
  1064. $post['orderinfo'] = $sp['id'].date('ymdHis',time()).rand(0,1);//订单号
  1065. }
  1066. if($post['paypal'] != '')
  1067. {
  1068. $pp = $this->fullorder->get_paypal($post['paypal']);
  1069. if($pp)
  1070. {
  1071. echo json_encode(array('msg'=>'此交易号的订单已存在!','success'=>false));exit;
  1072. }
  1073. }
  1074. $post['client'] = $this->input->post('client',true);//客户名称
  1075. $btime = $this->input->post('buytime',true);//付款时间
  1076. $post['buytime'] = strtotime($btime);//时间转UX
  1077. $post['dtime'] = time();//订单时间
  1078. $post['gtime'] = date('Ymd',time());//格式化时间
  1079. $post['pay'] = $this->input->post('pay',true);//支付方式
  1080. $post['capital'] = $this->input->post('capital',true);//资金状态
  1081. $post['type'] = $this->input->post('warehouse',true);//发货仓库
  1082. $post['currency'] = $this->input->post('currency',true);//币种
  1083. $currency = $this->typeclass->read($post['currency']);
  1084. $post['currencytitle'] = $currency['title'];//币种名称
  1085. $post['freight'] = $this->input->post('freight',true);//运费
  1086. $post['expressmoney'] = $this->input->post('expressmoney',true);//物流金额
  1087. $post['shouldmoney'] = $this->input->post('shouldmoney',true);//应收金额
  1088. $post['skje'] = $post['shouldmoney'];//收款金额
  1089. $product = $this->input->post('product');//产品名称
  1090. $product = str_replace(array('%26','%2B'),array('&','+'),$product);
  1091. $post['product'] = preg_replace('/( | | |\s)/',' ',$product);
  1092. $orderremarks = $this->input->post('orderremarks');//订单备注
  1093. $orderremarks = str_replace(array('%26','%2B'),array('&','+'),$orderremarks);
  1094. $post['orderremarks'] = preg_replace('/( | | |\s)/',' ',$orderremarks);
  1095. $shipremarks = $this->input->post('shipremarks');//仓库品名
  1096. $shipremarks = str_replace(array('%26','%2B'),array('&','+'),$shipremarks);//仓库品名
  1097. $post['shipremarks'] = preg_replace('/( | | |\s)/',' ',$shipremarks);
  1098. $post['email'] = $this->input->post('email',true);//邮箱
  1099. $name = $this->input->post('name',true);//名称
  1100. $post['name'] = preg_replace('/( | | |\s)/',' ',$name);
  1101. $post['phone'] = $this->input->post('phone',true);//电话
  1102. $post['phone'] = preg_replace('/\D/s','',$post['phone']);
  1103. $post['country'] = $this->input->post('country',true);//国家
  1104. $ct = $this->country->read($post['country']);//国家
  1105. $post['al'] = $ct['lb'];//国家二字码
  1106. $post['province'] = $this->input->post('province',true);//省、州
  1107. $post['province'] = preg_replace("/^[\s\v".chr(227).chr(128)."]+/","", $post['province']); //替换开头空字符
  1108. $post['province'] = preg_replace("/[\s\v".chr(227).chr(128)."]+$/","", $post['province']); //替换结尾空字符
  1109. $post['city'] = $this->input->post('city',true);//城市
  1110. $post['city'] = preg_replace("/^[\s\v".chr(227).chr(128)."]+/","", $post['city']); //替换开头空字符
  1111. $post['city'] = preg_replace("/[\s\v".chr(227).chr(128)."]+$/","", $post['city']); //替换结尾空字符
  1112. $post['zipcode'] = $this->input->post('zipcode',true);//邮编
  1113. $post['zipcode'] = preg_replace("/^[\s\v".chr(227).chr(128)."]+/","", $post['zipcode']); //替换开头空字符
  1114. $post['zipcode'] = preg_replace("/[\s\v".chr(227).chr(128)."]+$/","", $post['zipcode']); //替换结尾空字符
  1115. $post['address'] = $this->input->post('address',true);//地址
  1116. $post['printtype'] = $this->input->post('printtype',true);//打印类型
  1117. $fpdata = $this->input->post('fpdata');//购买产品内容
  1118. $fpdata = str_replace(array('%26','%2B'),array('&','+'),$fpdata);
  1119. $post['fpdata'] = $fpdata;
  1120. $post['sbpm'] = $this->input->post('sbpm',true);//申报品名
  1121. $post['zwpm'] = $this->input->post('zwpm',true);//中文品名
  1122. $post['ts'] = $this->input->post('ts',true);//条数
  1123. $post['dtsbjz'] = $this->input->post('dtsbjz',true);//单条申报价
  1124. $post['zsbjz'] = $this->input->post('zsbjz',true);//总申报价
  1125. $post['zzl'] = $this->input->post('zzl',true);//总重量
  1126. $post['zjs'] = $this->input->post('zjs',true);//总件数
  1127. $post['express'] = $this->input->post('express',true);//快递公司
  1128. $post['printtype'] = $this->input->post('printtype',true);//打印类型
  1129. $post['quantity'] = $this->input->post('quantity',true);//数量
  1130. $post['paypal'] = $this->input->post('paypal',true);//支付号
  1131. $post['guarantee'] = $this->input->post('guarantee',true);//卖家保障
  1132. $post['msg'] = $this->input->post('msg',true);//发送留言类型
  1133. $post['ioss'] = $this->input->post('ioss',true);
  1134. $post['sbpm'] = $this->input->post('sbpm',true);
  1135. $pay = $this->pay->get_typeclass($post['pay']);
  1136. $yga = $post['shouldmoney'];
  1137. $post['budget'] = 0;
  1138. if($pay)
  1139. {
  1140. $ygc = $pay['estimaterate'];//预估到账公式
  1141. $ifbudget = eval("return $yga*1.$ygc;");
  1142. $post['estimaterate'] = $pay['estimaterate'];
  1143. if($ifbudget > 0)
  1144. {
  1145. $post['budget'] = eval("return $yga*1.$ygc;");//预估到帐金额
  1146. }
  1147. }
  1148. else
  1149. {
  1150. $ygb = $sp['estimaterate'];//店铺默认到账公式
  1151. $ifbudget = eval("return $yga*1.$ygb;");
  1152. $post['estimaterate'] = $sp['estimaterate'];
  1153. if($ifbudget > 0)
  1154. {
  1155. $post['budget'] = eval("return $yga*1.$ygb;");//预估到帐金额
  1156. }
  1157. }
  1158. $baddress = $this->input->post('baddress',true);
  1159. $saddress = $this->input->post('saddress',true);
  1160. $baddress = array_reverse(explode(',',$baddress));
  1161. $saddress = array_reverse(explode(',',$saddress));
  1162. $bar = '';$sar = '';
  1163. $cr = $this->country->read($post['country']);
  1164. $baddress[1] = $cr['lb'];
  1165. $saddress[1] = $cr['lb'];
  1166. $baddress = array_reverse($baddress);
  1167. $saddress = array_reverse($saddress);
  1168. for($i=0;$i<count($baddress);$i++)
  1169. {
  1170. $bar .= $baddress[$i].',';
  1171. }
  1172. for($i=0;$i<count($saddress);$i++)
  1173. {
  1174. $sar .= $saddress[$i].',';
  1175. }
  1176. $post['baddress'] = rtrim($bar,',');//卖家保障
  1177. $post['saddress'] = rtrim($sar,',');//卖家保障
  1178. $whlabel = $this->input->post('whlabel',true);
  1179. if($post['express'] == 2 && (stripos($post['name'],'&') !== false || stripos($post['name'],"'") !== false))
  1180. {
  1181. echo json_encode(array('msg'=>'USPS收件人或公司名不可用特殊符号!','success'=>false));exit;
  1182. }
  1183. if(strlen($post['client']) > 35 || strlen($post['name']) > 35)//收件人姓名或公司名不允许超过35位
  1184. {
  1185. echo json_encode(array('msg'=>'收件人姓名或公司名不可超过35个字符!','success'=>false));exit;
  1186. }
  1187. if(($post['express'] == '5' || $post['express'] == '24' || $post['express'] == '42' || $post['express'] == '31') && $post['country'] != 192)
  1188. {
  1189. echo json_encode(array('msg'=>'非美国无法选择Fedex、DHL官方-美国!','success'=>false));exit;
  1190. }
  1191. if($post['express'] == '3' && $post['country'] != 192 && $post['country'] != 35)
  1192. {
  1193. echo json_encode(array('msg'=>'非美国和加拿大无法选择UPS!','success'=>false));exit;
  1194. }
  1195. if($post['express'] == '3' && $post['country'] == 35 && $post['zsbjz'] > 20)
  1196. {
  1197. echo json_encode(array('msg'=>'UPS加拿大最高申报不可超过20','success'=>false));exit;
  1198. }
  1199. if($post['express'] == '2' && $post['warehouse'] != 5)
  1200. {
  1201. echo json_encode(array('msg'=>'非美国仓无法选择USPS!','success'=>false));exit;
  1202. }
  1203. if($post['express'] == '99' && $post['bx'] > 0)
  1204. {
  1205. echo json_encode(array('msg'=>'此物流不允许购买保险','success'=>false));exit;
  1206. }
  1207. if($post['express'] == 42 && $post['sbpm'] != 'Human Hair Wigs' && $post['sbpm'] != 'Human Hair Goods')//$post['express'] == 3 ||
  1208. {
  1209. echo json_encode(array('msg'=>'此快递方式必须选择Human Hair Wigs/Human Hair Goods!','success'=>false));exit;
  1210. }
  1211. if($post['express'] == 24 && $post['sbpm'] != 'Hair Sample' && $post['sbpm'] != 'Human Hair Wigs' && $post['sbpm'] != 'Human Hair Goods')//$post['express'] == 3 ||
  1212. {
  1213. echo json_encode(array('msg'=>'此快递方式必须选择Hair Sample/Human Hair Wigs/Human Hair Goods!','success'=>false));exit;
  1214. }
  1215. if($post['country'] != 192 && $post['express'] == 1 && $post['sbpm'] != 'Synthetic Hair Wigs' && $post['sbpm'] != 'Synthetic Hair Goods')//$post['express'] == 3 ||
  1216. {
  1217. echo json_encode(array('msg'=>'非美国选择官方DHL必须选择Synthetic Hair Wigs/Synthetic Hair Goods','success'=>false));exit;
  1218. }
  1219. if($post['pay'] == '22' && ($post['paypal'] == '' || $post['guarantee'] == ''))
  1220. {
  1221. echo json_encode(array('msg'=>'交易号和卖家保障必须填写','success'=>false));exit;
  1222. }
  1223. if($post['pay'] == '23' && $post['paypal'] == '')
  1224. {
  1225. echo json_encode(array('msg'=>'交易号必须填写','success'=>false));exit;
  1226. }
  1227. $express = $this->express->read($post['express']);
  1228. if($post['zsbjz'] > $express['sbjz'])
  1229. {
  1230. echo json_encode(array('msg'=>'总申报价值不可超出'.$express['sbjz'],'success'=>false));exit;
  1231. }
  1232. if($express['ioss'] == 1 && $post['ioss'] == '')
  1233. {
  1234. echo json_encode(array('msg'=>'此快递方式必须选择IOSS!','success'=>false));exit;
  1235. }
  1236. if(strlen($post['address']) > $express['addresssize'] || strlen($post['address2']) > $express['addresssize'])
  1237. {
  1238. echo json_encode(array('msg'=>'此快递方地址不可超出'.$express['addresssize'].'个字符','success'=>false));exit;
  1239. }
  1240. if(strlen($post['address']) < 5)
  1241. {
  1242. echo json_encode(array('msg'=>'地址不可留空!','success'=>false));exit;
  1243. }
  1244. if($post['express'] == '2' && $post['zzl'] >= '16' && $post['js'] == '0')
  1245. {
  1246. //echo json_encode(array('msg'=>'总重量大于等于16不可选FIRST CLASS','success'=>false));exit;
  1247. }
  1248. if(($post['express'] == '3' || $post['express'] == '42' || $post['express'] == '24') && $post['shouldmoney'] < 1)
  1249. {
  1250. echo json_encode(array('msg'=>'零金额订单不可发 UPS/DHL官方-美国/Fedex(杭州)','success'=>false));exit;
  1251. }
  1252. if($post['express'] == '6' && $post['province'] == '')
  1253. {
  1254. echo json_encode(array('msg'=>'选择DPEX必须填写州信息','success'=>false));exit;
  1255. }
  1256. /**
  1257. $post['saddress']
  1258. if($post['printtype'] == 1)//如果是运单
  1259. {
  1260. $post['productdescription'] = $this->input->post('productdescription',true);
  1261. $post['customs'] = $this->input->post('customs',true);
  1262. }
  1263. **/
  1264. //开始注释 xyxg
  1265. /**
  1266. $warehousenew = $this->warehouse->read($post['type']);
  1267. $ft = array();
  1268. $ftdata = explode('|',rtrim($fpcount,'|'));
  1269. foreach ($ftdata as $va)
  1270. {
  1271. $ftitle = '';
  1272. $va = explode('-',trim($va,'-'));
  1273. foreach ($va as $v)
  1274. {
  1275. $v = $this->typeclass->read($v);
  1276. $ftitle .= $v['title'].' ';
  1277. }
  1278. $ft[] = rtrim($ftitle,' ');
  1279. }
  1280. $kcyz = $this->whlabel->get_kc($post['state'],$post['state'],$warehousenew['zd'],$warehousenew['ys'],$post['type'],$whlabel,$fpcount,$ft,$post['number'],$shop);//新添加订单老状态state和新状态state一样,不用走删除占用步奏
  1281. if($kcyz['t'] > '0')
  1282. {
  1283. echo $kcyz['m'];exit;
  1284. }
  1285. else
  1286. {
  1287. if($this->fullorder->insert($post))
  1288. {
  1289. $cusnum = $this->customer->read($customerid);
  1290. $this->customer->save(array('num'=>$cusnum['num']+1,'time'=>$post['buytime']),$customerid);
  1291. echo json_encode(array('msg'=>'下单成功','success'=>true));exit;
  1292. }
  1293. else
  1294. {
  1295. echo json_encode(array('msg'=>'下单失败,请重试','success'=>false));exit;
  1296. }
  1297. }
  1298. //结束注释
  1299. **/
  1300. $dtctitle = array();
  1301. $dictionaries = $this->typeclass->find_all();
  1302. foreach ($dictionaries as $v)
  1303. {
  1304. $dtctitle[$v['id']] = array($v['title'],$v['bqsku']);
  1305. }
  1306. $fpdata = $post['fpdata'];
  1307. if(stripos($fpdata,'-128-') !== false || stripos($fpdata,'-127-') !== false)
  1308. {
  1309. $dfp = explode(';',trim($fpdata,';'));
  1310. $fdata = '';
  1311. foreach ($dfp as $k=>$v)
  1312. {
  1313. $ptitleb = '';
  1314. $fp = explode('|',trim($v,'|'));
  1315. $fp0 = explode(',',$fp[0]);
  1316. if(isset($fp0[1]))
  1317. {
  1318. $fp1 = explode('-',trim($fp0[1],'-'));
  1319. }
  1320. else
  1321. {
  1322. $fp1 = explode('-',trim($fp[0],'-'));
  1323. }
  1324. foreach ($fp1 as $vv)
  1325. {
  1326. $ptitleb .= isset($dtctitle[$vv])?$dtctitle[$vv][0].' ':'';
  1327. }
  1328. if(isset($fp0[1]))
  1329. {
  1330. $ptitleb .= $dtctitle[$fp0[0]][1].'inch ';
  1331. $fp[1] = $ptitleb;
  1332. }
  1333. $fdata .= implode("|",$fp).";";
  1334. }
  1335. $fpdata = $fdata;
  1336. }
  1337. $warehouse = $this->warehouse->read($post['type']);
  1338. if($warehouse['bdcountry'] != 0 && $post['country'] != $warehouse['bdcountry'])
  1339. {
  1340. echo json_encode(array('msg'=>'当前国家无法选择'.$warehouse['title'].'!','success'=>false));exit;
  1341. }
  1342. $kcyz = $this->ck->get_kc($post['state'],$warehouse,$post['shop'],$post['number'],$whlabel,$fpdata);
  1343. if($kcyz['t'] > '0')
  1344. {
  1345. echo $kcyz['m'];exit;
  1346. }
  1347. else if($kcyz['fpdata'] != '')
  1348. {
  1349. $post['whlabel'] = $kcyz['whlabel'];
  1350. $post['fpdata'] = $kcyz['fpdata'];
  1351. }
  1352. $fl = $this->ck->get_fl($warehouse['hz'],$whlabel,$fpdata);
  1353. $post['sfxh'] = $fl['sfxh'];
  1354. $post['ckfl'] = $fl['ckfl'];
  1355. //查询净重开始
  1356. $post['jweight'] = $this->weight->get_weightcx($post['fpdata']);
  1357. //查询净重结束
  1358. $cusnum = $this->customer->read($customerid);
  1359. $this->customer->save(array('num'=>$cusnum['num']+1,'time'=>$post['buytime']),$customerid);
  1360. $this->fullorder->insert($post);
  1361. echo json_encode(array('msg'=>'下单成功','success'=>true));exit;
  1362. }
  1363. $arg_array = $arg_array[0];//用户ID
  1364. $customer = $this->customer->read($arg_array);//用户信息
  1365. $this->data['customer'] = $customer;
  1366. $country = $this->country->find_all('1=1','id,name','name asc');//国家
  1367. $this->data['country'] = $country;
  1368. $express = $this->express->find_all();//物流商
  1369. $this->data['express'] = $express;
  1370. $bm = $this->country->read($customer['country']);
  1371. $this->data['bm'] = $bm;
  1372. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  1373. $this->data['wlshop'] = $wlshop;
  1374. $this->data['user'] = $u['userid'];
  1375. $this->_Template('customer_mdedit',$this->data);
  1376. }
  1377. //上传excel
  1378. public function _excela()
  1379. {
  1380. $dir = '/data/excel/'.date('Ymd',time()).'/';
  1381. $config['upload_path'] = '.'.$dir ;
  1382. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  1383. $config['allowed_types'] = 'xls|xlsx';
  1384. $config['max_size'] = 10240;
  1385. $this->load->library('upload', $config);
  1386. $this->upload->initialize($config);
  1387. if ($this->upload->do_upload('userfile'))
  1388. {
  1389. $full_path = $dir.$this->upload->data('file_name');
  1390. $fileName = '.' . $full_path;
  1391. if (!file_exists($fileName))
  1392. {
  1393. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  1394. }
  1395. else
  1396. {
  1397. require_once "./data/excel/PHPExcel/IOFactory.php";
  1398. @$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  1399. @$phpExcel->setActiveSheetIndex(0);// 设置为默认表
  1400. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  1401. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  1402. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  1403. ++$column;//如果列数大于26行
  1404. $list = array();
  1405. for ($i = 2; $i <= $row; $i++) // 行数循环
  1406. {
  1407. $data = array();
  1408. for ($c = 'A'; $c != $column; $c++) // 列数循环
  1409. {
  1410. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  1411. }
  1412. $list[] = $data;
  1413. }
  1414. }
  1415. $i = 0;
  1416. $this->db->trans_begin();
  1417. foreach ($list as $key=>$value)
  1418. {
  1419. $value['1'] = $value['1']?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['1']):'';
  1420. $value['7'] = $value['7']?str_replace('/( | | |\s)/','',$value['7']):'';
  1421. if($value['7'] == "" || $value['11'] == "")
  1422. {
  1423. $i++;
  1424. continue;
  1425. }
  1426. else
  1427. {
  1428. $value['7'] = str_replace('/( | | |\s)/','',$value['7']);
  1429. }
  1430. $shop = $this->shop->get_name($value['9']);
  1431. if(!$shop)
  1432. {
  1433. $i++;
  1434. continue;
  1435. }
  1436. if($value['11'] == 2)
  1437. {
  1438. $repeat = $this->customer->get_address($value['1']);//只判断地址
  1439. }
  1440. else
  1441. {
  1442. $repeat = $this->customer->find_all('email = "'.$value[7].'" and shop = "'.$shop['id'].'"');//只判断邮箱
  1443. }
  1444. /* 判断邮箱和地址
  1445. if($value['1'] == "" || $value['1'] == " ")
  1446. {
  1447. if($value['7'] == "" || $value['7'] == " ")
  1448. {
  1449. $repeat = 1;
  1450. }
  1451. else
  1452. {
  1453. $repeat = $this->customer->get_email($value['7']);
  1454. }
  1455. }
  1456. else
  1457. {
  1458. $repeat = $this->customer->get_address($value['1']);
  1459. }
  1460. */
  1461. if(isset($repeat[0]['type']))
  1462. {
  1463. if($repeat[0]['type'] == $value['11'])
  1464. {
  1465. $i++;
  1466. }
  1467. else if($repeat[0]['type'] != $value['11'])
  1468. {
  1469. $this->customer->save(array('type'=>$value['11']),$repeat[0]['id']);
  1470. }
  1471. }
  1472. else
  1473. {
  1474. $source = $this->typeclass->get_title($value['10']);
  1475. if($source)
  1476. {
  1477. $post['name'] = ($value['0'] && $value['0'] != 'NULL')?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['0']):'';
  1478. $post['email'] = $value['7'];
  1479. if($value['5'] != '')
  1480. {
  1481. $country = $this->country->get_ename(str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['5']));
  1482. $post['country'] = $country['id'];
  1483. }
  1484. $post['level'] = $value['8']?$value['8']:5;
  1485. $post['phone'] = $value['6']?$value['6']:'';
  1486. $post['province'] = $value['3']?$value['3']:'';
  1487. $post['city'] = $value['2']?$value['2']:'';
  1488. $post['address'] = $value['1'];
  1489. $post['zipcode'] = $value['4']?$value['4']:'';
  1490. $post['shop'] = $shop['id'];
  1491. $post['source'] = $source['id'];
  1492. $post['type'] = $value['11'];
  1493. $val12 = $value['12']?$value['12']:'';
  1494. $post['count'] = $val12;
  1495. $str = $post['phone'];
  1496. preg_match_all('/[0-9]/u',$str,$result);
  1497. $numphone = join('',$result[0]);
  1498. $post['numphone'] = $numphone;
  1499. $this->customer->insert($post);
  1500. }
  1501. }
  1502. }
  1503. if ($this->db->trans_status() === FALSE)
  1504. {
  1505. $this->db->trans_commit();
  1506. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  1507. }
  1508. else
  1509. {
  1510. if(count($list) == $i)
  1511. {
  1512. $til = '导入全部失败!请检查导入信息';
  1513. }
  1514. else if(count($list) > $i && $i != 0)
  1515. {
  1516. $til = '部分导入成功!'.$i.'条信息有问题,请排查';
  1517. }
  1518. else if($i < 1)
  1519. {
  1520. $til = '导入成功!';
  1521. }
  1522. $this->db->trans_commit();
  1523. echo json_encode(array('msg'=>$til,'success'=>true));exit;
  1524. }
  1525. }
  1526. else
  1527. {
  1528. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  1529. }
  1530. }
  1531. public function _indexexcel()//通过计数,2020/02/21已校准
  1532. {
  1533. $user = $this->user->get_api($_SESSION['api']);
  1534. if($user)
  1535. {
  1536. $fgshop = "";$sid = "";
  1537. $users = explode('|',trim($user['shop'],'|'));
  1538. foreach ($users as $value)
  1539. {
  1540. $fgshop .= " shop = ".$value." or";
  1541. $sid .= " id = ".$value." or";
  1542. }
  1543. if($user['vip'] == 1)
  1544. {
  1545. $vip = 1;
  1546. }
  1547. else
  1548. {
  1549. $vip = 0;
  1550. }
  1551. }
  1552. else
  1553. {
  1554. $vip = 0;
  1555. }
  1556. $post = $this->input->post(NULL, TRUE);
  1557. if(isset($_GET['timetk']))
  1558. {
  1559. $shop = $this->input->get('shop',true);
  1560. $numphone = $this->input->get('numphone',true);
  1561. $name = $this->input->get('name',true);
  1562. $email = $this->input->get('email',true);
  1563. $address = $this->input->get('address',true);
  1564. $level = $this->input->get('level',true);
  1565. $num = $this->input->get('num',true);
  1566. $country = $this->input->get('country',true);
  1567. $excelid = $this->input->get('sid',true);
  1568. $timetk = $this->input->get('timetk',true);
  1569. $timetj = $this->input->get('timetj',true);
  1570. $timetk = strtotime($timetk);
  1571. $timetj = strtotime($timetj);
  1572. $where = "1=1 and type = 1 and (".rtrim($fgshop,'or').")";
  1573. if($shop)
  1574. {
  1575. $where .= " and shop = '$shop'";
  1576. }
  1577. if($numphone)
  1578. {
  1579. $where .= " and numphone = '$numphone'";
  1580. }
  1581. if($name)
  1582. {
  1583. $where .= " and name like '%$name%'";
  1584. }
  1585. if($email)
  1586. {
  1587. $where .= " and email like '%$email%'";
  1588. }
  1589. if($level)
  1590. {
  1591. $where .= " and level = '$level'";
  1592. }
  1593. if($country)
  1594. {
  1595. $where .= " and country = '$country'";
  1596. }
  1597. if($address)
  1598. {
  1599. $where .= " and address like '%$address%'";
  1600. }
  1601. if($num > 0 && $num < 10 && $num != '2a')
  1602. {
  1603. $where .= " and num = '$num'";
  1604. }
  1605. else if($num > 9)
  1606. {
  1607. $where .= " and num > '9'";
  1608. }
  1609. else if($num == '2a')
  1610. {
  1611. $where .= " and num > '1'";
  1612. }
  1613. else
  1614. {
  1615. $where .= " and num >= '0'";
  1616. }
  1617. if($timetk && $timetj)
  1618. {
  1619. $where .= " and ((time > '$timetk' and time < '$timetj') or time = '0')";
  1620. }
  1621. $xzid = '';
  1622. if($excelid)
  1623. {
  1624. $excelid = explode(',',trim($excelid,','));
  1625. foreach ($excelid as $key=>$value)
  1626. {
  1627. $xzid .= " id = ".$value." or";
  1628. }
  1629. $where .= " and (".rtrim($xzid,'or').")";;
  1630. }
  1631. //数据排序
  1632. $order_str = "id desc";
  1633. $numdata = array();
  1634. if(empty($page))
  1635. {
  1636. $start = 0;
  1637. $perpage = 1;
  1638. }
  1639. else
  1640. {
  1641. $start = ($page - 1)*$perpage;
  1642. }
  1643. //取得信息列表
  1644. $info_list = $this->customer->find_all($where,'shop,name,email,phone,address,city,province,zipcode,country,level,money,num,numphone,time,count',$order_str);
  1645. foreach ($info_list as $key=>$value)
  1646. {
  1647. $shop = $this->shop->read($value['shop']);
  1648. $info_list[$key]['shop'] = $shop['shopname'];
  1649. if($value['country'] != 0)
  1650. {
  1651. $country = $this->country->read($value['country']);
  1652. $info_list[$key]['country'] = $country['name'];
  1653. }
  1654. else
  1655. {
  1656. $info_list[$key]['country'] = "未知";
  1657. }
  1658. if($value['level'] == 1)
  1659. {
  1660. $info_list[$key]['level'] = "网红";
  1661. }
  1662. else if($value['level'] == 2)
  1663. {
  1664. $info_list[$key]['level'] = "批发";
  1665. }
  1666. else if($value['level'] == 3)
  1667. {
  1668. $info_list[$key]['level'] = "店铺转线下";
  1669. }
  1670. else if($value['level'] == 4)
  1671. {
  1672. $info_list[$key]['level'] = "线下其他";
  1673. }
  1674. else if($value['level'] == 5)
  1675. {
  1676. $info_list[$key]['level'] = "店内客户";
  1677. }
  1678. if($value['time'] != 0)
  1679. {
  1680. $info_list[$key]['time'] = date('Y-m-d',$value['time']);
  1681. }
  1682. else
  1683. {
  1684. $info_list[$key]['time'] = "无";
  1685. }
  1686. $info_list[$key]['numphone'] = ($value['num'] > 0 && $value['money'] > 0)?sprintf("%01.2f",$value['money']/$value['num']):0;
  1687. if(isset($value['email']) && $user['excelpass'] == '1')
  1688. {
  1689. $emailpass = $this->setting->get_excelpass($value['email']);
  1690. $info_list[$key]['email'] = $emailpass;
  1691. }
  1692. if(isset($value['phone']) && $user['excelpass'] == '1')
  1693. {
  1694. $phone = $this->setting->get_excelpass($value['phone']);
  1695. $info_list[$key]['phone'] = $phone;
  1696. }
  1697. }
  1698. $title = "按条件导出";
  1699. $titlename = "<table border=1>
  1700. <tr align='center'>
  1701. <td>店铺</td>
  1702. <td>名称</td>
  1703. <td>邮箱</td>
  1704. <td>电话</td>
  1705. <td>详细地址</td>
  1706. <td>城市</td>
  1707. <td>省/州</td>
  1708. <td>邮编</td>
  1709. <td>国家</td>
  1710. <td>类型</td>
  1711. <td>总额</td>
  1712. <td>成交次数</td>
  1713. <td>客单价</td>
  1714. <td>最后购买日期</td>
  1715. <td>备注</td>
  1716. </tr>
  1717. </table>";
  1718. $filename = $title.".xls";
  1719. $tail = "";
  1720. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  1721. }
  1722. }
  1723. //下载excel
  1724. public function _excel()
  1725. {
  1726. if(isset($_GET['excel']))
  1727. {
  1728. if(isset($_SESSION['api']))
  1729. {
  1730. $user = $this->user->get_api($_SESSION['api']);
  1731. $usp = $user;
  1732. $fgshop = "";$sid = "";
  1733. $user = explode('|',trim($user['shop'],'|'));
  1734. foreach ($user as $value)
  1735. {
  1736. $fgshop .= " shop = ".$value." or";
  1737. $sid .= " id = ".$value." or";
  1738. }
  1739. }
  1740. $dowid = $this->input->get('a');
  1741. $wid = "";
  1742. if($dowid != "")
  1743. {
  1744. $id_arr = explode(',',rtrim($dowid,','));
  1745. $wid .= " id = 0 or";
  1746. foreach ($id_arr as $v)
  1747. {
  1748. $wid .= " id = '$v' or";
  1749. }
  1750. $wid = " and".rtrim($wid,'or');
  1751. }
  1752. $excel = $this->input->get('excel',true);
  1753. $page = $this->input->get('page',true);
  1754. $perpage = $this->input->get('perpage',true);
  1755. $shop = $this->input->get('shop',true);
  1756. $name = $this->input->get('name',true);
  1757. $country = $this->input->get('country',true);
  1758. $email = $this->input->get('email',true);
  1759. $address = $this->input->get('address',true);
  1760. $level = $this->input->get('level',true);
  1761. $num = $this->input->get('num',true);
  1762. $timetk = $this->input->get('timetk',true);
  1763. $timetj = $this->input->get('timetj',true);
  1764. $timetk = strtotime($timetk);
  1765. $timetj = strtotime($timetj);
  1766. $where = "1 = 1 and (".rtrim($fgshop,'or').")";
  1767. if($shop)
  1768. {
  1769. $where .= " and shop = '$shop'";
  1770. }
  1771. if($name)
  1772. {
  1773. $where .= " and name like '%$name%'";
  1774. }
  1775. if($email)
  1776. {
  1777. $where .= " and email like '%$email%'";
  1778. }
  1779. if($country)
  1780. {
  1781. $where .= " and country = '$country'";
  1782. }
  1783. if($level)
  1784. {
  1785. $where .= " and level = '$level'";
  1786. }
  1787. if($num != '')
  1788. {
  1789. $nu = 1;
  1790. if($num > 9)
  1791. {
  1792. $where .= " and num > '9'";
  1793. }
  1794. else if($num == '2a')
  1795. {
  1796. $where .= " and num > '1'";
  1797. }
  1798. else
  1799. {
  1800. $where .= " and num = '$num'";
  1801. }
  1802. }
  1803. else
  1804. {
  1805. $nu = 2;
  1806. $where .= " and num >= '0'";
  1807. }
  1808. if($address)
  1809. {
  1810. $where .= " and address like '%$address%'";
  1811. }
  1812. if($timetk && $timetj)
  1813. {
  1814. $where .= " and time > '$timetk' and time < '$timetj'";
  1815. }
  1816. $where .= " and type = 1";//白名单用户
  1817. $info_list = array();
  1818. if($excel == 2) //老客户列表
  1819. {
  1820. //$where = str_replace("level = '$level'","level > '1'",$where);
  1821. $info_list = $this->customer->find_all($where.$wid,'name,email,country,time,num,money,numphone','time desc');
  1822. foreach ($info_list as $key=>$value)
  1823. {
  1824. $info_list[$key]['time'] = date('Y-m-d H:i:s',$value['time']);
  1825. if($value['country'] != 0)
  1826. {
  1827. $country = $this->country->read($value['country']);
  1828. $info_list[$key]['country'] = $country['ename'];
  1829. }
  1830. else
  1831. {
  1832. $info_list[$key]['country'] = '';
  1833. }
  1834. $info_list[$key]['numphone'] = sprintf("%01.2f",$value['money']/$value['num']);
  1835. if(isset($value['email']) && $usp['excelpass'] == '1')
  1836. {
  1837. $emailpass = $this->setting->get_excelpass($value['email']);
  1838. $info_list[$key]['email'] = $emailpass;
  1839. }
  1840. }
  1841. /**
  1842. foreach ($info_list as $key=>$value)
  1843. {
  1844. $value['time'] = date('Y-m-d H:i:s',$value['time']);
  1845. $d = $this->fullorder->find_count('email = "'.$value['email'].'" and shop = "'.$value['shop'].'" and mergeid = 0','orderinfo,state,product,name,email,dtime,shouldmoney','time desc');
  1846. if($d > 1)
  1847. {
  1848. $info_list[] = $v;
  1849. }
  1850. }
  1851. **/
  1852. $fzh = "<td>客户名</td><td>客户邮箱</td><td>客户国家</td><td>最近一次下单时间</td><td>购买次数</td><td>购买总金额</td><td>客单价</td>";
  1853. $title = "老客户列表";
  1854. }
  1855. else
  1856. {
  1857. $fdata = $this->customer->find_all($where.$wid,'email,shop','time desc');
  1858. foreach ($fdata as $key=>$value)
  1859. {
  1860. $d = $this->fullorder->find_all('email = "'.$value['email'].'" and shop = "'.$value['shop'].'" and mergeid = 0','orderinfo,state,product,shipremarks,name,email,country,dtime,shouldmoney','time desc');
  1861. if($nu == 2)
  1862. {
  1863. if(count($d) > 1)
  1864. {
  1865. foreach ($d as $k=>$v)
  1866. {
  1867. $v['dtime'] = date('Y-m-d H:i:s',$v['dtime']);
  1868. $typeclass = $this->typeclass->read($v['state']);
  1869. $v['state'] = $typeclass['spare'];
  1870. if($v['country'] != 0)
  1871. {
  1872. $country = $this->country->read($v['country']);
  1873. $v['country'] = $country['ename'];
  1874. }
  1875. else
  1876. {
  1877. $v['country'] = '';
  1878. }
  1879. if(isset($v['email']) && $usp['excelpass'] == '1')
  1880. {
  1881. $emailpass = $this->setting->get_excelpass($v['email']);
  1882. $v['email'] = $emailpass;
  1883. }
  1884. $info_list[] = $v;
  1885. }
  1886. }
  1887. }
  1888. else
  1889. {
  1890. foreach ($d as $k=>$v)
  1891. {
  1892. $v['dtime'] = date('Y-m-d H:i:s',$v['dtime']);
  1893. $typeclass = $this->typeclass->read($v['state']);
  1894. $v['state'] = $typeclass['spare'];
  1895. if($v['country'] != 0)
  1896. {
  1897. $country = $this->country->read($v['country']);
  1898. $v['country'] = $country['ename'];
  1899. }
  1900. else
  1901. {
  1902. $v['country'] = '';
  1903. }
  1904. if(isset($v['email']) && $usp['excelpass'] == '1')
  1905. {
  1906. $emailpass = $this->setting->get_excelpass($v['email']);
  1907. $v['email'] = $emailpass;
  1908. }
  1909. $info_list[] = $v;
  1910. }
  1911. }
  1912. }
  1913. $fzh = "<td>订单号</td><td>订单状态</td><td>产品名</td><td>仓库品名</td><td>客户名</td><td>客户邮箱</td><td>客户国家</td><td>下单时间</td><td>订单金额</td>";
  1914. $title = "老客户订单列表";
  1915. }
  1916. $titlename = "<table border=1>
  1917. <tr>"
  1918. .$fzh.
  1919. "</tr>
  1920. </table>";
  1921. $tail = "\n";
  1922. $filename = $title.'-'.date('Ymd',time()).".xls";
  1923. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  1924. }
  1925. }
  1926. //下载excel模板
  1927. public function _bankdown()
  1928. {
  1929. if(isset($_GET['bankdown']))
  1930. {
  1931. $numphone = $this->input->post('numphone',true);
  1932. $xtime = $this->input->get('xtime',true);
  1933. //$where = "1=1 and type = 2 and (".rtrim($fgshop,'or').")";
  1934. $shop = $this->input->get('shop',true);
  1935. $name = $this->input->get('name',true);
  1936. $email = $this->input->get('email',true);
  1937. $address = $this->input->get('address',true);
  1938. $type = $this->input->get('type',true);
  1939. $id = $this->input->get('id',true);
  1940. $timetk = $this->input->get('timetk',true);
  1941. $timetj = $this->input->get('timetj',true);
  1942. $timetk = strtotime($timetk);
  1943. $timetj = strtotime($timetj);
  1944. if($type)
  1945. {
  1946. $where = "type = '$type'";
  1947. }
  1948. else
  1949. {
  1950. $where = "id != 0";
  1951. }
  1952. if($id)
  1953. {
  1954. $id = explode('|',trim($id,'|'));
  1955. $downid = '';
  1956. foreach ($id as $value)
  1957. {
  1958. $downid .= " id = ".$value." or";
  1959. }
  1960. $where .= " and (".rtrim($downid,'or').")";
  1961. }
  1962. if(!$shop)
  1963. {
  1964. $user = $this->user->get_api($_SESSION['api']);
  1965. $usp = $user;
  1966. $fgshop = "";$sid = "";
  1967. $user = explode('|',trim($user['shop'],'|'));
  1968. foreach ($user as $value)
  1969. {
  1970. $fgshop .= " shop = ".$value." or";
  1971. $sid .= " id = ".$value." or";
  1972. }
  1973. $where .= " and (".rtrim($fgshop,'or').")";
  1974. }
  1975. else
  1976. {
  1977. $where .= " and shop = '$shop'";
  1978. }
  1979. if($email)
  1980. {
  1981. $where .= " and email = '$email'";
  1982. }
  1983. if($name)
  1984. {
  1985. $where .= " and name = '$name'";
  1986. }
  1987. if($address)
  1988. {
  1989. $where .= " and address = '$address'";
  1990. }
  1991. if($xtime)
  1992. {
  1993. $where .= " and typetime > '$timetk' and typetime < '$timetj'";
  1994. }
  1995. $info_list = $this->customer->find_all($where,'name,address,city,province,zipcode,country,phone,email,level,shop,source,type,count,typetime');
  1996. foreach ($info_list as $key=>$v)
  1997. {
  1998. $country = $this->country->read($v['country']);
  1999. $info_list[$key]['country'] = $country['ename'];
  2000. if($v['level'] == 1)
  2001. {
  2002. $info_list[$key]['level'] = '网红';
  2003. }
  2004. else if($v['level'] == 2)
  2005. {
  2006. $info_list[$key]['level'] = '批发';
  2007. }
  2008. else if($v['level'] == 3)
  2009. {
  2010. $info_list[$key]['level'] = '店铺转线下';
  2011. }
  2012. else if($v['level'] == 4)
  2013. {
  2014. $info_list[$key]['level'] = '线下其他';
  2015. }
  2016. else if($v['level'] == 5)
  2017. {
  2018. $info_list[$key]['level'] = '店内';
  2019. }
  2020. else
  2021. {
  2022. $info_list[$key]['level'] = '未知';
  2023. }
  2024. if($v['typetime'] != 0)
  2025. {
  2026. $info_list[$key]['typetime'] = date('Y-m-d',$v['typetime']);
  2027. }
  2028. else
  2029. {
  2030. $info_list[$key]['typetime'] = "无";
  2031. }
  2032. $shop = $this->shop->read($v['shop']);
  2033. $info_list[$key]['shop'] = $shop['shopname'];
  2034. $source = $this->typeclass->read($v['source']);
  2035. $info_list[$key]['source'] = $source['title'];
  2036. }
  2037. $titledata = array('姓名','详细地址','城市','省/州','邮编','国家','电话','邮箱','类型(1:网红2:批发3:店铺转线下4:线下其他5:店内)','所属店铺(必须ERP已有店铺)','来源(数据字典的户来源需存在)','黑白名单(白名单填1或黑名单填2)','备注','客户分类时间');
  2038. $fzh = "";
  2039. foreach ($titledata as $v)
  2040. {
  2041. $fzh .= "<td>".$v."</td>";
  2042. }
  2043. $title = "客户导出";
  2044. $titlename = "<table border=1>
  2045. <tr>"
  2046. .$fzh.
  2047. "</tr>
  2048. </table>";
  2049. $tail = "\n";
  2050. $filename = $title.".xls";
  2051. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  2052. }
  2053. }
  2054. //下载excel模板
  2055. public function _down()
  2056. {
  2057. if(isset($_GET['excela']))
  2058. {
  2059. $title = "客户导入模板";
  2060. $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','备注'));
  2061. $filename = $title.".xls";
  2062. $this->customer->get_excel($titledata,$filename);
  2063. }
  2064. }
  2065. public function _newold()
  2066. {
  2067. if(isset($_SESSION['api']))
  2068. {
  2069. $user = $this->user->get_api($_SESSION['api']);
  2070. $usp = $user;
  2071. $fgshop = "";$sid = "";
  2072. $usersp = explode('|',trim($user['shop'],'|'));
  2073. foreach ($usersp as $value)
  2074. {
  2075. $fgshop .= " shop = ".$value." or";
  2076. $sid .= " id = ".$value." or";
  2077. }
  2078. }
  2079. $post = $this->input->post(NULL, TRUE);
  2080. if(isset($post['timek']))
  2081. {
  2082. $new = array();$old = array();$time=array();
  2083. $timek = $this->input->post('timek',true);
  2084. $timej = $this->input->post('timej',true);
  2085. $k = strtotime($timek)-24*3600;//少一天为增加选择开始天时间
  2086. $j = strtotime($timej);
  2087. $n = ($j-$k)/(24*3600);
  2088. if($n < 1)
  2089. {
  2090. $n = 1;
  2091. }
  2092. for($i=1;$i<$n;$i++)
  2093. {
  2094. $nnum = 0;$onum = 0;
  2095. $t = $j-($n*24*60*60)+($i*24*60*60);
  2096. $time[] = date('Y-m-d',$t);
  2097. $ct = strtotime(date('Ymd',$t));
  2098. $ctj = strtotime(date('Ymd',$t+24*3600));
  2099. $info_list = $this->fullorder->find_all("mergeid = '0' and dtime > '$ct' and dtime < '$ctj' and (".rtrim($fgshop,'or').")");
  2100. foreach ($info_list as $value)
  2101. {
  2102. if($value['email'] != '0' && $value['email'] != '' && $value['email'] != '无')
  2103. {
  2104. $gnum = $this->fullorder->find_count("email = '".$value['email']."' and shop = '".$value['shop']."' and mergeid = 0");
  2105. if($gnum >1)
  2106. {
  2107. $onum += 1;
  2108. }
  2109. else
  2110. {
  2111. $nnum += 1;
  2112. }
  2113. }
  2114. else
  2115. {
  2116. $nnum += 1;
  2117. }
  2118. }
  2119. $new[] = $nnum;
  2120. $old[] = $onum;
  2121. }
  2122. echo @json_encode(array('time'=>$time,'cnew'=>$new,'cold'=>$old,'success'=>true));exit;
  2123. }
  2124. $this->_Template('customer_newold',$this->data);
  2125. }
  2126. }