Customersmt.php 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Customersmt extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_customersmt','customersmt');
  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_fullordersmt','fullordersmt');
  12. $this->load->_model('Model_excel','excel');
  13. $this->load->_model('Model_whlabel','whlabel');
  14. $this->load->_model('Model_warehouse','warehouse');
  15. $this->load->_model('Model_specialstock','specialstock');
  16. $this->load->_model('Model_ck','ck');
  17. $this->load->_model('Model_weight','weight');
  18. $this->load->_model('Model_pay','pay');
  19. $this->load->_model('Model_classid','classid');
  20. $this->load->_model('Model_apiyy','apiyy');
  21. $this->load->_model('Model_whlabel_fc','whlabel_fc');
  22. }
  23. //定义方法的调用规则 获取URI第二段值
  24. public function _remap($arg,$arg_array)
  25. {
  26. if($arg == 'add')//添加
  27. {
  28. $this->_add();
  29. }
  30. else if($arg == 'edit')//修改
  31. {
  32. $this->_edit($arg_array);
  33. }
  34. else if($arg == 'del')//黑名单
  35. {
  36. $this->_del();
  37. }
  38. else if($arg == 'change')//更改名单状态
  39. {
  40. $this->_change();
  41. }
  42. else if($arg == 'mdedit')//修改
  43. {
  44. $this->_mdedit($arg_array);
  45. }
  46. else if($arg == 'black')//黑名单
  47. {
  48. $this->_black();
  49. }
  50. else if($arg == 'excela')
  51. {
  52. $this->_excela();
  53. }
  54. else if($arg == 'excel')//下载excel
  55. {
  56. $this->_excel();
  57. }
  58. else if($arg == 'down')//黑名单
  59. {
  60. $this->_down();
  61. }
  62. else
  63. {
  64. $this->_index();
  65. }
  66. }
  67. //管理
  68. public function _index()
  69. {
  70. $user = $this->user->get_api($_SESSION['api']);
  71. if($user)
  72. {
  73. $fgshop = "";$sid = "";
  74. $user = explode('|',trim($user['shop'],'|'));
  75. foreach ($user as $value)
  76. {
  77. $fgshop .= " shop = ".$value." or";
  78. $sid .= " id = ".$value." or";
  79. }
  80. }
  81. $post = $this->input->post(NULL, TRUE);
  82. if(isset($post['page']))
  83. {
  84. $page = $this->input->post('page',true);
  85. $perpage = $this->input->post('perpage',true);
  86. $shop = $this->input->post('shop',true);
  87. $name = $this->input->post('name',true);
  88. $fullname = $this->input->post('fullname',true);
  89. $userid = $this->input->post('userid',true);
  90. $address = $this->input->post('address',true);
  91. $level = $this->input->post('level',true);
  92. $timetk = $this->input->post('timetk',true);
  93. $timetj = $this->input->post('timetj',true);
  94. $timetk = strtotime($timetk);
  95. $timetj = strtotime($timetj);
  96. $where = "1=1 and type = 1 and (".rtrim($fgshop,'or').")";
  97. if($shop)
  98. {
  99. $where .= " and shop = '$shop'";
  100. }
  101. if($name)
  102. {
  103. $where .= " and name like '%$name%'";
  104. }
  105. if($fullname)
  106. {
  107. $where .= " and fullname = '$fullname'";
  108. }
  109. if($userid)
  110. {
  111. $where .= " and userid like '%$userid%'";
  112. }
  113. if($level)
  114. {
  115. $where .= " and level = '$level'";
  116. }
  117. if($address)
  118. {
  119. $where .= " and address like '%$address%'";
  120. }
  121. if($timetk && $timetj)
  122. {
  123. $where .= " and ((time > '$timetk' and time < '$timetj') or time = 0)";
  124. }
  125. //数据排序
  126. $order_str = "id desc";
  127. if(empty($page))
  128. {
  129. $start = 0;
  130. $perpage = 1;
  131. }
  132. else
  133. {
  134. $start = ($page - 1)*$perpage;
  135. }
  136. //取得信息列表
  137. $info_list = $this->customersmt->find_all($where,'id,shop,source,name,fullname,country,level,money,num,time,count,type',$order_str,$start,$perpage);
  138. foreach ($info_list as $key=>$value)
  139. {
  140. $us = $this->customersmt->read($value['id']);
  141. $shop = $this->shop->read($value['shop']);
  142. $info_list[$key]['shop'] = $shop['shopname'];
  143. $source = $this->typeclass->read($value['source']);
  144. $info_list[$key]['source'] = $source['title'];
  145. if($value['fullname'] != '')
  146. {
  147. $info_list[$key]['num'] = $this->fullordersmt->find_count('fullname = "'.$value['fullname'].'" and shop = "'.$value['shop'].'" and mergeid = 0 and buytime != 0');
  148. }
  149. else
  150. {
  151. $info_list[$key]['num'] = $this->fullordersmt->find_count('address = "'.$us['address'].'" and shop = "'.$value['shop'].'" and mergeid = 0 and buytime != 0');
  152. }
  153. if($value['country'] != 0)
  154. {
  155. $country = $this->country->read($value['country']);
  156. $info_list[$key]['country'] = $country['name'];
  157. }
  158. else
  159. {
  160. $info_list[$key]['country'] = "未知";
  161. }
  162. if($value['level'] == 1)
  163. {
  164. $info_list[$key]['level'] = "网红";
  165. }
  166. else if($value['level'] == 2)
  167. {
  168. $info_list[$key]['level'] = "批发";
  169. }
  170. else if($value['level'] == 3)
  171. {
  172. $info_list[$key]['level'] = "店铺转线下";
  173. }
  174. else if($value['level'] == 4)
  175. {
  176. $info_list[$key]['level'] = "线下其他";
  177. }
  178. else if($value['level'] == 5)
  179. {
  180. $info_list[$key]['level'] = "店内客户";
  181. }
  182. if($value['time'] != 0)
  183. {
  184. $info_list[$key]['time'] = date('Y-m-d',$value['time']);
  185. }
  186. else
  187. {
  188. $info_list[$key]['time'] = "无";
  189. }
  190. $info_list[$key]['type'] = "<a href='javascript:void(0);' class='window' data-h='/customersmt/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>";
  191. }
  192. $total = $this->customersmt->find_count($where);
  193. $pagenum = ceil($total/$perpage);
  194. $over = $total-($start+$perpage);
  195. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  196. echo json_encode($rows);exit;
  197. }
  198. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  199. $this->data['wlshop'] = $wlshop;
  200. $this->_Template('customersmt',$this->data);
  201. }
  202. //管理
  203. public function _black()
  204. {
  205. $user = $this->user->get_api($_SESSION['api']);
  206. if($user)
  207. {
  208. $fgshop = "";$sid = "";
  209. $user = explode('|',trim($user['shop'],'|'));
  210. foreach ($user as $value)
  211. {
  212. $fgshop .= " shop = ".$value." or";
  213. $sid .= " id = ".$value." or";
  214. }
  215. }
  216. $post = $this->input->post(NULL, TRUE);
  217. if(isset($post['page']))
  218. {
  219. $page = $this->input->post('page',true);
  220. $perpage = $this->input->post('perpage',true);
  221. $shop = $this->input->post('shop',true);
  222. $name = $this->input->post('name',true);
  223. $userid = $this->input->post('userid',true);
  224. $address = $this->input->post('address',true);
  225. $where = "1=1 and type = 2 and (".rtrim($fgshop,'or').")";
  226. //$where = "1=1 and type = 2";
  227. if($shop)
  228. {
  229. $where .= " and shop = '$shop'";
  230. }
  231. if($name)
  232. {
  233. $where .= " and name like '%$name%'";
  234. }
  235. if($userid)
  236. {
  237. $where .= " and userid like '%$userid%'";
  238. }
  239. if($address)
  240. {
  241. $where .= " and address like '%$address%'";
  242. }
  243. //数据排序
  244. $order_str = "id desc";
  245. if(empty($page))
  246. {
  247. $start = 0;
  248. $perpage = 1;
  249. }
  250. else
  251. {
  252. $start = ($page - 1)*$perpage;
  253. }
  254. //取得信息列表
  255. $info_list = $this->customersmt->find_all($where,'id,shop,source,name,userid,address,typetime,type',$order_str,$start,$perpage);
  256. foreach ($info_list as $key=>$value)
  257. {
  258. $shop = $this->shop->read($value['shop']);
  259. $info_list[$key]['shop'] = $shop['shopname'];
  260. $source = $this->typeclass->read($value['source']);
  261. $info_list[$key]['source'] = $source['title'];
  262. if($value['typetime'] > 0)
  263. {
  264. $info_list[$key]['typetime'] = date('Y-m-d',$value['typetime']);
  265. }
  266. else
  267. {
  268. $info_list[$key]['typetime'] = '无';
  269. }
  270. $info_list[$key]['type'] = "<a class='customer' data-type='1' data-t='yc' data-id='".$value['id']."' href='javascript:void(0);'>移出</a>";
  271. }
  272. $total = $this->customersmt->find_count($where);
  273. $pagenum = ceil($total/$perpage);
  274. $over = $total-($start+$perpage);
  275. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  276. echo json_encode($rows);exit;
  277. }
  278. //$wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  279. $wlshop = $this->shop->find_all('1=1');
  280. $this->data['wlshop'] = $wlshop;
  281. $this->_Template('customersmt_black',$this->data);
  282. }
  283. //添加
  284. public function _add()
  285. {
  286. $user = $this->user->get_api($_SESSION['api']);
  287. if($user)
  288. {
  289. $fgshop = "";$sid = "";
  290. $user = explode('|',trim($user['shop'],'|'));
  291. foreach ($user as $value)
  292. {
  293. $fgshop .= " shop = ".$value." or";
  294. $sid .= " id = ".$value." or";
  295. }
  296. }
  297. $post = $this->input->post(NULL, TRUE);
  298. if(isset($post['shop']))
  299. {
  300. $post['shop'] = $this->input->post('shop',true);
  301. $post['source'] = $this->input->post('source',true);
  302. $post['level'] = $this->input->post('level',true);
  303. $post['country'] = $this->input->post('country',true);
  304. $name = $this->input->post('name',true);
  305. $post['name'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$name);
  306. $post['phone'] = $this->input->post('phone',true);
  307. $userid = $this->input->post('userid',true);
  308. $post['userid'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$userid);
  309. $post['province'] = $this->input->post('province',true);
  310. $post['city'] = $this->input->post('city',true);
  311. //$post['street'] = $this->input->post('street',true);
  312. $address = $this->input->post('address',true);
  313. $post['address'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$address);
  314. //$post['address2'] = $this->input->post('address2',true);
  315. $post['count'] = $this->input->post('count',true);
  316. $post['zhcx'] = $post['shop'].'-'.$post['userid'];
  317. if($this->customersmt->insert($post))
  318. {
  319. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  320. }
  321. else
  322. {
  323. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  324. }
  325. }
  326. $country = $this->country->find_all('1=1','id,name','name asc');
  327. $this->data['country'] = $country;
  328. $wlshop = $this->shop->find_all("type = 270 and (".rtrim($sid,'or').")");
  329. $this->data['wlshop'] = $wlshop;
  330. $this->_Template('customersmt_add',$this->data);
  331. }
  332. //修改
  333. public function _edit($arg_array)
  334. {
  335. $user = $this->user->get_api($_SESSION['api']);
  336. if($user)
  337. {
  338. $fgshop = "";$sid = "";
  339. $user = explode('|',trim($user['shop'],'|'));
  340. foreach ($user as $value)
  341. {
  342. $fgshop .= " shop = ".$value." or";
  343. $sid .= " id = ".$value." or";
  344. }
  345. }
  346. $post = $this->input->post(NULL, TRUE);
  347. if(isset($post['id']))
  348. {
  349. $id = $this->input->post('id',true);
  350. $us = $this->customersmt->read($id);
  351. $post['shop'] = $this->input->post('shop',true);
  352. $post['source'] = $this->input->post('source',true);
  353. $post['level'] = $this->input->post('level',true);
  354. $post['country'] = $this->input->post('country',true);
  355. $name = $this->input->post('name',true);
  356. $post['name'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$name);
  357. $post['phone'] = $this->input->post('phone',true);
  358. $userid = $this->input->post('userid',true);
  359. $post['userid'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$userid);
  360. $post['province'] = $this->input->post('province',true);
  361. $post['city'] = $this->input->post('city',true);
  362. //$post['street'] = $this->input->post('street',true);
  363. $address = $this->input->post('address',true);
  364. $post['address'] = str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$address);
  365. //$post['address2'] = $this->input->post('address2',true);
  366. $post['type'] = $this->input->post('type',true);
  367. $post['count'] = $this->input->post('count',true);
  368. $post['zhcx'] = $post['shop'].'-'.$post['userid'];
  369. if($this->customersmt->save($post,$id))
  370. {
  371. echo json_encode(array('msg'=>'操作成功!','success'=>true));exit;
  372. }
  373. else
  374. {
  375. echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
  376. }
  377. }
  378. $arg_array = $arg_array[0];
  379. $customersmt = $this->customersmt->read($arg_array);
  380. $this->data['customersmt'] = $customersmt;
  381. $country = $this->country->find_all('1=1','id,name','name asc');
  382. $this->data['country'] = $country;
  383. $wlshop = $this->shop->find_all("type = 270 and (".rtrim($sid,'or').")");
  384. $this->data['wlshop'] = $wlshop;
  385. if($customersmt['userid'] != '')
  386. {
  387. $fdata = $this->fullordersmt->find_all('userid = "'.$customersmt['userid'].'" and shop = "'.$customersmt['shop'].'" and mergeid = 0','orderinfo,state,product,name,client,buytime,shouldmoney','id desc');
  388. foreach ($fdata as $k=>$v)
  389. {
  390. $typeclass = $this->typeclass->read($v['state']);
  391. $fdata[$k]['state'] = $typeclass['title'];
  392. $fdata[$k]['buytime'] = date('Y-m-d',$v['buytime']);
  393. }
  394. $this->data['data'] = $fdata;
  395. }
  396. else
  397. {
  398. $fdata = $this->fullordersmt->find_all('address = "'.$customersmt['address'].'" and shop = "'.$customersmt['shop'].'" and mergeid = 0','orderinfo,state,product,name,client,buytime,shouldmoney','id desc');
  399. foreach ($fdata as $k=>$v)
  400. {
  401. $typeclass = $this->typeclass->read($v['state']);
  402. $fdata[$k]['state'] = $typeclass['title'];
  403. $fdata[$k]['buytime'] = date('Y-m-d',$v['buytime']);
  404. }
  405. $this->data['data'] = $fdata;
  406. }
  407. $this->_Template('customersmt_edit',$this->data);
  408. }
  409. //删除
  410. public function _del()
  411. {
  412. $post = $this->input->post(NULL, TRUE);
  413. if(isset($post['s']))
  414. {
  415. $id_arr = $this->input->post('s');
  416. $id_arr = explode(',',$id_arr);
  417. if(!$id_arr)
  418. {
  419. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  420. }
  421. //循环删除记录
  422. $a=0;
  423. foreach ($id_arr as $v)
  424. {
  425. $customer = $this->customersmt->read($v);
  426. if($customer['email'] != '0' && $customer['email'] != '' && $customer['email'] != '无')
  427. {
  428. $fdata = $this->fullordersmt->find_count('email = "'.$customer['email'].'" and shop = "'.$customer['shop'].'" and mergeid = 0');
  429. if($fdata > 0)
  430. {
  431. $a++;
  432. continue;
  433. }
  434. else
  435. {
  436. $this->customersmt->remove($v);
  437. }
  438. }
  439. }
  440. if($a > 0)
  441. {
  442. echo json_encode(array('del'=>$id_arr,'msg'=>'无订单客户删除成功,有订单的客户无法删除!','success'=>true));
  443. }
  444. else
  445. {
  446. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  447. }
  448. }
  449. }
  450. //删除
  451. public function _change()
  452. {
  453. $post = $this->input->post(NULL, TRUE);
  454. if(isset($post['type']))
  455. {
  456. $type = $this->input->post('type',true);
  457. $id = $this->input->post('id',true);
  458. $count = $this->input->post('count',true);
  459. if($this->customersmt->save(array('type'=>$type,'count'=>$count,'typetime'=>time()),$id))
  460. {
  461. echo json_encode(array('msg'=>'操作成功!','success'=>true));exit;
  462. }
  463. else
  464. {
  465. echo json_encode(array('msg'=>'操作失败,请重试','success'=>false));exit;
  466. }
  467. }
  468. }
  469. //修改客户分类
  470. public function _mdedit($arg_array)
  471. {
  472. $user = $this->user->get_api($_SESSION['api']);
  473. if($user)
  474. {
  475. $fgshop = "";$sid = "";
  476. $user = explode('|',trim($user['shop'],'|'));
  477. foreach ($user as $value)
  478. {
  479. $fgshop .= " shop = ".$value." or";
  480. $sid .= " id = ".$value." or";
  481. }
  482. }
  483. $post = $this->input->post(NULL, TRUE);
  484. if(isset($post['shop']))
  485. {
  486. $fpcount = $this->input->post('fpcount',true);
  487. if(!$fpcount)
  488. {
  489. echo json_encode(array('msg'=>'需要先清理浏览器缓存,刷新当前页面后再试!','success'=>false));exit;
  490. }
  491. $customerid = $this->input->post('customerid',true);
  492. $shop = $this->input->post('shop',true);
  493. $sp = $this->shop->read($shop);
  494. $num = $this->fullordersmt->find_count('shop = "'.$sp['id'].'" and gtime = "'.date('Ymd',time()).'"');
  495. $post['source'] = 1;//订单类型:1.线下订单2.PC3.手机
  496. $post['state'] = 207;//订单状态:207等待发货
  497. $post['review'] = 2;//审核状态:1.未送审2.待审核3.不通过4取消重审5.审核通过6.自动通过
  498. $post['print'] = 1;//打印状态:1.不可打印2.未打印3.已打印
  499. $post['library'] = 1;//出库状态:1.未出库2.已出库3.已退库
  500. $post['libraryconfirm'] = 1;//出库确认:1.不允许2.允许
  501. $post['dlz'] = 3;//不需要声明
  502. $post['link'] = $sp['link'];
  503. $post['sku'] = $sp['sku'];
  504. if($post['print'] != 3)
  505. {
  506. $post['librarynot'] = "订单未打印,未审核或未通过";//不能出库原因
  507. }
  508. $orderinfo = $this->input->post('orderinfo',true);
  509. if($orderinfo)
  510. {
  511. $arr=strlen($orderinfo);
  512. if($arr < 14 || $arr > 19)
  513. {
  514. echo json_encode(array('msg'=>'订单号必须大于13位小于20位!','success'=>false));exit;
  515. }
  516. }
  517. if($post['paypal'] != '')
  518. {
  519. $pp = $this->fullordersmt->get_paypal($post['paypal']);
  520. if($pp)
  521. {
  522. echo json_encode(array('msg'=>'此交易号的订单已存在!','success'=>false));exit;
  523. }
  524. }
  525. $post['shop'] = $sp['id'];
  526. $post['user'] = $sp['shopuser'];
  527. $nut = time();
  528. $nma = substr(date('ymd',$nut),1);
  529. $nmb = substr(strval($num+1+1000),1,3);
  530. $post['number'] = $sp['shortname'].'-'.$nma.'-'.$nmb;//编号
  531. $post['numberpx'] = date('ymd',$nut)*10000+$nmb;//按编号排序
  532. if($orderinfo != "")
  533. {
  534. $ordefin = $this->fullordersmt->get_orderinfo($orderinfo);
  535. if($ordefin)
  536. {
  537. echo json_encode(array('msg'=>'订单号重复!','success'=>false));exit;
  538. }
  539. else
  540. {
  541. $post['orderinfo'] = $orderinfo;
  542. }
  543. }
  544. else
  545. {
  546. $post['orderinfo'] = $sp['id'].date('ymdHis',time()).rand(0,1);//订单号
  547. }
  548. $dtime = time();
  549. $post['client'] = $this->input->post('client',true);//客户名称
  550. $btime = $this->input->post('buytime',true);//付款时间
  551. $post['buytime'] = $btime?strtotime($btime):$dtime;//时间转UX
  552. $post['dtime'] =$dtime;//订单时间
  553. $post['gtime'] = date('Ymd',time());//格式化时间
  554. //$post['pay'] = $this->input->post('pay',true);//支付方式
  555. $post['capital'] = $this->input->post('capital',true);//资金状态
  556. $post['type'] = $this->input->post('warehouse',true);//发货仓库
  557. $post['currency'] = $this->input->post('currency',true);//币种
  558. $currency = $this->typeclass->read($post['currency']);
  559. $post['currencytitle'] = $currency['title'];//币种名称
  560. $post['freight'] = $this->input->post('freight',true);//运费
  561. $post['expressmoney'] = $this->input->post('expressmoney',true);//物流金额
  562. $post['shouldmoney'] = $this->input->post('shouldmoney',true);//应收金额
  563. $post['skje'] = $post['shouldmoney'];//收款金额
  564. $product = $this->input->post('product');//产品名称
  565. $product = str_replace(array('%26','%2B'),array('&','+'),$product);
  566. $post['product'] = preg_replace('/( | | |\s)/',' ',$product);
  567. $orderremarks = $this->input->post('orderremarks');//订单备注
  568. $orderremarks = str_replace(array('%26','%2B'),array('&','+'),$orderremarks);
  569. $post['orderremarks'] = preg_replace('/( | | |\s)/',' ',$orderremarks);
  570. $shipremarks = $this->input->post('shipremarks');//仓库品名
  571. $shipremarks = str_replace(array('%26','%2B'),array('&','+'),$shipremarks);//仓库品名
  572. $post['shipremarks'] = preg_replace('/( | | |\s)/',' ',$shipremarks);
  573. $name = $this->input->post('name',true);//名称
  574. $post['name'] = preg_replace('/( | | |\s)/',' ',$name);
  575. $post['phone'] = $this->input->post('phone',true);//电话
  576. $post['country'] = $this->input->post('country',true);//国家
  577. $ct = $this->country->read($post['country']);//国家
  578. $post['al'] = $ct['lb'];//国家二字码
  579. $post['province'] = $this->input->post('province',true);//省、州
  580. $post['city'] = $this->input->post('city',true);//城市
  581. $post['zipcode'] = $this->input->post('zipcode',true);//邮编
  582. $post['address'] = $this->input->post('address',true);//地址
  583. $post['express'] = $this->input->post('express',true);//快递
  584. $post['printtype'] = $this->input->post('printtype',true);//打印类型
  585. $fpdata = $this->input->post('fpdata');//购买产品内容
  586. $fpdata = str_replace(array('%26','%2B'),array('&','+'),$fpdata);
  587. $post['fpdata'] = $fpdata;
  588. $post['sbpm'] = $this->input->post('sbpm',true);//申报品名
  589. $post['zwpm'] = $this->input->post('zwpm',true);//中文品名
  590. $post['ts'] = $this->input->post('ts',true);//条数
  591. $post['dtsbjz'] = $this->input->post('dtsbjz',true);//单条申报价
  592. $post['zsbjz'] = $this->input->post('zsbjz',true);//总申报价
  593. $post['zzl'] = $this->input->post('zzl',true);//总重量
  594. $post['zjs'] = $this->input->post('zjs',true);//总件数
  595. $post['express'] = $this->input->post('express',true);//快递公司
  596. $post['printtype'] = $this->input->post('printtype',true);//打印类型
  597. $post['pay'] = $this->input->post('pay',true);//支付方式
  598. $post['ioss'] = $this->input->post('ioss',true);
  599. $post['sbpm'] = $this->input->post('sbpm',true);
  600. $whlabel = $this->input->post('whlabel',true);
  601. $pay = $this->pay->get_typeclass($post['pay']);
  602. $yga = $post['shouldmoney'];
  603. $post['budget'] = 0;
  604. if($pay)
  605. {
  606. $ygc = $pay['estimaterate'];//预估到账公式
  607. $post['estimaterate'] = $pay['estimaterate'];
  608. $ifbudget = eval("return $yga*1.$ygc;");
  609. if($ifbudget > 0)
  610. {
  611. $post['budget'] = eval("return $yga*1.$ygc;");//预估到帐金额
  612. }
  613. }
  614. else
  615. {
  616. $ygb = $sp['estimaterate'];//店铺默认到账公式
  617. $post['estimaterate'] = $sp['estimaterate'];
  618. $ifbudget = eval("return $yga*1.$ygb;");
  619. if($ifbudget > 0)
  620. {
  621. $post['budget'] = eval("return $yga*1.$ygb;");//预估到帐金额
  622. }
  623. }
  624. if($post['express'] == 2 && (stripos($post['name'],'&') !== false || stripos($post['name'],"'") !== false))
  625. {
  626. echo json_encode(array('msg'=>'USPS收件人或公司名不可用特殊符号!','success'=>false));exit;
  627. }
  628. if(strlen($post['client']) > 35 || strlen($post['name']) > 35)//收件人姓名或公司名不允许超过35位
  629. {
  630. echo json_encode(array('msg'=>'收件人姓名或公司名不可超过35个字符!','success'=>false));exit;
  631. }
  632. if($post['express'] == '99' && $post['bx'] > 0)
  633. {
  634. echo json_encode(array('msg'=>'此物流不允许购买保险','success'=>false));exit;
  635. }
  636. if($post['express'] == 42 && $post['sbpm'] != 'Human Hair Wigs' && $post['sbpm'] != 'Human Hair Goods')//$post['express'] == 3 ||
  637. {
  638. echo json_encode(array('msg'=>'此快递方式必须选择Human Hair Wigs/Human Hair Goods!','success'=>false));exit;
  639. }
  640. if($post['express'] == 24 && $post['sbpm'] != 'Hair Sample' && $post['sbpm'] != 'Human Hair Wigs' && $post['sbpm'] != 'Human Hair Goods')//$post['express'] == 3 ||
  641. {
  642. echo json_encode(array('msg'=>'此快递方式必须选择Hair Sample/Human Hair Wigs/Human Hair Goods!','success'=>false));exit;
  643. }
  644. if($post['country'] != 192 && $post['express'] == 1 && $post['sbpm'] != 'Synthetic Hair Wigs' && $post['sbpm'] != 'Synthetic Hair Goods')//$post['express'] == 3 ||
  645. {
  646. echo json_encode(array('msg'=>'非美国选择官方DHL必须选择Synthetic Hair Wigs/Synthetic Hair Goods','success'=>false));exit;
  647. }
  648. if($post['express'] == '2' && $post['warehouse'] != 5)
  649. {
  650. echo json_encode(array('msg'=>'非美国仓无法选择USPS!','success'=>false));exit;
  651. }
  652. $express = $this->express->read($post['express']);
  653. if($post['zsbjz'] > $express['sbjz'])
  654. {
  655. echo json_encode(array('msg'=>'总申报价值不可超出'.$express['sbjz'],'success'=>false));exit;
  656. }
  657. if($post['shouldmoney'] > $express['shouldmoney'] && $express['shouldmoney'] != 0)
  658. {
  659. echo json_encode(array('msg'=>'订单金额不可超出'.$express['shouldmoney'],'success'=>false));exit;
  660. }
  661. if($express['ioss'] == 1 && $post['ioss'] == '')
  662. {
  663. echo json_encode(array('msg'=>'此快递方式必须选择IOSS!','success'=>false));exit;
  664. }
  665. if(strlen($post['address']) > $express['addresssize'] || strlen($post['address2']) > $express['addresssize'])
  666. {
  667. echo json_encode(array('msg'=>'此快递方地址不可超出'.$express['addresssize'].'个字符','success'=>false));exit;
  668. }
  669. if($post['express'] == '2' && $post['zzl'] > '16' && $post['js'] == '0')
  670. {
  671. echo json_encode(array('msg'=>'重量大于16不可按Ground Advantage提交!','success'=>false));exit;
  672. }
  673. if($post['express'] == '2' && isset($post['js']) && $post['js'] == '0'&& $post['qm'] == '1')
  674. {
  675. echo json_encode(array('msg'=>'Ground Advantage不可使用签名服务!','success'=>false));exit;
  676. }
  677. if(($post['express'] == '3' || $post['express'] == '42' || $post['express'] == '24') && $post['shouldmoney'] < 1)
  678. {
  679. echo json_encode(array('msg'=>'零金额订单不可发 UPS/DHL官方-美国/Fedex(杭州)','success'=>false));exit;
  680. }
  681. if($post['express'] == '42' && $post['zsbjz'] < 1)
  682. {
  683. echo json_encode(array('msg'=>'零申报金额不可发 DHL官方-美国','success'=>false));exit;
  684. }
  685. if($post['express'] == '6' && $post['province'] == '')
  686. {
  687. echo json_encode(array('msg'=>'选择DPEX必须填写州信息','success'=>false));exit;
  688. }
  689. /**
  690. $post['saddress']
  691. if($post['printtype'] == 1)//如果是运单
  692. {
  693. $post['productdescription'] = $this->input->post('productdescription',true);
  694. $post['customs'] = $this->input->post('customs',true);
  695. }
  696. **/
  697. //开始注释 xyxg
  698. /**
  699. $warehousenew = $this->warehouse->read($post['type']);
  700. $ft = array();
  701. $ftdata = explode('|',rtrim($fpcount,'|'));
  702. foreach ($ftdata as $va)
  703. {
  704. $ftitle = '';
  705. $va = explode('-',trim($va,'-'));
  706. foreach ($va as $v)
  707. {
  708. $v = $this->typeclass->read($v);
  709. $ftitle .= $v['title'].' ';
  710. }
  711. $ft[] = rtrim($ftitle,' ');
  712. }
  713. $kcyz = $this->whlabel->get_kc($post['state'],$post['state'],$warehousenew['zd'],$warehousenew['ys'],$post['type'],$whlabel,$fpcount,$ft,$post['number'],$shop);//新添加订单老状态state和新状态state一样,不用走删除占用步奏
  714. if($kcyz['t'] > '0')
  715. {
  716. echo $kcyz['m'];exit;
  717. }
  718. else
  719. {
  720. if($this->fullordersmt->insert($post))
  721. {
  722. $cusnum = $this->customersmt->read($customerid);
  723. $this->customersmt->save(array('num'=>$cusnum['num']+1,'time'=>$post['buytime']),$customerid);
  724. echo json_encode(array('msg'=>'下单成功','success'=>true));exit;
  725. }
  726. else
  727. {
  728. echo json_encode(array('msg'=>'下单失败,请重试','success'=>false));exit;
  729. }
  730. }
  731. //结束注释
  732. **/
  733. $dtctitle = array();
  734. $dictionaries = $this->typeclass->find_all();
  735. foreach ($dictionaries as $v)
  736. {
  737. $dtctitle[$v['id']] = array($v['title'],$v['bqsku']);
  738. }
  739. $fpdata = $post['fpdata'];
  740. if(stripos($fpdata,'-128-') !== false || stripos($fpdata,'-127-') !== false)
  741. {
  742. $dfp = explode(';',trim($fpdata,';'));
  743. $fdata = '';
  744. foreach ($dfp as $k=>$v)
  745. {
  746. $ptitleb = '';
  747. $fp = explode('|',trim($v,'|'));
  748. $fp0 = explode(',',$fp[0]);
  749. $fp1 = explode('-',trim($fp0[1],'-'));
  750. foreach ($fp1 as $vv)
  751. {
  752. $ptitleb .= isset($dtctitle[$vv])?$dtctitle[$vv][0].' ':'';
  753. }
  754. $ptitleb .= $dtctitle[$fp0[0]][1].'inch ';
  755. $fp[1] = $ptitleb;
  756. $fdata .= implode("|",$fp).";";
  757. }
  758. $fpdata = $fdata;
  759. }
  760. $warehouse = $this->warehouse->read($post['type']);
  761. if($warehouse['bdcountry'] != 0 && $post['country'] != $warehouse['bdcountry'])
  762. {
  763. echo json_encode(array('msg'=>'当前国家无法选择'.$warehouse['title'].'!','success'=>false));exit;
  764. }
  765. $kcyz = $this->ck->get_kc($post['state'],$warehouse,$post['shop'],$post['number'],$whlabel,$fpdata);
  766. if($kcyz['t'] > '0')
  767. {
  768. echo $kcyz['m'];exit;
  769. }
  770. else if($kcyz['fpdata'] != '')
  771. {
  772. $post['whlabel'] = $kcyz['whlabel'];
  773. $post['fpdata'] = $kcyz['fpdata'];
  774. }
  775. $fl = $this->ck->get_fl($warehouse['hz'],$whlabel,$fpdata);
  776. $post['sfxh'] = $fl['sfxh'];
  777. $post['ckfl'] = $fl['ckfl'];
  778. //查询净重开始
  779. $post['jweight'] = $this->weight->get_weightcx($post['fpdata']);
  780. //查询净重结束
  781. $cusnum = $this->customersmt->read($customerid);
  782. $this->customersmt->save(array('num'=>$cusnum['num']+1,'time'=>$post['buytime']),$customerid);
  783. $this->fullordersmt->insert($post);
  784. echo json_encode(array('msg'=>'下单成功','success'=>true));exit;
  785. }
  786. $arg_array = $arg_array[0];//用户ID
  787. $customersmt = $this->customersmt->read($arg_array);//用户信息
  788. $this->data['customersmt'] = $customersmt;
  789. $country = $this->country->find_all('1=1','id,name','name asc');//国家
  790. $this->data['country'] = $country;
  791. $express = $this->express->find_all();//物流商
  792. $this->data['express'] = $express;
  793. $bm = $this->country->read($customersmt['country']);
  794. $this->data['bm'] = $bm;
  795. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  796. $this->data['wlshop'] = $wlshop;
  797. $this->data['user'] = $user;
  798. $this->_Template('customersmt_mdedit',$this->data);
  799. }
  800. //上传excel
  801. public function _excela()
  802. {
  803. $dir = '/data/excel/'.date('Ymd',time()).'/';
  804. $config['upload_path'] = '.'.$dir ;
  805. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  806. $config['allowed_types'] = 'xls|xlsx';
  807. $config['max_size'] = 10240;
  808. $this->load->library('upload', $config);
  809. $this->upload->initialize($config);
  810. if ($this->upload->do_upload('userfile'))
  811. {
  812. $full_path = $dir.$this->upload->data('file_name');
  813. $fileName = '.' . $full_path;
  814. if (!file_exists($fileName))
  815. {
  816. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  817. }
  818. else
  819. {
  820. require_once "./data/excel/PHPExcel/IOFactory.php";
  821. @$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  822. @$phpExcel->setActiveSheetIndex(0);// 设置为默认表
  823. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  824. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  825. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  826. ++$column;//如果列数大于26行
  827. $list = array();
  828. for ($i = 2; $i <= $row; $i++) // 行数循环
  829. {
  830. $data = array();
  831. for ($c = 'A'; $c != $column; $c++) // 列数循环
  832. {
  833. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  834. }
  835. $list[] = $data;
  836. }
  837. }
  838. $i = 0;
  839. $this->db->trans_begin();
  840. foreach ($list as $key=>$value)
  841. {
  842. $value['1'] = $value['1']?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['1']):'';
  843. $value['7'] = $value['7']?str_replace('/( | | |\s)/','',$value['7']):'';
  844. if($value['0'] == "" || $value['1'] == "" || $value['6'] == "" || $value['11'] == "")
  845. {
  846. $i++;
  847. continue;
  848. }
  849. $shop = $this->shop->get_name($value['9']);
  850. if(!$shop)
  851. {
  852. $i++;
  853. continue;
  854. }
  855. if($value['11'] == 2)
  856. {
  857. $repeat = $this->customersmt->get_address($value['1']);//只判断地址
  858. }
  859. else
  860. {
  861. $repeat = $this->customersmt->find_all('name = "'.$value[0].'" and address = "'.$value[1].'" and phone = "'.$value[6].'" and shop = "'.$shop['id'].'"');//只判断邮箱
  862. }
  863. /* 判断邮箱和地址
  864. if($value['1'] == "" || $value['1'] == " ")
  865. {
  866. if($value['7'] == "" || $value['7'] == " ")
  867. {
  868. $repeat = 1;
  869. }
  870. else
  871. {
  872. $repeat = $this->customersmt->get_userid($value['7']);
  873. }
  874. }
  875. else
  876. {
  877. $repeat = $this->customersmt->get_address($value['1']);
  878. }
  879. */
  880. if(isset($repeat['type']))
  881. {
  882. if($repeat['type'] == $value['11'])
  883. {
  884. $i++;
  885. }
  886. else if($repeat['type'] != $value['11'])
  887. {
  888. $this->customersmt->save(array('type'=>$value['11']),$repeat['id']);
  889. }
  890. }
  891. else
  892. {
  893. $source = $this->typeclass->get_title($value['10']);
  894. if($source)
  895. {
  896. $post['name'] = ($value['0'] && $value['0'] != 'NULL')?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['0']):'';
  897. $post['userid'] = $value['7'];
  898. if($value['5'] != '')
  899. {
  900. $country = $this->country->get_ename(str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['5']));
  901. $post['country'] = $country['id'];
  902. }
  903. $post['level'] = $value['8']?$value['8']:5;
  904. $post['phone'] = $value['6']?$value['6']:'';
  905. $post['province'] = $value['3']?$value['3']:'';
  906. $post['city'] = $value['2']?$value['2']:'';
  907. $post['address'] = $value['1'];
  908. $post['zipcode'] = $value['4']?$value['4']:'';
  909. $post['shop'] = $shop['id'];
  910. $post['source'] = $source['id'];
  911. $post['type'] = $value['11'];
  912. $val12 = $value['12']?$value['12']:'';
  913. $post['count'] = $val12;
  914. $this->customersmt->insert($post);
  915. }
  916. }
  917. }
  918. if ($this->db->trans_status() === FALSE)
  919. {
  920. $this->db->trans_commit();
  921. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  922. }
  923. else
  924. {
  925. if(count($list) == $i)
  926. {
  927. $til = '导入全部失败!请检查导入信息';
  928. }
  929. else if(count($list) > $i && $i != 0)
  930. {
  931. $til = '部分导入成功!'.$i.'条信息有问题,请排查';
  932. }
  933. else if($i < 1)
  934. {
  935. $til = '导入成功!';
  936. }
  937. $this->db->trans_commit();
  938. echo json_encode(array('msg'=>$til,'success'=>true));exit;
  939. }
  940. }
  941. else
  942. {
  943. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  944. }
  945. }
  946. //下载excel
  947. public function _excel()
  948. {
  949. if(isset($_GET['excel']))
  950. {
  951. if(isset($_SESSION['api']))
  952. {
  953. $user = $this->user->get_api($_SESSION['api']);
  954. $usp = $user;
  955. $fgshop = "";$sid = "";
  956. $user = explode('|',trim($user['shop'],'|'));
  957. foreach ($user as $value)
  958. {
  959. $fgshop .= " shop = ".$value." or";
  960. $sid .= " id = ".$value." or";
  961. }
  962. }
  963. $dowid = $this->input->get('a');
  964. $wid = "";
  965. if($dowid != "")
  966. {
  967. $id_arr = explode(',',rtrim($dowid,','));
  968. $wid .= " id = 0 or";
  969. foreach ($id_arr as $v)
  970. {
  971. $wid .= " id = '$v' or";
  972. }
  973. $wid = " and".rtrim($wid,'or');
  974. }
  975. $excel = $this->input->get('excel',true);
  976. $page = $this->input->get('page',true);
  977. $perpage = $this->input->get('perpage',true);
  978. $shop = $this->input->get('shop',true);
  979. $name = $this->input->get('name',true);
  980. $userid = $this->input->get('userid',true);
  981. $address = $this->input->get('address',true);
  982. $level = $this->input->get('level',true);
  983. $timetk = $this->input->get('timetk',true);
  984. $timetj = $this->input->get('timetj',true);
  985. $timetk = strtotime($timetk);
  986. $timetj = strtotime($timetj);
  987. $where = "1 = 1 and (".rtrim($fgshop,'or').")";
  988. if($shop)
  989. {
  990. $where .= " and shop = '$shop'";
  991. }
  992. if($name)
  993. {
  994. $where .= " and name like '%$name%'";
  995. }
  996. if($userid)
  997. {
  998. $where .= " and userid like '%$userid%'";
  999. }
  1000. if($level)
  1001. {
  1002. $where .= " and level = '$level'";
  1003. }
  1004. if($address)
  1005. {
  1006. $where .= " and address like '%$address%'";
  1007. }
  1008. if($timetk && $timetj)
  1009. {
  1010. $where .= " and time > '$timetk' and time < '$timetj'";
  1011. }
  1012. $where .= " and type = 1";//白名单用户
  1013. if($excel == 2) //老客户列表
  1014. {
  1015. $info_list = $this->customersmt->find_all($where.$wid,'name,userid,time,num,money','time desc');
  1016. foreach ($info_list as $key=>$value)
  1017. {
  1018. $info_list[$key]['time'] = date('Y-m-d H:i:s',$value['time']);
  1019. }
  1020. $fzh = "<td>客户名</td><td>客户邮箱</td><td>最近一次下单时间</td><td>购买次数</td><td>购买总金额</td>";
  1021. $title = "老客户列表";
  1022. }
  1023. else
  1024. {
  1025. $info_list = array();
  1026. $fdata = $this->customersmt->find_all($where.$wid,'userid,shop','time desc');
  1027. foreach ($fdata as $key=>$value)
  1028. {
  1029. $d = $this->fullordersmt->find_all('userid = "'.$value['userid'].'" and shop = "'.$value['shop'].'" and mergeid = 0','orderinfo,state,product,name,userid,dtime,shouldmoney','time desc');
  1030. foreach ($d as $k=>$v)
  1031. {
  1032. $typeclass = $this->typeclass->read($v['state']);
  1033. $v['state'] = $typeclass['spare'];
  1034. $info_list[] = $v;
  1035. }
  1036. }
  1037. $fzh = "<td>订单号</td><td>订单状态</td><td>产品名</td><td>客户名</td><td>客户邮箱</td><td>下单时间</td><td>订单金额</td>";
  1038. $title = "老客户订单列表";
  1039. }
  1040. $titlename = "<table border=1>
  1041. <tr>"
  1042. .$fzh.
  1043. "</tr>
  1044. </table>";
  1045. $tail = "\n";
  1046. $filename = $title.'-'.date('Ymd',time()).".xls";
  1047. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  1048. }
  1049. }
  1050. //下载excel模板
  1051. public function _down()
  1052. {
  1053. if(isset($_GET['excela']))
  1054. {
  1055. $title = "客户导入模板";
  1056. $titledata = array(array('姓名(必填)','详细地址(必填)','城市','省/州','邮编','国家','电话(必填)','客户ID','类型(1:网红2:批发3:店铺转线下4:线下其他5:店内)','所属店铺(必须ERP已有店铺)','来源(数据字典的户来源需存在)','黑白名单(白名单填1或黑名单填2,必填)','备注'),array('lekia waites','700 Sandy Plains rd suite b14','marietta','Georgia','30066','United States','4047322519','123456','5','Ali Pearl Hair','速卖通','1','备注'));
  1057. $filename = $title.".xls";
  1058. $this->customersmt->get_excel($titledata,$filename);
  1059. }
  1060. }
  1061. }