Customertt.php 74 KB

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