Sale.php 164 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\GoodLog;
  4. use app\admin\model\ProcessOrder;
  5. use Exception;
  6. use think\App;
  7. use think\facade\Db;
  8. use app\admin\model\ActionLog;
  9. use think\facade\Validate;
  10. //销售单
  11. class Sale extends Base
  12. {
  13. public $noble=[];
  14. public function __construct(App $app)
  15. {
  16. parent::__construct($app);
  17. $this->noble=\think\facade\Config::get("noble");
  18. }
  19. public function create()
  20. {
  21. $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
  22. $orderCode=makeNo("QR");
  23. $customer_code= isset($this->post['customer_code'])&& $this->post['customer_code'] !=="" ? trim($this->post['customer_code']) :"";
  24. if($customer_code==""){
  25. return error_show(1002,"客户customer_code不能为空");
  26. }
  27. $customer=Db::name("customer_info")->where(["companyNo"=>$customer_code])->find();
  28. if($customer==false){
  29. return error_show(1004,"未找到客户数据");
  30. }
  31. $supplierNo= isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :"";
  32. if($supplierNo==""){
  33. return error_show(1002,"参数supplierNo不能为空");
  34. }
  35. $supplier=Db::name("business")->where(["companyNo"=>$supplierNo])->find();
  36. if($supplier==false){
  37. return error_show(1004,"未找到平台供应商数据");
  38. }
  39. $goodtype =isset($this->post['goodtype']) && $this->post['goodtype'] !=="" ?intval($this->post['goodtype']):"1";
  40. $order_type =isset($this->post['order_type']) && $this->post['order_type'] !=="" ?intval($this->post['order_type'])
  41. :"1";
  42. $sendtype =isset($this->post['sendtype']) && $this->post['sendtype'] !=="" ?intval($this->post['sendtype']):"";
  43. if($sendtype===''){
  44. return error_show(1004,"参数sendtype不能为空");
  45. }
  46. $platform_id =isset($this->post['platform_id']) && $this->post['platform_id'] !=="" ?intval($this->post['platform_id']):"";
  47. if($platform_id==''){
  48. return error_show(1004,"参数platform_id不能为空");
  49. }
  50. $platform_order =isset($this->post['platform_order']) && $this->post['platform_order'] !=="" ?trim($this->post['platform_order']):"";
  51. $good_code =isset($this->post['good_code']) && $this->post['good_code'] !=="" ?trim($this->post['good_code']):"";
  52. if($good_code==''){
  53. return error_show(1004,"参数good_code不能为空");
  54. }
  55. $good_num =isset($this->post['good_num']) && $this->post['good_num'] !=="" ?intval($this->post['good_num']):"";
  56. if($good_num===''){
  57. return error_show(1004,"参数good_num不能为空");
  58. }
  59. $arrtime = isset($this->post['arrtime'])&&$this->post['arrtime']!="" ?$this->post['arrtime']:"";
  60. if($arrtime==""){
  61. return error_show(1004,"参数arrtime不能为空");
  62. }
  63. $paytime =isset($this->post['paytime'])&&$this->post['paytime']!=""? $this->post['paytime']:"";
  64. $workNo =isset($this->post['workNo'])&&$this->post['workNo']!=""? trim($this->post['workNo']):"";
  65. // $poNo =isset($this->post['poNo'])&&$this->post['poNo']!=""? trim($this->post['poNo']):"";
  66. $ct = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  67. ->where(['a.skuCode' => $good_code])->field("b.*,a.skuCode,a.platform_code,a.plat_code")->find();
  68. if ($ct == false) {
  69. return error_show(1002, "未找到商品数据");
  70. }
  71. $goodinfo=$ct;
  72. $is_stock=$ct['is_stock'];
  73. $spuCode = $ct['spuCode'];
  74. $skuCode = $ct['skuCode'];
  75. $is_activity= isset($this->post['is_activity'])&&$this->post['is_activity']!=="" ?$this->post['is_activity']:"";
  76. $actcode= isset($this->post['act_code'])&&$this->post['act_code']!=="" ?trim($this->post['act_code']):"";
  77. if($order_type==1){
  78. if($is_activity===""){
  79. return error_show(1002, "参数is_activity不能为空");
  80. }
  81. if($is_activity==1 &&$actcode=="" ){
  82. return error_show(1002, "参数act_code不能为空");
  83. }
  84. }
  85. if($goodinfo['is_stock']==1){
  86. $stock =Db::name("good_stock")->where(["spuCode"=>$spuCode,"is_del"=>0])->find();
  87. if($stock==false||$stock['usable_stock']<$good_num){
  88. return error_show(1003,"库存数量不足");
  89. }
  90. }
  91. $origin = Db::name("good_nake")->where([["spuCode","=",$spuCode],["min_num","<=",$good_num],["is_del","=",
  92. 0]])->order("min_num desc")->find();
  93. if($origin==false){
  94. return error_show(1003,"未找到相关阶梯成本价格");
  95. }
  96. $origin_price = $origin['nake_total'];
  97. $sale_price = isset($this->post['good_price'])&&$this->post['good_price']!="" ? floatval($this->post['good_price']):0;
  98. if($goodtype==1){
  99. $good = Db::name("good_ladder")->where(["skuCode"=>$skuCode,"is_del"=>0,"status"=>1])->where([["min_num",
  100. "<=",$good_num]])->order("min_num desc")->find();
  101. if($good==false){
  102. return error_show(1003,"未找到相关阶梯价格");
  103. }
  104. $sale_price = $good['sale_price'];
  105. if($is_activity==1){
  106. $act = Db::name("activity_info")->alias("a")->leftJoin("good_activity b","a.activity_code=b.activity_code")
  107. ->where(["a.skuCode"=>$skuCode,"a.activity_code"=>$actcode,"a.is_del"=>0,"a.status"=>1,"b.status"=>6,"b.is_del"=>0])
  108. ->find();
  109. if($act==false){
  110. return error_show(1003,"未找到相关活动价");
  111. }
  112. if($act['moq_num']>$good_num){
  113. return error_show(1003,"商品不满足活动价起订量{$act['moq_num']}");
  114. }
  115. if($act['activity_stock']<$good_num){
  116. return error_show(1003,"商品活动库存剩余{$act['activity_stock']}");
  117. }
  118. $sale_price=$act['activity_price'];
  119. }
  120. }
  121. $cgd=[
  122. "supplierNo"=>$ct['supplierNo'],
  123. "companyNo"=>$supplierNo,
  124. "orderCode"=>$orderCode,
  125. "spuCode"=>$ct['spuCode'],
  126. "skuCode"=>$ct['skuCode'],
  127. "good_name"=>$ct['good_name'],
  128. "sale_price"=>$origin_price,
  129. "total_fee"=>$origin_price*$good_num,
  130. "pakge_fee"=>$ct['packing_fee'],
  131. "cert_fee"=>$ct['cert_fee'],
  132. "open_fee"=>$ct['open_fee'],
  133. "cost_fee"=>$ct['cost_fee'],
  134. "mark_fee"=>$ct['mark_fee'],
  135. "demo_fee"=>$ct['demo_fee'],
  136. "good_num"=>$good_num,
  137. "good_type"=>$goodtype,
  138. "order_type"=>$is_stock==1?1:2,
  139. "createrid"=>$ct['createrid'],
  140. "creater"=>$ct['creater'],
  141. 'send_way'=>2
  142. ];
  143. $addrlist = isset($this->post['addrlist']) && $this->post['addrlist'] !=="" ?$this->post['addrlist']:"";
  144. if($sendtype==1){
  145. if($addrlist=="" || empty($addrlist) ||!is_array($addrlist)){
  146. return error_show(1004,"参数addrlist不能为空");
  147. }
  148. }
  149. $remark =isset($this->post['remark']) && $this->post['remark'] !=="" ?trim($this->post['remark']):"";
  150. $apply_id =GetUserInfo($token);
  151. if(empty($apply_id)||$apply_id['code']!=0){
  152. return error_show(1002,"申请人数据不存在");
  153. }
  154. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  155. $ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  156. Db::startTrans();
  157. try {
  158. $data=[
  159. "orderCode"=>$orderCode,
  160. "good_code"=>$spuCode,
  161. "skuCode"=>$skuCode,
  162. "customer_code"=>$customer_code,
  163. "good_name"=>isset($goodinfo['good_name'])&&$goodinfo['good_name']!==''?$goodinfo['good_name']:'',
  164. "good_num"=>$good_num,
  165. "cat_id"=>$goodinfo['cat_id'],
  166. "apply_id"=>$rm,
  167. "apply_name"=>$ri,
  168. "origin_price"=>$origin_price,
  169. "sale_price"=>$sale_price,
  170. "post_fee"=>0,
  171. "status"=>0,
  172. "send_num"=>0,
  173. "wsend_num"=>$good_num,
  174. "send_status"=>1,
  175. "good_type"=>$goodtype,
  176. "send_type"=>$sendtype,
  177. "supplierNo"=>$supplierNo,
  178. "is_del"=>0,
  179. "zxNo"=>"",
  180. "platform_order"=>$platform_order,
  181. "platform_id"=>$platform_id,
  182. "remark"=>$remark,
  183. "is_stock"=>$is_stock,
  184. "is_activity"=>$is_activity===""?0:$is_activity,
  185. "order_type"=>$order_type,
  186. // "poNo"=>$poNo,
  187. "workNo"=>$workNo,
  188. "addtime"=>date("Y-m-d H:i:s"),
  189. "updatetime"=>date("Y-m-d H:i:s"),
  190. 'total_price'=>round($sale_price*$good_num,2),
  191. ];
  192. $paytime==""?"": $data['paytime'] = $paytime;
  193. $datainfo = Db::name('sale')->insert($data,true);
  194. if($datainfo>0){
  195. if($is_activity==1){
  196. $actup =[
  197. "activity_stock"=> $act['activity_stock'] - $good_num,
  198. "updatetime"=>date("Y-m-d H:i:s")
  199. ];
  200. $actupp= Db::name("activity_info")->where(["skuCode"=>$skuCode,"activity_code"=>$actcode,
  201. "is_del"=>0,"status"=>1])->save($actup);
  202. if($actupp==false){
  203. Db::rollback();
  204. return error_show(1002,"活动库存修改失败");
  205. }
  206. }
  207. if($is_stock==0){
  208. $bol=$this->createCgd($cgd);
  209. if($bol==false){
  210. Db::rollback();
  211. return error_show(1002,"订单创建失败");
  212. }
  213. }else{
  214. $dd=[
  215. "orderCode"=>$orderCode,
  216. "spuCode"=>$spuCode,
  217. "total_num"=>$good_num,
  218. "merge_num"=>0,
  219. "balance_num"=>$good_num,
  220. "status"=>1,
  221. "is_del"=>0,
  222. "addtime"=>date("Y-m-d H:i:s"),
  223. "updatetime"=>date("Y-m-d H:i:s"),
  224. ];
  225. $db=Db::name("sale_bk")->insert($dd);
  226. if($db==false){
  227. Db::rollback();
  228. return error_show(1002,"咨询订单创建失败");
  229. }
  230. }
  231. if($sendtype==1){
  232. foreach ($addrlist as $value){
  233. $temp=[];
  234. $addrs=[];
  235. if($value['addr_code']!==''&&is_array($value['addr_code'])){
  236. $addrs['provice_code'] = $value['addr_code'][0];
  237. $addrs['city_code'] = $value['addr_code'][1];
  238. $addrs['area_code'] = $value['addr_code'][2];
  239. $addr = json_encode($addrs);
  240. }else{
  241. $addr = isset($value['addr_code'])?$value['addr_code']:'';
  242. }
  243. $temp['orderCode']=$orderCode;
  244. $temp['contactor']=$value['contactor'];
  245. $temp['mobile'] = $value['mobile'];
  246. $temp['addr'] = $value['addr'];
  247. $temp['addr_code']=$addr;
  248. $temp['customer_code'] =$customer_code;
  249. $temp['receipt_quantity']=$value['receipt_quantity'];
  250. $temp['post_fee'] =0;
  251. $temp['is_del'] =0;
  252. $temp['addtime'] =date("Y-m-d H:i:s");
  253. $temp['updatetime'] =date("Y-m-d H:i:s");
  254. $temp['arrive_time']=$arrtime;
  255. $vmp = Db::name('order_addr')->insert($temp,true);
  256. if($vmp>0){
  257. if($is_stock==0) {
  258. $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
  259. ->select()->toArray();
  260. if (empty($order)) {
  261. return error_show(1004, "未找到可以发货得采购单数据");
  262. }
  263. $num = $value['receipt_quantity'];
  264. $orsend = [];
  265. foreach ($order as $val) {
  266. $outCode = makeNo("DF");
  267. $tep = [];
  268. $ornum = 0;
  269. if ($val['wsend_num'] >= $num) {
  270. $val['wsend_num'] -= $num;
  271. $val['send_num'] += $num;
  272. $ornum = $num;
  273. $num = 0;
  274. } else {
  275. $num -= $val['wsend_num'];
  276. $val['send_num'] += $val['wsend_num'];
  277. $ornum = $val['wsend_num'];
  278. $val['wsend_num'] = 0;
  279. }
  280. $or = Db::name("order_num")->save($val);
  281. if ($or == false) {
  282. Db::rollback();
  283. return error_show(1002, "发货地址添加创建失败");
  284. }
  285. $tep = [
  286. "cgdNo" => $val['cgdNo'],
  287. "outCode" => $outCode,
  288. "send_num" => $ornum,
  289. "status" => 1,
  290. "addtime" => date("Y-m-d H:i:s"),
  291. "updatetime" => date("Y-m-d H:i:s")
  292. ];
  293. $sen = Db::name("order_send")->save($tep);
  294. if ($sen == false) {
  295. Db::rollback();
  296. return error_show(1002, "发货地址添加创建失败");
  297. }
  298. $cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $val['cgdNo']])->find();
  299. if ($cgdinfo == false) {
  300. Db::rollback();
  301. return error_show(1002, "未匹配到采购数据");
  302. }
  303. $out = [
  304. "orderCode" => $orderCode,
  305. "outCode" => $outCode,
  306. "apply_id" => $rm,
  307. "apply_name" => $ri,
  308. "addrid" => $vmp,
  309. "post_name" => "",
  310. "post_code" => "",
  311. "post_fee" => 0,
  312. "sendtime" => date("Y-m-d H:i:s"),
  313. "send_num" => $ornum,
  314. "check_num" => 0,
  315. "error_num" => 0,
  316. "wsm_code" => $cgdinfo['wsm_code'],
  317. "order_type" =>1,
  318. "status" => 0,
  319. "addtime" => date("Y-m-d H:i:s"),
  320. "updatetime" => date("Y-m-d H:i:s")
  321. ];
  322. $ou = Db::name("order_out")->insert($out);
  323. if ($ou == false) {
  324. Db::rollback();
  325. return error_show(1002, "发货地址添加创建失败");
  326. }else{
  327. //修改状态,添加待办
  328. ActionLog::logAdd($this->post['token'], [
  329. "order_code" => $outCode,//出库单号
  330. "status" => 0,//这里的status是之前的值
  331. "action_remark" => '',//备注
  332. "action_type" => "create"//新建create,编辑edit,更改状态status
  333. ], "CKD", 0, $out);
  334. ProcessOrder::AddProcess($this->post['token'], [
  335. "order_type" => 'CKD',
  336. "order_code" => $outCode,//出库单号
  337. "order_id" => 0,
  338. "order_status" => 0
  339. ]);
  340. }
  341. }
  342. }
  343. }else{
  344. Db::rollback();
  345. return error_show(1002,"发货地址添加创建失败");
  346. }
  347. }
  348. }
  349. Db::commit();
  350. return error_show(0,"咨询订单创建成功",["order_code"=>$orderCode]);
  351. }
  352. Db::rollback();
  353. return error_show(1002,"咨询订单创建失败");
  354. }catch(\Exception $e){
  355. Db::rollback();
  356. return error_show(1005,$e->getMessage());
  357. }
  358. }
  359. //采购单
  360. public function createCgd($data){
  361. $cgdCode = makeNo("CG");
  362. $supplier=Db::name("supplier")->where(["code"=>$data['supplierNo'],"is_del"=>0])->find();
  363. if($supplier==false){
  364. return false;
  365. }
  366. $wsm= Db::name("warehouse_info")->where(["supplierNo"=>$data["supplierNo"],"companyNo"=>$data['companyNo'],"is_del"=>0])->find();
  367. if($wsm==false){
  368. $wsm_code = makeNo("WSM");
  369. $inwsm=[
  370. "wsm_code"=>$wsm_code,
  371. "name"=>$supplier['name'],
  372. "wsm_type"=>2,
  373. "supplierNo"=>$supplier['code'],
  374. "addr"=>"",
  375. "addrs_code"=>"",
  376. "contactor"=>0,
  377. "contactor_name"=>0,
  378. "mobile"=>"",
  379. "position"=>"",
  380. "companyNo"=>$data['companyNo'],
  381. "status"=>1,
  382. "is_del"=>0,
  383. "addtime"=>date("Y-m-d H:i:s"),
  384. "updatetime"=>date("Y-m-d H:i:s")
  385. ];
  386. $in = Db::name("warehouse_info")->insert($inwsm);
  387. if($in==false){
  388. return false;
  389. }
  390. }else{
  391. $wsm_code =$wsm['wsm_code'];
  392. }
  393. $cg =["cgdNo"=>$cgdCode,
  394. "bkcode"=>"",
  395. "wsm_code"=>$wsm_code,
  396. "cgder"=>$supplier['person'],
  397. "cgder_id"=>$supplier['personid'],
  398. "spuCode"=>$data['spuCode'],
  399. "skuCode"=>$data['skuCode'],
  400. "good_name"=>$data['good_name'],
  401. "good_num"=>$data['good_num'],
  402. "good_price"=>$data['sale_price'],
  403. "total_fee"=>round($data['sale_price']*$data['good_num'],2),
  404. "pakge_fee"=>$data['pakge_fee'],
  405. "cert_fee"=>$data['cert_fee'],
  406. "open_fee"=>$data['open_fee'],
  407. "teach_fee"=>$data['cost_fee'],
  408. "mark_fee"=>$data['mark_fee'],
  409. "demo_fee"=>$data['demo_fee'],
  410. #"weight"=>$data['weight'],
  411. "diff_weight"=>"0",
  412. "diff_fee"=>"0",
  413. "gold_price"=>"0",
  414. "supplierNo"=>$data['supplierNo'],
  415. "supplier_name"=>$supplier['name'],
  416. "companyNo"=>$data['companyNo'],
  417. "send_status"=>1,
  418. "send_num"=>0,
  419. "wsend_num"=>$data['good_num'],
  420. "remark"=>"",
  421. "status"=>0,//0初始化
  422. "lasttime"=>date("Y-m-d H:i:s"),
  423. "is_del"=>0,
  424. "order_type"=>$data['order_type'],
  425. "good_type"=>$data['good_type'],
  426. "addtime"=>date("Y-m-d H:i:s"),
  427. "updatetime"=>date("Y-m-d H:i:s")
  428. ];
  429. $up =Db::name("purchease_order")->insert($cg,true);
  430. if($up){
  431. //修改状态,添加待办
  432. ActionLog::logAdd($this->post['token'], [
  433. "order_code" => $cg['cgdNo'],//销售单code
  434. "status" => 0,//这里的status是之前的值
  435. "action_remark" => '',//备注
  436. "action_type" => "create"//新建create,编辑edit,更改状态status
  437. ], "CGD", $cg['status'], $cg);
  438. ProcessOrder::AddProcess($this->post['token'], [
  439. "order_type" => 'CGD',
  440. "order_code" => $cg['cgdNo'],//销售单code
  441. "order_id" => $up,
  442. "order_status" => $cg['status']
  443. ]);
  444. $rela=[
  445. "orderCode"=>$data['orderCode'],
  446. "cgdNo"=>$cgdCode,
  447. "spuCode"=>$data['spuCode'],
  448. "good_num"=>$data['good_num'],
  449. "wsend_num"=>$data['good_num'],
  450. "send_num"=>0,
  451. "wait_num"=>0,
  452. "status"=>1,
  453. "source"=>2
  454. ];
  455. $re =Db::name("order_num")->save($rela);
  456. if($re==false){
  457. return false;
  458. }else{
  459. $stokc =Db::name("good_stock")->where(['spuCode'=>$data['spuCode'],"wsm_code"=>$wsm_code,
  460. "is_del"=>0])->find();
  461. if($stokc==false){
  462. $stokc=[
  463. "spuCode"=>$data['spuCode'],
  464. "wsm_code"=>$wsm_code,
  465. "wait_in_stock"=>0,
  466. "wait_out_stock"=>0,
  467. "usable_stock"=>0,
  468. "intra_stock"=>0,
  469. "total_stock"=>0,
  470. "status"=>1,
  471. "addtime"=>date("Y-m-d H:i:s"),
  472. "updatetime"=>date("Y-m-d H:i:s")
  473. ];
  474. $stoc= Db::name("good_stock")->save($stokc);
  475. if($stoc==false){
  476. return false;
  477. }
  478. }
  479. return true;
  480. }
  481. }else{
  482. return false;
  483. }
  484. }
  485. public function addAddr(){
  486. $orderCode = isset($this->post['orderCode'])&&$this->post['orderCode']!=""? trim($this->post['orderCode']):"";
  487. $etid = Db::name("sale")->where(["orderCode" => $orderCode, "is_del" => 0])->find();
  488. if (empty($etid)) {
  489. return error_show(1002, "未找到数据");
  490. }
  491. $arrtime = isset($this->post['arrtime'])&&$this->post['arrtime']!="" ?$this->post['arrtime']:"";
  492. if($arrtime==""){
  493. return error_show(1004,"参数arrtime不能为空");
  494. }
  495. $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
  496. $apply_id =GetUserInfo($token);
  497. if(empty($apply_id)||$apply_id['code']!=0){
  498. return error_show(1002,"申请人数据不存在");
  499. }
  500. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  501. $ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  502. $addrlist = isset($this->post['addrlist']) && $this->post['addrlist'] !=="" ?$this->post['addrlist']:"";
  503. if($addrlist=="" || empty($addrlist) ||!is_array($addrlist)){
  504. return error_show(1004,"参数addrlist不能为空");
  505. }
  506. Db::startTrans();
  507. try{
  508. foreach ($addrlist as $value){
  509. $temp=[];
  510. $addrs=[];
  511. if($value['addr_code']!==''&&is_array($value['addr_code'])){
  512. $addrs['provice_code'] = $value['addr_code'][0];
  513. $addrs['city_code'] = $value['addr_code'][1];
  514. $addrs['area_code'] = $value['addr_code'][2];
  515. $addr = json_encode($addrs);
  516. }else{
  517. $addr = isset($value['addr_code'])?$value['addr_code']:'';
  518. }
  519. $temp['orderCode']=$orderCode;
  520. $temp['contactor']=$value['contactor'];
  521. $temp['mobile'] = $value['mobile'];
  522. $temp['addr'] = $value['addr'];
  523. $temp['addr_code']=$addr;
  524. $temp['customer_code'] =$etid['customer_code'];
  525. $temp['receipt_quantity']=$value['receipt_quantity'];
  526. $temp['post_fee'] =0;
  527. $temp['is_del'] =0;
  528. $temp['addtime'] =date("Y-m-d H:i:s");
  529. $temp['updatetime'] =date("Y-m-d H:i:s");
  530. $temp['arrive_time']=$arrtime;
  531. $vmp = Db::name('order_addr')->insert($temp,true);
  532. if($vmp>0){
  533. $order =Db::name("order_num")->where(["orderCode"=>$orderCode,"status"=>1])->where([["wsend_num",">=",0]])
  534. ->select()->toArray();
  535. if(empty($order)){
  536. return error_show(1004,"未找到可以发货得采购单数据");
  537. }
  538. $num = $value['receipt_quantity'];
  539. $orsend=[];
  540. foreach ($order as $val){
  541. $outCode=makeNo("DF");
  542. $tep=[];
  543. $ornum=0;
  544. if($val['wsend_num']>=$num){
  545. $val['wsend_num']-=$num;
  546. $val['send_num']+=$num;
  547. $ornum =$num;
  548. $num=0;
  549. }else{
  550. $num-=$val['wsend_num'];
  551. $val['send_num']+=$val['wsend_num'];
  552. $ornum =$val['wsend_num'];
  553. $val['wsend_num']=0;
  554. }
  555. $or =Db::name("order_num")->save($val);
  556. if($or==false){
  557. Db::rollback();
  558. return error_show(1002,"发货地址添加创建失败");
  559. }
  560. $tep=[
  561. "cgdNo"=>$val['cgdNo'],
  562. "outCode"=>$outCode,
  563. "send_num"=>$ornum,
  564. "status"=>1,
  565. "addtime"=>date("Y-m-d H:i:s"),
  566. "updatetime"=>date("Y-m-d H:i:s")
  567. ];
  568. $sen=Db::name("order_send")->save($tep);
  569. if($sen==false){
  570. Db::rollback();
  571. return error_show(1002,"发货地址添加创建失败");
  572. }
  573. $cgdinfo =Db::name("purchease_order")->where(["cgdNo"=>$val['cgdNo']])->find();
  574. if($cgdinfo==false){
  575. Db::rollback();
  576. return error_show(1002,"未匹配到采购数据");
  577. }
  578. $out=[
  579. "orderCode"=>$orderCode,
  580. "outCode"=>$outCode,
  581. "apply_id"=>$rm,
  582. "apply_name"=>$ri,
  583. "addrid"=>$vmp,
  584. "post_name"=>"",
  585. "post_code"=>"",
  586. "post_fee"=>0,
  587. "sendtime"=>date("Y-m-d H:i:s"),
  588. "send_num"=>$ornum,
  589. "check_num"=>0,
  590. "error_num"=>1,
  591. "wsm_code"=>$cgdinfo['wsm_code'],
  592. "order_type"=>$etid['order_type'],
  593. "status"=>0,
  594. "addtime"=>date("Y-m-d H:i:s"),
  595. "updatetime"=>date("Y-m-d H:i:s")
  596. ];
  597. $ou =Db::name("order_out")->insert($out);
  598. if($ou==false){
  599. Db::rollback();
  600. return error_show(1002,"发货地址添加创建失败");
  601. }else{
  602. //修改状态,添加待办
  603. ActionLog::logAdd($this->post['token'], [
  604. "order_code" => $outCode,//出库单号
  605. "status" => 0,//这里的status是之前的值
  606. "action_remark" => '',//备注
  607. "action_type" => "create"//新建create,编辑edit,更改状态status
  608. ], "CKD", 0, $out);
  609. ProcessOrder::AddProcess($this->post['token'], [
  610. "order_type" => 'CKD',
  611. "order_code" => $outCode,//出库单号
  612. "order_id" => 0,
  613. "order_status" => 0
  614. ]);
  615. }
  616. //维护商品所在仓库的库存 --- start
  617. $temp = Db::name('good_stock')
  618. ->field('id,usable_stock,wait_out_stock')
  619. ->where(['spuCode' => $val['spuCode'], 'wsm_code' => $cgdinfo['wsm_code']])
  620. ->find();
  621. if ($temp == false) {
  622. Db::rollback();
  623. return error_show(1004, '库存不足');
  624. }
  625. if (($temp['usable_stock'] - $ornum) < 0) {
  626. Db::rollback();
  627. return error_show(1004, '库存不足');
  628. }
  629. $up =Db::name('good_stock')
  630. ->where('id', $temp['id'])
  631. ->update([
  632. 'usable_stock' => $temp['usable_stock'] - $ornum,
  633. 'wait_out_stock' => $temp['wait_out_stock'] + $ornum,
  634. 'updatetime' => date('Y-m-d H:i:s'),
  635. ]);
  636. if($up==false){
  637. Db::rollback();
  638. return error_show(1004, '库存更新失败');
  639. }
  640. //维护商品所在仓库的库存 --- end
  641. if($num==0){
  642. break;
  643. }
  644. }
  645. }else{
  646. Db::rollback();
  647. return error_show(1002,"发货地址添加创建失败");
  648. }
  649. }
  650. Db::commit();
  651. return app_show(0,"发货地址添加完成");
  652. }catch(\Exception $e){
  653. Db::rollback();
  654. return error_show(1002,$e->getMessage());
  655. }
  656. }
  657. public function consultOrder(){
  658. $bidNo =isset($this->post['bidNo'])&&$this->post['bidNo']!="" ? trim($this->post['bidNo']):"";
  659. if($bidNo==""){
  660. return error_show(1003,"参数bidNo不能为空");
  661. }
  662. $zxinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
  663. if($zxinfo==false){
  664. return error_show(1003,"未找到咨询单商品信息");
  665. }
  666. if($zxinfo['status']!=6){
  667. return error_show(1003,"咨询单状态有误无法转单");
  668. }
  669. $zx =Db::name("consult_info")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->find();
  670. if($zx==false){
  671. return error_show(1003,"未找到咨询单信息");
  672. }
  673. if($zx['status']!=4){
  674. return error_show(1003,"咨询单状态有误无法转单");
  675. }
  676. $zxorder =Db::name("consult_order")->where(["zxNo"=>$zx["zxNo"],"is_del"=>0])->find();
  677. if($zxorder==false){
  678. return error_show(1003,"未找到咨询单信息");
  679. }
  680. $good_num =isset($this->post['good_num'])&&$this->post['good_num']!="" ? intval($this->post['good_num']):"";
  681. if($good_num===""){
  682. return error_show(1003,"参数 good_num 不能为空");
  683. }
  684. $sale_price = isset($this->post['sale_price']) && $this->post['sale_price'] != "" ? floatval($this->post['sale_price']) : "";
  685. if ($sale_price === "") {
  686. return error_show(1003, "参数 sale_price 销售单价 不能为空");
  687. }
  688. if ($sale_price < $zxinfo['sale_price']) {
  689. return error_show(1003, "修改的销售单价不能低于原来的销售单价");
  690. }
  691. $sendtype = isset($this->post['sendtype'])&&$this->post['sendtype']!="" ? intval($this->post['sendtype']):"";
  692. if($sendtype==""){
  693. return error_show(1003,"参数sendtype不能为空");
  694. }
  695. $remark = isset($this->post['remark'])&&$this->post['remark']!="" ? trim($this->post['remark']):"";
  696. $orderCode = makeNo("QR");
  697. $spuCode = $zxinfo['spuCode'];
  698. $skuCode = "";
  699. $is_stock=0;
  700. $cgd=[
  701. "supplierNo"=>$zxinfo['supplierNo'],
  702. "companyNo"=>$zxorder['companyNo'],
  703. "spuCode"=>$spuCode,
  704. "skuCode"=>$skuCode,
  705. "orderCode"=>$orderCode,
  706. "good_name"=>$zxinfo['good_name'],
  707. "sale_price"=>$zxinfo['origin_price'],
  708. "total_fee"=>$zxinfo['total_fee'],
  709. "pakge_fee"=>$zxinfo['pakge_fee'],
  710. "cert_fee"=>$zxinfo['cert_fee'],
  711. "open_fee"=>$zxinfo['open_fee'],
  712. "cost_fee"=>$zxinfo['cost_fee'],
  713. "mark_fee"=>$zxinfo['mark_fee'],
  714. "demo_fee"=>$zxinfo['demo_fee'],
  715. "good_num"=>$good_num,
  716. "createrid"=>$zxinfo['createrid'],
  717. "creater"=>$zxinfo['creater'],
  718. "good_type"=>1,
  719. "is_diff"=>$zxinfo['is_diff'],
  720. "order_type"=>3,
  721. 'send_way'=>$zxinfo['send_way']
  722. ];
  723. $token=isset($this->post['token'])&&$this->post['token']!=""? trim($this->post['token']):"";
  724. if($token==""){
  725. return error_show(102, "参数token不能为空");
  726. }
  727. $apply_id = GetUserInfo($token);
  728. if (empty($apply_id) || $apply_id['code'] != 0) {
  729. return error_show(102, "申请人数据不存在");
  730. }
  731. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  732. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  733. $va = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
  734. if($sendtype==1){
  735. if ($va == "") {
  736. return error_show(1002, "参数order_addr不能为空");
  737. }
  738. }
  739. $arrtime=isset($this->post['arrtime'])&&$this->post['arrtime']!="" ?$this->post['arrtime']:"";
  740. if($arrtime==""){
  741. return error_show(1002, "参数arrtime不能为空");
  742. }
  743. Db::startTrans();
  744. try{
  745. $data=[
  746. "orderCode"=>$orderCode,
  747. "good_code"=>$spuCode,
  748. "skuCode"=>$skuCode,
  749. "customer_code"=>$zxorder['khNo'],
  750. "good_name"=>isset($zxinfo['good_name'])&&$zxinfo['good_name']!==''?$zxinfo['good_name']:'',
  751. "good_num"=>$good_num,
  752. "cat_id"=>$zxinfo['cat_id'],
  753. "apply_id"=>$rm,
  754. "apply_name"=>$ri,
  755. "origin_price"=>$zxinfo['nake_fee'],
  756. "sale_price" => $sale_price,//销售单价支持修改
  757. "post_fee"=>0,
  758. "status"=>0,
  759. "send_num"=>0,
  760. "wsend_num"=>$good_num,
  761. "send_status"=>1,
  762. "good_type"=>1,
  763. "send_type"=>$sendtype,
  764. "supplierNo"=>$zxorder['companyNo'],
  765. "is_del"=>0,
  766. "zxNo"=>$bidNo,
  767. "platform_order"=>"",
  768. "platform_id"=>0,
  769. "remark"=>$remark,
  770. "arrive_time"=>$arrtime,
  771. "is_stock"=>0,
  772. "is_activity"=>0,
  773. "proof_id"=>0,
  774. "order_type"=>3,
  775. "addtime"=>date("Y-m-d H:i:s"),
  776. "updatetime"=>date("Y-m-d H:i:s"),
  777. 'total_price' => round($sale_price * $good_num, 2),
  778. ];
  779. $datainfo = Db::name('sale')->insert($data, true);
  780. if($datainfo>0){
  781. $old_zx_status = $zx['status'];
  782. $zx['status']=5;
  783. $zx['updatetime']=date("Y-m-d H:i:s");
  784. $sa=Db::name("consult_info")->save($zx);
  785. if($sa==false){
  786. Db::rollback();
  787. return error_show(1002,"咨询单修改失败");
  788. }else{
  789. //修改状态,添加待办
  790. ActionLog::logAdd($this->post['token'], [
  791. "order_code" => $zx['infoNo'],//咨询单详情编号
  792. "status" => $old_zx_status,//这里的status是之前的值
  793. "action_remark" => '',//备注
  794. "action_type" => "status"//新建create,编辑edit,更改状态status
  795. ], "ZXD", 5, $zx);
  796. ProcessOrder::AddProcess($this->post['token'], [
  797. "order_type" => 'ZXD',
  798. "order_code" => $zx['infoNo'],//咨询单详情编号
  799. "order_id" => $zx['id'],
  800. "order_status" => 5
  801. ]);
  802. }
  803. $bol=$this->createCgd($cgd);
  804. if($bol==false){
  805. Db::rollback();
  806. return error_show(1002,"咨询订单创建失败");
  807. }
  808. $limt=[
  809. "spuCode"=>$zxinfo['spuCode'],
  810. "good_name"=>$zxinfo['good_name'],
  811. "brand_id"=>$zxinfo['brand_id'],
  812. "good_unit"=>$zxinfo['unit_id'],
  813. "cat_id"=>$zxinfo['cat_id'],
  814. "good_type"=>0,
  815. "moq"=>1,
  816. "customized"=>$zxinfo['work_day'],
  817. "tax"=>$zxinfo['tax'],
  818. "supplierNo"=>$zxinfo["supplierNo"],
  819. "is_auth"=>0,
  820. "craft_desc"=>$zxinfo['good_name'],
  821. "good_remark"=>"",
  822. "platform_id"=>$zxorder['platform_id'],
  823. "good_img"=>$zxinfo['good_img'],
  824. "good_thumb_img"=>"",
  825. "good_info_img"=>"",
  826. "specinfo"=>$zxinfo['specinfo'],
  827. "work_day"=>$zxinfo['work_day'],
  828. "noble_metal"=>$zxinfo['metal_id'],
  829. "is_gold_price"=>$zxinfo['is_gold_price'],
  830. "config"=>$zxinfo['config'],
  831. "other_config"=>$zxinfo['other_config'],
  832. "weight"=>$zxinfo['weight'],
  833. "good_weight"=>$zxinfo['good_weight'],
  834. "is_diff"=>$zxinfo['is_diff'],
  835. "supply_area"=>$zxinfo['supply_area'],
  836. "pay_way"=>$zxinfo['pay_way'],
  837. "send_way"=>$zxinfo['send_way'],
  838. "status"=>1,
  839. "is_del"=>0,
  840. "createrid"=>$zxinfo['createrid'],
  841. "creater"=>$zxinfo['creater'],
  842. "addtime"=>date("Y-m-d H:i:s"),
  843. "updatetime"=>date("Y-m-d H:i:s")
  844. ];
  845. $good = Db::name("good_zixun")->insert($limt);
  846. if(!$good){
  847. Db::rollback();
  848. return error_show(1006,"咨询商品录入失败");
  849. }
  850. if(!empty($va)){
  851. $order =Db::name("order_num")->where(["orderCode"=>$orderCode,"status"=>1])->where([["wsend_num",">=",0]])
  852. ->find();
  853. if($order==false){
  854. Db::rollback();
  855. return error_show(1006,"采购单关联数据未找到");
  856. }
  857. foreach ($va as $value){
  858. $temp=[];
  859. $addrs=[];
  860. if($value['addr_code']!==''&&is_array($value['addr_code'])){
  861. $addrs['provice_code'] = $value['addr_code'][0];
  862. $addrs['city_code'] = $value['addr_code'][1];
  863. $addrs['area_code'] = $value['addr_code'][2];
  864. $addr = json_encode($addrs);
  865. }else{
  866. $addr = isset($value['addr_code'])?$value['addr_code']:'';
  867. }
  868. $temp['orderCode']=$orderCode;
  869. $temp['contactor']=$value['contactor'];
  870. $temp['mobile'] = $value['mobile'];
  871. $temp['addr'] = $value['addr'];
  872. $temp['addr_code']=$addr;
  873. $temp['customer_code'] =$zxorder['khNo'];
  874. $temp['receipt_quantity']=$value['receipt_quantity'];
  875. $temp['post_fee'] =0;
  876. $temp['is_del'] =0;
  877. $temp['addtime'] =date("Y-m-d H:i:s");
  878. $temp['updatetime'] =date("Y-m-d H:i:s");
  879. $temp['arrive_time']=$arrtime;
  880. $vmp = Db::name('order_addr')->insert($temp,true);
  881. if($vmp>0){
  882. $outCode=makeNo("DF");
  883. $out=[
  884. "orderCode"=>$orderCode,
  885. "outCode"=>$outCode,
  886. "apply_id"=>$rm,
  887. "apply_name"=>$ri,
  888. "addrid"=>$vmp,
  889. "post_name"=>"",
  890. "post_code"=>"",
  891. "post_fee"=>0,
  892. "sendtime"=>date("Y-m-d H:i:s"),
  893. "send_num"=>$value['receipt_quantity'],
  894. "check_num"=>0,
  895. "error_num"=>0,
  896. "wsm_code"=>"",
  897. "order_type"=>3,
  898. "status"=>0,
  899. "addtime"=>date("Y-m-d H:i:s"),
  900. "updatetime"=>date("Y-m-d H:i:s")
  901. ];
  902. $ou =Db::name("order_out")->insert($out);
  903. if($ou==false){
  904. Db::rollback();
  905. return error_show(1002,"发货地址添加创建失败");
  906. }else{
  907. //修改状态,添加待办
  908. ActionLog::logAdd($this->post['token'], [
  909. "order_code" => $outCode,//出库单号
  910. "status" => 0,//这里的status是之前的值
  911. "action_remark" => '',//备注
  912. "action_type" => "create"//新建create,编辑edit,更改状态status
  913. ], "CKD", 0, $out);
  914. ProcessOrder::AddProcess($this->post['token'], [
  915. "order_type" => 'CKD',
  916. "order_code" => $outCode,//出库单号
  917. "order_id" => 0,
  918. "order_status" => 0
  919. ]);
  920. }
  921. $order['send_num']+=$value['receipt_quantity'];
  922. $order['wsend_num']-=$value['receipt_quantity'];
  923. if($order['wsend_num']<0){
  924. Db::rollback();
  925. return error_show(1002,"发货数量已超出总数");
  926. }
  927. $ups = Db::name("order_num")->save($order);
  928. if($ups){
  929. $tep=[
  930. "cgdNo"=>$order['cgdNo'],
  931. "outCode"=>$outCode,
  932. "send_num"=>$value['receipt_quantity'],
  933. "status"=>1,
  934. "addtime"=>date("Y-m-d H:i:s"),
  935. "updatetime"=>date("Y-m-d H:i:s")
  936. ];
  937. $sen=Db::name("order_send")->save($tep);
  938. if($sen==false){
  939. Db::rollback();
  940. return error_show(1002,"发货地址添加创建失败");
  941. }
  942. }
  943. }else{
  944. Db::rollback();
  945. return error_show(1002,"发货地址添加创建失败");
  946. }
  947. }
  948. }
  949. Db::commit();
  950. return error_show(0,"咨询订单创建成功",["order_code"=>$orderCode]);
  951. }
  952. Db::rollback();
  953. return error_show(1002,"咨询订单创建失败");
  954. }catch(\Exception $e){
  955. Db::rollback();
  956. return error_show(1003,$e->getMessage());
  957. }
  958. }
  959. /**
  960. * @return \think\response\Json|void
  961. * @throws \think\db\exception\DataNotFoundException
  962. * @throws \think\db\exception\DbException
  963. * @throws \think\db\exception\ModelNotFoundException
  964. */
  965. public function projectCreate(){
  966. $planNo =isset($this->post['planNo'])&&$this->post['planNo']!=""?trim($this->post['planNo']):"";
  967. if($planNo==""){
  968. return error_show(1004,"参数planNo不能为空");
  969. }
  970. $plan =Db::name("project_plan")->where(["planNo"=>$planNo,"is_del"=>0])->find();
  971. if($plan==false){
  972. return error_show(1004,"未找到方案信息");
  973. }
  974. $feedbackid = Db::name("project_plan_rela")->where(["planNo"=>$planNo,"is_del"=>0])->column("feedback_id,sale_price,sale_num");
  975. if($feedbackid==false){
  976. return error_show(1004,"未找到方案反馈信息");
  977. }
  978. $project = Db::name("project")->where(["projectNo"=>$plan['projectNo'],"is_del"=>0])->find();
  979. if($project==false){
  980. return error_show(1004,"未找到方案信息");
  981. }
  982. $arrtime=isset($this->post['arrtime'])&&$this->post['arrtime']!="" ?$this->post['arrtime']:"";
  983. if($arrtime==""){
  984. return error_show(1002, "参数arrtime不能为空");
  985. }
  986. $planinfo =isset($this->post['planinfo'])&&!empty($this->post['planinfo']) ?$this->post['planinfo']:"";
  987. if($planinfo==""){
  988. return error_show(1002, "参数planinfo不能为空");
  989. }
  990. $token=isset($this->post['token'])&&$this->post['token']!=""? trim($this->post['token']):"";
  991. if($token==""){
  992. return error_show(102, "参数token不能为空");
  993. }
  994. $apply_id = GetUserInfo($token);
  995. if (empty($apply_id) || $apply_id['code'] != 0) {
  996. return error_show(102, "申请人数据不存在");
  997. }
  998. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  999. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1000. Db::startTrans();
  1001. try {
  1002. $feedid = array_column($feedbackid,"feedback_id");
  1003. foreach ($planinfo as $value){
  1004. $good=[];
  1005. $feedback = Db::name("project_feedback")->where(["id"=>$value['feedback_id'],"projectNo"=>$plan['projectNo'],
  1006. "is_del"=>0])->find();
  1007. if($feedback==false){
  1008. Db::rollback();
  1009. return error_show(1002, "反馈数据未找到");
  1010. }
  1011. $key =array_search($feedback['id'],$feedid);
  1012. $price = $feedbackid[$key];
  1013. $good['spuCode'] = $feedback['spuCode'];
  1014. $good['skuCode'] = $feedback['skuCode'];
  1015. $good['good_num'] = $price['sale_num'];
  1016. $good['sendtype'] = $value['sendtype'];
  1017. $good['sale_price']=$price['sale_price'];
  1018. $good['origin_price']=$feedback['origin_price'];
  1019. $good['companyNo']=$project['companyNo'];
  1020. $good['customerNo']=$project['khNo'];
  1021. $good['pgNo']=$feedback['pgNo'];
  1022. $good['arrtime']=$arrtime;
  1023. $good['rm']=$rm;
  1024. $good['ri']=$ri;
  1025. if($value['sendtype']==1){
  1026. if(!isset($value['addrlist'])||empty($value['addrlist'])){
  1027. Db::rollback();
  1028. return error_show(1002, "订单地址不能为空");
  1029. }
  1030. $good['addrlist'] = $value['addrlist'];
  1031. }
  1032. if($feedback['data_source']==1){
  1033. $feed=$this->project_good($good);
  1034. }else{
  1035. $feed=$this->project_zx($good);
  1036. }
  1037. if($feed==false){
  1038. Db::rollback();
  1039. return error_show(1002, "咨询订单生成失败");
  1040. }
  1041. $feedback['status']=2;
  1042. $feedback['updatetime']=date("Y-m-d H:i:s");
  1043. $fed =Db::name("project_feedback")->save($feedback);
  1044. if($fed==false){
  1045. Db::rollback();
  1046. return error_show(1002, "项目订单生成失败");
  1047. }
  1048. }
  1049. $old_plan_status = $plan['status'];
  1050. $plan['status']=2;
  1051. $plan['updatetime']=date("Y-m-d H:i:s");
  1052. $in =Db::name("project_plan")->save($plan);
  1053. if($in==false){
  1054. Db::rollback();
  1055. return error_show(1002, "项目订单生成失败");
  1056. }else{
  1057. //修改状态,添加待办,只记录动作
  1058. ActionLog::logAdd($this->post['token'], [
  1059. "order_code" => $planNo,//编码
  1060. "status" => $old_plan_status,//这里的status是之前的值
  1061. "action_remark" => '',//备注
  1062. "action_type" => "edit"//新建create,编辑edit,更改状态status
  1063. ], "PRO", 2, $plan);
  1064. }
  1065. $old_project_status = $project["status"];
  1066. $project["status"]=6;
  1067. $project['updatetime']=date("Y-m-d H:i:s");
  1068. $pr =Db::name("project")->save($project);
  1069. if($pr==false){
  1070. Db::rollback();
  1071. return error_show(1002, "项目订单生成失败");
  1072. }else{
  1073. //修改状态,添加待办
  1074. ActionLog::logAdd($this->post['token'], [
  1075. "order_code" => $project['projectNo'],//项目编码
  1076. "status" => $old_project_status,//这里的status是之前的值
  1077. "action_remark" => '',//备注
  1078. "action_type" => "status"//新建create,编辑edit,更改状态status
  1079. ], "PRO", 6, $project);
  1080. ProcessOrder::AddProcess($this->post['token'], [
  1081. "order_type" => 'PRO',
  1082. "order_code" => $project['projectNo'],
  1083. "order_id" => $project['id'],
  1084. "order_status" => 6
  1085. ]);
  1086. }
  1087. Db::commit();
  1088. return app_show(0, "咨询订单生成成功");
  1089. }catch (\Exception $e){
  1090. Db::rollback();
  1091. return error_show(1002, $e->getMessage());
  1092. }
  1093. }
  1094. /**
  1095. * @param $data
  1096. * @return false
  1097. * @throws \think\db\exception\DataNotFoundException
  1098. * @throws \think\db\exception\DbException
  1099. * @throws \think\db\exception\ModelNotFoundException
  1100. *
  1101. */
  1102. public function project_zx($data){
  1103. $goodinfo = Db::name("consult_bids")->where(["spuCode"=>$data['spuCode'],"is_del"=>0])->find();
  1104. if($goodinfo==false){
  1105. return false;
  1106. }
  1107. $orderCode=makeNo("QR");
  1108. $cgd=[
  1109. "supplierNo"=>$goodinfo['supplierNo'],
  1110. "companyNo"=>$data['companyNo'],
  1111. "spuCode"=>$data['spuCode'],
  1112. "skuCode"=>"",
  1113. "orderCode"=>$orderCode,
  1114. "good_name"=>$goodinfo['good_name'],
  1115. "sale_price"=>$data['origin_price'],
  1116. "total_fee"=>$data['origin_price']*$data['good_num'],
  1117. "pakge_fee"=>$goodinfo['pakge_fee'],
  1118. "cert_fee"=>$goodinfo['cert_fee'],
  1119. "open_fee"=>$goodinfo['open_fee'],
  1120. "cost_fee"=>$goodinfo['cost_fee'],
  1121. "mark_fee"=>$goodinfo['mark_fee'],
  1122. "demo_fee"=>$goodinfo['demo_fee'],
  1123. "good_num"=>$data['good_num'],
  1124. "createrid"=>$goodinfo['createrid'],
  1125. "creater"=>$goodinfo['creater'],
  1126. "good_type"=>1,
  1127. "order_type"=>4,
  1128. "send_way"=>$goodinfo['send_way'],
  1129. ];
  1130. $datas=[
  1131. "orderCode"=>$orderCode,
  1132. "good_code"=>$data['spuCode'],
  1133. "skuCode"=>"",
  1134. "customer_code"=>$data['customerNo'],
  1135. "good_name"=>isset($goodinfo['good_name'])&&$goodinfo['good_name']!==''?$goodinfo['good_name']:'',
  1136. "good_num"=>$data['good_num'],
  1137. "cat_id"=>$goodinfo['cat_id'],
  1138. "apply_id"=>$data['rm'],
  1139. "apply_name"=>$data['ri'],
  1140. "origin_price"=>$goodinfo['nake_fee'],
  1141. "sale_price"=>$data['sale_price'],
  1142. "post_fee"=>0,
  1143. "status"=>0,
  1144. "send_num"=>0,
  1145. "wsend_num"=>$data['good_num'],
  1146. "send_status"=>1,
  1147. "good_type"=>1,
  1148. "send_type"=>$data['sendtype'],
  1149. "supplierNo"=>$data['companyNo'],
  1150. "is_del"=>0,
  1151. "zxNo"=>$data["pgNo"],
  1152. "platform_order"=>"",
  1153. "platform_id"=>0,
  1154. "remark"=>"",
  1155. "is_stock"=>0,
  1156. "is_activity"=>0,
  1157. "proof_id"=>0,
  1158. "order_type"=>4,
  1159. "addtime"=>date("Y-m-d H:i:s"),
  1160. "updatetime"=>date("Y-m-d H:i:s"),
  1161. 'total_price'=>round($data['sale_price']*$data['good_num'],2),
  1162. ];
  1163. $datainfo = Db::name('sale')->insert($datas, true);
  1164. if($datainfo>0){
  1165. $bol = $this->createCgd($cgd);
  1166. if ($bol == false) {
  1167. return false;
  1168. }
  1169. $goodinfo['status']=6;
  1170. $goodinfo['updatetime']=date("Y-m-d H:i:s");
  1171. $sa=Db::name("consult_bids")->save($goodinfo);
  1172. if($sa==false){
  1173. return false;
  1174. }
  1175. $zxorder =Db::name("consult_order")->where(["zxNo"=>$goodinfo["zxNo"],"is_del"=>0])->find();
  1176. if($zxorder==false){
  1177. return false;
  1178. }
  1179. $limt=[
  1180. "spuCode"=>$goodinfo['spuCode'],
  1181. "good_name"=>$goodinfo['good_name'],
  1182. "brand_id"=>$goodinfo['brand_id'],
  1183. "good_unit"=>$goodinfo['unit_id'],
  1184. "cat_id"=>$goodinfo['cat_id'],
  1185. "good_type"=>0,
  1186. "moq"=>1,
  1187. "customized"=>$goodinfo['work_day'],
  1188. "tax"=>$goodinfo['tax'],
  1189. "supplierNo"=>$goodinfo["supplierNo"],
  1190. "is_auth"=>0,
  1191. "craft_desc"=>$goodinfo['good_name'],
  1192. "good_remark"=>"",
  1193. "good_img"=>$goodinfo['good_img'],
  1194. "good_thumb_img"=>"",
  1195. "good_info_img"=>"",
  1196. "platform_id"=>$zxorder['platform_id'],
  1197. "specinfo"=>$goodinfo['specinfo'],
  1198. "work_day"=>$goodinfo['work_day'],
  1199. "noble_metal"=>$goodinfo['metal_id'],
  1200. "is_gold_price"=>$goodinfo['is_gold_price'],
  1201. "good_weight"=>$goodinfo['good_weight'],
  1202. "config"=>$goodinfo['config'],
  1203. "other_config"=>$goodinfo['other_config'],
  1204. "weight"=>$goodinfo['weight'],
  1205. "is_diff"=>$goodinfo['is_diff'],
  1206. "supply_area"=>$goodinfo['supply_area'],
  1207. "pay_way"=>$goodinfo['pay_way'],
  1208. "send_way"=>$goodinfo['send_way'],
  1209. "status"=>1,
  1210. "is_del"=>0,
  1211. "createrid"=>$goodinfo['createrid'],
  1212. "creater"=>$goodinfo['creater'],
  1213. "addtime"=>date("Y-m-d H:i:s"),
  1214. "updatetime"=>date("Y-m-d H:i:s")
  1215. ];
  1216. $good = Db::name("good_zixun")->insert($limt);
  1217. if(!$good){
  1218. return false;
  1219. }
  1220. if ($data['sendtype']==1&&!empty($data['addrlist'])) {
  1221. $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
  1222. ->find();
  1223. if ($order == false) {
  1224. return false;
  1225. }
  1226. foreach ($data['addrlist'] as $value) {
  1227. $temp = [];
  1228. $addrs = [];
  1229. if ($value['addr_code'] !== '' && is_array($value['addr_code'])) {
  1230. $addrs['provice_code'] = $value['addr_code'][0];
  1231. $addrs['city_code'] = $value['addr_code'][1];
  1232. $addrs['area_code'] = $value['addr_code'][2];
  1233. $addr = json_encode($addrs);
  1234. } else {
  1235. $addr = isset($value['addr_code']) ? $value['addr_code'] : '';
  1236. }
  1237. $temp['orderCode'] = $orderCode;
  1238. $temp['contactor'] = $value['contactor'];
  1239. $temp['mobile'] = $value['mobile'];
  1240. $temp['addr'] = $value['addr'];
  1241. $temp['addr_code'] = $addr;
  1242. $temp['customer_code'] = $data['companyNo'];
  1243. $temp['receipt_quantity'] = $value['receipt_quantity'];
  1244. $temp['post_fee'] = 0;
  1245. $temp['is_del'] = 0;
  1246. $temp['addtime'] = date("Y-m-d H:i:s");
  1247. $temp['updatetime'] = date("Y-m-d H:i:s");
  1248. $temp['arrive_time'] = $data['arrtime'];
  1249. $vmp = Db::name('order_addr')->insert($temp, true);
  1250. if ($vmp > 0) {
  1251. // $outCode = makeNo("CK");
  1252. // $out = [
  1253. // "orderCode" => $orderCode,
  1254. // "outCode" => $outCode,
  1255. // "apply_id"=>$data['rm'],
  1256. // "apply_name"=>$data['ri'],
  1257. // "addrid" => $vmp,
  1258. // "post_name" => "",
  1259. // "post_code" => "",
  1260. // "post_fee" => 0,
  1261. // "sendtime" => date("Y-m-d H:i:s"),
  1262. // "send_num" => $value['receipt_quantity'],
  1263. // "check_num" => 0,
  1264. // "error_num" => 0,
  1265. // "wsm_code" => "",
  1266. // "order_type" => 4,
  1267. // "status" => 0,
  1268. // "addtime" => date("Y-m-d H:i:s"),
  1269. // "updatetime" => date("Y-m-d H:i:s")
  1270. // ];
  1271. // $ou = Db::name("order_out")->insert($out);
  1272. // if ($ou == false) {
  1273. // return false;
  1274. // }
  1275. // $order['send_num'] += $value['receipt_quantity'];
  1276. // $order['wsend_num'] -= $value['receipt_quantity'];
  1277. // if ($order['wsend_num'] < 0) {
  1278. // return false;
  1279. // }
  1280. // $ups = Db::name("order_num")->save($order);
  1281. // if ($ups) {
  1282. // $tep = [
  1283. // "cgdNo" => $order['cgdNo'],
  1284. // "outCode" => $outCode,
  1285. // "send_num" => $value['receipt_quantity'],
  1286. // "status" => 1,
  1287. // "addtime" => date("Y-m-d H:i:s"),
  1288. // "updatetime" => date("Y-m-d H:i:s")
  1289. // ];
  1290. // $sen = Db::name("order_send")->save($tep);
  1291. // if ($sen == false) {
  1292. // return false;
  1293. // }
  1294. // }
  1295. } else {
  1296. return false;
  1297. }
  1298. }
  1299. }
  1300. }
  1301. return true;
  1302. }
  1303. /**
  1304. * @param $data
  1305. * @return bool
  1306. * @throws \think\db\exception\DataNotFoundException
  1307. * @throws \think\db\exception\DbException
  1308. * @throws \think\db\exception\ModelNotFoundException
  1309. */
  1310. public function project_good($data){
  1311. $good=Db::name('good')
  1312. ->alias("a")
  1313. ->leftJoin("good_platform b","a.spuCode=b.spuCode")
  1314. ->where(["b.skuCode"=>$data['skuCode'],"a.is_del"=>0,"b.is_del"=>0])
  1315. ->find();
  1316. if($good==false){
  1317. return false;
  1318. }
  1319. $goodlass = Db::name("good_ladder")->where(["skuCode"=>$data['skuCode'],"is_del"=>0,"status"=>1])->where([["min_num",
  1320. "<=",$data['good_num']]])->order("min_num desc")->find();
  1321. if($goodlass==false){
  1322. return false;
  1323. }
  1324. $sale_price = $goodlass['sale_price'];
  1325. $origin = Db::name("good_nake")->where([["spuCode","=",$data['spuCode']],["min_num","<=",$data['good_num']],
  1326. ["is_del","=",0]])->order("min_num desc")->find();
  1327. if($origin==false){
  1328. return false;
  1329. }
  1330. $origin_price = $origin['nake_total'];
  1331. $orderCode=makeNo("QR");
  1332. $datas=[
  1333. "orderCode"=>$orderCode,
  1334. "good_code"=>$data['spuCode'],
  1335. "skuCode"=>$data['skuCode'],
  1336. "customer_code"=>$data['customerNo'],
  1337. "good_name"=>isset($good['good_name'])&&$good['good_name']!==''?$good['good_name']:'',
  1338. "good_num"=>$data['good_num'],
  1339. "cat_id"=>$good['cat_id'],
  1340. "apply_id"=>$data['rm'],
  1341. "apply_name"=>$data['ri'],
  1342. "origin_price"=>$origin_price,
  1343. "sale_price"=>$sale_price,
  1344. "post_fee"=>0,
  1345. "status"=>0,
  1346. "send_num"=>0,
  1347. "wsend_num"=>$data['good_num'],
  1348. "send_status"=>1,
  1349. "good_type"=>1,
  1350. "send_type"=>$data['sendtype'],
  1351. "supplierNo"=>$data['companyNo'],
  1352. "is_del"=>0,
  1353. "zxNo"=>$data["pgNo"],
  1354. "platform_order"=>"",
  1355. "platform_id"=>0,
  1356. "remark"=>"",
  1357. "is_stock"=>$good['is_stock'],
  1358. "is_activity"=>0,
  1359. "proof_id"=>0,
  1360. "order_type"=>2,
  1361. "addtime"=>date("Y-m-d H:i:s"),
  1362. "updatetime"=>date("Y-m-d H:i:s"),
  1363. 'total_price'=>round($sale_price*$data['good_num'],2),
  1364. ];
  1365. $datainfo = Db::name('sale')->insert($datas, true);
  1366. if($datainfo>0) {
  1367. $cgd=[
  1368. "supplierNo"=>$good['supplierNo'],
  1369. "companyNo"=>$data['companyNo'],
  1370. "orderCode"=>$orderCode,
  1371. "spuCode"=>$good['spuCode'],
  1372. "skuCode"=>$good['skuCode'],
  1373. "good_name"=>$good['good_name'],
  1374. "sale_price"=>$origin_price,
  1375. "total_fee"=>$origin_price*$data['good_num'],
  1376. "pakge_fee"=>$origin['package_fee'],
  1377. "cert_fee"=>$origin['cert_fee'],
  1378. "open_fee"=>$good['open_fee'],
  1379. "cost_fee"=>$origin['cost_fee'],
  1380. "mark_fee"=>$origin['mark_fee'],
  1381. "demo_fee"=>$good['demo_fee'],
  1382. "good_num"=>$data['good_num'],
  1383. "good_type"=>1,
  1384. "createrid"=>$good['createrid'],
  1385. "creater"=>$good['creater'],
  1386. "order_type"=>$good['is_stock']==1?1:2,
  1387. 'send_way'=>2
  1388. ];
  1389. if($good['is_stock']==0) {
  1390. $bol = $this->createCgd($cgd);
  1391. if ($bol == false) {
  1392. return false;
  1393. }
  1394. }else{
  1395. $dd=[
  1396. "orderCode"=>$orderCode,
  1397. "spuCode"=>$good['spuCode'],
  1398. "total_num"=>$data['good_num'],
  1399. "merge_num"=>0,
  1400. "balance_num"=>$data['good_num'],
  1401. "status"=>1,
  1402. "is_del"=>0,
  1403. "addtime"=>date("Y-m-d H:i:s"),
  1404. "updatetime"=>date("Y-m-d H:i:s"),
  1405. ];
  1406. $db=Db::name("sale_bk")->insert($dd);
  1407. if($db==false){
  1408. return false;
  1409. }
  1410. }
  1411. if ($data['sendtype']==1&&!empty($data['addrlist'])) {
  1412. // $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
  1413. // ->find();
  1414. // if ($order == false) {
  1415. // return false;
  1416. // }
  1417. foreach ($data['addrlist'] as $value) {
  1418. $temp = [];
  1419. $addrs = [];
  1420. if ($value['addr_code'] !== '' && is_array($value['addr_code'])) {
  1421. $addrs['provice_code'] = $value['addr_code'][0];
  1422. $addrs['city_code'] = $value['addr_code'][1];
  1423. $addrs['area_code'] = $value['addr_code'][2];
  1424. $addr = json_encode($addrs);
  1425. } else {
  1426. $addr = isset($value['addr_code']) ? $value['addr_code'] : '';
  1427. }
  1428. $temp['orderCode'] = $orderCode;
  1429. $temp['contactor'] = $value['contactor'];
  1430. $temp['mobile'] = $value['mobile'];
  1431. $temp['addr'] = $value['addr'];
  1432. $temp['addr_code'] = $addr;
  1433. $temp['customer_code'] =$data['companyNo'];
  1434. $temp['receipt_quantity'] = $value['receipt_quantity'];
  1435. $temp['post_fee'] = 0;
  1436. $temp['is_del'] = 0;
  1437. $temp['addtime'] = date("Y-m-d H:i:s");
  1438. $temp['updatetime'] = date("Y-m-d H:i:s");
  1439. $temp['arrive_time'] = $data['arrtime'];
  1440. $vmp = Db::name('order_addr')->insert($temp, true);
  1441. if ($vmp > 0) {
  1442. // if($good['is_stock']!=1){
  1443. // $outCode = makeNo("CK");
  1444. // $out = [
  1445. // "orderCode" => $orderCode,
  1446. // "outCode" => $outCode,
  1447. // "apply_id"=>$data['rm'],
  1448. // "apply_name"=>$data['ri'],
  1449. // "addrid" => $vmp,
  1450. // "post_name" => "",
  1451. // "post_code" => "",
  1452. // "post_fee" => 0,
  1453. // "sendtime" => date("Y-m-d H:i:s"),
  1454. // "send_num" => $value['receipt_quantity'],
  1455. // "check_num" => 0,
  1456. // "error_num" => 0,
  1457. // "wsm_code" => "",
  1458. // "order_type" => 4,
  1459. // "status" => 0,
  1460. // "addtime" => date("Y-m-d H:i:s"),
  1461. // "updatetime" => date("Y-m-d H:i:s")
  1462. // ];
  1463. // $ou = Db::name("order_out")->insert($out);
  1464. // if ($ou == false) {
  1465. // return false;
  1466. // }
  1467. // $order['send_num'] += $value['receipt_quantity'];
  1468. // $order['wsend_num'] -= $value['receipt_quantity'];
  1469. // if ($order['wsend_num'] < 0) {
  1470. // return false;
  1471. // }
  1472. // $ups = Db::name("order_num")->save($order);
  1473. // if ($ups) {
  1474. // $tep = [
  1475. // "cgdNo" => $order['cgdNo'],
  1476. // "outCode" => $outCode,
  1477. // "send_num" => $value['receipt_quantity'],
  1478. // "status" => 1,
  1479. // "addtime" => date("Y-m-d H:i:s"),
  1480. // "updatetime" => date("Y-m-d H:i:s")
  1481. // ];
  1482. // $sen = Db::name("order_send")->insert($tep);
  1483. // if ($sen == false) {
  1484. // return false;
  1485. // }
  1486. // }
  1487. // }
  1488. } else {
  1489. return false;
  1490. }
  1491. }
  1492. }
  1493. }
  1494. return true;
  1495. }
  1496. public function list()
  1497. {
  1498. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  1499. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  1500. $where[] = ['is_del', "=", 0];
  1501. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  1502. if ($orderCode !== "") {
  1503. $where[] = ['orderCode', "like", "%$orderCode%"];
  1504. }
  1505. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !== "" ? trim($this->post['apply_name'])
  1506. : "";
  1507. if ($apply_name !== "") {
  1508. $where[] = ['apply_name', "like", "%$apply_name%"];
  1509. }
  1510. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name'])
  1511. : "";
  1512. if ($good_name !== "") {
  1513. $where[] = ['good_name', "like", "%$good_name%"];
  1514. }
  1515. $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
  1516. if ($good_code !== "") {
  1517. $where[] = ['good_code', "like", "%$good_code%"];
  1518. }
  1519. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] !== "" ? trim($this->post['customer_code']) : "";
  1520. if ($customer_code !== "") {
  1521. $where[] = ['customer_code', "like", "%$customer_code%"];
  1522. }
  1523. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  1524. if ($supplierNo !== "") {
  1525. $where[] = ['supplierNo', "like", "%$supplierNo%"];
  1526. }
  1527. $ordertype = isset($this->post['order_type']) && $this->post['order_type'] !== "" ? intval($this->post['order_type'])
  1528. : "";
  1529. if ($ordertype !== "") {
  1530. $where[] = ['order_type', "=", $ordertype];
  1531. }
  1532. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  1533. if ($status !== "") {
  1534. $where[] = ['status', "=", $status];
  1535. }
  1536. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  1537. if ($start != "") {
  1538. $where[] = ["addtime", '>=', $start];
  1539. }
  1540. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  1541. if ($end != "") {
  1542. $where[] = ["addtime", '<=', $end];
  1543. }
  1544. $count = Db::name('sale')->where($where)->count();
  1545. $total = ceil($count / $size);
  1546. $page = $page >= $total ? $total : $page;
  1547. $list = Db::name('sale')->where($where)->order("addtime desc")->page($page, $size)->select();
  1548. $data = [];
  1549. foreach ($list as $value) {
  1550. if($value['order_type']==3|| $value['order_type']==4){
  1551. $var = Db::name("good_zixun")->where(["spuCode"=>$value['good_code'],"is_del"=>0])->find();
  1552. $value["speclist"]=isset($var['specinfo'])&&$var['specinfo']!=""? json_decode($var['specinfo'],true):"";
  1553. }else {
  1554. $var = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  1555. ->where(['a.skuCode' => $value['skuCode']])->find();
  1556. $spec = Db::name("good_spec")->where(["spuCode"=>$var['spuCode'],"is_del"=>0])->select()->toArray();
  1557. $speclist=[];
  1558. if(!empty($spec)){
  1559. foreach ($spec as $val){
  1560. $temp=[];
  1561. $temp['id']=$val['id'];
  1562. $temp['spuCode']=$val['spuCode'];
  1563. $temp['spec_id']=$val['spec_id'];
  1564. $temp['spec_value_id']=$val['spec_value_id'];
  1565. $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
  1566. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  1567. $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
  1568. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  1569. $speclist[]=$temp;
  1570. }
  1571. }
  1572. $value["speclist"]=empty($speclist)?[]:$speclist;
  1573. }
  1574. $value['can'] = isset($var['cat_id']) && $var['cat_id'] != 0 ? made($var['cat_id']) : [];
  1575. $value['supplierName'] = '';
  1576. if ($value['supplierNo'] != "") {
  1577. $supplier = Db::name("business")->where(["companyNo" => $value['supplierNo']])->find();
  1578. $value['supplierName'] = isset($supplier['company']) ? $supplier['company'] : "";
  1579. }
  1580. $value['customerName'] = '';
  1581. if ($value['customer_code'] != "") {
  1582. $supplier = Db::name("customer_info")->where(["companyNo" => $value['customer_code']])->find();
  1583. $value['customerName'] = isset($supplier['companyName']) ? $supplier['companyName'] : "";
  1584. }
  1585. $value['useage']="";
  1586. if($value['use_order']!=0){
  1587. $use =Db::name("order_use")->where(["id"=>$value['use_order']])->find();
  1588. $value['useage'] = isset($use['order_use']) ?$use['order_use']:"";
  1589. }else{
  1590. $value['use_order']='';
  1591. }
  1592. $data[] = $value;
  1593. }
  1594. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  1595. }
  1596. public function edit()
  1597. {
  1598. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  1599. $id = isset($this->post['id']) && $this->post['id'] !== "" ? trim($this->post['id']) : "";
  1600. if ($id == "") {
  1601. return error_show(1002, "参数id不能为空");
  1602. }
  1603. $etid = Db::name("sale")->where(["id" => $id, "is_del" => 0])->find();
  1604. if (empty($etid)) {
  1605. return error_show(1002, "未找到数据");
  1606. }
  1607. // $orderCode=isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
  1608. // if($orderCode==""){
  1609. // return error_show(1002,"销售单code不能为空");
  1610. // }
  1611. $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
  1612. if ($good_code == "") {
  1613. return error_show(1002, "商品code不能为空");
  1614. }
  1615. $ct = Db::name('good')->alias('a')->join('good_type b', 'b.good_code=a.good_code', 'left')
  1616. ->where(['b.type_code' => $good_code])->find();
  1617. if ($ct == "") {
  1618. return error_show(1002, "未找到商品数据");
  1619. }
  1620. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] !== "" ? trim($this->post['customer_code']) : "";
  1621. if ($customer_code == "") {
  1622. return error_show(1002, "客户code不能为空");
  1623. }
  1624. $customer = Db::name("customer_info")->where(["companyNo" => $customer_code])->find();
  1625. if ($customer == false) {
  1626. return error_show(1004, "未找到客户数据");
  1627. }
  1628. $supplierNo = $this->post['supplierNo'] && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  1629. if ($supplierNo == "") {
  1630. return error_show(1002, "参数supplierNo不能为空");
  1631. }
  1632. $supplier = Db::name("supplier")->where(["code" => $supplierNo])->find();
  1633. if ($supplier == false) {
  1634. return error_show(1004, "未找到平台供应商数据");
  1635. }
  1636. $apply_id = GetUserInfo($token);
  1637. if (empty($apply_id) || $apply_id['code'] != 0) {
  1638. return error_show(1002, "申请人数据不存在");
  1639. }
  1640. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1641. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1642. // $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim
  1643. //($this->post['good_name']) : "";
  1644. // $good_num = isset($this->post['good_num']) && $this->post['good_num'] !== "" ? intval
  1645. //($this->post['good_num']) : "";
  1646. // $origin_price = isset($this->post['origin_price']) && $this->post['origin_price'] !== "" ? intval
  1647. // ($this->post['origin_price']) : "";
  1648. // $sale_price = isset($this->post['sale_price']) && $this->post['sale_price'] !== "" ? trim($this->post['sale_price']) : "";
  1649. // $total_price = isset($this->post['total_price']) && $this->post['total_price'] !== "" ? trim($this->post['total_price']) : "";
  1650. // $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? trim($this->post['post_fee']) : "";
  1651. // $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1652. $vr = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
  1653. if ($vr == "") {
  1654. return error_show(1002, "参数order_addr不能为空");
  1655. }
  1656. $vi = isset($this->post['good_stock']) && $this->post['good_stock'] !== "" ? $this->post['good_stock'] : "";
  1657. if ($vi == "") {
  1658. return error_show(1002, "参数good_stock不能为空");
  1659. }
  1660. $good_num = intval(array_sum(array_column($vi, "num")));
  1661. Db::startTrans();
  1662. try {
  1663. $datn = [
  1664. "id" => $id,
  1665. "good_code" => $good_code,
  1666. "customer_code" => $customer_code,
  1667. "good_num" => $good_num,
  1668. "supplierNo" => $supplierNo,
  1669. "apply_id" => $rm,
  1670. "apply_name" => $ri,
  1671. "is_del" => 0,
  1672. "updatetime" => date("Y-m-d H:i:s")
  1673. ];
  1674. $datninfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->save($datn);
  1675. if ($datninfo > 0) {
  1676. $stn = ["order_code"=>$etid['orderCode'],"status"=>$etid['status'],"action_remark"=>'',"action_type"=>"edit"];
  1677. ActionLog::logAdd($this->post['token'],$stn,"XSQRD",$etid['status'],$datn);
  1678. $order=["order_type"=>'XSQRD',"order_code"=>$etid['orderCode'],"order_id"=>$id,"order_status"=>$etid['status']];
  1679. ProcessOrder::AddProcess($this->post['token'],$order);
  1680. foreach ($vi as $ion) {
  1681. $iten = [];
  1682. isset($ion['id']) && $ion['id'] !== "" ? $iten['id'] = $ion['id'] : '';
  1683. $iten['orderCode'] = $etid['orderCode'];
  1684. $iten['wsm_code'] = $ion['wsm_code'];
  1685. $iten['stock_id'] = 0;
  1686. $iten['num'] = $ion['num'];
  1687. $iten['status'] = 1;
  1688. $iten['sale_price'] = $ct['original_price'];
  1689. isset($ion['id']) && $ion['id'] !== "" ? '' : $iten['addtime'] = date("Y-m-d H:i:s");
  1690. $iten['updatetime'] = date("Y-m-d H:i:s");
  1691. $vp = Db::name('sale_info')->save($iten);
  1692. if ($vp == false)
  1693. {
  1694. Db::rollback();
  1695. return error_show(1002, "更新失败");
  1696. }
  1697. }
  1698. foreach ($vr as $value) {
  1699. $temp = [];
  1700. isset($value['id']) && $value['id'] !== "" ? $temp['id'] = $value['id'] : '';
  1701. $temp['orderCode'] = $etid['orderCode'];
  1702. $temp['contactor'] = $value['contactor'];
  1703. $temp['mobile'] = $value['mobile'];
  1704. $temp['addr'] = $value['addr'];
  1705. $temp['addr_code'] = $value['addr_code'];
  1706. $temp['customer_code'] = $customer_code;
  1707. $temp['receipt_quantity'] = $value['receipt_quantity'];
  1708. $temp['post_fee'] = 0;
  1709. $temp['is_del'] = $value['is_del'];
  1710. isset($value['id']) && $value['id'] !== "" ? '' : $temp['addtime'] = date("Y-m-d H:i:s");
  1711. $temp['updatetime'] = date("Y-m-d H:i:s");
  1712. $temp['arrive_time'] = date("Y-m-d H:i:s");
  1713. $dat = Db::name('order_addr')->save($temp);
  1714. if ($dat == false) {
  1715. Db::rollback();
  1716. return error_show(1002, "更新失败");
  1717. }
  1718. }
  1719. Db::commit();
  1720. return error_show(0, "更新成功");
  1721. }
  1722. Db::rollback();
  1723. return error_show(1002, "更新失败");
  1724. } catch (Exception $e) {
  1725. Db::rollback();
  1726. return error_show(1005, $e->getMessage());
  1727. }
  1728. }
  1729. public function info()
  1730. {
  1731. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  1732. if ($id == "") {
  1733. return error_show(1002, "参数id不能为空");
  1734. }
  1735. $einfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
  1736. if (empty($einfo)) {
  1737. return error_show(1002, "未找到销售订单数据");
  1738. }
  1739. if($einfo['order_type']==3|| $einfo['order_type']==4){
  1740. $goon = Db::name("good_zixun")->where(["spuCode"=>$einfo['good_code'],"is_del"=>0])->find();
  1741. }else {
  1742. $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  1743. ->where(['a.skuCode' => $einfo['skuCode']])->find();
  1744. }
  1745. if ($goon==false) {
  1746. return error_show(1003, "未找到商品数据");
  1747. }else{
  1748. $goon['exclusive']=isset($goon['is_exclusive'])?makeExcluse($goon['is_exclusive']):"";
  1749. $unit =Db::name("unit")->where(["id"=>$goon['good_unit']])->find();
  1750. $goon['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1751. $spec = Db::name("good_spec")->where(["spuCode"=>$goon['spuCode'],"is_del"=>0])->select()->toArray();
  1752. $speclist=[];
  1753. if(!empty($spec)){
  1754. foreach ($spec as $value){
  1755. $temp=[];
  1756. $temp['id']=$value['id'];
  1757. $temp['spuCode']=$value['spuCode'];
  1758. $temp['spec_id']=$value['spec_id'];
  1759. $temp['spec_value_id']=$value['spec_value_id'];
  1760. $temp['is_del']=$value['is_del'];
  1761. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  1762. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  1763. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  1764. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  1765. $speclist[]=$temp;
  1766. }
  1767. }
  1768. $goon["speclist"]=empty($speclist)?[]:$speclist;
  1769. $proof =Db::name("good_proof")->where(["spuCode"=>$goon['spuCode'],"is_del"=>0])->order("updatetime desc")->field("id,proof_type,proof_url")->find();
  1770. $goon['proof'] = isset($proof)&&$proof!=false? $proof:[];
  1771. $goon['origin_place_cn']="";
  1772. $goon['delivery_place_cn']="";
  1773. if(isset($goon['delivery_place'])&&$goon['delivery_place']!==""){
  1774. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1775. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$goon['delivery_place']);
  1776. $goon['delivery_place_cn']=GetAddr(json_encode($place));
  1777. }
  1778. if(isset($goon['delivery_place'])&&$goon['origin_place']!==""){
  1779. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1780. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$goon['origin_place']);
  1781. $goon['origin_place_cn']=GetAddr(json_encode($place));
  1782. }
  1783. if($goon['brand_id']!=0){
  1784. $brand=Db::name("brand")->where(["id"=>$goon['brand_id']])->find();
  1785. $goon["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1786. }else{
  1787. $goon["brand_name"]="";
  1788. $goon["brand_id"]="";
  1789. }
  1790. $supplier = Db::name("supplier")->where(["code"=>$goon['supplierNo']])->find();
  1791. $goon['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1792. $goon['noble_name']=isset($goon['noble_metal'])&&$goon['noble_metal']!=0?$this->noble[$goon['noble_metal']] :"";
  1793. if(isset($goon['companyNo'])&&$goon['companyNo']!=""){
  1794. $company = Db::name("business")->where(["companyNo"=>$goon['companyNo']])->find();
  1795. }
  1796. $goon['company'] = isset($company['company'])?$company['company']:"";
  1797. }
  1798. $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  1799. $in = Db::name('customer_info')->where(['companyNo' => $einfo['customer_code']])->field('companyName')->find();
  1800. $einfo['supplierName'] = '';
  1801. if ($einfo['supplierNo'] != "") {
  1802. $supplier = Db::name("business")->where(["companyNo" => $einfo['supplierNo']])->find();
  1803. $einfo['supplierName'] = isset($supplier['company']) ? $supplier['company'] : "";
  1804. }
  1805. $fo = Db::name('order_addr')->alias("a")->leftJoin("order_out b","a.id=b.addrid")
  1806. ->where(['a.orderCode' => $einfo['orderCode'], 'a.is_del' => 0])->field("a.*,b.post_name,b.post_code,
  1807. b.post_fee,b.sendtime,b.send_num,b.check_num,b.error_num,b.wsm_code,b.order_type,b.status as send_status,b.outCode")
  1808. ->select();
  1809. $addrs = [];
  1810. if (!empty($fo)) {
  1811. foreach ($fo as $value) {
  1812. $value['addr_info'] = "";
  1813. $value['send_num'] = 0;
  1814. if ($value['addr_code'] != "") {
  1815. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1816. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['addr_code']);
  1817. $addr = GetAddr(json_encode($place));
  1818. $value['addr_info'] = $addr;
  1819. }
  1820. $value['wsm_name']="";
  1821. if(isset($value['wsm_code'])&&$value['wsm_code']!=""){
  1822. $wsmcode = Db::name("warehouse_info")->where(["wsm_code" => $value['wsm_code']])->find();
  1823. $value['wsm_name'] =isset($wsmcode['name'])?$wsmcode['name']:"";
  1824. }
  1825. $addrs[] = $value;
  1826. }
  1827. }
  1828. $einfo['useage']="";
  1829. if($einfo['use_order']!=0){
  1830. $use =Db::name("order_use")->where(["id"=>$einfo['use_order']])->find();
  1831. $einfo['useage'] = isset($use['order_use']) ?$use['order_use']:"";
  1832. }else{
  1833. $einfo['use_order']='';
  1834. }
  1835. $einfo['platform_name']='';
  1836. if($einfo['platform_id']!=0){
  1837. $plat=Db::name("platform")->where(['id'=>$einfo['platform_id']])->find();
  1838. $einfo['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
  1839. }
  1840. $einfo['companyName'] = isset($in['companyName']) ? $in['companyName'] : "";
  1841. $einfo['addrs'] = $addrs;
  1842. $einfo['can'] = $int;
  1843. $einfo['goodinfo'] = $goon;
  1844. if (empty($einfo)) {
  1845. return error_show(1002, "未找到销售订单数据");
  1846. } else {
  1847. return app_show(0, "获取成功", $einfo);
  1848. }
  1849. }
  1850. public function del()
  1851. {
  1852. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  1853. if ($id === "") {
  1854. return error_show(1002, "参数id不能为空");
  1855. }
  1856. $ed = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
  1857. if (empty($ed)) {
  1858. return error_show(1002, "未找到销售订单数据");
  1859. }
  1860. $str = Db::name('sale')->update(['id' => $id, 'is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")]);
  1861. if ($str) {
  1862. $stc = ["order_code"=>$id,"status"=>$ed['status'],"action_remark"=>'',"action_type"=>"delete"];
  1863. ActionLog::logAdd($this->post['token'],$stc,"XSQRD",$ed['status'],['id' => $id, 'is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")]);
  1864. $order=["order_type"=>'XSQRD',"order_code"=>$ed['orderCode'],"order_id"=>$id,"order_status"=>$ed['status']];
  1865. ProcessOrder::workdel($order);
  1866. return error_show(0, "删除成功");
  1867. } else {
  1868. return error_show(1002, "删除失败");
  1869. }
  1870. }
  1871. public function status()
  1872. {
  1873. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  1874. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  1875. if ($id == "") {
  1876. return error_show(1002, "参数id不能为空");
  1877. }
  1878. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1879. if ($status == "") {
  1880. return error_show(1002, "订单状态不能为空");
  1881. }
  1882. $dio = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
  1883. if (empty($dio)) {
  1884. return error_show(1002, "销售单信息未找到");
  1885. }
  1886. if ($status == 1 && $dio['order_type'] == 2) {
  1887. $zxinfo = Db::name("consult")->where(["zxNo" => $dio['zxNo'], "is_del" => 0])->find();
  1888. if ($zxinfo == false) {
  1889. return error_show(1004, "未找到咨询单数据");
  1890. }
  1891. $gold['price'] = 0;
  1892. if ($zxinfo['zx_type'] == 2) {
  1893. if ($zxinfo['metals'] == "") {
  1894. return error_show(1004, "未找到咨询单贵金属类型数据");
  1895. }
  1896. $metals = $zxinfo['metals'] == '18K' ? 1 : ($zxinfo['metals'] == '24K' ? 2 : 3);
  1897. $gold = Db::name("gold_price")->where(["type" => $metals])->order("addtime desc")->find();
  1898. if (empty($gold)) {
  1899. return error_show(1004, "未找到咨询单贵金属类型数据");
  1900. }
  1901. $dio['gold_price'] = $gold['price'];
  1902. }
  1903. $wsm = Db::name("warehouse_info")->where(["supplierNo" => $zxinfo['gysNo'], "wsm_type" => 2])->find();
  1904. if (empty($wsm)) {
  1905. return error_show(1002, "供应商仓库未找到");
  1906. }
  1907. }
  1908. $apply_id = GetUserInfo($token);
  1909. if (empty($apply_id) || $apply_id['code'] != 0) {
  1910. return error_show(1002, "申请人数据不存在");
  1911. }
  1912. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1913. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1914. Db::startTrans();
  1915. try {
  1916. $vmp =$dio['status'];
  1917. $dio['status'] = $status;
  1918. $dio['updatetime'] = date("Y-m-d H:i:s");
  1919. $st = Db::name('sale')->save($dio);
  1920. if ($st) {
  1921. $stn = ["order_code"=>$dio['orderCode'],"status"=>$vmp,"action_remark"=>'',"action_type"=>"status"];
  1922. ActionLog::logAdd($this->post['token'],$stn, $dio['order_type'] == 2?"ZXQRD":"XSQRD",$dio['status'],$dio);
  1923. $order=["order_type"=>$dio['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$dio['orderCode'],"order_id"=>$id,"order_status"=>$dio['status']];
  1924. ProcessOrder::AddProcess($this->post['token'],$order);
  1925. if ($status == 3 && $dio['order_type'] == 1) {
  1926. $dn = Db::name('sale_info')->where(['orderCode' => $st['orderCode']])->select();
  1927. foreach ($dn as $value) {
  1928. $dm = Db::name('good_stock')->where(['wsm_code' => $value['wsm_code'], 'good_type_code' => $st['good_code']])->find();
  1929. if ($dm == "") {
  1930. Db::rollback();
  1931. return error_show(1003, "未找到商品数据");
  1932. }
  1933. if ($value['num'] > $dm['usable_stock']) {
  1934. Db::rollback();
  1935. return error_show(1002, "超出库存数量");
  1936. }
  1937. $dm['usable_stock'] -= $value['num'];
  1938. $dm['wait_out_stock'] += $value['num'];
  1939. $send = Db::name("order_out")->where(["wsm_code" => $value['wsm_code']])->sum("send_num");
  1940. $value['send_num'] = $send ?? 0;
  1941. $value['wsend_num'] = $value['num'] - $value['send_num'];
  1942. $Db = Db::name('good_stock')->update($dm);
  1943. $Db['updatetime'] = date('Y-m-d H:i:s');
  1944. if ($Db == false) {
  1945. Db::rollback();
  1946. return error_show(1002, "状态更新失败");
  1947. }
  1948. }
  1949. }
  1950. if ($status == 1 && $dio['order_type'] == 2) {
  1951. $cgd = makeNo("CG");
  1952. $clll = [
  1953. "cgdNo" => $cgd,
  1954. "bkcode" => $dio['orderCode'],
  1955. "wsm_code" => $wsm['wsm_code'],
  1956. "cgder_id" => Db::name('depart_user')->where('nickname',$zxinfo['saler'])->value('uid')??0,//重名以及多个账号的话…………
  1957. "cgder" => $zxinfo['saler'],
  1958. "good_code" => "GD-" . $zxinfo['cpNo'],
  1959. "good_name" => $zxinfo['cpName'],
  1960. "good_type_code" => $zxinfo['cpNo'],
  1961. "good_num" => $dio['good_num'],
  1962. "good_price" => $zxinfo['total_fee'],
  1963. "total_fee" => round($zxinfo['total_fee'] * $dio['good_num'], 2),
  1964. "pakge_fee" => $zxinfo['package_fee'],
  1965. "cert_fee" => $zxinfo['cert_fee'],
  1966. "open_fee" => $zxinfo['open_fee'],
  1967. "delivery_fee" => $zxinfo['delivery_fee'],
  1968. "mark_fee" => $zxinfo['mark_fee'],
  1969. "teach_fee" => $zxinfo['cost_fee'],
  1970. "demo_fee" => $zxinfo['demo_fee'],
  1971. "nake_fee" => $zxinfo['bare_fee'],
  1972. "weight" => isset($zxinfo['weight']) ? $zxinfo['weight'] : 0,
  1973. "supplierNo" => $zxinfo['gysNo'],
  1974. "supplier_name" => $zxinfo['gysname'],
  1975. "gold_price" => $gold['price'],
  1976. "send_num" => 0,
  1977. "wsend_num" => $dio['good_num'],
  1978. "remark" => '',
  1979. "lasttime" => date("Y-m-d H:i:s"),
  1980. "is_del" => 0,
  1981. "status" => $dio['send_type'] == 1 ? 3 : 0,
  1982. "order_type" => 2,
  1983. "addtime" => date("Y-m-d H:i:s"),
  1984. "updatetime" => date("Y-m-d H:i:s")
  1985. ];
  1986. $cgin = Db::name("purchease_order")->insert($clll);
  1987. // var_dump(Db::name("purchease_order")->getLastSql(),$clll);
  1988. if ($cgin == false) {
  1989. $stb = ["order_code"=>$cgd,"status"=> $clll['status'],"action_remark"=>'',"action_type"=>"create"];
  1990. ActionLog::logAdd($this->post['token'],$stb,"xsd", $clll['status'],$stb);
  1991. Db::rollback();
  1992. return error_show(1002, "咨询采购单创建商品失败");
  1993. }
  1994. if ($dio['send_type'] == 1) {
  1995. $addr = Db::name('order_addr')->where(["orderCode" => $dio['orderCode'], 'is_del' => 0])->select();
  1996. foreach ($addr as $value) {
  1997. $outCode = makeNo("DF");
  1998. $data = [
  1999. "wsm_code" => $wsm['wsm_code'],
  2000. "orderCode" => $dio['orderCode'],
  2001. "outCode" => $outCode,
  2002. "order_type" => $dio['order_type'],
  2003. "apply_id" => $rm,
  2004. "apply_name" => $ri,
  2005. "addrid" => $value['id'],
  2006. "post_name" => '',
  2007. "post_code" => '',
  2008. "post_fee" => '',
  2009. "sendtime" => date("Y-m-d H:i:s"),
  2010. "send_num" => $value['receipt_quantity'],
  2011. "check_num" => 0,
  2012. "error_num" => 0,
  2013. "status" => 0,
  2014. "addtime" => date("Y-m-d H:i:s"),
  2015. "updatetime" => date("Y-m-d H:i:s")
  2016. ];
  2017. $datainfo = Db::name('order_out')->insert($data);
  2018. if (!$datainfo) {
  2019. $sti = ["order_code"=>$dio['orderCode'],"status"=> 0,"action_remark"=>'',"action_type"=>"create"];
  2020. ActionLog::logAdd($this->post['token'],$sti,"xsd",0,$sti);
  2021. Db::rollback();
  2022. return error_show(1003, "创建失败");
  2023. }else{
  2024. //修改状态,添加待办
  2025. ActionLog::logAdd($this->post['token'], [
  2026. "order_code" => $outCode,//出库单号
  2027. "status" => 0,//这里的status是之前的值
  2028. "action_remark" => '',//备注
  2029. "action_type" => "create"//新建create,编辑edit,更改状态status
  2030. ], "CKD", 0, $data);
  2031. ProcessOrder::AddProcess($this->post['token'], [
  2032. "order_type" => 'CKD',
  2033. "order_code" => $outCode,//出库单号
  2034. "order_id" => 0,
  2035. "order_status" => 0
  2036. ]);
  2037. }
  2038. }
  2039. $wsm_in_code = makeNo("CF");
  2040. $orin = [
  2041. "wsm_in_code" => $wsm_in_code,
  2042. "cgdNo" => $cgd,
  2043. "wsm_code" => $wsm['wsm_code'],
  2044. "wsm_reaper" => "",
  2045. "send_num" => $dio['good_num'],
  2046. "post_company" => '',
  2047. "post_code" => '',
  2048. "post_fee" => '',
  2049. "sendtime" => date("Y-m-d H:i:s"),
  2050. "apply_id" => $rm,
  2051. "apply_name" => $ri,
  2052. "wait_num" => 0,
  2053. "status" => 4,
  2054. "addtime" => date("Y-m-d H:i:s"),
  2055. "updatetime" => date("Y-m-d H:i:s")
  2056. ];
  2057. $win = Db::name("purchease_in")->insert($orin);
  2058. if (!$win){
  2059. $stv = ["order_code"=>$wsm_in_code,"status"=>4,"action_remark"=>'',"action_type"=>"create"];
  2060. ActionLog::logAdd($this->post['token'],$stv,"xsd",4,$stv);
  2061. Db::rollback();
  2062. return error_show(1003, "创建失败");
  2063. }
  2064. $good = Db::name("good_stock")->where(["wsm_code" => $wsm['wsm_code'], "good_type_code" => $zxinfo['cpNo'], "is_del" => 0])->find();
  2065. if (empty($good)) {
  2066. $good = [
  2067. "good_type_code" => $zxinfo['cpNo'],
  2068. "wsm_code" => $wsm['wsm_code'],
  2069. "usable_stock" => 0,
  2070. "wait_out_stock" => 0,
  2071. "total_stock" => 0,
  2072. "addtime" => date("Y-m-d H:i:s"),
  2073. "updatetime" => date("Y-m-d H:i:s"),
  2074. ];
  2075. }
  2076. $good['wait_out_stock'] += $dio['good_num'];
  2077. $good['total_stock'] = $good['usable_stock'] + $good['wait_out_stock'];
  2078. $good['updatetime'] = date("Y-m-d H:i:s");
  2079. $upd = Db::name("good_stock")->save($good);
  2080. if (!$upd) {
  2081. $ste = ["order_code"=> $zxinfo['cpNo'],"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  2082. ActionLog::logAdd($this->post['token'],$ste,"xsd",0,$ste);
  2083. Db::rollback();
  2084. return error_show(1003, "创建失败");
  2085. }
  2086. }
  2087. }
  2088. }
  2089. Db::commit();
  2090. return error_show(0, "订单状态更新成功");
  2091. } catch (Exception $e) {
  2092. Db::rollback();
  2093. return error_show(1005, $e->getMessage());
  2094. }
  2095. }
  2096. public function fee()
  2097. {
  2098. $id = isset($this->post['id']) && $this->post['id'] !== "" ? trim($this->post['id']) : "";
  2099. if ($id == "") {
  2100. return error_show(1002, "参数id不能为空");
  2101. }
  2102. $etid = Db::name("sale")->where(["id" => $id, "is_del" => 0])->find();
  2103. if (empty($etid)) {
  2104. return error_show(1002, "未找到数据");
  2105. }
  2106. $vr = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
  2107. if ($vr == "") {
  2108. return error_show(1002, "参数order_addr不能为空");
  2109. }
  2110. Db::startTrans();
  2111. try {
  2112. $data = [
  2113. "id" => $id,
  2114. "status" => 2,
  2115. "is_del" => 0,
  2116. "updatetime" => date("Y-m-d H:i:s")
  2117. ];
  2118. $datainfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->save($data);
  2119. if ($datainfo) {
  2120. $stx = ["order_code"=> $etid['orderCode'],"status"=>$etid['status'],"action_remark"=>'',
  2121. "action_type"=>"edit"];
  2122. ActionLog::logAdd($this->post['token'],$stx,$etid['order_type'] == 2?"ZXQRD":"XSQRD",2,$data);
  2123. $order=["order_type"=>$etid['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$etid['orderCode'],"order_id"=>$id,"order_status"=>$data['status']];
  2124. ProcessOrder::AddProcess($this->post['token'],$order);
  2125. foreach ($vr as $value) {
  2126. $tm = [];
  2127. $tm['id'] = $value['id'];
  2128. $tm['orderCode'] = $etid['orderCode'];
  2129. $tm['post_fee'] = $value['post_fee'];
  2130. $tm['updatetime'] = date("Y-m-d H:i:s");
  2131. $dn = Db::name('order_addr')->save($tm);
  2132. if ($dn == false) {
  2133. Db::rollback();
  2134. return error_show(1002, "更新失败");
  2135. }
  2136. }
  2137. Db::commit();
  2138. return error_show(0, "更新成功");
  2139. }
  2140. Db::rollback();
  2141. return error_show(1003, "更新失败");
  2142. } catch (Exception $e) {
  2143. Db::rollback();
  2144. return error_show(1005, $e->getMessage());
  2145. }
  2146. }
  2147. public function out()
  2148. {
  2149. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  2150. $outCode = makeNo("DF");
  2151. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  2152. if ($orderCode == "") {
  2153. return error_show(1002, "参数orderCoder不能为空");
  2154. }
  2155. $der = Db::name('sale')->where(['orderCode' => $orderCode])->find();
  2156. if ($der == "") {
  2157. return error_show(1002, "未找到出库订单单号");
  2158. }
  2159. // $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !== "" ? trim($this->post['wsm_code']) : "";
  2160. // if ($wsm_code == "") {
  2161. // return error_show(1002, "参数wsm_code不能为空");
  2162. // }
  2163. // $wsm = Db::name('sale_info')->where(['wsm_code' => $wsm_code, 'orderCode' => $der['orderCode']])->find();
  2164. // if ($wsm == "") {
  2165. // return error_show(1002, "未找到仓库编码");
  2166. // }
  2167. $post_name = isset($this->post['post_name']) && $this->post['post_name'] !== "" ? trim($this->post['post_name']) : "";
  2168. if ($post_name == "") {
  2169. return error_show(1002, "物流公司不能为空");
  2170. }
  2171. $post_code = isset($this->post['post_code']) && $this->post['post_code'] !== "" ? trim($this->post['post_code']) : "";
  2172. if ($post_code == "") {
  2173. return error_show(1002, "物流单号不能为空");
  2174. }
  2175. $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? intval($this->post['post_fee']) : "";
  2176. if ($post_fee == "") {
  2177. return error_show(1002, "物流费不能为空");
  2178. }
  2179. $send_num = isset($this->post['send_num']) && $this->post['send_num'] !== "" ? $this->post['send_num'] : "";
  2180. if ($send_num == "") {
  2181. return error_show(1002, "发货数量不能为空");
  2182. }
  2183. if ($send_num > $der['wsend_num']) {
  2184. return error_show(1002, "超出可发货数量");
  2185. }
  2186. $apply_id = GetUserInfo($token);
  2187. if (empty($apply_id) || $apply_id['code'] != 0) {
  2188. return error_show(1002, "申请人数据不存在");
  2189. }
  2190. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  2191. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  2192. $addrid = isset($this->post['addrid']) && $this->post['addrid'] !== "" ? intval($this->post['addrid']) : "";
  2193. $dr = Db::name('order_addr')->where(['id' => $addrid, 'is_del' => 0])->find();
  2194. if (empty($dr)) {
  2195. return error_show(1003, "收货人信息未找到");
  2196. }
  2197. if ($dr['orderCode'] !== $orderCode) {
  2198. return error_show(1002, "订单code不存在");
  2199. }
  2200. $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !== "" ? $this->post['sendtime'] : date("Y-m-d H:i:s");
  2201. // $check_num = isset($this->post['check_num']) && $this->post['check_num'] !=="" ? $this->post['check_num'] :"";
  2202. // $error_num = isset($this->post['error_num']) && $this->post['error_num'] !=="" ? $this->post['error_num'] :"";
  2203. $status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] : "1";
  2204. //$order_type = isset($this->post['order_type']) && $this->post['order_type'] !=="" ? $this->post['order_type'] :"1";
  2205. //$dn=Db::name('sale_info')->where(['wsm_code'=>$outCode])->find();
  2206. Db::startTrans();
  2207. try {
  2208. $data = [
  2209. "wsm_code" => "",
  2210. "orderCode" => $orderCode,
  2211. "outCode" => $outCode,
  2212. "order_type" => $der['order_type'],
  2213. "apply_id" => $rm,
  2214. "apply_name" => $ri,
  2215. "addrid" => $dr['id'],
  2216. "post_name" => $post_name,
  2217. "post_code" => $post_code,
  2218. "post_fee" => $post_fee,
  2219. "sendtime" => $sendtime,
  2220. "send_num" => $send_num,
  2221. "check_num" => 0,
  2222. "error_num" => 0,
  2223. "status" => $status,
  2224. "addtime" => date("Y-m-d H:i:s"),
  2225. "updatetime" => date("Y-m-d H:i:s")
  2226. ];
  2227. $datainfo = Db::name('order_out')->insert($data,true);
  2228. if ($datainfo>0) {
  2229. $stx = ["order_code"=>$outCode,"status"=>$status,"action_remark"=>'',"action_type"=>"create"];
  2230. ActionLog::logAdd($this->post['token'],$stx,$der['order_type']==1?"CKD":'ZXCKD',$status,$data);
  2231. $order=["order_type"=>$der['order_type']==1?"CKD":'ZXCKD',"order_code"=>$outCode,"order_id"=>$datainfo,"order_status"=>$data['status']];
  2232. ProcessOrder::AddProcess($this->post['token'],$order);
  2233. if ($status == 1) {
  2234. $item =$der['status'];
  2235. $der['send_num'] += $send_num;
  2236. $der['wsend_num'] -= $send_num;//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
  2237. $der['send_status'] = $der['send_num'] == 0 ? 1 : $der['wsend_num'] == 0 ? 3 : 2;
  2238. $der['status'] = $der['send_num'] == 0 ? 3 : $der['wsend_num'] == 0 ? 5 : 4;
  2239. $der['updatetime'] = date("Y-m-d H:i:s");
  2240. $si = Db::name('sale')->save($der);
  2241. if ($si == false) {
  2242. Db::rollback();
  2243. return error_show(1003, "更新失败");
  2244. }
  2245. $stx = ["order_code"=>$orderCode,"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
  2246. ActionLog::logAdd($this->post['token'],$stx,$der['order_type'] == 2?"ZXQRD":"XSQRD",$der['status'],$der);
  2247. $order=["order_type"=>$der['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$orderCode,"order_id"=>$der['id'],"order_status"=>$data['status']];
  2248. ProcessOrder::AddProcess($this->post['token'],$order);
  2249. $str = Db::name('good_stock')->where(['wsm_code' => $var['wsm_code'], 'good_type_code' => $der['good_code']])->find();
  2250. if ($str == false) {
  2251. Db::rollback();
  2252. return error_show(1002, "商品数据未找到");
  2253. }
  2254. if ($send_num > $str['wait_out_stock']) {
  2255. Db::rollback();
  2256. return error_show(1002, "超出库存数量");
  2257. }
  2258. $str['wait_out_stock'] -= $send_num;
  2259. $str['intra_stock'] += $send_num;
  2260. $str['updatetime'] = date("Y-m-d H:i:s");
  2261. $stre = Db::name('good_stock')->save($str);
  2262. if ($stre == false) {
  2263. Db::rollback();
  2264. return error_show(1002, "状态更新失败");
  2265. }
  2266. //商品变动日志表,good_log_code字段存储采购单号
  2267. $good_data[] = ['good_log_code' => $outCode, "stock_id" => $str['id'], "type" => 2, 'stock' => $send_num, "stock_name" => "wait_out_stock"];
  2268. $good_data[] = ['good_log_code' => $outCode, "stock_id" => $str['id'], "type" => 1, 'stock' => $send_num, "stock_name" => "intra_stock"];
  2269. GoodLog::LogAdd($this->post['token'],$good_data,$der['order_type'] != 1?"ZXQRD":"XSQRD");
  2270. }
  2271. Db::commit();
  2272. return error_show(0, "创建成功");
  2273. } else {
  2274. Db::rollback();
  2275. return error_show(1003, "创建失败");
  2276. }
  2277. } catch (Exception $e) {
  2278. Db::rollback();
  2279. return error_show(1005, $e->getMessage());
  2280. }
  2281. }
  2282. public function customer()
  2283. {
  2284. $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
  2285. if (empty($outCode)) {
  2286. return error_show(1002, "销售订单编号不能为空");
  2287. }
  2288. $codeinfo = Db::name('order_out')->where(['outCode' => $outCode])->find();
  2289. if ($codeinfo == "") {
  2290. return error_show(1003, "未找到订单数据");
  2291. }
  2292. // $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
  2293. // if($orderCode==""){
  2294. // return error_show(1002,"参数orderCoder不能为空");
  2295. // }
  2296. $dr = Db::name('sale')->where(['orderCode' => $codeinfo['orderCode']])->find();
  2297. if ($dr == "") {
  2298. return error_show(1002, "未找到销售订单");
  2299. }
  2300. $status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] : "";
  2301. if ($status == "") {
  2302. return error_show(10002, "状态不能为空");
  2303. }
  2304. Db::startTrans();
  2305. try {
  2306. $time = $codeinfo['status'];
  2307. $codeinfo['status'] = $status;
  2308. $codeinfo['updatetime'] = date("Y-m-d H:i:s");
  2309. $cust = Db::name('order_out')->save($codeinfo);
  2310. if ($cust) {
  2311. $stx = ["order_code"=>$outCode,"status"=>$time,"action_remark"=>'',"action_type"=>"status"];
  2312. ActionLog::logAdd($this->post['token'],$stx,$codeinfo['order_type'] == 2?"ZXCKD":"CKD",$codeinfo['status'],$codeinfo);
  2313. $order=["order_type"=>$codeinfo['order_type'] == 2?"ZXCKD":"CKD","order_code"=>$outCode,
  2314. "order_id"=>$codeinfo['id'],"order_status"=>$codeinfo['status']];
  2315. ProcessOrder::AddProcess($this->post['token'],$order);
  2316. if ($status == 1) {
  2317. $stokc =Db::name("good_stock")->where(['spuCode'=>$codeinfo['spuCode'],"wsm_code"=>$codeinfo['wsm_code'],
  2318. "is_del"=>0])->find();
  2319. if($stokc==false){
  2320. Db::rollback();
  2321. return error_show(1002, "未找库存到数据");
  2322. }else{
  2323. if ($codeinfo['send_num'] > $stokc['usable_stock']) {
  2324. Db::rollback();
  2325. return error_show(1002, "超出库存数量");
  2326. }
  2327. $stokc['wait_out_stock']+=$codeinfo['send_num'];
  2328. $stokc['usable_stock']-=$codeinfo['send_num'];
  2329. $stokc['updatetime']=date("Y-m-d H:i:s");
  2330. }
  2331. $stoc= Db::name("good_stock")->save($stokc);
  2332. if($stoc==false){
  2333. Db::rollback();
  2334. return error_show(1002, "库存更新失败");
  2335. }
  2336. $item =$dr['status'];
  2337. $dr['send_num'] +=$codeinfo['send_num'];
  2338. $dr['wsend_num'] -= $codeinfo['send_num'];//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
  2339. $dr['send_status'] = $dr['send_num'] == 0 ? 1 : $dr['wsend_num'] == 0 ? 3 : 2;
  2340. $dr['status'] = $dr['send_num'] == 0 ? 3 : $dr['wsend_num'] == 0 ? 5 : 4;
  2341. $dr['updatetime'] = date("Y-m-d H:i:s");
  2342. $si = Db::name('sale')->save($dr);
  2343. if ($si == false) {
  2344. Db::rollback();
  2345. return error_show(1003, "更新失败");
  2346. }
  2347. $stx = ["order_code"=>$dr['orderCode'],"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
  2348. ActionLog::logAdd($this->post['token'],$stx,$dr['order_type'] == 2?"ZXQRD":"XSQRD",$dr['status'],
  2349. $dr);
  2350. $order=["order_type"=>$dr['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$dr['orderCode'],"order_id"=>$dr['id'],"order_status"=>$dr['status']];
  2351. ProcessOrder::AddProcess($this->post['token'],$order);
  2352. //商品变动日志表,good_log_code字段存储销售订单编号
  2353. $good_data[] = ['good_log_code' => $outCode, "stock_id" => $stoc['id'], "type" => 1, 'stock' => $codeinfo['send_num'], "stock_name" => "wait_out_stock"];
  2354. $good_data[] = ['good_log_code' => $outCode, "stock_id" => $stoc['id'], "type" => 2, 'stock' => $codeinfo['send_num'], "stock_name" => "usable_stock"];
  2355. GoodLog::LogAdd($this->post['token'],$good_data,'CKD');
  2356. }
  2357. if ($status == 3) {
  2358. $var = Db::name('good_stock')->where(['wsm_code' => $codeinfo['wsm_code'], 'good_type_code' => $dr['good_code']])->find();
  2359. if ($var == false) {
  2360. Db::rollback();
  2361. return error_show(1002, "未找到商品数据");
  2362. }
  2363. if ($codeinfo['send_num'] > $var['intra_stock']) {
  2364. Db::rollback();
  2365. return error_show(1003, "超出在途库存数量");
  2366. }
  2367. $var['intra_stock'] -= $codeinfo['send_num'];
  2368. $var['updatetime'] = date("Y-m-d H:i:s");
  2369. $stre = Db::name('good_stock')->save($var);
  2370. //商品变动日志表,good_log_code字段存储销售订单编号
  2371. $good_data[] = ['good_log_code' => $outCode, "stock_id" => $var['id'], "type" => 2, 'stock' => $codeinfo['send_num'], "stock_name" => "intra_stock"];
  2372. GoodLog::LogAdd($this->post['token'],$good_data,$codeinfo['order_type'] == 2?"ZXCKD":"CKD");
  2373. if ($stre == false) {
  2374. Db::rollback();
  2375. return error_show(1002, "状态更新失败");
  2376. }
  2377. }
  2378. Db::commit();
  2379. return error_show(0, "出库订单更新成功");
  2380. } else {
  2381. Db::rollback();
  2382. return error_show(1003, "出库订单更新失败");
  2383. }
  2384. } catch (Exception $e) {
  2385. Db::rollback();
  2386. return error_show(1005, $e->getMessage());
  2387. }
  2388. }
  2389. public function difflist()
  2390. {
  2391. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  2392. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  2393. $where = [];
  2394. $cgdNo = isset($this->post['orderCode']) && $this->post['orderCode'] != "" ? trim($this->post['orderCode']) : "";
  2395. if ($cgdNo != "") {
  2396. $where[] = ['a.orderCode', "like", "%$cgdNo%"];
  2397. }
  2398. $diffNo = isset($this->post['diffCode']) && $this->post['diffCode'] != "" ? trim($this->post['diffCode']) : "";
  2399. if ($diffNo != "") {
  2400. $where[] = ['a.diffCode', "like", "%$diffNo%"];
  2401. }
  2402. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  2403. if ($status !== "") {
  2404. $where[] = ['a.status', "=", $status];
  2405. }
  2406. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  2407. if ($start != "") {
  2408. $where[] = ["a.addtime", '>=', $start];
  2409. }
  2410. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  2411. if ($end != "") {
  2412. $where[] = ["a.addtime", '<=', $end];
  2413. }
  2414. // $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !==""? intval($this->post['apply_name']):"";
  2415. // if($apply_name!==""){
  2416. // $where[]=['a.apply_name',"like","%$apply_name%"];
  2417. // }
  2418. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  2419. if ($supplierNo != "") {
  2420. // $supplier = Db::name("business")->where([['code', "like", "%$supplierNo%"]])->column('code');
  2421. //// if(empty($supplier)){
  2422. //// return error_show(1004,"未找到供应商信息");
  2423. //// }
  2424. // $wsmcode = Db::name("sale")->where(["is_del" => 0, "supplierNo" => $supplier])->column("orderCode");
  2425. $where[] = ['c.supplierNo', "like", "%$supplierNo%"];
  2426. }
  2427. $companyNo =isset($this->post['companyNo']) &&$this->post['companyNo'] !=="" ? trim($this->post['companyNo']):"";
  2428. if($companyNo!=""){
  2429. $where[]=['c.customer_code',"like","%$companyNo%"];
  2430. }
  2431. $count = Db::name('sale_diff')->alias('a')
  2432. ->join("sale c", "c.orderCode=a.orderCode", "left")
  2433. ->join("customer_info v", "v.companyNo=c.customer_code", "left")
  2434. ->where($where)->count();
  2435. $total = ceil($count / $size);
  2436. $page = $page >= $total ? intval($total) : $page;
  2437. $list = Db::name('sale_diff')->alias('a')
  2438. ->join("sale c", "c.orderCode=a.orderCode", "left")
  2439. ->join("customer_info v", "v.companyNo=c.customer_code", "left")
  2440. ->where($where)->page($page, $size)->field("a.*,c.customer_code,v.companyName,c.skuCode,c.order_type,c.supplierNo")
  2441. ->order("a.addtime desc")->select();
  2442. $data = [];
  2443. foreach ($list as $value) {
  2444. if($value['order_type']==3|| $value['order_type']==4){
  2445. $goon = Db::name("good_zixun")->where(["spuCode"=>$value['good_code'],"is_del"=>0])->find();
  2446. }else {
  2447. $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  2448. ->where(['a.skuCode' => $value['skuCode']])->find();
  2449. }
  2450. $value['can'] = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  2451. $wsm = Db::name("business")->where(['companyNo' => $value['supplierNo']])->find();
  2452. $value['supplierNo'] = isset($wsm['companyNo']) ? $wsm['companyNo'] : "";
  2453. $value['supplierName'] = isset($wsm['company']) ? $wsm['company'] : "";
  2454. $data[] = $value;
  2455. }
  2456. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  2457. }
  2458. /**
  2459. * @return \think\response\Json|void
  2460. * @throws \think\db\exception\DataNotFoundException
  2461. * @throws \think\db\exception\DbException
  2462. * @throws \think\db\exception\ModelNotFoundException
  2463. */
  2464. public function diffcheck()
  2465. {
  2466. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  2467. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  2468. if ($id === "") {
  2469. return error_show(1004, "参数id不能为空");
  2470. }
  2471. $info = Db::name("sale_diff")->where(["id" => $id])->find();
  2472. if (empty($info)) {
  2473. return error_show(1004, "订单数据未找到");
  2474. }
  2475. $is_act = isset($this->post['is_act']) && $this->post['is_act'] !== "" ? intval($this->post['is_act']) : "";
  2476. if ($is_act === '') {
  2477. return error_show(1004, "参数is_act不能为空");
  2478. }
  2479. $customer_remark = isset($this->post['customer_remark']) && $this->post['customer_remark'] !== "" ? trim($this->post['customer_remark']) : "";
  2480. if ($customer_remark === '') {
  2481. return error_show(1004, "参数customer_remark不能为空");
  2482. }
  2483. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "2";
  2484. $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
  2485. $item = $info['status'];
  2486. $info['is_act'] = $is_act;
  2487. $info['customer_remark'] = $customer_remark;
  2488. $info['status'] = $status;
  2489. $info['remark'] = $remark;
  2490. $info['updatetime'] = date("Y-m-d H:i:s");
  2491. $up = Db::name("sale_diff")->save($info);
  2492. if ($up) {
  2493. $stx = ["order_code"=>$info["orderCode"],"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
  2494. ActionLog::logAdd($this->post['token'],$stx,"QRGCD",$info['status'],$info);
  2495. $order=["order_type"=>"QRGCD","order_code"=>$info["orderCode"],"order_id"=>$info['id'],"order_status"=>$info['status']];
  2496. ProcessOrder::AddProcess($this->post['token'],$order);
  2497. return app_show(0, "更新成功");
  2498. } else {
  2499. return error_show(1003, "更新失败");
  2500. }
  2501. }
  2502. /**
  2503. * @return \think\response\Json|void
  2504. * @throws \think\db\exception\DataNotFoundException
  2505. * @throws \think\db\exception\DbException
  2506. * @throws \think\db\exception\ModelNotFoundException
  2507. */
  2508. public function diffstatus()
  2509. {
  2510. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  2511. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  2512. if ($id === "") {
  2513. return error_show(1004, "参数id不能为空");
  2514. }
  2515. $info = Db::name("sale_diff")->where(["id" => $id])->find();
  2516. if ($info==false) {
  2517. return error_show(1004, "订单数据未找到");
  2518. }
  2519. $cgd = Db::name("purchease_diff")->where(['id'=>$info['cgd_diffid']])->find();
  2520. if($cgd==false){
  2521. return error_show(1004, "采购工差单数据未找到");
  2522. }
  2523. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "3";
  2524. $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
  2525. $ite=$info['status'];
  2526. Db::startTrans();
  2527. try{
  2528. $upda=[
  2529. "status"=>$status,
  2530. "remark"=>$remark,
  2531. "updatetime"=> date("Y-m-d H:i:s"),
  2532. ];
  2533. $up = Db::name("sale_diff")->where($info)->save($upda);
  2534. if ($up) {
  2535. $stx = ["order_code"=>$info["orderCode"],"status"=>$ite,"action_remark"=>'',"action_type"=>"status"];
  2536. ActionLog::logAdd($this->post['token'],$stx,"QRGCD",$info['status'],$info);
  2537. $order=["order_type"=>"QRGCD","order_code"=>$info["orderCode"],"order_id"=>$info['id'],"order_status"=>$status];
  2538. ProcessOrder::AddProcess($this->post['token'],$order);
  2539. $cgdup =Db::name("purchease_diff")->where(["id"=>$info['cgd_diffid']])->save($upda);
  2540. if($cgdup){
  2541. Db::commit();
  2542. return app_show(0, "更新成功");
  2543. }
  2544. }
  2545. Db::rollback();
  2546. return error_show(1003, "更新失败");
  2547. }catch (\Exception $e){
  2548. Db::rollback();
  2549. return error_show(1003,$e->getMessage());
  2550. }
  2551. }
  2552. /**
  2553. * @return \think\response\Json|void
  2554. * @throws \think\db\exception\DataNotFoundException
  2555. * @throws \think\db\exception\DbException
  2556. * @throws \think\db\exception\ModelNotFoundException
  2557. */
  2558. public function diffinfo()
  2559. {
  2560. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  2561. if ($id === "") {
  2562. return error_show(1004, "参数id不能为空");
  2563. }
  2564. $info = Db::name('sale_diff')->where(["id" => $id])->find();
  2565. if (empty($info)) {
  2566. return error_show(1004, "工差订单数据未找到");
  2567. }
  2568. $einfo = Db::name('sale')->where(['orderCode' => $info['orderCode'], 'is_del' => 0])->find();
  2569. if ($einfo==false) {
  2570. return error_show(1002, "未找到销售订单数据");
  2571. }
  2572. if($einfo['order_type']==3|| $einfo['order_type']==4){
  2573. $goon = Db::name("good_zixun")->where(["spuCode"=>$einfo['good_code'],"is_del"=>0])->find();
  2574. }else {
  2575. $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  2576. ->where(['a.skuCode' => $einfo['skuCode']])->find();
  2577. }
  2578. if($goon==false){
  2579. return error_show(1002, "未找到商品数据");
  2580. }
  2581. $info['skuCode'] =isset($goon['skuCode']) ? $goon['skuCode']:"";
  2582. $info['spuCode'] =isset($goon['spuCode']) ? $goon['spuCode']:"";
  2583. $info['order_type'] =isset($einfo['order_type']) ? $einfo['order_type']:"";
  2584. $info['can'] = isset($info['cat_id']) && $info['cat_id'] !== 0 ? made($info['cat_id']) : [];
  2585. return app_show(0, "获取成功", $info);
  2586. }
  2587. public function saleout(){
  2588. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  2589. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
  2590. $where= [];
  2591. $orderCode=isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode'])
  2592. :"";
  2593. if($orderCode !==""){
  2594. $where[]=['a.orderCode',"like","%$orderCode%"];
  2595. }
  2596. $order_type=isset($this->post['order_type']) && $this->post['order_type'] !=="" ? trim($this->post['order_type'])
  2597. :"";
  2598. if($order_type !==""){
  2599. $where[]=['a.order_type',"=",$order_type];
  2600. }
  2601. $outCode=isset($this->post['outCode']) && $this->post['outCode'] !=="" ? trim($this->post['outCode'])
  2602. :"";
  2603. if($outCode !==""){
  2604. $where[]=['a.outCode',"like","%$outCode%"];
  2605. }
  2606. $apply_name=isset($this->post['apply_name']) && $this->post['apply_name'] !=="" ? trim($this->post['apply_name'])
  2607. :"";
  2608. if($apply_name !==""){
  2609. $where[]=['a.apply_name',"like","%$apply_name%"];
  2610. }
  2611. $good_code=isset($this->post['good_code']) && $this->post['good_code'] !=="" ? trim($this->post['good_code'])
  2612. :"";
  2613. if($good_code !==""){
  2614. $where[]=['b.good_code',"like","%$good_code%"];
  2615. }
  2616. $good_name=isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name'])
  2617. :"";
  2618. if($good_name !==""){
  2619. $where[]=['b.good_name',"like","%$good_name%"];
  2620. }
  2621. $status=isset($this->post['status']) && $this->post['status'] !=="" ? trim($this->post['status']):"";
  2622. if($status !==""){
  2623. $where[]=['a.status',"=",$status];
  2624. }
  2625. $start = isset($this->post['start']) && $this->post['start'] !=="" ? $this->post['start'] :"";
  2626. if($start !=""){
  2627. $where[]= ["a.addtime",'>=',$start];
  2628. }
  2629. $end = isset($this->post['end']) && $this->post['end'] !=="" ? $this->post['end'] :"";
  2630. if($end !=""){
  2631. $where[]= ["a.addtime",'<=',$end];
  2632. }
  2633. $companyNo =isset($this->post['companyNo']) &&$this->post['companyNo'] !=="" ? trim($this->post['companyNo']):"";
  2634. if($companyNo!=""){
  2635. $where[]=['b.customer_code',"like","%$companyNo%"];
  2636. }
  2637. $count = Db::name('order_out')->alias('a')
  2638. ->join("sale b", "b.orderCode=a.orderCode", "left")
  2639. ->join("customer_info v", "v.companyNo=b.customer_code", "left")
  2640. //->join("good n","n.good_code=b.good_code","left")
  2641. ->where($where)->count();
  2642. $total = ceil($count / $size);
  2643. $page = $page >= $total ? $total : $page;
  2644. $list = Db::name('order_out')->alias('a')->join("sale b", "b.orderCode=a.orderCode", "left")
  2645. ->join("customer_info v", "v.companyNo=b.customer_code", "left")
  2646. //->join("good n","n.good_code=b.good_code","left")
  2647. ->field("a.*,b.good_name,b.good_code,b.skuCode,b.supplierNo,b.customer_code,v.companyName,b.origin_price,b.sale_price,b.total_price")
  2648. ->where($where)->order("addtime desc")->page($page, $size)->select();
  2649. $data=[];
  2650. foreach ($list as $value) {
  2651. $wsmcode = Db::name("warehouse_info")->alias("k")->leftJoin("supplier c", "k.supplierNo=c.code")
  2652. ->where(["k.wsm_code" => $value['wsm_code']])->field("k.name as wsm_name,c.name,c.code")->find();
  2653. $addr = Db::name("order_addr")->where(["id" => $value['addrid']])->find();
  2654. if($value['order_type']==3|| $value['order_type']==4){
  2655. $goon = Db::name("good_zixun")->where(["spuCode"=>$value['good_code'],"is_del"=>0])->find();
  2656. }else {
  2657. $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  2658. ->where(['a.skuCode' => $value['skuCode']])->find();
  2659. }
  2660. $value['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
  2661. $value['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
  2662. $value['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
  2663. $value['addr'] = isset($addr['addr']) ? $addr['addr'] : "";
  2664. $value['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
  2665. $value['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
  2666. $value['can'] = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  2667. $data[] = $value;
  2668. }
  2669. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  2670. }
  2671. public function outinfo()
  2672. {
  2673. $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
  2674. if ($outCode == "") {
  2675. return error_show(1002, "参数outcode不能为空");
  2676. }
  2677. $codeinfo = Db::name("order_out")->where(['outCode' => $outCode])->find();
  2678. if (empty($codeinfo)) {
  2679. return error_show(1002, "未找到出库数据");
  2680. }
  2681. $item = Db::name("sale")->where(['orderCode' => $codeinfo['orderCode']])->find();
  2682. if($item['order_type']==3|| $item['order_type']==4){
  2683. $goodinfo = Db::name("good_zixun")->where(["spuCode"=>$item['good_code'],"is_del"=>0])->find();
  2684. if($goodinfo==false){
  2685. return error_show(1004,"未找到商品数据");
  2686. }
  2687. }else{
  2688. $goodinfo = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  2689. ->where(['a.skuCode' =>$item['skuCode']])->find();
  2690. if ($goodinfo == false) {
  2691. return error_show(1002, "未找到商品数据");
  2692. }
  2693. }
  2694. $int = isset($goodinfo['cat_id']) && $goodinfo['cat_id'] != 0 ? made($goodinfo['cat_id']) : [];
  2695. $addr = Db::name("order_addr")->where(["id" => $codeinfo['addrid']])->find();
  2696. $codeinfo['good_name'] = isset($item['good_name']) ? $item['good_name'] : "";
  2697. $codeinfo['good_num'] = isset($item['good_num']) ? $item['good_num'] : "";
  2698. $codeinfo['good_code'] = isset($item['good_code']) ? $item['good_code'] : "";
  2699. $codeinfo['origin_price'] = isset($item['origin_price']) ? $item['origin_price'] : "";
  2700. $codeinfo['sale_price'] = isset($item['sale_price']) ? $item['sale_price'] : "";
  2701. $codeinfo['total_price'] = isset($item['total_price']) ? $item['total_price'] : "";
  2702. $codeinfo['skuCode'] = isset($item['skuCode']) ? $item['skuCode'] : "";
  2703. $codeinfo['addr'] = GetAddr($addr['addr_code']);
  2704. $codeinfo['addr'] .= isset($addr['addr']) ? $addr['addr'] : "";
  2705. $codeinfo['addr_code'] = isset($addr['addr_code']) ? $addr['addr_code'] : "";
  2706. $codeinfo['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
  2707. $codeinfo['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
  2708. $codeinfo['can'] = $int;
  2709. $orderReturn = Db::name("order_return")->where(["outCode"=>$outCode,"is_del"=>0])->order("id desc")->find();
  2710. $codeinfo['order_return'] = $orderReturn ;
  2711. return app_show(0, "获取成功", $codeinfo);
  2712. }
  2713. public function outadd(){
  2714. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  2715. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  2716. if ($orderCode == "") {
  2717. return error_show(1002, "参数orderCoder不能为空");
  2718. }
  2719. $der = Db::name('sale')->where(['orderCode' => $orderCode,"is_del"=>0])->find();
  2720. if ($der == "") {
  2721. return error_show(1002, "未找到出库订单单号");
  2722. }
  2723. $send_num = isset($this->post['send_num']) && $this->post['send_num'] !== "" ? $this->post['send_num'] : "";
  2724. if ($send_num == "") {
  2725. return error_show(1002, "发货数量不能为空");
  2726. }
  2727. if ($send_num > $der['wsend_num']) {
  2728. return error_show(1002, "超出可发货数量");
  2729. }
  2730. $contactor = isset($this->post['contactor'])&&$this->post['contactor']!="" ? trim($this->post['contactor']):"";
  2731. if($contactor==""){
  2732. return error_show(1002, "参数contactor不能为空");
  2733. }
  2734. $mobile = isset($this->post['mobile'])&&$this->post['mobile']!="" ? trim($this->post['mobile']):"";
  2735. if($mobile==""){
  2736. return error_show(1002, "参数mobile不能为空");
  2737. }
  2738. $addr = isset($this->post['addr'])&&$this->post['addr']!="" ? trim($this->post['addr']):"";
  2739. if($addr==""){
  2740. return error_show(1002, "参数addr不能为空");
  2741. }
  2742. $addr_code = isset($this->post['addr_code'])&&$this->post['addr_code']!="" ? trim($this->post['addr_code']):"";
  2743. if($addr_code==""){
  2744. return error_show(1002, "参数addr_code不能为空");
  2745. }
  2746. $apply_id = GetUserInfo($token);
  2747. if (empty($apply_id) || $apply_id['code'] != 0) {
  2748. return error_show(1002, "申请人数据不存在");
  2749. }
  2750. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  2751. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  2752. $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !== "" ? $this->post['sendtime'] : date("Y-m-d H:i:s");
  2753. $order =Db::name("order_num")->where(["orderCode"=>$orderCode,"status"=>1])->where([["wsend_num",">=",0]])
  2754. ->select()->toArray();
  2755. if(empty($order)){
  2756. return error_show(1004,"未找到可以发货得采购单数据");
  2757. }
  2758. Db::startTrans();
  2759. try {
  2760. $addrlst =[
  2761. "orderCode"=>$orderCode,
  2762. "addr"=>$addr,
  2763. "addr_code"=>json_encode($addr_code),
  2764. "contactor"=>$contactor,
  2765. "mobile"=>$mobile,
  2766. "customer_code"=>$der['customer_code'],
  2767. "post_fee"=>$der['post_fee'],
  2768. "arrive_time"=>$sendtime,
  2769. "receipt_quantity"=>$send_num,
  2770. "is_del"=>0,
  2771. "addtime"=>date("Y-m-d H:i:s"),
  2772. "updatetime"=>date("Y-m-d H:i:s")
  2773. ];
  2774. $addrid = Db::name("order_addr")->insert($addrlst,true);
  2775. if($addrid>0){
  2776. $der['send_num'] +=$send_num;
  2777. $der['wsend_num'] -= $send_num;
  2778. $der['send_status'] = $der['send_num'] == 0 ? 1 : $der['wsend_num'] == 0 ? 3 : 2;
  2779. $der['status'] = $der['send_num'] == 0 ? 3 : $der['wsend_num'] == 0 ? 5 : 4;
  2780. $der['updatetime'] = date("Y-m-d H:i:s");
  2781. $si = Db::name('sale')->save($der);
  2782. if($si==false){
  2783. Db::rollback();
  2784. return error_show(1002,"出库单新建失败");
  2785. }
  2786. $num = $send_num;
  2787. $data=[];
  2788. foreach ($order as $val){
  2789. $outCode = makeNo("DF");
  2790. $cgd =Db::name("purchease_order")->where(["cgdNo"=>$val['cgdNo']])->find();
  2791. $tep=[];
  2792. $ornum=0;
  2793. if($val['wsend_num']>=$num){
  2794. $val['wsend_num']-=$num;
  2795. $val['send_num']+=$num;
  2796. $ornum =$num;
  2797. $num=0;
  2798. }else{
  2799. $num-=$val['wsend_num'];
  2800. $val['send_num']+=$val['wsend_num'];
  2801. $ornum =$val['wsend_num'];
  2802. $val['wsend_num']=0;
  2803. }
  2804. $or =Db::name("order_num")->save($val);
  2805. if($or==false){
  2806. Db::rollback();
  2807. return error_show(1002,"发货地址添加创建失败");
  2808. }
  2809. $tep=[
  2810. "cgdNo"=>$val['cgdNo'],
  2811. "outCode"=>$outCode,
  2812. "send_num"=>$ornum,
  2813. "status"=>1,
  2814. "addtime"=>date("Y-m-d H:i:s"),
  2815. "updatetime"=>date("Y-m-d H:i:s")
  2816. ];
  2817. $sen=Db::name("order_send")->save($tep);
  2818. if($sen==false){
  2819. Db::rollback();
  2820. return error_show(1002,"发货地址添加创建失败");
  2821. }
  2822. $data[] = [
  2823. "wsm_code" => isset($cgd['wsm_code'])? $cgd['wsm_code']:"",
  2824. "orderCode" => $orderCode,
  2825. "outCode" => $outCode,
  2826. "order_type" => $der['order_type'],
  2827. "apply_id" => $rm,
  2828. "apply_name" => $ri,
  2829. "addrid" => $addrid,
  2830. "post_name" => "",
  2831. "post_code" =>"",
  2832. "post_fee" => "",
  2833. "sendtime" => $sendtime,
  2834. "send_num" => $ornum,
  2835. "check_num" => 0,
  2836. "error_num" => 0,
  2837. "status" => 1,
  2838. "addtime" => date("Y-m-d H:i:s"),
  2839. "updatetime" => date("Y-m-d H:i:s")
  2840. ];
  2841. //维护商品所在仓库的库存 --- start
  2842. $temp = Db::name('good_stock')
  2843. ->field('id,usable_stock,wait_out_stock')
  2844. ->where(['spuCode' => $val['spuCode'], 'wsm_code' => $cgd['wsm_code']])
  2845. ->find();
  2846. if ($temp == false) {
  2847. Db::rollback();
  2848. return error_show(1004, '库存不足');
  2849. }
  2850. if (($temp['usable_stock'] - $ornum) < 0) {
  2851. Db::rollback();
  2852. return error_show(1004, '库存不足');
  2853. }
  2854. $up =Db::name('good_stock')
  2855. ->where('id', $temp['id'])
  2856. ->update([
  2857. 'usable_stock' => $temp['usable_stock'] - $ornum,
  2858. 'wait_out_stock' => $temp['wait_out_stock'] + $ornum,
  2859. 'updatetime' => date('Y-m-d H:i:s'),
  2860. ]);
  2861. if($up==false){
  2862. Db::rollback();
  2863. return error_show(1004, '库存更新失败');
  2864. }
  2865. if($num==0){
  2866. break;
  2867. }
  2868. }
  2869. $datainfo = Db::name('order_out')->insertAll($data);
  2870. if($datainfo>0){
  2871. foreach ($data as $k => $v_data) {
  2872. //修改状态,添加待办
  2873. ActionLog::logAdd($this->post['token'], [
  2874. "order_code" => $v_data['outCode'],//出库单号
  2875. "status" => $v_data['status'],//这里的status是之前的值
  2876. "action_remark" => '',//备注
  2877. "action_type" => "create"//新建create,编辑edit,更改状态status
  2878. ], "CKD", $v_data['status'], $v_data);
  2879. ProcessOrder::AddProcess($this->post['token'], [
  2880. "order_type" => 'CKD',
  2881. "order_code" => $v_data['outCode'],//出库单号
  2882. "order_id" => 0,
  2883. "order_status" => $v_data['status']
  2884. ]);
  2885. }
  2886. Db::commit();
  2887. return app_show(0,"出库单新建成功");
  2888. }
  2889. }
  2890. Db::rollback();
  2891. return error_show(1004,"出库单新建失败");
  2892. } catch (Exception $e) {
  2893. Db::rollback();
  2894. return error_show(1005, $e->getMessage());
  2895. }
  2896. }
  2897. public function outdel(){
  2898. }
  2899. public function outSend(){
  2900. $outCode=isset($this->post['outCode'])&& $this->post['outCode']!=""? trim($this->post['outCode']):"";
  2901. if($outCode==""){
  2902. return error_show(1004,"参数outCode不能为空");
  2903. }
  2904. $outinfo = Db::name("order_out")->where(["outCode"=>$outCode])->find();
  2905. if($outinfo==false){
  2906. return error_show(1004,"发货数据未找到");
  2907. }
  2908. $einfo = Db::name('sale')->where(['orderCode' => $outinfo['orderCode'], 'is_del' => 0])->find();
  2909. if (empty($einfo)) {
  2910. return error_show(1002, "未找到销售订单数据");
  2911. }
  2912. $post_name = isset($this->post['post_name']) &&$this->post['post_name']!="" ? trim($this->post['post_name']):"";
  2913. if($post_name==""){
  2914. return error_show(1004,"参数post_name不能为空");
  2915. }
  2916. $post_code = isset($this->post['post_code']) &&$this->post['post_code']!="" ? trim($this->post['post_code']):"";
  2917. if($post_code==""){
  2918. return error_show(1004,"参数post_code不能为空");
  2919. }
  2920. $post_fee = isset($this->post['post_fee']) && $this->post['post_fee']!="" ? floatval($this->post['post_fee']):"";
  2921. $outinfo['post_name'] = $post_name;
  2922. $outinfo['post_code'] = $post_code;
  2923. $outinfo['post_fee'] = $post_fee;
  2924. $outinfo['sendtime'] = date("Y-m-d H:i:s");
  2925. $old_outinfo_status = $outinfo['status'];
  2926. $outinfo['status'] = 2;
  2927. $outinfo['updatetime'] = date("Y-m-d H:i:s");
  2928. Db::startTrans();
  2929. try{
  2930. $up =Db::name("order_out")->save($outinfo);
  2931. if($up){
  2932. //修改状态,添加待办
  2933. ActionLog::logAdd($this->post['token'], [
  2934. "order_code" => $outinfo['outCode'],//出库单号
  2935. "status" => $old_outinfo_status,//这里的status是之前的值
  2936. "action_remark" => '',//备注
  2937. "action_type" => "edit"//新建create,编辑edit,更改状态status
  2938. ], "CKD", $outinfo['status'], $outinfo);
  2939. ProcessOrder::AddProcess($this->post['token'], [
  2940. "order_type" => 'CKD',
  2941. "order_code" => $outinfo['outCode'],//出库单号
  2942. "order_id" => $outinfo['id'],
  2943. "order_status" => $outinfo['status']
  2944. ]);
  2945. $stokc =Db::name("good_stock")->where(['spuCode'=>$einfo['good_code'],"wsm_code"=>$outinfo['wsm_code'],"is_del"=>0])->find();
  2946. if($stokc==false){
  2947. Db::rollback();
  2948. return error_show(1002, "未找库存到数据");
  2949. }else{
  2950. if ($outinfo['send_num'] > $stokc['wait_out_stock']) {
  2951. Db::rollback();
  2952. return error_show(1002, "超出库存数量");
  2953. }
  2954. $stokc['wait_out_stock']-=$outinfo['send_num'];
  2955. $stokc['intra_stock']+=$outinfo['send_num'];
  2956. $stokc['updatetime']=date("Y-m-d H:i:s");
  2957. }
  2958. $stoc= Db::name("good_stock")->save($stokc);
  2959. if($stoc==false){
  2960. Db::rollback();
  2961. return error_show(1002, "库存更新失败");
  2962. }
  2963. Db::commit();
  2964. return app_show(0,"发货成功");
  2965. }else{
  2966. Db::rollback();
  2967. return error_show(1004,"发货失败");
  2968. }
  2969. }catch (\Exception $e){
  2970. Db::rollback();
  2971. return error_show(1004,$e->getMessage());
  2972. }
  2973. }
  2974. public function RelaCgd($outinfo){
  2975. $der = Db::name('sale')->where(['orderCode' => $outinfo['orderCode']])->find();
  2976. if ($der == "") {
  2977. return false;
  2978. }
  2979. if($der['is_stock']==1){
  2980. $cgd = Db::name("order_bk")->where([["spuCode","=",$der['spuCode']],["is_del","=",0],["balance_num",">",0]])
  2981. ->select()->toArray();
  2982. if(empty($cgd)){
  2983. return false;
  2984. }
  2985. $send =$outinfo['send_num'];
  2986. $outsend=[];
  2987. foreach ($cgd as $value){
  2988. $temp=[];
  2989. if($value['balance_num']>=$send){
  2990. $value['balance_num']-=$send;
  2991. $value['merge_num']+=$send;
  2992. $send=0;
  2993. $temp['send_num'] =$send;
  2994. }else{
  2995. $value['balance_num'] =0;
  2996. $value['merge_num']+=$value['balance_num'];
  2997. $send -= $value['balance_num'];
  2998. $temp['send_num'] =$value['balance_num'];
  2999. }
  3000. $value['status'] = $value['balance_num']==0 ?2:$value['merge_num']==0?0:1 ;
  3001. $value['updatetime'] = date("Y-m-d H:i:s");
  3002. $bk = Db::name("order_bk")->save($value);
  3003. if($bk==false){
  3004. return false;
  3005. }
  3006. $temp['cgdNo'] = $value['cgdNo'];
  3007. $temp['outCode'] = $outinfo['outCode'];
  3008. $temp['status'] = 1;
  3009. $temp['addtime']=date("Y-m-d H:i:s");
  3010. $temp['updatetime']=date("Y-m-d H:i:s");
  3011. $outsend[]=$temp;
  3012. $order = Db::name("order_num")->where(["orderCode"=>$der['orderCode'],"cgdNo"=>$value['cgdNo'],"spuCode"=>$der['spuCode'],"status"=>1])->find();
  3013. if($order==false){
  3014. $order=[
  3015. "orderCode"=>$der['orderCode'],
  3016. "cgdNo"=>$value['cgdNo'],
  3017. "spuCode"=>$der['spuCode'],
  3018. "good_num"=>$der['good_num'],
  3019. "wsend_num"=>$der['good_num']-$temp['send_num'],
  3020. "send_num"=>$temp['send_num'],
  3021. "status"=>1,
  3022. "source"=>1
  3023. ];
  3024. }else{
  3025. $order['wsend_num']-=$temp['send_num'];
  3026. $order['send_num']+=$temp['send_num'];
  3027. }
  3028. if($order['wsend_num']<0){
  3029. return false;
  3030. }
  3031. $up =Db::name("order_num")->save($order);
  3032. if($up==false){
  3033. return false;
  3034. }
  3035. if($send==0){
  3036. break;
  3037. }
  3038. }
  3039. if(empty($temp)){
  3040. return false;
  3041. }
  3042. $insert = Db::name("order_send")->insertAll($outsend);
  3043. if($insert){
  3044. return true;
  3045. }else{
  3046. return false;
  3047. }
  3048. }else{
  3049. $order = Db::name("order_num")->where(["orderCode"=>$der['orderCode'],"spuCode"=>$der['spuCode'],
  3050. "status"=>1])->find();
  3051. if($order==false){
  3052. return false;
  3053. }else{
  3054. if($outinfo['send_num']> $order['wsend_num']){
  3055. return false;
  3056. }
  3057. $order['wsend_num']-=$outinfo['send_num'];
  3058. $order['send_num']+=$outinfo['send_num'];
  3059. if($order['wsend_num']<0){
  3060. return false;
  3061. }
  3062. $up =Db::name("order_num")->save($order);
  3063. if($up==false){
  3064. return false;
  3065. }
  3066. $temp=[];
  3067. $temp['cgdNo'] = $order['cgdNo'];
  3068. $temp['outCode'] = $outinfo['outCode'];
  3069. $temp['send_num'] =$outinfo['send_num'];
  3070. $temp['status'] = 1;
  3071. $temp['addtime']=date("Y-m-d H:i:s");
  3072. $temp['updatetime']=date("Y-m-d H:i:s");
  3073. $insert = Db::name("order_send")->insert($temp);
  3074. if($insert){
  3075. return true;
  3076. }else{
  3077. return false;
  3078. }
  3079. }
  3080. }
  3081. }
  3082. public function addother(){
  3083. $orderCode =isset($this->post['orderCode']) && $this->post['orderCode']!=""?trim($this->post['orderCode']):"";
  3084. if($orderCode==""){
  3085. return error_show(1004,"参数orderCode不能为空");
  3086. }
  3087. $order =Db::name("sale")->where(["orderCode"=>$orderCode,"is_del"=>0])->find();
  3088. if($order==false){
  3089. return error_show(1004,"未找到订单数据");
  3090. }
  3091. $paytime =isset($this->post['paytime'])&&$this->post['paytime']!=""? $this->post['paytime']:"";
  3092. $workNo =isset($this->post['workNo'])&&$this->post['workNo']!=""? trim($this->post['workNo']):"";
  3093. $platform_order =isset($this->post['platform_order'])&&$this->post['platform_order']!=""? trim($this->post['platform_order']):"";
  3094. $paytime==""?"":$order['paytime']=$paytime;
  3095. $order['workNo']=$workNo;
  3096. $order['platform_order']=$platform_order;
  3097. $order['updatetime']=date("Y-m-d H:i:s");
  3098. $sa=Db::name("sale")->save($order);
  3099. if($sa){
  3100. return app_show(0,"更新成功");
  3101. }else{
  3102. return error_show(1004,"更新失败");
  3103. }
  3104. }
  3105. public function getPrice()
  3106. {
  3107. $skuCode = isset($this->post['skuCode']) && $this->post['skuCode'] != "" ? trim($this->post['skuCode']) : "";
  3108. if ($skuCode === "") {
  3109. return error_show(1003, "参数skuCode不能为空");
  3110. }
  3111. $is_activity = isset($this->post['is_activity']) && $this->post['is_activity'] !== "" ? intval($this->post['is_activity'])
  3112. : "";
  3113. if ($is_activity === "") {
  3114. return error_show(1003, "参数is_activity不能为空");
  3115. }
  3116. $sale_num = isset($this->post['sale_num']) && $this->post['sale_num'] !== "" ? intval($this->post['sale_num']) : "";
  3117. if ($sale_num === "") {
  3118. return error_show(1003, "参数sale_num不能为空");
  3119. }
  3120. $ct = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  3121. ->where(['a.skuCode' => $skuCode])->find();
  3122. if ($ct == false) {
  3123. return error_show(1002, "未找到商品数据");
  3124. }
  3125. $stock = 0;
  3126. if ($ct['is_stock'] == 1) {
  3127. $good_stock = Db::name("good_stock")->where(["spuCode" => $ct['spuCode'], "is_del" => 0])->find();
  3128. $stock = isset($good_stock['usable_stock']) ? $good_stock['usable_stock'] : "0";
  3129. }
  3130. if ($is_activity == 1) {
  3131. $act = Db::name("activity_info")->alias("a")->leftJoin("good_activity b", "a.activity_code=b.activity_code")
  3132. ->where(["a.skuCode" => $skuCode, "a.is_del" => 0, "a.status" => 1, "b.status" => 6, "b.is_del" => 0])->find();
  3133. if ($act == false) {
  3134. return error_show(1003, "未找到相关活动价");
  3135. }
  3136. if ($act['moq_num'] > $sale_num) {
  3137. return error_show(1003, "商品不满足活动价起订量{$act['moq_num']}");
  3138. }
  3139. if ($act['activity_stock'] < $sale_num) {
  3140. return error_show(1003, "商品活动库存剩余{$act['activity_stock']}");
  3141. }
  3142. return app_show(0, "获取成功", ['sale_price' => $act['activity_price'], "stock" => $act['activity_stock']]);
  3143. } else {
  3144. if ($ct['is_stock'] == 0) {
  3145. //good_nake 成本阶梯 good_ladder销售阶梯
  3146. $origin = Db::name("good_nake")->where([["spuCode", "=", $ct['spuCode']], ["is_del", "=", 0]])->order("min_num asc")->find();
  3147. if (!$origin) {
  3148. return error_show(1003, "没有找到成本数据");
  3149. }
  3150. }
  3151. $good = Db::name("good_ladder")->where(["skuCode" => $skuCode, "is_del" => 0, "status" => 1])->order("min_num asc")->find();
  3152. if (!$good) {
  3153. return error_show(1003, "未找到相关阶梯价格");
  3154. }
  3155. if(!isset($origin['min_num'])) $origin['min_num']=0;
  3156. $lastnum = max($origin['min_num']??0, $good['min_num']);
  3157. if ($sale_num < $lastnum) {
  3158. return error_show(1003, "商品不满足起订量{$lastnum}");
  3159. }
  3160. $good_temp = Db::name("good_ladder")->where(["skuCode" => $skuCode, "is_del" => 0, "status" => 1])->where('min_num', '<=', $sale_num)->order("min_num desc")->find();
  3161. if (!$good_temp) {
  3162. return error_show(1003, "未找到相关阶梯价格");
  3163. }
  3164. return app_show(0, "获取成功", ['sale_price' => $good_temp['sale_price'], "stock" => $stock]);
  3165. }
  3166. }
  3167. public function saleuse(){
  3168. $orderCode= isset($this->post['orderCode'])&&!empty($this->post['orderCode'])?$this->post['orderCode']:"";
  3169. if($orderCode==""){
  3170. return error_show(1003,"参数orderCode不能为空");
  3171. }
  3172. $order= Db::name("sale")->where(["orderCode"=>$orderCode,"is_del"=>0])->select()->toArray();
  3173. if(empty($order)){
  3174. return error_show(1003,"订单数据未找到");
  3175. }
  3176. $useid= isset($this->post['useid'])&&$this->post['useid']!=""?intval($this->post['useid']):"";
  3177. if($useid==""){
  3178. return error_show(1003,"参数useid不能为空");
  3179. }
  3180. $use =Db::name("order_use")->where(["id"=>$useid,"is_del"=>0])->find();
  3181. if($use==false){
  3182. return error_show(1003,"用途数据未找到");
  3183. }
  3184. $asve=['use_order'=>$useid,"updatetime"=>date("Y-m-d H:i:s")];
  3185. $up=Db::name("sale")->where(["orderCode"=>$orderCode,"is_del"=>0])->update($asve);
  3186. if($up>0){
  3187. return app_show(0,"更新成功");
  3188. }else{
  3189. return error_show(1003,"更新失败");
  3190. }
  3191. }
  3192. public function goodzxinfo(){
  3193. $orderCode= isset($this->post['spuCode'])&&$this->post['spuCode']!=''?trim($this->post['spuCode']):"";
  3194. if($orderCode==""){
  3195. return error_show(1003,"参数spuCode不能为空");
  3196. }
  3197. $order= Db::name("good_zixun")->where(["spuCode"=>$orderCode,"is_del"=>0])->find();
  3198. if(empty($order)){
  3199. return error_show(1003,"订单数据未找到");
  3200. }
  3201. $unit =Db::name("unit")->where(["id"=>$order['good_unit']])->find();
  3202. if($order['brand_id']!=0){
  3203. $brand=Db::name("brand")->where(["id"=>$order['brand_id']])->find();
  3204. $order["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  3205. }else{
  3206. $order["brand_name"]="";
  3207. $order["brand_id"]="";
  3208. }
  3209. $order['specinfo']=json_decode($order['specinfo'],true);
  3210. $order['unit'] = isset($unit['unit'])?$unit['unit']:'';
  3211. $order['cat_info'] = made($order['cat_id'],[]);
  3212. $order['noble_name']=isset($order['noble_metal'])&&$order['noble_metal']!=0?$this->noble[$order['noble_metal']] :"";
  3213. if($order['is_gold_price']==1){
  3214. $price=Db::name("gold_price1")->where(["type"=>$order['noble_metal'],"status"=>1,"is_del"=>0])->order("addtime desc")->find();
  3215. }
  3216. $supplier = Db::name("supplier")->where(["code"=>$order['supplierNo']])->find();
  3217. $order['supplier_name'] = isset($supplier['name']) ? $supplier['name']:"";
  3218. $palt =Db::name("platform")->where(["id"=>$order['platform_id']])->find();
  3219. $order['platform_name']=isset($palt['platform_name']) ? $palt['platform_name']:"";
  3220. $order["gold_price"] = isset($price['price'])?$price['price']:0;
  3221. $order["noble_weight"] = isset($order['weight'])?$order['weight']:0;
  3222. return app_show(0,"获取成功",$order);
  3223. }
  3224. //获取采反商品详情,当数据不在good_zixun中,模仿goodzxinfo
  3225. public function getGoodZxInfoByNotZixun(){
  3226. $param=$this->request->only(['spuCode'],'post','trim');
  3227. $val=Validate::rule(['spuCode'=>'require']);
  3228. if(!$val->check($param)) return error_show(1004,$val->getError());
  3229. $order = Db::name('consult_bids')
  3230. ->field(true)
  3231. ->where(['spuCode'=>$param['spuCode'],'is_del'=>0])
  3232. ->find();
  3233. // $orderCode= isset($this->post['spuCode'])&&$this->post['spuCode']!=''?trim($this->post['spuCode']):"";
  3234. // if($orderCode==""){
  3235. // return error_show(1003,"参数spuCode不能为空");
  3236. // }
  3237. // $order= Db::name("good_zixun")->where(["spuCode"=>$orderCode,"is_del"=>0])->find();
  3238. // if(empty($order)){
  3239. // return error_show(1003,"订单数据未找到");
  3240. // }
  3241. $unit =Db::name("unit")->where(["id"=>$order['unit_id']])->find();
  3242. if($order['brand_id']!=0){
  3243. $brand=Db::name("brand")->where(["id"=>$order['brand_id']])->find();
  3244. $order["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  3245. }else{
  3246. $order["brand_name"]="";
  3247. $order["brand_id"]="";
  3248. }
  3249. $order['specinfo']=json_decode($order['specinfo'],true);
  3250. $order['unit'] = isset($unit['unit'])?$unit['unit']:'';
  3251. $order['cat_info'] = made($order['cat_id'],[]);
  3252. $order['noble_name']=isset($order['noble_metal'])&&$order['noble_metal']!=0?$this->noble[$order['noble_metal']] :"";
  3253. if($order['is_gold_price']==1){
  3254. $price=Db::name("gold_price1")->where(["type"=>$order['noble_metal'],"status"=>1,"is_del"=>0])->order("addtime desc")->find();
  3255. }
  3256. $supplier = Db::name("supplier")->where(["code"=>$order['supplierNo']])->find();
  3257. $order['supplier_name'] = isset($supplier['name']) ? $supplier['name']:"";
  3258. // $palt =Db::name("platform")->where(["id"=>$order['platform_id']])->find();
  3259. // $order['platform_name']=isset($palt['platform_name']) ? $palt['platform_name']:"";
  3260. $order["gold_price"] = isset($price['price'])?$price['price']:0;
  3261. $order["noble_weight"] = isset($order['weight'])?$order['weight']:0;
  3262. return app_show(0,"获取成功",$order);
  3263. }
  3264. }