123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745 |
- <?php defined('BASEPATH') OR exit('No direct script access allowed');
- class Apismt extends Start_Controller {
- public function __construct(){
- parent::__construct();
- $this->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');
- $this->load->_model('Model_specialstock','specialstock');
- $this->load->_model('Model_ck','ck');
- $this->load->_model('Model_weight','weight');
- $this->load->_model('Model_classid','classid');
- $this->load->_model('Model_apiyy','apiyy');
- $this->load->_model('Model_whlabel_fc','whlabel_fc');
- $this->load->_model('Model_shopsku','shopsku');
- }
- //定义方法的调用规则 获取URI第二段值
- public function _remap($arg,$arg_array)
- {
- if($arg == 'smtaeorder')//添加
- {
- $this->_aeorder_zg($arg_array);
- }
- else if($arg == 'aeorder')//更改物流状态并发送站内信
- {
- $this->_aeorder($arg_array);
- }
- else if($arg == 'aeorder_zg')//手动
- {
- $this->_aeorder_zg($arg_array);
- }
- else if($arg == 'znx')//更改物流状态并发送站内信
- {
- $this->_znx($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('spare!= "" and classid != 1 and classid != 2 and classid != 3 and classid != 4 and classid != 5 and classid != 11 and classid != 16 and classid != 17 and classid != 20 and classid != 21 and classid != 23 and classid != 24 and classid != 29 and classid != 30 and classid != 31 and classid != 32');
- // 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 or classid=100 or classid=999)
- $dtc = array();
- foreach ($dictionaries as $v)
- {
- if(stripos($v['spare'],'|') !== false)//如果有多个值
- {
- $v['spare'] = explode('|',$v['spare']);
- foreach ($v['spare'] as $k=>$vs)
- {
- if(stripos($v['zh'],'|') !== false)
- {
- $vzh = explode('|',$v['zh']);
- $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$vzh[$k],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
- }
- else
- {
- $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
- }
- }
- }
- else
- {
- $dtc[strtolower($v['spare'])] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$v['spare']);
- }
-
- }
- $dictionaries2 = $this->typeclass->find_all();
- foreach ($dictionaries2 as $v)
- {
- $dtctitle[$v['id']] = $v['title'];
- }
- /* 匹配结束 */
- /* 价格加入 */
- /**
- $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,spare');
- 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,ename');
- foreach ($cuydata as $v)
- {
- $cuy[$v['al']] = array('id'=>$v['id'],'lb'=>$v['lb'],'ename'=>$v['ename']);//获取到国家ID
- }
- /* 国家加入键值-j */
- /* 币种加入键值-k */
- $typeclass = array();
- $tdata = $this->typeclass->find_all('classid=30','id,title');
- foreach ($tdata as $v)
- {
- $typeclass[$v['title']] = $v['id'];
- }
- /* 币种加入键值-j */
- /* 新增SKU-k */
- $zjsku = array();
- $shopsku = $this->shopsku->find_all();
- foreach ($shopsku as $val)
- {
- $ss = explode(',',trim($val['shop'],','));
- foreach ($ss as $v)
- {
- if(isset($zjsku[$v]))
- {
- $zjsku[$v] .= ','.trim($val['sku'],',');
- }
- else
- {
- $zjsku[$v] = trim($val['sku'],',');
- }
- }
- }
- /* 新增SKU-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();
- $n = $value['id'] == 7?75:60;
- for($i=1;$i<$n;$i++)
- {
- $res = $this->apismt->get_hqfull($i,50,time()-90*24*3600,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,array(),$int,$zt,$cuy,$typeclass,$is,$zjsku);
- $this->_fhsm();//发货声明
- $this->_wfk($cuy);//未付款单独发送
- $this->_znx();//查找消息模板并发送
- }
- }
-
- public function _state($res,$ste,$zt,$shop)
- {
- foreach ($res as $v)
- {
- $v['shop'] = $shop['id'];
- if($v['fundstate'] != 'NOT_PAY' && $v['fundstate'] != '')
- {
- $dataorder = $this->fullordersmt->get_orderinfo($v['orderinfo']);
- if(!isset($dataorder['state']))
- {
- $smtorder = $this->fullordersmtorder->get_orderinfo($v['orderinfo']);
- if(!$smtorder && $v['orderinfo'] != '0')
- {
- $this->fullordersmtorder->insert(array('orderinfo'=>$v['orderinfo'],'msg'=>0,'shop'=>$shop['id'],'fundstate'=>0));
- }
- else if($smtorder['fundstate'] == '1')//已付款$v[order]搜索有,证明已付款
- {
- $this->fullordersmtorder->save(array('fundstate'=>0),$smtorder['id']);
- }
- continue;
- }
- else if(!isset($zt[$v['state']]) || $ste[$dataorder['state']] == $v['state'])
- {
- continue;
- }
- else if($ste[$dataorder['state']] != $v['state'] && $dataorder['tb'] == '0')
- {
- $orderexpress = $this->express->read($dataorder['express']);
- $data = $this->apismt->get_order($v['orderinfo'],$shop['code']);
- $overtime = $zt[$v['state']] == 207?$data['overtime']:$dataorder['overtime'];
- if($data['express'])
- {
- $express = $this->express->get_aecode($data['express']);
- if($data['express'] == $orderexpress['aecode'])
- {
- $express = $dataorder['express'];
- }
- else
- {
- $express = isset($express['id'])?$express['id']:$dataorder['express'];
- }
- $waybill = $data['waybill'];
- }
- else
- {
- $express = $dataorder['express'];
- $waybill = $dataorder['waybill'];
- }
- $dlz = $data['express']?1:$dataorder['dlz'];
- $expressstate = isset($data['expressstate'])?$data['expressstate']:$dataorder['expressstate'];
-
- /**
- //库存开始
- $warehouse = $this->warehouse->read($dataorder['type']);
- $warehousenew = $this->warehouse->read($dataorder['type']);
- $thisfpdata = explode(';',rtrim($dataorder['fpdata'],';'));
- $fpcount = '';
- foreach ($thisfpdata as $v)
- {
- $thisv = explode('|',$v);
- $thisv = explode(',',$thisv[0]);
- $fpcount .= $thisv[1].'|';
- }
- $ft = array();
- $ftdata = explode('|',rtrim($fpcount,'|'));
- foreach ($ftdata as $va)
- {
- $ftitle = '';
- $va = explode('-',trim($va,'-'));
- foreach ($va as $v)
- {
- $v = $this->typeclass->read($v);
- $ftitle .= $v['title'].' ';
- }
- $ft[] = rtrim($ftitle,' ');
- }
- @$this->specialstock->get_kc($dataorder['state'],$zt[$v['state']],$dataorder['whlabel'],$dataorder['whlabel'],$dataorder['number']);
- @$this->whlabel->get_kc($dataorder['state'],$zt[$v['state']],$warehousenew['zd'],$warehousenew['ys'],$dataorder['type'],$dataorder['whlabel'],$fpcount,$ft,$dataorder['number'],$dataorder['shop'],$dataorder['type'],$dataorder['whlabel']);
- //库存结束
-
- $warehouse = $this->warehouse->read($dataorder['type']);
- if($dataorder['library'] == 1 || ($dataorder['library'] != 2 && ($zt[$v['state']] != '207' || $zt[$v['state']] == '209')))
- {
- $kcyz = $this->ck->get_kc($zt[$v['state']],$warehouse,$dataorder['shop'],$dataorder['number'],$dataorder['whlabel'],$dataorder['fpdata']);
- }
- $fl = $this->ck->get_fl($warehouse['hz'],$dataorder['whlabel'],$dataorder['fpdata']);
-
- **/
- $this->fullordersmt->save(array('state'=>$zt[$v['state']],'express'=>$express,'waybill'=>$waybill,'dlz'=>$dlz,'expressstate'=>$expressstate,'overtime'=>$overtime),$dataorder['id']);
- }
- }
- else
- {
- $smtorder = $this->fullordersmtorder->get_orderinfo($v['orderinfo']);
- if(!$smtorder)
- {
- $this->fullordersmtorder->insert(array('orderinfo'=>$v['orderinfo'],'msg'=>0,'shop'=>$shop['id'],'fundstate'=>1));
- }
- }
- }
- }
-
- //获取订单信息
- public function _wfk($cuy)
- {
- $data = $this->fullordersmtorder->find_all("type = '0' and msg = '0'");
- foreach ($data as $v)
- {
- $shop = $this->shop->read($v['shop']);
- $data = $this->apismt->get_order($v['orderinfo'],$shop['code']);
- if(isset($data['country']) && isset($data['state']))
- {
- $data['country'] = $cuy[$data['country']]['ename'];
- $data['shop'] = $shop['id'];$count = '';
- if($data['state'] == 'PLACE_ORDER_SUCCESS')
- {
- $notice = $this->notice->get_go($data,$shop,'ordertatus','283');
- if($notice == 1)
- {
- $msg = 1;
- }
- else
- {
- $msg = 4;$count = $notice;
- }
- }
- else
- {
- $msg = 2;
- }
- $this->fullordersmtorder->save(array('msg'=>$msg,'count'=>$count),$v['id']);
- }
- else
- {
- $this->fullordersmtorder->save(array('msg'=>3),$v['id']);
- }
- }
- }
-
- //获取订单信息
- public function _orderinfo($gethl,$dtc,$dtctitle,$money,$int,$zt,$cuy,$typeclass,$is)
- {
- $time = time();
- $smtorder = $this->fullordersmtorder->find_all("type = '0' and fundstate = '0'",'*','id desc');
- foreach ($smtorder as $var)
- {
- $dataorder = $this->fullordersmt->get_orderinfo($var['orderinfo']);
- if(isset($dataorder['orderinfo']) || $var['orderinfo'] == '0')
- {
- $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;
- }
- $num = $this->fullordersmt->find_count('gtime = "'.date('Ymd',$post['buytime']).'" and shop = "'.$shop['id'].'"','id');
- $num2 = $this->fullordersmt->find_all('gtime = "'.date('Ymd',$post['buytime']).'" and shop = "'.$shop['id'].'"','id');
- $num2 = count($num2);
- if(date('Ymd',$post['buytime']) == '20190902' && $var['shop'] == 13)
- {
- $num = $num+1;$num2 = $num2+1;
- }
- if($num != $num2)
- {
- continue;//计算两遍数量对比防止错误编号
- }
- if(!$post['country'] || $post['country'] == NULL || $post['country'] == 'null')
- {
- continue;
- }
- $post['shop'] = $var['shop'];//不可删
- $state = $post['state'];
- $post['state'] = $zt[$state];//更改状态为ID
- $post['user'] = $shop['shopuser'];
- if($post['country'] == 'GB')
- {
- $post['country'] = 'UK';
- }
- $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;//资金支付状况,全部付款
- if($num > 998)
- {
- $nmb = $num+1;
- }
- else
- {
- $nmb = substr(strval($num+1+1000),1,3);
- }
- $post['number'] = $shop['shortname'].'-'.substr(date('ymd',$post['buytime']),1).'-'.$nmb;//编号
- $post['numberpx'] = date('ymd',$post['buytime'])*10000+$nmb;//按编号排序
- $post['skje'] = $post['shouldmoney'];//收款金额
- $yga = $post['shouldmoney'];$ygb = $shop['estimaterate'];
- $post['estimaterate'] = $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 = '';$link = '';
- 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'].';';
- $link .= ($link!='')?',https://www.aliexpress.com/item/'.$val['id'].'.html':'https://www.aliexpress.com/item/'.$val['id'].'.html';
- }
- }
- $post['sku'] = rtrim($sku,';');
- $post['link'] = $link;
- $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'] = '6.4';
- $post['mergeid'] = 0;
- $post['oldaddress'] = json_encode(array('country'=>$post['country'],'province'=>$post['province'],'city'=>$post['city'],'zipcode'=>$post['zipcode'],'phone'=>$post['phone'],'address'=>$post['address'],'name'=>$post['name'],'money'=>$post['shouldmoney']));
- if($post['shop'] != '9' && $post['shop'] != '26')
- {
- $warehouse = $this->warehouse->find_all("fpzd = '1'",'*','fpsx desc');
- foreach ($warehouse as $v)
- {
- if($v['bdcountry'] != 0 && $v['bdcountry'] != $post['country'])
- {
- continue;
- }
- $yx = 'get_yx_'.$v['bdck'];
- $kczd = $this->ck->$yx($post['state'],$v,$post['shop'],$post['number'],$post['whlabel'],$post['fpdata']);
- if($kczd['t'] == 0)
- {
- $country = $this->country->read($post['country']);//获取国家中配置物流
- if($country['express'] != 0)
- {
- $post['express'] = $country['express'];
- }
- if($v['express'] != 0)//优先使用仓库指定物流,替换掉上面的国家配置物流
- {
- $post['express'] = $v['express'];
- }
- if(stripos($kczd['whlabel'],$v['hz']) !== false)
- {
- $post['type'] = $v['id'];
- $post['whlabel'] = $kczd['whlabel'];
- $post['fpdata'] = $kczd['fpdata'];
- break 1;
- }
- }
- }
- $qdw = $this->warehouse->read($post['type']);
- $fl = $this->ck->get_fl($qdw['hz'],$post['whlabel'],$post['fpdata']);
- $post['sfxh'] = $fl['sfxh'];
- $post['ckfl'] = $fl['ckfl'];
- //特殊仓自动写位置 开始
- $zclp = array();
- $mc = $qdw['bdck'];
- if($mc == 'specialstock')
- {
- $pm = explode(';',trim($post['shipremarks'],';'));
- foreach ($pm as $k=>$vv)
- {
- $vv = trim($vv,' ');
- $lp = $this->typeclass->find_all("zh = '$vv'");
- if(isset($lp[0]['classid']))
- {
- $zclp[] = $vv;
- unset($pm[$k]);
- }
- }
- $pm = array_values($pm);
- $w = explode('|',trim($post['whlabel'],'|'));
- foreach ($w as $k=>$val)
- {
- $hwm = '';
- if(stripos($val,$qdw['hz']) !== false)
- {
- $num = explode('-',trim($val,'-'));
- $xq = explode('~',trim($num[2],'~'));
- foreach ($xq as $v)
- {
- $h = $this->$mc->read(trim($v,$qdw['hz']));
- $pm[$k] .= '(该货物在特殊库存仓 , 位置:'.$h['details'].(($h['cpid']>0)?' - 编码:'.$h['cpid']:'').')';
- }
- }
- }
- if($zclp)
- {
- $zclp = ';'.implode(";",$zclp);
- }
- else
- {
- $zclp = '';
- }
- $post['shipremarks'] = implode(";",$pm).$zclp;
- }
- //特殊仓自动写位置 结束
- //合并重复项
- $hbcfw = explode('|',trim($post['whlabel'],'|'));
- $hbcff = explode(';',trim($post['fpdata'],';'));
- $c = 0;
- $hbw = array();
- $hbf = array();
- for($i=0;$i<count($hbcfw);$i++)
- {
- $w = explode('-',$hbcfw[$i]);
- $f = explode('|',$hbcff[$i]);
- $w2 = ($w[2]==0)?0:'';
- if(!isset($hbw[$w[0].$w2]))
- {
- $hbw[$w[0].$w2] = $hbcfw[$i];
- $hbf[$w[0].$w2] = $hbcff[$i];
- }
- else
- {
- $c++;
- $cw = explode('-',$hbw[$w[0].$w2]);
- $cf = explode('|',$hbf[$w[0].$w2]);
- if($cw[2] != 0 && $w[2] != 0)
- {
- $cf[2] += $f[2];
- $cf[9] .= '~'.$f[9];
- $hbf[$w[0].$w2] = implode("|",$cf);
- $cw[1] += $f[2];
- $cw[2] .= '~'.$f[9];
- $hbw[$w[0].$w2] = implode("-",$cw);
- }
- else if($cw[2] == 0 && $w[2] == 0)
- {
- $cf[2] += $f[2];
- $hbf[$w[0].$w2] = implode("|",$cf);
- $cw[1] += $f[2];
- $hbw[$w[0].$w2] = implode("-",$cw);
- }
- else
- {
- $hbw[] = $hbcfw[$i];
- $hbf[] = $hbcff[$i];
- }
- }
- }
- if($c > 0)
- {
- $post['fpdata'] = implode(";",$hbf).';';
- $post['whlabel'] = '|'.implode("|",$hbw).'|';
- }
- //合并重复项结束
- $post['jweight'] = $this->weight->get_weightcx($post['fpdata']);
- }
- $tjid = $this->fullordersmt->insert($post);
- if($tjid)
- {
- $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']);
- $khid = $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'];
- $ct['zhcx'] = $var['shop'].'-'.$post['userid'];
- $khid = $this->customersmt->insert($ct);
- }
- }
- }
- echo 'orderinfo-ok-';
- }
-
- public function _znx()
- {
- $time = time();
- $notice = $this->notice->find_all("message = '2' and state = '1' and ktime < '$time' and jtime > '$time'");
- foreach ($notice as $key=>$var)
- {
- $ordertatus = $var['ordertatus'];
- $where = "shop = '".$var['shop']."' and source != '1' and buytime > 1569513600";
- if($var['ordertatus'] == 209 || $var['ordertatus'] == 216)//等待买家收货//已完成
- {
- $where .= " and review > '4' and library = '2' and print = '3' and waybill != ''";//已打印已出库
- }
- $where .= " and state = '".$ordertatus."'";
- $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']);
- $country = $this->country->read($v['country']);
- $v['country'] = $country['ename'];
- $express['servicename'] =$service['title'];//增加快递名称
- if($var['type'] == 1 && stripos($v['zdstate'],$v['state']) === false)
- {
- $go = $this->notice->get_god($v,$shop,$express,$var);
- if($go == 1)
- {
- $this->fullordersmt->save(array('content'=>$v['content'].$var['title'].'成功;','zdstate'=>$v['zdstate'].$v['state'].'|','exstateerror'=>''),$v['id']);
- }
- else
- {
- $this->fullordersmt->save(array('exstateerror'=>date('Y-m-d H:i',time()).'-'.$go),$v['id']);
- }
- }
- else if($var['type'] == 2)
- {
- if($express['cxcode'] == '' && $v['exstateerror'] == '')
- {
- $this->fullordersmt->save(array('exstateerror'=>'此快递不支持轨迹查询'),$var['id']);
- continue;
- }
- else if($express['cxcode'] == '' && $v['exstateerror'] != '')
- {
- continue;
- }
- else if($express['cxcode'] == 'fedex' || $express['cxcode'] == 'usps' || $express['cxcode'] == 'dhl' || $express['cxcode'] == 'cne' || $express['cxcode'] == 'dpex' || $express['cxcode'] == 'dpd')
- {
- $logistics = $express['cxcode'];
- }
- else
- {
- $logistics = 'apismt';
- }
- $v['cxcode'] = strtolower($express['cxcode']);//增加快递服务商码
- $v['servicename'] =$service['title'];//增加快递名称
- $v['url'] = $express['url'];//增加快递链接
- $fs = $this->$logistics->get_logistics($v);
- if($fs)
- {
- if($fs['f'] == 1 && $fs['exstate'] == 4)
- {
- $this->fullordersmt->save(array('state'=>216,'zdstate'=>$fs['exstate'].'|'),$v['id']);
- }
- if($fs['f'] == 1 && stripos('|'.$v['zdstate'],'|'.$fs['exstate'].'|') === false && $fs['exstate'] == $var['logisticstatus'])//正常物流状态发送站内信
- {
- $go = $this->notice->get_god($v,$shop,$express,$var);
- if($go == 1)
- {
- $this->fullordersmt->save(array('content'=>$v['content'].$var['title'].'成功;','zdstate'=>$v['zdstate'].$fs['exstate'].'|'),$v['id']);
- }
- else
- {
- $this->fullordersmt->save(array('exstateerror'=>date('Y-m-d H',time()).'-'.$go),$v['id']);
- }
- }
- }
- }
- }
- }
- echo 'znx-ok';
- }
-
- public function _fhsm()
- {
- $data = $this->fullordersmt->find_all("dlz = '0' and library = '2' and waybill != '' and (state = '207' or state = '209')");
- foreach ($data as $k=>$v)
- {
- $shop = $this->shop->read($v['shop']);
- $express = $this->express->read($v['express']);
- if($v['merge'] == $v['id'])
- {
- $t = $this->fullordersmt->find_all("merge = '".$v['merge']."' and dlz != '1'");
- $l=0;
- foreach ($t as $vv)
- {
- $d = $this->apismt->get_out($v['waybill'],'all',$vv['orderinfo'],$express['aecode'],$shop['code']);
- if(isset($d['result_success']) && $d['result_success'] == "true")
- {
- $this->fullordersmt->save(array('dlz'=>1,'exstate'=>1,'state'=>209),$vv['id']);
- }
- else
- {
- $this->fullordersmt->save(array('dlz'=>2,'exstate'=>1),$vv['id']);
- }
- $l++;
- if($l > 10)
- {
- break;
- }
- }
- }
- $dlz = $this->apismt->get_out($v['waybill'],'all',$v['orderinfo'],$express['aecode'],$shop['code']);
- if(isset($dlz['result_success']) && $dlz['result_success'] == "true")
- {
- $this->fullordersmt->save(array('dlz'=>1,'exstate'=>1,'state'=>209),$v['id']);
- }
- else
- {
- $this->fullordersmt->save(array('dlz'=>2,'exstate'=>1),$v['id']);
- }
- }
- }
- }
|