Customer.php 96 KB

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