Fullorderabf.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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. }
  29. else
  30. {
  31. $this->_index();
  32. }
  33. }
  34. //管理
  35. public function _index()
  36. {
  37. exit('No direct script access allowed');
  38. }
  39. //一键添加订单
  40. private function _addOrder(){
  41. $user = $this->user->get_api($_SESSION['api']);
  42. if($user)
  43. {
  44. $uu = $user;
  45. $fgshop = "";$sid = "";
  46. $u = $user;
  47. $user = explode('|',trim($user['shop'],'|'));
  48. foreach ($user as $value)
  49. {
  50. $fgshop .= " shop = ".$value." or";
  51. $sid .= " id = ".$value." or";
  52. }
  53. }
  54. $post = $this->input->post(NULL, TRUE);
  55. if(isset($post['shop']))
  56. {
  57. $fpcount = $this->input->post('fpcount',true);
  58. if(!$fpcount)
  59. {
  60. echo json_encode(array('msg'=>'需要先清理浏览器缓存,刷新当前页面后再试!','success'=>false));exit;
  61. }
  62. $customerid = $this->input->post('customerid',true);
  63. if(empty($customerid)){
  64. $tmp_email = $this->input->post('email',true);
  65. $tmp_shop = $this->input->post('shop',true);
  66. $customer = $this->customer->get_email($tmp_email,$tmp_shop);
  67. }else{
  68. $customer = $this->customer->read($customerid);
  69. }
  70. if(empty($customer)){
  71. $str = $post['phone'];
  72. preg_match_all('/[0-9]/u',$str,$result);
  73. $numphone = join('',$result[0]);
  74. $ct['shop'] = $post['shop'];
  75. $ct['source'] = 10;
  76. $ct['level'] = 5;
  77. $ct['country'] = $post['country'];
  78. $ct['time'] = time();
  79. $ct['num'] = 1;
  80. $ct['money'] = $post['shouldmoney'];
  81. $ct['zipcode'] = $post['zipcode'];
  82. $ct['name'] = $post['name'];
  83. $ct['phone'] = $post['phone'];
  84. $ct['numphone'] = $numphone;
  85. $ct['email'] = preg_replace('/( | | |\s)+/','',$post['email']);
  86. $ct['province'] = $post['province'];
  87. $ct['city'] = $post['city'];
  88. $ct['address'] = $post['address'];
  89. $ct['zhcx'] = $post['shop'].'-'.$ct['email'];
  90. $ct['is_tb'] = 0;
  91. $this->customer->insert($ct);
  92. $tmp_email = $this->input->post('email',true);
  93. $tmp_shop = $this->input->post('shop',true);
  94. $customer = $this->customer->get_email($tmp_email,$tmp_shop);
  95. $customerid = $customer['id'];
  96. }else{
  97. $customerid = $customer['id'];
  98. }
  99. if(empty($customerid)){
  100. echo json_encode(array('msg'=>'客户信息异常!','success'=>false));exit;
  101. }
  102. $shop = $this->input->post('shop',true);
  103. $sp = $this->shop->read($shop);
  104. $num = $this->fullorder->find_count('shop = "'.$sp['id'].'" and gtime = "'.date('Ymd',time()).'"');
  105. $post['source'] = 1;//订单类型:1.线下订单2.PC3.手机
  106. $post['state'] = 207;//订单状态:207等待发货
  107. $post['review'] = 2;//审核状态:1.未送审2.待审核3.不通过4取消重审5.审核通过6.自动通过
  108. $post['print'] = 1;//打印状态:1.不可打印2.未打印3.已打印
  109. $post['library'] = 1;//出库状态:1.未出库2.已出库3.已退库
  110. $post['libraryconfirm'] = 1;//出库确认:1.不允许2.允许
  111. $post['link'] = $sp['link'];
  112. $post['issku'] = $sp['sku'];
  113. if($post['print'] != 3)
  114. {
  115. $post['librarynot'] = "订单未打印,未审核或未通过";//不能出库原因
  116. }
  117. $orderinfo = $this->input->post('orderinfo',true);
  118. $post['shop'] = $sp['id'];
  119. $post['user'] = $sp['shopuser'];
  120. $post['number'] = $sp['shortname'].'-'.date('ymd',time()).'-'.(substr(strval($num+1+1000),1,3));//编号
  121. if($orderinfo != "")
  122. {
  123. $ordefin = $this->fullorder->get_orderinfo($orderinfo);
  124. if($ordefin)
  125. {
  126. echo json_encode(array('msg'=>'订单号重复!','success'=>false));exit;
  127. }
  128. else
  129. {
  130. $post['orderinfo'] = $orderinfo;
  131. }
  132. }
  133. else
  134. {
  135. $post['orderinfo'] = $sp['id'].date('ymdHis',time()).rand(0,1);//订单号
  136. }
  137. if($post['paypal'] != '')
  138. {
  139. $pp = $this->fullorder->get_paypal($post['paypal']);
  140. if($pp)
  141. {
  142. echo json_encode(array('msg'=>'此交易号的订单已存在!','success'=>false));exit;
  143. }
  144. }
  145. $post['client'] = $this->input->post('client',true);//客户名称
  146. $btime = $this->input->post('buytime',true);//付款时间
  147. $post['buytime'] = strtotime($btime);//时间转UX
  148. $post['dtime'] = time();//订单时间
  149. $post['gtime'] = date('Ymd',time());//格式化时间
  150. $post['pay'] = $this->input->post('pay',true);//支付方式
  151. $post['capital'] = $this->input->post('capital',true);//资金状态
  152. $post['type'] = $this->input->post('warehouse',true);//发货仓库
  153. $post['currency'] = $this->input->post('currency',true);//币种
  154. $currency = $this->typeclass->read($post['currency']);
  155. $post['currencytitle'] = $currency['title'];//币种名称
  156. $post['freight'] = $this->input->post('freight',true);//运费
  157. $post['expressmoney'] = $this->input->post('expressmoney',true);//物流金额
  158. $post['shouldmoney'] = $this->input->post('shouldmoney',true);//应收金额
  159. $post['shouldmoney'] = (float)$post['shouldmoney'];
  160. $post['skje'] = $post['shouldmoney'];//收款金额
  161. $product = $this->input->post('product');//产品名称
  162. $product = str_replace(array('%26','%2B'),array('&','+'),$product);
  163. $post['product'] = preg_replace('/( | | |\s)/',' ',$product);
  164. $orderremarks = $this->input->post('orderremarks');//订单备注
  165. $orderremarks = str_replace(array('%26','%2B'),array('&','+'),$orderremarks);
  166. $post['orderremarks'] = preg_replace('/( | | |\s)/',' ',$orderremarks);
  167. $shipremarks = $this->input->post('shipremarks');//仓库品名
  168. $shipremarks = str_replace(array('%26','%2B'),array('&','+'),$shipremarks);//仓库品名
  169. $post['shipremarks'] = preg_replace('/( | | |\s)/',' ',$shipremarks);
  170. $post['email'] = $this->input->post('email',true);//邮箱
  171. $name = $this->input->post('name',true);//名称
  172. $post['name'] = preg_replace('/( | | |\s)/',' ',$name);
  173. $post['phone'] = $this->input->post('phone',true);//电话
  174. $post['phone'] = preg_replace('/\D/s','',$post['phone']);
  175. $post['country'] = $this->input->post('country',true);//国家
  176. $ct = $this->country->read($post['country']);//国家
  177. $post['al'] = $ct['lb'];//国家二字码
  178. $post['province'] = $this->input->post('province',true);//省、州
  179. $post['province'] = preg_replace("/^[\s\v".chr(227).chr(128)."]+/","", $post['province']); //替换开头空字符
  180. $post['province'] = preg_replace("/[\s\v".chr(227).chr(128)."]+$/","", $post['province']); //替换结尾空字符
  181. $post['city'] = $this->input->post('city',true);//城市
  182. $post['city'] = preg_replace("/^[\s\v".chr(227).chr(128)."]+/","", $post['city']); //替换开头空字符
  183. $post['city'] = preg_replace("/[\s\v".chr(227).chr(128)."]+$/","", $post['city']); //替换结尾空字符
  184. $post['zipcode'] = $this->input->post('zipcode',true);//邮编
  185. $post['zipcode'] = preg_replace("/^[\s\v".chr(227).chr(128)."]+/","", $post['zipcode']); //替换开头空字符
  186. $post['zipcode'] = preg_replace("/[\s\v".chr(227).chr(128)."]+$/","", $post['zipcode']); //替换结尾空字符
  187. $post['address'] = $this->input->post('address',true);//地址
  188. $post['printtype'] = $this->input->post('printtype',true);//打印类型
  189. $fpdata = $this->input->post('fpdata');//购买产品内容
  190. $fpdata = str_replace(array('%26','%2B'),array('&','+'),$fpdata);
  191. $post['fpdata'] = $fpdata;
  192. $post['sbpm'] = $this->input->post('sbpm',true);//申报品名
  193. $post['zwpm'] = $this->input->post('zwpm',true);//中文品名
  194. $post['ts'] = $this->input->post('ts',true);//条数
  195. $post['dtsbjz'] = $this->input->post('dtsbjz',true);//单条申报价
  196. $post['zsbjz'] = $this->input->post('zsbjz',true);//总申报价
  197. $post['zzl'] = $this->input->post('zzl',true);//总重量
  198. $post['zjs'] = $this->input->post('zjs',true);//总件数
  199. $post['express'] = $this->input->post('express',true);//快递公司
  200. $post['printtype'] = $this->input->post('printtype',true);//打印类型
  201. $post['quantity'] = $this->input->post('quantity',true);//数量
  202. $post['paypal'] = $post['orderinfo'];//支付号
  203. $post['guarantee'] = $this->input->post('guarantee',true);//卖家保障
  204. $post['msg'] = $this->input->post('msg',true);//发送留言类型
  205. $post['ioss'] = $this->input->post('ioss',true);
  206. $post['sbpm'] = $this->input->post('sbpm',true);
  207. $post['merge'] = $post['mergeid'] = 0;
  208. $pay = $this->pay->get_typeclass($post['pay']);
  209. $yga = $post['shouldmoney'];
  210. $post['budget'] = 0;
  211. $post['estimaterate'] = 1;
  212. $post['budget'] = $post['shouldmoney'];
  213. $baddress = $this->input->post('baddress',true);
  214. $saddress = $this->input->post('saddress',true);
  215. $baddress = array_reverse(explode(',',$baddress));
  216. $saddress = array_reverse(explode(',',$saddress));
  217. $bar = '';$sar = '';
  218. $cr = $this->country->read($post['country']);
  219. $baddress[1] = $cr['lb'];
  220. $saddress[1] = $cr['lb'];
  221. $baddress = array_reverse($baddress);
  222. $saddress = array_reverse($saddress);
  223. for($i=0;$i<count($baddress);$i++)
  224. {
  225. $bar .= $baddress[$i].',';
  226. }
  227. for($i=0;$i<count($saddress);$i++)
  228. {
  229. $sar .= $saddress[$i].',';
  230. }
  231. if(empty($post['ts'])){
  232. echo json_encode(array('msg'=>'申报条数不能为空!','success'=>false));exit;
  233. }
  234. $post['baddress'] = rtrim($bar,',');//卖家保障
  235. $post['saddress'] = rtrim($sar,',');//卖家保障
  236. $whlabel = $this->input->post('whlabel',true);
  237. if($post['express'] == 2 && (stripos($post['name'],'&') !== false || stripos($post['name'],"'") !== false))
  238. {
  239. echo json_encode(array('msg'=>'USPS收件人或公司名不可用特殊符号!','success'=>false));exit;
  240. }
  241. if(strlen($post['client']) > 35 || strlen($post['name']) > 35)//收件人姓名或公司名不允许超过35位
  242. {
  243. echo json_encode(array('msg'=>'收件人姓名或公司名不可超过35个字符!','success'=>false));exit;
  244. }
  245. if(($post['express'] == '5' || $post['express'] == '24' || $post['express'] == '42' || $post['express'] == '31') && $post['country'] != 192)
  246. {
  247. echo json_encode(array('msg'=>'非美国无法选择Fedex、DHL官方-美国!','success'=>false));exit;
  248. }
  249. if($post['express'] == '3' && $post['country'] != 192 && $post['country'] != 35)
  250. {
  251. echo json_encode(array('msg'=>'非美国和加拿大无法选择UPS!','success'=>false));exit;
  252. }
  253. if($post['express'] == '3' && $post['country'] == 35 && $post['zsbjz'] > 20)
  254. {
  255. echo json_encode(array('msg'=>'UPS加拿大最高申报不可超过20','success'=>false));exit;
  256. }
  257. if($post['express'] == '2' && $post['warehouse'] != 5)
  258. {
  259. echo json_encode(array('msg'=>'非美国仓无法选择USPS!','success'=>false));exit;
  260. }
  261. if($post['express'] == '99' && $post['bx'] > 0)
  262. {
  263. echo json_encode(array('msg'=>'此物流不允许购买保险','success'=>false));exit;
  264. }
  265. if($post['express'] == 42 && $post['sbpm'] != 'Human Hair Wigs' && $post['sbpm'] != 'Human Hair Goods')//$post['express'] == 3 ||
  266. {
  267. echo json_encode(array('msg'=>'此快递方式必须选择Human Hair Wigs/Human Hair Goods!','success'=>false));exit;
  268. }
  269. if($post['express'] == 24 && $post['sbpm'] != 'Hair Sample' && $post['sbpm'] != 'Human Hair Wigs' && $post['sbpm'] != 'Human Hair Goods')//$post['express'] == 3 ||
  270. {
  271. echo json_encode(array('msg'=>'此快递方式必须选择Hair Sample/Human Hair Wigs/Human Hair Goods!','success'=>false));exit;
  272. }
  273. if($post['country'] != 192 && $post['express'] == 1 && $post['sbpm'] != 'Synthetic Hair Wigs' && $post['sbpm'] != 'Synthetic Hair Goods')//$post['express'] == 3 ||
  274. {
  275. echo json_encode(array('msg'=>'非美国选择官方DHL必须选择Synthetic Hair Wigs/Synthetic Hair Goods','success'=>false));exit;
  276. }
  277. if(empty($post['paypal'])){
  278. echo json_encode(array('msg'=>'交易号必须填写','success'=>false));exit;
  279. }
  280. $express = $this->express->read($post['express']);
  281. if($post['zsbjz'] > $express['sbjz'])
  282. {
  283. echo json_encode(array('msg'=>'总申报价值不可超出'.$express['sbjz'],'success'=>false));exit;
  284. }
  285. if($post['shouldmoney'] > $express['shouldmoney'] && $express['shouldmoney'] != 0)
  286. {
  287. echo json_encode(array('msg'=>'订单金额不可超出'.$express['shouldmoney'],'success'=>false));exit;
  288. }
  289. if($express['ioss'] == 1 && $post['ioss'] == '')
  290. {
  291. echo json_encode(array('msg'=>'此快递方式必须选择IOSS!','success'=>false));exit;
  292. }
  293. if(strlen($post['address']) > $express['addresssize'] || strlen($post['address2']) > $express['addresssize'])
  294. {
  295. echo json_encode(array('msg'=>'此快递方地址不可超出'.$express['addresssize'].'个字符','success'=>false));exit;
  296. }
  297. if(strlen($post['address']) < 5)
  298. {
  299. echo json_encode(array('msg'=>'地址不可留空!','success'=>false));exit;
  300. }
  301. if($post['express'] == '2' && $post['zzl'] > '16' && $post['js'] == '0')
  302. {
  303. echo json_encode(array('msg'=>'重量大于16不可按Ground Advantage提交!','success'=>false));exit;
  304. }
  305. if($post['express'] == '2' && isset($post['js']) && $post['js'] == '0'&& $post['qm'] == '1')
  306. {
  307. echo json_encode(array('msg'=>'Ground Advantage不可使用签名服务!','success'=>false));exit;
  308. }
  309. if(($post['express'] == '3' || $post['express'] == '42' || $post['express'] == '24') && $post['shouldmoney'] < 1)
  310. {
  311. echo json_encode(array('msg'=>'零金额订单不可发 UPS/DHL官方-美国/Fedex(杭州)','success'=>false));exit;
  312. }
  313. if($post['express'] == '42' && $post['zsbjz'] < 1)
  314. {
  315. echo json_encode(array('msg'=>'零申报金额不可发 DHL官方-美国','success'=>false));exit;
  316. }
  317. if($post['express'] == '6' && $post['province'] == '')
  318. {
  319. echo json_encode(array('msg'=>'选择DPEX必须填写州信息','success'=>false));exit;
  320. }
  321. //仅独立站 地址美国对电话 10或者11位进行判断
  322. if($post['country'] == 192){
  323. if((strlen($post['phone'])!= 10) && (strlen($post['phone'])!= 11)){
  324. echo json_encode(array('msg'=>'美国电话号码应为10/11位!','success'=>false));exit;
  325. }
  326. }
  327. //减少代码复用吧
  328. $lo_ret = $this->logic_order->checkEditCustomer($post);
  329. if($lo_ret['code'] != 1){
  330. echo json_encode(array('msg'=>$lo_ret['msg'],'success'=>false));exit;
  331. }
  332. $dtctitle = array();
  333. $dictionaries = $this->typeclass->find_all();
  334. foreach ($dictionaries as $v)
  335. {
  336. $dtctitle[$v['id']] = array($v['title'],$v['bqsku']);
  337. }
  338. $fpdata = $post['fpdata'];
  339. if(stripos($fpdata,'-128-') !== false || stripos($fpdata,'-127-') !== false)
  340. {
  341. $dfp = explode(';',trim($fpdata,';'));
  342. $fdata = '';
  343. foreach ($dfp as $k=>$v)
  344. {
  345. $ptitleb = '';
  346. $fp = explode('|',trim($v,'|'));
  347. $fp0 = explode(',',$fp[0]);
  348. if(isset($fp0[1]))
  349. {
  350. $fp1 = explode('-',trim($fp0[1],'-'));
  351. }
  352. else
  353. {
  354. $fp1 = explode('-',trim($fp[0],'-'));
  355. }
  356. foreach ($fp1 as $vv)
  357. {
  358. $ptitleb .= isset($dtctitle[$vv])?$dtctitle[$vv][0].' ':'';
  359. }
  360. if(isset($fp0[1]))
  361. {
  362. $ptitleb .= $dtctitle[$fp0[0]][1].'inch ';
  363. $fp[1] = $ptitleb;
  364. }
  365. $fdata .= implode("|",$fp).";";
  366. }
  367. $fpdata = $fdata;
  368. }
  369. $warehouse = $this->warehouse->read($post['type']);
  370. if($warehouse['bdcountry'] != 0 && $post['country'] != $warehouse['bdcountry'])
  371. {
  372. echo json_encode(array('msg'=>'当前国家无法选择'.$warehouse['title'].'!','success'=>false));exit;
  373. }
  374. $kcyz = $this->ck->get_kc($post['state'],$warehouse,$post['shop'],$post['number'],$whlabel,$fpdata);
  375. if($kcyz['t'] > '0')
  376. {
  377. echo $kcyz['m'];exit;
  378. }
  379. else if($kcyz['fpdata'] != '')
  380. {
  381. $post['whlabel'] = $kcyz['whlabel'];
  382. $post['fpdata'] = $kcyz['fpdata'];
  383. }
  384. $fl = $this->ck->get_fl($warehouse['hz'],$whlabel,$fpdata);
  385. $post['sfxh'] = $fl['sfxh'];
  386. $post['ckfl'] = $fl['ckfl'];
  387. //查询净重开始
  388. $post['jweight'] = $this->weight->get_weightcx($post['fpdata']);
  389. //查询净重结束
  390. $cusnum = $this->customer->read($customerid);
  391. $this->customer->save(array('num'=>$cusnum['num']+1,'time'=>$post['buytime']),$customerid);
  392. unset($post['id']);
  393. $this->fullorder->insert($post);
  394. echo json_encode(array('msg'=>'下单成功','success'=>true));exit;
  395. }
  396. $customer = [
  397. "shop"=>'28',
  398. "source"=>10,
  399. 'name'=>"何总客户",
  400. 'province'=>'河南省',
  401. 'city'=>"许昌市",
  402. 'street'=>"",
  403. 'zipcode'=>"461000",
  404. 'al'=>"",
  405. 'phone'=>"15393779998",
  406. 'email'=>"hzkh@xcly.com",
  407. 'country'=>"41",
  408. "express"=>"14",
  409. "address"=>"建安区英豪路与滨河路交叉路口往东约50米路北 龙盈实业(客户自提)",
  410. ];
  411. $this->data['customer'] = $customer;
  412. $country = $this->country->find_all('1=1','id,name','name asc');//国家
  413. $this->data['country'] = $country;
  414. $express = $this->express->find_all();//物流商
  415. $this->data['express'] = $express;
  416. $bm = $this->country->read($customer['country']);
  417. $this->data['bm'] = $bm;
  418. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  419. $this->data['wlshop'] = $wlshop;
  420. $this->data['user'] = $u['userid'];
  421. $this->_Template('fullorderabf_yjtj',$this->data);
  422. }
  423. }