Customersmt.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053
  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($express['ioss'] == 1 && $post['ioss'] == '')
  658. {
  659. echo json_encode(array('msg'=>'此快递方式必须选择IOSS!','success'=>false));exit;
  660. }
  661. if(strlen($post['address']) > $express['addresssize'] || strlen($post['address2']) > $express['addresssize'])
  662. {
  663. echo json_encode(array('msg'=>'此快递方地址不可超出'.$express['addresssize'].'个字符','success'=>false));exit;
  664. }
  665. if($post['express'] == '2' && $post['zzl'] >= '16' && $post['js'] == '0')
  666. {
  667. //echo json_encode(array('msg'=>'总重量大于等于16不可选FIRST CLASS','success'=>false));exit;
  668. }
  669. if(($post['express'] == '3' || $post['express'] == '42' || $post['express'] == '24') && $post['shouldmoney'] < 1)
  670. {
  671. echo json_encode(array('msg'=>'零金额订单不可发 UPS/DHL官方-美国/Fedex(杭州)','success'=>false));exit;
  672. }
  673. if($post['express'] == '6' && $post['province'] == '')
  674. {
  675. echo json_encode(array('msg'=>'选择DPEX必须填写州信息','success'=>false));exit;
  676. }
  677. /**
  678. $post['saddress']
  679. if($post['printtype'] == 1)//如果是运单
  680. {
  681. $post['productdescription'] = $this->input->post('productdescription',true);
  682. $post['customs'] = $this->input->post('customs',true);
  683. }
  684. **/
  685. //开始注释 xyxg
  686. /**
  687. $warehousenew = $this->warehouse->read($post['type']);
  688. $ft = array();
  689. $ftdata = explode('|',rtrim($fpcount,'|'));
  690. foreach ($ftdata as $va)
  691. {
  692. $ftitle = '';
  693. $va = explode('-',trim($va,'-'));
  694. foreach ($va as $v)
  695. {
  696. $v = $this->typeclass->read($v);
  697. $ftitle .= $v['title'].' ';
  698. }
  699. $ft[] = rtrim($ftitle,' ');
  700. }
  701. $kcyz = $this->whlabel->get_kc($post['state'],$post['state'],$warehousenew['zd'],$warehousenew['ys'],$post['type'],$whlabel,$fpcount,$ft,$post['number'],$shop);//新添加订单老状态state和新状态state一样,不用走删除占用步奏
  702. if($kcyz['t'] > '0')
  703. {
  704. echo $kcyz['m'];exit;
  705. }
  706. else
  707. {
  708. if($this->fullordersmt->insert($post))
  709. {
  710. $cusnum = $this->customersmt->read($customerid);
  711. $this->customersmt->save(array('num'=>$cusnum['num']+1,'time'=>$post['buytime']),$customerid);
  712. echo json_encode(array('msg'=>'下单成功','success'=>true));exit;
  713. }
  714. else
  715. {
  716. echo json_encode(array('msg'=>'下单失败,请重试','success'=>false));exit;
  717. }
  718. }
  719. //结束注释
  720. **/
  721. $dtctitle = array();
  722. $dictionaries = $this->typeclass->find_all();
  723. foreach ($dictionaries as $v)
  724. {
  725. $dtctitle[$v['id']] = array($v['title'],$v['bqsku']);
  726. }
  727. $fpdata = $post['fpdata'];
  728. if(stripos($fpdata,'-128-') !== false || stripos($fpdata,'-127-') !== false)
  729. {
  730. $dfp = explode(';',trim($fpdata,';'));
  731. $fdata = '';
  732. foreach ($dfp as $k=>$v)
  733. {
  734. $ptitleb = '';
  735. $fp = explode('|',trim($v,'|'));
  736. $fp0 = explode(',',$fp[0]);
  737. $fp1 = explode('-',trim($fp0[1],'-'));
  738. foreach ($fp1 as $vv)
  739. {
  740. $ptitleb .= isset($dtctitle[$vv])?$dtctitle[$vv][0].' ':'';
  741. }
  742. $ptitleb .= $dtctitle[$fp0[0]][1].'inch ';
  743. $fp[1] = $ptitleb;
  744. $fdata .= implode("|",$fp).";";
  745. }
  746. $fpdata = $fdata;
  747. }
  748. $warehouse = $this->warehouse->read($post['type']);
  749. if($warehouse['bdcountry'] != 0 && $post['country'] != $warehouse['bdcountry'])
  750. {
  751. echo json_encode(array('msg'=>'当前国家无法选择'.$warehouse['title'].'!','success'=>false));exit;
  752. }
  753. $kcyz = $this->ck->get_kc($post['state'],$warehouse,$post['shop'],$post['number'],$whlabel,$fpdata);
  754. if($kcyz['t'] > '0')
  755. {
  756. echo $kcyz['m'];exit;
  757. }
  758. else if($kcyz['fpdata'] != '')
  759. {
  760. $post['whlabel'] = $kcyz['whlabel'];
  761. $post['fpdata'] = $kcyz['fpdata'];
  762. }
  763. $fl = $this->ck->get_fl($warehouse['hz'],$whlabel,$fpdata);
  764. $post['sfxh'] = $fl['sfxh'];
  765. $post['ckfl'] = $fl['ckfl'];
  766. //查询净重开始
  767. $post['jweight'] = $this->weight->get_weightcx($post['fpdata']);
  768. //查询净重结束
  769. $cusnum = $this->customersmt->read($customerid);
  770. $this->customersmt->save(array('num'=>$cusnum['num']+1,'time'=>$post['buytime']),$customerid);
  771. $this->fullordersmt->insert($post);
  772. echo json_encode(array('msg'=>'下单成功','success'=>true));exit;
  773. }
  774. $arg_array = $arg_array[0];//用户ID
  775. $customersmt = $this->customersmt->read($arg_array);//用户信息
  776. $this->data['customersmt'] = $customersmt;
  777. $country = $this->country->find_all('1=1','id,name','name asc');//国家
  778. $this->data['country'] = $country;
  779. $express = $this->express->find_all();//物流商
  780. $this->data['express'] = $express;
  781. $bm = $this->country->read($customersmt['country']);
  782. $this->data['bm'] = $bm;
  783. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  784. $this->data['wlshop'] = $wlshop;
  785. $this->_Template('customersmt_mdedit',$this->data);
  786. }
  787. //上传excel
  788. public function _excela()
  789. {
  790. $dir = '/data/excel/'.date('Ymd',time()).'/';
  791. $config['upload_path'] = '.'.$dir ;
  792. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  793. $config['allowed_types'] = 'xls|xlsx';
  794. $config['max_size'] = 10240;
  795. $this->load->library('upload', $config);
  796. $this->upload->initialize($config);
  797. if ($this->upload->do_upload('userfile'))
  798. {
  799. $full_path = $dir.$this->upload->data('file_name');
  800. $fileName = '.' . $full_path;
  801. if (!file_exists($fileName))
  802. {
  803. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  804. }
  805. else
  806. {
  807. require_once "./data/excel/PHPExcel/IOFactory.php";
  808. @$phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  809. @$phpExcel->setActiveSheetIndex(0);// 设置为默认表
  810. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  811. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  812. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  813. ++$column;//如果列数大于26行
  814. $list = array();
  815. for ($i = 2; $i <= $row; $i++) // 行数循环
  816. {
  817. $data = array();
  818. for ($c = 'A'; $c != $column; $c++) // 列数循环
  819. {
  820. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  821. }
  822. $list[] = $data;
  823. }
  824. }
  825. $i = 0;
  826. $this->db->trans_begin();
  827. foreach ($list as $key=>$value)
  828. {
  829. $value['1'] = $value['1']?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['1']):'';
  830. $value['7'] = $value['7']?str_replace('/( | | |\s)/','',$value['7']):'';
  831. if($value['0'] == "" || $value['1'] == "" || $value['6'] == "" || $value['11'] == "")
  832. {
  833. $i++;
  834. continue;
  835. }
  836. $shop = $this->shop->get_name($value['9']);
  837. if(!$shop)
  838. {
  839. $i++;
  840. continue;
  841. }
  842. if($value['11'] == 2)
  843. {
  844. $repeat = $this->customersmt->get_address($value['1']);//只判断地址
  845. }
  846. else
  847. {
  848. $repeat = $this->customersmt->find_all('name = "'.$value[0].'" and address = "'.$value[1].'" and phone = "'.$value[6].'" and shop = "'.$shop['id'].'"');//只判断邮箱
  849. }
  850. /* 判断邮箱和地址
  851. if($value['1'] == "" || $value['1'] == " ")
  852. {
  853. if($value['7'] == "" || $value['7'] == " ")
  854. {
  855. $repeat = 1;
  856. }
  857. else
  858. {
  859. $repeat = $this->customersmt->get_userid($value['7']);
  860. }
  861. }
  862. else
  863. {
  864. $repeat = $this->customersmt->get_address($value['1']);
  865. }
  866. */
  867. if(isset($repeat['type']))
  868. {
  869. if($repeat['type'] == $value['11'])
  870. {
  871. $i++;
  872. }
  873. else if($repeat['type'] != $value['11'])
  874. {
  875. $this->customersmt->save(array('type'=>$value['11']),$repeat['id']);
  876. }
  877. }
  878. else
  879. {
  880. $source = $this->typeclass->get_title($value['10']);
  881. if($source)
  882. {
  883. $post['name'] = ($value['0'] && $value['0'] != 'NULL')?str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['0']):'';
  884. $post['userid'] = $value['7'];
  885. if($value['5'] != '')
  886. {
  887. $country = $this->country->get_ename(str_replace(array('/( | | |\s)/',"'"),array(' ',"’"),$value['5']));
  888. $post['country'] = $country['id'];
  889. }
  890. $post['level'] = $value['8']?$value['8']:5;
  891. $post['phone'] = $value['6']?$value['6']:'';
  892. $post['province'] = $value['3']?$value['3']:'';
  893. $post['city'] = $value['2']?$value['2']:'';
  894. $post['address'] = $value['1'];
  895. $post['zipcode'] = $value['4']?$value['4']:'';
  896. $post['shop'] = $shop['id'];
  897. $post['source'] = $source['id'];
  898. $post['type'] = $value['11'];
  899. $val12 = $value['12']?$value['12']:'';
  900. $post['count'] = $val12;
  901. $this->customersmt->insert($post);
  902. }
  903. }
  904. }
  905. if ($this->db->trans_status() === FALSE)
  906. {
  907. $this->db->trans_commit();
  908. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  909. }
  910. else
  911. {
  912. if(count($list) == $i)
  913. {
  914. $til = '导入全部失败!请检查导入信息';
  915. }
  916. else if(count($list) > $i && $i != 0)
  917. {
  918. $til = '部分导入成功!'.$i.'条信息有问题,请排查';
  919. }
  920. else if($i < 1)
  921. {
  922. $til = '导入成功!';
  923. }
  924. $this->db->trans_commit();
  925. echo json_encode(array('msg'=>$til,'success'=>true));exit;
  926. }
  927. }
  928. else
  929. {
  930. echo json_encode(array('msg'=>'上传失败!','t'=>$this->upload->display_errors(),'success'=>false));exit;
  931. }
  932. }
  933. //下载excel
  934. public function _excel()
  935. {
  936. if(isset($_GET['excel']))
  937. {
  938. if(isset($_SESSION['api']))
  939. {
  940. $user = $this->user->get_api($_SESSION['api']);
  941. $usp = $user;
  942. $fgshop = "";$sid = "";
  943. $user = explode('|',trim($user['shop'],'|'));
  944. foreach ($user as $value)
  945. {
  946. $fgshop .= " shop = ".$value." or";
  947. $sid .= " id = ".$value." or";
  948. }
  949. }
  950. $dowid = $this->input->get('a');
  951. $wid = "";
  952. if($dowid != "")
  953. {
  954. $id_arr = explode(',',rtrim($dowid,','));
  955. $wid .= " id = 0 or";
  956. foreach ($id_arr as $v)
  957. {
  958. $wid .= " id = '$v' or";
  959. }
  960. $wid = " and".rtrim($wid,'or');
  961. }
  962. $excel = $this->input->get('excel',true);
  963. $page = $this->input->get('page',true);
  964. $perpage = $this->input->get('perpage',true);
  965. $shop = $this->input->get('shop',true);
  966. $name = $this->input->get('name',true);
  967. $userid = $this->input->get('userid',true);
  968. $address = $this->input->get('address',true);
  969. $level = $this->input->get('level',true);
  970. $timetk = $this->input->get('timetk',true);
  971. $timetj = $this->input->get('timetj',true);
  972. $timetk = strtotime($timetk);
  973. $timetj = strtotime($timetj);
  974. $where = "1 = 1 and (".rtrim($fgshop,'or').")";
  975. if($shop)
  976. {
  977. $where .= " and shop = '$shop'";
  978. }
  979. if($name)
  980. {
  981. $where .= " and name like '%$name%'";
  982. }
  983. if($userid)
  984. {
  985. $where .= " and userid like '%$userid%'";
  986. }
  987. if($level)
  988. {
  989. $where .= " and level = '$level'";
  990. }
  991. if($address)
  992. {
  993. $where .= " and address like '%$address%'";
  994. }
  995. if($timetk && $timetj)
  996. {
  997. $where .= " and time > '$timetk' and time < '$timetj'";
  998. }
  999. $where .= " and type = 1";//白名单用户
  1000. if($excel == 2) //老客户列表
  1001. {
  1002. $info_list = $this->customersmt->find_all($where.$wid,'name,userid,time,num,money','time desc');
  1003. foreach ($info_list as $key=>$value)
  1004. {
  1005. $info_list[$key]['time'] = date('Y-m-d H:i:s',$value['time']);
  1006. }
  1007. $fzh = "<td>客户名</td><td>客户邮箱</td><td>最近一次下单时间</td><td>购买次数</td><td>购买总金额</td>";
  1008. $title = "老客户列表";
  1009. }
  1010. else
  1011. {
  1012. $info_list = array();
  1013. $fdata = $this->customersmt->find_all($where.$wid,'userid,shop','time desc');
  1014. foreach ($fdata as $key=>$value)
  1015. {
  1016. $d = $this->fullordersmt->find_all('userid = "'.$value['userid'].'" and shop = "'.$value['shop'].'" and mergeid = 0','orderinfo,state,product,name,userid,dtime,shouldmoney','time desc');
  1017. foreach ($d as $k=>$v)
  1018. {
  1019. $typeclass = $this->typeclass->read($v['state']);
  1020. $v['state'] = $typeclass['spare'];
  1021. $info_list[] = $v;
  1022. }
  1023. }
  1024. $fzh = "<td>订单号</td><td>订单状态</td><td>产品名</td><td>客户名</td><td>客户邮箱</td><td>下单时间</td><td>订单金额</td>";
  1025. $title = "老客户订单列表";
  1026. }
  1027. $titlename = "<table border=1>
  1028. <tr>"
  1029. .$fzh.
  1030. "</tr>
  1031. </table>";
  1032. $tail = "\n";
  1033. $filename = $title.'-'.date('Ymd',time()).".xls";
  1034. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  1035. }
  1036. }
  1037. //下载excel模板
  1038. public function _down()
  1039. {
  1040. if(isset($_GET['excela']))
  1041. {
  1042. $title = "客户导入模板";
  1043. $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','备注'));
  1044. $filename = $title.".xls";
  1045. $this->customersmt->get_excel($titledata,$filename);
  1046. }
  1047. }
  1048. }