Specialstock.php 139 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Specialstock extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_specialstock','specialstock');
  7. $this->load->_model('Model_warehouse','warehouse');
  8. $this->load->_model('Model_purchase','purchase');
  9. $this->load->_model('Model_excel','excel');
  10. $this->load->_model('Model_fullorder','fullorder');
  11. $this->load->_model('Model_fullordertt','fullordertt');
  12. $this->load->_model('Model_fullorder_smt','fullorder_smt');
  13. $this->load->_model('Model_fullordersmt','fullordersmt');
  14. $this->load->_model('Model_express','express');
  15. $this->load->_model('Model_shop','shop');
  16. $this->load->_model('Model_typeclass','typeclass');
  17. $this->load->_model('Model_country','country');
  18. $this->load->_model('Model_warehouse','warehouse');
  19. $this->load->_model('Model_kdniao','kdniao');
  20. $this->load->_model('Model_notice','notice');
  21. $this->load->_model('Model_dhl','dhl');
  22. $this->load->_model('Model_shop','shop');
  23. $this->load->_model('Model_fullorderexcel','fullorderexcel');
  24. $this->load->_model('Model_ljg','ljg');
  25. $this->load->_model('Model_usps','usps');
  26. $this->load->_model('Model_whlabelwz','whlabelwz');
  27. $this->load->_model('Model_classid','classid');
  28. }
  29. //定义方法的调用规则 获取URI第二段值
  30. public function _remap($arg,$arg_array)
  31. {
  32. if($arg == 'existence')//在库标签
  33. {
  34. $this->_existence();
  35. }
  36. else if($arg == 'cpbqdc')//在库标签
  37. {
  38. $this->_cpbqdc();
  39. }
  40. else if($arg == 'type')//进销存浏览
  41. {
  42. $this->_type($arg_array);
  43. }
  44. else if($arg == 'xhctype')//现货仓进销存浏览
  45. {
  46. $this->_xhctype($arg_array);
  47. }
  48. else if($arg == 'typedy')//进销存浏览店员浏览
  49. {
  50. $this->_typedy();
  51. }
  52. else if($arg == 'xhctypedy')//现货仓进销存浏览店员浏览
  53. {
  54. $this->_xhctypedy();
  55. }
  56. else if($arg == 'usatype')//美仓进销存浏览
  57. {
  58. $this->_usatype();
  59. }
  60. else if($arg == 'usatypeapp')//美仓APP进销存浏览
  61. {
  62. $this->_usatypeapp();
  63. }
  64. else if($arg == 'enteradd')//入库操作
  65. {
  66. $this->_enteradd();
  67. }
  68. else if($arg == 'enteredit')//修改
  69. {
  70. $this->_enteredit($arg_array);
  71. }
  72. else if($arg == 'enter')//入库浏览
  73. {
  74. $this->_enter();
  75. }
  76. else if($arg == 'xhcenter')//入库浏览
  77. {
  78. $this->_xhcenter();
  79. }
  80. else if($arg == 'out')//出库浏览
  81. {
  82. $this->_out();
  83. }
  84. else if($arg == 'label')//出库标签浏览
  85. {
  86. $this->_label();
  87. }
  88. else if($arg == 'outorder')//独立站出库订单
  89. {
  90. $this->_outorder();
  91. }
  92. else if($arg == 'soutorder')//速卖通出库订单
  93. {
  94. $this->_soutorder();
  95. }
  96. else if($arg == 'retreat')//退库订单
  97. {
  98. $this->_retreat();
  99. }
  100. else if($arg == 'retreatlk')//退库订单
  101. {
  102. $this->_retreatlk();
  103. }
  104. else if($arg == 'change')//更换标签
  105. {
  106. $this->_change();
  107. }
  108. else if($arg == 'del')//删除
  109. {
  110. $this->_del($arg_array);
  111. }
  112. else if($arg == 'exceljxc')//进销存信息导出
  113. {
  114. $this->_exceljxc();
  115. }
  116. else if($arg == 'excelr')//入库信息导出
  117. {
  118. $this->_excelr();
  119. }
  120. else if($arg == 'excelct')//出库、退库信息导出
  121. {
  122. $this->_excelct();
  123. }
  124. else if($arg == 'kcyz')//库存验证
  125. {
  126. $this->_kcyz();
  127. }
  128. else if($arg == 'kj')//库存扣减
  129. {
  130. $this->_kj($arg_array);
  131. }
  132. else if($arg == 'presetout')//预设库存导入
  133. {
  134. $this->_presetout($arg_array);
  135. }
  136. else if($arg == 'presetedit')//预设库存导入
  137. {
  138. $this->_presetedit($arg_array);
  139. }
  140. else if($arg == 'summary')//汇总导出
  141. {
  142. $this->_summary($arg_array);
  143. }
  144. else if($arg == 'manifest')//usps发货清单
  145. {
  146. $this->_manifest();
  147. }
  148. else if($arg == 'abnormal')//占单异常
  149. {
  150. $this->_abnormal();
  151. }
  152. else if($arg == 'error')
  153. {
  154. $this->_error();
  155. }
  156. else if($arg == 'ppkc')
  157. {
  158. $this->_ppkc();
  159. }
  160. else if($arg == 'list')
  161. {
  162. $this->_list($arg_array);
  163. }
  164. else if($arg == 'hwwz')
  165. {
  166. $this->_hwwz();
  167. }
  168. else if($arg == 'order')
  169. {
  170. $this->_order();
  171. }
  172. else if($arg == 'placeorder')
  173. {
  174. $this->_placeorder();
  175. }
  176. else
  177. {
  178. $this->_index();
  179. }
  180. }
  181. public function _del($id_arr)
  182. {
  183. if($id_arr)
  184. {
  185. $id_arr = explode(',',$id_arr);
  186. //循环删除记录
  187. foreach ($id_arr as $value)
  188. {
  189. $data = $this->specialstock->read($value);
  190. $z = $this->specialstock->find_all('sku = "'.$data['sku'].'" and number = "'.$data['number'].'" and zd = "" and state = 0 and warehouse = "'.$data['warehouse'].'" and features = "'.$data['features'].'"');
  191. foreach ($z as $v)
  192. {
  193. $this->specialstock->remove($v['id']);
  194. }
  195. }
  196. return json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  197. }
  198. else
  199. {
  200. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  201. }
  202. }
  203. public function _list($arg_array)
  204. {
  205. $ppid = array();
  206. $number = (isset($arg_array[1]))?$arg_array[1]:'no';
  207. if(!isset($arg_array[2]))
  208. {
  209. echo "特殊产品信息错误!清除浏览器缓存后再试";exit;
  210. }
  211. $hz = '';
  212. $bdck = $this->warehouse->get_bdck('specialstock');
  213. if($bdck)
  214. {
  215. if($bdck['hz'] != '' && stripos($arg_array[2],$bdck['hz']) !== false)
  216. {
  217. $hz = $bdck['hz'];
  218. }
  219. }
  220. if(stripos($arg_array[2],'-') !== false)
  221. {
  222. $dcp = explode('-',$arg_array[2]);
  223. foreach ($dcp as $v)
  224. {
  225. if($hz != '')
  226. {
  227. $ppid[] = trim($v,$hz);
  228. }
  229. else
  230. {
  231. $ppid[] = 0;
  232. }
  233. }
  234. if($hz != '')
  235. {
  236. $xzid = trim($dcp[0],$hz);
  237. }
  238. else
  239. {
  240. $xzid = 0;
  241. }
  242. }
  243. else
  244. {
  245. if($arg_array[2] != 0 && $hz != '')
  246. {
  247. $xzid = trim($arg_array[2],$hz);//已选择产品用
  248. $ppid[] = $xzid;
  249. }
  250. else
  251. {
  252. $xzid = $arg_array[0];//未选择产品用
  253. $ppid[] = 0;
  254. }
  255. }
  256. $thisdata = $this->specialstock->read($xzid);
  257. $data = array();$dataw = array();
  258. //本单已占用的,无论是否已出库
  259. if(stripos($thisdata['featurespp'],'-149') !== false)//如果是360头套 那么也可以匹配370头套
  260. {
  261. $tjd = explode('-',$thisdata['featurespp']);
  262. $dataally = $this->specialstock->find_all("(featurespp = '".$thisdata['featurespp']."' or featurespp = '".$tjd[0]."-".$tjd[1]."-".$tjd[2]."-329"."') and zd = '".$number."'");
  263. }
  264. else
  265. {
  266. $dataally = $this->specialstock->find_all("featurespp = '".$thisdata['featurespp']."' and zd = '".$number."'");
  267. }
  268. foreach ($dataally as $v)
  269. {
  270. $sm = '';
  271. $zd = ($number == $v['zd'])?1:0;
  272. $cpid = ($v['cpid']>0)?' - 编码:'.$v['cpid']:'';
  273. $cpbz = ($v['cpbz']!='')?'<p style="color:#f00">货物说明:'.$v['cpbz'].'</p>':'';
  274. $features = '-';$c = '';
  275. $td = explode('-',trim($v['features'],'-'));
  276. foreach ($td as $va)
  277. {
  278. $s = $this->typeclass->read($va);
  279. if($s['classid'] == '14')
  280. {
  281. $c = $va;
  282. }
  283. else
  284. {
  285. $features .= $va.'-';
  286. }
  287. }
  288. foreach ($ppid as $va)
  289. {
  290. if($va == $v['id'])
  291. {
  292. $sm = '<p style="color:#F00">当前选择的产品</p>';
  293. }
  294. else if(stripos($sm,'当前选择的产品') === false)
  295. {
  296. $sm = '<p style="color:#F00">本单已占用</p>';
  297. }
  298. }
  299. $tp = $this->typeclass->read($c);
  300. $data[] = array('id'=>$v['id'],'z'=>$zd,'title'=>$v['title'].$sm,'features'=>$c.','.$features,'cc'=>$tp['spare'],'num'=>1,'details'=>'位置:'.$v['details'].$cpid.$cpbz,'sm'=>$sm);
  301. }
  302. //未占用的库存
  303. if(stripos($thisdata['featurespp'],'-149') !== false)//如果是360头套 那么也可以匹配370头套
  304. {
  305. $tjd = explode('-',$thisdata['featurespp']);
  306. $dataallw = $this->specialstock->find_all("(featurespp = '".$thisdata['featurespp']."' or featurespp = '".$tjd[0]."-".$tjd[1]."-".$tjd[2]."-329"."') and zd = '' and state = '0'");
  307. }
  308. else
  309. {
  310. $dataallw = $this->specialstock->find_all("featurespp = '".$thisdata['featurespp']."' and zd = '' and state = '0'");
  311. }
  312. foreach ($dataallw as $v)
  313. {
  314. $zd = ($number == $v['zd'])?1:0;
  315. $cpid = ($v['cpid']>0)?' - 编码:'.$v['cpid']:'';
  316. $cpbz = ($v['cpbz']!='')?'<p style="color:#f00">货物说明:'.$v['cpbz'].'</p>':'';
  317. $features = '-';$c = '';
  318. $td = explode('-',trim($v['features'],'-'));
  319. foreach ($td as $va)
  320. {
  321. $sm = '';
  322. $s = $this->typeclass->read($va);
  323. if($s['classid'] == '14')
  324. {
  325. $c = $va;
  326. }
  327. else
  328. {
  329. $features .= $va.'-';
  330. }
  331. foreach ($ppid as $va)
  332. {
  333. if($va == $v['id'])
  334. {
  335. $sm = '<p style="color:#F00">当前选择的产品,需提交后占单</p>';
  336. }
  337. }
  338. }
  339. $tp = $this->typeclass->read($c);
  340. $dataw[] = array('id'=>$v['id'],'z'=>$zd,'title'=>$v['title'].$sm,'ct'=>$v['title'],'features'=>$c.','.$features,'cc'=>$tp['spare'],'num'=>1,'details'=>'位置:'.$v['details'].$cpid.$cpbz);
  341. }
  342. $this->data['data'] = $data;
  343. $this->data['dataw'] = $dataw;
  344. $this->data['id'] = $arg_array[0];
  345. $this->data['ppid'] = $ppid;
  346. $this->_Template('specialstock_list',$this->data);
  347. }
  348. //检查是否匹配特殊库存
  349. public function _ppkc()
  350. {
  351. $post = $this->input->post(NULL, TRUE);
  352. if(isset($post['data']))
  353. {
  354. $data = $this->input->post('data',true);
  355. $number = $this->input->post('number',true);
  356. $whlabel = $this->input->post('whlabel',true);
  357. $data = explode('|',rtrim($data,'|'));
  358. $whlabel = explode('|',trim($whlabel,'|'));
  359. $i = 0;$list = array();$a=array();
  360. foreach ($data as $v)
  361. {
  362. $v = str_replace(array('-163-','-164-','-165-','-166-'),'-',$v);
  363. $vfl = explode('-',trim($v,'-'));
  364. $num = explode('-',trim($whlabel[$i],'-'));
  365. if(isset($vfl[4]))
  366. {
  367. if($vfl[4] == 149)//如果是360头套 那么也可以匹配370头套
  368. {
  369. $pp = $this->specialstock->find_all("featurespp = '".$vfl[0].'-'.$vfl[2].'-'.$vfl[3].'-'.$vfl[4]."' and zd = '' and state = '0'");
  370. if(!$pp)
  371. {
  372. $pp = $this->specialstock->find_all("(featurespp = '".$vfl[0].'-'.$vfl[2].'-'.$vfl[3].'-'.$vfl[4]."' or featurespp = '".$vfl[0].'-'.$vfl[2].'-'.$vfl[3]."-329') and zd = '' and state = '0'");
  373. }
  374. }
  375. else
  376. {
  377. $pp = $this->specialstock->find_all("featurespp = '".$vfl[0].'-'.$vfl[2].'-'.$vfl[3].'-'.$vfl[4]."' and zd = '' and state = '0'");
  378. }
  379. $yzd='';
  380. if(isset($num[2]))
  381. {
  382. preg_match_all('/\d+/',$num[2],$n);
  383. $n = join('',$n[0]);
  384. $yzd = $this->specialstock->find_all("id = '$n' and zd = '$number'");
  385. }
  386. if(count($pp) >= $num[1] && !$yzd)
  387. {
  388. $w = '特殊';//有现货仓的设置后面特殊更改为现货
  389. $list[] = array($i,$pp[0]['id'],$w);
  390. }
  391. else if($yzd)
  392. {
  393. foreach ($yzd as $val)
  394. {
  395. if($num[2] == $val['id'].'z')
  396. {
  397. $w = '特殊';//有现货仓的设置后面特殊更改为现货
  398. $list[] = array($i,$yzd[0]['id'],$w);
  399. }
  400. }
  401. }
  402. }
  403. $i++;
  404. }
  405. if($list)
  406. {
  407. echo json_encode(array('list'=>$list,'success'=>true));exit;
  408. }
  409. }
  410. }
  411. //管理
  412. public function _index()
  413. {
  414. $post = $this->input->post(NULL, TRUE);
  415. if(isset($post['page']))
  416. {
  417. $page = $this->input->post('page',true);
  418. $perpage = $this->input->post('perpage',true);
  419. $sku = $this->input->post('sku',true);
  420. $number = $this->input->post('number',true);
  421. $warehouse = $this->input->post('warehouse',true);
  422. $purchase = $this->input->post('purchase',true);
  423. $orderinfo = $this->input->post('orderinfo',true);
  424. $waybill = $this->input->post('waybill',true);
  425. $category = $this->input->post('category',true);
  426. $size = $this->input->post('size',true);
  427. $grade = $this->input->post('grade',true);
  428. $color = $this->input->post('color',true);
  429. $lowe = $this->input->post('lowe',true);
  430. $state = $this->input->post('state',true);
  431. $label = $this->input->post('label',true);
  432. $timetk = $this->input->post('timetkk',true);
  433. $timetj = $this->input->post('timetjj',true);
  434. $timetk = strtotime($timetk);
  435. $timetj = strtotime($timetj);
  436. $where = "1=1 ";
  437. if($timetk && $timetj)
  438. {
  439. $where .= " and time > '$timetk' and time < '$timetj'";
  440. }
  441. if($sku)
  442. {
  443. $where .= " and sku = '$sku'";
  444. }
  445. if($number)
  446. {
  447. $where .= " and number = '$number'";
  448. }
  449. if($warehouse)
  450. {
  451. $where .= " and warehouse = '$warehouse'";
  452. }
  453. if($purchase)
  454. {
  455. $where .= " and purchase = '$purchase'";
  456. }
  457. if($orderinfo)
  458. {
  459. $where .= " and orderinfo = '$orderinfo'";
  460. }
  461. if($waybill)
  462. {
  463. $where .= " and waybill = '$waybill'";
  464. }
  465. if($category)
  466. {
  467. $where .= " and features like '%-$category-%'";
  468. }
  469. if($size)
  470. {
  471. $where .= " and features like '%-$size-%'";
  472. }
  473. if($grade)
  474. {
  475. $where .= " and features like '%-$grade-%'";
  476. }
  477. if($color)
  478. {
  479. $where .= " and features like '%-$color-%'";
  480. }
  481. if($lowe)
  482. {
  483. $where .= " and features like '%-$lowe-%'";
  484. }
  485. if($label)
  486. {
  487. $where .= " and label = '$label'";
  488. }
  489. if($state || $state == 0)
  490. {
  491. $where .= " and state = '$state'";
  492. }
  493. //数据排序
  494. $order_str = "time desc";
  495. if(empty($page))
  496. {
  497. $start = 0;
  498. $perpage = 1;
  499. }
  500. else
  501. {
  502. $start = ($page - 1)*$perpage;
  503. }
  504. //取得信息列表
  505. $info_list = $this->specialstock->find_all($where,'id,state,purchase,sku,title,label,printing,enter,warehouse,outk,orderinfo,waybill,text,time',$order_str,$start,$perpage);
  506. foreach ($info_list as $key=>$value)
  507. {
  508. $warehouse = $this->warehouse->read($value['warehouse']);
  509. $info_list[$key]['warehouse'] = $warehouse['title'];
  510. $purchase = $this->purchase->read($value['purchase']);
  511. $info_list[$key]['purchase'] = $purchase['title'];
  512. if($value['enter'] != 0)
  513. {
  514. $info_list[$key]['enter'] = '<p>'.date('Y-m-d',$value['enter']).'</p><p>'.date('H:i:s',$value['enter']).'</p>';
  515. }
  516. else
  517. {
  518. $info_list[$key]['enter'] = "";
  519. }
  520. if($value['outk'] != 0)
  521. {
  522. $info_list[$key]['outk'] = '<p>'.date('Y-m-d',$value['outk']).'</p><p>'.date('H:i:s',$value['outk']).'</p>';
  523. }
  524. else
  525. {
  526. $info_list[$key]['outk'] = "";
  527. }
  528. if($value['printing'] != 0)
  529. {
  530. $info_list[$key]['printing'] = '<p>'.date('Y-m-d',$value['printing']).'</p><p>'.date('H:i:s',$value['printing']).'</p>';
  531. }
  532. else
  533. {
  534. $info_list[$key]['printing'] = "";
  535. }
  536. if($value['orderinfo'] == 0)
  537. {
  538. $info_list[$key]['orderinfo'] = "";
  539. }
  540. if($value['waybill'] == 0)
  541. {
  542. $info_list[$key]['waybill'] = "";
  543. }
  544. if($value['state'] == 0)
  545. {
  546. $info_list[$key]['state'] = "在库";
  547. }
  548. else if($value['state'] == 1)
  549. {
  550. $info_list[$key]['state'] = "出库";
  551. }
  552. else if($value['state'] == 2)
  553. {
  554. $info_list[$key]['state'] = "退库";
  555. }
  556. else if($value['state'] == 3)
  557. {
  558. $info_list[$key]['state'] = "调拨中";
  559. }
  560. else if($value['state'] == 4)
  561. {
  562. $info_list[$key]['state'] = "再加工";
  563. }
  564. else if($value['state'] == 5)
  565. {
  566. $info_list[$key]['state'] = "维修中";
  567. }
  568. else if($value['state'] == 6)
  569. {
  570. $info_list[$key]['state'] = "盘亏";
  571. }
  572. else if($value['state'] == 7)
  573. {
  574. $info_list[$key]['state'] = "更换标签";
  575. }
  576. else if($value['state'] == 8)
  577. {
  578. $info_list[$key]['state'] = "其它";
  579. }
  580. else if($value['state'] == 9)
  581. {
  582. $info_list[$key]['state'] = "预设";
  583. }
  584. if($value['text'] == "")
  585. {
  586. $info_list[$key]['text'] = "";
  587. }
  588. $info_list[$key]['time'] = '<p>'.date('Y-m-d',$value['time']).'</p><p>'.date('H:i:s',$value['time']).'</p>';
  589. }
  590. $total = $this->specialstock->find_count($where);
  591. $pagenum = ceil($total/$perpage);
  592. $over = $total-($start+$perpage);
  593. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  594. echo json_encode($rows);exit;
  595. }
  596. if(isset($post['outsku']))
  597. {
  598. $cz = $this->input->post('cz',true);
  599. if($cz == '1')
  600. {
  601. $sku = $this->input->post('outsku',true);
  602. if($sku)
  603. {
  604. $data = $this->specialstock->find_all("sku = '$sku' and zd = '' and state = '0' and warehouse = '5'");
  605. if(count($data) < 1)
  606. {
  607. echo json_encode(array('msg'=>'库存不足!','success'=>false));exit;
  608. }
  609. $this->specialstock->save(array('state'=>10,'outk'=>time(),'time'=>time()),$data[0]['id']);
  610. echo json_encode(array('success'=>true));exit;
  611. }
  612. }
  613. else
  614. {
  615. $sku = $this->input->post('outsku',true);
  616. if($sku)
  617. {
  618. $data = $this->specialstock->find_all("sku = '$sku' and state = '10' and warehouse = '5'");
  619. if(count($data) < 1)
  620. {
  621. echo json_encode(array('msg'=>'没有此SKU出库数据!','success'=>false));exit;
  622. }
  623. $this->specialstock->save(array('state'=>0,'outk'=>0,'time'=>time()),$data[0]['id']);
  624. echo json_encode(array('success'=>true));exit;
  625. }
  626. }
  627. }
  628. $this->data['url'] = str_replace('/','',$this->uri->slash_segment(2));
  629. $this->_Template('specialstock',$this->data);
  630. }
  631. //在库标签
  632. public function _existence()
  633. {
  634. $post = $this->input->post(NULL, TRUE);
  635. if(isset($post['s']))
  636. {
  637. $id_arr = $this->input->post('s');
  638. $id_arr = explode(',',$id_arr);
  639. if(!$id_arr)
  640. {
  641. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  642. }
  643. //循环删除记录
  644. foreach ($id_arr as $v)
  645. {
  646. $this->specialstock->remove($v);
  647. }
  648. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));exit;
  649. }
  650. if(isset($post['page']))
  651. {
  652. $page = $this->input->post('page',true);
  653. $perpage = $this->input->post('perpage',true);
  654. $warehouse = $this->input->post('warehouse',true);
  655. $label = $this->input->post('label',true);
  656. $where = "1=1 and state = 0";
  657. if($warehouse)
  658. {
  659. $where .= " and warehouse = '$warehouse'";
  660. }
  661. if($label)
  662. {
  663. $where .= " and label = '$label'";
  664. }
  665. //数据排序
  666. $order_str = "time asc";
  667. if(empty($page))
  668. {
  669. $start = 0;
  670. $perpage = 1;
  671. }
  672. else
  673. {
  674. $start = ($page - 1)*$perpage;
  675. }
  676. //取得信息列表
  677. $info_list = $this->specialstock->find_all($where,'id,sku,title,label,printing,enter',$order_str,$start,$perpage);
  678. foreach ($info_list as $key=>$value)
  679. {
  680. if($value['enter'] != 0)
  681. {
  682. $info_list[$key]['enter'] = date('Y-m-d H:i:s',$value['enter']);
  683. }
  684. else
  685. {
  686. $info_list[$key]['enter'] = "";
  687. }
  688. if($value['printing'] != 0)
  689. {
  690. $info_list[$key]['printing'] = date('Y-m-d H:i:s',$value['printing']);
  691. }
  692. else
  693. {
  694. $info_list[$key]['printing'] = "";
  695. }
  696. }
  697. $total = $this->specialstock->find_count($where);
  698. $pagenum = ceil($total/$perpage);
  699. $over = $total-($start+$perpage);
  700. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  701. echo json_encode($rows);exit;
  702. }
  703. $this->_Template('specialstock_existence',$this->data);
  704. }
  705. public function _typedy()
  706. {
  707. $post = $this->input->post(NULL, TRUE);
  708. if(isset($post['page']))
  709. {
  710. $page = $this->input->post('page',true);
  711. $perpage = $this->input->post('perpage',true);
  712. $category = $this->input->post('category',true);
  713. $size = $this->input->post('size',true);
  714. $grade = $this->input->post('grade',true);
  715. $color = $this->input->post('color',true);
  716. $lowe = $this->input->post('lowe',true);
  717. $sku = $this->input->post('sku');
  718. $title = $this->input->post('title');
  719. $warehouse = $this->input->post('warehouse',true);
  720. $usa = $this->input->post('usa',true);
  721. $purchase = $this->input->post('purchase',true);
  722. $lacetype = $this->input->post('lacetype',true);
  723. $haircap = $this->input->post('haircap',true);
  724. $density = $this->input->post('density',true);
  725. $details = $this->input->post('details',true);
  726. $state = $this->input->post('state',true);
  727. $ktime = $this->input->post('ktime',true);
  728. $jtime = $this->input->post('jtime',true);
  729. $ktime = strtotime($ktime);
  730. $jtime = strtotime($jtime);
  731. $where = "1=1";$gj = "";$ck = "";
  732. if($lacetype)
  733. {
  734. $where .= " and features like '%-$lacetype-%'";
  735. }
  736. if($category)
  737. {
  738. $where .= " and features like '%-$category-%'";
  739. }
  740. if($size)
  741. {
  742. $where .= " and features like '%-$size-%'";
  743. }
  744. if($grade)
  745. {
  746. $where .= " and features like '%-$grade-%'";
  747. }
  748. if($color)
  749. {
  750. $where .= " and features like '%-$color-%'";
  751. }
  752. if($lowe)
  753. {
  754. $where .= " and features like '%-$lowe-%'";
  755. }
  756. if($haircap)
  757. {
  758. $where .= " and features like '%-$haircap-%'";
  759. }
  760. if($density)
  761. {
  762. $where .= " and features like '%-$density-%'";
  763. }
  764. if($usa)
  765. {
  766. if(!$warehouse)
  767. {
  768. $where .= " and (warehouse = '5' or warehouse = '8')";
  769. }
  770. }
  771. if($warehouse)
  772. {
  773. $where .= " and warehouse = '$warehouse'";
  774. }
  775. if($details)
  776. {
  777. $where .= " and details = '$details'";
  778. }
  779. if($purchase)
  780. {
  781. $where .= " and purchase = '$purchase'";
  782. }
  783. if($state)
  784. {
  785. $where .= " and state = '$state'";
  786. }
  787. if($ktime && $jtime)
  788. {
  789. $gj = " and enter > '$ktime' and enter < '$jtime'";
  790. $ck = " and outk > '$ktime' and outk < '$jtime'";
  791. }
  792. //数据排序
  793. $order_str = "id desc";
  794. if(empty($page))
  795. {
  796. $start = 0;
  797. $perpage = 1;
  798. }
  799. else
  800. {
  801. $start = ($page - 1)*$perpage;
  802. }
  803. if($sku)
  804. {
  805. $sku = trim($sku,' ');
  806. $sku = trim($sku,' ');
  807. $where .= " and sku like '%$sku%'";
  808. $info_list = $this->specialstock->find_pc($where,'sku,features,warehouse','id,sku,title,details,cpbz,features,number',$order_str,$start,$perpage);
  809. }
  810. else if($title)
  811. {
  812. $title = trim($title,' ');
  813. $title = trim($title,' ');
  814. $where .= " and title like '%$title%'";
  815. $info_list = $this->specialstock->find_pc($where,'sku,features,warehouse','id,sku,title,details,cpbz,features,number',$order_str,$start,$perpage);
  816. }
  817. else
  818. {
  819. //$where .= " and time > '$ktime' and time < '$jtime'";
  820. $info_list = $this->specialstock->find_pc($where,'sku,features,warehouse','id,sku,title,details,cpbz,features,number',$order_str,$start,$perpage);
  821. }
  822. //取得信息列表
  823. $rows = array();$list = array();
  824. foreach ($info_list as $key=>$value)
  825. {
  826. $wid = $this->specialstock->read($value['id']);
  827. $c = $this->specialstock->find_all($where.' and sku = "'.$value['sku'].'" and state = 0 and warehouse = "'.$wid['warehouse'].'" and features = "'.$value['features'].'"','details,cpid');
  828. $z = $this->specialstock->find_all($where.' and sku = "'.$value['sku'].'" and zd != "" and state = 0 and warehouse = "'.$wid['warehouse'].'" and features = "'.$value['features'].'"');
  829. $number = $value['number'];$ftime = time()-15*24*3600;
  830. $z = count($z);//查看订单号
  831. $info_list[$key]['features'] = count($c);
  832. $info_list[$key]['number'] = $z;
  833. $details = array();
  834. $cpid = array();
  835. foreach ($c as $k=>$v)
  836. {
  837. $details[$v['details']] = $v['details'];
  838. if($v['cpid'] != 0)
  839. {
  840. $cpid[$v['cpid']] = $v['cpid'];
  841. }
  842. }
  843. $info_list[$key]['details'] = ($cpid)?implode(" ",$details).'<p>'.implode(" ",$cpid).'</p>':implode(" ",$details);
  844. }
  845. $total = count($this->specialstock->find_pc($where,'sku,features,warehouse','id,warehouse,sku,title,features,number'));
  846. $pagenum = ceil($total/$perpage);
  847. $over = $total-($start+$perpage);
  848. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list),'CS'=>$warehouse);
  849. echo json_encode($rows);exit;
  850. }
  851. $this->_Template('specialstock_typedy',$this->data);
  852. }
  853. //进销存浏览
  854. public function _type($arg_array)
  855. {
  856. $vip = 0;
  857. if(isset($_SESSION['api']))
  858. {
  859. $user = $this->user->get_api($_SESSION['api']);
  860. if($user['vip'] == 1)
  861. {
  862. $vip = 1;
  863. }
  864. }
  865. else
  866. {
  867. header('Location: /');exit;
  868. }
  869. if(isset($arg_array[0]))
  870. {
  871. if($arg_array[0] == 'del')
  872. {
  873. $s = $this->input->post('s',true);
  874. $del = $this->_0kcdel($s);
  875. echo $del;exit;
  876. }
  877. }
  878. $post = $this->input->post(NULL, TRUE);
  879. if(isset($post['page']))
  880. {
  881. $page = $this->input->post('page',true);
  882. $perpage = $this->input->post('perpage',true);
  883. $category = $this->input->post('category',true);
  884. $size = $this->input->post('size',true);
  885. $grade = $this->input->post('grade',true);
  886. $color = $this->input->post('color',true);
  887. $lowe = $this->input->post('lowe',true);
  888. $sku = $this->input->post('sku');
  889. $title = $this->input->post('title');
  890. $warehouse = $this->input->post('warehouse',true);
  891. $usa = $this->input->post('usa',true);
  892. $purchase = $this->input->post('purchase',true);
  893. $lacetype = $this->input->post('lacetype',true);
  894. $haircap = $this->input->post('haircap',true);
  895. $density = $this->input->post('density',true);
  896. $details = $this->input->post('details',true);
  897. $state = $this->input->post('state',true);
  898. $ktime = $this->input->post('ktime',true);
  899. $jtime = $this->input->post('jtime',true);
  900. $ktime = strtotime($ktime);
  901. $jtime = strtotime($jtime);
  902. $where = "1=1";$gj = "";$ck = "";
  903. if($lacetype)
  904. {
  905. $where .= " and features like '%-$lacetype-%'";
  906. }
  907. if($category)
  908. {
  909. $where .= " and features like '%-$category-%'";
  910. }
  911. if($size)
  912. {
  913. $where .= " and features like '%-$size-%'";
  914. }
  915. if($grade)
  916. {
  917. $where .= " and features like '%-$grade-%'";
  918. }
  919. if($color)
  920. {
  921. $where .= " and features like '%-$color-%'";
  922. }
  923. if($lowe)
  924. {
  925. $where .= " and features like '%-$lowe-%'";
  926. }
  927. if($haircap)
  928. {
  929. $where .= " and features like '%-$haircap-%'";
  930. }
  931. if($density)
  932. {
  933. $where .= " and features like '%-$density-%'";
  934. }
  935. if($usa)
  936. {
  937. if(!$warehouse)
  938. {
  939. $where .= " and (warehouse = '5' or warehouse = '8')";
  940. }
  941. }
  942. if($warehouse)
  943. {
  944. $where .= " and warehouse = '$warehouse'";
  945. }
  946. if($details)
  947. {
  948. $where .= " and details = '$details'";
  949. }
  950. if($purchase)
  951. {
  952. $where .= " and purchase = '$purchase'";
  953. }
  954. if($state)
  955. {
  956. $where .= " and state = '$state'";
  957. }
  958. if($ktime && $jtime)
  959. {
  960. $gj = " and enter > '$ktime' and enter < '$jtime'";
  961. $ck = " and outk > '$ktime' and outk < '$jtime'";
  962. }
  963. //数据排序
  964. $order_str = "id desc";
  965. if(empty($page))
  966. {
  967. $start = 0;
  968. $perpage = 1;
  969. }
  970. else
  971. {
  972. $start = ($page - 1)*$perpage;
  973. }
  974. if($sku)
  975. {
  976. $sku = trim($sku,' ');
  977. $sku = trim($sku,' ');
  978. $where .= " and sku like '%$sku%'";
  979. $info_list = $this->specialstock->find_pc($where,'sku,features,warehouse','id,sku,title,details,cpbz,features',$order_str,$start,$perpage);
  980. }
  981. else if($title)
  982. {
  983. $title = trim($title,' ');
  984. $title = trim($title,' ');
  985. $where .= " and title like '%$title%'";
  986. $info_list = $this->specialstock->find_pc($where,'sku,features,warehouse','id,sku,title,details,cpbz,features',$order_str,$start,$perpage);
  987. }
  988. else
  989. {
  990. //$where .= " and time > '$ktime' and time < '$jtime'";
  991. $info_list = $this->specialstock->find_pc($where,'sku,features,warehouse','id,sku,title,details,cpbz,features',$order_str,$start,$perpage);
  992. }
  993. //取得信息列表
  994. $rows = array();$list = array();
  995. foreach ($info_list as $key=>$value)
  996. {
  997. $wid = $this->specialstock->read($value['id']);
  998. $c = $this->specialstock->find_all($where.' and sku = "'.$value['sku'].'" and state = 0 and warehouse = "'.$wid['warehouse'].'" and features = "'.$value['features'].'"','details,cpid');
  999. $g = $this->specialstock->find_count($where.$gj.' and sku = "'.$value['sku'].'" and state < 100 and warehouse = "'.$wid['warehouse'].'" and features = "'.$value['features'].'"');
  1000. $x = $this->specialstock->find_count($where.$ck.' and sku = "'.$value['sku'].'" and state = 1 and warehouse = "'.$wid['warehouse'].'" and features = "'.$value['features'].'"');
  1001. $t = $this->specialstock->find_count($where.$ck.' and sku = "'.$value['sku'].'" and retreat > 0 and warehouse = "'.$wid['warehouse'].'"');
  1002. $z = $this->specialstock->find_all($where.' and sku = "'.$value['sku'].'" and zd != "" and state = 0 and warehouse = "'.$wid['warehouse'].'" and features = "'.$value['features'].'"');
  1003. $od = array();$odid = '';
  1004. foreach ($z as $v)
  1005. {
  1006. if(!isset($od[$v['zd']]))
  1007. {
  1008. $od[$v['zd']] = 1;//所有数据sku
  1009. }
  1010. else
  1011. {
  1012. $od[$v['zd']] = $od[$v['zd']]+1;
  1013. }
  1014. }
  1015. foreach ($od as $k=>$vv)
  1016. {
  1017. $odid .= $k.'数量'.$vv;
  1018. }
  1019. $ftime = time()-15*24*3600;
  1020. $z = count($z).'('.$odid.')';//查看订单号
  1021. $info_list[$key]['features'] = count($c);
  1022. $info_list[$key]['g'] = $g;
  1023. $info_list[$key]['x'] = $x;
  1024. $info_list[$key]['t'] = $t;
  1025. $info_list[$key]['z'] = $z;
  1026. $details = array();
  1027. $cpid = array();
  1028. foreach ($c as $k=>$v)
  1029. {
  1030. $details[$v['details']] = $v['details'];
  1031. if($v['cpid'] != 0)
  1032. {
  1033. $cpid[$v['cpid']] = $v['cpid'];
  1034. }
  1035. }
  1036. $info_list[$key]['details'] = ($cpid)?implode(" ",$details).'<p>'.implode(" ",$cpid).'</p>':implode(" ",$details);
  1037. }
  1038. $total = count($this->specialstock->find_pc($where,'sku,features,warehouse','id,warehouse,sku,title,features'));
  1039. $pagenum = ceil($total/$perpage);
  1040. $over = $total-($start+$perpage);
  1041. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  1042. echo json_encode($rows);exit;
  1043. }
  1044. $this->data['vip'] = $vip;
  1045. $this->_Template('specialstock_type',$this->data);
  1046. }
  1047. public function _xhctypedy()
  1048. {
  1049. $post = $this->input->post(NULL, TRUE);
  1050. if(isset($post['page']))
  1051. {
  1052. $page = $this->input->post('page',true);
  1053. $perpage = $this->input->post('perpage',true);
  1054. $category = $this->input->post('category',true);
  1055. $size = $this->input->post('size',true);
  1056. $grade = $this->input->post('grade',true);
  1057. $color = $this->input->post('color',true);
  1058. $lowe = $this->input->post('lowe',true);
  1059. $sku = $this->input->post('sku',true);
  1060. $details = $this->input->post('details',true);
  1061. $warehouse = $this->input->post('warehouse',true);
  1062. $purchase = $this->input->post('purchase',true);
  1063. $lacetype = $this->input->post('lacetype',true);
  1064. $state = $this->input->post('state',true);
  1065. $ktime = $this->input->post('ktime',true);
  1066. $jtime = $this->input->post('jtime',true);
  1067. $ktime = strtotime($ktime);
  1068. $jtime = strtotime($jtime);
  1069. $where = "warehouse != '12'";$gj = "";$ck = "";
  1070. if($category)
  1071. {
  1072. $where .= " and features like '%-$category-%'";
  1073. }
  1074. if($size)
  1075. {
  1076. $where .= " and features like '%-$size-%'";
  1077. }
  1078. if($grade)
  1079. {
  1080. $where .= " and features like '%-$grade-%'";
  1081. }
  1082. if($color)
  1083. {
  1084. $where .= " and features like '%-$color-%'";
  1085. }
  1086. if($lowe)
  1087. {
  1088. $where .= " and features like '%-$lowe-%'";
  1089. }
  1090. if($lacetype)
  1091. {
  1092. $where .= " and features like '%-$lacetype-%'";
  1093. }
  1094. if($warehouse)
  1095. {
  1096. $where .= " and warehouse = '$warehouse'";
  1097. }
  1098. if($purchase)
  1099. {
  1100. $where .= " and purchase = '$purchase'";
  1101. }
  1102. if($state)
  1103. {
  1104. $where .= " and state = '$state'";
  1105. }
  1106. if($sku)
  1107. {
  1108. $where .= " and sku like '%$sku%'";
  1109. }
  1110. if($details)
  1111. {
  1112. $where .= " and details like '%$details%'";
  1113. }
  1114. if($ktime && $jtime)
  1115. {
  1116. $gj = " and enter > '$ktime' and enter < '$jtime'";
  1117. $ck = " and outk > '$ktime' and outk < '$jtime'";
  1118. }
  1119. //数据排序
  1120. $order_str = "id desc";
  1121. if(empty($page))
  1122. {
  1123. $start = 0;
  1124. $perpage = 1;
  1125. }
  1126. else
  1127. {
  1128. $start = ($page - 1)*$perpage;
  1129. }
  1130. //取得信息列表
  1131. $info_list = $this->specialstock->find_all($where,'*');
  1132. $rows = array();$list = array();
  1133. foreach ($info_list as $key=>$value)
  1134. {
  1135. $rows[$value['number'].$value['details'].$value['warehouse']] = $value;//所有数据sku
  1136. }
  1137. foreach ($rows as $k=>$value)
  1138. {
  1139. $c = $this->specialstock->find_count($where.' and sku = "'.$value['sku'].'" and details = "'.$value['details'].'" and state = 0 and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"');
  1140. if($c < 1)
  1141. {
  1142. unset($rows[$k]);
  1143. }
  1144. }
  1145. $rowsdq = array_slice($rows,$start,$perpage);
  1146. foreach ($rowsdq as $value)
  1147. {
  1148. $warehouse = $this->warehouse->read($value['warehouse']);
  1149. $c = $this->specialstock->find_count($where.' and sku = "'.$value['sku'].'" and details = "'.$value['details'].'" and state = 0 and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"');
  1150. $z = $this->specialstock->find_all($where.' and sku = "'.$value['sku'].'" and details = "'.$value['details'].'" and zd != "" and state = 0 and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"');
  1151. $number = $value['number'];$ftime = time()-15*24*3600;
  1152. $z = count($z);//查看订单号
  1153. //$z = $od;
  1154. $list[] = array('id'=>$value['id'],'sku'=>$value['sku'],'title'=>$value['title'],'wz'=>$value['details'],'bz'=>$value['cpbz'],'c'=>$c,'z'=>$z);
  1155. }
  1156. $total = count($rows);
  1157. $pagenum = ceil($total/$perpage);
  1158. $over = $total-($start+$perpage);
  1159. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  1160. echo json_encode($rows);exit;
  1161. }
  1162. $this->_Template('specialstock_xhctypedy',$this->data);
  1163. }
  1164. //进销存浏览
  1165. public function _xhctype($arg_array)
  1166. {
  1167. $post = $this->input->post(NULL, TRUE);
  1168. if(isset($arg_array[0]))
  1169. {
  1170. if($arg_array[0] == 'del')
  1171. {
  1172. $s = $this->input->post('s',true);
  1173. $del = $this->_del($s);
  1174. echo $del;exit;
  1175. }
  1176. }
  1177. if(isset($post['page']))
  1178. {
  1179. $page = $this->input->post('page',true);
  1180. $perpage = $this->input->post('perpage',true);
  1181. $category = $this->input->post('category',true);
  1182. $size = $this->input->post('size',true);
  1183. $grade = $this->input->post('grade',true);
  1184. $color = $this->input->post('color',true);
  1185. $lowe = $this->input->post('lowe',true);
  1186. $sku = $this->input->post('sku',true);
  1187. $details = $this->input->post('details',true);
  1188. $warehouse = $this->input->post('warehouse',true);
  1189. $purchase = $this->input->post('purchase',true);
  1190. $lacetype = $this->input->post('lacetype',true);
  1191. $state = $this->input->post('state',true);
  1192. $ktime = $this->input->post('ktime',true);
  1193. $jtime = $this->input->post('jtime',true);
  1194. $ktime = strtotime($ktime);
  1195. $jtime = strtotime($jtime);
  1196. $where = "warehouse != '12'";$gj = "";$ck = "";
  1197. if($category)
  1198. {
  1199. $where .= " and features like '%-$category-%'";
  1200. }
  1201. if($size)
  1202. {
  1203. $where .= " and features like '%-$size-%'";
  1204. }
  1205. if($grade)
  1206. {
  1207. $where .= " and features like '%-$grade-%'";
  1208. }
  1209. if($color)
  1210. {
  1211. $where .= " and features like '%-$color-%'";
  1212. }
  1213. if($lowe)
  1214. {
  1215. $where .= " and features like '%-$lowe-%'";
  1216. }
  1217. if($lacetype)
  1218. {
  1219. $where .= " and features like '%-$lacetype-%'";
  1220. }
  1221. if($warehouse)
  1222. {
  1223. $where .= " and warehouse = '$warehouse'";
  1224. }
  1225. if($purchase)
  1226. {
  1227. $where .= " and purchase = '$purchase'";
  1228. }
  1229. if($state)
  1230. {
  1231. $where .= " and state = '$state'";
  1232. }
  1233. if($sku)
  1234. {
  1235. $where .= " and sku like '%$sku%'";
  1236. }
  1237. if($details)
  1238. {
  1239. $where .= " and details like '%$details%'";
  1240. }
  1241. if($ktime && $jtime)
  1242. {
  1243. $gj = " and enter > '$ktime' and enter < '$jtime'";
  1244. $ck = " and outk > '$ktime' and outk < '$jtime'";
  1245. }
  1246. //数据排序
  1247. $order_str = "id desc";
  1248. if(empty($page))
  1249. {
  1250. $start = 0;
  1251. $perpage = 1;
  1252. }
  1253. else
  1254. {
  1255. $start = ($page - 1)*$perpage;
  1256. }
  1257. //取得信息列表
  1258. $info_list = $this->specialstock->find_all($where,'*');
  1259. $rows = array();$list = array();
  1260. foreach ($info_list as $key=>$value)
  1261. {
  1262. $rows[$value['number'].$value['details'].$value['warehouse']] = $value;//所有数据sku
  1263. }
  1264. $rowsdq = array_slice($rows,$start,$perpage);
  1265. foreach ($rowsdq as $k=>$value)
  1266. {
  1267. $warehouse = $this->warehouse->read($value['warehouse']);
  1268. $c = $this->specialstock->find_count($where.' and sku = "'.$value['sku'].'" and details = "'.$value['details'].'" and state = 0 and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"');
  1269. $g = $this->specialstock->find_count($where.$gj.' and sku = "'.$value['sku'].'" and details = "'.$value['details'].'" and state < 100 and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"');
  1270. $x = $this->specialstock->find_count($where.$ck.' and sku = "'.$value['sku'].'" and details = "'.$value['details'].'" and state = 1 and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"');
  1271. $t = $this->specialstock->find_count($where.$ck.' and sku = "'.$value['sku'].'" and details = "'.$value['details'].'" and retreat > 0 and warehouse = "'.$value['warehouse'].'"');
  1272. $z = $this->specialstock->find_all($where.' and sku = "'.$value['sku'].'" and details = "'.$value['details'].'" and zd != "" and state = 0 and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"');
  1273. $od = array();$odid = '';
  1274. foreach ($z as $v)
  1275. {
  1276. if(!isset($od[$v['zd']]))
  1277. {
  1278. $od[$v['zd']] = 1;//所有数据sku
  1279. }
  1280. else
  1281. {
  1282. $od[$v['zd']] = $od[$v['zd']]+1;
  1283. }
  1284. }
  1285. foreach ($od as $k=>$vv)
  1286. {
  1287. $odid .= $k.'数量'.$vv;
  1288. }
  1289. $number = $value['number'];$ftime = time()-15*24*3600;
  1290. /**
  1291. if($value['shop'] != '')
  1292. {
  1293. $shop = $value['shop'];
  1294. $orderdlz = $this->fullorder->find_all("time > '$ftime' and shop = '$shop' and type = '".$value['warehouse']."' and library = '1' and state = '207' and specialstock like '%|$number-%'",'specialstock,shop,orderinfo,number');
  1295. $ordersmt = $this->fullordersmt->find_all("time > '$ftime' and shop = '$shop' and type = '".$value['warehouse']."' and library = '1' and state = '207' and specialstock like '%|$number-%'",'specialstock,shop,orderinfo,number');
  1296. $order = array_merge($orderdlz,$ordersmt);
  1297. $od = 0;$a = '';$orid = '';
  1298. foreach ($order as $v)
  1299. {
  1300. $or = explode('|',ltrim($v['specialstock'],'|'));
  1301. for($i=0;$i<count($or);$i++)
  1302. {
  1303. $orod = explode('-',$or[$i]);
  1304. if($orod[0] == $number)
  1305. {
  1306. $od += $orod[1];
  1307. }
  1308. }
  1309. $orid .= $v['number'].'-';
  1310. }
  1311. }
  1312. else
  1313. {
  1314. $orderdlz = $this->fullorder->find_all("time > '$ftime' and type = '".$value['warehouse']."' and library = '1' and state = '207' and specialstock like '%|$number-%'",'specialstock,shop,orderinfo,number');
  1315. $ordersmt = $this->fullordersmt->find_all("time > '$ftime' and type = '".$value['warehouse']."' and library = '1' and state = '207' and specialstock like '%|$number-%'",'specialstock,shop,orderinfo,number');
  1316. $order = array_merge($orderdlz,$ordersmt);
  1317. $od = 0;$a = '';$orid = '';$qt = array();
  1318. foreach ($order as $v)
  1319. {
  1320. $or = explode('|',ltrim($v['specialstock'],'|'));
  1321. for($i=0;$i<count($or);$i++)
  1322. {
  1323. $orod = explode('-',$or[$i]);
  1324. if($orod[0] == $number)
  1325. {
  1326. $czzs = $this->specialstock->find_count("number = '$number' and warehouse = '".$value['warehouse']."' and shop = '".$v['shop']."' and state = 0");
  1327. if($czzs > 0)
  1328. {
  1329. if(isset($qt[$v['shop']]))
  1330. {
  1331. if($qt[$v['shop']] < $orod[1])
  1332. {
  1333. $od += $orod[1];//专属小于单量不计算剩余直接归入通用
  1334. $orid .= $v['number'].'+数量'.$orod[1].'-';
  1335. }
  1336. else
  1337. {
  1338. $qt[$v['shop']] -= $orod[1];
  1339. }
  1340. }
  1341. else
  1342. {
  1343. $qt[$v['shop']] = $czzs;
  1344. }
  1345. }
  1346. else
  1347. {
  1348. $od += $orod[1];
  1349. $orid .= $v['number'].'+数量'.$orod[1].'-';
  1350. }
  1351. }
  1352. }
  1353. }
  1354. }
  1355. **/
  1356. $z = count($z).'('.$odid.')';//查看订单号
  1357. //$z = $od;
  1358. $wz = ($value['cpid'] > 0)?$value['details'].'-'.$value['cpid']:$value['details'];
  1359. $list[] = array('id'=>$value['id'],'sku'=>$value['sku'],'title'=>$value['title'],'wz'=>$wz,'bz'=>$value['cpbz'],'c'=>$c,'g'=>$g,'x'=>$x,'t'=>$t,'z'=>$z);
  1360. }
  1361. $total = count($rows);
  1362. $pagenum = ceil($total/$perpage);
  1363. $over = $total-($start+$perpage);
  1364. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  1365. echo json_encode($rows);exit;
  1366. }
  1367. $this->_Template('specialstock_xhctype',$this->data);
  1368. }
  1369. //美仓进销存浏览
  1370. public function _usatype()
  1371. {
  1372. $this->_Template('specialstock_typeusa',$this->data);
  1373. }
  1374. //美仓进销存浏览
  1375. public function _usatypeapp()
  1376. {
  1377. $post = $this->input->post(NULL, TRUE);
  1378. if(isset($post['page']))
  1379. {
  1380. $page = $this->input->post('page',true);
  1381. $perpage = $this->input->post('perpage',true);
  1382. $sku = $this->input->post('sku',true);
  1383. $warehouse = '5';
  1384. $title = $this->input->post('title',true);
  1385. $state = $this->input->post('state',true);
  1386. $ktime = $this->input->post('ktime',true);
  1387. $jtime = $this->input->post('jtime',true);
  1388. $ktime = strtotime($ktime);
  1389. $jtime = strtotime($jtime);
  1390. $where = "1=1";$gj = "";$ck = "";
  1391. if($title)
  1392. {
  1393. $st = explode(' ',trim($title,' '));
  1394. foreach ($st as $v)
  1395. {
  1396. $where .= " and title like '%$v%'";
  1397. }
  1398. }
  1399. if($warehouse)
  1400. {
  1401. $where .= " and warehouse = '$warehouse'";
  1402. }
  1403. if($state)
  1404. {
  1405. $where .= " and state = '$state'";
  1406. }
  1407. if($sku)
  1408. {
  1409. $where .= " and sku like '%$sku%'";
  1410. }
  1411. if($ktime && $jtime)
  1412. {
  1413. $gj = " and enter > '$ktime' and enter < '$jtime'";
  1414. $ck = " and outk > '$ktime' and outk < '$jtime'";
  1415. }
  1416. //数据排序
  1417. $order_str = "id desc";
  1418. if(empty($page))
  1419. {
  1420. $start = 0;
  1421. $perpage = 1;
  1422. }
  1423. else
  1424. {
  1425. $start = ($page - 1)*$perpage;
  1426. }
  1427. //取得信息列表
  1428. $info_list = $this->specialstock->find_all($where,'*');
  1429. $rows = array();$list = array();
  1430. foreach ($info_list as $key=>$value)
  1431. {
  1432. $rows[$value['sku'].'warehouse'.$value['warehouse']] = $value;//所有数据sku
  1433. }
  1434. $rowsdq = array_slice($rows,$start,$perpage);
  1435. foreach ($rowsdq as $value)
  1436. {
  1437. $warehouse = $this->warehouse->read($value['warehouse']);
  1438. $c = $this->specialstock->find_count($where.' and sku = "'.$value['sku'].'" and state = 0 and warehouse = "'.$value['warehouse'].'"');
  1439. $x = $this->specialstock->find_count($where.' and sku = "'.$value['sku'].'" and state = 1 and warehouse = "'.$value['warehouse'].'"');
  1440. $t = $this->specialstock->find_count($where.' and sku = "'.$value['sku'].'" and retreat > 0 and warehouse = "'.$value['warehouse'].'"');
  1441. $od = array();$odid = '';
  1442. $list[] = array('id'=>$value['id'],'sku'=>$value['sku'],'title'=>$value['title'],'c'=>$c,'x'=>$x,'t'=>$t);
  1443. }
  1444. $total = count($rows);
  1445. $pagenum = ceil($total/$perpage);
  1446. $over = $total-($start+$perpage);
  1447. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  1448. echo json_encode($rows);exit;
  1449. }
  1450. $this->_Template('phone/p_usatypeapp',$this->data);
  1451. }
  1452. //入库操作
  1453. public function _enteradd()
  1454. {
  1455. $dt = 0;
  1456. if(isset($_SESSION['api']))
  1457. {
  1458. $user = $this->user->get_api($_SESSION['api']);
  1459. $usp = $user;
  1460. $fgshop = "";$sid = "";
  1461. $user = explode('|',trim($user['shop'],'|'));
  1462. foreach ($user as $value)
  1463. {
  1464. $fgshop .= " shop = ".$value." or";
  1465. $sid .= " id = ".$value." or";
  1466. }
  1467. }
  1468. $post = $this->input->post(NULL, TRUE);
  1469. if(isset($post['details']))
  1470. {
  1471. $list = array();$num = "";$title = "";$features = "";$state=0;//正常入库
  1472. $order = $this->input->post('order',true);
  1473. $post['details'] = $this->input->post('details',true);
  1474. $post['sku'] = $this->input->post('sku',true);
  1475. $category = $this->input->post('category',true);
  1476. $list['category'] = $category;
  1477. $list['hairtype'] = $this->input->post('hairtype',true);
  1478. $list['grade'] = $this->input->post('grade',true);
  1479. $size = $this->input->post('size',true);
  1480. $list['size'] = rtrim($size,',');
  1481. $list['hairnumber'] = $this->input->post('hairnumber',true);
  1482. $list['extension'] = $this->input->post('extension',true);
  1483. if($category == 1297)
  1484. {
  1485. $list['sywignumber'] = $this->input->post('sywignumber',true);
  1486. }
  1487. if($category == 1702)
  1488. {
  1489. $list['syhairnumber'] = $this->input->post('syhairnumber',true);
  1490. $list['syother'] = $this->input->post('syother',true);
  1491. }
  1492. if($category == 133)
  1493. {
  1494. $list['fittype'] = $this->input->post('fittype',true);
  1495. $list['acother'] = $this->input->post('acother',true);
  1496. }
  1497. $list['color'] = $this->input->post('color',true);
  1498. $list['lowe'] = $this->input->post('lowe',true);
  1499. $post['warehouse'] = $this->input->post('warehouse',true);
  1500. if($category == 127)
  1501. {
  1502. $list['type'] = $this->input->post('type',true);
  1503. $list['headroad'] = $this->input->post('headroad',true);
  1504. $list['density'] = $this->input->post('density',true);
  1505. if($list['type'] == 195 || $list['type'] == 197 || $list['type'] == 199)
  1506. {
  1507. $list['lacesize'] = $this->input->post('lacesize',true);
  1508. }
  1509. $list['lacecolor'] = $this->input->post('lacecolor',true);
  1510. $list['lacetypes'] = $this->input->post('lacetypes',true);
  1511. }
  1512. if($category == 128)
  1513. {
  1514. $list['lacetype'] = $this->input->post('lacetype',true);
  1515. $list['haircap'] = $this->input->post('haircap',true);
  1516. $list['density'] = $this->input->post('density',true);
  1517. $list['lacecolor'] = $this->input->post('lacecolor',true);
  1518. $list['lacetypes'] = $this->input->post('lacetypes',true);
  1519. $list['wigother'] = $this->input->post('wigother',true);
  1520. $list['wigother2'] = $this->input->post('wigother2',true);
  1521. }
  1522. if($category == 129)
  1523. {
  1524. $list['wide'] = $this->input->post('wide',true);
  1525. }
  1526. if($category == 131)
  1527. {
  1528. $list['gifttype'] = $this->input->post('gifttype',true);
  1529. $list['giftother'] = $this->input->post('giftother',true);
  1530. }
  1531. if($category == 134)
  1532. {
  1533. $list['pieceweight'] = $this->input->post('pieceweight',true);
  1534. }
  1535. if($category == 1297)
  1536. {
  1537. $list['synthetictype'] = $this->input->post('synthetictype',true);
  1538. $list['sywigother'] = $this->input->post('sywigother',true);
  1539. }
  1540. if($category == 130 || $category == 133 || $category == 1702)
  1541. {
  1542. $list['items'] = $this->input->post('items',true);
  1543. $list['weight'] = $this->input->post('weight',true);
  1544. }
  1545. else if($category == 1702)
  1546. {
  1547. $list['syhairther'] = $this->input->post('syhairther',true);
  1548. }
  1549. foreach($list as $k=>$v)
  1550. {
  1551. if($v != 0)
  1552. {
  1553. $num .=$v;
  1554. $features .=$v.'-';
  1555. $post[$k] = $v;
  1556. $typeclass = $this->typeclass->read($v);
  1557. if($k != 'size')
  1558. {
  1559. $title .= $typeclass['title']." ";
  1560. }
  1561. }
  1562. }
  1563. $typeclass = $this->typeclass->read($list['size']);
  1564. $title .= $typeclass['title'];
  1565. $time = time();
  1566. $post['title'] = rtrim($title,' ');
  1567. $post['number'] = $num;
  1568. $post['features'] = '-'.$features;
  1569. $featurespp = str_replace(array('-163-','-164-','-165-','-166-'),'-',$features);
  1570. $featurespp = explode('-',trim($featurespp,'-'));
  1571. $post['featurespp'] = $featurespp[0].'-'.$featurespp[3].'-'.$featurespp[4].'-'.$featurespp[5];
  1572. $post['enter'] = $time;
  1573. $post['time'] = $time;//操作时间
  1574. for($i=0;$i<$order;$i++)
  1575. {
  1576. $post['label'] = time().rand(100,999).$i;//产品标签 辨别各个产品,暂不使用
  1577. $this->specialstock->insert($post);
  1578. }
  1579. echo json_encode(array('msg'=>'入库成功','success'=>true));exit;
  1580. }
  1581. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  1582. $this->data['wlshop'] = $wlshop;
  1583. $this->_Template('specialstock_enteradd',$this->data);
  1584. }
  1585. //修改产品
  1586. public function _enteredit($arg_array)
  1587. {
  1588. $dt = 0;
  1589. if(isset($_SESSION['api']))
  1590. {
  1591. $user = $this->user->get_api($_SESSION['api']);
  1592. $usp = $user;
  1593. $fgshop = "";$sid = "";
  1594. $user = explode('|',trim($user['shop'],'|'));
  1595. foreach ($user as $value)
  1596. {
  1597. $fgshop .= " shop = ".$value." or";
  1598. $sid .= " id = ".$value." or";
  1599. }
  1600. }
  1601. $post = $this->input->post(NULL, TRUE);
  1602. if(isset($post['details']))
  1603. {
  1604. $list = array();$num = "";$title = "";$features = "";$state=0;//正常入库
  1605. $id = $this->input->post('id',true);
  1606. $order = $this->input->post('order',true);
  1607. $post['details'] = $this->input->post('details',true);
  1608. $post['sku'] = $this->input->post('sku',true);
  1609. $category = $this->input->post('category',true);
  1610. $list['category'] = $category;
  1611. $list['hairtype'] = $this->input->post('hairtype',true);
  1612. $list['grade'] = $this->input->post('grade',true);
  1613. $size = $this->input->post('size',true);
  1614. $list['size'] = rtrim($size,',');
  1615. $list['hairnumber'] = $this->input->post('hairnumber',true);
  1616. $list['extension'] = $this->input->post('extension',true);
  1617. if($category == 1297)
  1618. {
  1619. $list['sywignumber'] = $this->input->post('sywignumber',true);
  1620. }
  1621. if($category == 1702)
  1622. {
  1623. $list['syhairnumber'] = $this->input->post('syhairnumber',true);
  1624. $list['syother'] = $this->input->post('syother',true);
  1625. }
  1626. if($category == 133)
  1627. {
  1628. $list['fittype'] = $this->input->post('fittype',true);
  1629. $list['acother'] = $this->input->post('acother',true);
  1630. }
  1631. $list['color'] = $this->input->post('color',true);
  1632. $list['lowe'] = $this->input->post('lowe',true);
  1633. $post['warehouse'] = $this->input->post('warehouse',true);
  1634. if($category == 127)
  1635. {
  1636. $list['type'] = $this->input->post('type',true);
  1637. $list['headroad'] = $this->input->post('headroad',true);
  1638. $list['density'] = $this->input->post('density',true);
  1639. if($list['type'] == 195 || $list['type'] == 197 || $list['type'] == 199)
  1640. {
  1641. $list['lacesize'] = $this->input->post('lacesize',true);
  1642. }
  1643. $list['lacecolor'] = $this->input->post('lacecolor',true);
  1644. $list['lacetypes'] = $this->input->post('lacetypes',true);
  1645. }
  1646. if($category == 128)
  1647. {
  1648. $list['lacetype'] = $this->input->post('lacetype',true);
  1649. $list['haircap'] = $this->input->post('haircap',true);
  1650. $list['density'] = $this->input->post('density',true);
  1651. $list['lacecolor'] = $this->input->post('lacecolor',true);
  1652. $list['lacetypes'] = $this->input->post('lacetypes',true);
  1653. $list['wigother'] = $this->input->post('wigother',true);
  1654. $list['wigother2'] = $this->input->post('wigother2',true);
  1655. }
  1656. if($category == 129)
  1657. {
  1658. $list['wide'] = $this->input->post('wide',true);
  1659. }
  1660. if($category == 131)
  1661. {
  1662. $list['gifttype'] = $this->input->post('gifttype',true);
  1663. $list['giftother'] = $this->input->post('giftother',true);
  1664. }
  1665. if($category == 134)
  1666. {
  1667. $list['pieceweight'] = $this->input->post('pieceweight',true);
  1668. }
  1669. if($category == 1297)
  1670. {
  1671. $list['synthetictype'] = $this->input->post('synthetictype',true);
  1672. $list['sywigother'] = $this->input->post('sywigother',true);
  1673. }
  1674. if($category == 130 || $category == 133 || $category == 1702)
  1675. {
  1676. $list['items'] = $this->input->post('items',true);
  1677. $list['weight'] = $this->input->post('weight',true);
  1678. }
  1679. else if($category == 1702)
  1680. {
  1681. $list['syhairther'] = $this->input->post('syhairther',true);
  1682. }
  1683. foreach($list as $k=>$v)
  1684. {
  1685. if($v != 0)
  1686. {
  1687. $num .=$v;
  1688. $features .=$v.'-';
  1689. $typeclass = $this->typeclass->read($v);
  1690. if($k != 'size')
  1691. {
  1692. $title .= $typeclass['title']." ";
  1693. }
  1694. }
  1695. }
  1696. $typeclass = $this->typeclass->read($list['size']);
  1697. $title .= $typeclass['title'];
  1698. $time = time();
  1699. $post['title'] = rtrim($title,' ');
  1700. $post['number'] = $num;
  1701. $post['features'] = '-'.$features;
  1702. $featurespp = str_replace(array('-163-','-164-','-165-','-166-'),'-',$features);
  1703. $featurespp = explode('-',trim($featurespp,'-'));
  1704. $post['featurespp'] = $featurespp[0].'-'.$featurespp[3].'-'.$featurespp[4].'-'.$featurespp[5];
  1705. $post['time'] = $time;//操作时间
  1706. $uid = $this->specialstock->read($id);
  1707. $datanum = $this->specialstock->find_count("state = 0 and number = '".$uid['number']."' and zd != ''");
  1708. if($datanum > 0)
  1709. {
  1710. echo json_encode(array('msg'=>'此库存有占单,请解除占单后再修改!','success'=>false));exit;
  1711. }
  1712. $data = $this->specialstock->find_all("number = '".$uid['number']."' and enter = '".$uid['enter']."'");// and enter = '".$uid['enter']."'
  1713. foreach ($data as $v)
  1714. {
  1715. $post['id'] = $v['id'];
  1716. $this->specialstock->save($post,$v['id']);
  1717. }
  1718. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  1719. }
  1720. $uid = $this->specialstock->read($arg_array[0]);
  1721. $uid['order'] = $this->specialstock->find_count('enter = '.$uid['enter']);
  1722. $this->data['enter'] = $uid ;
  1723. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  1724. $this->data['wlshop'] = $wlshop;
  1725. $whlabelwz = $this->whlabelwz->find_all();
  1726. $this->data['whlabelwz'] = $whlabelwz;
  1727. $this->_Template('specialstock_enteredit',$this->data);
  1728. }
  1729. //入库浏览
  1730. public function _enter()
  1731. {
  1732. $post = $this->input->post(NULL, TRUE);
  1733. if(isset($post['s']))
  1734. {
  1735. $id_arr = $this->input->post('s');
  1736. $id_arr = explode(',',$id_arr);
  1737. if(!$id_arr)
  1738. {
  1739. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  1740. }
  1741. //循环删除记录
  1742. foreach ($id_arr as $v)
  1743. {
  1744. $sid = $this->specialstock->read($v);
  1745. $info_list = $this->specialstock->find_all('enter ='.$sid['enter']);
  1746. foreach ($info_list as $va)
  1747. {
  1748. $this->specialstock->remove($va['id']);
  1749. }
  1750. }
  1751. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));exit;
  1752. }
  1753. if(isset($post['page']))
  1754. {
  1755. $page = $this->input->post('page',true);
  1756. $perpage = $this->input->post('perpage',true);
  1757. $category = $this->input->post('category',true);
  1758. $size = $this->input->post('size',true);
  1759. $grade = $this->input->post('grade',true);
  1760. $color = $this->input->post('color',true);
  1761. $details = $this->input->post('details',true);
  1762. $sku = $this->input->post('sku',true);
  1763. $warehouse = '';//12
  1764. $ktime = $this->input->post('ktime',true);
  1765. $jtime = $this->input->post('jtime',true);
  1766. $ktime = strtotime($ktime);
  1767. $jtime = strtotime($jtime);
  1768. $where = "1=1";$gj = "";$ck = "";
  1769. if($category)
  1770. {
  1771. $where .= " and features like '%-$category-%'";
  1772. }
  1773. if($size)
  1774. {
  1775. $where .= " and features like '%-$size-%'";
  1776. }
  1777. if($grade)
  1778. {
  1779. $where .= " and features like '%-$grade-%'";
  1780. }
  1781. if($color)
  1782. {
  1783. $where .= " and features like '%-$color-%'";
  1784. }
  1785. if($details)
  1786. {
  1787. $where .= " and details like '%$details%'";
  1788. }
  1789. if($sku)
  1790. {
  1791. $where .= " and sku like '%$sku%'";
  1792. }
  1793. if($warehouse)
  1794. {
  1795. $where .= " and warehouse = '$warehouse'";
  1796. }
  1797. if($ktime && $jtime)
  1798. {
  1799. $where .= " and enter > '$ktime' and enter < '$jtime'";
  1800. }
  1801. //数据排序
  1802. $order_str = "enter desc";
  1803. if(empty($page))
  1804. {
  1805. $start = 0;
  1806. $perpage = 1;
  1807. }
  1808. else
  1809. {
  1810. $start = ($page - 1)*$perpage;
  1811. }
  1812. //取得信息列表
  1813. $info_list = $this->specialstock->find_all($where,'*',$order_str);
  1814. $rows = array();$list = array();
  1815. foreach ($info_list as $key=>$value)
  1816. {
  1817. $rows[$value['enter'].$value['number']] = $value;//所有数据sku
  1818. }
  1819. foreach ($rows as $value)
  1820. {
  1821. $g = $this->specialstock->find_count($where.' and enter = "'.$value['enter'].'" and state != 9');
  1822. $list[] = array('id'=>$value['id'],'sku'=>$value['sku'],'title'=>$value['title'],'details'=>$value['details'],'time'=>date('Y-m-d H:i:s',$value['enter']),'number'=>$g);
  1823. }
  1824. $total = count($list);
  1825. $pagenum = ceil($total/$perpage);
  1826. $over = $total-($start+$perpage);
  1827. $list = array_slice($list,$start,$perpage);//数组中提取分页指定的内容 +true key排序不变
  1828. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list),'abc'=>($where));
  1829. echo json_encode($rows);exit;
  1830. }
  1831. $this->_Template('specialstock_enter',$this->data);
  1832. }
  1833. //入库浏览
  1834. public function _xhcenter()
  1835. {
  1836. $post = $this->input->post(NULL, TRUE);
  1837. if(isset($post['s']))
  1838. {
  1839. $id_arr = $this->input->post('s');
  1840. $id_arr = explode(',',$id_arr);
  1841. if(!$id_arr)
  1842. {
  1843. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  1844. }
  1845. //循环删除记录
  1846. foreach ($id_arr as $v)
  1847. {
  1848. $sid = $this->specialstock->read($v);
  1849. $info_list = $this->specialstock->find_all('enter ='.$sid['enter']);
  1850. foreach ($info_list as $va)
  1851. {
  1852. $this->specialstock->remove($va['id']);
  1853. }
  1854. }
  1855. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));exit;
  1856. }
  1857. if(isset($post['page']))
  1858. {
  1859. $page = $this->input->post('page',true);
  1860. $perpage = $this->input->post('perpage',true);
  1861. $category = $this->input->post('category',true);
  1862. $size = $this->input->post('size',true);
  1863. $grade = $this->input->post('grade',true);
  1864. $color = $this->input->post('color',true);
  1865. $details = $this->input->post('details',true);
  1866. $sku = $this->input->post('sku',true);
  1867. $warehouse = $this->input->post('warehouse',true);
  1868. $ktime = $this->input->post('ktime',true);
  1869. $jtime = $this->input->post('jtime',true);
  1870. $ktime = strtotime($ktime);
  1871. $jtime = strtotime($jtime);
  1872. $where = "warehouse != '12'";$gj = "";$ck = "";
  1873. if($category)
  1874. {
  1875. $where .= " and features like '%-$category-%'";
  1876. }
  1877. if($size)
  1878. {
  1879. $where .= " and features like '%-$size-%'";
  1880. }
  1881. if($grade)
  1882. {
  1883. $where .= " and features like '%-$grade-%'";
  1884. }
  1885. if($color)
  1886. {
  1887. $where .= " and features like '%-$color-%'";
  1888. }
  1889. if($details)
  1890. {
  1891. $where .= " and details like '%$details%'";
  1892. }
  1893. if($sku)
  1894. {
  1895. $where .= " and sku like '%$sku%'";
  1896. }
  1897. if($warehouse)
  1898. {
  1899. $where .= " and warehouse = '$warehouse'";
  1900. }
  1901. if($ktime && $jtime)
  1902. {
  1903. $where .= " and enter > '$ktime' and enter < '$jtime'";
  1904. }
  1905. //数据排序
  1906. $order_str = "enter desc";
  1907. if(empty($page))
  1908. {
  1909. $start = 0;
  1910. $perpage = 1;
  1911. }
  1912. else
  1913. {
  1914. $start = ($page - 1)*$perpage;
  1915. }
  1916. //取得信息列表
  1917. $info_list = $this->specialstock->find_all($where,'*',$order_str);
  1918. $rows = array();$list = array();
  1919. foreach ($info_list as $key=>$value)
  1920. {
  1921. $rows[$value['enter'].$value['number']] = $value;//所有数据sku
  1922. }
  1923. foreach ($rows as $value)
  1924. {
  1925. $g = $this->specialstock->find_count($where.' and enter = "'.$value['enter'].'" and state != 9');
  1926. $list[] = array('id'=>$value['id'],'sku'=>$value['sku'],'title'=>$value['title'],'details'=>$value['details'],'time'=>date('Y-m-d H:i:s',$value['enter']),'number'=>$g);
  1927. }
  1928. $total = count($list);
  1929. $pagenum = ceil($total/$perpage);
  1930. $over = $total-($start+$perpage);
  1931. $list = array_slice($list,$start,$perpage);//数组中提取分页指定的内容 +true key排序不变
  1932. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  1933. echo json_encode($rows);exit;
  1934. }
  1935. $this->_Template('specialstock_xhcenter',$this->data);
  1936. }
  1937. //出库浏览
  1938. public function _out()
  1939. {
  1940. $post = $this->input->post(NULL, TRUE);
  1941. if(isset($post['page']))
  1942. {
  1943. $page = $this->input->post('page',true);
  1944. $perpage = $this->input->post('perpage',true);
  1945. $category = $this->input->post('category',true);
  1946. $size = $this->input->post('size',true);
  1947. $grade = $this->input->post('grade',true);
  1948. $color = $this->input->post('color',true);
  1949. $lowe = $this->input->post('lowe',true);
  1950. $sku = $this->input->post('sku',true);
  1951. $warehouse = $this->input->post('warehouse',true);
  1952. $purchase = $this->input->post('purchase',true);
  1953. $ktime = $this->input->post('ktime',true);
  1954. $jtime = $this->input->post('jtime',true);
  1955. $ktime = strtotime($ktime);
  1956. $jtime = strtotime($jtime);
  1957. $where = "state=3";$gj = "";$ck = "";
  1958. if($category)
  1959. {
  1960. $where .= " and features like '%-$category-%'";
  1961. }
  1962. if($size)
  1963. {
  1964. $where .= " and features like '%-$size-%'";
  1965. }
  1966. if($grade)
  1967. {
  1968. $where .= " and features like '%-$grade-%'";
  1969. }
  1970. if($color)
  1971. {
  1972. $where .= " and features like '%-$color-%'";
  1973. }
  1974. if($lowe)
  1975. {
  1976. $where .= " and features like '%-$lowe-%'";
  1977. }
  1978. if($state)
  1979. {
  1980. $where .= " and state = '$state'";
  1981. }
  1982. if($warehouse)
  1983. {
  1984. $where .= " and warehouse = '$warehouse'";
  1985. }
  1986. if($purchase)
  1987. {
  1988. $where .= " and purchase = '$purchase'";
  1989. }
  1990. if($sku)
  1991. {
  1992. $where .= " and sku = '$sku'";
  1993. }
  1994. if($ktime && $jtime)
  1995. {
  1996. $where .= " and outk > '$ktime' and outk < '$jtime'";
  1997. }
  1998. //数据排序
  1999. $order_str = "id desc";
  2000. if(empty($page))
  2001. {
  2002. $start = 0;
  2003. $perpage = 1;
  2004. }
  2005. else
  2006. {
  2007. $start = ($page - 1)*$perpage;
  2008. }
  2009. //取得信息列表
  2010. $info_list = $this->specialstock->find_all($where,'sku');
  2011. $rows = array();$list = array();
  2012. foreach ($info_list as $key=>$value)
  2013. {
  2014. $rows[] = $value['sku'].'warehouse'.$value['warehouse'];//所有数据sku
  2015. }
  2016. $rows = array_unique($rows);//删除重复记录
  2017. foreach ($rows as $key=>$value)
  2018. {
  2019. $data = $this->specialstock->get_sku($value);//获取目前sku的所有数据
  2020. $ck = $this->warehouse->read($data['warehouse']);
  2021. $warehouse = $ck['title'];
  2022. $gy = $this->purchase->read($data['purchase']);
  2023. $purchase = $gy['purchase'];
  2024. $g = $this->specialstock->find_count($where.' and sku = "'.$value.'" and state = 3');
  2025. $list[] = array('id'=>$data['id'],'warehouse'=>$warehouse,'purchase'=>$purchase,'sku'=>$data['sku'],'title'=>$data['title'],'time'=>date('Y-m-d H:i:s',$data['enter']),'number'=>$g);
  2026. }
  2027. $total = count($list);
  2028. $pagenum = ceil($total/$perpage);
  2029. $over = $total-($start+$perpage);
  2030. $list = array_slice($list,$start,$perpage);//数组中提取分页指定的内容 +true key排序不变
  2031. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  2032. echo json_encode($rows);exit;
  2033. }
  2034. $this->_Template('specialstock_out',$this->data);
  2035. }
  2036. //出库标签浏览
  2037. public function _label()
  2038. {
  2039. $post = $this->input->post(NULL, TRUE);
  2040. if(isset($post['page']))
  2041. {
  2042. $page = $this->input->post('page',true);
  2043. $perpage = $this->input->post('perpage',true);
  2044. $sku = $this->input->post('sku',true);
  2045. $warehouse = $this->input->post('warehouse',true);
  2046. $purchase = $this->input->post('purchase',true);
  2047. $orderinfo = $this->input->post('orderinfo',true);
  2048. $waybill = $this->input->post('waybill',true);
  2049. $category = $this->input->post('category',true);
  2050. $size = $this->input->post('size',true);
  2051. $grade = $this->input->post('grade',true);
  2052. $color = $this->input->post('color',true);
  2053. $lowe = $this->input->post('lowe',true);
  2054. $where = "state=1";
  2055. if($sku)
  2056. {
  2057. $where .= " and sku = '$sku'";
  2058. }
  2059. if($warehouse)
  2060. {
  2061. $where .= " and warehouse = '$warehouse'";
  2062. }
  2063. if($purchase)
  2064. {
  2065. $where .= " and purchase = '$purchase'";
  2066. }
  2067. if($orderinfo)
  2068. {
  2069. $where .= " and orderinfo = '$orderinfo'";
  2070. }
  2071. if($waybill)
  2072. {
  2073. $where .= " and waybill = '$waybill'";
  2074. }
  2075. if($category)
  2076. {
  2077. $where .= " and features like '%-$category-%'";
  2078. }
  2079. if($size)
  2080. {
  2081. $where .= " and features like '%-$size-%'";
  2082. }
  2083. if($grade)
  2084. {
  2085. $where .= " and features like '%-$grade-%'";
  2086. }
  2087. if($color)
  2088. {
  2089. $where .= " and features like '%-$color-%'";
  2090. }
  2091. if($lowe)
  2092. {
  2093. $where .= " and features like '%-$lowe-%'";
  2094. }
  2095. //数据排序
  2096. $order_str = "outk desc";
  2097. if(empty($page))
  2098. {
  2099. $start = 0;
  2100. $perpage = 1;
  2101. }
  2102. else
  2103. {
  2104. $start = ($page - 1)*$perpage;
  2105. }
  2106. //取得信息列表
  2107. $info_list = $this->specialstock->find_all($where,'id,warehouse,sku,title,label,purchase,orderinfo,waybill,outk',$order_str,$start,$perpage);
  2108. foreach ($info_list as $key=>$value)
  2109. {
  2110. $warehouse = $this->warehouse->read($value['warehouse']);
  2111. $info_list[$key]['warehouse'] = $warehouse['title'];
  2112. $purchase = $this->purchase->read($value['purchase']);
  2113. $info_list[$key]['purchase'] = $purchase['title'];
  2114. if($value['outk'] != 0)
  2115. {
  2116. $info_list[$key]['outk'] = date('Y-m-d H:i:s',$value['outk']);
  2117. }
  2118. else
  2119. {
  2120. $info_list[$key]['outk'] = "";
  2121. }
  2122. if($value['orderinfo'] == 0)
  2123. {
  2124. $info_list[$key]['orderinfo'] = "";
  2125. }
  2126. if($value['waybill'] == 0)
  2127. {
  2128. $info_list[$key]['waybill'] = "";
  2129. }
  2130. }
  2131. $total = $this->specialstock->find_count($where);
  2132. $pagenum = ceil($total/$perpage);
  2133. $over = $total-($start+$perpage);
  2134. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  2135. echo json_encode($rows);exit;
  2136. }
  2137. $this->_Template('specialstock_label',$this->data);
  2138. }
  2139. //独立站出库订单
  2140. public function _outorder()
  2141. {
  2142. if(isset($_SESSION['api']))
  2143. {
  2144. $user = $this->user->get_api($_SESSION['api']);
  2145. $usp = $user;
  2146. $fgshop = "";$sid = "";
  2147. $user = explode('|',trim($user['shop'],'|'));
  2148. foreach ($user as $value)
  2149. {
  2150. $sid .= " id = ".$value." or";
  2151. }
  2152. }
  2153. $post = $this->input->post(NULL, TRUE);
  2154. if(isset($post['page']))
  2155. {
  2156. $page = $this->input->post('page',true);
  2157. $perpage = $this->input->post('perpage',true);
  2158. $warehouse = $this->input->post('warehouse',true);
  2159. $xztime = $this->input->post('xztime',true);
  2160. $timetk = $this->input->post('timetkk',true);
  2161. $timetj = $this->input->post('timetjj',true);
  2162. $shop = $this->input->post('shop',true);
  2163. $source = $this->input->post('source',true);
  2164. $orderinfo = $this->input->post('orderinfo',true);
  2165. $number = $this->input->post('number',true);
  2166. $express = $this->input->post('express',true);
  2167. $waybill = $this->input->post('waybill',true);
  2168. $library = $this->input->post('library',true);
  2169. $country = $this->input->post('country',true);
  2170. $so = $this->input->post('so',true);
  2171. $libraryconfirm = $this->input->post('libraryconfirm',true);
  2172. $print = $this->input->post('print',true);
  2173. $state = $this->input->post('state',true);
  2174. $timetk = strtotime($timetk);
  2175. $timetj = strtotime($timetj);
  2176. /**
  2177. $sj = $this->input->post('sj',true);
  2178. if($sj)
  2179. {
  2180. $sj = $this->input->post('sj',true);
  2181. }
  2182. else
  2183. {
  2184. $sj = "fullorder";
  2185. }
  2186. **/
  2187. $sj = "fullorder";
  2188. $where = "mergeid = 0";
  2189. if($warehouse)
  2190. {
  2191. $where .= " and type = '$warehouse'";
  2192. }
  2193. if($timetk && $timetj)
  2194. {
  2195. $where .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
  2196. }
  2197. if($orderinfo)
  2198. {
  2199. $where .= " and orderinfo = '$orderinfo'";
  2200. }
  2201. if($number)
  2202. {
  2203. $where .= " and number = '$number'";
  2204. }
  2205. if($express)
  2206. {
  2207. $where .= " and express = '$express'";
  2208. }
  2209. if($waybill)
  2210. {
  2211. $where .= " and waybill = '$waybill'";
  2212. }
  2213. if($library)
  2214. {
  2215. $where .= " and library = '$library'";
  2216. }
  2217. if($print)
  2218. {
  2219. $where .= " and print = '$print'";
  2220. }
  2221. if($libraryconfirm)
  2222. {
  2223. $where .= " and libraryconfirm = '$libraryconfirm'";
  2224. }
  2225. if($state)
  2226. {
  2227. $where .= " and state = '$state'";
  2228. }
  2229. if($shop)
  2230. {
  2231. $where .= " and shop = '$shop'";
  2232. }
  2233. if($country)
  2234. {
  2235. $where .= " and country = '$country'";
  2236. }
  2237. if($so)
  2238. {
  2239. $where .= " and shipremarks like '%$so%'";
  2240. }
  2241. if($source)
  2242. {
  2243. $where .= " and source = '$source'";
  2244. }
  2245. else
  2246. {
  2247. if(isset($_SESSION['api']))
  2248. {
  2249. foreach ($user as $value)
  2250. {
  2251. $fgshop .= " shop = ".$value." or";
  2252. }
  2253. $where .= " and (".rtrim($fgshop,'or').")";
  2254. }
  2255. }
  2256. //数据排序
  2257. $order_str = "librarytime desc";
  2258. if(empty($page))
  2259. {
  2260. $start = 0;
  2261. $perpage = 1;
  2262. }
  2263. else
  2264. {
  2265. $start = ($page - 1)*$perpage;
  2266. }
  2267. //取得信息列表
  2268. $info_list = $this->$sj->find_all($where,'id,shop,type,orderinfo,number,waybill,express,librarytime',$order_str,$start,$perpage);
  2269. //格式化数据
  2270. foreach ($info_list as $key=>$value)
  2271. {
  2272. $shop = $this->shop->read($value['shop']);
  2273. $info_list[$key]['shop'] = $shop['shopname'];
  2274. $express = $this->express->read($value['express']);
  2275. $info_list[$key]['express'] = $express['servicename'];
  2276. $warehouse = $this->warehouse->read($value['type']);
  2277. $info_list[$key]['type'] = $warehouse['title'];
  2278. if($value['librarytime'] == '0')
  2279. {
  2280. $info_list[$key]['librarytime'] = '<em class="t"></em>';
  2281. }
  2282. else
  2283. {
  2284. $info_list[$key]['librarytime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['librarytime']).'</em>';
  2285. }
  2286. }
  2287. $total = $this->$sj->find_count($where);
  2288. $pagenum = ceil($total/$perpage);
  2289. $over = $total-($start+$perpage);
  2290. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  2291. echo json_encode($rows);exit;
  2292. }
  2293. $this->data['express'] = $this->express->find_all();
  2294. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  2295. $this->data['wlshop'] = $wlshop;
  2296. $this->data['fullorderexcel'] = $this->fullorderexcel->find_all('type=2','*','idorder desc');//导出模板
  2297. $this->_Template('specialstock_outorder',$this->data);
  2298. }
  2299. //速卖通出库订单
  2300. public function _soutorder()
  2301. {
  2302. if(isset($_SESSION['api']))
  2303. {
  2304. $user = $this->user->get_api($_SESSION['api']);
  2305. $usp = $user;
  2306. $fgshop = "";$sid = "";
  2307. $user = explode('|',trim($user['shop'],'|'));
  2308. foreach ($user as $value)
  2309. {
  2310. $sid .= " id = ".$value." or";
  2311. }
  2312. }
  2313. $post = $this->input->post(NULL, TRUE);
  2314. if(isset($post['page']))
  2315. {
  2316. $page = $this->input->post('page',true);
  2317. $perpage = $this->input->post('perpage',true);
  2318. $warehouse = $this->input->post('warehouse',true);
  2319. $xztime = $this->input->post('xztime',true);
  2320. $timetk = $this->input->post('timetkk',true);
  2321. $timetj = $this->input->post('timetjj',true);
  2322. $shop = $this->input->post('shop',true);
  2323. $source = $this->input->post('source',true);
  2324. $orderinfo = $this->input->post('orderinfo',true);
  2325. $number = $this->input->post('number',true);
  2326. $express = $this->input->post('express',true);
  2327. $waybill = $this->input->post('waybill',true);
  2328. $library = $this->input->post('library',true);
  2329. $country = $this->input->post('country',true);
  2330. $libraryconfirm = $this->input->post('libraryconfirm',true);
  2331. $print = $this->input->post('print',true);
  2332. $state = $this->input->post('state',true);
  2333. $so = $this->input->post('so',true);
  2334. $timetk = strtotime($timetk);
  2335. $timetj = strtotime($timetj);
  2336. /**
  2337. $sj = $this->input->post('sj',true);
  2338. if($sj)
  2339. {
  2340. $sj = $this->input->post('sj',true);
  2341. }
  2342. else
  2343. {
  2344. $sj = "fullorder";
  2345. }
  2346. **/
  2347. $sj = "fullordersmt";
  2348. $where = "mergeid = 0";
  2349. if($warehouse)
  2350. {
  2351. $where .= " and type = '$warehouse'";
  2352. }
  2353. if($timetk && $timetj)
  2354. {
  2355. $where .= " and ".$xztime." > '$timetk' and ".$xztime." < '$timetj'";
  2356. }
  2357. if($orderinfo)
  2358. {
  2359. $where .= " and orderinfo = '$orderinfo'";
  2360. }
  2361. if($number)
  2362. {
  2363. $where .= " and number = '$number'";
  2364. }
  2365. if($express)
  2366. {
  2367. $where .= " and express = '$express'";
  2368. }
  2369. if($waybill)
  2370. {
  2371. $where .= " and waybill = '$waybill'";
  2372. }
  2373. if($library)
  2374. {
  2375. $where .= " and library = '$library'";
  2376. }
  2377. if($print)
  2378. {
  2379. $where .= " and print = '$print'";
  2380. }
  2381. if($libraryconfirm)
  2382. {
  2383. $where .= " and libraryconfirm = '$libraryconfirm'";
  2384. }
  2385. if($state)
  2386. {
  2387. $where .= " and state = '$state'";
  2388. }
  2389. if($shop)
  2390. {
  2391. $where .= " and shop = '$shop'";
  2392. }
  2393. if($so)
  2394. {
  2395. $where .= " and shipremarks like '%$so%'";
  2396. }
  2397. if($source)
  2398. {
  2399. $where .= " and source = '$source'";
  2400. }
  2401. if($country)
  2402. {
  2403. $where .= " and country = '$country'";
  2404. }
  2405. else
  2406. {
  2407. if(isset($_SESSION['api']))
  2408. {
  2409. foreach ($user as $value)
  2410. {
  2411. $fgshop .= " shop = ".$value." or";
  2412. }
  2413. $where .= " and (".rtrim($fgshop,'or').")";
  2414. }
  2415. }
  2416. //数据排序
  2417. $order_str = "librarytime desc";
  2418. if(empty($page))
  2419. {
  2420. $start = 0;
  2421. $perpage = 1;
  2422. }
  2423. else
  2424. {
  2425. $start = ($page - 1)*$perpage;
  2426. }
  2427. //取得信息列表
  2428. $info_list = $this->$sj->find_all($where,'id,shop,type,orderinfo,number,waybill,express,librarytime',$order_str,$start,$perpage);
  2429. //格式化数据
  2430. foreach ($info_list as $key=>$value)
  2431. {
  2432. $shop = $this->shop->read($value['shop']);
  2433. $info_list[$key]['shop'] = $shop['shopname'];
  2434. $express = $this->express->read($value['express']);
  2435. $info_list[$key]['express'] = $express['servicename'];
  2436. $warehouse = $this->warehouse->read($value['type']);
  2437. $info_list[$key]['type'] = $warehouse['title'];
  2438. if($value['librarytime'] == '0')
  2439. {
  2440. $info_list[$key]['librarytime'] = '<em class="t"></em>';
  2441. }
  2442. else
  2443. {
  2444. $info_list[$key]['librarytime'] = '<em class="t">'.date('Y-m-d H:i:s',$value['librarytime']).'</em>';
  2445. }
  2446. }
  2447. $total = $this->$sj->find_count($where);
  2448. $pagenum = ceil($total/$perpage);
  2449. $over = $total-($start+$perpage);
  2450. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  2451. echo json_encode($rows);exit;
  2452. }
  2453. $this->data['express'] = $this->express->find_all();
  2454. $wlshop = $this->shop->find_all('1=1 and '.rtrim($sid,'or'));
  2455. $this->data['wlshop'] = $wlshop;
  2456. $this->data['fullorderexcel'] = $this->fullorderexcel->find_all('type=5','*','idorder desc');//导出模板
  2457. $this->_Template('specialstock_soutorder',$this->data);
  2458. }
  2459. //订单退库
  2460. public function _retreat()
  2461. {
  2462. $post = $this->input->post(NULL, TRUE);
  2463. if(isset($post['page']))
  2464. {
  2465. $page = $this->input->post('page',true);
  2466. $perpage = $this->input->post('perpage',true);
  2467. $warehouse = $this->input->post('warehouse',true);
  2468. $timetk = $this->input->post('timetk',true);
  2469. $timetj = $this->input->post('timetj',true);
  2470. $shop = $this->input->post('shop',true);
  2471. $source = $this->input->post('source',true);
  2472. $state = $this->input->post('state',true);
  2473. $review = $this->input->post('review',true);
  2474. $state = $this->input->post('state',true);
  2475. $express = $this->input->post('express',true);
  2476. $orderinfo = $this->input->post('orderinfo',true);
  2477. $user = $this->input->post('user',true);
  2478. $name = $this->input->post('name',true);
  2479. $waybill = $this->input->post('waybill',true);
  2480. $timetk = strtotime($timetk);
  2481. $timetj = strtotime($timetj);
  2482. $where = "(state=206 or state=210) and mergeid = 0";
  2483. if($warehouse)
  2484. {
  2485. $where .= " and state = '$warehouse'";
  2486. }
  2487. if($timetk && $timetj)
  2488. {
  2489. $where .= " and buytime > '$timetk' and buytime < '$timetj'";
  2490. }
  2491. if($shop)
  2492. {
  2493. $where .= " and shop = '$shop'";
  2494. }
  2495. if($source)
  2496. {
  2497. $where .= " and source = '$source'";
  2498. }
  2499. if($state)
  2500. {
  2501. $where .= " and state = '$state'";
  2502. }
  2503. if($review)
  2504. {
  2505. $where .= " and review = '$review'";
  2506. }
  2507. if($state)
  2508. {
  2509. $where .= " and state = '$state'";
  2510. }
  2511. if($express)
  2512. {
  2513. $where .= " and express = '$express'";
  2514. }
  2515. if($orderinfo)
  2516. {
  2517. $where .= " and orderinfo = '$orderinfo'";
  2518. }
  2519. if($user)
  2520. {
  2521. $where .= " and user = '$user'";
  2522. }
  2523. if($name)
  2524. {
  2525. $where .= " and name = '$name'";
  2526. }
  2527. if($waybill)
  2528. {
  2529. $where .= " and waybill = '$waybill'";
  2530. }
  2531. //数据排序
  2532. $order_str = "id desc";
  2533. if(empty($page))
  2534. {
  2535. $start = 0;
  2536. $perpage = 1;
  2537. }
  2538. else
  2539. {
  2540. $start = ($page - 1)*$perpage;
  2541. }
  2542. //取得信息列表
  2543. $info_list = $this->fullorder->find_all($where,'id,shop,warehouse,orderinfo,number,express,waybill,state,buytime',$order_str,$start,$perpage);
  2544. //格式化数据
  2545. foreach ($info_list as $key=>$value)
  2546. {
  2547. $shop = $this->shop->read($value['shop']);
  2548. $info_list[$key]['shop'] = $shop['shopname'];
  2549. $warehouse = $this->warehouse->read($value['warehouse']);
  2550. $info_list[$key]['warehouse'] = $warehouse['title'];
  2551. $info_list[$key]['orderinfo'] = "<a href='/fullorder/editoff/".$value['id']."'>".$value['orderinfo']."</a>";
  2552. $info_list[$key]['buytime'] = '<p>'.date('Y-m-d',$value['buytime']).'</p><p>'.date('H:i:s',$value['buytime']).'</p>';
  2553. if($value['waybill'] == 0)
  2554. {
  2555. $info_list[$key]['waybill'] = "";
  2556. }
  2557. $express = $this->express->read($value['express']);
  2558. $info_list[$key]['express'] = $express['title'];
  2559. $typeclass = $this->typeclass->read($value['state']);
  2560. $info_list[$key]['state'] = $typeclass['title'];
  2561. }
  2562. $total = $this->fullorder->find_count($where);
  2563. $pagenum = ceil($total/$perpage);
  2564. $over = $total-($start+$perpage);
  2565. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  2566. echo json_encode($rows);exit;
  2567. }
  2568. $this->data['express'] = $this->express->find_all();
  2569. $this->_Template('specialstock_retreat',$this->data);
  2570. }
  2571. //退库标签浏览
  2572. public function _retreatlk()
  2573. {
  2574. $post = $this->input->post(NULL, TRUE);
  2575. if(isset($post['page']))
  2576. {
  2577. $page = $this->input->post('page',true);
  2578. $perpage = $this->input->post('perpage',true);
  2579. $timetk = $this->input->post('timetk',true);
  2580. $timetj = $this->input->post('timetj',true);
  2581. $sku = $this->input->post('sku',true);
  2582. $warehouse = $this->input->post('warehouse',true);
  2583. $purchase = $this->input->post('purchase',true);
  2584. $orderinfo = $this->input->post('orderinfo',true);
  2585. $waybill = $this->input->post('waybill',true);
  2586. $category = $this->input->post('category',true);
  2587. $size = $this->input->post('size',true);
  2588. $grade = $this->input->post('grade',true);
  2589. $color = $this->input->post('color',true);
  2590. $lowe = $this->input->post('lowe',true);
  2591. $state = $this->input->post('state',true);
  2592. $timetk = strtotime($timetk);
  2593. $timetj = strtotime($timetj);
  2594. $where = "state=2";
  2595. if($timetk && $timetj)
  2596. {
  2597. $where .= " and retreat > '$timetk' and retreat < '$timetj'";
  2598. }
  2599. if($sku)
  2600. {
  2601. $where .= " and sku = '$sku'";
  2602. }
  2603. if($warehouse)
  2604. {
  2605. $where .= " and warehouse = '$warehouse'";
  2606. }
  2607. if($purchase)
  2608. {
  2609. $where .= " and purchase = '$purchase'";
  2610. }
  2611. if($orderinfo)
  2612. {
  2613. $where .= " and orderinfo = '$orderinfo'";
  2614. }
  2615. if($waybill)
  2616. {
  2617. $where .= " and waybill = '$waybill'";
  2618. }
  2619. if($category)
  2620. {
  2621. $where .= " and features like '%-$category-%'";
  2622. }
  2623. if($size)
  2624. {
  2625. $where .= " and features like '%-$size-%'";
  2626. }
  2627. if($grade)
  2628. {
  2629. $where .= " and features like '%-$grade-%'";
  2630. }
  2631. if($color)
  2632. {
  2633. $where .= " and features like '%-$color-%'";
  2634. }
  2635. if($lowe)
  2636. {
  2637. $where .= " and features like '%-$lowe-%'";
  2638. }
  2639. //数据排序
  2640. $order_str = "time desc";
  2641. if(empty($page))
  2642. {
  2643. $start = 0;
  2644. $perpage = 1;
  2645. }
  2646. else
  2647. {
  2648. $start = ($page - 1)*$perpage;
  2649. }
  2650. //取得信息列表
  2651. $info_list = $this->specialstock->find_all($where,'id,warehouse,retreatwarehouse,sku,title,label,purchase,orderinfo,waybill,retreat,outk',$order_str,$start,$perpage);
  2652. foreach ($info_list as $key=>$value)
  2653. {
  2654. $warehouse = $this->warehouse->read($value['warehouse']);
  2655. $info_list[$key]['warehouse'] = $warehouse['title'];
  2656. $retreatwarehouse = $this->warehouse->read($value['retreatwarehouse']);
  2657. $info_list[$key]['retreatwarehouse'] = $retreatwarehouse['title'];
  2658. $purchase = $this->purchase->read($value['purchase']);
  2659. $info_list[$key]['purchase'] = $purchase['title'];
  2660. if($value['outk'] != 0)
  2661. {
  2662. $info_list[$key]['outk'] = date('Y-m-d H:i:s',$value['outk']);
  2663. }
  2664. else
  2665. {
  2666. $info_list[$key]['outk'] = "";
  2667. }
  2668. if($value['retreat'] != 0)
  2669. {
  2670. $info_list[$key]['retreat'] = date('Y-m-d H:i:s',$value['retreat']);
  2671. }
  2672. else
  2673. {
  2674. $info_list[$key]['retreat'] = "";
  2675. }
  2676. if($value['orderinfo'] == 0)
  2677. {
  2678. $info_list[$key]['orderinfo'] = "";
  2679. }
  2680. if($value['waybill'] == 0)
  2681. {
  2682. $info_list[$key]['waybill'] = "";
  2683. }
  2684. }
  2685. $total = $this->specialstock->find_count($where);
  2686. $pagenum = ceil($total/$perpage);
  2687. $over = $total-($start+$perpage);
  2688. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  2689. echo json_encode($rows);exit;
  2690. }
  2691. $this->_Template('specialstock_retreatlk',$this->data);
  2692. }
  2693. //更换标签及浏览
  2694. public function _change()
  2695. {
  2696. $post = $this->input->post(NULL, TRUE);
  2697. if(isset($post['page']))
  2698. {
  2699. $page = $this->input->post('page',true);
  2700. $perpage = $this->input->post('perpage',true);
  2701. $timetk = $this->input->post('timetk',true);
  2702. $timetj = $this->input->post('timetj',true);
  2703. $label = $this->input->post('label',true);
  2704. $oldlabel = $this->input->post('oldlabel',true);
  2705. $timetk = strtotime($timetk);
  2706. $timetj = strtotime($timetj);
  2707. $where = "state=10 ";
  2708. if($timetk && $timetj)
  2709. {
  2710. $where .= " and labeltime > '$timetk' and labeltime < '$timetj'";
  2711. }
  2712. if($label)
  2713. {
  2714. $where .= " and label = '$label'";
  2715. }
  2716. if($oldlabel)
  2717. {
  2718. $where .= " and oldlabel = '$oldlabel'";
  2719. }
  2720. //数据排序
  2721. $order_str = "time asc";
  2722. if(empty($page))
  2723. {
  2724. $start = 0;
  2725. $perpage = 1;
  2726. }
  2727. else
  2728. {
  2729. $start = ($page - 1)*$perpage;
  2730. }
  2731. //取得信息列表
  2732. $info_list = $this->specialstock->find_all($where,'id,oldlabel,oldtitle,label,title, labeltime',$order_str,$start,$perpage);
  2733. foreach ($info_list as $key=>$value)
  2734. {
  2735. $info_list[$key]['labeltime'] = date('Y-m-d H:i:s',$value['labeltime']);
  2736. }
  2737. $total = $this->specialstock->find_count($where);
  2738. $pagenum = ceil($total/$perpage);
  2739. $over = $total-($start+$perpage);
  2740. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  2741. echo json_encode($rows);exit;
  2742. }
  2743. $this->_Template('specialstock_change',$this->data);
  2744. }
  2745. //产品标签
  2746. public function _cpbqdc()
  2747. {
  2748. if(isset($_GET['excel']))
  2749. {
  2750. $where = "1=1";
  2751. //数据排序
  2752. $order_str = "id desc";
  2753. if(empty($page))
  2754. {
  2755. $start = 0;
  2756. $perpage = 1;
  2757. }
  2758. else
  2759. {
  2760. $start = ($page - 1)*$perpage;
  2761. }
  2762. $warehouse = $this->input->get('warehouse',true);
  2763. $state = $this->input->get('state',true);
  2764. $timetk = $this->input->get('timetkk',true);
  2765. $timetj = $this->input->get('timetjj',true);
  2766. $timetk = strtotime($timetk);
  2767. $timetj = strtotime($timetj);
  2768. if($warehouse)
  2769. {
  2770. $where .= " and warehouse = '$warehouse'";
  2771. }
  2772. if($state || $state == 0)
  2773. {
  2774. $where .= " and state = '$state'";
  2775. }
  2776. if($timetk && $timetj)
  2777. {
  2778. $where .= " and time > '$timetk' and time < '$timetj'";
  2779. }
  2780. //取得信息列表
  2781. $info_list = $this->specialstock->find_all($where,'*');
  2782. $rows = array();$list = array();
  2783. foreach ($info_list as $key=>$value)
  2784. {
  2785. $rows[$value['time']] = $value;//所有数据sku
  2786. }
  2787. foreach ($rows as $value)
  2788. {
  2789. $warehouse = $this->warehouse->read($value['warehouse']);
  2790. $s = $this->specialstock->find_count($where.' and time = "'.$value['time'].'"');
  2791. $list[] = array($warehouse['title'],$value['sku'],$value['title'],date('Y-m-d H:i:s',$value['enter']),date('Y-m-d H:i:s',$value['time']),$value['details'],$s);
  2792. }
  2793. $title = "产品标签统计表";
  2794. $titlename = "<table border=1>
  2795. <tr><th colspan='6' align='center'><h3>".$title."<h3></th></tr>
  2796. <tr align='center'>
  2797. <td>仓库</td>
  2798. <td>SKU</td>
  2799. <td>产品</td>
  2800. <td>入库时间</td>
  2801. <td>操作时间</td>
  2802. <td>备注</td>
  2803. <td>数量</td>
  2804. </tr>
  2805. </table>";
  2806. $filename = $title.".xls";
  2807. $tail = "";
  2808. $this->excel->get_fz2($list,$titlename,$filename,$tail);
  2809. }
  2810. }
  2811. //进销存导出
  2812. public function _exceljxc()
  2813. {
  2814. if(isset($_GET['excel']))
  2815. {
  2816. $where = "1=1";
  2817. //数据排序
  2818. $order_str = "id desc";
  2819. if(empty($page))
  2820. {
  2821. $start = 0;
  2822. $perpage = 1;
  2823. }
  2824. else
  2825. {
  2826. $start = ($page - 1)*$perpage;
  2827. }
  2828. $category = $this->input->get('category',true);
  2829. $warehouse = $this->input->get('warehouse',true);
  2830. $pc = $this->input->get('pc',true);
  2831. if($pc)
  2832. {
  2833. $pc = trim($pc,'x');
  2834. $pc = explode('x',$pc);
  2835. foreach ($pc as $v)
  2836. {
  2837. $where .= " and warehouse != '".$v."'";
  2838. }
  2839. }
  2840. if($category)
  2841. {
  2842. $where .= " and features like '%-$category-%'";
  2843. }
  2844. if($warehouse)
  2845. {
  2846. $where .= " and warehouse = '$warehouse'";
  2847. }
  2848. //取得信息列表
  2849. $info_list = $this->specialstock->find_pc($where,'sku,features,warehouse','id,features,sku,details,warehouse,number,title,cpbz');
  2850. $list = array();
  2851. foreach ($info_list as $value)
  2852. {
  2853. $classid = $this->classid->sku();
  2854. $pm = $classid;
  2855. //$scsku = array(13=>'',22=>'',8=>'',15=>'',18=>'','100'=>'',33=>'',34=>'',7=>'','dc'=>'','c'=>'',14=>'',12=>'',25=>'',26=>'',27=>'',10=>'',6=>'',9=>'',999=>'',9999=>'');
  2856. $features = explode('-',trim($value['features'],'-'));
  2857. foreach ($features as $v)
  2858. {
  2859. $typeclass = $this->typeclass->read($v);
  2860. $pm[$typeclass['classid']] = $typeclass['zh'];
  2861. //$scsku[$typeclass['classid']] = $typeclass['bqsku'];
  2862. }
  2863. $typeclass = $this->typeclass->read($v);
  2864. //$scsku = implode("-",$scsku);
  2865. $zh = implode(" ",$pm);
  2866. $zh = str_replace('自然色 ','',rtrim($zh,' '));
  2867. //$scsku = str_replace('- ','-',trim($scsku,'-'));
  2868. //$scsku = str_replace(array('--------','-------','------','-----','----','---','--'),'-',$scsku);
  2869. $cpid = '';
  2870. $c = $this->specialstock->find_all($where.' and sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and state = "0" and features = "'.$value['features'].'"','cpid');
  2871. foreach ($c as $v)
  2872. {
  2873. if($v['cpid'] != 0)
  2874. {
  2875. $cpid .= $v['cpid'].' ';
  2876. }
  2877. }
  2878. $g = $this->specialstock->find_count($where.' and sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and state != "9" and features = "'.$value['features'].'"');
  2879. $x = $this->specialstock->find_count($where.' and sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and state = "1" and features = "'.$value['features'].'"');
  2880. $t = $this->specialstock->find_count($where.' and sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and state = "2" and features = "'.$value['features'].'"');
  2881. $number = $value['number'];$ftime = time()-15*24*3600;
  2882. $warehouse = $this->warehouse->read($value['warehouse']);
  2883. $list[] = array($value['details'],$cpid,$value['title'],$value['sku'],$zh,$g,count($c),$x,$t,$value['cpbz']);
  2884. }
  2885. $title = "总进销存统计表";
  2886. $titlename = "<table border=1>
  2887. <tr><th colspan='10' align='center'><h3>".$title."<h3></th></tr>
  2888. <tr align='center'>
  2889. <td>位置</td>
  2890. <td>库存编码</td>
  2891. <td>产品</td>
  2892. <td>SKU</td>
  2893. <td>中文</td>
  2894. <td>入库总量</td>
  2895. <td>库存数量</td>
  2896. <td>销售数量</td>
  2897. <td>退货数量</td>
  2898. <td>备注</td>
  2899. </tr>
  2900. </table>";
  2901. $filename = $title.".xls";
  2902. $tail = "";
  2903. $this->excel->get_fz2($list,$titlename,$filename,$tail);
  2904. }
  2905. }
  2906. //入库导出
  2907. public function _excelr()
  2908. {
  2909. if(isset($_GET['excel']))
  2910. {
  2911. $category = $this->input->get('category',true);
  2912. $size = $this->input->get('size',true);
  2913. $grade = $this->input->get('grade',true);
  2914. $color = $this->input->get('color',true);
  2915. $lowe = $this->input->get('lowe',true);
  2916. $sku = $this->input->get('sku',true);
  2917. $warehouse = $this->input->get('warehouse',true);
  2918. $purchase = $this->input->get('purchase',true);
  2919. $ktime = $this->input->get('ktime',true);
  2920. $jtime = $this->input->get('jtime',true);
  2921. $ktime = strtotime($ktime);
  2922. $jtime = strtotime($jtime);
  2923. $where = "1=1";$gj = "";$ck = "";
  2924. $pc = $this->input->get('pc',true);
  2925. if($pc)
  2926. {
  2927. $pc = trim($pc,'x');
  2928. $pc = explode('x',$pc);
  2929. foreach ($pc as $v)
  2930. {
  2931. $where .= " and warehouse != '".$v."'";
  2932. }
  2933. }
  2934. if($category)
  2935. {
  2936. $where .= " and features like '%-$category-%'";
  2937. }
  2938. if($size)
  2939. {
  2940. $where .= " and features like '%-$size-%'";
  2941. }
  2942. if($grade)
  2943. {
  2944. $where .= " and features like '%-$grade-%'";
  2945. }
  2946. if($color)
  2947. {
  2948. $where .= " and features like '%-$color-%'";
  2949. }
  2950. if($lowe)
  2951. {
  2952. $where .= " and features like '%-$lowe-%'";
  2953. }
  2954. if($warehouse)
  2955. {
  2956. $where .= " and warehouse = '$warehouse'";
  2957. }
  2958. if($purchase)
  2959. {
  2960. $where .= " and purchase = '$purchase'";
  2961. }
  2962. if($sku)
  2963. {
  2964. $where .= " and sku = '$sku'";
  2965. }
  2966. if($ktime && $jtime)
  2967. {
  2968. $where .= " and enter > '$ktime' and enter < '$jtime' and state != 9";
  2969. }
  2970. //数据排序
  2971. $order_str = "id desc";
  2972. if(empty($page))
  2973. {
  2974. $start = 0;
  2975. $perpage = 1;
  2976. }
  2977. else
  2978. {
  2979. $start = ($page - 1)*$perpage;
  2980. }
  2981. //取得信息列表
  2982. $info_list = $this->specialstock->find_pc($where,'enter','*',$order_str);
  2983. $list = array();
  2984. foreach ($info_list as $value)
  2985. {
  2986. $ck = $this->warehouse->read($value['warehouse']);
  2987. $warehouse = $ck['title'];
  2988. $tkck = $this->warehouse->read($value['retreatwarehouse']);//退库仓库
  2989. $retreatwarehouse = $tkck['title'];
  2990. $gy = $this->purchase->read($value['purchase']);
  2991. $purchase = $gy['title'];
  2992. $cpid = '';
  2993. $g = $this->specialstock->find_all($where.' and enter = "'.$value['enter'].'"','cpid');
  2994. foreach ($g as $v)
  2995. {
  2996. if($v['cpid'] != 0)
  2997. {
  2998. $cpid .= $v['cpid'].' ';
  2999. }
  3000. }
  3001. $list[] = array('details'=>$value['details'],'title'=>$value['title'],'time'=>date('Y-m-d H:i:s',$value['enter']),'number'=>count($g),'cpid'=>$cpid);
  3002. }
  3003. $title = date('Y-m-d',$ktime).'至'.date('Y-m-d',$jtime)."入库详情";
  3004. $titlename = "<table border=1>
  3005. <tr><th colspan='4' align='center'><h3>".$title."<h3></th></tr>
  3006. <tr align='center'>
  3007. <td>备注</td>
  3008. <td>产品</td>
  3009. <td>时间</td>
  3010. <td>数量</td>
  3011. <td>编码</td>
  3012. </tr>
  3013. </table>";
  3014. $filename = $title.".xls";
  3015. $tail = "";
  3016. $this->excel->get_fz2($list,$titlename,$filename,$tail);
  3017. }
  3018. }
  3019. //出库、退库导出
  3020. public function _excelct()
  3021. {
  3022. if(isset($_GET['excel']))
  3023. {
  3024. $type = $this->input->get('excel',true);
  3025. $category = $this->input->get('category',true);
  3026. $size = $this->input->get('size',true);
  3027. $grade = $this->input->get('grade',true);
  3028. $color = $this->input->get('color',true);
  3029. $lowe = $this->input->get('lowe',true);
  3030. $lacetype = $this->input->get('lacetype',true);
  3031. $details = $this->input->get('details',true);
  3032. $sku = $this->input->get('sku',true);
  3033. $warehouse = $this->input->get('warehouse',true);
  3034. $purchase = $this->input->get('purchase',true);
  3035. $state = $this->input->get('state',true);
  3036. $sid = $this->input->get('sid',true);
  3037. $ktime = $this->input->get('ktime',true);
  3038. $jtime = $this->input->get('jtime',true);
  3039. $ktime = strtotime($ktime);
  3040. $jtime = strtotime($jtime);
  3041. $where = "1=1";$gj = "";$ck = "";
  3042. $pc = $this->input->get('pc',true);
  3043. if($pc)
  3044. {
  3045. $pc = trim($pc,'x');
  3046. $pc = explode('x',$pc);
  3047. foreach ($pc as $v)
  3048. {
  3049. $where .= " and warehouse != '".$v."'";
  3050. }
  3051. }
  3052. if($category)
  3053. {
  3054. $where .= " and features like '%-$category-%'";
  3055. }
  3056. if($size)
  3057. {
  3058. $where .= " and features like '%-$size-%'";
  3059. }
  3060. if($grade)
  3061. {
  3062. $where .= " and features like '%-$grade-%'";
  3063. }
  3064. if($color)
  3065. {
  3066. $where .= " and features like '%-$color-%'";
  3067. }
  3068. if($lowe)
  3069. {
  3070. $where .= " and features like '%-$lowe-%'";
  3071. }
  3072. if($warehouse)
  3073. {
  3074. $where .= " and warehouse = '$warehouse'";
  3075. }
  3076. if($purchase)
  3077. {
  3078. $where .= " and purchase = '$purchase'";
  3079. }
  3080. if($state)
  3081. {
  3082. $where .= " and state = '$state'";
  3083. }
  3084. if($sku)
  3085. {
  3086. $where .= " and sku like '%$sku%'";
  3087. }
  3088. if($lacetype)
  3089. {
  3090. $where .= " and features like '%-$lacetype-%'";
  3091. }
  3092. if($details)
  3093. {
  3094. $where .= " and details like '%$details%'";
  3095. }
  3096. if($ktime && $jtime)
  3097. {
  3098. if($type == 1)
  3099. {
  3100. $tl = '出库';
  3101. $where .= " and state= '1' and outk > '$ktime' and outk < '$jtime'";
  3102. }
  3103. else if($type == 2)
  3104. {
  3105. $tl = '退库';
  3106. $where .= " and state= '2' and retreat > '$ktime' and retreat < '$jtime'";
  3107. }
  3108. else if($type == 3)
  3109. {
  3110. $gj = " and enter > '$ktime' and enter < '$jtime'";
  3111. $ck = " and outk > '$ktime' and outk < '$jtime'";
  3112. }
  3113. else if($type == 4)
  3114. {
  3115. $tl = '出库+零售';
  3116. $where .= " and (state= '1' or state= '10') and outk > '$ktime' and outk < '$jtime'";
  3117. }
  3118. else if($type == 5)
  3119. {
  3120. $tl = '零售';
  3121. $where .= " and state= '10' and outk > '$ktime' and outk < '$jtime'";
  3122. }
  3123. }
  3124. if($sid)
  3125. {
  3126. $sd = "";
  3127. $s = explode(',',trim($sid,','));
  3128. foreach ($s as $value)
  3129. {
  3130. $sd .= " id = ".$value." or";
  3131. }
  3132. $sidwhere .= " and (".rtrim($sd,'or').")";
  3133. }
  3134. //数据排序
  3135. $order_str = "time desc";
  3136. if(empty($page))
  3137. {
  3138. $start = 0;
  3139. $perpage = 1;
  3140. }
  3141. else
  3142. {
  3143. $start = ($page - 1)*$perpage;
  3144. }
  3145. //取得信息列表
  3146. if($type != 3 && $type != 5)
  3147. {
  3148. if($type == 1 || $type == 4)
  3149. {
  3150. $info_list = $this->specialstock->find_all($where,'details,cpid,title,label,orderinfo,waybill,outk,cpbz',$order_str);
  3151. foreach ($info_list as $key=>$value)
  3152. {
  3153. $info_list[$key]['outk'] = date('Y-m-d H:i:s',$value['outk']);//减12调整美国时间
  3154. }
  3155. }
  3156. else
  3157. {
  3158. $info_list = $this->specialstock->find_all($where,'details,cpid,title,label,orderinfo,waybill,retreat,cpbz',$order_str);
  3159. foreach ($info_list as $key=>$value)
  3160. {
  3161. $info_list[$key]['retreat'] = date('Y-m-d H:i:s',$value['retreat']);//减12调整美国时间
  3162. }
  3163. }
  3164. $title = date('Y-m-d',$ktime).'至'.date('Y-m-d',$jtime).$tl.'详情';
  3165. $titlename = "<table border=1>
  3166. <tr><th colspan='8' align='center'><h3>".$title."<h3></th></tr>
  3167. <tr align='center'>
  3168. <td>位置</td>
  3169. <td>产品编码</td>
  3170. <td>产品</td>
  3171. <td>标签</td>
  3172. <td>订单号</td>
  3173. <td>运单号</td>
  3174. <td>".$tl."时间(中国时间)</td>
  3175. <td>备注</td>
  3176. </tr>
  3177. </table>";
  3178. $filename = $title.".xls";
  3179. $tail = "";
  3180. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  3181. }
  3182. else if($type == 5)
  3183. {
  3184. $info_list = $this->specialstock->find_all($where,'details,cpid,title,label,outk,cpbz',$order_str);
  3185. foreach ($info_list as $key=>$value)
  3186. {
  3187. $info_list[$key]['outk'] = date('Y-m-d H:i:s',$value['outk']);//减12调整美国时间
  3188. $warehouse = $this->warehouse->read($value['warehouse']);
  3189. $info_list[$key]['warehouse'] = $warehouse['title'];
  3190. }
  3191. $title = date('Y-m-d',$ktime).'至'.date('Y-m-d',$jtime).$tl.'详情';
  3192. $titlename = "<table border=1>
  3193. <tr><th colspan='6' align='center'><h3>".$title."<h3></th></tr>
  3194. <tr align='center'>
  3195. <td>位置</td>
  3196. <td>产品编码</td>
  3197. <td>产品</td>
  3198. <td>标签</td>
  3199. <td>".$tl."时间(中国时间)</td>
  3200. <td>备注</td>
  3201. </tr>
  3202. </table>";
  3203. $filename = $title.".xls";
  3204. $tail = "";
  3205. $this->excel->get_fz2($info_list,$titlename,$filename,$tail);
  3206. }
  3207. else
  3208. {
  3209. $info_list = $this->specialstock->find_pc($where.$sidwhere,'sku,warehouse,features','*');
  3210. $list = array();
  3211. foreach ($info_list as $value)
  3212. {
  3213. $classid = $this->classid->sku();
  3214. $pm = $classid;
  3215. //$scsku = array(13=>'',22=>'',8=>'',15=>'',18=>'','100'=>'',33=>'',34=>'',7=>'','dc'=>'','c'=>'',14=>'',12=>'',25=>'',26=>'',27=>'',10=>'',6=>'',9=>'',999=>'',9999=>'');
  3216. $features = explode('-',trim($value['features'],'-'));
  3217. foreach ($features as $v)
  3218. {
  3219. $typeclass = $this->typeclass->read($v);
  3220. $pm[$typeclass['classid']] = $typeclass['zh'];
  3221. //$scsku[$typeclass['classid']] = $typeclass['bqsku'];
  3222. }
  3223. $typeclass = $this->typeclass->read($v);
  3224. //$scsku = implode("-",$scsku);
  3225. $zh = implode(" ",$pm);
  3226. $zh = str_replace('自然色 ','',rtrim($zh,' '));
  3227. //$scsku = str_replace('- ','-',trim($scsku,'-'));
  3228. //$scsku = str_replace(array('--------','-------','------','-----','----','---','--'),'-',$scsku);
  3229. $cpid = '';
  3230. $c = $this->specialstock->find_all($where.' and sku = "'.$value['sku'].'" and features = "'.$value['features'].'" and warehouse = "'.$value['warehouse'].'" and state = "0"','cpid');
  3231. foreach ($c as $v)
  3232. {
  3233. if($v['cpid'] != 0)
  3234. {
  3235. $cpid .= $v['cpid'].' ';
  3236. }
  3237. }
  3238. $g = $this->specialstock->find_count($where.$gj.' and sku = "'.$value['sku'].'" and features = "'.$value['features'].'" and warehouse = "'.$value['warehouse'].'" and state != "9"');
  3239. $x = $this->specialstock->find_count($where.$ck.' and sku = "'.$value['sku'].'" and features = "'.$value['features'].'" and warehouse = "'.$value['warehouse'].'" and state = "1"');
  3240. $t = $this->specialstock->find_count($where.$ck.' and sku = "'.$value['sku'].'" and features = "'.$value['features'].'" and warehouse = "'.$value['warehouse'].'" and state = "2"');
  3241. $number = $value['number'];$ftime = time()-15*24*3600;
  3242. $warehouse = $this->warehouse->read($value['warehouse']);
  3243. $list[] = array($value['details'],$cpid,$value['title'],$value['sku'],$zh,$g,count($c),$x,$t,$value['cpbz']);
  3244. }
  3245. $title = date('Y-m-d',$ktime).'至'.date('Y-m-d',$jtime).'进销存详情';
  3246. $titlename = "<table border=1>
  3247. <tr><th colspan='9' align='center'><h3>".$title."<h3></th></tr>
  3248. <tr align='center'>
  3249. <td>位置</td>
  3250. <td>库存编码</td>
  3251. <td>产品</td>
  3252. <td>SKU</td>
  3253. <td>中文</td>
  3254. <td>入库总量</td>
  3255. <td>库存数量</td>
  3256. <td>销售数量</td>
  3257. <td>退货数量</td>
  3258. <td>备注</td>
  3259. </tr>
  3260. </table>";
  3261. $filename = $title.".xls";
  3262. $tail = "";
  3263. $this->excel->get_fz2($list,$titlename,$filename,$tail);
  3264. }
  3265. }
  3266. }
  3267. //数量调整模板导出
  3268. public function _presetout()
  3269. {
  3270. if(isset($_GET['excel']))
  3271. {
  3272. $where = "1=1";
  3273. //数据排序
  3274. $order_str = "id desc";
  3275. if(empty($page))
  3276. {
  3277. $start = 0;
  3278. $perpage = 1;
  3279. }
  3280. else
  3281. {
  3282. $start = ($page - 1)*$perpage;
  3283. }
  3284. $pc = $this->input->get('pc',true);
  3285. if($pc)
  3286. {
  3287. $pc = trim($pc,'x');
  3288. $pc = explode('x',$pc);
  3289. foreach ($pc as $v)
  3290. {
  3291. $where .= " and warehouse != '".$v."'";
  3292. }
  3293. }
  3294. //取得信息列表
  3295. $info_list = $this->specialstock->find_all($where,'*');
  3296. $rows = array();$list = array();
  3297. foreach ($info_list as $key=>$value)
  3298. {
  3299. $rows[$value['number']] = $value;//所有数据sku
  3300. }
  3301. foreach ($rows as $value)
  3302. {
  3303. $warehouse = $this->warehouse->read($value['warehouse']);
  3304. $number = $value['number'];$ftime = time()-15*24*3600;
  3305. $list[] = array($value['features'],$value['sku'],'0','','0',$warehouse['title']);
  3306. }
  3307. $title = "库存模板";
  3308. $titlename = "<table border=1>
  3309. <tr align='center'>
  3310. <td>编码号</td>
  3311. <td>SKU</td>
  3312. <td>增减数量(正数或负数)</td>
  3313. <td>扣减备注</td>
  3314. <td>扣减方式:0减少库存1删除库存</td>
  3315. <td>所属仓库</td>
  3316. </tr>
  3317. </table>";
  3318. $filename = $title.".xls";
  3319. $tail = "";
  3320. $this->excel->get_fz2($list,$titlename,$filename,$tail);
  3321. }
  3322. }
  3323. //数量调整模板导入
  3324. public function _presetedit()
  3325. {
  3326. $dir = '/data/excel/'.date('Ymd',time()).'/';
  3327. $config['upload_path'] = '.'.$dir ;
  3328. $config['file_name'] = date('Ymd_His_',time()).rand(1000,9999);
  3329. $config['allowed_types'] = 'xls|xlsx|csv';
  3330. $config['max_size'] = 10240;
  3331. $this->load->library('upload', $config);
  3332. $this->upload->initialize($config);
  3333. if ($this->upload->do_upload('userfile'))
  3334. {
  3335. $full_path = $dir.$this->upload->data('file_name');
  3336. $fileName = '.' . $full_path;
  3337. if (!file_exists($fileName))
  3338. {
  3339. echo json_encode(array('msg'=>"上传失败,请重试",'success'=>false));exit;
  3340. }
  3341. else
  3342. {
  3343. libxml_use_internal_errors(true);
  3344. require_once "./data/excel/PHPExcel/IOFactory.php";
  3345. $phpExcel = PHPExcel_IOFactory::load($fileName);// 载入当前文件
  3346. $phpExcel->setActiveSheetIndex(0);// 设置为默认表
  3347. $sheetCount = $phpExcel->getSheetCount();// 获取表格数量
  3348. $row = $phpExcel->getActiveSheet()->getHighestRow();// 获取行数
  3349. $column = $phpExcel->getActiveSheet()->getHighestColumn();// 获取列数
  3350. ++$column;//如果列数大于26行
  3351. $list = array();
  3352. for ($i = 2; $i <= $row; $i++) // 行数循环
  3353. {
  3354. $data = array();
  3355. for ($c = 'A'; $c != $column; $c++) // 列数循环
  3356. {
  3357. $data[] = $phpExcel->getActiveSheet()->getCell($c . $i)->getValue();
  3358. }
  3359. $list[] = $data;
  3360. }
  3361. }
  3362. $i = 0;$j = 0;$ed = array();
  3363. foreach ($list as $key=>$value)
  3364. {
  3365. $time = time();
  3366. if($value['0'] == "")
  3367. {
  3368. continue;
  3369. }
  3370. $features = $value['0'];
  3371. $num = $value['2'];//调整数量
  3372. $text = $value['3'];//扣减说明
  3373. $type = $value['4'];//调整方式0扣减1删除
  3374. $d = $this->specialstock->get_features($features);
  3375. if(!$d)//如果没有这个SKU
  3376. {
  3377. $ed[] = array($title.'-库存中不存在此编码');
  3378. $j++;
  3379. continue;
  3380. }
  3381. if($num < 0)//扣减库存
  3382. {
  3383. $data = $this->specialstock->find_all('warehouse = "'.$warehouse['id'].'" and features = "'.$features.'" and zd = "" and state = 0');
  3384. if(count($data) < abs($num))
  3385. {
  3386. $ed[] = array($title.'-扣减数量大于库存剩余数量!');
  3387. $j++;
  3388. continue;
  3389. }
  3390. if($type == 0)//如果扣减方式为 扣减库存
  3391. {
  3392. for($i=0;$i<abs($num);$i++)
  3393. {
  3394. $this->specialstock->save(array('state'=>8,'text'=>$text,'deltime'=>$time,'time'=>$time),$data[$i]['id']);
  3395. }
  3396. }
  3397. else
  3398. {
  3399. for($i=0;$i<abs($num);$i++)
  3400. {
  3401. $this->specialstock->remove($data[$i]['id']);
  3402. }
  3403. }
  3404. }
  3405. else if($num > 0)//增加库存
  3406. {
  3407. $post['shop'] = $d['shop'];
  3408. $post['purchase'] = $d['purchase'];
  3409. $post['retreatwarehouse'] = $d['retreatwarehouse'];
  3410. $post['state'] = 0;
  3411. $post['title'] = $d['title'];
  3412. $post['number'] = $d['number'];
  3413. $post['features'] = $d['features'];
  3414. $post['enter'] = $time;
  3415. $post['time'] = $time;//操作时间
  3416. for($i=0;$i<$num;$i++)
  3417. {
  3418. $post['label'] = time().rand(100,999).$i;
  3419. $this->specialstock->insert($post);
  3420. }
  3421. }
  3422. sleep(1);//防止入库时间一样,需要延迟1秒
  3423. }
  3424. if($j > 0)
  3425. {
  3426. $tt = date('Ymd',time());
  3427. $title = '库存导入错误信息-'.$tt;
  3428. $titlename = "<table border=1><tr><td>错误详情</td></tr></table>";
  3429. $tail = "\n";
  3430. $filename = $title.".xls";
  3431. $ecl = $this->excel->get_fz3($ed,$titlename,$filename,$tail);
  3432. $dir = '/data/excel/'.$time.'/';
  3433. $file_name = 'error_'.$time.rand(1000,9999);
  3434. if(!is_dir('.'.$dir))mkdir('.'.$dir,0777);
  3435. $myfile = fopen(".".$dir.$file_name.".xls", "w") or die();
  3436. fwrite($myfile,$ecl);
  3437. fclose($myfile);
  3438. $error = $dir.$file_name.'.xls';
  3439. echo json_encode(array('msg'=>'导入成功,'.$j.'条异常,','error'=>$error,'success'=>true));exit;
  3440. }
  3441. else
  3442. {
  3443. echo json_encode(array('msg'=>'导入成功!','error'=>1,'success'=>true));exit;
  3444. }
  3445. }
  3446. }
  3447. //笛卡儿积
  3448. function cp($ps,$sets,$list)
  3449. {
  3450. $result = array();$j=0;
  3451. for($i=0,$count=count($sets); $i<$count-1; $i++)
  3452. {
  3453. if($i==0)
  3454. {
  3455. $result = $sets[$i];
  3456. }
  3457. $tmp = array();
  3458. foreach($result as $res)
  3459. {
  3460. foreach($sets[$i+1] as $set)
  3461. {
  3462. $tmp[] = $res.','.$set;
  3463. }
  3464. }
  3465. $result = $tmp;
  3466. }
  3467. $this->db->trans_begin();
  3468. foreach ($result as $v)
  3469. {
  3470. $post = array();$title = "";$num="";
  3471. $data = explode(',',$v);
  3472. for($i=0;$i<count($list); $i++)
  3473. {
  3474. $post[$list[$i]] = $data[$i];
  3475. $typeclass = $this->typeclass->read($data[$i]);
  3476. $title = $title.$typeclass['title']." ";
  3477. if($data[$i] != 0)
  3478. {
  3479. $num .=$data[$i];//所有数据ID拼接
  3480. }
  3481. }
  3482. foreach ($ps as $kp=>$vp)
  3483. {
  3484. $post[$kp] = $vp;
  3485. }
  3486. $post['number'] = $num;
  3487. $info_list = $this->specialstock->get_number($num);//查询specialstock是否存在此拼接的数据ID
  3488. if($info_list)
  3489. {
  3490. $j++;
  3491. }
  3492. else
  3493. {
  3494. $skunum = $this->specialstock->find_count();
  3495. $post['sku'] = 'LY'.substr(strval($skunum+1+10000000),1,7);
  3496. $post['title'] = rtrim($title,' ');
  3497. $this->specialstock->insert($post);
  3498. }
  3499. }
  3500. if ($this->db->trans_status() === FALSE)
  3501. {
  3502. $this->db->trans_commit();
  3503. return NULL;
  3504. }
  3505. else
  3506. {
  3507. $this->db->trans_commit();
  3508. return $j;
  3509. }
  3510. }
  3511. public function _kj($arg_array)
  3512. {
  3513. if(isset($_POST['number']))
  3514. {
  3515. $time = time();
  3516. $number = $this->input->post('number',true);
  3517. $num = $this->input->post('num',true);
  3518. $text = $this->input->post('text',true);
  3519. $order = $this->specialstock->find_all("number = '$number' and zd = '' and state = 0");
  3520. if($num > count($order))
  3521. {
  3522. echo json_encode(array('msg'=>"扣减数量大于剩余库存数量!",'success'=>false));exit;
  3523. }
  3524. else
  3525. {
  3526. for($i=0;$i<$num;$i++)
  3527. {
  3528. $this->specialstock->save(array('state'=>8,'text'=>$text,'deltime'=>$time,'time'=>$time),$order[$i]['id']);
  3529. }
  3530. }
  3531. echo json_encode(array('msg'=>"扣减成功!",'success'=>false));exit;
  3532. }
  3533. $uid = $this->specialstock->read($arg_array[0]);
  3534. $uid['num'] = $this->specialstock->find_count('number = "'.$uid['number']. '" and zd = "" and state = 0');
  3535. $this->data['data'] = $uid ;
  3536. $this->_Template('specialstock_kj',$this->data);
  3537. }
  3538. public function _summary($arg_array)
  3539. {
  3540. if(isset($_GET['excel']))
  3541. {
  3542. $ktime = $this->input->get('ktime',true);
  3543. $jtime = $this->input->get('jtime',true);
  3544. $ktime = strtotime($ktime);
  3545. $jtime = strtotime($jtime);
  3546. $where = "1=1";
  3547. if($ktime && $jtime)
  3548. {
  3549. $where .= " and outk > '$ktime' and outk < '$jtime'";
  3550. }
  3551. //数据排序
  3552. $order_str = "time desc";
  3553. if(empty($page))
  3554. {
  3555. $start = 0;
  3556. $perpage = 1;
  3557. }
  3558. else
  3559. {
  3560. $start = ($page - 1)*$perpage;
  3561. }
  3562. $pc = $this->input->get('pc',true);
  3563. if($pc)
  3564. {
  3565. $pc = trim($pc,'x');
  3566. $pc = explode('x',$pc);
  3567. foreach ($pc as $v)
  3568. {
  3569. $where .= " and warehouse != '".$v."'";
  3570. }
  3571. }
  3572. //取得信息列表
  3573. $info_list = $this->specialstock->find_pc($where,'number','*');
  3574. foreach ($info_list as $value)
  3575. {
  3576. $xcpid = '';$scpid = '';
  3577. $x = $this->specialstock->find_all($where.' and number = "'.$value['number'].'"');
  3578. foreach ($x as $v)
  3579. {
  3580. if($v['cpid'] != 0)
  3581. {
  3582. $xcpid .= $v['cpid'].' ';
  3583. }
  3584. }
  3585. $s = $this->specialstock->find_all('state = 0 and number = "'.$value['number'].'"');
  3586. foreach ($s as $v)
  3587. {
  3588. if($v['cpid'] != 0)
  3589. {
  3590. $scpid .= $v['cpid'].' ';
  3591. }
  3592. }
  3593. $list[] = array('details'=>$value['details'],'title'=>$value['title'],'s'=>count($s),'x'=>count($x),'scpid'=>$scpid,'xcpid'=>$xcpid,'outk'=>date('Y-m-d H:i:s',$value['outk']));
  3594. }
  3595. $title = date('Y-m-d',$ktime).'至'.date('Y-m-d',$jtime).'出库汇总详情';
  3596. $titlename = "<table border=1>
  3597. <tr align='center'>
  3598. <td>仓库备注</td>
  3599. <td>产品名</td>
  3600. <td>总剩余库存</td>
  3601. <td>".date('Y-m-d',$ktime).'至'.date('Y-m-d',$jtime)."销售数量</td>
  3602. <td>剩余产品编码</td>
  3603. <td>销售产品编码</td>
  3604. <td>出库时间</td>
  3605. </tr>
  3606. </table>";
  3607. $filename = $title.".xls";
  3608. $tail = "";
  3609. $this->excel->get_fz2($list,$titlename,$filename,$tail);
  3610. }
  3611. }
  3612. //usps发货清单
  3613. public function _manifest()
  3614. {
  3615. if(isset($_POST['manifest']))
  3616. {
  3617. $wltext = $this->input->post('wltext',true);
  3618. $time = time()-16*3600;
  3619. $ptime = strtotime(date('Y-m-d',$time));
  3620. $waybill = array();
  3621. $fullorder = $this->fullorder->find_all("printtime > '$ptime' and librarytime > '$ptime' and library = 2 and waybill != '' and (type = 5 or type = 8)",'number,waybill');
  3622. foreach ($fullorder as $v)
  3623. {
  3624. $waybill[$v['waybill']] = $v['waybill'];
  3625. }
  3626. $fullordersmt = $this->fullordersmt->find_all("printtime > '$ptime' and librarytime > '$ptime' and library = 2 and waybill != '' and (type = 5 or type = 8)",'number,waybill');
  3627. foreach ($fullordersmt as $v)
  3628. {
  3629. $waybill[$v['waybill']] = $v['waybill'];
  3630. }
  3631. $wltext = explode(';',$wltext);
  3632. foreach ($wltext as $v)
  3633. {
  3634. if(isset($waybill[$v]))
  3635. {
  3636. unset($waybill[$v]);
  3637. }
  3638. }
  3639. $data = $this->usps->get_manifest($waybill);
  3640. if(isset($data['Description']))
  3641. {
  3642. echo json_encode(array('msg'=>$data['Description'],'success'=>false));exit;
  3643. }
  3644. else if(isset($data['SCANFormImage']) && isset($data['SCANFormNumber']))
  3645. {
  3646. $bctime = date('Ymd',time());
  3647. $pdf = $this->_pdf($data['SCANFormImage'],$data['SCANFormNumber'],$bctime);
  3648. echo json_encode(array('msg'=>$pdf,'success'=>true));exit;
  3649. }
  3650. else
  3651. {
  3652. echo json_encode(array('msg'=>$data,'success'=>false));exit;
  3653. }
  3654. }
  3655. }
  3656. public function _pdf($pdf,$title,$bctime)
  3657. {
  3658. $pdf_path = './data/pdf/'.$bctime.'/';
  3659. $file_base64 = $pdf;
  3660. $file_base64 = preg_replace('/data:.*;base64,/i', '', $file_base64);
  3661. $file_base64 = base64_decode($file_base64);
  3662. if(!is_dir($pdf_path))mkdir($pdf_path,0777); //上传目录不存在则创建
  3663. file_put_contents($pdf_path.$title.'.pdf',$file_base64);
  3664. return 'http://'.$_SERVER['HTTP_HOST'].'/data/pdf/'.$bctime.'/'.$title.'.pdf';
  3665. }
  3666. /**
  3667. *
  3668. *
  3669. *
  3670. 进销存占单异常索引
  3671. *
  3672. *
  3673. *
  3674. **/
  3675. public function _abnormal()
  3676. {
  3677. $post = $this->input->post(NULL, TRUE);
  3678. if(isset($post['page']))
  3679. {
  3680. $page = $this->input->post('page',true);
  3681. $perpage = $this->input->post('perpage',true);
  3682. $sku = $this->input->post('sku',true);
  3683. $where = "1=1";
  3684. //数据排序
  3685. $order_str = "id desc";
  3686. if(empty($page))
  3687. {
  3688. $start = 0;
  3689. $perpage = 1;
  3690. }
  3691. else
  3692. {
  3693. $start = ($page - 1)*$perpage;
  3694. }
  3695. //取得信息列表
  3696. $info_list = $this->specialstock->find_all($where,'*');
  3697. $rows = array();$list = array();
  3698. foreach ($info_list as $key=>$value)
  3699. {
  3700. $rows[$value['sku']] = $value;//所有数据sku
  3701. }
  3702. foreach ($rows as $value)
  3703. {
  3704. $warehouse = $this->warehouse->read($value['warehouse']);
  3705. $c = $this->specialstock->find_count('sku = "'.$value['sku'].'" and state = "0" and warehouse = "5"');
  3706. $number = $value['number'];$ftime = time()-15*24*3600;
  3707. if($value['shop'] != '')
  3708. {
  3709. $shop = $value['shop'];
  3710. $orderdlz = $this->fullorder->find_all("time > '$ftime' and shop = '$shop' and type = '5' and library = '1' and state = '207' and specialstock like '%|$number-%'",'specialstock,shop,orderinfo,number');
  3711. $ordersmt = $this->fullordersmt->find_all("time > '$ftime' and shop = '$shop' and type = '5' and library = '1' and state = '207' and specialstock like '%|$number-%'",'specialstock,shop,orderinfo,number');
  3712. $order = array_merge($orderdlz,$ordersmt);
  3713. $od = 0;$a = '';$orid = '';
  3714. foreach ($order as $v)
  3715. {
  3716. $or = explode('|',ltrim($v['specialstock'],'|'));
  3717. for($i=0;$i<count($or);$i++)
  3718. {
  3719. $orod = explode('-',$or[$i]);
  3720. if($orod[0] == $number)
  3721. {
  3722. $od += $orod[1];
  3723. }
  3724. }
  3725. $orid .= $v['number'].'-';
  3726. }
  3727. }
  3728. else
  3729. {
  3730. $orderdlz = $this->fullorder->find_all("time > '$ftime' and type = '5' and library = '1' and state = '207' and specialstock like '%|$number-%'",'specialstock,shop,orderinfo,number');
  3731. $ordersmt = $this->fullordersmt->find_all("time > '$ftime' and type = '5' and library = '1' and state = '207' and specialstock like '%|$number-%'",'specialstock,shop,orderinfo,number');
  3732. $order = array_merge($orderdlz,$ordersmt);
  3733. $od = 0;$a = '';$orid = '';$qt = array();
  3734. foreach ($order as $v)
  3735. {
  3736. $or = explode('|',ltrim($v['specialstock'],'|'));
  3737. for($i=0;$i<count($or);$i++)
  3738. {
  3739. $orod = explode('-',$or[$i]);
  3740. if($orod[0] == $number)
  3741. {
  3742. $czzs = $this->specialstock->find_count("number = '$number' and warehouse = '5' and shop = '".$v['shop']."' and state = 0");
  3743. if($czzs > 0)
  3744. {
  3745. if(isset($qt[$v['shop']]))
  3746. {
  3747. if($qt[$v['shop']] < $orod[1])
  3748. {
  3749. $od += $orod[1];//专属小于单量不计算剩余直接归入通用
  3750. $orid .= $v['number'].'+数量'.$orod[1].'-';
  3751. }
  3752. else
  3753. {
  3754. $qt[$v['shop']] -= $orod[1];
  3755. }
  3756. }
  3757. else
  3758. {
  3759. $qt[$v['shop']] = $czzs;
  3760. }
  3761. }
  3762. else
  3763. {
  3764. $od += $orod[1];
  3765. $orid .= $v['number'].'+数量'.$orod[1].'-';
  3766. }
  3767. }
  3768. }
  3769. }
  3770. }
  3771. $z = $od.'('.$orid.')';//查看订单号
  3772. //$z = $od;
  3773. if($od > $c)
  3774. {
  3775. $list[] = array('id'=>$value['id'],'warehouse'=>$warehouse['title'],'sku'=>$value['sku'],'title'=>$value['title'],'c'=>$c,'z'=>$z);
  3776. }
  3777. }
  3778. $listdata = array_slice($list,$start,$perpage);
  3779. $total = count($list);
  3780. $pagenum = ceil($total/$perpage);
  3781. $over = $total-($start+$perpage);
  3782. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($listdata));
  3783. echo json_encode($rows);exit;
  3784. }
  3785. $this->_Template('specialstock_abnormal',$this->data);
  3786. }
  3787. /**
  3788. *
  3789. *
  3790. *
  3791. 进销存占单异常索引
  3792. *
  3793. *
  3794. *
  3795. **/
  3796. public function _error()
  3797. {
  3798. $post = $this->input->post(NULL, TRUE);
  3799. if(isset($post['page']))
  3800. {
  3801. $page = $this->input->post('page',true);
  3802. $perpage = $this->input->post('perpage',true);
  3803. $sku = $this->input->post('sku',true);
  3804. $warehouse = $this->input->post('warehouse',true);
  3805. $where = "1=1";
  3806. if($sku)
  3807. {
  3808. $where .= " and sku = '$sku'";
  3809. }
  3810. if($warehouse)
  3811. {
  3812. $where .= " and warehouse = '$warehouse'";
  3813. }
  3814. //数据排序
  3815. $order_str = "id desc";
  3816. if(empty($page))
  3817. {
  3818. $start = 0;
  3819. $perpage = 1;
  3820. }
  3821. else
  3822. {
  3823. $start = ($page - 1)*$perpage;
  3824. }
  3825. //取得信息列表
  3826. $info_list = $this->specialstock->find_all($where,'*');
  3827. $rows = array();$list = array();
  3828. foreach ($info_list as $key=>$value)
  3829. {
  3830. if($value['sku'] != '')
  3831. {
  3832. $rows[$value['sku']] = $value;//所有数据sku
  3833. }
  3834. }
  3835. foreach ($rows as $value)
  3836. {
  3837. $warehouse = $this->warehouse->read($value['warehouse']);
  3838. $c = $this->specialstock->find_count('sku = "'.$value['sku'].'" and state = "0" and warehouse = "'.$value['warehouse'].'"');
  3839. $number = $value['number'];$ftime = time()-15*24*3600;
  3840. if($c < 1)
  3841. {
  3842. $list[] = array('id'=>$value['id'],'warehouse'=>$warehouse['title'],'sku'=>$value['sku'],'title'=>$value['title'],'c'=>$c);
  3843. }
  3844. }
  3845. $listdata = array_slice($list,$start,$perpage);
  3846. $total = count($list);
  3847. $pagenum = ceil($total/$perpage);
  3848. $over = $total-($start+$perpage);
  3849. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($listdata));
  3850. echo json_encode($rows);exit;
  3851. }
  3852. if(isset($post['s']))
  3853. {
  3854. $id_arr = $this->input->post('s');
  3855. $id_arr = explode(',',$id_arr);
  3856. if(!$id_arr)
  3857. {
  3858. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  3859. }
  3860. //循环删除记录
  3861. foreach ($id_arr as $v)
  3862. {
  3863. $dd = $this->specialstock->read($v);
  3864. $deldd = $this->specialstock->find_all("sku = '".$dd['sku']."'");
  3865. foreach ($deldd as $vv)
  3866. {
  3867. $this->specialstock->remove($vv['id']);
  3868. }
  3869. }
  3870. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));exit;
  3871. }
  3872. $this->_Template('specialstock_error',$this->data);
  3873. }
  3874. /**
  3875. *
  3876. *
  3877. * 占单
  3878. *
  3879. *
  3880. **/
  3881. public function _kcyz()
  3882. {
  3883. $post = $this->input->post(NULL, TRUE);
  3884. if(isset($post['warehouse']))
  3885. {
  3886. $warehouse = $this->input->post('warehouse',true);
  3887. $specialstock = $this->input->post('specialstock',true);
  3888. $id = $this->input->post('id',true);
  3889. $shop = $this->input->post('shop',true);
  3890. $number = $this->input->post('number',true);
  3891. if(!$specialstock || $specialstock == '|')
  3892. {
  3893. return array('t'=>1,'m'=>json_encode(array('t'=>1,'msg'=>'请先添加产品信息!','success'=>false)));exit;
  3894. }
  3895. $pp = explode('|',trim($specialstock,'|'));
  3896. $x = 0;$save = array();
  3897. foreach ($pp as $va)
  3898. {
  3899. $num = explode('-',$va);
  3900. if($number)
  3901. {
  3902. $specialstock = $this->specialstock->find_all("state = 0 and number = '$num[0]' and warehouse = '$warehouse' and (zd = '$number' or zd = '') and (shop IS NULL or shop = '')");//通用
  3903. $shopspecialstock = $this->specialstock->find_all("state = 0 and number = '$num[0]' and warehouse = '$warehouse' and (zd = '$number' or zd = '') and shop like '%,".$shop.",%'");//专属
  3904. }
  3905. else
  3906. {
  3907. $specialstock = $this->specialstock->find_all("state = 0 and number = '$num[0]' and warehouse = '$warehouse' and zd = '' and (shop IS NULL or shop = '')");//通用
  3908. $shopspecialstock = $this->specialstock->find_all("state = 0 and number = '$num[0]' and warehouse = '$warehouse' and zd = '' and shop like '%,".$shop.",%'");//专属
  3909. }
  3910. $x++;
  3911. if(count($specialstock)+count($shopspecialstock) < $num[1])
  3912. {
  3913. $save[] = $x-1;continue;//提前先加X不然出错,所以要减1
  3914. }
  3915. }
  3916. if(isset($save[0]))
  3917. {
  3918. echo json_encode(array('t'=>2,'msg'=>"红色商品名库存匹配错误或库存不够扣减",'error'=>$save,'success'=>false));exit;
  3919. }
  3920. else
  3921. {
  3922. echo json_encode(array('success'=>true));exit;
  3923. }
  3924. }
  3925. }
  3926. public function _hwwz()//货物位置
  3927. {
  3928. if(isset($_GET['id']))
  3929. {
  3930. $id = $this->input->get('id',true);
  3931. $sku = $this->input->get('sku',true);
  3932. $bs = $this->input->get('bs',true);
  3933. $number = $this->input->get('number',true);
  3934. $warehouse = $this->input->get('warehouse',true);
  3935. $purchase = $this->input->get('purchase',true);
  3936. $orderinfo = $this->input->get('orderinfo',true);
  3937. $waybill = $this->input->get('waybill',true);
  3938. $category = $this->input->get('category',true);
  3939. $size = $this->input->get('size',true);
  3940. $grade = $this->input->get('grade',true);
  3941. $color = $this->input->get('color',true);
  3942. $lowe = $this->input->get('lowe',true);
  3943. $state = $this->input->get('state',true);
  3944. $label = $this->input->get('label',true);
  3945. $px = $this->input->get('px',true);
  3946. $details = $this->input->get('details',true);
  3947. $timetk = $this->input->get('timetkk',true);
  3948. $timetj = $this->input->get('timetjj',true);
  3949. $timetk = strtotime($timetk);
  3950. $timetj = strtotime($timetj);
  3951. $where = "state='0'";
  3952. //数据排序
  3953. $order_str = $px." desc";
  3954. if(empty($page))
  3955. {
  3956. $start = 0;
  3957. $perpage = 1;
  3958. }
  3959. else
  3960. {
  3961. $start = ($page - 1)*$perpage;
  3962. }
  3963. $category = $this->input->get('category',true);
  3964. $warehouse = $this->input->get('warehouse',true);
  3965. if($category)
  3966. {
  3967. $where .= " and features like '%-$category-%'";
  3968. }
  3969. if($warehouse)
  3970. {
  3971. $where .= " and warehouse = '$warehouse'";
  3972. }
  3973. if($details)
  3974. {
  3975. $where .= " and details = '$details'";
  3976. }
  3977. if($id != '')
  3978. {
  3979. $sid = "";
  3980. $usersp = explode(',',trim($id,','));
  3981. foreach ($usersp as $value)
  3982. {
  3983. $sid .= " id = ".$value." or";
  3984. }
  3985. $info_list = $this->specialstock->find_all($where." and (".rtrim($sid,'or').")",'*','details desc');
  3986. }
  3987. else
  3988. {
  3989. $info_list = $this->specialstock->find_all($where,'*','details desc');
  3990. }
  3991. $rows = array();$list = array();
  3992. foreach ($info_list as $key=>$value)
  3993. {
  3994. $rows[$value['sku'].$value['warehouse'].$value['details']] = $value;//所有数据sku
  3995. }
  3996. foreach ($rows as $value)
  3997. {
  3998. $classid = $this->classid->sku();
  3999. $pm = $classid;
  4000. //$scsku = array(13=>'',22=>'',8=>'',15=>'',18=>'','100'=>'',33=>'',34=>'',7=>'','dc'=>'','c'=>'',14=>'',12=>'',25=>'',26=>'',27=>'',10=>'',6=>'',9=>'',999=>'',9999=>'');
  4001. $features = explode('-',trim($value['features'],'-'));
  4002. foreach ($features as $v)
  4003. {
  4004. $typeclass = $this->typeclass->read($v);
  4005. $pm[$typeclass['classid']] = $typeclass['zh'];
  4006. //$scsku[$typeclass['classid']] = $typeclass['bqsku'];
  4007. }
  4008. $typeclass = $this->typeclass->read($v);
  4009. //$scsku = implode("-",$scsku);
  4010. $zh = implode(" ",$pm);
  4011. $zh = str_replace('自然色 ','',rtrim($zh,' '));
  4012. //$scsku = str_replace('- ','-',trim($scsku,'-'));
  4013. //$scsku = str_replace(array('--------','-------','------','-----','----','---','--'),'-',$scsku);
  4014. $c = $this->specialstock->find_count($where.' and sku = "'.$value['sku'].'" and details = "'.$value['details'].'" and warehouse = "'.$value['warehouse'].'" and state = "0"');
  4015. $number = $value['number'];$ftime = time()-15*24*3600;
  4016. $warehouse = $this->warehouse->read($value['warehouse']);
  4017. $list[] = array($value['id'],$value['details'],$zh,$c);
  4018. }
  4019. $title = "库存表";
  4020. $titlename = "";
  4021. $filename = $title.".xls";
  4022. $tail = "";
  4023. $this->excel->get_fz2($list,$titlename,$filename,$tail);
  4024. }
  4025. }
  4026. public function _order()
  4027. {
  4028. $post = $this->input->post(NULL, TRUE);
  4029. if(isset($arg_array[0]))
  4030. {
  4031. if($arg_array[0] == 'del')
  4032. {
  4033. $s = $this->input->post('s',true);
  4034. $del = $this->_del($s);
  4035. echo $del;exit;
  4036. }
  4037. }
  4038. if(isset($post['page']))
  4039. {
  4040. $page = $this->input->post('page',true);
  4041. $perpage = $this->input->post('perpage',true);
  4042. $category = $this->input->post('category',true);
  4043. $size = $this->input->post('size',true);
  4044. $grade = $this->input->post('grade',true);
  4045. $color = $this->input->post('color',true);
  4046. $lowe = $this->input->post('lowe',true);
  4047. $sku = $this->input->post('sku',true);
  4048. $details = $this->input->post('details',true);
  4049. $warehouse = $this->input->post('warehouse',true);
  4050. $purchase = $this->input->post('purchase',true);
  4051. $lacetype = $this->input->post('lacetype',true);
  4052. $state = $this->input->post('state',true);
  4053. $ktime = $this->input->post('ktime',true);
  4054. $jtime = $this->input->post('jtime',true);
  4055. $ktime = strtotime($ktime);
  4056. $jtime = strtotime($jtime);
  4057. $where = "zd =''";$gj = "";$ck = "";
  4058. if($category)
  4059. {
  4060. $where .= " and features like '%-$category-%'";
  4061. }
  4062. if($size)
  4063. {
  4064. $where .= " and features like '%-$size-%'";
  4065. }
  4066. if($grade)
  4067. {
  4068. $where .= " and features like '%-$grade-%'";
  4069. }
  4070. if($color)
  4071. {
  4072. $where .= " and features like '%-$color-%'";
  4073. }
  4074. if($lowe)
  4075. {
  4076. $where .= " and features like '%-$lowe-%'";
  4077. }
  4078. if($lacetype)
  4079. {
  4080. $where .= " and features like '%-$lacetype-%'";
  4081. }
  4082. if($warehouse)
  4083. {
  4084. $where .= " and warehouse = '$warehouse'";
  4085. }
  4086. if($purchase)
  4087. {
  4088. $where .= " and purchase = '$purchase'";
  4089. }
  4090. if($state)
  4091. {
  4092. $where .= " and state = '$state'";
  4093. }
  4094. if($sku)
  4095. {
  4096. $where .= " and sku like '%$sku%'";
  4097. }
  4098. if($details)
  4099. {
  4100. $where .= " and details like '%$details%'";
  4101. }
  4102. if($ktime && $jtime)
  4103. {
  4104. $gj = " and enter > '$ktime' and enter < '$jtime'";
  4105. $ck = " and outk > '$ktime' and outk < '$jtime'";
  4106. }
  4107. //数据排序
  4108. $order_str = "id desc";
  4109. if(empty($page))
  4110. {
  4111. $start = 0;
  4112. $perpage = 1;
  4113. }
  4114. else
  4115. {
  4116. $start = ($page - 1)*$perpage;
  4117. }
  4118. //取得信息列表
  4119. $info_list = $this->specialstock->find_all($where,'*');
  4120. $rows = array();$list = array();
  4121. foreach ($info_list as $key=>$value)
  4122. {
  4123. $rows[$value['number'].$value['warehouse']] = $value;//所有数据sku
  4124. }
  4125. $rowsdq = array_slice($rows,$start,$perpage);
  4126. $inch = '';$zh = '';
  4127. $classid = $this->classid->sku();
  4128. $pm = $classid;
  4129. foreach ($rowsdq as $value)
  4130. {
  4131. $features = '-';
  4132. $td = explode('-',trim($value['features'],'-'));
  4133. foreach ($td as $va)
  4134. {
  4135. $s = $this->typeclass->read($va);
  4136. if($s['classid'] == '14')
  4137. {
  4138. $c = $va;
  4139. $inch = $s['spare'];
  4140. if(isset($pm[$s['classid']]))
  4141. {
  4142. $pm[$s['classid']] = $s['zh'];
  4143. }
  4144. }
  4145. else
  4146. {
  4147. $features .= $va.'-';
  4148. if(isset($pm[$s['classid']]))
  4149. {
  4150. $pm[$s['classid']] = $s['zh'];
  4151. }
  4152. }
  4153. }
  4154. $features = $c.','.$features;
  4155. $warehouse = $this->warehouse->read($value['warehouse']);
  4156. $cpid = ($value['cpid']>0)?' - 编码:'.$value['cpid']:'';
  4157. $nr = implode(" ",$pm);
  4158. $nr = preg_replace(array('/(\s+)/','/分\s/u'),array(' ','分'),$nr);
  4159. $c = $this->specialstock->find_count($where.' and sku = "'.$value['sku'].'" and warehouse = "'.$value['warehouse'].'" and features = "'.$value['features'].'"');
  4160. $list[] = array('id'=>$value['id'],'sku'=>$value['sku'],'title'=>$value['title'],'c'=>$c,'tj'=>"<span data-f='".$features."' data-t='".$value['title']."' data-i='".$inch."' data-n='".$c."' data-id='".$value['id']."' data-id='".$value['id']."' data-wz='".$nr.' - 位置:'.$value['details'].$cpid.";'>添加</span>");
  4161. }
  4162. $total = count($rows);
  4163. $pagenum = ceil($total/$perpage);
  4164. $over = $total-($start+$perpage);
  4165. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($list));
  4166. echo json_encode($rows);exit;
  4167. }
  4168. $this->_Template('specialstock_order',$this->data);
  4169. }
  4170. public function _0kcdel($id_arr)
  4171. {
  4172. if($id_arr)
  4173. {
  4174. $id_arr = explode(',',$id_arr);
  4175. $j = count($id_arr);
  4176. $i = 0;
  4177. //循环删除记录
  4178. foreach ($id_arr as $value)
  4179. {
  4180. $data = $this->specialstock->read($value);
  4181. $z = $this->specialstock->find_count('sku = "'.$data['sku'].'" and zd = "" and state = 0 and warehouse = "'.$data['warehouse'].'" and features = "'.$data['features'].'"');
  4182. if($z < 1)
  4183. {
  4184. $z = $this->specialstock->find_all('sku = "'.$data['sku'].'" and warehouse = "'.$data['warehouse'].'" and features = "'.$data['features'].'"');
  4185. foreach ($z as $v)
  4186. {
  4187. $this->specialstock->remove($v['id']);
  4188. }
  4189. $i++;
  4190. }
  4191. }
  4192. if($i != $j && $i != 0)
  4193. {
  4194. return json_encode(array('del'=>$id_arr,'msg'=>'有非0库存数据,0库存删除成功!','success'=>true));
  4195. }
  4196. else if($i != $j && $i == 0)
  4197. {
  4198. return json_encode(array('del'=>$id_arr,'msg'=>'库存非0不允许删除!','success'=>false));
  4199. }
  4200. else
  4201. {
  4202. return json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  4203. }
  4204. }
  4205. else
  4206. {
  4207. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  4208. }
  4209. }
  4210. }