Customeramz.php 72 KB

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