Customeramz.php 73 KB

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