load->library('session'); $this->load->_model('Model_api','api'); $this->load->_model('Model_apismt','apismt'); $this->load->_model('Model_shop','shop'); $this->load->_model('Model_fullordersmt','fullordersmt'); $this->load->_model('Model_fullordersmtorder','fullordersmtorder'); $this->load->_model('Model_country','country'); $this->load->_model('Model_hl','hl'); $this->load->_model('Model_is','is'); $this->load->_model('Model_kdniao','kdniao'); $this->load->_model('Model_typeclass','typeclass'); $this->load->_model('Model_warehouse','warehouse'); $this->load->_model('Model_fullorderexcel','fullorderexcel'); $this->load->_model('Model_dhltest','dhltest'); $this->load->_model('Model_customersmt','customersmt'); $this->load->_model('Model_express','express'); $this->load->_model('Model_service','service'); $this->load->_model('Model_notice','notice'); $this->load->_model('Model_whlabel','whlabel'); $this->load->_model('Model_productdescribe','productdescribe'); $this->load->_model('Model_ljg','ljg'); $this->load->_model('Model_commodityread','commodityread'); $this->load->_model('Model_fedex','fedex'); $this->load->_model('Model_dhl','dhl'); $this->load->_model('Model_usps','usps'); } //定义方法的调用规则 获取URI第二段值 public function _remap($arg,$arg_array) { if($arg == 'aeorder')//添加 { $this->_aeorder_zg($arg_array); } else if($arg == 'smtaeorder')//更改物流状态并发送站内信 { $this->_aeorder($arg_array); } else if($arg == 'logistics')//更改物流状态并发送站内信 { $this->_logistics($arg_array); } } public function _aeorder_zg($arg_array) { echo 1; } public function _aeorder($arg_array) { $gethl = $this->hl->get_hl();//获取即时汇率 $dictionaries = $this->typeclass->find_all('ae!= "" and (classid=13 or classid=22 or classid=8 or classid=15 or classid=27 or classid=25 or classid=26 or classid=18 or classid=14 or classid=9 or classid=12 or classid=10 or classid=6)'); //产品人发类型颜色 $dtc = array(); foreach ($dictionaries as $v) { if(stripos($v['spare'],'|') !== false)//如果有多个值 { $v['spare'] = explode('|',$v['spare']); foreach ($v['spare'] as $vs) { $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id']); } } else { $dtc[strtolower($v['spare'])] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id']); } } $dictionaries2 = $this->typeclass->find_all(); foreach ($dictionaries2 as $v) { $dtctitle[$v['id']] = $v['title']; } $dtc['Clip'] = array('classid'=>18,'zh'=>'卡子发卡子发','id'=>0); $dtc['Clip--D'] = array('classid'=>18,'zh'=>'卡子发卡子发','id'=>0); $dtc['Clip--L'] = array('classid'=>18,'zh'=>'卡子发卡子发','id'=>0); $dtc['with bangs'] = array('classid'=>999,'zh'=>'(带齐刘海)','id'=>0); $dtc['no bangs'] = array('classid'=>999,'zh'=>'(无刘海)','id'=>0); $dtc['nwb'] = array('classid'=>15,'zh'=>'扁头 自然曲','id'=>111);//中文词不一样,ID一样 $dtctitle[126] = 'Hair Weaving'; $dtctitle[127] = 'Closure'; $dtctitle[128] = 'Wigs'; $dtctitle[130] = 'Clip-in Full Head'; /* 匹配结束 */ /* 价格加入 */ $money = array(); $productdescribe = $this->productdescribe->find_all('1=1','number,purchase,cost,salesprice,title'); foreach ($productdescribe as $v) { $money[$v['number']] = array('purchase'=>$v['purchase'],'cost'=>$v['cost'],'salesprice'=>$v['salesprice'],'title'=>$v['title']); } /* 价格加入 */ /* 匹配ID加入 */ $int = array(); $intdata = $this->typeclass->find_all('classid=14','id,ae'); foreach ($intdata as $v) { $v['spare'] = explode('|',$v['spare']); $int[$v['id']] = $v['spare'][0]; } /* 匹配ID结束 */ /* 匹配状态加入 */ $zt = array();$ste = array(); $ztdata = $this->typeclass->find_all('classid=29','id,classtitle'); foreach ($ztdata as $v) { $zt[$v['classtitle']] = $v['id']; $ste[$v['id']] = $v['classtitle']; } /* 匹配状态结束 */ /* 国家加入键值-k */ $cuy = array(); $cuydata = $this->country->find_all('1=1','al,lb,id'); foreach ($cuydata as $v) { $cuy[$v['al']] = array('id'=>$v['id'],'lb'=>$v['lb']);//获取到国家ID } /* 国家加入键值-j */ /* 币种加入键值-k */ $typeclass = array(); $tdata = $this->typeclass->find_all('classid=30','id,title'); foreach ($tdata as $v) { $typeclass[$v['title']] = $v['id']; } /* 币种加入键值-j */ $is = $this->is->find_all('1=1','*','number asc');//获取仓库平匹配表 $sid = ''; if(isset($_SESSION['api'])) { $user = $this->user->get_api($_SESSION['api']); $user = explode('|',trim($user['shop'],'|')); foreach ($user as $value) { $sid .= " id = '$value' or"; } $sid = " and (".rtrim($sid,'or').")"; } $post = $this->input->post(NULL, TRUE); if(isset($post['is']) || isset($arg_array[0])) { $shop = $this->shop->find_all("code != '' and type = 270 and tb = 1".$sid);//获取店铺信息 foreach ($shop as $value) { //订单状态: PLACE_ORDER_SUCCESS:等待买家付款; IN_CANCEL:买家申请取消; WAIT_SELLER_SEND_GOODS:等待您发货; SELLER_PART_SEND_GOODS:部分发货; WAIT_BUYER_ACCEPT_GOODS:等待买家收货; FUND_PROCESSING:买家确认收货后,等待退放款处理的状态; FINISH:已结束的订单; IN_ISSUE:含纠纷的订单; IN_FROZEN:冻结中的订单; WAIT_SELLER_EXAMINE_MONEY:等待您确认金额; RISK_CONTROL:订单处于风控24小时中,从买家在线支付完成后开始,持续24小时。例:["FINISH_PAY_CLOSED","FINISH_CANCEL"] $data = array(); for($i=1;$i<5;$i++) { $res = $this->apismt->get_hq($i,50,time()-360000,time(),'["IN_CANCEL","WAIT_SELLER_SEND_GOODS","SELLER_PART_SEND_GOODS","WAIT_BUYER_ACCEPT_GOODS","FUND_PROCESSING","IN_ISSUE","IN_FROZEN","WAIT_SELLER_EXAMINE_MONEY","RISK_CONTROL"]',$value['code']); if(!$res) { continue; } foreach ($res as $va) { $data[] = $va; } } $this->_state($data,$ste,$zt,$value); } $this->_orderinfo($gethl,$dtc,$dtctitle,$money,$int,$zt,$cuy,$typeclass,$is); //$this->zd();//查找消息模板并发送 } } public function _state($res,$ste,$zt,$value) { foreach ($res as $v) { $dataorder = $this->fullordersmt->get_orderinfo($v['orderinfo']); if(isset($dataorder['state'])) { if($ste[$dataorder['state']] == $v['state']) { continue; } else { $shop = $this->shop->read($dataorder['shop']); $data = $this->apismt->get_order($v['orderinfo'],$shop['code']); if($data['express']) { $express = $this->express->get_aecode($data['express']); $express = $express['id']; $waybill = $data['waybill']; } else { $express = $dataorder['express']; $waybill = $dataorder['waybill']; } $dlz = isset($v['dlz'])?$v['dlz']:$dataorder['dlz']; $expressstate = isset($data['expressstate'])?$data['expressstate']:$dataorder['expressstate']; $this->fullordersmt->save(array('state'=>$zt[$v['state']],'express'=>$express,'waybill'=>$waybill,'dlz'=>$dlz,'expressstate'=>$expressstate),$dataorder['id']); } } else { $smtorder = $this->fullordersmtorder->get_orderinfo($v['orderinfo']); if(!$smtorder) { $this->fullordersmtorder->insert(array('orderinfo'=>$v['orderinfo'],'shop'=>$value['id'])); } } } } //获取订单信息 public function _orderinfo($gethl,$dtc,$dtctitle,$money,$int,$zt,$cuy,$typeclass,$is) { $time = time(); $smtorder = $this->fullordersmtorder->find_all("type = '0'",'*','id desc'); foreach ($smtorder as $var) { $dataorder = $this->fullordersmt->get_orderinfo($var['orderinfo']); if(isset($dataorder['orderinfo'])) { $this->fullordersmtorder->save(array('type'=>1),$var['id']); continue; } $shop = $this->shop->read($var['shop']); $post = $this->apismt->get_order($var['orderinfo'],$shop['code']); if(!isset($post['state'])) { continue; } if($post['buytime'] == '0' && $post['state'] != 'FINISH') { /** $notice = $this->notice->find_all("type = '1' and state = '1' and ktime < '$time' and jtime > '$time' and ordertatus = '203' and shop = '".$var['shop']."'");//未发送并且未付款并且未关闭 if($notice && $var['type'] == '0' && $var['msg'] == '0') { $var['userid'] = $post['userid']; $var['name'] = ($post['fullname'])?$post['fullname']:$post['name']; $go = $this->notice->get_smtone($var,$shop,$notice[0]['content']);//速卖通 if($go == 1) { $this->fullordersmtorder->save(array('msg'=>1),$var['id']); } } **/ $notice = $this->notice->get_go($var,$shop,'ordertatus','203'); if($notice == 1) { $this->fullordersmtorder->save(array('msg'=>1),$var['id']); } continue; } else if($post['buytime'] == '0' && $post['state'] == 'FINISH') { $this->fullordersmtorder->remove($var['id']); continue; } $num = $this->fullordersmt->find_count('gtime = "'.date('Ymd',$post['buytime']).'" and shop = "'.$shop['id'].'"'); $post['shop'] = $var['shop'];//不可删 $state = $post['state']; $post['state'] = $zt[$state];//更改状态为ID $post['user'] = $shop['shopuser']; $post['al'] = $cuy[$post['country']]['lb'];//国家二字码 $post['country'] = $cuy[$post['country']]['id'];//国家ID $post['currency'] = $typeclass['USD'];//币种-美元ID $post['currencytitle'] = 'USD';//币种-美元ID $post['type'] = 1;//发货仓库 $post['capital'] = 3;//资金支付状况,全部付款 $nmb = substr(strval($num+1+1000),1,3); $post['number'] = $shop['shortname'].'-'.substr(date('ymd',$post['buytime']),1).'-'.$nmb;//编号 $post['numberpx'] = substr(date('ymd',$post['buytime']),1).$nmb;//按编号排序 $yga = $post['shouldmoney'];$ygb = $shop['estimaterate']; $post['budget'] = eval("return $yga*1.$ygb;");//预估到帐金额 $post['gtime'] = date('Ymd',$post['buytime']);//格式化付款时间 if(isset($post['express'])) { if($post['express']) { $express = $this->express->get_aecode($post['express']); $post['express'] = ($express)?$express['id']:0; } } else { $post['express'] = 0; } $post['name'] = str_replace("'","’",$post['name']); $post['userid'] = str_replace("'","’",$post['userid']); $post['fullname'] = str_replace("'","’",$post['fullname']); $post['address'] = str_replace("'","’",$post['address']); $sku = '';$fpdata = '';$title = '';$whlabel = ''; foreach ($post['sku'] as $val) { //$val['skucode'] = is_array($val['skucode'])?'':$val['skucode'];//之前获取sku_code会出现数组,现在不会出现数组,暂保留 $val['skucode'] = str_replace(";","%' and skuid like '%",$val['skucode']); $ku = "and skuid like '%".$val['skucode']."%'"; $u = $this->commodityread->get_tbproduct($val['id'],$ku); if($u) { $read = $this->api->matching($val['num'],$u['sku'],$dtc,$money,$int,$dtctitle); $fpdata .= $read['product']; $whlabel .= $read['whlabel']; $title .= $read['title']; $sku .= ($u['sku']!='')?$val['id'].':'.$u['sku'].';':$val['id'].';'; } } $post['sku'] = rtrim($sku,';'); $post['fpdata'] = $fpdata; $post['shipremarks'] = $title; $post['whlabel'] = ($whlabel!='|')?str_replace('||','|',$whlabel):''; foreach ($gethl as $v) { $code = str_replace(" ","",$v['code']); if($code == 'USD')//查找对应汇率值 { $hl = $v['refePrice']/100; } } $post['hl'] = $hl; $post['mergeid'] = 0; if($this->fullordersmt->insert($post)) { $this->fullordersmtorder->save(array('type'=>1),$var['id']); $adrs = $this->customersmt->get_us($post['userid'],$var['shop']); if($adrs) { $this->customersmt->save(array('time'=>$post['buytime'],'num'=>$adrs['num']+1,'money'=>$adrs['money']+$post['shouldmoney']),$adrs['id']); } else { $ct['shop'] = $var['shop']; $ct['source'] = 1; $ct['level'] = 5; $ct['country'] = $post['country']; $ct['time'] = $post['buytime']; $ct['num'] = 1; $ct['money'] = $post['shouldmoney']; $ct['zipcode'] = $post['zipcode']; $ct['name'] = $post['name']; $ct['client'] = $post['name']; $ct['phone'] = $post['phone']; $ct['userid'] = $post['userid']; $ct['fullname'] = $post['fullname']; $ct['province'] = $post['province']; $ct['city'] = $post['city']; $ct['address'] = $post['address']; $this->customersmt->insert($ct); } } } echo 'orderinfo-ok-'; } public function _logistics($arg_array) { $post = $this->input->post(NULL, TRUE); if(isset($arg_array[0])) { $wl = $this->wl();//物流 //$zd = $this->zd();//自动 已放入获取订单中执行 //$yx = $this->yx();//营销 if($wl > 0) { echo json_encode(array('msg'=>'发送站内信成功','success'=>true));exit; } else { echo json_encode(array('msg'=>'无需要发送信息','success'=>false));exit; } } } public function zd() { $time = time(); $notice = $this->notice->find_all("type = '1' and state = '1' and ktime < '$time' and jtime > '$time'"); foreach ($notice as $key=>$var) { $where = "state = '".$var['ordertatus']."' and shop = '".$var['shop']."' and source != '1'"; if($var['ordertatus'] == 207)//等待发货 { $where .= " and review > '4' and print != '1'"; } else if($var['ordertatus'] == 209)//等待买家收货 { $where .= " and library = '2' and print = '3' and waybill != ''";//已打印已出库 } else if($var['ordertatus'] == 216)//已完成 { $where .= " and library = '2' and print = '3'"; } $data = $this->fullordersmt->find_all($where); foreach ($data as $k=>$v) { $shop = $this->shop->read($v['shop']); $express = $this->express->read($v['express']); $service = $this->service->read($express['service']); $express['servicename'] =$service['title'];//增加快递名称 if($var['ordertatus'] == 209 && $v['dlz'] == '0' && $v['waybill'] != '')//发货声明 { $dlz = $this->apismt->get_out($v['waybill'],'all',$v['orderinfo'],$express['aecode'],$shop['code']); if(isset($dlz['result_success'])) { $this->fullordersmt->save(array('dlz'=>1,'exstate'=>1),$v['id']); } else { $this->fullordersmt->save(array('dlz'=>2,'exstate'=>1),$v['id']); } } if(stripos($v['zdstate'],$v['state']) === false || $v['zdstate'] == "") { $go = $this->notice->get_god($v,$shop,$express,$var['content'],$var['message']); if($go == 1) { $this->fullordersmt->save(array('content'=>$v['content'].$var['title'].'成功;','zdstate'=>$v['zdstate'].$v['state'].'|'),$v['id']); $i++; } else { $this->fullordersmt->save(array('exstateerror'=>$go),$v['id']); } } } } echo 'zd-ok'; } public function wl() { $i = 0; $data = $this->fullordersmt->find_all("state = '209' and library = '2' and source != 1"); if($data) { foreach ($data as $var) { $ex = $this->express->read($var['express']);//查找快递 if($ex['cxcode'] == '' && $var['exstateerror'] == '') { $this->fullordersmt->save(array('exstateerror'=>'此快递不支持轨迹查询'),$var['id']); continue; } else if($ex['cxcode'] == '' && $var['exstateerror'] != '') { continue; } else if($ex['cxcode'] == 'fedex') { $logistics = 'fedex'; } else if($ex['cxcode'] == 'usps') { $logistics = 'usps'; } else if($ex['cxcode'] == 'dhl') { $logistics = 'dhl'; } else { $logistics = 'apismt'; } $service = $this->service->read($ex['service']); $var['express'] = strtolower($ex['cxcode']);//替换为快递服务商码 $var['servicename'] =$service['title'];//增加快递名称 $var['url'] = $ex['url'];//增加快递链接 $v = $this->$logistics->get_logistics($var); if($v) { if($v['f'] == 1 && $v['exstate'] != $var['exstate'])//正常物流状态发送站内信 { if($v['exstate'] == 4) { $this->fullordersmt->save(array('state'=>216,'exstate'=>$v['exstate']),$var['id']); } else { $this->fullordersmt->save(array('exstate'=>$v['exstate']),$var['id']); } $shop = $this->shop->read($var['shop']); $go = $this->notice->get_go($var,$shop,'logisticstatus',$v['exstate']); if($v['exstate'] == 1) { $msg = '揽收'; } else if($v['exstate'] == 2) { $msg = '在途中'; } else if($v['exstate'] == 3) { $msg = '派送中'; } else if($v['exstate'] == 4) { $msg = '已签收'; } $gg = ($go==1)?$msg.':站内信成功;':$msg.':站内信失败;'; $go = ($go==1)?'':$go; $this->fullordersmt->save(array('content'=>$var['content'].$gg,'exstateerror'=>$go),$var['id']); $i++; } else if ($v['f'] == '0') { $this->fullordersmt->save(array('exstateerror'=>$v['content']),$var['id']); } } } } return $i;exit; } public function StrCombinations($arr,$len=0,&$res,$str="")//字符串组合 { $arr_len = count($arr); if($len == 0) { $res[] = $str; } else { for($i=0; $i<$arr_len; $i++) { $tmp = array_shift($arr); if (empty($str)) { $this->StrCombinations($arr, $len-1, $res,$tmp); } else { $this->StrCombinations($arr, $len-1, $res,$str.";".$tmp); } array_push($arr, $tmp); } } } /** //获取新订单及更改状态 public function _state($res,$ste,$zt,$value) { foreach ($res as $v) { if($v['state'] == 'PLACE_ORDER_SUCCESS') { continue; } $dataorder = $this->fullordersmt->get_orderinfo($v['orderinfo']); if(isset($dataorder['orderinfo'])) { if($dataorder['mergeid'] != '5' && $ste[$dataorder['state']] != $v['state']) { $shop = $this->shop->read($dataorder['shop']); $data = $this->apismt->get_order($v['orderinfo'],$shop['code']); if($data['express']) { $express = $this->express->get_aecode($data['express']); $express = $express['id']; $waybill = $data['waybill']; } else { $express = $dataorder['express']; $waybill = $dataorder['waybill']; } $dlz = isset($v['dlz'])?$v['dlz']:$dataorder['dlz']; $expressstate = isset($data['expressstate'])?$data['expressstate']:$dataorder['expressstate']; $this->fullordersmt->save(array('state'=>$zt[$v['state']],'express'=>$express,'waybill'=>$waybill,'dlz'=>$dlz,'expressstate'=>$expressstate),$dataorder['id']); } } else { $this->fullordersmt->insert(array('orderinfo'=>$v['orderinfo'],'mergeid'=>5,'shop'=>$value['id'],'user'=>$value['shopuser'])); } } //触发站内信模板,出发站内信模板查找 } //获取订单信息 public function _orderinfo($gethl,$dtc,$dtctitle,$money,$int,$zt,$cuy,$typeclass,$is) { $dataroder = $this->fullordersmt->find_all("mergeid = 5"); foreach ($dataroder as $var) { $shop = $this->shop->read($var['shop']); $post = $this->apismt->get_order($var['orderinfo'],$shop['code']); if(!$post['state']) { continue; } $num = $this->fullordersmt->find_count('gtime = "'.date('Ymd',$post['buytime']).'" and shop = "'.$shop['id'].'"'); $post['shop'] = $var['shop'];//不可删 $state = $post['state']; $post['state'] = $zt[$state];//更改状态为ID $post['al'] = $cuy[$post['country']]['lb'];//国家二字码 $post['country'] = $cuy[$post['country']]['id'];//国家ID $post['currency'] = $typeclass['USD'];//币种-美元ID $post['currencytitle'] = 'USD';//币种-美元ID $post['type'] = 1;//发货仓库 $post['capital'] = 3;//资金支付状况,全部付款 $nmb = substr(strval($num+1+1000),1,3); $post['number'] = $shop['shortname'].'-'.substr(date('ymd',$post['buytime']),1).'-'.$nmb;//编号 $post['numberpx'] = substr(date('ymd',$post['buytime']),1).$nmb;//按编号排序 $yga = $post['shouldmoney'];$ygb = $shop['estimaterate']; $post['budget'] = eval("return $yga*1.$ygb;");//预估到帐金额 $post['gtime'] = date('Ymd',$post['dtime']);//格式化订单时间 if(isset($post['express'])) { if($post['express']) { $express = $this->express->get_aecode($post['express']); $post['express'] = $express['id']; } } $post['name'] = str_replace("'","’",$post['name']); $post['userid'] = str_replace("'","’",$post['userid']); $post['fullname'] = str_replace("'","’",$post['fullname']); $post['address'] = str_replace("'","’",$post['address']); $sku = '';$fpdata = '';$title = '';$whlabel = ''; foreach ($post['sku'] as $val) { //$val['skucode'] = is_array($val['skucode'])?'':$val['skucode'];//之前获取sku_code会出现数组,现在不会出现数组,暂保留 $u = $this->commodityread->get_productid($val['id'],$val['skucode']); $sku .= ($u['sku']!='')?$val['id'].':'.$u['sku'].';':$val['id'].';'; $read = $this->api->matching($val['num'],$u['sku'],$dtc,$money,$int,$dtctitle); $fpdata .= $read['product']; $title .= $read['title']; $whlabel .= $read['whlabel']; } $post['sku'] = rtrim($sku,';'); $post['fpdata'] = $fpdata; $post['shipremarks'] = $title; $post['whlabel'] = ($whlabel!='|')?str_replace('||','|',$whlabel):''; foreach ($gethl as $v) { $code = str_replace(" ","",$v['code']); if($code == 'USD')//查找对应汇率值 { $hl = $v['refePrice']/100; } } $post['hl'] = $hl; $post['mergeid'] = 0; $this->fullordersmt->save($post,$var['id']); if($post['buytime'] != '0') { $adrs = $this->customersmt->get_us($post['userid'],$var['shop']); if($adrs) { $this->customersmt->save(array('time'=>$post['buytime'],'num'=>$adrs['num']+1,'money'=>$adrs['money']+$post['shouldmoney']),$adrs['id']); } else { $ct['shop'] = $var['shop']; $ct['source'] = 1; $ct['level'] = 5; $ct['country'] = $post['country']; $ct['time'] = $post['buytime']; $ct['num'] = 1; $ct['money'] = $post['shouldmoney']; $ct['zipcode'] = $post['zipcode']; $ct['name'] = $post['name']; $ct['client'] = $post['name']; $ct['phone'] = $post['phone']; $ct['userid'] = $post['userid']; $ct['fullname'] = $post['fullname']; $ct['province'] = $post['province']; $ct['city'] = $post['city']; $ct['address'] = $post['address']; $this->customersmt->insert($ct); } } } } **/ }