Customertt.php 74 KB

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