Customer.php 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722
  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. if(empty($post['paypal'])){
  1244. echo json_encode(array('msg'=>'交易号必须填写','success'=>false));exit;
  1245. }
  1246. $express = $this->express->read($post['express']);
  1247. if($post['zsbjz'] > $express['sbjz'])
  1248. {
  1249. echo json_encode(array('msg'=>'总申报价值不可超出'.$express['sbjz'],'success'=>false));exit;
  1250. }
  1251. if($post['shouldmoney'] > $express['shouldmoney'] && $express['shouldmoney'] != 0)
  1252. {
  1253. echo json_encode(array('msg'=>'订单金额不可超出'.$express['shouldmoney'],'success'=>false));exit;
  1254. }
  1255. if($express['ioss'] == 1 && $post['ioss'] == '')
  1256. {
  1257. echo json_encode(array('msg'=>'此快递方式必须选择IOSS!','success'=>false));exit;
  1258. }
  1259. if(strlen($post['address']) > $express['addresssize'] || strlen($post['address2']) > $express['addresssize'])
  1260. {
  1261. echo json_encode(array('msg'=>'此快递方地址不可超出'.$express['addresssize'].'个字符','success'=>false));exit;
  1262. }
  1263. if(strlen($post['address']) < 5)
  1264. {
  1265. echo json_encode(array('msg'=>'地址不可留空!','success'=>false));exit;
  1266. }
  1267. if($post['express'] == '2' && $post['zzl'] > '16' && $post['js'] == '0')
  1268. {
  1269. echo json_encode(array('msg'=>'重量大于16不可按Ground Advantage提交!','success'=>false));exit;
  1270. }
  1271. if($post['express'] == '2' && isset($post['js']) && $post['js'] == '0'&& $post['qm'] == '1')
  1272. {
  1273. echo json_encode(array('msg'=>'Ground Advantage不可使用签名服务!','success'=>false));exit;
  1274. }
  1275. if(($post['express'] == '3' || $post['express'] == '42' || $post['express'] == '24') && $post['shouldmoney'] < 1)
  1276. {
  1277. echo json_encode(array('msg'=>'零金额订单不可发 UPS/DHL官方-美国/Fedex(杭州)','success'=>false));exit;
  1278. }
  1279. if($post['express'] == '42' && $post['zsbjz'] < 1)
  1280. {
  1281. echo json_encode(array('msg'=>'零申报金额不可发 DHL官方-美国','success'=>false));exit;
  1282. }
  1283. if($post['express'] == '6' && $post['province'] == '')
  1284. {
  1285. echo json_encode(array('msg'=>'选择DPEX必须填写州信息','success'=>false));exit;
  1286. }
  1287. /**
  1288. $post['saddress']
  1289. if($post['printtype'] == 1)//如果是运单
  1290. {
  1291. $post['productdescription'] = $this->input->post('productdescription',true);
  1292. $post['customs'] = $this->input->post('customs',true);
  1293. }
  1294. **/
  1295. //开始注释 xyxg
  1296. /**
  1297. $warehousenew = $this->warehouse->read($post['type']);
  1298. $ft = array();
  1299. $ftdata = explode('|',rtrim($fpcount,'|'));
  1300. foreach ($ftdata as $va)
  1301. {
  1302. $ftitle = '';
  1303. $va = explode('-',trim($va,'-'));
  1304. foreach ($va as $v)
  1305. {
  1306. $v = $this->typeclass->read($v);
  1307. $ftitle .= $v['title'].' ';
  1308. }
  1309. $ft[] = rtrim($ftitle,' ');
  1310. }
  1311. $kcyz = $this->whlabel->get_kc($post['state'],$post['state'],$warehousenew['zd'],$warehousenew['ys'],$post['type'],$whlabel,$fpcount,$ft,$post['number'],$shop);//新添加订单老状态state和新状态state一样,不用走删除占用步奏
  1312. if($kcyz['t'] > '0')
  1313. {
  1314. echo $kcyz['m'];exit;
  1315. }
  1316. else
  1317. {
  1318. if($this->fullorder->insert($post))
  1319. {
  1320. $cusnum = $this->customer->read($customerid);
  1321. $this->customer->save(array('num'=>$cusnum['num']+1,'time'=>$post['buytime']),$customerid);
  1322. echo json_encode(array('msg'=>'下单成功','success'=>true));exit;
  1323. }
  1324. else
  1325. {
  1326. echo json_encode(array('msg'=>'下单失败,请重试','success'=>false));exit;
  1327. }
  1328. }
  1329. //结束注释
  1330. **/
  1331. $dtctitle = array();
  1332. $dictionaries = $this->typeclass->find_all();
  1333. foreach ($dictionaries as $v)
  1334. {
  1335. $dtctitle[$v['id']] = array($v['title'],$v['bqsku']);
  1336. }
  1337. $fpdata = $post['fpdata'];
  1338. if(stripos($fpdata,'-128-') !== false || stripos($fpdata,'-127-') !== false)
  1339. {
  1340. $dfp = explode(';',trim($fpdata,';'));
  1341. $fdata = '';
  1342. foreach ($dfp as $k=>$v)
  1343. {
  1344. $ptitleb = '';
  1345. $fp = explode('|',trim($v,'|'));
  1346. $fp0 = explode(',',$fp[0]);
  1347. if(isset($fp0[1]))
  1348. {
  1349. $fp1 = explode('-',trim($fp0[1],'-'));
  1350. }
  1351. else
  1352. {
  1353. $fp1 = explode('-',trim($fp[0],'-'));
  1354. }
  1355. foreach ($fp1 as $vv)
  1356. {
  1357. $ptitleb .= isset($dtctitle[$vv])?$dtctitle[$vv][0].' ':'';
  1358. }
  1359. if(isset($fp0[1]))
  1360. {
  1361. $ptitleb .= $dtctitle[$fp0[0]][1].'inch ';
  1362. $fp[1] = $ptitleb;
  1363. }
  1364. $fdata .= implode("|",$fp).";";
  1365. }
  1366. $fpdata = $fdata;
  1367. }
  1368. $warehouse = $this->warehouse->read($post['type']);
  1369. if($warehouse['bdcountry'] != 0 && $post['country'] != $warehouse['bdcountry'])
  1370. {
  1371. echo json_encode(array('msg'=>'当前国家无法选择'.$warehouse['title'].'!','success'=>false));exit;
  1372. }
  1373. $kcyz = $this->ck->get_kc($post['state'],$warehouse,$post['shop'],$post['number'],$whlabel,$fpdata);
  1374. if($kcyz['t'] > '0')
  1375. {
  1376. echo $kcyz['m'];exit;
  1377. }
  1378. else if($kcyz['fpdata'] != '')
  1379. {
  1380. $post['whlabel'] = $kcyz['whlabel'];
  1381. $post['fpdata'] = $kcyz['fpdata'];
  1382. }
  1383. $fl = $this->ck->get_fl($warehouse['hz'],$whlabel,$fpdata);
  1384. $post['sfxh'] = $fl['sfxh'];
  1385. $post['ckfl'] = $fl['ckfl'];
  1386. //查询净重开始
  1387. $post['jweight'] = $this->weight->get_weightcx($post['fpdata']);
  1388. //查询净重结束
  1389. $cusnum = $this->customer->read($customerid);
  1390. $this->customer->save(array('num'=>$cusnum['num']+1,'time'=>$post['buytime']),$customerid);
  1391. unset($post['id']);
  1392. $this->fullorder->insert($post);
  1393. echo json_encode(array('msg'=>'下单成功','success'=>true));exit;
  1394. }
  1395. $arg_array = $arg_array[0];//用户ID
  1396. $customer = $this->customer->read($arg_array);//用户信息
  1397. $this->data['customer'] = $customer;
  1398. $country = $this->country->find_all('1=1','id,name','name asc');//国家
  1399. $this->data['country'] = $country;
  1400. $express = $this->express->find_all();//物流商
  1401. $this->data['express'] = $express;
  1402. $bm = $this->country->read($customer['country']);
  1403. $this->data['bm'] = $bm;
  1404. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  1405. $this->data['wlshop'] = $wlshop;
  1406. $this->data['user'] = $u['userid'];
  1407. $this->_Template('customer_mdedit',$this->data);
  1408. }
  1409. //上传excel
  1410. public function _excela()
  1411. {
  1412. $dir = '/data/excel/'.date('Ymd',time()).'/';
  1413. $config['upload_path'] = '.'.$dir ;
  1414. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  1415. $config['allowed_types'] = 'xls|xlsx';
  1416. $config['max_size'] = 10240;
  1417. $this->load->library('upload', $config);
  1418. $this->upload->initialize($config);
  1419. if ($this->upload->do_upload('userfile'))
  1420. {
  1421. $full_path = $dir.$this->upload->data('file_name');
  1422. $fileName = '.' . $full_path;
  1423. if (!file_exists($fileName))
  1424. {
  1425. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  1426. }
  1427. else
  1428. {
  1429. require_once "./data/excel/PHPExcel/IOFactory.php";
  1430. @$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  1431. @$phpExcel->setActiveSheetIndex(0);// 设置为默认表
  1432. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  1433. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  1434. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  1435. ++$column;//如果列数大于26行
  1436. $list = array();
  1437. for ($i = 2; $i <= $row; $i++) // 行数循环
  1438. {
  1439. $data = array();
  1440. for ($c = 'A'; $c != $column; $c++) // 列数循环
  1441. {
  1442. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  1443. }
  1444. $list[] = $data;
  1445. }
  1446. }
  1447. $i = 0;
  1448. $this->db->trans_begin();
  1449. foreach ($list as $key=>$value)
  1450. {
  1451. $value['1'] = $value['1']?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['1']):'';
  1452. $value['7'] = $value['7']?str_replace('/( | | |\s)/','',$value['7']):'';
  1453. if($value['7'] == "" || $value['11'] == "")
  1454. {
  1455. $i++;
  1456. continue;
  1457. }
  1458. else
  1459. {
  1460. $value['7'] = str_replace('/( | | |\s)/','',$value['7']);
  1461. }
  1462. $shop = $this->shop->get_name($value['9']);
  1463. if(!$shop)
  1464. {
  1465. $i++;
  1466. continue;
  1467. }
  1468. if($value['11'] == 2)
  1469. {
  1470. $repeat = $this->customer->get_address($value['1']);//只判断地址
  1471. }
  1472. else
  1473. {
  1474. $repeat = $this->customer->find_all('email = "'.$value[7].'" and shop = "'.$shop['id'].'"');//只判断邮箱
  1475. }
  1476. /* 判断邮箱和地址
  1477. if($value['1'] == "" || $value['1'] == " ")
  1478. {
  1479. if($value['7'] == "" || $value['7'] == " ")
  1480. {
  1481. $repeat = 1;
  1482. }
  1483. else
  1484. {
  1485. $repeat = $this->customer->get_email($value['7']);
  1486. }
  1487. }
  1488. else
  1489. {
  1490. $repeat = $this->customer->get_address($value['1']);
  1491. }
  1492. */
  1493. if(isset($repeat[0]['type']))
  1494. {
  1495. if($repeat[0]['type'] == $value['11'])
  1496. {
  1497. $i++;
  1498. }
  1499. else if($repeat[0]['type'] != $value['11'])
  1500. {
  1501. $this->customer->save(array('type'=>$value['11']),$repeat[0]['id']);
  1502. }
  1503. }
  1504. else
  1505. {
  1506. $source = $this->typeclass->get_title($value['10']);
  1507. if($source)
  1508. {
  1509. $post['name'] = ($value['0'] && $value['0'] != 'NULL')?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['0']):'';
  1510. $post['email'] = $value['7'];
  1511. if($value['5'] != '')
  1512. {
  1513. $country = $this->country->get_ename(str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['5']));
  1514. $post['country'] = $country['id'];
  1515. }
  1516. $post['level'] = $value['8']?$value['8']:5;
  1517. $post['phone'] = $value['6']?$value['6']:'';
  1518. $post['province'] = $value['3']?$value['3']:'';
  1519. $post['city'] = $value['2']?$value['2']:'';
  1520. $post['address'] = $value['1'];
  1521. $post['zipcode'] = $value['4']?$value['4']:'';
  1522. $post['shop'] = $shop['id'];
  1523. $post['source'] = $source['id'];
  1524. $post['type'] = $value['11'];
  1525. $val12 = $value['12']?$value['12']:'';
  1526. $post['count'] = $val12;
  1527. $str = $post['phone'];
  1528. preg_match_all('/[0-9]/u',$str,$result);
  1529. $numphone = join('',$result[0]);
  1530. $post['numphone'] = $numphone;
  1531. $this->customer->insert($post);
  1532. }
  1533. }
  1534. }
  1535. if ($this->db->trans_status() === FALSE)
  1536. {
  1537. $this->db->trans_commit();
  1538. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  1539. }
  1540. else
  1541. {
  1542. if(count($list) == $i)
  1543. {
  1544. $til = '导入全部失败!请检查导入信息';
  1545. }
  1546. else if(count($list) > $i && $i != 0)
  1547. {
  1548. $til = '部分导入成功!'.$i.'条信息有问题,请排查';
  1549. }
  1550. else if($i < 1)
  1551. {
  1552. $til = '导入成功!';
  1553. }
  1554. $this->db->trans_commit();
  1555. echo json_encode(array('msg'=>$til,'success'=>true));exit;
  1556. }
  1557. }
  1558. else
  1559. {
  1560. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  1561. }
  1562. }
  1563. public function _temuexcel()
  1564. {
  1565. $dir = '/data/excel/'.date('Ymd',time()).'/';
  1566. $config['upload_path'] = '.'.$dir ;
  1567. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  1568. $config['allowed_types'] = 'xls|xlsx';
  1569. $config['max_size'] = 10240;
  1570. $this->load->library('upload', $config);
  1571. $this->upload->initialize($config);
  1572. if ($this->upload->do_upload('userfile'))
  1573. {
  1574. $full_path = $dir.$this->upload->data('file_name');
  1575. $fileName = '.' . $full_path;
  1576. if (!file_exists($fileName))
  1577. {
  1578. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  1579. }
  1580. else
  1581. {
  1582. require_once "./data/excel/PHPExcel/IOFactory.php";
  1583. @$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  1584. @$phpExcel->setActiveSheetIndex(0);// 设置为默认表
  1585. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  1586. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  1587. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  1588. ++$column;//如果列数大于26行
  1589. $list = array();
  1590. for ($i = 2; $i <= $row; $i++) // 行数循环
  1591. {
  1592. $data = array();
  1593. for ($c = 'A'; $c != $column; $c++) // 列数循环
  1594. {
  1595. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  1596. }
  1597. $list[] = $data;
  1598. }
  1599. }
  1600. $i = 0;
  1601. $gethl = $this->hl->get_hl();//获取即时汇率
  1602. $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');
  1603. $dtc = array();
  1604. foreach ($dictionaries as $v)
  1605. {
  1606. if(stripos($v['spare'],'|') !== false)//如果有多个值
  1607. {
  1608. $v['spare'] = explode('|',$v['spare']);
  1609. foreach ($v['spare'] as $k=>$vs)
  1610. {
  1611. if(stripos($v['zh'],'|') !== false)
  1612. {
  1613. $vzh = explode('|',$v['zh']);
  1614. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$vzh[$k],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
  1615. }
  1616. else
  1617. {
  1618. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
  1619. }
  1620. }
  1621. }
  1622. else
  1623. {
  1624. $dtc[strtolower($v['spare'])] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$v['spare']);
  1625. }
  1626. }
  1627. $dk = array();
  1628. $dictionaries2 = $this->typeclass->find_all();
  1629. foreach ($dictionaries2 as $v)
  1630. {
  1631. $dtctitle[$v['id']] = $v['title'];
  1632. $dk[$v['id']] = $v['bqsku'];
  1633. }
  1634. /* 匹配结束 */
  1635. /* 价格加入 */
  1636. $money = array();
  1637. $productdescribe = $this->productdescribe->find_all('1=1');
  1638. foreach ($productdescribe as $v)
  1639. {
  1640. $money[$v['number']] = array();
  1641. }
  1642. /* 价格加入 */
  1643. /* 匹配ID加入 */
  1644. $int = array();
  1645. $intdata = $this->typeclass->find_all('classid=14','id,spare');
  1646. foreach ($intdata as $v)
  1647. {
  1648. $v['spare'] = explode('|',$v['spare']);
  1649. $int[$v['id']] = $v['spare'][0];
  1650. }
  1651. /* 匹配ID加入 */
  1652. $zjsku = array();
  1653. $shopsku = $this->shopsku->find_all();
  1654. foreach ($shopsku as $val)
  1655. {
  1656. $ss = explode(',',trim($val['shop'],','));
  1657. foreach ($ss as $v)
  1658. {
  1659. if(isset($zjsku[$v]))
  1660. {
  1661. $zjsku[$v] .= ','.trim($val['sku'],',');
  1662. }
  1663. else
  1664. {
  1665. $zjsku[$v] = trim($val['sku'],',');
  1666. }
  1667. }
  1668. }
  1669. /* 匹配ID结束 */
  1670. $this->db->trans_begin();
  1671. foreach ($list as $key=>$value)
  1672. {
  1673. $addtess = ($value['15']!='--'?$value['15'].' ':'').($value['14']!='--'?$value['14'].' ':'').$value['13'];
  1674. $addtess = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$addtess);
  1675. $repeat = $this->customer->find_all('phone = "'.$value[11].'" and address = "'.($value['15']!='--'?$value['15'].' ':'').($value['14']!='--'?$value['14'].' ':'').$value['13'].'" and shop = 19');//判断电话地址
  1676. $sku = $value['8'];
  1677. $je = (isset($value['28']))?$value['28']:0;
  1678. $value['29'] = str_replace('/','-',$value['29']);
  1679. $dtime = strtotime($value['29']);
  1680. $post['name'] = ($value['10'] && $value['10'] != 'NULL')?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['10']):'';
  1681. $post['email'] = $value['12'];
  1682. if($value['20'] != '')
  1683. {
  1684. $country = $this->country->get_ename(str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['20']));
  1685. $post['country'] = $country['id'];
  1686. }
  1687. $post['level'] = 4;
  1688. $post['phone'] = $value['11']?$value['11']:'';
  1689. $post['province'] = $value['18']?$value['18']:'';
  1690. $post['city'] = $value['17']?$value['17']:'';
  1691. $post['address'] = $addtess;
  1692. $post['zipcode'] = $value['19']?$value['19']:'';
  1693. $post['shop'] = 19;
  1694. $post['source'] = 2;
  1695. $post['type'] = 1;
  1696. $post['count'] = '';
  1697. $post['time'] = $dtime;
  1698. $str = $post['phone'];
  1699. preg_match_all('/[0-9]/u',$str,$result);
  1700. $numphone = join('',$result[0]);
  1701. $post['numphone'] = $numphone;
  1702. if(!isset($repeat[0]))
  1703. {
  1704. $this->customer->insert($post);
  1705. }
  1706. else
  1707. {
  1708. $this->customer->save(array('num'=>$repeat[0]['num']+1),$repeat[0]['id']);
  1709. }
  1710. $sbsku = '';
  1711. $whlabel = $this->whlabel->get_sku($sku);
  1712. if($whlabel)
  1713. {
  1714. $w = explode('-',trim($whlabel['features'],'-'));
  1715. foreach ($w as $v)
  1716. {
  1717. if(isset($dk[$v]))
  1718. {
  1719. $sbsku .= $dk[$v].'-';
  1720. }
  1721. }
  1722. }
  1723. $sbsku = trim($sbsku,'-');
  1724. $time = time();
  1725. $shop = $this->shop->read(19);
  1726. $ddpost['orderremarks'] = isset($value['30'])?$value['30']:'';
  1727. $ddpost['shop'] = $shop['id'];//店铺ID
  1728. $ddpost['user'] = $shop['shopuser'];//店铺负责人
  1729. $orderid = 0;
  1730. $ddpost['orderid'] = 0;
  1731. $ddpost['product'] = '';//产品名称
  1732. $ddpost['link'] = '';//产品链接
  1733. $ddpost['issku'] = $sku;
  1734. $ddpost['quantity'] = rtrim($value['3'],';');
  1735. $ddpost['clientremarks'] = '';//客户备注
  1736. //$ddpost['paypal'] = '';//交易号
  1737. $ddpost['guarantee'] = '';//卖家保障
  1738. $ddpost['parameter'] = '';//属性
  1739. $ddpost['shippingmethod'] = '';//用户选择快递方式及运费金额
  1740. $ddpost['source'] = 2;//订单类型
  1741. $ddpost['type'] = 1;//发货仓库
  1742. $ddpost['capital'] = 3;//资金支付状况,全部付款
  1743. $num = $this->fullorder->find_count('gtime = "'.date('Ymd',$dtime).'" and shop = 19');
  1744. $ddpost['number'] = $shop['shortname'].'-'.substr(date('ymd',$dtime),1).'-'.(substr(strval($num+1+1000),1,3));//编号
  1745. $ddpost['orderinfo'] = preg_replace('/[^0-9]/', '', $value['0']);//订单号
  1746. $d = $this->fullorder->get_orderinfo($ddpost['orderinfo']);
  1747. if(isset($d['id']))
  1748. {
  1749. $i++;
  1750. continue;
  1751. }
  1752. $ddpost['paypal'] = $ddpost['orderinfo'];
  1753. $ddpost['insurance'] = 0;//运输保险费用
  1754. $ddpost['baddress'] = '';
  1755. $ddpost['saddress'] = '';
  1756. $ddpost['country'] = $country['id'];//此国家的ID
  1757. $ddpost['al'] = $country['lb'];//联邦名称
  1758. $ddpost['bname'] = $post['name'];//名称
  1759. $ddpost['sname'] = $post['name'];//名称
  1760. $ddpost['client'] = $post['name'];//公司名称
  1761. $ddpost['name'] = $post['name'];//收件人名称
  1762. $ddpost['phone'] = $post['phone'];//收件人电话
  1763. $ddpost['email'] = $post['email'];//客户邮箱
  1764. $ddpost['zipcode'] = $post['zipcode'];//收件人邮编
  1765. $ddpost['province'] = $post['province'];//收件人省份
  1766. $ddpost['city'] = $post['city'];//收件人城市
  1767. $ddpost['address'] = $post['address'];//收件人地址
  1768. $ddpost['shouldmoney'] = $je;//应收金额
  1769. $ddpost['skje'] = $je;//收款金额
  1770. $ddpost['ismoney'] = '';//支付币种金额
  1771. $ddpost['shouldmoney'] = $je;//金额
  1772. $ddpost['budget'] = $je;//预估到帐金额
  1773. $ddpost['buytime'] = $dtime;//格式化付款时间
  1774. $ddpost['dtime'] = $dtime;//订单时间
  1775. $ddpost['gtime'] = date('Ymd',$dtime);//格式化订单时间
  1776. $ddpost['currencytitle'] = 'USD';//结算币种名称
  1777. $ddpost['currency'] = 219;//钱币ID
  1778. $ddpost['time'] = time();//同步时间
  1779. $ddpost['shopify'] = 0;//同步时间
  1780. $ddpost['hl'] = '6.4';//汇率
  1781. $matching = $this->api->matching($ddpost['quantity'],$sbsku,$dtc,$money,$int,$dtctitle,$shop);
  1782. $ddpost['shipremarks'] = $matching['title'];
  1783. $ddpost['cost'] = $matching['cost'];
  1784. $ddpost['purchase'] = $matching['purchase'];
  1785. $ddpost['fpdata'] = $matching['product'];
  1786. $ddpost['whlabel'] = $matching['whlabel'];
  1787. $ddpost['slpx'] = $matching['wcslpx'];
  1788. $ddpost['state'] = 207;
  1789. $ddpost['type'] = 17;
  1790. $this->fullorder->insert($ddpost);
  1791. }
  1792. if ($this->db->trans_status() === FALSE)
  1793. {
  1794. $this->db->trans_commit();
  1795. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  1796. }
  1797. else
  1798. {
  1799. if(count($list) == $i)
  1800. {
  1801. $til = '导入全部失败!请检查导入信息';
  1802. }
  1803. else if(count($list) > $i && $i != 0)
  1804. {
  1805. $til = '部分导入成功!'.$i.'条信息有问题,请排查';
  1806. }
  1807. else if($i < 1)
  1808. {
  1809. $til = '导入成功!';
  1810. }
  1811. $this->db->trans_commit();
  1812. echo json_encode(array('msg'=>$til,'success'=>true));exit;
  1813. }
  1814. }
  1815. else
  1816. {
  1817. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  1818. }
  1819. }
  1820. //代发客户导入
  1821. public function _daifakehuexcel()
  1822. {
  1823. $shopid = 0;
  1824. $user = $this->user->get_api($_SESSION['api']);
  1825. if($user)
  1826. {
  1827. $users = explode('|',trim($user['shop'],'|'));
  1828. if(count($users) == 1){
  1829. $shopid = $users[0];
  1830. }else{
  1831. echo json_encode(array('msg'=>"此账号不能用于该功能!",'success'=>true));exit;
  1832. }
  1833. }
  1834. if(empty($shopid)){
  1835. echo json_encode(array('msg'=>"系统无法识别店铺!",'success'=>true));exit;
  1836. }
  1837. $dir = '/data/excel/'.date('Ymd',time()).'/';
  1838. $config['upload_path'] = '.'.$dir ;
  1839. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  1840. $config['allowed_types'] = 'xls|xlsx';
  1841. $config['max_size'] = 10240;
  1842. $this->load->library('upload', $config);
  1843. $this->upload->initialize($config);
  1844. if ($this->upload->do_upload('userfile'))
  1845. {
  1846. $full_path = $dir.$this->upload->data('file_name');
  1847. $fileName = '.' . $full_path;
  1848. if (!file_exists($fileName))
  1849. {
  1850. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  1851. }
  1852. else
  1853. {
  1854. require_once "./data/excel/PHPExcel/IOFactory.php";
  1855. @$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  1856. @$phpExcel->setActiveSheetIndex(0);// 设置为默认表
  1857. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  1858. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  1859. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  1860. ++$column;//如果列数大于26行
  1861. $list = array();
  1862. for ($i = 2; $i <= $row; $i++) // 行数循环
  1863. {
  1864. $data = array();
  1865. for ($c = 'A'; $c != $column; $c++) // 列数循环
  1866. {
  1867. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  1868. }
  1869. $list[] = $data;
  1870. }
  1871. }
  1872. $i = 0;
  1873. $gethl = $this->hl->get_hl();//获取即时汇率
  1874. $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');
  1875. $dtc = array();
  1876. foreach ($dictionaries as $v)
  1877. {
  1878. if(stripos($v['spare'],'|') !== false)//如果有多个值
  1879. {
  1880. $v['spare'] = explode('|',$v['spare']);
  1881. foreach ($v['spare'] as $k=>$vs)
  1882. {
  1883. if(stripos($v['zh'],'|') !== false)
  1884. {
  1885. $vzh = explode('|',$v['zh']);
  1886. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$vzh[$k],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
  1887. }
  1888. else
  1889. {
  1890. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
  1891. }
  1892. }
  1893. }
  1894. else
  1895. {
  1896. $dtc[strtolower($v['spare'])] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$v['spare']);
  1897. }
  1898. }
  1899. $dk = array();
  1900. $dictionaries2 = $this->typeclass->find_all();
  1901. foreach ($dictionaries2 as $v)
  1902. {
  1903. $dtctitle[$v['id']] = $v['title'];
  1904. $dk[$v['id']] = $v['bqsku'];
  1905. }
  1906. /* 匹配结束 */
  1907. /* 价格加入 */
  1908. $money = array();
  1909. $productdescribe = $this->productdescribe->find_all('1=1');
  1910. foreach ($productdescribe as $v)
  1911. {
  1912. $money[$v['number']] = array();
  1913. }
  1914. /* 价格加入 */
  1915. /* 匹配ID加入 */
  1916. $int = array();
  1917. $intdata = $this->typeclass->find_all('classid=14','id,spare');
  1918. foreach ($intdata as $v)
  1919. {
  1920. $v['spare'] = explode('|',$v['spare']);
  1921. $int[$v['id']] = $v['spare'][0];
  1922. }
  1923. /* 匹配ID加入 */
  1924. $zjsku = array();
  1925. $shopsku = $this->shopsku->find_all();
  1926. foreach ($shopsku as $val)
  1927. {
  1928. $ss = explode(',',trim($val['shop'],','));
  1929. foreach ($ss as $v)
  1930. {
  1931. if(isset($zjsku[$v]))
  1932. {
  1933. $zjsku[$v] .= ','.trim($val['sku'],',');
  1934. }
  1935. else
  1936. {
  1937. $zjsku[$v] = trim($val['sku'],',');
  1938. }
  1939. }
  1940. }
  1941. /* 匹配ID结束 */
  1942. $this->db->trans_begin();
  1943. foreach ($list as $key=>$value)
  1944. {
  1945. $addtess = $value[7].$value[6];
  1946. $addtess = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$addtess);
  1947. $repeat = $this->customer->find_all('phone = "'.$value[4].'" and address = "'.$addtess.'" and shop = '.$shopid);//判断电话地址
  1948. $sku = $value['2'];
  1949. $je = (isset($value['12']))?$value['12']:0;
  1950. if(!empty($value[13])){
  1951. $value['13'] = str_replace('/','-',$value['13']);
  1952. $dtime = strtotime($value['13']);
  1953. }else{
  1954. $dtime = time();
  1955. }
  1956. $post['name'] = (!empty($value[3]))?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['3']):'';
  1957. $post['email'] = $value['5'];
  1958. if($value['11'] != '')
  1959. {
  1960. $country = $this->country->get_ename(str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['11']));
  1961. $post['country'] = $country['id'];
  1962. }
  1963. $post['level'] = 4;
  1964. $post['phone'] = $value['4']?$value['4']:'';
  1965. $post['province'] = $value['9']?$value['9']:'';
  1966. $post['city'] = $value['8']?$value['8']:'';
  1967. $post['address'] = $addtess;
  1968. $post['zipcode'] = $value['10']?$value['10']:'';
  1969. $post['shop'] = $shopid;
  1970. $post['source'] = 2;
  1971. $post['type'] = 1;
  1972. $post['count'] = '';
  1973. $post['time'] = $dtime;
  1974. $str = $post['phone'];
  1975. preg_match_all('/[0-9]/u',$str,$result);
  1976. $numphone = join('',$result[0]);
  1977. $post['numphone'] = $numphone;
  1978. if(!isset($repeat[0]))
  1979. {
  1980. $this->customer->insert($post);
  1981. }
  1982. else
  1983. {
  1984. $this->customer->save(array('num'=>$repeat[0]['num']+1),$repeat[0]['id']);
  1985. }
  1986. $sbsku = '';
  1987. $whlabel = $this->whlabel->get_sku($sku);
  1988. if($whlabel)
  1989. {
  1990. $w = explode('-',trim($whlabel['features'],'-'));
  1991. foreach ($w as $v)
  1992. {
  1993. if(isset($dk[$v]))
  1994. {
  1995. $sbsku .= $dk[$v].'-';
  1996. }
  1997. }
  1998. }
  1999. $sbsku = trim($sbsku,'-');
  2000. $time = time();
  2001. $shop = $this->shop->read($shopid);
  2002. $ddpost['orderremarks'] = '';
  2003. $ddpost['shop'] = $shop['id'];//店铺ID
  2004. $ddpost['user'] = $shop['shopuser'];//店铺负责人
  2005. $orderid = 0;
  2006. $ddpost['orderid'] = 0;
  2007. $ddpost['product'] = '';//产品名称
  2008. $ddpost['link'] = '';//产品链接
  2009. $ddpost['issku'] = $sku;
  2010. $ddpost['quantity'] = rtrim($value['1'],';');
  2011. $ddpost['clientremarks'] = '';//客户备注
  2012. $ddpost['guarantee'] = '';//卖家保障
  2013. $ddpost['parameter'] = '';//属性
  2014. $ddpost['shippingmethod'] = '';//用户选择快递方式及运费金额
  2015. $ddpost['source'] = 2;//订单类型
  2016. $ddpost['type'] = 1;//发货仓库
  2017. $ddpost['capital'] = 3;//资金支付状况,全部付款
  2018. $num = $this->fullorder->find_count('gtime = "'.date('Ymd',$dtime).'" and shop = '.$shopid);
  2019. $ddpost['number'] = $shop['shortname'].'-'.substr(date('ymd',$dtime),1).'-'.(substr(strval($num+1+1000),1,3));//编号
  2020. $ddpost['orderinfo'] = preg_replace('/[^0-9]/', '', $value['0']);//订单号
  2021. $d = $this->fullorder->get_orderinfo($ddpost['orderinfo']);
  2022. if(isset($d['id']))
  2023. {
  2024. $i++;
  2025. continue;
  2026. }
  2027. $ddpost['paypal'] = $ddpost['orderinfo'];//交易号
  2028. $ddpost['insurance'] = 0;//运输保险费用
  2029. $ddpost['baddress'] = '';
  2030. $ddpost['saddress'] = '';
  2031. $ddpost['country'] = $country['id'];//此国家的ID
  2032. $ddpost['al'] = $country['lb'];//联邦名称
  2033. $ddpost['bname'] = $post['name'];//名称
  2034. $ddpost['sname'] = $post['name'];//名称
  2035. $ddpost['client'] = $post['name'];//公司名称
  2036. $ddpost['name'] = $post['name'];//收件人名称
  2037. $ddpost['phone'] = $post['phone'];//收件人电话
  2038. $ddpost['email'] = $post['email'];//客户邮箱
  2039. $ddpost['zipcode'] = $post['zipcode'];//收件人邮编
  2040. $ddpost['province'] = $post['province'];//收件人省份
  2041. $ddpost['city'] = $post['city'];//收件人城市
  2042. $ddpost['address'] = $post['address'];//收件人地址
  2043. $ddpost['shouldmoney'] = $je;//应收金额
  2044. $ddpost['skje'] = $je;//收款金额
  2045. $ddpost['ismoney'] = '';//支付币种金额
  2046. $ddpost['shouldmoney'] = $je;//金额
  2047. $ddpost['budget'] = $je;//预估到帐金额
  2048. $ddpost['buytime'] = $dtime;//格式化付款时间
  2049. $ddpost['dtime'] = $dtime;//订单时间
  2050. $ddpost['gtime'] = date('Ymd',$dtime);//格式化订单时间
  2051. $ddpost['currencytitle'] = 'USD';//结算币种名称
  2052. $ddpost['currency'] = 219;//钱币ID
  2053. $ddpost['time'] = time();//同步时间
  2054. $ddpost['shopify'] = 0;//同步时间
  2055. $ddpost['hl'] = '6.4';//汇率
  2056. $matching = $this->api->matching($ddpost['quantity'],$sbsku,$dtc,$money,$int,$dtctitle,$shop);
  2057. $ddpost['shipremarks'] = $matching['title'];
  2058. $ddpost['cost'] = $matching['cost'];
  2059. $ddpost['purchase'] = $matching['purchase'];
  2060. $ddpost['fpdata'] = $matching['product'];
  2061. $ddpost['whlabel'] = $matching['whlabel'];
  2062. $ddpost['slpx'] = $matching['wcslpx'];
  2063. $ddpost['state'] = 207;
  2064. $ddpost['type'] = 13;
  2065. $this->fullorder->insert($ddpost);
  2066. }
  2067. if ($this->db->trans_status() === FALSE)
  2068. {
  2069. $this->db->trans_commit();
  2070. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  2071. }
  2072. else
  2073. {
  2074. if(count($list) == $i)
  2075. {
  2076. $til = '导入全部失败!请检查导入信息';
  2077. }
  2078. else if(count($list) > $i && $i != 0)
  2079. {
  2080. $til = '部分导入成功!'.$i.'条信息有问题,请排查';
  2081. }
  2082. else if($i < 1)
  2083. {
  2084. $til = '导入成功!';
  2085. }
  2086. $this->db->trans_commit();
  2087. echo json_encode(array('msg'=>$til,'success'=>true));exit;
  2088. }
  2089. }
  2090. else
  2091. {
  2092. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  2093. }
  2094. }
  2095. public function _indexexcel()//通过计数,2020/02/21已校准
  2096. {
  2097. $user = $this->user->get_api($_SESSION['api']);
  2098. if($user)
  2099. {
  2100. $fgshop = "";$sid = "";
  2101. $users = explode('|',trim($user['shop'],'|'));
  2102. foreach ($users as $value)
  2103. {
  2104. $fgshop .= " shop = ".$value." or";
  2105. $sid .= " id = ".$value." or";
  2106. }
  2107. if($user['vip'] == 1)
  2108. {
  2109. $vip = 1;
  2110. }
  2111. else
  2112. {
  2113. $vip = 0;
  2114. }
  2115. }
  2116. else
  2117. {
  2118. $vip = 0;
  2119. }
  2120. $post = $this->input->post(NULL, TRUE);
  2121. if(isset($_GET['timetk']))
  2122. {
  2123. $shop = $this->input->get('shop',true);
  2124. $numphone = $this->input->get('numphone',true);
  2125. $name = $this->input->get('name',true);
  2126. $email = $this->input->get('email',true);
  2127. $address = $this->input->get('address',true);
  2128. $level = $this->input->get('level',true);
  2129. $num = $this->input->get('num',true);
  2130. $country = $this->input->get('country',true);
  2131. $excelid = $this->input->get('sid',true);
  2132. $timetk = $this->input->get('timetk',true);
  2133. $timetj = $this->input->get('timetj',true);
  2134. $timetk = strtotime($timetk);
  2135. $timetj = strtotime($timetj);
  2136. $where = "1=1 and type = 1 and (".rtrim($fgshop,'or').")";
  2137. if($shop)
  2138. {
  2139. $where .= " and shop = '$shop'";
  2140. }
  2141. if($numphone)
  2142. {
  2143. $where .= " and numphone = '$numphone'";
  2144. }
  2145. if($name)
  2146. {
  2147. $where .= " and name like '%$name%'";
  2148. }
  2149. if($email)
  2150. {
  2151. $where .= " and email like '%$email%'";
  2152. }
  2153. if($level)
  2154. {
  2155. $where .= " and level = '$level'";
  2156. }
  2157. if($country)
  2158. {
  2159. $where .= " and country = '$country'";
  2160. }
  2161. if($address)
  2162. {
  2163. $where .= " and address like '%$address%'";
  2164. }
  2165. if($num > 0 && $num < 10 && $num != '2a')
  2166. {
  2167. $where .= " and num = '$num'";
  2168. }
  2169. else if($num > 9)
  2170. {
  2171. $where .= " and num > '9'";
  2172. }
  2173. else if($num == '2a')
  2174. {
  2175. $where .= " and num > '1'";
  2176. }
  2177. else
  2178. {
  2179. $where .= " and num >= '0'";
  2180. }
  2181. if($timetk && $timetj)
  2182. {
  2183. $where .= " and ((time > '$timetk' and time < '$timetj') or time = '0')";
  2184. }
  2185. $xzid = '';
  2186. if($excelid)
  2187. {
  2188. $excelid = explode(',',trim($excelid,','));
  2189. foreach ($excelid as $key=>$value)
  2190. {
  2191. $xzid .= " id = ".$value." or";
  2192. }
  2193. $where .= " and (".rtrim($xzid,'or').")";;
  2194. }
  2195. //数据排序
  2196. $order_str = "id desc";
  2197. $numdata = array();
  2198. if(empty($page))
  2199. {
  2200. $start = 0;
  2201. $perpage = 1;
  2202. }
  2203. else
  2204. {
  2205. $start = ($page - 1)*$perpage;
  2206. }
  2207. //取得信息列表
  2208. $info_list = $this->customer->find_all($where,'shop,name,email,phone,address,city,province,zipcode,country,level,money,num,numphone,time,count',$order_str);
  2209. foreach ($info_list as $key=>$value)
  2210. {
  2211. $shop = $this->shop->read($value['shop']);
  2212. $info_list[$key]['shop'] = $shop['shopname'];
  2213. if($value['country'] != 0)
  2214. {
  2215. $country = $this->country->read($value['country']);
  2216. $info_list[$key]['country'] = $country['name'];
  2217. }
  2218. else
  2219. {
  2220. $info_list[$key]['country'] = "未知";
  2221. }
  2222. if($value['level'] == 1)
  2223. {
  2224. $info_list[$key]['level'] = "网红";
  2225. }
  2226. else if($value['level'] == 2)
  2227. {
  2228. $info_list[$key]['level'] = "批发";
  2229. }
  2230. else if($value['level'] == 3)
  2231. {
  2232. $info_list[$key]['level'] = "店铺转线下";
  2233. }
  2234. else if($value['level'] == 4)
  2235. {
  2236. $info_list[$key]['level'] = "线下其他";
  2237. }
  2238. else if($value['level'] == 5)
  2239. {
  2240. $info_list[$key]['level'] = "店内客户";
  2241. }
  2242. if($value['time'] != 0)
  2243. {
  2244. $info_list[$key]['time'] = date('Y-m-d',$value['time']);
  2245. }
  2246. else
  2247. {
  2248. $info_list[$key]['time'] = "无";
  2249. }
  2250. $info_list[$key]['numphone'] = ($value['num'] > 0 && $value['money'] > 0)?sprintf("%01.2f",$value['money']/$value['num']):0;
  2251. if(isset($value['email']) && $user['excelpass'] == '1')
  2252. {
  2253. $emailpass = $this->setting->get_excelpass($value['email']);
  2254. $info_list[$key]['email'] = $emailpass;
  2255. }
  2256. if(isset($value['phone']) && $user['excelpass'] == '1')
  2257. {
  2258. $phone = $this->setting->get_excelpass($value['phone']);
  2259. $info_list[$key]['phone'] = $phone;
  2260. }
  2261. }
  2262. $title = "按条件导出";
  2263. $titlename = "<table border=1>
  2264. <tr align='center'>
  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. <td>客单价</td>
  2278. <td>最后购买日期</td>
  2279. <td>备注</td>
  2280. </tr>
  2281. </table>";
  2282. $filename = $title.".xls";
  2283. $tail = "";
  2284. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  2285. }
  2286. }
  2287. //下载excel
  2288. public function _excel()
  2289. {
  2290. if(isset($_GET['excel']))
  2291. {
  2292. if(isset($_SESSION['api']))
  2293. {
  2294. $user = $this->user->get_api($_SESSION['api']);
  2295. $usp = $user;
  2296. $fgshop = "";$sid = "";
  2297. $user = explode('|',trim($user['shop'],'|'));
  2298. foreach ($user as $value)
  2299. {
  2300. $fgshop .= " shop = ".$value." or";
  2301. $sid .= " id = ".$value." or";
  2302. }
  2303. }
  2304. $dowid = $this->input->get('a');
  2305. $wid = "";
  2306. if($dowid != "")
  2307. {
  2308. $id_arr = explode(',',rtrim($dowid,','));
  2309. $wid .= " id = 0 or";
  2310. foreach ($id_arr as $v)
  2311. {
  2312. $wid .= " id = '$v' or";
  2313. }
  2314. $wid = " and".rtrim($wid,'or');
  2315. }
  2316. $excel = $this->input->get('excel',true);
  2317. $page = $this->input->get('page',true);
  2318. $perpage = $this->input->get('perpage',true);
  2319. $shop = $this->input->get('shop',true);
  2320. $name = $this->input->get('name',true);
  2321. $country = $this->input->get('country',true);
  2322. $email = $this->input->get('email',true);
  2323. $address = $this->input->get('address',true);
  2324. $level = $this->input->get('level',true);
  2325. $num = $this->input->get('num',true);
  2326. $timetk = $this->input->get('timetk',true);
  2327. $timetj = $this->input->get('timetj',true);
  2328. $timetk = strtotime($timetk);
  2329. $timetj = strtotime($timetj);
  2330. $where = "1 = 1 and (".rtrim($fgshop,'or').")";
  2331. if($shop)
  2332. {
  2333. $where .= " and shop = '$shop'";
  2334. }
  2335. if($name)
  2336. {
  2337. $where .= " and name like '%$name%'";
  2338. }
  2339. if($email)
  2340. {
  2341. $where .= " and email like '%$email%'";
  2342. }
  2343. if($country)
  2344. {
  2345. $where .= " and country = '$country'";
  2346. }
  2347. if($level)
  2348. {
  2349. $where .= " and level = '$level'";
  2350. }
  2351. if($num != '')
  2352. {
  2353. $nu = 1;
  2354. if($num > 9)
  2355. {
  2356. $where .= " and num > '9'";
  2357. }
  2358. else if($num == '2a')
  2359. {
  2360. $where .= " and num > '1'";
  2361. }
  2362. else
  2363. {
  2364. $where .= " and num = '$num'";
  2365. }
  2366. }
  2367. else
  2368. {
  2369. $nu = 2;
  2370. $where .= " and num >= '0'";
  2371. }
  2372. if($address)
  2373. {
  2374. $where .= " and address like '%$address%'";
  2375. }
  2376. if($timetk && $timetj)
  2377. {
  2378. $where .= " and time > '$timetk' and time < '$timetj'";
  2379. }
  2380. $where .= " and type = 1";//白名单用户
  2381. $info_list = array();
  2382. if($excel == 2) //老客户列表
  2383. {
  2384. //$where = str_replace("level = '$level'","level > '1'",$where);
  2385. $info_list = $this->customer->find_all($where.$wid,'name,email,country,time,num,money,numphone','time desc');
  2386. foreach ($info_list as $key=>$value)
  2387. {
  2388. $info_list[$key]['time'] = date('Y-m-d H:i:s',$value['time']);
  2389. if($value['country'] != 0)
  2390. {
  2391. $country = $this->country->read($value['country']);
  2392. $info_list[$key]['country'] = $country['ename'];
  2393. }
  2394. else
  2395. {
  2396. $info_list[$key]['country'] = '';
  2397. }
  2398. if($value['num'] > 0){
  2399. $info_list[$key]['numphone'] = sprintf("%01.2f",$value['money']/$value['num']);
  2400. }else{
  2401. $info_list[$key]['numphone'] = "<span style='color:red'>num异常".$value['num']."</span>";
  2402. }
  2403. if(isset($value['email']) && $usp['excelpass'] == '1')
  2404. {
  2405. $emailpass = $this->setting->get_excelpass($value['email']);
  2406. $info_list[$key]['email'] = $emailpass;
  2407. }
  2408. }
  2409. /**
  2410. foreach ($info_list as $key=>$value)
  2411. {
  2412. $value['time'] = date('Y-m-d H:i:s',$value['time']);
  2413. $d = $this->fullorder->find_count('email = "'.$value['email'].'" and shop = "'.$value['shop'].'" and mergeid = 0','orderinfo,state,product,name,email,dtime,shouldmoney','time desc');
  2414. if($d > 1)
  2415. {
  2416. $info_list[] = $v;
  2417. }
  2418. }
  2419. **/
  2420. $fzh = "<td>客户名</td><td>客户邮箱</td><td>客户国家</td><td>最近一次下单时间</td><td>购买次数</td><td>购买总金额</td><td>客单价</td>";
  2421. $title = "老客户列表";
  2422. }
  2423. else
  2424. {
  2425. $fdata = $this->customer->find_all($where.$wid,'email,shop','time desc');
  2426. foreach ($fdata as $key=>$value)
  2427. {
  2428. $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');
  2429. if($nu == 2)
  2430. {
  2431. if(count($d) > 1)
  2432. {
  2433. foreach ($d as $k=>$v)
  2434. {
  2435. $v['dtime'] = date('Y-m-d H:i:s',$v['dtime']);
  2436. $typeclass = $this->typeclass->read($v['state']);
  2437. $v['state'] = $typeclass['spare'];
  2438. if($v['country'] != 0)
  2439. {
  2440. $country = $this->country->read($v['country']);
  2441. $v['country'] = $country['ename'];
  2442. }
  2443. else
  2444. {
  2445. $v['country'] = '';
  2446. }
  2447. if(isset($v['email']) && $usp['excelpass'] == '1')
  2448. {
  2449. $emailpass = $this->setting->get_excelpass($v['email']);
  2450. $v['email'] = $emailpass;
  2451. }
  2452. $info_list[] = $v;
  2453. }
  2454. }
  2455. }
  2456. else
  2457. {
  2458. foreach ($d as $k=>$v)
  2459. {
  2460. $v['dtime'] = date('Y-m-d H:i:s',$v['dtime']);
  2461. $typeclass = $this->typeclass->read($v['state']);
  2462. $v['state'] = $typeclass['spare'];
  2463. if($v['country'] != 0)
  2464. {
  2465. $country = $this->country->read($v['country']);
  2466. $v['country'] = $country['ename'];
  2467. }
  2468. else
  2469. {
  2470. $v['country'] = '';
  2471. }
  2472. if(isset($v['email']) && $usp['excelpass'] == '1')
  2473. {
  2474. $emailpass = $this->setting->get_excelpass($v['email']);
  2475. $v['email'] = $emailpass;
  2476. }
  2477. $info_list[] = $v;
  2478. }
  2479. }
  2480. }
  2481. $fzh = "<td>订单号</td><td>订单状态</td><td>产品名</td><td>仓库品名</td><td>客户名</td><td>客户邮箱</td><td>客户国家</td><td>下单时间</td><td>订单金额</td>";
  2482. $title = "老客户订单列表";
  2483. }
  2484. $titlename = "<table border=1>
  2485. <tr>"
  2486. .$fzh.
  2487. "</tr>
  2488. </table>";
  2489. $tail = "\n";
  2490. $filename = $title.'-'.date('Ymd',time()).".xls";
  2491. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  2492. }
  2493. }
  2494. //下载excel模板
  2495. public function _bankdown()
  2496. {
  2497. if(isset($_GET['bankdown']))
  2498. {
  2499. $numphone = $this->input->post('numphone',true);
  2500. $xtime = $this->input->get('xtime',true);
  2501. //$where = "1=1 and type = 2 and (".rtrim($fgshop,'or').")";
  2502. $shop = $this->input->get('shop',true);
  2503. $name = $this->input->get('name',true);
  2504. $email = $this->input->get('email',true);
  2505. $address = $this->input->get('address',true);
  2506. $type = $this->input->get('type',true);
  2507. $id = $this->input->get('id',true);
  2508. $timetk = $this->input->get('timetk',true);
  2509. $timetj = $this->input->get('timetj',true);
  2510. $timetk = strtotime($timetk);
  2511. $timetj = strtotime($timetj);
  2512. if($type)
  2513. {
  2514. $where = "type = '$type'";
  2515. }
  2516. else
  2517. {
  2518. $where = "id != 0";
  2519. }
  2520. if($id)
  2521. {
  2522. $id = explode('|',trim($id,'|'));
  2523. $downid = '';
  2524. foreach ($id as $value)
  2525. {
  2526. $downid .= " id = ".$value." or";
  2527. }
  2528. $where .= " and (".rtrim($downid,'or').")";
  2529. }
  2530. if(!$shop)
  2531. {
  2532. $user = $this->user->get_api($_SESSION['api']);
  2533. $usp = $user;
  2534. $fgshop = "";$sid = "";
  2535. $user = explode('|',trim($user['shop'],'|'));
  2536. foreach ($user as $value)
  2537. {
  2538. $fgshop .= " shop = ".$value." or";
  2539. $sid .= " id = ".$value." or";
  2540. }
  2541. $where .= " and (".rtrim($fgshop,'or').")";
  2542. }
  2543. else
  2544. {
  2545. $where .= " and shop = '$shop'";
  2546. }
  2547. if($email)
  2548. {
  2549. $where .= " and email = '$email'";
  2550. }
  2551. if($name)
  2552. {
  2553. $where .= " and name = '$name'";
  2554. }
  2555. if($address)
  2556. {
  2557. $where .= " and address = '$address'";
  2558. }
  2559. if($xtime)
  2560. {
  2561. $where .= " and typetime > '$timetk' and typetime < '$timetj'";
  2562. }
  2563. $info_list = $this->customer->find_all($where,'name,address,city,province,zipcode,country,phone,email,level,shop,source,type,count,typetime');
  2564. foreach ($info_list as $key=>$v)
  2565. {
  2566. $country = $this->country->read($v['country']);
  2567. $info_list[$key]['country'] = $country['ename'];
  2568. if($v['level'] == 1)
  2569. {
  2570. $info_list[$key]['level'] = '网红';
  2571. }
  2572. else if($v['level'] == 2)
  2573. {
  2574. $info_list[$key]['level'] = '批发';
  2575. }
  2576. else if($v['level'] == 3)
  2577. {
  2578. $info_list[$key]['level'] = '店铺转线下';
  2579. }
  2580. else if($v['level'] == 4)
  2581. {
  2582. $info_list[$key]['level'] = '线下其他';
  2583. }
  2584. else if($v['level'] == 5)
  2585. {
  2586. $info_list[$key]['level'] = '店内';
  2587. }
  2588. else
  2589. {
  2590. $info_list[$key]['level'] = '未知';
  2591. }
  2592. if($v['typetime'] != 0)
  2593. {
  2594. $info_list[$key]['typetime'] = date('Y-m-d',$v['typetime']);
  2595. }
  2596. else
  2597. {
  2598. $info_list[$key]['typetime'] = "无";
  2599. }
  2600. $shop = $this->shop->read($v['shop']);
  2601. $info_list[$key]['shop'] = $shop['shopname'];
  2602. $source = $this->typeclass->read($v['source']);
  2603. $info_list[$key]['source'] = $source['title'];
  2604. }
  2605. $titledata = array('姓名','详细地址','城市','省/州','邮编','国家','电话','邮箱','类型(1:网红2:批发3:店铺转线下4:线下其他5:店内)','所属店铺(必须ERP已有店铺)','来源(数据字典的户来源需存在)','黑白名单(白名单填1或黑名单填2)','备注','客户分类时间');
  2606. $fzh = "";
  2607. foreach ($titledata as $v)
  2608. {
  2609. $fzh .= "<td>".$v."</td>";
  2610. }
  2611. $title = "客户导出";
  2612. $titlename = "<table border=1>
  2613. <tr>"
  2614. .$fzh.
  2615. "</tr>
  2616. </table>";
  2617. $tail = "\n";
  2618. $filename = $title.".xls";
  2619. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  2620. }
  2621. }
  2622. //下载excel模板
  2623. public function _down()
  2624. {
  2625. if(isset($_GET['excela']))
  2626. {
  2627. $title = "客户导入模板";
  2628. $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','备注'));
  2629. $filename = $title.".xls";
  2630. $this->customer->get_excel($titledata,$filename);
  2631. }
  2632. }
  2633. public function _newold()
  2634. {
  2635. if(isset($_SESSION['api']))
  2636. {
  2637. $user = $this->user->get_api($_SESSION['api']);
  2638. $usp = $user;
  2639. $fgshop = "";$sid = "";
  2640. $usersp = explode('|',trim($user['shop'],'|'));
  2641. foreach ($usersp as $value)
  2642. {
  2643. $fgshop .= " shop = ".$value." or";
  2644. $sid .= " id = ".$value." or";
  2645. }
  2646. }
  2647. $post = $this->input->post(NULL, TRUE);
  2648. if(isset($post['timek']))
  2649. {
  2650. $new = array();$old = array();$time=array();
  2651. $timek = $this->input->post('timek',true);
  2652. $timej = $this->input->post('timej',true);
  2653. $k = strtotime($timek)-24*3600;//少一天为增加选择开始天时间
  2654. $j = strtotime($timej);
  2655. $n = ($j-$k)/(24*3600);
  2656. if($n < 1)
  2657. {
  2658. $n = 1;
  2659. }
  2660. for($i=1;$i<$n;$i++)
  2661. {
  2662. $nnum = 0;$onum = 0;
  2663. $t = $j-($n*24*60*60)+($i*24*60*60);
  2664. $time[] = date('Y-m-d',$t);
  2665. $ct = strtotime(date('Ymd',$t));
  2666. $ctj = strtotime(date('Ymd',$t+24*3600));
  2667. $info_list = $this->fullorder->find_all("mergeid = '0' and dtime > '$ct' and dtime < '$ctj' and (".rtrim($fgshop,'or').")");
  2668. foreach ($info_list as $value)
  2669. {
  2670. if($value['email'] != '0' && $value['email'] != '' && $value['email'] != '无')
  2671. {
  2672. $gnum = $this->fullorder->find_count("email = '".$value['email']."' and shop = '".$value['shop']."' and mergeid = 0");
  2673. if($gnum >1)
  2674. {
  2675. $onum += 1;
  2676. }
  2677. else
  2678. {
  2679. $nnum += 1;
  2680. }
  2681. }
  2682. else
  2683. {
  2684. $nnum += 1;
  2685. }
  2686. }
  2687. $new[] = $nnum;
  2688. $old[] = $onum;
  2689. }
  2690. echo @json_encode(array('time'=>$time,'cnew'=>$new,'cold'=>$old,'success'=>true));exit;
  2691. }
  2692. $this->_Template('customer_newold',$this->data);
  2693. }
  2694. }