Customer.php 94 KB

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