Fullorderabf.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. /**
  3. * 作为fullorder的替补文件 因为fullorder的文件代码太长了 这里分担下压力
  4. */
  5. class Fullorderabf extends Start_Controller {
  6. public function __construct(){
  7. parent::__construct();
  8. $this->load->_model('Model_user','user');
  9. $this->load->_model('Model_fullorder','fullorder');
  10. $this->load->_model('Model_shop','shop');
  11. $this->load->_model('Model_express','express');
  12. $this->load->_model('Model_country','country');
  13. $this->load->_model('Model_typeclass','typeclass');
  14. $this->load->_model('Model_pay','pay');
  15. $this->load->_model('Model_logic_order','logic_order');
  16. $this->load->_model('Model_warehouse','warehouse');
  17. $this->load->_model('Model_ck','ck');
  18. $this->load->_model('Model_specialstock','specialstock');
  19. $this->load->_model('Model_whlabel','whlabel');
  20. $this->load->_model('Model_customer','customer');
  21. }
  22. //定义方法的调用规则 获取URI第二段值
  23. public function _remap($arg,$arg_array)
  24. {
  25. if($arg == 'yjtj')//一件添加订单
  26. {
  27. $this->_addOrder();
  28. }elseif($arg == 'yhtj_kh'){
  29. $this->_addOrder_kh($arg_array);
  30. }
  31. else
  32. {
  33. $this->_index();
  34. }
  35. }
  36. //管理
  37. public function _index()
  38. {
  39. exit('No direct script access allowed');
  40. }
  41. //一键添加订单
  42. private function _addOrder(){
  43. $user = $this->user->get_api($_SESSION['api']);
  44. if($user)
  45. {
  46. $uu = $user;
  47. $fgshop = "";$sid = "";
  48. $u = $user;
  49. $user = explode('|',trim($user['shop'],'|'));
  50. foreach ($user as $value)
  51. {
  52. $fgshop .= " shop = ".$value." or";
  53. $sid .= " id = ".$value." or";
  54. }
  55. }
  56. $post = $this->input->post(NULL, TRUE);
  57. if(isset($post['shop']))
  58. {
  59. $fpcount = $this->input->post('fpcount',true);
  60. if(!$fpcount)
  61. {
  62. echo json_encode(array('msg'=>'需要先清理浏览器缓存,刷新当前页面后再试!','success'=>false));exit;
  63. }
  64. $customerid = $this->input->post('customerid',true);
  65. if(empty($customerid)){
  66. $tmp_email = $this->input->post('email',true);
  67. $tmp_shop = $this->input->post('shop',true);
  68. $customer = $this->customer->get_email($tmp_email,$tmp_shop);
  69. }else{
  70. $customer = $this->customer->read($customerid);
  71. }
  72. if(empty($customer)){
  73. $str = $post['phone'];
  74. preg_match_all('/[0-9]/u',$str,$result);
  75. $numphone = join('',$result[0]);
  76. $ct['shop'] = $post['shop'];
  77. $ct['source'] = 10;
  78. $ct['level'] = 5;
  79. $ct['country'] = $post['country'];
  80. $ct['time'] = time();
  81. $ct['num'] = 1;
  82. $ct['money'] = $post['shouldmoney'];
  83. $ct['zipcode'] = $post['zipcode'];
  84. $ct['name'] = $post['name'];
  85. $ct['phone'] = $post['phone'];
  86. $ct['numphone'] = $numphone;
  87. $ct['email'] = preg_replace('/( | | |\s)+/','',$post['email']);
  88. $ct['province'] = $post['province'];
  89. $ct['city'] = $post['city'];
  90. $ct['address'] = $post['address'];
  91. $ct['zhcx'] = $post['shop'].'-'.$ct['email'];
  92. $ct['is_tb'] = 0;
  93. $this->customer->insert($ct);
  94. $tmp_email = $this->input->post('email',true);
  95. $tmp_shop = $this->input->post('shop',true);
  96. $customer = $this->customer->get_email($tmp_email,$tmp_shop);
  97. $customerid = $customer['id'];
  98. }else{
  99. $customerid = $customer['id'];
  100. }
  101. if(empty($customerid)){
  102. echo json_encode(array('msg'=>'客户信息异常!','success'=>false));exit;
  103. }
  104. $shop = $this->input->post('shop',true);
  105. $sp = $this->shop->read($shop);
  106. $num = $this->fullorder->find_count('shop = "'.$sp['id'].'" and gtime = "'.date('Ymd',time()).'"');
  107. $post['source'] = 1;//订单类型:1.线下订单2.PC3.手机
  108. $post['state'] = 207;//订单状态:207等待发货
  109. $post['review'] = 2;//审核状态:1.未送审2.待审核3.不通过4取消重审5.审核通过6.自动通过
  110. $post['print'] = 1;//打印状态:1.不可打印2.未打印3.已打印
  111. $post['library'] = 1;//出库状态:1.未出库2.已出库3.已退库
  112. $post['libraryconfirm'] = 1;//出库确认:1.不允许2.允许
  113. $post['link'] = $sp['link'];
  114. $post['issku'] = $sp['sku'];
  115. if($post['print'] != 3)
  116. {
  117. $post['librarynot'] = "订单未打印,未审核或未通过";//不能出库原因
  118. }
  119. $orderinfo = $this->input->post('orderinfo',true);
  120. $post['shop'] = $sp['id'];
  121. $post['user'] = $sp['shopuser'];
  122. $post['number'] = $sp['shortname'].'-'.date('ymd',time()).'-'.(substr(strval($num+1+1000),1,3));//编号
  123. if($orderinfo != "")
  124. {
  125. $ordefin = $this->fullorder->get_orderinfo($orderinfo);
  126. if($ordefin)
  127. {
  128. echo json_encode(array('msg'=>'订单号重复!','success'=>false));exit;
  129. }
  130. else
  131. {
  132. $post['orderinfo'] = $orderinfo;
  133. }
  134. }
  135. else
  136. {
  137. $post['orderinfo'] = $sp['id'].date('ymdHis',time()).rand(0,1);//订单号
  138. }
  139. if($post['paypal'] != '')
  140. {
  141. $pp = $this->fullorder->get_paypal($post['paypal']);
  142. if($pp)
  143. {
  144. echo json_encode(array('msg'=>'此交易号的订单已存在!','success'=>false));exit;
  145. }
  146. }
  147. $post['client'] = $this->input->post('client',true);//客户名称
  148. $btime = $this->input->post('buytime',true);//付款时间
  149. $post['buytime'] = strtotime($btime);//时间转UX
  150. $post['dtime'] = time();//订单时间
  151. $post['gtime'] = date('Ymd',time());//格式化时间
  152. $post['pay'] = $this->input->post('pay',true);//支付方式
  153. $post['capital'] = $this->input->post('capital',true);//资金状态
  154. $post['type'] = $this->input->post('warehouse',true);//发货仓库
  155. $post['currency'] = $this->input->post('currency',true);//币种
  156. $currency = $this->typeclass->read($post['currency']);
  157. $post['currencytitle'] = $currency['title'];//币种名称
  158. $post['freight'] = $this->input->post('freight',true);//运费
  159. $post['expressmoney'] = $this->input->post('expressmoney',true);//物流金额
  160. $post['shouldmoney'] = $this->input->post('shouldmoney',true);//应收金额
  161. $post['shouldmoney'] = (float)$post['shouldmoney'];
  162. $post['skje'] = $post['shouldmoney'];//收款金额
  163. $product = $this->input->post('product');//产品名称
  164. $product = str_replace(array('%26','%2B'),array('&','+'),$product);
  165. $post['product'] = preg_replace('/( | | |\s)/',' ',$product);
  166. $orderremarks = $this->input->post('orderremarks');//订单备注
  167. $orderremarks = str_replace(array('%26','%2B'),array('&','+'),$orderremarks);
  168. $post['orderremarks'] = preg_replace('/( | | |\s)/',' ',$orderremarks);
  169. $shipremarks = $this->input->post('shipremarks');//仓库品名
  170. $shipremarks = str_replace(array('%26','%2B'),array('&','+'),$shipremarks);//仓库品名
  171. $post['shipremarks'] = preg_replace('/( | | |\s)/',' ',$shipremarks);
  172. $post['email'] = $this->input->post('email',true);//邮箱
  173. $name = $this->input->post('name',true);//名称
  174. $post['name'] = preg_replace('/( | | |\s)/',' ',$name);
  175. $post['phone'] = $this->input->post('phone',true);//电话
  176. $post['phone'] = preg_replace('/\D/s','',$post['phone']);
  177. $post['country'] = $this->input->post('country',true);//国家
  178. $ct = $this->country->read($post['country']);//国家
  179. $post['al'] = $ct['lb'];//国家二字码
  180. $post['province'] = $this->input->post('province',true);//省、州
  181. $post['province'] = preg_replace("/^[\s\v".chr(227).chr(128)."]+/","", $post['province']); //替换开头空字符
  182. $post['province'] = preg_replace("/[\s\v".chr(227).chr(128)."]+$/","", $post['province']); //替换结尾空字符
  183. $post['city'] = $this->input->post('city',true);//城市
  184. $post['city'] = preg_replace("/^[\s\v".chr(227).chr(128)."]+/","", $post['city']); //替换开头空字符
  185. $post['city'] = preg_replace("/[\s\v".chr(227).chr(128)."]+$/","", $post['city']); //替换结尾空字符
  186. $post['zipcode'] = $this->input->post('zipcode',true);//邮编
  187. $post['zipcode'] = preg_replace("/^[\s\v".chr(227).chr(128)."]+/","", $post['zipcode']); //替换开头空字符
  188. $post['zipcode'] = preg_replace("/[\s\v".chr(227).chr(128)."]+$/","", $post['zipcode']); //替换结尾空字符
  189. $post['address'] = $this->input->post('address',true);//地址
  190. $post['printtype'] = $this->input->post('printtype',true);//打印类型
  191. $fpdata = $this->input->post('fpdata');//购买产品内容
  192. $fpdata = str_replace(array('%26','%2B'),array('&','+'),$fpdata);
  193. $post['fpdata'] = $fpdata;
  194. $post['sbpm'] = $this->input->post('sbpm',true);//申报品名
  195. $post['zwpm'] = $this->input->post('zwpm',true);//中文品名
  196. $post['ts'] = $this->input->post('ts',true);//条数
  197. $post['dtsbjz'] = $this->input->post('dtsbjz',true);//单条申报价
  198. $post['zsbjz'] = $this->input->post('zsbjz',true);//总申报价
  199. $post['zzl'] = $this->input->post('zzl',true);//总重量
  200. $post['zjs'] = $this->input->post('zjs',true);//总件数
  201. $post['express'] = $this->input->post('express',true);//快递公司
  202. $post['printtype'] = $this->input->post('printtype',true);//打印类型
  203. $post['quantity'] = $this->input->post('quantity',true);//数量
  204. $post['paypal'] = $post['orderinfo'];//支付号
  205. $post['guarantee'] = $this->input->post('guarantee',true);//卖家保障
  206. $post['msg'] = $this->input->post('msg',true);//发送留言类型
  207. $post['ioss'] = $this->input->post('ioss',true);
  208. $post['sbpm'] = $this->input->post('sbpm',true);
  209. $post['merge'] = $post['mergeid'] = 0;
  210. $pay = $this->pay->get_typeclass($post['pay']);
  211. $yga = $post['shouldmoney'];
  212. $post['budget'] = 0;
  213. $post['estimaterate'] = 1;
  214. $post['budget'] = $post['shouldmoney'];
  215. $baddress = $this->input->post('baddress',true);
  216. $saddress = $this->input->post('saddress',true);
  217. $baddress = array_reverse(explode(',',$baddress));
  218. $saddress = array_reverse(explode(',',$saddress));
  219. $bar = '';$sar = '';
  220. $cr = $this->country->read($post['country']);
  221. $baddress[1] = $cr['lb'];
  222. $saddress[1] = $cr['lb'];
  223. $baddress = array_reverse($baddress);
  224. $saddress = array_reverse($saddress);
  225. for($i=0;$i<count($baddress);$i++)
  226. {
  227. $bar .= $baddress[$i].',';
  228. }
  229. for($i=0;$i<count($saddress);$i++)
  230. {
  231. $sar .= $saddress[$i].',';
  232. }
  233. if(empty($post['ts'])){
  234. echo json_encode(array('msg'=>'申报条数不能为空!','success'=>false));exit;
  235. }
  236. $post['baddress'] = rtrim($bar,',');//卖家保障
  237. $post['saddress'] = rtrim($sar,',');//卖家保障
  238. $whlabel = $this->input->post('whlabel',true);
  239. if($post['express'] == 2 && (stripos($post['name'],'&') !== false || stripos($post['name'],"'") !== false))
  240. {
  241. echo json_encode(array('msg'=>'USPS收件人或公司名不可用特殊符号!','success'=>false));exit;
  242. }
  243. if(strlen($post['client']) > 35 || strlen($post['name']) > 35)//收件人姓名或公司名不允许超过35位
  244. {
  245. echo json_encode(array('msg'=>'收件人姓名或公司名不可超过35个字符!','success'=>false));exit;
  246. }
  247. if(($post['express'] == '5' || $post['express'] == '24' || $post['express'] == '42' || $post['express'] == '31') && $post['country'] != 192)
  248. {
  249. echo json_encode(array('msg'=>'非美国无法选择Fedex、DHL官方-美国!','success'=>false));exit;
  250. }
  251. if($post['express'] == '3' && $post['country'] != 192 && $post['country'] != 35)
  252. {
  253. echo json_encode(array('msg'=>'非美国和加拿大无法选择UPS!','success'=>false));exit;
  254. }
  255. if($post['express'] == '3' && $post['country'] == 35 && $post['zsbjz'] > 20)
  256. {
  257. echo json_encode(array('msg'=>'UPS加拿大最高申报不可超过20','success'=>false));exit;
  258. }
  259. if($post['express'] == '2' && $post['warehouse'] != 5)
  260. {
  261. echo json_encode(array('msg'=>'非美国仓无法选择USPS!','success'=>false));exit;
  262. }
  263. if($post['express'] == '99' && $post['bx'] > 0)
  264. {
  265. echo json_encode(array('msg'=>'此物流不允许购买保险','success'=>false));exit;
  266. }
  267. if($post['express'] == 42 && $post['sbpm'] != 'Human Hair Wigs' && $post['sbpm'] != 'Human Hair Goods')//$post['express'] == 3 ||
  268. {
  269. echo json_encode(array('msg'=>'此快递方式必须选择Human Hair Wigs/Human Hair Goods!','success'=>false));exit;
  270. }
  271. if($post['express'] == 24 && $post['sbpm'] != 'Hair Sample' && $post['sbpm'] != 'Human Hair Wigs' && $post['sbpm'] != 'Human Hair Goods')//$post['express'] == 3 ||
  272. {
  273. echo json_encode(array('msg'=>'此快递方式必须选择Hair Sample/Human Hair Wigs/Human Hair Goods!','success'=>false));exit;
  274. }
  275. if($post['country'] != 192 && $post['express'] == 1 && $post['sbpm'] != 'Synthetic Hair Wigs' && $post['sbpm'] != 'Synthetic Hair Goods')//$post['express'] == 3 ||
  276. {
  277. echo json_encode(array('msg'=>'非美国选择官方DHL必须选择Synthetic Hair Wigs/Synthetic Hair Goods','success'=>false));exit;
  278. }
  279. if(empty($post['paypal'])){
  280. echo json_encode(array('msg'=>'交易号必须填写','success'=>false));exit;
  281. }
  282. $express = $this->express->read($post['express']);
  283. if($post['zsbjz'] > $express['sbjz'])
  284. {
  285. echo json_encode(array('msg'=>'总申报价值不可超出'.$express['sbjz'],'success'=>false));exit;
  286. }
  287. if($post['shouldmoney'] > $express['shouldmoney'] && $express['shouldmoney'] != 0)
  288. {
  289. echo json_encode(array('msg'=>'订单金额不可超出'.$express['shouldmoney'],'success'=>false));exit;
  290. }
  291. if($express['ioss'] == 1 && $post['ioss'] == '')
  292. {
  293. echo json_encode(array('msg'=>'此快递方式必须选择IOSS!','success'=>false));exit;
  294. }
  295. if(strlen($post['address']) > $express['addresssize'] || strlen($post['address2']) > $express['addresssize'])
  296. {
  297. echo json_encode(array('msg'=>'此快递方地址不可超出'.$express['addresssize'].'个字符','success'=>false));exit;
  298. }
  299. if(strlen($post['address']) < 5)
  300. {
  301. echo json_encode(array('msg'=>'地址不可留空!','success'=>false));exit;
  302. }
  303. if($post['express'] == '2' && $post['zzl'] > '16' && $post['js'] == '0')
  304. {
  305. echo json_encode(array('msg'=>'重量大于16不可按Ground Advantage提交!','success'=>false));exit;
  306. }
  307. if($post['express'] == '2' && isset($post['js']) && $post['js'] == '0'&& $post['qm'] == '1')
  308. {
  309. echo json_encode(array('msg'=>'Ground Advantage不可使用签名服务!','success'=>false));exit;
  310. }
  311. if(($post['express'] == '3' || $post['express'] == '42' || $post['express'] == '24') && $post['shouldmoney'] < 1)
  312. {
  313. echo json_encode(array('msg'=>'零金额订单不可发 UPS/DHL官方-美国/Fedex(杭州)','success'=>false));exit;
  314. }
  315. if($post['express'] == '42' && $post['zsbjz'] < 1)
  316. {
  317. echo json_encode(array('msg'=>'零申报金额不可发 DHL官方-美国','success'=>false));exit;
  318. }
  319. if($post['express'] == '6' && $post['province'] == '')
  320. {
  321. echo json_encode(array('msg'=>'选择DPEX必须填写州信息','success'=>false));exit;
  322. }
  323. //仅独立站 地址美国对电话 10或者11位进行判断
  324. if($post['country'] == 192){
  325. if((strlen($post['phone'])!= 10) && (strlen($post['phone'])!= 11)){
  326. echo json_encode(array('msg'=>'美国电话号码应为10/11位!','success'=>false));exit;
  327. }
  328. }
  329. //减少代码复用吧
  330. $lo_ret = $this->logic_order->checkEditCustomer($post);
  331. if($lo_ret['code'] != 1){
  332. echo json_encode(array('msg'=>$lo_ret['msg'],'success'=>false));exit;
  333. }
  334. $dtctitle = array();
  335. $dictionaries = $this->typeclass->find_all();
  336. foreach ($dictionaries as $v)
  337. {
  338. $dtctitle[$v['id']] = array($v['title'],$v['bqsku']);
  339. }
  340. $fpdata = $post['fpdata'];
  341. if(stripos($fpdata,'-128-') !== false || stripos($fpdata,'-127-') !== false)
  342. {
  343. $dfp = explode(';',trim($fpdata,';'));
  344. $fdata = '';
  345. foreach ($dfp as $k=>$v)
  346. {
  347. $ptitleb = '';
  348. $fp = explode('|',trim($v,'|'));
  349. $fp0 = explode(',',$fp[0]);
  350. if(isset($fp0[1]))
  351. {
  352. $fp1 = explode('-',trim($fp0[1],'-'));
  353. }
  354. else
  355. {
  356. $fp1 = explode('-',trim($fp[0],'-'));
  357. }
  358. foreach ($fp1 as $vv)
  359. {
  360. $ptitleb .= isset($dtctitle[$vv])?$dtctitle[$vv][0].' ':'';
  361. }
  362. if(isset($fp0[1]))
  363. {
  364. $ptitleb .= $dtctitle[$fp0[0]][1].'inch ';
  365. $fp[1] = $ptitleb;
  366. }
  367. $fdata .= implode("|",$fp).";";
  368. }
  369. $fpdata = $fdata;
  370. }
  371. $warehouse = $this->warehouse->read($post['type']);
  372. if($warehouse['bdcountry'] != 0 && $post['country'] != $warehouse['bdcountry'])
  373. {
  374. echo json_encode(array('msg'=>'当前国家无法选择'.$warehouse['title'].'!','success'=>false));exit;
  375. }
  376. $kcyz = $this->ck->get_kc($post['state'],$warehouse,$post['shop'],$post['number'],$whlabel,$fpdata);
  377. if($kcyz['t'] > '0')
  378. {
  379. echo $kcyz['m'];exit;
  380. }
  381. else if($kcyz['fpdata'] != '')
  382. {
  383. $post['whlabel'] = $kcyz['whlabel'];
  384. $post['fpdata'] = $kcyz['fpdata'];
  385. }
  386. $fl = $this->ck->get_fl($warehouse['hz'],$whlabel,$fpdata);
  387. $post['sfxh'] = $fl['sfxh'];
  388. $post['ckfl'] = $fl['ckfl'];
  389. //查询净重开始
  390. $post['jweight'] = $this->weight->get_weightcx($post['fpdata']);
  391. //查询净重结束
  392. $cusnum = $this->customer->read($customerid);
  393. $this->customer->save(array('num'=>$cusnum['num']+1,'time'=>$post['buytime']),$customerid);
  394. unset($post['id']);
  395. $this->fullorder->insert($post);
  396. echo json_encode(array('msg'=>'下单成功','success'=>true));exit;
  397. }
  398. $customer = [
  399. "shop"=>'28',
  400. "source"=>10,
  401. 'name'=>"何总客户",
  402. 'province'=>'河南省',
  403. 'city'=>"许昌市",
  404. 'street'=>"",
  405. 'zipcode'=>"461000",
  406. 'al'=>"",
  407. 'phone'=>"15393779998",
  408. 'email'=>"hzkh@xcly.com",
  409. 'country'=>"41",
  410. "express"=>"14",
  411. "address"=>"建安区英豪路与滨河路交叉路口往东约50米路北 龙盈实业(客户自提)",
  412. ];
  413. $this->data['customer'] = $customer;
  414. $country = $this->country->find_all('1=1','id,name','name asc');//国家
  415. $this->data['country'] = $country;
  416. $express = $this->express->find_all();//物流商
  417. $this->data['express'] = $express;
  418. $bm = $this->country->read($customer['country']);
  419. $this->data['bm'] = $bm;
  420. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  421. $this->data['wlshop'] = $wlshop;
  422. $this->data['user'] = $u['userid'];
  423. $this->_Template('fullorderabf_yjtj',$this->data);
  424. }
  425. //一键添加订单
  426. private function _addOrder_kh(){
  427. $user = $this->user->get_api($_SESSION['api']);
  428. if($user)
  429. {
  430. $uu = $user;
  431. $fgshop = "";$sid = "";
  432. $u = $user;
  433. $user = explode('|',trim($user['shop'],'|'));
  434. foreach ($user as $value)
  435. {
  436. $fgshop .= " shop = ".$value." or";
  437. $sid .= " id = ".$value." or";
  438. }
  439. }
  440. $post = $this->input->post(NULL, TRUE);
  441. if(isset($post['shop']))
  442. {
  443. $fpcount = $this->input->post('fpcount',true);
  444. if(!$fpcount)
  445. {
  446. echo json_encode(array('msg'=>'需要先清理浏览器缓存,刷新当前页面后再试!','success'=>false));exit;
  447. }
  448. $customerid = $this->input->post('customerid',true);
  449. if(empty($customerid)){
  450. $tmp_email = $this->input->post('email',true);
  451. $tmp_shop = $this->input->post('shop',true);
  452. $customer = $this->customer->get_email($tmp_email,$tmp_shop);
  453. }else{
  454. $customer = $this->customer->read($customerid);
  455. }
  456. if(empty($customer)){
  457. $str = $post['phone'];
  458. preg_match_all('/[0-9]/u',$str,$result);
  459. $numphone = join('',$result[0]);
  460. $ct['shop'] = $post['shop'];
  461. $ct['source'] = 10;
  462. $ct['level'] = 5;
  463. $ct['country'] = $post['country'];
  464. $ct['time'] = time();
  465. $ct['num'] = 1;
  466. $ct['money'] = $post['shouldmoney'];
  467. $ct['zipcode'] = $post['zipcode'];
  468. $ct['name'] = $post['name'];
  469. $ct['phone'] = $post['phone'];
  470. $ct['numphone'] = $numphone;
  471. $ct['email'] = preg_replace('/( | | |\s)+/','',$post['email']);
  472. $ct['province'] = $post['province'];
  473. $ct['city'] = $post['city'];
  474. $ct['address'] = $post['address'];
  475. $ct['zhcx'] = $post['shop'].'-'.$ct['email'];
  476. $ct['is_tb'] = 0;
  477. $this->customer->insert($ct);
  478. $tmp_email = $this->input->post('email',true);
  479. $tmp_shop = $this->input->post('shop',true);
  480. $customer = $this->customer->get_email($tmp_email,$tmp_shop);
  481. $customerid = $customer['id'];
  482. }else{
  483. $customerid = $customer['id'];
  484. }
  485. if(empty($customerid)){
  486. echo json_encode(array('msg'=>'客户信息异常!','success'=>false));exit;
  487. }
  488. $shop = $this->input->post('shop',true);
  489. $sp = $this->shop->read($shop);
  490. $num = $this->fullorder->find_count('shop = "'.$sp['id'].'" and gtime = "'.date('Ymd',time()).'"');
  491. $post['source'] = 1;//订单类型:1.线下订单2.PC3.手机
  492. $post['state'] = 207;//订单状态:207等待发货
  493. $post['review'] = 2;//审核状态:1.未送审2.待审核3.不通过4取消重审5.审核通过6.自动通过
  494. $post['print'] = 1;//打印状态:1.不可打印2.未打印3.已打印
  495. $post['library'] = 1;//出库状态:1.未出库2.已出库3.已退库
  496. $post['libraryconfirm'] = 1;//出库确认:1.不允许2.允许
  497. $post['link'] = $sp['link'];
  498. $post['issku'] = $sp['sku'];
  499. if($post['print'] != 3)
  500. {
  501. $post['librarynot'] = "订单未打印,未审核或未通过";//不能出库原因
  502. }
  503. $orderinfo = $this->input->post('orderinfo',true);
  504. $post['shop'] = $sp['id'];
  505. $post['user'] = $sp['shopuser'];
  506. $post['number'] = $sp['shortname'].'-'.date('ymd',time()).'-'.(substr(strval($num+1+1000),1,3));//编号
  507. if($orderinfo != "")
  508. {
  509. $ordefin = $this->fullorder->get_orderinfo($orderinfo);
  510. if($ordefin)
  511. {
  512. echo json_encode(array('msg'=>'订单号重复!','success'=>false));exit;
  513. }
  514. else
  515. {
  516. $post['orderinfo'] = $orderinfo;
  517. }
  518. }
  519. else
  520. {
  521. $post['orderinfo'] = $sp['id'].date('ymdHis',time()).rand(0,1);//订单号
  522. }
  523. if($post['paypal'] != '')
  524. {
  525. $pp = $this->fullorder->get_paypal($post['paypal']);
  526. if($pp)
  527. {
  528. echo json_encode(array('msg'=>'此交易号的订单已存在!','success'=>false));exit;
  529. }
  530. }
  531. $post['client'] = $this->input->post('client',true);//客户名称
  532. $btime = $this->input->post('buytime',true);//付款时间
  533. $post['buytime'] = strtotime($btime);//时间转UX
  534. $post['dtime'] = time();//订单时间
  535. $post['gtime'] = date('Ymd',time());//格式化时间
  536. $post['pay'] = $this->input->post('pay',true);//支付方式
  537. $post['capital'] = $this->input->post('capital',true);//资金状态
  538. $post['type'] = $this->input->post('warehouse',true);//发货仓库
  539. $post['currency'] = $this->input->post('currency',true);//币种
  540. $currency = $this->typeclass->read($post['currency']);
  541. $post['currencytitle'] = $currency['title'];//币种名称
  542. $post['freight'] = $this->input->post('freight',true);//运费
  543. $post['expressmoney'] = $this->input->post('expressmoney',true);//物流金额
  544. $post['shouldmoney'] = $this->input->post('shouldmoney',true);//应收金额
  545. $post['shouldmoney'] = (float)$post['shouldmoney'];
  546. $post['skje'] = $post['shouldmoney'];//收款金额
  547. $product = $this->input->post('product');//产品名称
  548. $product = str_replace(array('%26','%2B'),array('&','+'),$product);
  549. $post['product'] = preg_replace('/( | | |\s)/',' ',$product);
  550. $orderremarks = $this->input->post('orderremarks');//订单备注
  551. $orderremarks = str_replace(array('%26','%2B'),array('&','+'),$orderremarks);
  552. $post['orderremarks'] = preg_replace('/( | | |\s)/',' ',$orderremarks);
  553. $shipremarks = $this->input->post('shipremarks');//仓库品名
  554. $shipremarks = str_replace(array('%26','%2B'),array('&','+'),$shipremarks);//仓库品名
  555. $post['shipremarks'] = preg_replace('/( | | |\s)/',' ',$shipremarks);
  556. $post['email'] = $this->input->post('email',true);//邮箱
  557. $name = $this->input->post('name',true);//名称
  558. $post['name'] = preg_replace('/( | | |\s)/',' ',$name);
  559. $post['phone'] = $this->input->post('phone',true);//电话
  560. $post['phone'] = preg_replace('/\D/s','',$post['phone']);
  561. $post['country'] = $this->input->post('country',true);//国家
  562. $ct = $this->country->read($post['country']);//国家
  563. $post['al'] = $ct['lb'];//国家二字码
  564. $post['province'] = $this->input->post('province',true);//省、州
  565. $post['province'] = preg_replace("/^[\s\v".chr(227).chr(128)."]+/","", $post['province']); //替换开头空字符
  566. $post['province'] = preg_replace("/[\s\v".chr(227).chr(128)."]+$/","", $post['province']); //替换结尾空字符
  567. $post['city'] = $this->input->post('city',true);//城市
  568. $post['city'] = preg_replace("/^[\s\v".chr(227).chr(128)."]+/","", $post['city']); //替换开头空字符
  569. $post['city'] = preg_replace("/[\s\v".chr(227).chr(128)."]+$/","", $post['city']); //替换结尾空字符
  570. $post['zipcode'] = $this->input->post('zipcode',true);//邮编
  571. $post['zipcode'] = preg_replace("/^[\s\v".chr(227).chr(128)."]+/","", $post['zipcode']); //替换开头空字符
  572. $post['zipcode'] = preg_replace("/[\s\v".chr(227).chr(128)."]+$/","", $post['zipcode']); //替换结尾空字符
  573. $post['address'] = $this->input->post('address',true);//地址
  574. $post['printtype'] = $this->input->post('printtype',true);//打印类型
  575. $fpdata = $this->input->post('fpdata');//购买产品内容
  576. $fpdata = str_replace(array('%26','%2B'),array('&','+'),$fpdata);
  577. $post['fpdata'] = $fpdata;
  578. $post['sbpm'] = $this->input->post('sbpm',true);//申报品名
  579. $post['zwpm'] = $this->input->post('zwpm',true);//中文品名
  580. $post['ts'] = $this->input->post('ts',true);//条数
  581. $post['dtsbjz'] = $this->input->post('dtsbjz',true);//单条申报价
  582. $post['zsbjz'] = $this->input->post('zsbjz',true);//总申报价
  583. $post['zzl'] = $this->input->post('zzl',true);//总重量
  584. $post['zjs'] = $this->input->post('zjs',true);//总件数
  585. $post['express'] = $this->input->post('express',true);//快递公司
  586. $post['printtype'] = $this->input->post('printtype',true);//打印类型
  587. $post['quantity'] = $this->input->post('quantity',true);//数量
  588. $post['paypal'] = $post['orderinfo'];//支付号
  589. $post['guarantee'] = $this->input->post('guarantee',true);//卖家保障
  590. $post['msg'] = $this->input->post('msg',true);//发送留言类型
  591. $post['ioss'] = $this->input->post('ioss',true);
  592. $post['sbpm'] = $this->input->post('sbpm',true);
  593. $post['merge'] = $post['mergeid'] = 0;
  594. $pay = $this->pay->get_typeclass($post['pay']);
  595. $yga = $post['shouldmoney'];
  596. $post['budget'] = 0;
  597. $post['estimaterate'] = 1;
  598. $post['budget'] = $post['shouldmoney'];
  599. $baddress = $this->input->post('baddress',true);
  600. $saddress = $this->input->post('saddress',true);
  601. $baddress = array_reverse(explode(',',$baddress));
  602. $saddress = array_reverse(explode(',',$saddress));
  603. $bar = '';$sar = '';
  604. $cr = $this->country->read($post['country']);
  605. $baddress[1] = $cr['lb'];
  606. $saddress[1] = $cr['lb'];
  607. $baddress = array_reverse($baddress);
  608. $saddress = array_reverse($saddress);
  609. for($i=0;$i<count($baddress);$i++)
  610. {
  611. $bar .= $baddress[$i].',';
  612. }
  613. for($i=0;$i<count($saddress);$i++)
  614. {
  615. $sar .= $saddress[$i].',';
  616. }
  617. if(empty($post['ts'])){
  618. echo json_encode(array('msg'=>'申报条数不能为空!','success'=>false));exit;
  619. }
  620. $post['baddress'] = rtrim($bar,',');//卖家保障
  621. $post['saddress'] = rtrim($sar,',');//卖家保障
  622. $whlabel = $this->input->post('whlabel',true);
  623. if($post['express'] == 2 && (stripos($post['name'],'&') !== false || stripos($post['name'],"'") !== false))
  624. {
  625. echo json_encode(array('msg'=>'USPS收件人或公司名不可用特殊符号!','success'=>false));exit;
  626. }
  627. if(strlen($post['client']) > 35 || strlen($post['name']) > 35)//收件人姓名或公司名不允许超过35位
  628. {
  629. echo json_encode(array('msg'=>'收件人姓名或公司名不可超过35个字符!','success'=>false));exit;
  630. }
  631. if(($post['express'] == '5' || $post['express'] == '24' || $post['express'] == '42' || $post['express'] == '31') && $post['country'] != 192)
  632. {
  633. echo json_encode(array('msg'=>'非美国无法选择Fedex、DHL官方-美国!','success'=>false));exit;
  634. }
  635. if($post['express'] == '3' && $post['country'] != 192 && $post['country'] != 35)
  636. {
  637. echo json_encode(array('msg'=>'非美国和加拿大无法选择UPS!','success'=>false));exit;
  638. }
  639. if($post['express'] == '3' && $post['country'] == 35 && $post['zsbjz'] > 20)
  640. {
  641. echo json_encode(array('msg'=>'UPS加拿大最高申报不可超过20','success'=>false));exit;
  642. }
  643. if($post['express'] == '2' && $post['warehouse'] != 5)
  644. {
  645. echo json_encode(array('msg'=>'非美国仓无法选择USPS!','success'=>false));exit;
  646. }
  647. if($post['express'] == '99' && $post['bx'] > 0)
  648. {
  649. echo json_encode(array('msg'=>'此物流不允许购买保险','success'=>false));exit;
  650. }
  651. if($post['express'] == 42 && $post['sbpm'] != 'Human Hair Wigs' && $post['sbpm'] != 'Human Hair Goods')//$post['express'] == 3 ||
  652. {
  653. echo json_encode(array('msg'=>'此快递方式必须选择Human Hair Wigs/Human Hair Goods!','success'=>false));exit;
  654. }
  655. if($post['express'] == 24 && $post['sbpm'] != 'Hair Sample' && $post['sbpm'] != 'Human Hair Wigs' && $post['sbpm'] != 'Human Hair Goods')//$post['express'] == 3 ||
  656. {
  657. echo json_encode(array('msg'=>'此快递方式必须选择Hair Sample/Human Hair Wigs/Human Hair Goods!','success'=>false));exit;
  658. }
  659. if($post['country'] != 192 && $post['express'] == 1 && $post['sbpm'] != 'Synthetic Hair Wigs' && $post['sbpm'] != 'Synthetic Hair Goods')//$post['express'] == 3 ||
  660. {
  661. echo json_encode(array('msg'=>'非美国选择官方DHL必须选择Synthetic Hair Wigs/Synthetic Hair Goods','success'=>false));exit;
  662. }
  663. if(empty($post['paypal'])){
  664. echo json_encode(array('msg'=>'交易号必须填写','success'=>false));exit;
  665. }
  666. $express = $this->express->read($post['express']);
  667. if($post['zsbjz'] > $express['sbjz'])
  668. {
  669. echo json_encode(array('msg'=>'总申报价值不可超出'.$express['sbjz'],'success'=>false));exit;
  670. }
  671. if($post['shouldmoney'] > $express['shouldmoney'] && $express['shouldmoney'] != 0)
  672. {
  673. echo json_encode(array('msg'=>'订单金额不可超出'.$express['shouldmoney'],'success'=>false));exit;
  674. }
  675. if($express['ioss'] == 1 && $post['ioss'] == '')
  676. {
  677. echo json_encode(array('msg'=>'此快递方式必须选择IOSS!','success'=>false));exit;
  678. }
  679. if(strlen($post['address']) > $express['addresssize'] || strlen($post['address2']) > $express['addresssize'])
  680. {
  681. echo json_encode(array('msg'=>'此快递方地址不可超出'.$express['addresssize'].'个字符','success'=>false));exit;
  682. }
  683. if(strlen($post['address']) < 5)
  684. {
  685. echo json_encode(array('msg'=>'地址不可留空!','success'=>false));exit;
  686. }
  687. if($post['express'] == '2' && $post['zzl'] > '16' && $post['js'] == '0')
  688. {
  689. echo json_encode(array('msg'=>'重量大于16不可按Ground Advantage提交!','success'=>false));exit;
  690. }
  691. if($post['express'] == '2' && isset($post['js']) && $post['js'] == '0'&& $post['qm'] == '1')
  692. {
  693. echo json_encode(array('msg'=>'Ground Advantage不可使用签名服务!','success'=>false));exit;
  694. }
  695. if(($post['express'] == '3' || $post['express'] == '42' || $post['express'] == '24') && $post['shouldmoney'] < 1)
  696. {
  697. echo json_encode(array('msg'=>'零金额订单不可发 UPS/DHL官方-美国/Fedex(杭州)','success'=>false));exit;
  698. }
  699. if($post['express'] == '42' && $post['zsbjz'] < 1)
  700. {
  701. echo json_encode(array('msg'=>'零申报金额不可发 DHL官方-美国','success'=>false));exit;
  702. }
  703. if($post['express'] == '6' && $post['province'] == '')
  704. {
  705. echo json_encode(array('msg'=>'选择DPEX必须填写州信息','success'=>false));exit;
  706. }
  707. //仅独立站 地址美国对电话 10或者11位进行判断
  708. if($post['country'] == 192){
  709. if((strlen($post['phone'])!= 10) && (strlen($post['phone'])!= 11)){
  710. echo json_encode(array('msg'=>'美国电话号码应为10/11位!','success'=>false));exit;
  711. }
  712. }
  713. //减少代码复用吧
  714. $lo_ret = $this->logic_order->checkEditCustomer($post);
  715. if($lo_ret['code'] != 1){
  716. echo json_encode(array('msg'=>$lo_ret['msg'],'success'=>false));exit;
  717. }
  718. $dtctitle = array();
  719. $dictionaries = $this->typeclass->find_all();
  720. foreach ($dictionaries as $v)
  721. {
  722. $dtctitle[$v['id']] = array($v['title'],$v['bqsku']);
  723. }
  724. $fpdata = $post['fpdata'];
  725. if(stripos($fpdata,'-128-') !== false || stripos($fpdata,'-127-') !== false)
  726. {
  727. $dfp = explode(';',trim($fpdata,';'));
  728. $fdata = '';
  729. foreach ($dfp as $k=>$v)
  730. {
  731. $ptitleb = '';
  732. $fp = explode('|',trim($v,'|'));
  733. $fp0 = explode(',',$fp[0]);
  734. if(isset($fp0[1]))
  735. {
  736. $fp1 = explode('-',trim($fp0[1],'-'));
  737. }
  738. else
  739. {
  740. $fp1 = explode('-',trim($fp[0],'-'));
  741. }
  742. foreach ($fp1 as $vv)
  743. {
  744. $ptitleb .= isset($dtctitle[$vv])?$dtctitle[$vv][0].' ':'';
  745. }
  746. if(isset($fp0[1]))
  747. {
  748. $ptitleb .= $dtctitle[$fp0[0]][1].'inch ';
  749. $fp[1] = $ptitleb;
  750. }
  751. $fdata .= implode("|",$fp).";";
  752. }
  753. $fpdata = $fdata;
  754. }
  755. $warehouse = $this->warehouse->read($post['type']);
  756. if($warehouse['bdcountry'] != 0 && $post['country'] != $warehouse['bdcountry'])
  757. {
  758. echo json_encode(array('msg'=>'当前国家无法选择'.$warehouse['title'].'!','success'=>false));exit;
  759. }
  760. $kcyz = $this->ck->get_kc($post['state'],$warehouse,$post['shop'],$post['number'],$whlabel,$fpdata);
  761. if($kcyz['t'] > '0')
  762. {
  763. echo $kcyz['m'];exit;
  764. }
  765. else if($kcyz['fpdata'] != '')
  766. {
  767. $post['whlabel'] = $kcyz['whlabel'];
  768. $post['fpdata'] = $kcyz['fpdata'];
  769. }
  770. $fl = $this->ck->get_fl($warehouse['hz'],$whlabel,$fpdata);
  771. $post['sfxh'] = $fl['sfxh'];
  772. $post['ckfl'] = $fl['ckfl'];
  773. //查询净重开始
  774. $post['jweight'] = $this->weight->get_weightcx($post['fpdata']);
  775. //查询净重结束
  776. $cusnum = $this->customer->read($customerid);
  777. $this->customer->save(array('num'=>$cusnum['num']+1,'time'=>$post['buytime']),$customerid);
  778. unset($post['id']);
  779. $this->fullorder->insert($post);
  780. echo json_encode(array('msg'=>'下单成功','success'=>true));exit;
  781. }
  782. $id = $this->input->get('cid',true);
  783. $customer = $this->customer->read($id);
  784. $customer['express'] = 14;//默认顺丰
  785. // $customer = [
  786. // "shop"=>'28',
  787. // "source"=>10,
  788. // 'name'=>"何总客户",
  789. // 'province'=>'河南省',
  790. // 'city'=>"许昌市",
  791. // 'street'=>"",
  792. // 'zipcode'=>"461000",
  793. // 'al'=>"",
  794. // 'phone'=>"15393779998",
  795. // 'email'=>"hzkh@xcly.com",
  796. // 'country'=>"41",
  797. // "express"=>"14",
  798. // "address"=>"建安区英豪路与滨河路交叉路口往东约50米路北 龙盈实业(客户自提)",
  799. // ];
  800. $this->data['customer'] = $customer;
  801. $country = $this->country->find_all('1=1','id,name','name asc');//国家
  802. $this->data['country'] = $country;
  803. $express = $this->express->find_all();//物流商
  804. $this->data['express'] = $express;
  805. $bm = $this->country->read($customer['country']);
  806. $this->data['bm'] = $bm;
  807. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  808. $this->data['wlshop'] = $wlshop;
  809. $this->data['user'] = $u['userid'];
  810. $this->_Template('fullorderabf_yjtj',$this->data);
  811. }
  812. }