Customer.php 96 KB

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