Customertt.php 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187
  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'].'-'.date('ymd',time()).'-'.(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. $post['cate_one'] = 1;
  1139. $post['cate_two'] = 0;
  1140. /**
  1141. if($pay)
  1142. {
  1143. $ygc = $pay['estimaterate'];//预估到账公式
  1144. $ifbudget = eval("return $yga*1.$ygc;");
  1145. $post['estimaterate'] = $pay['estimaterate'];
  1146. if($ifbudget > 0)
  1147. {
  1148. $post['budget'] = eval("return $yga*1.$ygc;");//预估到帐金额
  1149. }
  1150. }
  1151. else
  1152. {
  1153. $ygb = $sp['estimaterate'];//店铺默认到账公式
  1154. $ifbudget = eval("return $yga*1.$ygb;");
  1155. $post['estimaterate'] = $sp['estimaterate'];
  1156. if($ifbudget > 0)
  1157. {
  1158. $post['budget'] = eval("return $yga*1.$ygb;");//预估到帐金额
  1159. }
  1160. }
  1161. **/
  1162. $ygb = $sp['estimaterate'];//店铺默认到账公式
  1163. $ifbudget = eval("return $yga*1.$ygb;");
  1164. $post['estimaterate'] = $sp['estimaterate'];
  1165. if($ifbudget > 0)
  1166. {
  1167. $post['budget'] = eval("return $yga*1.$ygb;");//预估到帐金额
  1168. }
  1169. $baddress = $this->input->post('baddress',true);
  1170. $saddress = $this->input->post('saddress',true);
  1171. $baddress = array_reverse(explode(',',$baddress));
  1172. $saddress = array_reverse(explode(',',$saddress));
  1173. $bar = '';$sar = '';
  1174. $cr = $this->country->read($post['country']);
  1175. $baddress[1] = $cr['lb'];
  1176. $saddress[1] = $cr['lb'];
  1177. $baddress = array_reverse($baddress);
  1178. $saddress = array_reverse($saddress);
  1179. for($i=0;$i<count($baddress);$i++)
  1180. {
  1181. $bar .= $baddress[$i].',';
  1182. }
  1183. for($i=0;$i<count($saddress);$i++)
  1184. {
  1185. $sar .= $saddress[$i].',';
  1186. }
  1187. $post['baddress'] = rtrim($bar,',');//卖家保障
  1188. $post['saddress'] = rtrim($sar,',');//卖家保障
  1189. $whlabel = $this->input->post('whlabel',true);
  1190. if($post['express'] == 2 && (stripos($post['name'],'&') !== false || stripos($post['name'],"'") !== false))
  1191. {
  1192. echo json_encode(array('msg'=>'USPS收件人或公司名不可用特殊符号!','success'=>false));exit;
  1193. }
  1194. if(strlen($post['client']) > 35 || strlen($post['name']) > 35)//收件人姓名或公司名不允许超过35位
  1195. {
  1196. echo json_encode(array('msg'=>'收件人姓名或公司名不可超过35个字符!','success'=>false));exit;
  1197. }
  1198. if(($post['express'] == '5' || $post['express'] == '24' || $post['express'] == '42' || $post['express'] == '31') && $post['country'] != 192)
  1199. {
  1200. echo json_encode(array('msg'=>'非美国无法选择Fedex、DHL官方-美国!','success'=>false));exit;
  1201. }
  1202. if($post['express'] == '3' && $post['country'] != 192 && $post['country'] != 35)
  1203. {
  1204. echo json_encode(array('msg'=>'非美国和加拿大无法选择UPS!','success'=>false));exit;
  1205. }
  1206. if($post['express'] == '3' && $post['country'] == 35 && $post['zsbjz'] > 20)
  1207. {
  1208. echo json_encode(array('msg'=>'UPS加拿大最高申报不可超过20','success'=>false));exit;
  1209. }
  1210. if($post['express'] == '2' && $post['warehouse'] != 5)
  1211. {
  1212. echo json_encode(array('msg'=>'非美国仓无法选择USPS!','success'=>false));exit;
  1213. }
  1214. if($post['express'] == '99' && $post['bx'] > 0)
  1215. {
  1216. echo json_encode(array('msg'=>'此物流不允许购买保险','success'=>false));exit;
  1217. }
  1218. if($post['express'] == 42 && $post['sbpm'] != 'Human Hair Wigs' && $post['sbpm'] != 'Human Hair Goods')//$post['express'] == 3 ||
  1219. {
  1220. echo json_encode(array('msg'=>'此快递方式必须选择Human Hair Wigs/Human Hair Goods!','success'=>false));exit;
  1221. }
  1222. if($post['express'] == 24 && $post['sbpm'] != 'Hair Sample' && $post['sbpm'] != 'Human Hair Wigs' && $post['sbpm'] != 'Human Hair Goods')//$post['express'] == 3 ||
  1223. {
  1224. echo json_encode(array('msg'=>'此快递方式必须选择Hair Sample/Human Hair Wigs/Human Hair Goods!','success'=>false));exit;
  1225. }
  1226. if($post['country'] != 192 && $post['express'] == 1 && $post['sbpm'] != 'Synthetic Hair Wigs' && $post['sbpm'] != 'Synthetic Hair Goods')//$post['express'] == 3 ||
  1227. {
  1228. echo json_encode(array('msg'=>'非美国选择官方DHL必须选择Synthetic Hair Wigs/Synthetic Hair Goods','success'=>false));exit;
  1229. }
  1230. /**
  1231. if($post['pay'] == '22' && ($post['paypal'] == '' || $post['guarantee'] == ''))
  1232. {
  1233. echo json_encode(array('msg'=>'交易号和卖家保障必须填写','success'=>false));exit;
  1234. }
  1235. if($post['pay'] == '23' && $post['paypal'] == '')
  1236. {
  1237. echo json_encode(array('msg'=>'交易号必须填写','success'=>false));exit;
  1238. }
  1239. **/
  1240. $express = $this->express->read($post['express']);
  1241. if($post['zsbjz'] > $express['sbjz'])
  1242. {
  1243. echo json_encode(array('msg'=>'总申报价值不可超出'.$express['sbjz'],'success'=>false));exit;
  1244. }
  1245. if($post['shouldmoney'] > $express['shouldmoney'] && $express['shouldmoney'] != 0)
  1246. {
  1247. echo json_encode(array('msg'=>'订单金额不可超出'.$express['shouldmoney'],'success'=>false));exit;
  1248. }
  1249. if($express['ioss'] == 1 && $post['ioss'] == '')
  1250. {
  1251. echo json_encode(array('msg'=>'此快递方式必须选择IOSS!','success'=>false));exit;
  1252. }
  1253. if(strlen($post['address']) > $express['addresssize'] || strlen($post['address2']) > $express['addresssize'])
  1254. {
  1255. echo json_encode(array('msg'=>'此快递方地址不可超出'.$express['addresssize'].'个字符','success'=>false));exit;
  1256. }
  1257. if(strlen($post['address']) < 5)
  1258. {
  1259. echo json_encode(array('msg'=>'地址不可留空!','success'=>false));exit;
  1260. }
  1261. if($post['express'] == '2' && $post['zzl'] > '16' && $post['js'] == '0')
  1262. {
  1263. echo json_encode(array('msg'=>'重量大于16不可按Ground Advantage提交!','success'=>false));exit;
  1264. }
  1265. if($post['express'] == '2' && isset($post['js']) && $post['js'] == '0'&& $post['qm'] == '1')
  1266. {
  1267. echo json_encode(array('msg'=>'Ground Advantage不可使用签名服务!','success'=>false));exit;
  1268. }
  1269. if(($post['express'] == '3' || $post['express'] == '42' || $post['express'] == '24') && $post['shouldmoney'] < 1)
  1270. {
  1271. echo json_encode(array('msg'=>'零金额订单不可发 UPS/DHL官方-美国/Fedex(杭州)','success'=>false));exit;
  1272. }
  1273. if($post['express'] == '42' && $post['zsbjz'] < 1)
  1274. {
  1275. echo json_encode(array('msg'=>'零申报金额不可发 DHL官方-美国','success'=>false));exit;
  1276. }
  1277. if($post['express'] == '6' && $post['province'] == '')
  1278. {
  1279. echo json_encode(array('msg'=>'选择DPEX必须填写州信息','success'=>false));exit;
  1280. }
  1281. //减少代码复用吧
  1282. $lo_ret = $this->logic_order->checkEditCustomer($post);
  1283. if($lo_ret['code'] != 1){
  1284. echo json_encode(array('msg'=>$lo_ret['msg'],'success'=>false));exit;
  1285. }
  1286. /**
  1287. $post['saddress']
  1288. if($post['printtype'] == 1)//如果是运单
  1289. {
  1290. $post['productdescription'] = $this->input->post('productdescription',true);
  1291. $post['customs'] = $this->input->post('customs',true);
  1292. }
  1293. **/
  1294. //开始注释 xyxg
  1295. /**
  1296. $warehousenew = $this->warehouse->read($post['type']);
  1297. $ft = array();
  1298. $ftdata = explode('|',rtrim($fpcount,'|'));
  1299. foreach ($ftdata as $va)
  1300. {
  1301. $ftitle = '';
  1302. $va = explode('-',trim($va,'-'));
  1303. foreach ($va as $v)
  1304. {
  1305. $v = $this->typeclass->read($v);
  1306. $ftitle .= $v['title'].' ';
  1307. }
  1308. $ft[] = rtrim($ftitle,' ');
  1309. }
  1310. $kcyz = $this->whlabel->get_kc($post['state'],$post['state'],$warehousenew['zd'],$warehousenew['ys'],$post['type'],$whlabel,$fpcount,$ft,$post['number'],$shop);//新添加订单老状态state和新状态state一样,不用走删除占用步奏
  1311. if($kcyz['t'] > '0')
  1312. {
  1313. echo $kcyz['m'];exit;
  1314. }
  1315. else
  1316. {
  1317. if($this->fullordertt->insert($post))
  1318. {
  1319. $cusnum = $this->customertt->read($customerttid);
  1320. $this->customertt->save(array('num'=>$cusnum['num']+1,'time'=>$post['buytime']),$customerttid);
  1321. echo json_encode(array('msg'=>'下单成功','success'=>true));exit;
  1322. }
  1323. else
  1324. {
  1325. echo json_encode(array('msg'=>'下单失败,请重试','success'=>false));exit;
  1326. }
  1327. }
  1328. //结束注释
  1329. **/
  1330. $dtctitle = array();
  1331. $dictionaries = $this->typeclass->find_all();
  1332. foreach ($dictionaries as $v)
  1333. {
  1334. $dtctitle[$v['id']] = array($v['title'],$v['bqsku']);
  1335. }
  1336. $fpdata = $post['fpdata'];
  1337. if(stripos($fpdata,'-128-') !== false || stripos($fpdata,'-127-') !== false)
  1338. {
  1339. // $dfp = explode(';',trim($fpdata,';'));
  1340. // $fdata = '';
  1341. // foreach ($dfp as $k=>$v)
  1342. // {
  1343. // $ptitleb = '';
  1344. // $fp = explode('|',trim($v,'|'));
  1345. // $fp0 = explode(',',$fp[0]);
  1346. // if(isset($fp0[1])){
  1347. // $fp1 = explode('-',trim($fp0[1],'-'));
  1348. // foreach ($fp1 as $vv)
  1349. // {
  1350. // $ptitleb .= isset($dtctitle[$vv])?$dtctitle[$vv][0].' ':'';
  1351. // }
  1352. // $ptitleb .= $dtctitle[$fp0[0]][1].'inch ';
  1353. // $fp[1] = $ptitleb;
  1354. // $fdata .= implode("|",$fp).";";
  1355. // }
  1356. // }
  1357. // $fpdata = $fdata;
  1358. $dfp = explode(';',trim($fpdata,';'));
  1359. $fdata = '';
  1360. foreach ($dfp as $k=>$v)
  1361. {
  1362. $ptitleb = '';
  1363. $fp = explode('|',trim($v,'|'));
  1364. $fp0 = explode(',',$fp[0]);
  1365. if(isset($fp0[1]))
  1366. {
  1367. $fp1 = explode('-',trim($fp0[1],'-'));
  1368. }
  1369. else
  1370. {
  1371. $fp1 = explode('-',trim($fp[0],'-'));
  1372. }
  1373. foreach ($fp1 as $vv)
  1374. {
  1375. $ptitleb .= isset($dtctitle[$vv])?$dtctitle[$vv][0].' ':'';
  1376. }
  1377. if(isset($fp0[1]))
  1378. {
  1379. $ptitleb .= $dtctitle[$fp0[0]][1].'inch ';
  1380. $fp[1] = $ptitleb;
  1381. }
  1382. $fdata .= implode("|",$fp).";";
  1383. }
  1384. $fpdata = $fdata;
  1385. }
  1386. $warehouse = $this->warehouse->read($post['type']);
  1387. if($warehouse['bdcountry'] != 0 && $post['country'] != $warehouse['bdcountry'])
  1388. {
  1389. echo json_encode(array('msg'=>'当前国家无法选择'.$warehouse['title'].'!','success'=>false));exit;
  1390. }
  1391. $kcyz = $this->ck->get_kc($post['state'],$warehouse,$post['shop'],$post['number'],$whlabel,$fpdata);
  1392. if($kcyz['t'] > '0')
  1393. {
  1394. echo $kcyz['m'];exit;
  1395. }
  1396. else if($kcyz['fpdata'] != '')
  1397. {
  1398. $post['whlabel'] = $kcyz['whlabel'];
  1399. $post['fpdata'] = $kcyz['fpdata'];
  1400. }
  1401. $fl = $this->ck->get_fl($warehouse['hz'],$whlabel,$fpdata);
  1402. $post['sfxh'] = $fl['sfxh'];
  1403. $post['ckfl'] = $fl['ckfl'];
  1404. //查询净重开始
  1405. $post['jweight'] = $this->weight->get_weightcx($post['fpdata']);
  1406. //查询净重结束
  1407. unset($post['id']);
  1408. $cusnum = $this->customertt->read($customerttid);
  1409. $this->customertt->save(array('num'=>$cusnum['num']+1,'time'=>$post['buytime']),$customerttid);
  1410. $this->fullordertt->insert($post);
  1411. echo json_encode(array('msg'=>'下单成功','success'=>true));exit;
  1412. }
  1413. $arg_array = $arg_array[0];//用户ID
  1414. $customertt = $this->customertt->read($arg_array);//用户信息
  1415. $this->data['customertt'] = $customertt;
  1416. $country = $this->country->find_all('1=1','id,name','name asc');//国家
  1417. $this->data['country'] = $country;
  1418. $express = $this->express->find_all();//物流商
  1419. $this->data['express'] = $express;
  1420. $bm = $this->country->read($customertt['country']);
  1421. $this->data['bm'] = $bm;
  1422. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  1423. $this->data['wlshop'] = $wlshop;
  1424. $this->data['user'] = $u['userid'];
  1425. $this->_Template('customertt_mdedit',$this->data);
  1426. }
  1427. //上传excel
  1428. public function _excela()
  1429. {
  1430. $dir = '/data/excel/'.date('Ymd',time()).'/';
  1431. $config['upload_path'] = '.'.$dir ;
  1432. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  1433. $config['allowed_types'] = 'xls|xlsx';
  1434. $config['max_size'] = 10240;
  1435. $this->load->library('upload', $config);
  1436. $this->upload->initialize($config);
  1437. if ($this->upload->do_upload('userfile'))
  1438. {
  1439. $full_path = $dir.$this->upload->data('file_name');
  1440. $fileName = '.' . $full_path;
  1441. if (!file_exists($fileName))
  1442. {
  1443. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  1444. }
  1445. else
  1446. {
  1447. require_once "./data/excel/PHPExcel/IOFactory.php";
  1448. @$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  1449. @$phpExcel->setActiveSheetIndex(0);// 设置为默认表
  1450. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  1451. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  1452. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  1453. ++$column;//如果列数大于26行
  1454. $list = array();
  1455. for ($i = 2; $i <= $row; $i++) // 行数循环
  1456. {
  1457. $data = array();
  1458. for ($c = 'A'; $c != $column; $c++) // 列数循环
  1459. {
  1460. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  1461. }
  1462. $list[] = $data;
  1463. }
  1464. }
  1465. $i = 0;
  1466. $this->db->trans_begin();
  1467. foreach ($list as $key=>$value)
  1468. {
  1469. $value['1'] = $value['1']?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['1']):'';
  1470. $value['7'] = $value['7']?str_replace('/( | | |\s)/','',$value['7']):'';
  1471. if($value['7'] == "" || $value['11'] == "")
  1472. {
  1473. $i++;
  1474. continue;
  1475. }
  1476. else
  1477. {
  1478. $value['7'] = str_replace('/( | | |\s)/','',$value['7']);
  1479. }
  1480. $shop = $this->shop->get_name($value['9']);
  1481. if(!$shop)
  1482. {
  1483. $i++;
  1484. continue;
  1485. }
  1486. if($value['11'] == 2)
  1487. {
  1488. $repeat = $this->customertt->get_address($value['1']);//只判断地址
  1489. }
  1490. else
  1491. {
  1492. $repeat = $this->customertt->find_all('email = "'.$value[7].'" and shop = "'.$shop['id'].'"');//只判断邮箱
  1493. }
  1494. /* 判断邮箱和地址
  1495. if($value['1'] == "" || $value['1'] == " ")
  1496. {
  1497. if($value['7'] == "" || $value['7'] == " ")
  1498. {
  1499. $repeat = 1;
  1500. }
  1501. else
  1502. {
  1503. $repeat = $this->customertt->get_email($value['7']);
  1504. }
  1505. }
  1506. else
  1507. {
  1508. $repeat = $this->customertt->get_address($value['1']);
  1509. }
  1510. */
  1511. if(isset($repeat[0]['type']))
  1512. {
  1513. if($repeat[0]['type'] == $value['11'])
  1514. {
  1515. $i++;
  1516. }
  1517. else if($repeat[0]['type'] != $value['11'])
  1518. {
  1519. $this->customertt->save(array('type'=>$value['11']),$repeat[0]['id']);
  1520. }
  1521. }
  1522. else
  1523. {
  1524. $source = $this->typeclass->get_title($value['10']);
  1525. if($source)
  1526. {
  1527. $post['name'] = ($value['0'] && $value['0'] != 'NULL')?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['0']):'';
  1528. $post['email'] = $value['7'];
  1529. if($value['5'] != '')
  1530. {
  1531. $country = $this->country->get_ename(str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['5']));
  1532. $post['country'] = $country['id'];
  1533. }
  1534. $post['level'] = $value['8']?$value['8']:5;
  1535. $post['phone'] = $value['6']?$value['6']:'';
  1536. $post['province'] = $value['3']?$value['3']:'';
  1537. $post['city'] = $value['2']?$value['2']:'';
  1538. $post['address'] = $value['1'];
  1539. $post['zipcode'] = $value['4']?$value['4']:'';
  1540. $post['shop'] = $shop['id'];
  1541. $post['source'] = $source['id'];
  1542. $post['type'] = $value['11'];
  1543. $val12 = $value['12']?$value['12']:'';
  1544. $post['count'] = $val12;
  1545. $str = $post['phone'];
  1546. preg_match_all('/[0-9]/u',$str,$result);
  1547. $numphone = join('',$result[0]);
  1548. $post['numphone'] = $numphone;
  1549. $this->customertt->insert($post);
  1550. }
  1551. }
  1552. }
  1553. if ($this->db->trans_status() === FALSE)
  1554. {
  1555. $this->db->trans_commit();
  1556. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  1557. }
  1558. else
  1559. {
  1560. if(count($list) == $i)
  1561. {
  1562. $til = '导入全部失败!请检查导入信息';
  1563. }
  1564. else if(count($list) > $i && $i != 0)
  1565. {
  1566. $til = '部分导入成功!'.$i.'条信息有问题,请排查';
  1567. }
  1568. else if($i < 1)
  1569. {
  1570. $til = '导入成功!';
  1571. }
  1572. $this->db->trans_commit();
  1573. echo json_encode(array('msg'=>$til,'success'=>true));exit;
  1574. }
  1575. }
  1576. else
  1577. {
  1578. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  1579. }
  1580. }
  1581. public function _indexexcel()//通过计数,2020/02/21已校准
  1582. {
  1583. $user = $this->user->get_api($_SESSION['api']);
  1584. if($user)
  1585. {
  1586. $fgshop = "";$sid = "";
  1587. $users = explode('|',trim($user['shop'],'|'));
  1588. foreach ($users as $value)
  1589. {
  1590. $fgshop .= " shop = ".$value." or";
  1591. $sid .= " id = ".$value." or";
  1592. }
  1593. if($user['vip'] == 1)
  1594. {
  1595. $vip = 1;
  1596. }
  1597. else
  1598. {
  1599. $vip = 0;
  1600. }
  1601. }
  1602. else
  1603. {
  1604. $vip = 0;
  1605. }
  1606. $post = $this->input->post(NULL, TRUE);
  1607. if(isset($_GET['timetk']))
  1608. {
  1609. $shop = $this->input->get('shop',true);
  1610. $numphone = $this->input->get('numphone',true);
  1611. $name = $this->input->get('name',true);
  1612. $email = $this->input->get('email',true);
  1613. $address = $this->input->get('address',true);
  1614. $level = $this->input->get('level',true);
  1615. $num = $this->input->get('num',true);
  1616. $country = $this->input->get('country',true);
  1617. $excelid = $this->input->get('sid',true);
  1618. $timetk = $this->input->get('timetk',true);
  1619. $timetj = $this->input->get('timetj',true);
  1620. $timetk = strtotime($timetk);
  1621. $timetj = strtotime($timetj);
  1622. $where = "1=1 and type = 1 and (".rtrim($fgshop,'or').")";
  1623. if($shop)
  1624. {
  1625. $where .= " and shop = '$shop'";
  1626. }
  1627. if($numphone)
  1628. {
  1629. $where .= " and numphone = '$numphone'";
  1630. }
  1631. if($name)
  1632. {
  1633. $where .= " and name like '%$name%'";
  1634. }
  1635. if($email)
  1636. {
  1637. $where .= " and email like '%$email%'";
  1638. }
  1639. if($level)
  1640. {
  1641. $where .= " and level = '$level'";
  1642. }
  1643. if($country)
  1644. {
  1645. $where .= " and country = '$country'";
  1646. }
  1647. if($address)
  1648. {
  1649. $where .= " and address like '%$address%'";
  1650. }
  1651. if($num > 0 && $num < 10 && $num != '2a')
  1652. {
  1653. $where .= " and num = '$num'";
  1654. }
  1655. else if($num > 9)
  1656. {
  1657. $where .= " and num > '9'";
  1658. }
  1659. else if($num == '2a')
  1660. {
  1661. $where .= " and num > '1'";
  1662. }
  1663. else
  1664. {
  1665. $where .= " and num >= '0'";
  1666. }
  1667. if($timetk && $timetj)
  1668. {
  1669. $where .= " and ((time > '$timetk' and time < '$timetj') or time = '0')";
  1670. }
  1671. $xzid = '';
  1672. if($excelid)
  1673. {
  1674. $excelid = explode(',',trim($excelid,','));
  1675. foreach ($excelid as $key=>$value)
  1676. {
  1677. $xzid .= " id = ".$value." or";
  1678. }
  1679. $where .= " and (".rtrim($xzid,'or').")";;
  1680. }
  1681. //数据排序
  1682. $order_str = "id desc";
  1683. $numdata = array();
  1684. if(empty($page))
  1685. {
  1686. $start = 0;
  1687. $perpage = 1;
  1688. }
  1689. else
  1690. {
  1691. $start = ($page - 1)*$perpage;
  1692. }
  1693. //取得信息列表
  1694. $info_list = $this->customertt->find_all($where,'shop,name,email,phone,country,level,money,num,numphone,time,count',$order_str);
  1695. foreach ($info_list as $key=>$value)
  1696. {
  1697. $shop = $this->shop->read($value['shop']);
  1698. $info_list[$key]['shop'] = $shop['shopname'];
  1699. if($value['country'] != 0)
  1700. {
  1701. $country = $this->country->read($value['country']);
  1702. $info_list[$key]['country'] = $country['name'];
  1703. }
  1704. else
  1705. {
  1706. $info_list[$key]['country'] = "未知";
  1707. }
  1708. if($value['level'] == 1)
  1709. {
  1710. $info_list[$key]['level'] = "网红";
  1711. }
  1712. else if($value['level'] == 2)
  1713. {
  1714. $info_list[$key]['level'] = "批发";
  1715. }
  1716. else if($value['level'] == 3)
  1717. {
  1718. $info_list[$key]['level'] = "店铺转线下";
  1719. }
  1720. else if($value['level'] == 4)
  1721. {
  1722. $info_list[$key]['level'] = "线下其他";
  1723. }
  1724. else if($value['level'] == 5)
  1725. {
  1726. $info_list[$key]['level'] = "店内客户";
  1727. }
  1728. if($value['time'] != 0)
  1729. {
  1730. $info_list[$key]['time'] = date('Y-m-d',$value['time']);
  1731. }
  1732. else
  1733. {
  1734. $info_list[$key]['time'] = "无";
  1735. }
  1736. $info_list[$key]['numphone'] = ($value['num'] > 0 && $value['money'] > 0)?sprintf("%01.2f",$value['money']/$value['num']):0;
  1737. if(isset($value['email']) && $user['excelpass'] == '1')
  1738. {
  1739. $emailpass = $this->setting->get_excelpass($value['email']);
  1740. $info_list[$key]['email'] = $emailpass;
  1741. }
  1742. if(isset($value['phone']) && $user['excelpass'] == '1')
  1743. {
  1744. $phone = $this->setting->get_excelpass($value['phone']);
  1745. $info_list[$key]['phone'] = $phone;
  1746. }
  1747. }
  1748. $title = "按条件导出";
  1749. $titlename = "<table border=1>
  1750. <tr align='center'>
  1751. <td>店铺</td>
  1752. <td>名称</td>
  1753. <td>邮箱</td>
  1754. <td>电话</td>
  1755. <td>国家</td>
  1756. <td>类型</td>
  1757. <td>总额</td>
  1758. <td>成交次数</td>
  1759. <td>客单价</td>
  1760. <td>最后购买日期</td>
  1761. <td>备注</td>
  1762. </tr>
  1763. </table>";
  1764. $filename = $title.".xls";
  1765. $tail = "";
  1766. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  1767. }
  1768. }
  1769. //下载excel
  1770. public function _excel()
  1771. {
  1772. if(isset($_GET['excel']))
  1773. {
  1774. if(isset($_SESSION['api']))
  1775. {
  1776. $user = $this->user->get_api($_SESSION['api']);
  1777. $usp = $user;
  1778. $fgshop = "";$sid = "";
  1779. $user = explode('|',trim($user['shop'],'|'));
  1780. foreach ($user as $value)
  1781. {
  1782. $fgshop .= " shop = ".$value." or";
  1783. $sid .= " id = ".$value." or";
  1784. }
  1785. }
  1786. $dowid = $this->input->get('a');
  1787. $wid = "";
  1788. if($dowid != "")
  1789. {
  1790. $id_arr = explode(',',rtrim($dowid,','));
  1791. $wid .= " id = 0 or";
  1792. foreach ($id_arr as $v)
  1793. {
  1794. $wid .= " id = '$v' or";
  1795. }
  1796. $wid = " and".rtrim($wid,'or');
  1797. }
  1798. $excel = $this->input->get('excel',true);
  1799. $page = $this->input->get('page',true);
  1800. $perpage = $this->input->get('perpage',true);
  1801. $shop = $this->input->get('shop',true);
  1802. $name = $this->input->get('name',true);
  1803. $country = $this->input->get('country',true);
  1804. $email = $this->input->get('email',true);
  1805. $address = $this->input->get('address',true);
  1806. $level = $this->input->get('level',true);
  1807. $num = $this->input->get('num',true);
  1808. $timetk = $this->input->get('timetk',true);
  1809. $timetj = $this->input->get('timetj',true);
  1810. $timetk = strtotime($timetk);
  1811. $timetj = strtotime($timetj);
  1812. $where = "1 = 1 and (".rtrim($fgshop,'or').")";
  1813. if($shop)
  1814. {
  1815. $where .= " and shop = '$shop'";
  1816. }
  1817. if($name)
  1818. {
  1819. $where .= " and name like '%$name%'";
  1820. }
  1821. if($email)
  1822. {
  1823. $where .= " and email like '%$email%'";
  1824. }
  1825. if($country)
  1826. {
  1827. $where .= " and country = '$country'";
  1828. }
  1829. if($level)
  1830. {
  1831. $where .= " and level = '$level'";
  1832. }
  1833. if($num != '')
  1834. {
  1835. $nu = 1;
  1836. if($num > 9)
  1837. {
  1838. $where .= " and num > '9'";
  1839. }
  1840. else if($num == '2a')
  1841. {
  1842. $where .= " and num > '1'";
  1843. }
  1844. else
  1845. {
  1846. $where .= " and num = '$num'";
  1847. }
  1848. }
  1849. else
  1850. {
  1851. $nu = 2;
  1852. $where .= " and num >= '0'";
  1853. }
  1854. if($address)
  1855. {
  1856. $where .= " and address like '%$address%'";
  1857. }
  1858. if($timetk && $timetj)
  1859. {
  1860. $where .= " and time > '$timetk' and time < '$timetj'";
  1861. }
  1862. $where .= " and type = 1";//白名单用户
  1863. $info_list = array();
  1864. if($excel == 2) //老客户列表
  1865. {
  1866. //$where = str_replace("level = '$level'","level > '1'",$where);
  1867. $info_list = $this->customertt->find_all($where.$wid,'name,email,country,time,num,money,numphone','time desc');
  1868. foreach ($info_list as $key=>$value)
  1869. {
  1870. $info_list[$key]['time'] = date('Y-m-d H:i:s',$value['time']);
  1871. if($value['country'] != 0)
  1872. {
  1873. $country = $this->country->read($value['country']);
  1874. $info_list[$key]['country'] = $country['ename'];
  1875. }
  1876. else
  1877. {
  1878. $info_list[$key]['country'] = '';
  1879. }
  1880. $info_list[$key]['numphone'] = sprintf("%01.2f",$value['money']/$value['num']);
  1881. if(isset($value['email']) && $usp['excelpass'] == '1')
  1882. {
  1883. $emailpass = $this->setting->get_excelpass($value['email']);
  1884. $info_list[$key]['email'] = $emailpass;
  1885. }
  1886. }
  1887. /**
  1888. foreach ($info_list as $key=>$value)
  1889. {
  1890. $value['time'] = date('Y-m-d H:i:s',$value['time']);
  1891. $d = $this->fullordertt->find_count('email = "'.$value['email'].'" and shop = "'.$value['shop'].'" and mergeid = 0','orderinfo,state,product,name,email,dtime,shouldmoney','time desc');
  1892. if($d > 1)
  1893. {
  1894. $info_list[] = $v;
  1895. }
  1896. }
  1897. **/
  1898. $fzh = "<td>客户名</td><td>客户邮箱</td><td>客户国家</td><td>最近一次下单时间</td><td>购买次数</td><td>购买总金额</td><td>客单价</td>";
  1899. $title = "老客户列表";
  1900. }
  1901. else
  1902. {
  1903. $fdata = $this->customertt->find_all($where.$wid,'email,shop','time desc');
  1904. foreach ($fdata as $key=>$value)
  1905. {
  1906. $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');
  1907. if($nu == 2)
  1908. {
  1909. if(count($d) > 1)
  1910. {
  1911. foreach ($d as $k=>$v)
  1912. {
  1913. $v['dtime'] = date('Y-m-d H:i:s',$v['dtime']);
  1914. $typeclass = $this->typeclass->read($v['state']);
  1915. $v['state'] = $typeclass['spare'];
  1916. if($v['country'] != 0)
  1917. {
  1918. $country = $this->country->read($v['country']);
  1919. $v['country'] = $country['ename'];
  1920. }
  1921. else
  1922. {
  1923. $v['country'] = '';
  1924. }
  1925. if(isset($v['email']) && $usp['excelpass'] == '1')
  1926. {
  1927. $emailpass = $this->setting->get_excelpass($v['email']);
  1928. $v['email'] = $emailpass;
  1929. }
  1930. $info_list[] = $v;
  1931. }
  1932. }
  1933. }
  1934. else
  1935. {
  1936. foreach ($d as $k=>$v)
  1937. {
  1938. $v['dtime'] = date('Y-m-d H:i:s',$v['dtime']);
  1939. $typeclass = $this->typeclass->read($v['state']);
  1940. $v['state'] = $typeclass['spare'];
  1941. if($v['country'] != 0)
  1942. {
  1943. $country = $this->country->read($v['country']);
  1944. $v['country'] = $country['ename'];
  1945. }
  1946. else
  1947. {
  1948. $v['country'] = '';
  1949. }
  1950. if(isset($v['email']) && $usp['excelpass'] == '1')
  1951. {
  1952. $emailpass = $this->setting->get_excelpass($v['email']);
  1953. $v['email'] = $emailpass;
  1954. }
  1955. $info_list[] = $v;
  1956. }
  1957. }
  1958. }
  1959. $fzh = "<td>订单号</td><td>订单状态</td><td>产品名</td><td>仓库品名</td><td>客户名</td><td>客户邮箱</td><td>客户国家</td><td>下单时间</td><td>订单金额</td>";
  1960. $title = "老客户订单列表";
  1961. }
  1962. $titlename = "<table border=1>
  1963. <tr>"
  1964. .$fzh.
  1965. "</tr>
  1966. </table>";
  1967. $tail = "\n";
  1968. $filename = $title.'-'.date('Ymd',time()).".xls";
  1969. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  1970. }
  1971. }
  1972. //下载excel模板
  1973. public function _bankdown()
  1974. {
  1975. if(isset($_GET['bankdown']))
  1976. {
  1977. $numphone = $this->input->post('numphone',true);
  1978. $xtime = $this->input->get('xtime',true);
  1979. //$where = "1=1 and type = 2 and (".rtrim($fgshop,'or').")";
  1980. $shop = $this->input->get('shop',true);
  1981. $name = $this->input->get('name',true);
  1982. $email = $this->input->get('email',true);
  1983. $address = $this->input->get('address',true);
  1984. $type = $this->input->get('type',true);
  1985. $id = $this->input->get('id',true);
  1986. $timetk = $this->input->get('timetk',true);
  1987. $timetj = $this->input->get('timetj',true);
  1988. $timetk = strtotime($timetk);
  1989. $timetj = strtotime($timetj);
  1990. if($type)
  1991. {
  1992. $where = "type = '$type'";
  1993. }
  1994. else
  1995. {
  1996. $where = "id != 0";
  1997. }
  1998. if($id)
  1999. {
  2000. $id = explode('|',trim($id,'|'));
  2001. $downid = '';
  2002. foreach ($id as $value)
  2003. {
  2004. $downid .= " id = ".$value." or";
  2005. }
  2006. $where .= " and (".rtrim($downid,'or').")";
  2007. }
  2008. if(!$shop)
  2009. {
  2010. $user = $this->user->get_api($_SESSION['api']);
  2011. $usp = $user;
  2012. $fgshop = "";$sid = "";
  2013. $user = explode('|',trim($user['shop'],'|'));
  2014. foreach ($user as $value)
  2015. {
  2016. $fgshop .= " shop = ".$value." or";
  2017. $sid .= " id = ".$value." or";
  2018. }
  2019. $where .= " and (".rtrim($fgshop,'or').")";
  2020. }
  2021. else
  2022. {
  2023. $where .= " and shop = '$shop'";
  2024. }
  2025. if($email)
  2026. {
  2027. $where .= " and email = '$email'";
  2028. }
  2029. if($name)
  2030. {
  2031. $where .= " and name = '$name'";
  2032. }
  2033. if($address)
  2034. {
  2035. $where .= " and address = '$address'";
  2036. }
  2037. if($xtime)
  2038. {
  2039. $where .= " and typetime > '$timetk' and typetime < '$timetj'";
  2040. }
  2041. $info_list = $this->customertt->find_all($where,'name,address,city,province,zipcode,country,phone,email,level,shop,source,type,count,typetime');
  2042. foreach ($info_list as $key=>$v)
  2043. {
  2044. $country = $this->country->read($v['country']);
  2045. $info_list[$key]['country'] = $country['ename'];
  2046. if($v['level'] == 1)
  2047. {
  2048. $info_list[$key]['level'] = '网红';
  2049. }
  2050. else if($v['level'] == 2)
  2051. {
  2052. $info_list[$key]['level'] = '批发';
  2053. }
  2054. else if($v['level'] == 3)
  2055. {
  2056. $info_list[$key]['level'] = '店铺转线下';
  2057. }
  2058. else if($v['level'] == 4)
  2059. {
  2060. $info_list[$key]['level'] = '线下其他';
  2061. }
  2062. else if($v['level'] == 5)
  2063. {
  2064. $info_list[$key]['level'] = '店内';
  2065. }
  2066. else
  2067. {
  2068. $info_list[$key]['level'] = '未知';
  2069. }
  2070. if($v['typetime'] != 0)
  2071. {
  2072. $info_list[$key]['typetime'] = date('Y-m-d',$v['typetime']);
  2073. }
  2074. else
  2075. {
  2076. $info_list[$key]['typetime'] = "无";
  2077. }
  2078. $shop = $this->shop->read($v['shop']);
  2079. $info_list[$key]['shop'] = $shop['shopname'];
  2080. $source = $this->typeclass->read($v['source']);
  2081. $info_list[$key]['source'] = $source['title'];
  2082. }
  2083. $titledata = array('姓名','详细地址','城市','省/州','邮编','国家','电话','邮箱','类型(1:网红2:批发3:店铺转线下4:线下其他5:店内)','所属店铺(必须ERP已有店铺)','来源(数据字典的户来源需存在)','黑白名单(白名单填1或黑名单填2)','备注','客户分类时间');
  2084. $fzh = "";
  2085. foreach ($titledata as $v)
  2086. {
  2087. $fzh .= "<td>".$v."</td>";
  2088. }
  2089. $title = "客户导出";
  2090. $titlename = "<table border=1>
  2091. <tr>"
  2092. .$fzh.
  2093. "</tr>
  2094. </table>";
  2095. $tail = "\n";
  2096. $filename = $title.".xls";
  2097. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  2098. }
  2099. }
  2100. //下载excel模板
  2101. public function _down()
  2102. {
  2103. if(isset($_GET['excela']))
  2104. {
  2105. $title = "客户导入模板";
  2106. $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','备注'));
  2107. $filename = $title.".xls";
  2108. $this->customertt->get_excel($titledata,$filename);
  2109. }
  2110. }
  2111. public function _newold()
  2112. {
  2113. if(isset($_SESSION['api']))
  2114. {
  2115. $user = $this->user->get_api($_SESSION['api']);
  2116. $usp = $user;
  2117. $fgshop = "";$sid = "";
  2118. $usersp = explode('|',trim($user['shop'],'|'));
  2119. foreach ($usersp as $value)
  2120. {
  2121. $fgshop .= " shop = ".$value." or";
  2122. $sid .= " id = ".$value." or";
  2123. }
  2124. }
  2125. $post = $this->input->post(NULL, TRUE);
  2126. if(isset($post['timek']))
  2127. {
  2128. $new = array();$old = array();$time=array();
  2129. $timek = $this->input->post('timek',true);
  2130. $timej = $this->input->post('timej',true);
  2131. $k = strtotime($timek)-24*3600;//少一天为增加选择开始天时间
  2132. $j = strtotime($timej);
  2133. $n = ($j-$k)/(24*3600);
  2134. if($n < 1)
  2135. {
  2136. $n = 1;
  2137. }
  2138. for($i=1;$i<$n;$i++)
  2139. {
  2140. $nnum = 0;$onum = 0;
  2141. $t = $j-($n*24*60*60)+($i*24*60*60);
  2142. $time[] = date('Y-m-d',$t);
  2143. $ct = strtotime(date('Ymd',$t));
  2144. $ctj = strtotime(date('Ymd',$t+24*3600));
  2145. $info_list = $this->fullordertt->find_all("mergeid = '0' and dtime > '$ct' and dtime < '$ctj' and (".rtrim($fgshop,'or').")");
  2146. foreach ($info_list as $value)
  2147. {
  2148. if($value['email'] != '0' && $value['email'] != '' && $value['email'] != '无')
  2149. {
  2150. $gnum = $this->fullordertt->find_count("email = '".$value['email']."' and shop = '".$value['shop']."' and mergeid = 0");
  2151. if($gnum >1)
  2152. {
  2153. $onum += 1;
  2154. }
  2155. else
  2156. {
  2157. $nnum += 1;
  2158. }
  2159. }
  2160. else
  2161. {
  2162. $nnum += 1;
  2163. }
  2164. }
  2165. $new[] = $nnum;
  2166. $old[] = $onum;
  2167. }
  2168. echo @json_encode(array('time'=>$time,'cnew'=>$new,'cold'=>$old,'success'=>true));exit;
  2169. }
  2170. $this->_Template('customertt_newold',$this->data);
  2171. }
  2172. }