Customersmt.php 39 KB

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