load->_model('Model_user','user'); $this->load->_model('Model_fullorder','fullorder'); $this->load->_model('Model_shop','shop'); $this->load->_model('Model_express','express'); $this->load->_model('Model_country','country'); $this->load->_model('Model_typeclass','typeclass'); $this->load->_model('Model_pay','pay'); $this->load->_model('Model_logic_order','logic_order'); $this->load->_model('Model_warehouse','warehouse'); $this->load->_model('Model_ck','ck'); $this->load->_model('Model_specialstock','specialstock'); $this->load->_model('Model_whlabel','whlabel'); $this->load->_model('Model_customer','customer'); } //定义方法的调用规则 获取URI第二段值 public function _remap($arg,$arg_array) { if($arg == 'yjtj')//一件添加订单 { $this->_addOrder(); } else { $this->_index(); } } //管理 public function _index() { exit('No direct script access allowed'); } //一键添加订单 private function _addOrder(){ $user = $this->user->get_api($_SESSION['api']); if($user) { $uu = $user; $fgshop = "";$sid = ""; $u = $user; $user = explode('|',trim($user['shop'],'|')); foreach ($user as $value) { $fgshop .= " shop = ".$value." or"; $sid .= " id = ".$value." or"; } } $post = $this->input->post(NULL, TRUE); if(isset($post['shop'])) { $fpcount = $this->input->post('fpcount',true); if(!$fpcount) { echo json_encode(array('msg'=>'需要先清理浏览器缓存,刷新当前页面后再试!','success'=>false));exit; } $customerid = $this->input->post('customerid',true); if(empty($customerid)){ $tmp_email = $this->input->post('email',true); $tmp_shop = $this->input->post('shop',true); $customer = $this->customer->get_email($tmp_email,$tmp_shop); }else{ $customer = $this->customer->read($customerid); } if(empty($customer)){ $str = $post['phone']; preg_match_all('/[0-9]/u',$str,$result); $numphone = join('',$result[0]); $ct['shop'] = $post['shop']; $ct['source'] = 10; $ct['level'] = 5; $ct['country'] = $post['country']; $ct['time'] = time(); $ct['num'] = 1; $ct['money'] = $post['shouldmoney']; $ct['zipcode'] = $post['zipcode']; $ct['name'] = $post['name']; $ct['phone'] = $post['phone']; $ct['numphone'] = $numphone; $ct['email'] = preg_replace('/( | | |\s)+/','',$post['email']); $ct['province'] = $post['province']; $ct['city'] = $post['city']; $ct['address'] = $post['address']; $ct['zhcx'] = $post['shop'].'-'.$ct['email']; $ct['is_tb'] = 0; $this->customer->insert($ct); $tmp_email = $this->input->post('email',true); $tmp_shop = $this->input->post('shop',true); $customer = $this->customer->get_email($tmp_email,$tmp_shop); $customerid = $customer['id']; }else{ $customerid = $customer['id']; } if(empty($customerid)){ echo json_encode(array('msg'=>'客户信息异常!','success'=>false));exit; } $shop = $this->input->post('shop',true); $sp = $this->shop->read($shop); $num = $this->fullorder->find_count('shop = "'.$sp['id'].'" and gtime = "'.date('Ymd',time()).'"'); $post['source'] = 1;//订单类型:1.线下订单2.PC3.手机 $post['state'] = 207;//订单状态:207等待发货 $post['review'] = 2;//审核状态:1.未送审2.待审核3.不通过4取消重审5.审核通过6.自动通过 $post['print'] = 1;//打印状态:1.不可打印2.未打印3.已打印 $post['library'] = 1;//出库状态:1.未出库2.已出库3.已退库 $post['libraryconfirm'] = 1;//出库确认:1.不允许2.允许 $post['link'] = $sp['link']; $post['issku'] = $sp['sku']; if($post['print'] != 3) { $post['librarynot'] = "订单未打印,未审核或未通过";//不能出库原因 } $orderinfo = $this->input->post('orderinfo',true); $post['shop'] = $sp['id']; $post['user'] = $sp['shopuser']; $post['number'] = $sp['shortname'].'-'.date('ymd',time()).'-'.(substr(strval($num+1+1000),1,3));//编号 if($orderinfo != "") { $ordefin = $this->fullorder->get_orderinfo($orderinfo); if($ordefin) { echo json_encode(array('msg'=>'订单号重复!','success'=>false));exit; } else { $post['orderinfo'] = $orderinfo; } } else { $post['orderinfo'] = $sp['id'].date('ymdHis',time()).rand(0,1);//订单号 } if($post['paypal'] != '') { $pp = $this->fullorder->get_paypal($post['paypal']); if($pp) { echo json_encode(array('msg'=>'此交易号的订单已存在!','success'=>false));exit; } } $post['client'] = $this->input->post('client',true);//客户名称 $btime = $this->input->post('buytime',true);//付款时间 $post['buytime'] = strtotime($btime);//时间转UX $post['dtime'] = time();//订单时间 $post['gtime'] = date('Ymd',time());//格式化时间 $post['pay'] = $this->input->post('pay',true);//支付方式 $post['capital'] = $this->input->post('capital',true);//资金状态 $post['type'] = $this->input->post('warehouse',true);//发货仓库 $post['currency'] = $this->input->post('currency',true);//币种 $currency = $this->typeclass->read($post['currency']); $post['currencytitle'] = $currency['title'];//币种名称 $post['freight'] = $this->input->post('freight',true);//运费 $post['expressmoney'] = $this->input->post('expressmoney',true);//物流金额 $post['shouldmoney'] = $this->input->post('shouldmoney',true);//应收金额 $post['shouldmoney'] = (float)$post['shouldmoney']; $post['skje'] = $post['shouldmoney'];//收款金额 $product = $this->input->post('product');//产品名称 $product = str_replace(array('%26','%2B'),array('&','+'),$product); $post['product'] = preg_replace('/( | | |\s)/',' ',$product); $orderremarks = $this->input->post('orderremarks');//订单备注 $orderremarks = str_replace(array('%26','%2B'),array('&','+'),$orderremarks); $post['orderremarks'] = preg_replace('/( | | |\s)/',' ',$orderremarks); $shipremarks = $this->input->post('shipremarks');//仓库品名 $shipremarks = str_replace(array('%26','%2B'),array('&','+'),$shipremarks);//仓库品名 $post['shipremarks'] = preg_replace('/( | | |\s)/',' ',$shipremarks); $post['email'] = $this->input->post('email',true);//邮箱 $name = $this->input->post('name',true);//名称 $post['name'] = preg_replace('/( | | |\s)/',' ',$name); $post['phone'] = $this->input->post('phone',true);//电话 $post['phone'] = preg_replace('/\D/s','',$post['phone']); $post['country'] = $this->input->post('country',true);//国家 $ct = $this->country->read($post['country']);//国家 $post['al'] = $ct['lb'];//国家二字码 $post['province'] = $this->input->post('province',true);//省、州 $post['province'] = preg_replace("/^[\s\v".chr(227).chr(128)."]+/","", $post['province']); //替换开头空字符 $post['province'] = preg_replace("/[\s\v".chr(227).chr(128)."]+$/","", $post['province']); //替换结尾空字符 $post['city'] = $this->input->post('city',true);//城市 $post['city'] = preg_replace("/^[\s\v".chr(227).chr(128)."]+/","", $post['city']); //替换开头空字符 $post['city'] = preg_replace("/[\s\v".chr(227).chr(128)."]+$/","", $post['city']); //替换结尾空字符 $post['zipcode'] = $this->input->post('zipcode',true);//邮编 $post['zipcode'] = preg_replace("/^[\s\v".chr(227).chr(128)."]+/","", $post['zipcode']); //替换开头空字符 $post['zipcode'] = preg_replace("/[\s\v".chr(227).chr(128)."]+$/","", $post['zipcode']); //替换结尾空字符 $post['address'] = $this->input->post('address',true);//地址 $post['printtype'] = $this->input->post('printtype',true);//打印类型 $fpdata = $this->input->post('fpdata');//购买产品内容 $fpdata = str_replace(array('%26','%2B'),array('&','+'),$fpdata); $post['fpdata'] = $fpdata; $post['sbpm'] = $this->input->post('sbpm',true);//申报品名 $post['zwpm'] = $this->input->post('zwpm',true);//中文品名 $post['ts'] = $this->input->post('ts',true);//条数 $post['dtsbjz'] = $this->input->post('dtsbjz',true);//单条申报价 $post['zsbjz'] = $this->input->post('zsbjz',true);//总申报价 $post['zzl'] = $this->input->post('zzl',true);//总重量 $post['zjs'] = $this->input->post('zjs',true);//总件数 $post['express'] = $this->input->post('express',true);//快递公司 $post['printtype'] = $this->input->post('printtype',true);//打印类型 $post['quantity'] = $this->input->post('quantity',true);//数量 $post['paypal'] = $post['orderinfo'];//支付号 $post['guarantee'] = $this->input->post('guarantee',true);//卖家保障 $post['msg'] = $this->input->post('msg',true);//发送留言类型 $post['ioss'] = $this->input->post('ioss',true); $post['sbpm'] = $this->input->post('sbpm',true); $post['merge'] = $post['mergeid'] = 0; $pay = $this->pay->get_typeclass($post['pay']); $yga = $post['shouldmoney']; $post['budget'] = 0; $post['estimaterate'] = 1; $post['budget'] = $post['shouldmoney']; $baddress = $this->input->post('baddress',true); $saddress = $this->input->post('saddress',true); $baddress = array_reverse(explode(',',$baddress)); $saddress = array_reverse(explode(',',$saddress)); $bar = '';$sar = ''; $cr = $this->country->read($post['country']); $baddress[1] = $cr['lb']; $saddress[1] = $cr['lb']; $baddress = array_reverse($baddress); $saddress = array_reverse($saddress); for($i=0;$i'申报条数不能为空!','success'=>false));exit; } $post['baddress'] = rtrim($bar,',');//卖家保障 $post['saddress'] = rtrim($sar,',');//卖家保障 $whlabel = $this->input->post('whlabel',true); if($post['express'] == 2 && (stripos($post['name'],'&') !== false || stripos($post['name'],"'") !== false)) { echo json_encode(array('msg'=>'USPS收件人或公司名不可用特殊符号!','success'=>false));exit; } if(strlen($post['client']) > 35 || strlen($post['name']) > 35)//收件人姓名或公司名不允许超过35位 { echo json_encode(array('msg'=>'收件人姓名或公司名不可超过35个字符!','success'=>false));exit; } if(($post['express'] == '5' || $post['express'] == '24' || $post['express'] == '42' || $post['express'] == '31') && $post['country'] != 192) { echo json_encode(array('msg'=>'非美国无法选择Fedex、DHL官方-美国!','success'=>false));exit; } if($post['express'] == '3' && $post['country'] != 192 && $post['country'] != 35) { echo json_encode(array('msg'=>'非美国和加拿大无法选择UPS!','success'=>false));exit; } if($post['express'] == '3' && $post['country'] == 35 && $post['zsbjz'] > 20) { echo json_encode(array('msg'=>'UPS加拿大最高申报不可超过20','success'=>false));exit; } if($post['express'] == '2' && $post['warehouse'] != 5) { echo json_encode(array('msg'=>'非美国仓无法选择USPS!','success'=>false));exit; } if($post['express'] == '99' && $post['bx'] > 0) { echo json_encode(array('msg'=>'此物流不允许购买保险','success'=>false));exit; } if($post['express'] == 42 && $post['sbpm'] != 'Human Hair Wigs' && $post['sbpm'] != 'Human Hair Goods')//$post['express'] == 3 || { echo json_encode(array('msg'=>'此快递方式必须选择Human Hair Wigs/Human Hair Goods!','success'=>false));exit; } if($post['express'] == 24 && $post['sbpm'] != 'Hair Sample' && $post['sbpm'] != 'Human Hair Wigs' && $post['sbpm'] != 'Human Hair Goods')//$post['express'] == 3 || { echo json_encode(array('msg'=>'此快递方式必须选择Hair Sample/Human Hair Wigs/Human Hair Goods!','success'=>false));exit; } if($post['country'] != 192 && $post['express'] == 1 && $post['sbpm'] != 'Synthetic Hair Wigs' && $post['sbpm'] != 'Synthetic Hair Goods')//$post['express'] == 3 || { echo json_encode(array('msg'=>'非美国选择官方DHL必须选择Synthetic Hair Wigs/Synthetic Hair Goods','success'=>false));exit; } if(empty($post['paypal'])){ echo json_encode(array('msg'=>'交易号必须填写','success'=>false));exit; } $express = $this->express->read($post['express']); if($post['zsbjz'] > $express['sbjz']) { echo json_encode(array('msg'=>'总申报价值不可超出'.$express['sbjz'],'success'=>false));exit; } if($post['shouldmoney'] > $express['shouldmoney'] && $express['shouldmoney'] != 0) { echo json_encode(array('msg'=>'订单金额不可超出'.$express['shouldmoney'],'success'=>false));exit; } if($express['ioss'] == 1 && $post['ioss'] == '') { echo json_encode(array('msg'=>'此快递方式必须选择IOSS!','success'=>false));exit; } if(strlen($post['address']) > $express['addresssize'] || strlen($post['address2']) > $express['addresssize']) { echo json_encode(array('msg'=>'此快递方地址不可超出'.$express['addresssize'].'个字符','success'=>false));exit; } if(strlen($post['address']) < 5) { echo json_encode(array('msg'=>'地址不可留空!','success'=>false));exit; } if($post['express'] == '2' && $post['zzl'] > '16' && $post['js'] == '0') { echo json_encode(array('msg'=>'重量大于16不可按Ground Advantage提交!','success'=>false));exit; } if($post['express'] == '2' && isset($post['js']) && $post['js'] == '0'&& $post['qm'] == '1') { echo json_encode(array('msg'=>'Ground Advantage不可使用签名服务!','success'=>false));exit; } if(($post['express'] == '3' || $post['express'] == '42' || $post['express'] == '24') && $post['shouldmoney'] < 1) { echo json_encode(array('msg'=>'零金额订单不可发 UPS/DHL官方-美国/Fedex(杭州)','success'=>false));exit; } if($post['express'] == '42' && $post['zsbjz'] < 1) { echo json_encode(array('msg'=>'零申报金额不可发 DHL官方-美国','success'=>false));exit; } if($post['express'] == '6' && $post['province'] == '') { echo json_encode(array('msg'=>'选择DPEX必须填写州信息','success'=>false));exit; } //仅独立站 地址美国对电话 10或者11位进行判断 if($post['country'] == 192){ if((strlen($post['phone'])!= 10) && (strlen($post['phone'])!= 11)){ echo json_encode(array('msg'=>'美国电话号码应为10/11位!','success'=>false));exit; } } //减少代码复用吧 $lo_ret = $this->logic_order->checkEditCustomer($post); if($lo_ret['code'] != 1){ echo json_encode(array('msg'=>$lo_ret['msg'],'success'=>false));exit; } $dtctitle = array(); $dictionaries = $this->typeclass->find_all(); foreach ($dictionaries as $v) { $dtctitle[$v['id']] = array($v['title'],$v['bqsku']); } $fpdata = $post['fpdata']; if(stripos($fpdata,'-128-') !== false || stripos($fpdata,'-127-') !== false) { $dfp = explode(';',trim($fpdata,';')); $fdata = ''; foreach ($dfp as $k=>$v) { $ptitleb = ''; $fp = explode('|',trim($v,'|')); $fp0 = explode(',',$fp[0]); if(isset($fp0[1])) { $fp1 = explode('-',trim($fp0[1],'-')); } else { $fp1 = explode('-',trim($fp[0],'-')); } foreach ($fp1 as $vv) { $ptitleb .= isset($dtctitle[$vv])?$dtctitle[$vv][0].' ':''; } if(isset($fp0[1])) { $ptitleb .= $dtctitle[$fp0[0]][1].'inch '; $fp[1] = $ptitleb; } $fdata .= implode("|",$fp).";"; } $fpdata = $fdata; } $warehouse = $this->warehouse->read($post['type']); if($warehouse['bdcountry'] != 0 && $post['country'] != $warehouse['bdcountry']) { echo json_encode(array('msg'=>'当前国家无法选择'.$warehouse['title'].'!','success'=>false));exit; } $kcyz = $this->ck->get_kc($post['state'],$warehouse,$post['shop'],$post['number'],$whlabel,$fpdata); if($kcyz['t'] > '0') { echo $kcyz['m'];exit; } else if($kcyz['fpdata'] != '') { $post['whlabel'] = $kcyz['whlabel']; $post['fpdata'] = $kcyz['fpdata']; } $fl = $this->ck->get_fl($warehouse['hz'],$whlabel,$fpdata); $post['sfxh'] = $fl['sfxh']; $post['ckfl'] = $fl['ckfl']; //查询净重开始 $post['jweight'] = $this->weight->get_weightcx($post['fpdata']); //查询净重结束 $cusnum = $this->customer->read($customerid); $this->customer->save(array('num'=>$cusnum['num']+1,'time'=>$post['buytime']),$customerid); unset($post['id']); $this->fullorder->insert($post); echo json_encode(array('msg'=>'下单成功','success'=>true));exit; } $customer = [ "shop"=>'28', "source"=>10, 'name'=>"何总客户", 'province'=>'河南省', 'city'=>"许昌市", 'street'=>"", 'zipcode'=>"461000", 'al'=>"", 'phone'=>"15393779998", 'email'=>"hzkh@xcly.com", 'country'=>"41", "express"=>"14", "address"=>"建安区英豪路与滨河路交叉路口往东约50米路北 龙盈实业(客户自提)", ]; $this->data['customer'] = $customer; $country = $this->country->find_all('1=1','id,name','name asc');//国家 $this->data['country'] = $country; $express = $this->express->find_all();//物流商 $this->data['express'] = $express; $bm = $this->country->read($customer['country']); $this->data['bm'] = $bm; $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or')); $this->data['wlshop'] = $wlshop; $this->data['user'] = $u['userid']; $this->_Template('fullorderabf_yjtj',$this->data); } }