Customer.php 94 KB

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