Customer.php 84 KB

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