Fullorderabf.php 17 KB

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