Customertt.php 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class customertt extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_customertt','customertt');
  7. $this->load->_model('Model_typeclass','typeclass');
  8. $this->load->_model('Model_shop','shop');
  9. $this->load->_model('Model_country','country');
  10. $this->load->_model('Model_express','express');
  11. $this->load->_model('Model_fullorder','fullorder');
  12. $this->load->_model('Model_fullordertt','fullordertt');
  13. $this->load->_model('Model_excel','excel');
  14. $this->load->_model('Model_whlabel','whlabel');
  15. $this->load->_model('Model_warehouse','warehouse');
  16. $this->load->_model('Model_specialstock','specialstock');
  17. $this->load->_model('Model_ck','ck');
  18. $this->load->_model('Model_weight','weight');
  19. $this->load->_model('Model_pay','pay');
  20. $this->load->_model('Model_setting','setting');
  21. $this->load->_model('Model_classid','classid');
  22. $this->load->_model('Model_apiyy','apiyy');
  23. $this->load->_model('Model_apiyy','apiyy');
  24. $this->load->_model('Model_whlabel_fc','whlabel_fc');
  25. }
  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->customertt->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->customertt->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->fullordertt->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='/customertt/mdedit/".$value['id']."' data-t='客户下单'><b>下单</b></a>&nbsp;&nbsp;&nbsp;&nbsp;<a class='customer' data-type='2' data-t='yr' data-id='".$value['id']."' href='javascript:void(0);'>移入黑名单</a>";
  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->customertt->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('customertt',$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->customertt->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->fullordertt->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='/customertt/mdedit/".$value['id']."' data-t='客户下单'><b>下单</b></a></p><a class='customer' data-type='2' data-t='yr' data-id='".$value['id']."' href='javascript:void(0);'>移入黑名单</a>";
  418. }
  419. $total = $this->customertt->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('customertt',$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->customertt->find_all($where);
  487. $data = $this->customertt->find_all("address like '%".$d[0]['address']."%' or email like '%".$d[0]['email']."%' or numphone like '%".$d[0]['numphone']."%'",'id,shop,source,name,email,country,level,money,num,time,type,numphone,address');
  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->customertt->find_all($where,'id,shop,source,name,email,country,level,money,num,time,type',$order_str,$start,$perpage);
  513. $total = $this->customertt->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='/customertt/mdedit/".$value['id']."' data-t='客户下单'><b>下单</b></a>&nbsp;&nbsp;&nbsp;&nbsp;<a class='customer' data-type='2' data-t='yr' data-id='".$value['id']."' href='javascript:void(0);'>移入黑名单</a>";
  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('customertt_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->customertt->find_all("address like '%".$value['address']."%' or email like '%".$value['email']."%' or numphone like '%".$value['numphone']."%'",'id,shop,source,name,email,country,level,money,num,time,type,numphone,address');
  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->customertt->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->customertt->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->customertt->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('customertt_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->customertt->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->customertt->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->customertt->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('customertt_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->customertt->get_email($post['email'],$post['shop']);
  852. if($kh)
  853. {
  854. echo json_encode(array('msg'=>'此客户已存在!','success'=>false));exit;
  855. }
  856. if($this->customertt->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 = 1514 and (".rtrim($sid,'or').")");
  868. $this->data['wlshop'] = $wlshop;
  869. $this->_Template('customertt_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->customertt->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->customertt->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. $customertt = $this->customertt->read($arg_array);
  923. $this->data['customertt'] = $customertt;
  924. $country = $this->country->find_all('1=1','id,name','name asc');
  925. $this->data['country'] = $country;
  926. $wlshop = $this->shop->find_all("type = 1514 and (".rtrim($sid,'or').")");
  927. $this->data['wlshop'] = $wlshop;
  928. if($customertt['email'] != '0' && $customertt['email'] != '' && $customertt['email'] != '无')
  929. {
  930. $fdata = $this->fullordertt->find_all('email = "'.$customertt['email'].'" and shop = "'.$customertt['shop'].'" and mergeid = 0','orderinfo,state,product,name,email,dtime,shouldmoney','id desc');
  931. foreach ($fdata as $k=>$v)
  932. {
  933. $d = $this->fullordertt->get_orderinfo($v['orderinfo']);
  934. $fdata[$k]['orderinfo'] = "<a href='/fullordertt/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('customertt_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. $customertt = $this->customertt->read($v);
  960. if($customertt['email'] != '0' && $customertt['email'] != '' && $customertt['email'] != '无')
  961. {
  962. $fdata = $this->fullordertt->find_count('email = "'.$customertt['email'].'" and shop = "'.$customertt['shop'].'" and mergeid = 0');
  963. }
  964. if($fdata > 0)
  965. {
  966. $a++;
  967. continue;
  968. }
  969. else
  970. {
  971. $this->customertt->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->customertt->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. $customerttid = $this->input->post('customerttid',true);
  1028. $shop = $this->input->post('shop',true);
  1029. $sp = $this->shop->read($shop);
  1030. $num = $this->fullordertt->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'].'-'.substr(date('ymd',time()),1).'-'.(substr(strval($num+1+1000),1,3));//编号
  1047. if($orderinfo != "")
  1048. {
  1049. $ordefin = $this->fullordertt->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->fullordertt->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. $post['saddress']
  1280. if($post['printtype'] == 1)//如果是运单
  1281. {
  1282. $post['productdescription'] = $this->input->post('productdescription',true);
  1283. $post['customs'] = $this->input->post('customs',true);
  1284. }
  1285. **/
  1286. //开始注释 xyxg
  1287. /**
  1288. $warehousenew = $this->warehouse->read($post['type']);
  1289. $ft = array();
  1290. $ftdata = explode('|',rtrim($fpcount,'|'));
  1291. foreach ($ftdata as $va)
  1292. {
  1293. $ftitle = '';
  1294. $va = explode('-',trim($va,'-'));
  1295. foreach ($va as $v)
  1296. {
  1297. $v = $this->typeclass->read($v);
  1298. $ftitle .= $v['title'].' ';
  1299. }
  1300. $ft[] = rtrim($ftitle,' ');
  1301. }
  1302. $kcyz = $this->whlabel->get_kc($post['state'],$post['state'],$warehousenew['zd'],$warehousenew['ys'],$post['type'],$whlabel,$fpcount,$ft,$post['number'],$shop);//新添加订单老状态state和新状态state一样,不用走删除占用步奏
  1303. if($kcyz['t'] > '0')
  1304. {
  1305. echo $kcyz['m'];exit;
  1306. }
  1307. else
  1308. {
  1309. if($this->fullordertt->insert($post))
  1310. {
  1311. $cusnum = $this->customertt->read($customerttid);
  1312. $this->customertt->save(array('num'=>$cusnum['num']+1,'time'=>$post['buytime']),$customerttid);
  1313. echo json_encode(array('msg'=>'下单成功','success'=>true));exit;
  1314. }
  1315. else
  1316. {
  1317. echo json_encode(array('msg'=>'下单失败,请重试','success'=>false));exit;
  1318. }
  1319. }
  1320. //结束注释
  1321. **/
  1322. $dtctitle = array();
  1323. $dictionaries = $this->typeclass->find_all();
  1324. foreach ($dictionaries as $v)
  1325. {
  1326. $dtctitle[$v['id']] = array($v['title'],$v['bqsku']);
  1327. }
  1328. $fpdata = $post['fpdata'];
  1329. if(stripos($fpdata,'-128-') !== false || stripos($fpdata,'-127-') !== false)
  1330. {
  1331. $dfp = explode(';',trim($fpdata,';'));
  1332. $fdata = '';
  1333. foreach ($dfp as $k=>$v)
  1334. {
  1335. $ptitleb = '';
  1336. $fp = explode('|',trim($v,'|'));
  1337. $fp0 = explode(',',$fp[0]);
  1338. $fp1 = explode('-',trim($fp0[1],'-'));
  1339. foreach ($fp1 as $vv)
  1340. {
  1341. $ptitleb .= isset($dtctitle[$vv])?$dtctitle[$vv][0].' ':'';
  1342. }
  1343. $ptitleb .= $dtctitle[$fp0[0]][1].'inch ';
  1344. $fp[1] = $ptitleb;
  1345. $fdata .= implode("|",$fp).";";
  1346. }
  1347. $fpdata = $fdata;
  1348. }
  1349. $warehouse = $this->warehouse->read($post['type']);
  1350. if($warehouse['bdcountry'] != 0 && $post['country'] != $warehouse['bdcountry'])
  1351. {
  1352. echo json_encode(array('msg'=>'当前国家无法选择'.$warehouse['title'].'!','success'=>false));exit;
  1353. }
  1354. $kcyz = $this->ck->get_kc($post['state'],$warehouse,$post['shop'],$post['number'],$whlabel,$fpdata);
  1355. if($kcyz['t'] > '0')
  1356. {
  1357. echo $kcyz['m'];exit;
  1358. }
  1359. else if($kcyz['fpdata'] != '')
  1360. {
  1361. $post['whlabel'] = $kcyz['whlabel'];
  1362. $post['fpdata'] = $kcyz['fpdata'];
  1363. }
  1364. $fl = $this->ck->get_fl($warehouse['hz'],$whlabel,$fpdata);
  1365. $post['sfxh'] = $fl['sfxh'];
  1366. $post['ckfl'] = $fl['ckfl'];
  1367. //查询净重开始
  1368. $post['jweight'] = $this->weight->get_weightcx($post['fpdata']);
  1369. //查询净重结束
  1370. $cusnum = $this->customertt->read($customerttid);
  1371. $this->customertt->save(array('num'=>$cusnum['num']+1,'time'=>$post['buytime']),$customerttid);
  1372. $this->fullordertt->insert($post);
  1373. echo json_encode(array('msg'=>'下单成功','success'=>true));exit;
  1374. }
  1375. $arg_array = $arg_array[0];//用户ID
  1376. $customertt = $this->customertt->read($arg_array);//用户信息
  1377. $this->data['customertt'] = $customertt;
  1378. $country = $this->country->find_all('1=1','id,name','name asc');//国家
  1379. $this->data['country'] = $country;
  1380. $express = $this->express->find_all();//物流商
  1381. $this->data['express'] = $express;
  1382. $bm = $this->country->read($customertt['country']);
  1383. $this->data['bm'] = $bm;
  1384. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  1385. $this->data['wlshop'] = $wlshop;
  1386. $this->data['user'] = $u['userid'];
  1387. $this->_Template('customertt_mdedit',$this->data);
  1388. }
  1389. //上传excel
  1390. public function _excela()
  1391. {
  1392. $dir = '/data/excel/'.date('Ymd',time()).'/';
  1393. $config['upload_path'] = '.'.$dir ;
  1394. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  1395. $config['allowed_types'] = 'xls|xlsx';
  1396. $config['max_size'] = 10240;
  1397. $this->load->library('upload', $config);
  1398. $this->upload->initialize($config);
  1399. if ($this->upload->do_upload('userfile'))
  1400. {
  1401. $full_path = $dir.$this->upload->data('file_name');
  1402. $fileName = '.' . $full_path;
  1403. if (!file_exists($fileName))
  1404. {
  1405. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  1406. }
  1407. else
  1408. {
  1409. require_once "./data/excel/PHPExcel/IOFactory.php";
  1410. @$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  1411. @$phpExcel->setActiveSheetIndex(0);// 设置为默认表
  1412. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  1413. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  1414. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  1415. ++$column;//如果列数大于26行
  1416. $list = array();
  1417. for ($i = 2; $i <= $row; $i++) // 行数循环
  1418. {
  1419. $data = array();
  1420. for ($c = 'A'; $c != $column; $c++) // 列数循环
  1421. {
  1422. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  1423. }
  1424. $list[] = $data;
  1425. }
  1426. }
  1427. $i = 0;
  1428. $this->db->trans_begin();
  1429. foreach ($list as $key=>$value)
  1430. {
  1431. $value['1'] = $value['1']?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['1']):'';
  1432. $value['7'] = $value['7']?str_replace('/( | | |\s)/','',$value['7']):'';
  1433. if($value['7'] == "" || $value['11'] == "")
  1434. {
  1435. $i++;
  1436. continue;
  1437. }
  1438. else
  1439. {
  1440. $value['7'] = str_replace('/( | | |\s)/','',$value['7']);
  1441. }
  1442. $shop = $this->shop->get_name($value['9']);
  1443. if(!$shop)
  1444. {
  1445. $i++;
  1446. continue;
  1447. }
  1448. if($value['11'] == 2)
  1449. {
  1450. $repeat = $this->customertt->get_address($value['1']);//只判断地址
  1451. }
  1452. else
  1453. {
  1454. $repeat = $this->customertt->find_all('email = "'.$value[7].'" and shop = "'.$shop['id'].'"');//只判断邮箱
  1455. }
  1456. /* 判断邮箱和地址
  1457. if($value['1'] == "" || $value['1'] == " ")
  1458. {
  1459. if($value['7'] == "" || $value['7'] == " ")
  1460. {
  1461. $repeat = 1;
  1462. }
  1463. else
  1464. {
  1465. $repeat = $this->customertt->get_email($value['7']);
  1466. }
  1467. }
  1468. else
  1469. {
  1470. $repeat = $this->customertt->get_address($value['1']);
  1471. }
  1472. */
  1473. if(isset($repeat[0]['type']))
  1474. {
  1475. if($repeat[0]['type'] == $value['11'])
  1476. {
  1477. $i++;
  1478. }
  1479. else if($repeat[0]['type'] != $value['11'])
  1480. {
  1481. $this->customertt->save(array('type'=>$value['11']),$repeat[0]['id']);
  1482. }
  1483. }
  1484. else
  1485. {
  1486. $source = $this->typeclass->get_title($value['10']);
  1487. if($source)
  1488. {
  1489. $post['name'] = ($value['0'] && $value['0'] != 'NULL')?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['0']):'';
  1490. $post['email'] = $value['7'];
  1491. if($value['5'] != '')
  1492. {
  1493. $country = $this->country->get_ename(str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['5']));
  1494. $post['country'] = $country['id'];
  1495. }
  1496. $post['level'] = $value['8']?$value['8']:5;
  1497. $post['phone'] = $value['6']?$value['6']:'';
  1498. $post['province'] = $value['3']?$value['3']:'';
  1499. $post['city'] = $value['2']?$value['2']:'';
  1500. $post['address'] = $value['1'];
  1501. $post['zipcode'] = $value['4']?$value['4']:'';
  1502. $post['shop'] = $shop['id'];
  1503. $post['source'] = $source['id'];
  1504. $post['type'] = $value['11'];
  1505. $val12 = $value['12']?$value['12']:'';
  1506. $post['count'] = $val12;
  1507. $str = $post['phone'];
  1508. preg_match_all('/[0-9]/u',$str,$result);
  1509. $numphone = join('',$result[0]);
  1510. $post['numphone'] = $numphone;
  1511. $this->customertt->insert($post);
  1512. }
  1513. }
  1514. }
  1515. if ($this->db->trans_status() === FALSE)
  1516. {
  1517. $this->db->trans_commit();
  1518. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  1519. }
  1520. else
  1521. {
  1522. if(count($list) == $i)
  1523. {
  1524. $til = '导入全部失败!请检查导入信息';
  1525. }
  1526. else if(count($list) > $i && $i != 0)
  1527. {
  1528. $til = '部分导入成功!'.$i.'条信息有问题,请排查';
  1529. }
  1530. else if($i < 1)
  1531. {
  1532. $til = '导入成功!';
  1533. }
  1534. $this->db->trans_commit();
  1535. echo json_encode(array('msg'=>$til,'success'=>true));exit;
  1536. }
  1537. }
  1538. else
  1539. {
  1540. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  1541. }
  1542. }
  1543. public function _indexexcel()//通过计数,2020/02/21已校准
  1544. {
  1545. $user = $this->user->get_api($_SESSION['api']);
  1546. if($user)
  1547. {
  1548. $fgshop = "";$sid = "";
  1549. $users = explode('|',trim($user['shop'],'|'));
  1550. foreach ($users as $value)
  1551. {
  1552. $fgshop .= " shop = ".$value." or";
  1553. $sid .= " id = ".$value." or";
  1554. }
  1555. if($user['vip'] == 1)
  1556. {
  1557. $vip = 1;
  1558. }
  1559. else
  1560. {
  1561. $vip = 0;
  1562. }
  1563. }
  1564. else
  1565. {
  1566. $vip = 0;
  1567. }
  1568. $post = $this->input->post(NULL, TRUE);
  1569. if(isset($_GET['timetk']))
  1570. {
  1571. $shop = $this->input->get('shop',true);
  1572. $numphone = $this->input->get('numphone',true);
  1573. $name = $this->input->get('name',true);
  1574. $email = $this->input->get('email',true);
  1575. $address = $this->input->get('address',true);
  1576. $level = $this->input->get('level',true);
  1577. $num = $this->input->get('num',true);
  1578. $country = $this->input->get('country',true);
  1579. $excelid = $this->input->get('sid',true);
  1580. $timetk = $this->input->get('timetk',true);
  1581. $timetj = $this->input->get('timetj',true);
  1582. $timetk = strtotime($timetk);
  1583. $timetj = strtotime($timetj);
  1584. $where = "1=1 and type = 1 and (".rtrim($fgshop,'or').")";
  1585. if($shop)
  1586. {
  1587. $where .= " and shop = '$shop'";
  1588. }
  1589. if($numphone)
  1590. {
  1591. $where .= " and numphone = '$numphone'";
  1592. }
  1593. if($name)
  1594. {
  1595. $where .= " and name like '%$name%'";
  1596. }
  1597. if($email)
  1598. {
  1599. $where .= " and email like '%$email%'";
  1600. }
  1601. if($level)
  1602. {
  1603. $where .= " and level = '$level'";
  1604. }
  1605. if($country)
  1606. {
  1607. $where .= " and country = '$country'";
  1608. }
  1609. if($address)
  1610. {
  1611. $where .= " and address like '%$address%'";
  1612. }
  1613. if($num > 0 && $num < 10 && $num != '2a')
  1614. {
  1615. $where .= " and num = '$num'";
  1616. }
  1617. else if($num > 9)
  1618. {
  1619. $where .= " and num > '9'";
  1620. }
  1621. else if($num == '2a')
  1622. {
  1623. $where .= " and num > '1'";
  1624. }
  1625. else
  1626. {
  1627. $where .= " and num >= '0'";
  1628. }
  1629. if($timetk && $timetj)
  1630. {
  1631. $where .= " and ((time > '$timetk' and time < '$timetj') or time = '0')";
  1632. }
  1633. $xzid = '';
  1634. if($excelid)
  1635. {
  1636. $excelid = explode(',',trim($excelid,','));
  1637. foreach ($excelid as $key=>$value)
  1638. {
  1639. $xzid .= " id = ".$value." or";
  1640. }
  1641. $where .= " and (".rtrim($xzid,'or').")";;
  1642. }
  1643. //数据排序
  1644. $order_str = "id desc";
  1645. $numdata = array();
  1646. if(empty($page))
  1647. {
  1648. $start = 0;
  1649. $perpage = 1;
  1650. }
  1651. else
  1652. {
  1653. $start = ($page - 1)*$perpage;
  1654. }
  1655. //取得信息列表
  1656. $info_list = $this->customertt->find_all($where,'shop,name,email,phone,country,level,money,num,numphone,time,count',$order_str);
  1657. foreach ($info_list as $key=>$value)
  1658. {
  1659. $shop = $this->shop->read($value['shop']);
  1660. $info_list[$key]['shop'] = $shop['shopname'];
  1661. if($value['country'] != 0)
  1662. {
  1663. $country = $this->country->read($value['country']);
  1664. $info_list[$key]['country'] = $country['name'];
  1665. }
  1666. else
  1667. {
  1668. $info_list[$key]['country'] = "未知";
  1669. }
  1670. if($value['level'] == 1)
  1671. {
  1672. $info_list[$key]['level'] = "网红";
  1673. }
  1674. else if($value['level'] == 2)
  1675. {
  1676. $info_list[$key]['level'] = "批发";
  1677. }
  1678. else if($value['level'] == 3)
  1679. {
  1680. $info_list[$key]['level'] = "店铺转线下";
  1681. }
  1682. else if($value['level'] == 4)
  1683. {
  1684. $info_list[$key]['level'] = "线下其他";
  1685. }
  1686. else if($value['level'] == 5)
  1687. {
  1688. $info_list[$key]['level'] = "店内客户";
  1689. }
  1690. if($value['time'] != 0)
  1691. {
  1692. $info_list[$key]['time'] = date('Y-m-d',$value['time']);
  1693. }
  1694. else
  1695. {
  1696. $info_list[$key]['time'] = "无";
  1697. }
  1698. $info_list[$key]['numphone'] = ($value['num'] > 0 && $value['money'] > 0)?sprintf("%01.2f",$value['money']/$value['num']):0;
  1699. if(isset($value['email']) && $user['excelpass'] == '1')
  1700. {
  1701. $emailpass = $this->setting->get_excelpass($value['email']);
  1702. $info_list[$key]['email'] = $emailpass;
  1703. }
  1704. if(isset($value['phone']) && $user['excelpass'] == '1')
  1705. {
  1706. $phone = $this->setting->get_excelpass($value['phone']);
  1707. $info_list[$key]['phone'] = $phone;
  1708. }
  1709. }
  1710. $title = "按条件导出";
  1711. $titlename = "<table border=1>
  1712. <tr align='center'>
  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. <td>备注</td>
  1724. </tr>
  1725. </table>";
  1726. $filename = $title.".xls";
  1727. $tail = "";
  1728. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  1729. }
  1730. }
  1731. //下载excel
  1732. public function _excel()
  1733. {
  1734. if(isset($_GET['excel']))
  1735. {
  1736. if(isset($_SESSION['api']))
  1737. {
  1738. $user = $this->user->get_api($_SESSION['api']);
  1739. $usp = $user;
  1740. $fgshop = "";$sid = "";
  1741. $user = explode('|',trim($user['shop'],'|'));
  1742. foreach ($user as $value)
  1743. {
  1744. $fgshop .= " shop = ".$value." or";
  1745. $sid .= " id = ".$value." or";
  1746. }
  1747. }
  1748. $dowid = $this->input->get('a');
  1749. $wid = "";
  1750. if($dowid != "")
  1751. {
  1752. $id_arr = explode(',',rtrim($dowid,','));
  1753. $wid .= " id = 0 or";
  1754. foreach ($id_arr as $v)
  1755. {
  1756. $wid .= " id = '$v' or";
  1757. }
  1758. $wid = " and".rtrim($wid,'or');
  1759. }
  1760. $excel = $this->input->get('excel',true);
  1761. $page = $this->input->get('page',true);
  1762. $perpage = $this->input->get('perpage',true);
  1763. $shop = $this->input->get('shop',true);
  1764. $name = $this->input->get('name',true);
  1765. $country = $this->input->get('country',true);
  1766. $email = $this->input->get('email',true);
  1767. $address = $this->input->get('address',true);
  1768. $level = $this->input->get('level',true);
  1769. $num = $this->input->get('num',true);
  1770. $timetk = $this->input->get('timetk',true);
  1771. $timetj = $this->input->get('timetj',true);
  1772. $timetk = strtotime($timetk);
  1773. $timetj = strtotime($timetj);
  1774. $where = "1 = 1 and (".rtrim($fgshop,'or').")";
  1775. if($shop)
  1776. {
  1777. $where .= " and shop = '$shop'";
  1778. }
  1779. if($name)
  1780. {
  1781. $where .= " and name like '%$name%'";
  1782. }
  1783. if($email)
  1784. {
  1785. $where .= " and email like '%$email%'";
  1786. }
  1787. if($country)
  1788. {
  1789. $where .= " and country = '$country'";
  1790. }
  1791. if($level)
  1792. {
  1793. $where .= " and level = '$level'";
  1794. }
  1795. if($num != '')
  1796. {
  1797. $nu = 1;
  1798. if($num > 9)
  1799. {
  1800. $where .= " and num > '9'";
  1801. }
  1802. else if($num == '2a')
  1803. {
  1804. $where .= " and num > '1'";
  1805. }
  1806. else
  1807. {
  1808. $where .= " and num = '$num'";
  1809. }
  1810. }
  1811. else
  1812. {
  1813. $nu = 2;
  1814. $where .= " and num >= '0'";
  1815. }
  1816. if($address)
  1817. {
  1818. $where .= " and address like '%$address%'";
  1819. }
  1820. if($timetk && $timetj)
  1821. {
  1822. $where .= " and time > '$timetk' and time < '$timetj'";
  1823. }
  1824. $where .= " and type = 1";//白名单用户
  1825. $info_list = array();
  1826. if($excel == 2) //老客户列表
  1827. {
  1828. //$where = str_replace("level = '$level'","level > '1'",$where);
  1829. $info_list = $this->customertt->find_all($where.$wid,'name,email,country,time,num,money,numphone','time desc');
  1830. foreach ($info_list as $key=>$value)
  1831. {
  1832. $info_list[$key]['time'] = date('Y-m-d H:i:s',$value['time']);
  1833. if($value['country'] != 0)
  1834. {
  1835. $country = $this->country->read($value['country']);
  1836. $info_list[$key]['country'] = $country['ename'];
  1837. }
  1838. else
  1839. {
  1840. $info_list[$key]['country'] = '';
  1841. }
  1842. $info_list[$key]['numphone'] = sprintf("%01.2f",$value['money']/$value['num']);
  1843. if(isset($value['email']) && $usp['excelpass'] == '1')
  1844. {
  1845. $emailpass = $this->setting->get_excelpass($value['email']);
  1846. $info_list[$key]['email'] = $emailpass;
  1847. }
  1848. }
  1849. /**
  1850. foreach ($info_list as $key=>$value)
  1851. {
  1852. $value['time'] = date('Y-m-d H:i:s',$value['time']);
  1853. $d = $this->fullordertt->find_count('email = "'.$value['email'].'" and shop = "'.$value['shop'].'" and mergeid = 0','orderinfo,state,product,name,email,dtime,shouldmoney','time desc');
  1854. if($d > 1)
  1855. {
  1856. $info_list[] = $v;
  1857. }
  1858. }
  1859. **/
  1860. $fzh = "<td>客户名</td><td>客户邮箱</td><td>客户国家</td><td>最近一次下单时间</td><td>购买次数</td><td>购买总金额</td><td>客单价</td>";
  1861. $title = "老客户列表";
  1862. }
  1863. else
  1864. {
  1865. $fdata = $this->customertt->find_all($where.$wid,'email,shop','time desc');
  1866. foreach ($fdata as $key=>$value)
  1867. {
  1868. $d = $this->fullordertt->find_all('email = "'.$value['email'].'" and shop = "'.$value['shop'].'" and mergeid = 0','orderinfo,state,product,shipremarks,name,email,country,dtime,shouldmoney','time desc');
  1869. if($nu == 2)
  1870. {
  1871. if(count($d) > 1)
  1872. {
  1873. foreach ($d as $k=>$v)
  1874. {
  1875. $v['dtime'] = date('Y-m-d H:i:s',$v['dtime']);
  1876. $typeclass = $this->typeclass->read($v['state']);
  1877. $v['state'] = $typeclass['spare'];
  1878. if($v['country'] != 0)
  1879. {
  1880. $country = $this->country->read($v['country']);
  1881. $v['country'] = $country['ename'];
  1882. }
  1883. else
  1884. {
  1885. $v['country'] = '';
  1886. }
  1887. if(isset($v['email']) && $usp['excelpass'] == '1')
  1888. {
  1889. $emailpass = $this->setting->get_excelpass($v['email']);
  1890. $v['email'] = $emailpass;
  1891. }
  1892. $info_list[] = $v;
  1893. }
  1894. }
  1895. }
  1896. else
  1897. {
  1898. foreach ($d as $k=>$v)
  1899. {
  1900. $v['dtime'] = date('Y-m-d H:i:s',$v['dtime']);
  1901. $typeclass = $this->typeclass->read($v['state']);
  1902. $v['state'] = $typeclass['spare'];
  1903. if($v['country'] != 0)
  1904. {
  1905. $country = $this->country->read($v['country']);
  1906. $v['country'] = $country['ename'];
  1907. }
  1908. else
  1909. {
  1910. $v['country'] = '';
  1911. }
  1912. if(isset($v['email']) && $usp['excelpass'] == '1')
  1913. {
  1914. $emailpass = $this->setting->get_excelpass($v['email']);
  1915. $v['email'] = $emailpass;
  1916. }
  1917. $info_list[] = $v;
  1918. }
  1919. }
  1920. }
  1921. $fzh = "<td>订单号</td><td>订单状态</td><td>产品名</td><td>仓库品名</td><td>客户名</td><td>客户邮箱</td><td>客户国家</td><td>下单时间</td><td>订单金额</td>";
  1922. $title = "老客户订单列表";
  1923. }
  1924. $titlename = "<table border=1>
  1925. <tr>"
  1926. .$fzh.
  1927. "</tr>
  1928. </table>";
  1929. $tail = "\n";
  1930. $filename = $title.'-'.date('Ymd',time()).".xls";
  1931. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  1932. }
  1933. }
  1934. //下载excel模板
  1935. public function _bankdown()
  1936. {
  1937. if(isset($_GET['bankdown']))
  1938. {
  1939. $numphone = $this->input->post('numphone',true);
  1940. $xtime = $this->input->get('xtime',true);
  1941. //$where = "1=1 and type = 2 and (".rtrim($fgshop,'or').")";
  1942. $shop = $this->input->get('shop',true);
  1943. $name = $this->input->get('name',true);
  1944. $email = $this->input->get('email',true);
  1945. $address = $this->input->get('address',true);
  1946. $type = $this->input->get('type',true);
  1947. $id = $this->input->get('id',true);
  1948. $timetk = $this->input->get('timetk',true);
  1949. $timetj = $this->input->get('timetj',true);
  1950. $timetk = strtotime($timetk);
  1951. $timetj = strtotime($timetj);
  1952. if($type)
  1953. {
  1954. $where = "type = '$type'";
  1955. }
  1956. else
  1957. {
  1958. $where = "id != 0";
  1959. }
  1960. if($id)
  1961. {
  1962. $id = explode('|',trim($id,'|'));
  1963. $downid = '';
  1964. foreach ($id as $value)
  1965. {
  1966. $downid .= " id = ".$value." or";
  1967. }
  1968. $where .= " and (".rtrim($downid,'or').")";
  1969. }
  1970. if(!$shop)
  1971. {
  1972. $user = $this->user->get_api($_SESSION['api']);
  1973. $usp = $user;
  1974. $fgshop = "";$sid = "";
  1975. $user = explode('|',trim($user['shop'],'|'));
  1976. foreach ($user as $value)
  1977. {
  1978. $fgshop .= " shop = ".$value." or";
  1979. $sid .= " id = ".$value." or";
  1980. }
  1981. $where .= " and (".rtrim($fgshop,'or').")";
  1982. }
  1983. else
  1984. {
  1985. $where .= " and shop = '$shop'";
  1986. }
  1987. if($email)
  1988. {
  1989. $where .= " and email = '$email'";
  1990. }
  1991. if($name)
  1992. {
  1993. $where .= " and name = '$name'";
  1994. }
  1995. if($address)
  1996. {
  1997. $where .= " and address = '$address'";
  1998. }
  1999. if($xtime)
  2000. {
  2001. $where .= " and typetime > '$timetk' and typetime < '$timetj'";
  2002. }
  2003. $info_list = $this->customertt->find_all($where,'name,address,city,province,zipcode,country,phone,email,level,shop,source,type,count,typetime');
  2004. foreach ($info_list as $key=>$v)
  2005. {
  2006. $country = $this->country->read($v['country']);
  2007. $info_list[$key]['country'] = $country['ename'];
  2008. if($v['level'] == 1)
  2009. {
  2010. $info_list[$key]['level'] = '网红';
  2011. }
  2012. else if($v['level'] == 2)
  2013. {
  2014. $info_list[$key]['level'] = '批发';
  2015. }
  2016. else if($v['level'] == 3)
  2017. {
  2018. $info_list[$key]['level'] = '店铺转线下';
  2019. }
  2020. else if($v['level'] == 4)
  2021. {
  2022. $info_list[$key]['level'] = '线下其他';
  2023. }
  2024. else if($v['level'] == 5)
  2025. {
  2026. $info_list[$key]['level'] = '店内';
  2027. }
  2028. else
  2029. {
  2030. $info_list[$key]['level'] = '未知';
  2031. }
  2032. if($v['typetime'] != 0)
  2033. {
  2034. $info_list[$key]['typetime'] = date('Y-m-d',$v['typetime']);
  2035. }
  2036. else
  2037. {
  2038. $info_list[$key]['typetime'] = "无";
  2039. }
  2040. $shop = $this->shop->read($v['shop']);
  2041. $info_list[$key]['shop'] = $shop['shopname'];
  2042. $source = $this->typeclass->read($v['source']);
  2043. $info_list[$key]['source'] = $source['title'];
  2044. }
  2045. $titledata = array('姓名','详细地址','城市','省/州','邮编','国家','电话','邮箱','类型(1:网红2:批发3:店铺转线下4:线下其他5:店内)','所属店铺(必须ERP已有店铺)','来源(数据字典的户来源需存在)','黑白名单(白名单填1或黑名单填2)','备注','客户分类时间');
  2046. $fzh = "";
  2047. foreach ($titledata as $v)
  2048. {
  2049. $fzh .= "<td>".$v."</td>";
  2050. }
  2051. $title = "客户导出";
  2052. $titlename = "<table border=1>
  2053. <tr>"
  2054. .$fzh.
  2055. "</tr>
  2056. </table>";
  2057. $tail = "\n";
  2058. $filename = $title.".xls";
  2059. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  2060. }
  2061. }
  2062. //下载excel模板
  2063. public function _down()
  2064. {
  2065. if(isset($_GET['excela']))
  2066. {
  2067. $title = "客户导入模板";
  2068. $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','备注'));
  2069. $filename = $title.".xls";
  2070. $this->customertt->get_excel($titledata,$filename);
  2071. }
  2072. }
  2073. public function _newold()
  2074. {
  2075. if(isset($_SESSION['api']))
  2076. {
  2077. $user = $this->user->get_api($_SESSION['api']);
  2078. $usp = $user;
  2079. $fgshop = "";$sid = "";
  2080. $usersp = explode('|',trim($user['shop'],'|'));
  2081. foreach ($usersp as $value)
  2082. {
  2083. $fgshop .= " shop = ".$value." or";
  2084. $sid .= " id = ".$value." or";
  2085. }
  2086. }
  2087. $post = $this->input->post(NULL, TRUE);
  2088. if(isset($post['timek']))
  2089. {
  2090. $new = array();$old = array();$time=array();
  2091. $timek = $this->input->post('timek',true);
  2092. $timej = $this->input->post('timej',true);
  2093. $k = strtotime($timek)-24*3600;//少一天为增加选择开始天时间
  2094. $j = strtotime($timej);
  2095. $n = ($j-$k)/(24*3600);
  2096. if($n < 1)
  2097. {
  2098. $n = 1;
  2099. }
  2100. for($i=1;$i<$n;$i++)
  2101. {
  2102. $nnum = 0;$onum = 0;
  2103. $t = $j-($n*24*60*60)+($i*24*60*60);
  2104. $time[] = date('Y-m-d',$t);
  2105. $ct = strtotime(date('Ymd',$t));
  2106. $ctj = strtotime(date('Ymd',$t+24*3600));
  2107. $info_list = $this->fullordertt->find_all("mergeid = '0' and dtime > '$ct' and dtime < '$ctj' and (".rtrim($fgshop,'or').")");
  2108. foreach ($info_list as $value)
  2109. {
  2110. if($value['email'] != '0' && $value['email'] != '' && $value['email'] != '无')
  2111. {
  2112. $gnum = $this->fullordertt->find_count("email = '".$value['email']."' and shop = '".$value['shop']."' and mergeid = 0");
  2113. if($gnum >1)
  2114. {
  2115. $onum += 1;
  2116. }
  2117. else
  2118. {
  2119. $nnum += 1;
  2120. }
  2121. }
  2122. else
  2123. {
  2124. $nnum += 1;
  2125. }
  2126. }
  2127. $new[] = $nnum;
  2128. $old[] = $onum;
  2129. }
  2130. echo @json_encode(array('time'=>$time,'cnew'=>$new,'cold'=>$old,'success'=>true));exit;
  2131. }
  2132. $this->_Template('customertt_newold',$this->data);
  2133. }
  2134. }