Fullorderabf.php 37 KB

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