Sale.php 165 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402
  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. //新加字段
  744. $platform_order=isset($this->post['platform_order'])&&$this->post['platform_order']!="" ?$this->post['platform_order']:"";
  745. if($platform_order==""){
  746. return error_show(1002, "参数platform_order不能为空");
  747. }
  748. $workNo=isset($this->post['workNo'])&&$this->post['workNo']!="" ?$this->post['workNo']:"";
  749. if($workNo==""){
  750. return error_show(1002, "参数workNo不能为空");
  751. }
  752. Db::startTrans();
  753. try{
  754. $data=[
  755. "orderCode"=>$orderCode,
  756. "good_code"=>$spuCode,
  757. "skuCode"=>$skuCode,
  758. "customer_code"=>$zxorder['khNo'],
  759. "good_name"=>isset($zxinfo['good_name'])&&$zxinfo['good_name']!==''?$zxinfo['good_name']:'',
  760. "good_num"=>$good_num,
  761. "cat_id"=>$zxinfo['cat_id'],
  762. "apply_id"=>$rm,
  763. "apply_name"=>$ri,
  764. "origin_price"=>$zxinfo['nake_fee'],
  765. "sale_price" => $sale_price,//销售单价支持修改
  766. "post_fee"=>0,
  767. "status"=>0,
  768. "send_num"=>0,
  769. "wsend_num"=>$good_num,
  770. "send_status"=>1,
  771. "good_type"=>1,
  772. "send_type"=>$sendtype,
  773. "supplierNo"=>$zxorder['companyNo'],
  774. "is_del"=>0,
  775. "zxNo"=>$bidNo,
  776. "platform_order"=>$platform_order,
  777. "platform_id"=>0,
  778. "remark"=>$remark,
  779. "arrive_time"=>$arrtime,
  780. "is_stock"=>0,
  781. "is_activity"=>0,
  782. "proof_id"=>0,
  783. "order_type"=>3,
  784. "addtime"=>date("Y-m-d H:i:s"),
  785. "updatetime"=>date("Y-m-d H:i:s"),
  786. 'total_price' => round($sale_price * $good_num, 2),
  787. 'workNo'=>$workNo,
  788. ];
  789. $datainfo = Db::name('sale')->insert($data, true);
  790. if($datainfo>0){
  791. $old_zx_status = $zx['status'];
  792. $zx['status']=5;
  793. $zx['updatetime']=date("Y-m-d H:i:s");
  794. $sa=Db::name("consult_info")->save($zx);
  795. if($sa==false){
  796. Db::rollback();
  797. return error_show(1002,"咨询单修改失败");
  798. }else{
  799. //修改状态,添加待办
  800. ActionLog::logAdd($this->post['token'], [
  801. "order_code" => $zx['infoNo'],//咨询单详情编号
  802. "status" => $old_zx_status,//这里的status是之前的值
  803. "action_remark" => '',//备注
  804. "action_type" => "status"//新建create,编辑edit,更改状态status
  805. ], "ZXD", 5, $zx);
  806. ProcessOrder::AddProcess($this->post['token'], [
  807. "order_type" => 'ZXD',
  808. "order_code" => $zx['infoNo'],//咨询单详情编号
  809. "order_id" => $zx['id'],
  810. "order_status" => 5
  811. ]);
  812. }
  813. $bol=$this->createCgd($cgd);
  814. if($bol==false){
  815. Db::rollback();
  816. return error_show(1002,"咨询订单创建失败");
  817. }
  818. $limt=[
  819. "spuCode"=>$zxinfo['spuCode'],
  820. "good_name"=>$zxinfo['good_name'],
  821. "brand_id"=>$zxinfo['brand_id'],
  822. "good_unit"=>$zxinfo['unit_id'],
  823. "cat_id"=>$zxinfo['cat_id'],
  824. "good_type"=>0,
  825. "moq"=>1,
  826. "customized"=>$zxinfo['work_day'],
  827. "tax"=>$zxinfo['tax'],
  828. "supplierNo"=>$zxinfo["supplierNo"],
  829. "is_auth"=>0,
  830. "craft_desc"=>$zxinfo['good_name'],
  831. "good_remark"=>"",
  832. "platform_id"=>$zxorder['platform_id'],
  833. "good_img"=>$zxinfo['good_img'],
  834. "good_thumb_img"=>"",
  835. "good_info_img"=>"",
  836. "specinfo"=>$zxinfo['specinfo'],
  837. "work_day"=>$zxinfo['work_day'],
  838. "noble_metal"=>$zxinfo['metal_id'],
  839. "is_gold_price"=>$zxinfo['is_gold_price'],
  840. "config"=>$zxinfo['config'],
  841. "other_config"=>$zxinfo['other_config'],
  842. "weight"=>$zxinfo['weight'],
  843. "good_weight"=>$zxinfo['good_weight'],
  844. "is_diff"=>$zxinfo['is_diff'],
  845. "supply_area"=>$zxinfo['supply_area'],
  846. "pay_way"=>$zxinfo['pay_way'],
  847. "send_way"=>$zxinfo['send_way'],
  848. "status"=>1,
  849. "is_del"=>0,
  850. "createrid"=>$zxinfo['createrid'],
  851. "creater"=>$zxinfo['creater'],
  852. "addtime"=>date("Y-m-d H:i:s"),
  853. "updatetime"=>date("Y-m-d H:i:s")
  854. ];
  855. $good = Db::name("good_zixun")->insert($limt);
  856. if(!$good){
  857. Db::rollback();
  858. return error_show(1006,"咨询商品录入失败");
  859. }
  860. if(!empty($va)){
  861. $order =Db::name("order_num")->where(["orderCode"=>$orderCode,"status"=>1])->where([["wsend_num",">=",0]])
  862. ->find();
  863. if($order==false){
  864. Db::rollback();
  865. return error_show(1006,"采购单关联数据未找到");
  866. }
  867. foreach ($va as $value){
  868. $temp=[];
  869. $addrs=[];
  870. if($value['addr_code']!==''&&is_array($value['addr_code'])){
  871. $addrs['provice_code'] = $value['addr_code'][0];
  872. $addrs['city_code'] = $value['addr_code'][1];
  873. $addrs['area_code'] = $value['addr_code'][2];
  874. $addr = json_encode($addrs);
  875. }else{
  876. $addr = isset($value['addr_code'])?$value['addr_code']:'';
  877. }
  878. $temp['orderCode']=$orderCode;
  879. $temp['contactor']=$value['contactor'];
  880. $temp['mobile'] = $value['mobile'];
  881. $temp['addr'] = $value['addr'];
  882. $temp['addr_code']=$addr;
  883. $temp['customer_code'] =$zxorder['khNo'];
  884. $temp['receipt_quantity']=$value['receipt_quantity'];
  885. $temp['post_fee'] =0;
  886. $temp['is_del'] =0;
  887. $temp['addtime'] =date("Y-m-d H:i:s");
  888. $temp['updatetime'] =date("Y-m-d H:i:s");
  889. $temp['arrive_time']=$arrtime;
  890. $vmp = Db::name('order_addr')->insert($temp,true);
  891. if($vmp>0){
  892. $outCode=makeNo("DF");
  893. $out=[
  894. "orderCode"=>$orderCode,
  895. "outCode"=>$outCode,
  896. "apply_id"=>$rm,
  897. "apply_name"=>$ri,
  898. "addrid"=>$vmp,
  899. "post_name"=>"",
  900. "post_code"=>"",
  901. "post_fee"=>0,
  902. "sendtime"=>date("Y-m-d H:i:s"),
  903. "send_num"=>$value['receipt_quantity'],
  904. "check_num"=>0,
  905. "error_num"=>0,
  906. "wsm_code"=>"",
  907. "order_type"=>3,
  908. "status"=>0,
  909. "addtime"=>date("Y-m-d H:i:s"),
  910. "updatetime"=>date("Y-m-d H:i:s")
  911. ];
  912. $ou =Db::name("order_out")->insert($out);
  913. if($ou==false){
  914. Db::rollback();
  915. return error_show(1002,"发货地址添加创建失败");
  916. }else{
  917. //修改状态,添加待办
  918. ActionLog::logAdd($this->post['token'], [
  919. "order_code" => $outCode,//出库单号
  920. "status" => 0,//这里的status是之前的值
  921. "action_remark" => '',//备注
  922. "action_type" => "create"//新建create,编辑edit,更改状态status
  923. ], "CKD", 0, $out);
  924. ProcessOrder::AddProcess($this->post['token'], [
  925. "order_type" => 'CKD',
  926. "order_code" => $outCode,//出库单号
  927. "order_id" => 0,
  928. "order_status" => 0
  929. ]);
  930. }
  931. $order['send_num']+=$value['receipt_quantity'];
  932. $order['wsend_num']-=$value['receipt_quantity'];
  933. if($order['wsend_num']<0){
  934. Db::rollback();
  935. return error_show(1002,"发货数量已超出总数");
  936. }
  937. $ups = Db::name("order_num")->save($order);
  938. if($ups){
  939. $tep=[
  940. "cgdNo"=>$order['cgdNo'],
  941. "outCode"=>$outCode,
  942. "send_num"=>$value['receipt_quantity'],
  943. "status"=>1,
  944. "addtime"=>date("Y-m-d H:i:s"),
  945. "updatetime"=>date("Y-m-d H:i:s")
  946. ];
  947. $sen=Db::name("order_send")->save($tep);
  948. if($sen==false){
  949. Db::rollback();
  950. return error_show(1002,"发货地址添加创建失败");
  951. }
  952. }
  953. }else{
  954. Db::rollback();
  955. return error_show(1002,"发货地址添加创建失败");
  956. }
  957. }
  958. }
  959. Db::commit();
  960. return error_show(0,"咨询订单创建成功",["order_code"=>$orderCode]);
  961. }
  962. Db::rollback();
  963. return error_show(1002,"咨询订单创建失败");
  964. }catch(\Exception $e){
  965. Db::rollback();
  966. return error_show(1003,$e->getMessage());
  967. }
  968. }
  969. /**
  970. * @return \think\response\Json|void
  971. * @throws \think\db\exception\DataNotFoundException
  972. * @throws \think\db\exception\DbException
  973. * @throws \think\db\exception\ModelNotFoundException
  974. */
  975. public function projectCreate(){
  976. $planNo =isset($this->post['planNo'])&&$this->post['planNo']!=""?trim($this->post['planNo']):"";
  977. if($planNo==""){
  978. return error_show(1004,"参数planNo不能为空");
  979. }
  980. $plan =Db::name("project_plan")->where(["planNo"=>$planNo,"is_del"=>0])->find();
  981. if($plan==false){
  982. return error_show(1004,"未找到方案信息");
  983. }
  984. $feedbackid = Db::name("project_plan_rela")->where(["planNo"=>$planNo,"is_del"=>0])->column("feedback_id,sale_price,sale_num");
  985. if($feedbackid==false){
  986. return error_show(1004,"未找到方案反馈信息");
  987. }
  988. $project = Db::name("project")->where(["projectNo"=>$plan['projectNo'],"is_del"=>0])->find();
  989. if($project==false){
  990. return error_show(1004,"未找到方案信息");
  991. }
  992. $arrtime=isset($this->post['arrtime'])&&$this->post['arrtime']!="" ?$this->post['arrtime']:"";
  993. if($arrtime==""){
  994. return error_show(1002, "参数arrtime不能为空");
  995. }
  996. $planinfo =isset($this->post['planinfo'])&&!empty($this->post['planinfo']) ?$this->post['planinfo']:"";
  997. if($planinfo==""){
  998. return error_show(1002, "参数planinfo不能为空");
  999. }
  1000. $token=isset($this->post['token'])&&$this->post['token']!=""? trim($this->post['token']):"";
  1001. if($token==""){
  1002. return error_show(102, "参数token不能为空");
  1003. }
  1004. $apply_id = GetUserInfo($token);
  1005. if (empty($apply_id) || $apply_id['code'] != 0) {
  1006. return error_show(102, "申请人数据不存在");
  1007. }
  1008. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1009. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1010. Db::startTrans();
  1011. try {
  1012. $feedid = array_column($feedbackid,"feedback_id");
  1013. foreach ($planinfo as $value){
  1014. $good=[];
  1015. $feedback = Db::name("project_feedback")->where(["id"=>$value['feedback_id'],"projectNo"=>$plan['projectNo'],
  1016. "is_del"=>0])->find();
  1017. if($feedback==false){
  1018. Db::rollback();
  1019. return error_show(1002, "反馈数据未找到");
  1020. }
  1021. $key =array_search($feedback['id'],$feedid);
  1022. $price = $feedbackid[$key];
  1023. $good['spuCode'] = $feedback['spuCode'];
  1024. $good['skuCode'] = $feedback['skuCode'];
  1025. $good['good_num'] = $price['sale_num'];
  1026. $good['sendtype'] = $value['sendtype'];
  1027. $good['sale_price']=$price['sale_price'];
  1028. $good['origin_price']=$feedback['origin_price'];
  1029. $good['companyNo']=$project['companyNo'];
  1030. $good['customerNo']=$project['khNo'];
  1031. $good['pgNo']=$feedback['pgNo'];
  1032. $good['arrtime']=$arrtime;
  1033. $good['rm']=$rm;
  1034. $good['ri']=$ri;
  1035. if($value['sendtype']==1){
  1036. if(!isset($value['addrlist'])||empty($value['addrlist'])){
  1037. Db::rollback();
  1038. return error_show(1002, "订单地址不能为空");
  1039. }
  1040. $good['addrlist'] = $value['addrlist'];
  1041. }
  1042. if($feedback['data_source']==1){
  1043. $feed=$this->project_good($good);
  1044. }else{
  1045. $feed=$this->project_zx($good);
  1046. }
  1047. if($feed==false){
  1048. Db::rollback();
  1049. return error_show(1002, "咨询订单生成失败");
  1050. }
  1051. $feedback['status']=2;
  1052. $feedback['updatetime']=date("Y-m-d H:i:s");
  1053. $fed =Db::name("project_feedback")->save($feedback);
  1054. if($fed==false){
  1055. Db::rollback();
  1056. return error_show(1002, "项目订单生成失败");
  1057. }
  1058. }
  1059. $old_plan_status = $plan['status'];
  1060. $plan['status']=2;
  1061. $plan['updatetime']=date("Y-m-d H:i:s");
  1062. $in =Db::name("project_plan")->save($plan);
  1063. if($in==false){
  1064. Db::rollback();
  1065. return error_show(1002, "项目订单生成失败");
  1066. }else{
  1067. //修改状态,添加待办,只记录动作
  1068. ActionLog::logAdd($this->post['token'], [
  1069. "order_code" => $planNo,//编码
  1070. "status" => $old_plan_status,//这里的status是之前的值
  1071. "action_remark" => '',//备注
  1072. "action_type" => "edit"//新建create,编辑edit,更改状态status
  1073. ], "PRO", 2, $plan);
  1074. }
  1075. $old_project_status = $project["status"];
  1076. $project["status"]=6;
  1077. $project['updatetime']=date("Y-m-d H:i:s");
  1078. $pr =Db::name("project")->save($project);
  1079. if($pr==false){
  1080. Db::rollback();
  1081. return error_show(1002, "项目订单生成失败");
  1082. }else{
  1083. //修改状态,添加待办
  1084. ActionLog::logAdd($this->post['token'], [
  1085. "order_code" => $project['projectNo'],//项目编码
  1086. "status" => $old_project_status,//这里的status是之前的值
  1087. "action_remark" => '',//备注
  1088. "action_type" => "status"//新建create,编辑edit,更改状态status
  1089. ], "PRO", 6, $project);
  1090. ProcessOrder::AddProcess($this->post['token'], [
  1091. "order_type" => 'PRO',
  1092. "order_code" => $project['projectNo'],
  1093. "order_id" => $project['id'],
  1094. "order_status" => 6
  1095. ]);
  1096. }
  1097. Db::commit();
  1098. return app_show(0, "咨询订单生成成功");
  1099. }catch (\Exception $e){
  1100. Db::rollback();
  1101. return error_show(1002, $e->getMessage());
  1102. }
  1103. }
  1104. /**
  1105. * @param $data
  1106. * @return false
  1107. * @throws \think\db\exception\DataNotFoundException
  1108. * @throws \think\db\exception\DbException
  1109. * @throws \think\db\exception\ModelNotFoundException
  1110. *
  1111. */
  1112. public function project_zx($data){
  1113. $goodinfo = Db::name("consult_bids")->where(["spuCode"=>$data['spuCode'],"is_del"=>0])->find();
  1114. if($goodinfo==false){
  1115. return false;
  1116. }
  1117. $orderCode=makeNo("QR");
  1118. $cgd=[
  1119. "supplierNo"=>$goodinfo['supplierNo'],
  1120. "companyNo"=>$data['companyNo'],
  1121. "spuCode"=>$data['spuCode'],
  1122. "skuCode"=>"",
  1123. "orderCode"=>$orderCode,
  1124. "good_name"=>$goodinfo['good_name'],
  1125. "sale_price"=>$data['origin_price'],
  1126. "total_fee"=>$data['origin_price']*$data['good_num'],
  1127. "pakge_fee"=>$goodinfo['pakge_fee'],
  1128. "cert_fee"=>$goodinfo['cert_fee'],
  1129. "open_fee"=>$goodinfo['open_fee'],
  1130. "cost_fee"=>$goodinfo['cost_fee'],
  1131. "mark_fee"=>$goodinfo['mark_fee'],
  1132. "demo_fee"=>$goodinfo['demo_fee'],
  1133. "good_num"=>$data['good_num'],
  1134. "createrid"=>$goodinfo['createrid'],
  1135. "creater"=>$goodinfo['creater'],
  1136. "good_type"=>1,
  1137. "order_type"=>4,
  1138. "send_way"=>$goodinfo['send_way'],
  1139. ];
  1140. $datas=[
  1141. "orderCode"=>$orderCode,
  1142. "good_code"=>$data['spuCode'],
  1143. "skuCode"=>"",
  1144. "customer_code"=>$data['customerNo'],
  1145. "good_name"=>isset($goodinfo['good_name'])&&$goodinfo['good_name']!==''?$goodinfo['good_name']:'',
  1146. "good_num"=>$data['good_num'],
  1147. "cat_id"=>$goodinfo['cat_id'],
  1148. "apply_id"=>$data['rm'],
  1149. "apply_name"=>$data['ri'],
  1150. "origin_price"=>$goodinfo['nake_fee'],
  1151. "sale_price"=>$data['sale_price'],
  1152. "post_fee"=>0,
  1153. "status"=>0,
  1154. "send_num"=>0,
  1155. "wsend_num"=>$data['good_num'],
  1156. "send_status"=>1,
  1157. "good_type"=>1,
  1158. "send_type"=>$data['sendtype'],
  1159. "supplierNo"=>$data['companyNo'],
  1160. "is_del"=>0,
  1161. "zxNo"=>$data["pgNo"],
  1162. "platform_order"=>"",
  1163. "platform_id"=>0,
  1164. "remark"=>"",
  1165. "is_stock"=>0,
  1166. "is_activity"=>0,
  1167. "proof_id"=>0,
  1168. "order_type"=>4,
  1169. "addtime"=>date("Y-m-d H:i:s"),
  1170. "updatetime"=>date("Y-m-d H:i:s"),
  1171. 'total_price'=>round($data['sale_price']*$data['good_num'],2),
  1172. ];
  1173. $datainfo = Db::name('sale')->insert($datas, true);
  1174. if($datainfo>0){
  1175. $bol = $this->createCgd($cgd);
  1176. if ($bol == false) {
  1177. return false;
  1178. }
  1179. $goodinfo['status']=6;
  1180. $goodinfo['updatetime']=date("Y-m-d H:i:s");
  1181. $sa=Db::name("consult_bids")->save($goodinfo);
  1182. if($sa==false){
  1183. return false;
  1184. }
  1185. $zxorder =Db::name("consult_order")->where(["zxNo"=>$goodinfo["zxNo"],"is_del"=>0])->find();
  1186. if($zxorder==false){
  1187. return false;
  1188. }
  1189. $limt=[
  1190. "spuCode"=>$goodinfo['spuCode'],
  1191. "good_name"=>$goodinfo['good_name'],
  1192. "brand_id"=>$goodinfo['brand_id'],
  1193. "good_unit"=>$goodinfo['unit_id'],
  1194. "cat_id"=>$goodinfo['cat_id'],
  1195. "good_type"=>0,
  1196. "moq"=>1,
  1197. "customized"=>$goodinfo['work_day'],
  1198. "tax"=>$goodinfo['tax'],
  1199. "supplierNo"=>$goodinfo["supplierNo"],
  1200. "is_auth"=>0,
  1201. "craft_desc"=>$goodinfo['good_name'],
  1202. "good_remark"=>"",
  1203. "good_img"=>$goodinfo['good_img'],
  1204. "good_thumb_img"=>"",
  1205. "good_info_img"=>"",
  1206. "platform_id"=>$zxorder['platform_id'],
  1207. "specinfo"=>$goodinfo['specinfo'],
  1208. "work_day"=>$goodinfo['work_day'],
  1209. "noble_metal"=>$goodinfo['metal_id'],
  1210. "is_gold_price"=>$goodinfo['is_gold_price'],
  1211. "good_weight"=>$goodinfo['good_weight'],
  1212. "config"=>$goodinfo['config'],
  1213. "other_config"=>$goodinfo['other_config'],
  1214. "weight"=>$goodinfo['weight'],
  1215. "is_diff"=>$goodinfo['is_diff'],
  1216. "supply_area"=>$goodinfo['supply_area'],
  1217. "pay_way"=>$goodinfo['pay_way'],
  1218. "send_way"=>$goodinfo['send_way'],
  1219. "status"=>1,
  1220. "is_del"=>0,
  1221. "createrid"=>$goodinfo['createrid'],
  1222. "creater"=>$goodinfo['creater'],
  1223. "addtime"=>date("Y-m-d H:i:s"),
  1224. "updatetime"=>date("Y-m-d H:i:s")
  1225. ];
  1226. $good = Db::name("good_zixun")->insert($limt);
  1227. if(!$good){
  1228. return false;
  1229. }
  1230. if ($data['sendtype']==1&&!empty($data['addrlist'])) {
  1231. $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
  1232. ->find();
  1233. if ($order == false) {
  1234. return false;
  1235. }
  1236. foreach ($data['addrlist'] as $value) {
  1237. $temp = [];
  1238. $addrs = [];
  1239. if ($value['addr_code'] !== '' && is_array($value['addr_code'])) {
  1240. $addrs['provice_code'] = $value['addr_code'][0];
  1241. $addrs['city_code'] = $value['addr_code'][1];
  1242. $addrs['area_code'] = $value['addr_code'][2];
  1243. $addr = json_encode($addrs);
  1244. } else {
  1245. $addr = isset($value['addr_code']) ? $value['addr_code'] : '';
  1246. }
  1247. $temp['orderCode'] = $orderCode;
  1248. $temp['contactor'] = $value['contactor'];
  1249. $temp['mobile'] = $value['mobile'];
  1250. $temp['addr'] = $value['addr'];
  1251. $temp['addr_code'] = $addr;
  1252. $temp['customer_code'] = $data['companyNo'];
  1253. $temp['receipt_quantity'] = $value['receipt_quantity'];
  1254. $temp['post_fee'] = 0;
  1255. $temp['is_del'] = 0;
  1256. $temp['addtime'] = date("Y-m-d H:i:s");
  1257. $temp['updatetime'] = date("Y-m-d H:i:s");
  1258. $temp['arrive_time'] = $data['arrtime'];
  1259. $vmp = Db::name('order_addr')->insert($temp, true);
  1260. if ($vmp > 0) {
  1261. // $outCode = makeNo("CK");
  1262. // $out = [
  1263. // "orderCode" => $orderCode,
  1264. // "outCode" => $outCode,
  1265. // "apply_id"=>$data['rm'],
  1266. // "apply_name"=>$data['ri'],
  1267. // "addrid" => $vmp,
  1268. // "post_name" => "",
  1269. // "post_code" => "",
  1270. // "post_fee" => 0,
  1271. // "sendtime" => date("Y-m-d H:i:s"),
  1272. // "send_num" => $value['receipt_quantity'],
  1273. // "check_num" => 0,
  1274. // "error_num" => 0,
  1275. // "wsm_code" => "",
  1276. // "order_type" => 4,
  1277. // "status" => 0,
  1278. // "addtime" => date("Y-m-d H:i:s"),
  1279. // "updatetime" => date("Y-m-d H:i:s")
  1280. // ];
  1281. // $ou = Db::name("order_out")->insert($out);
  1282. // if ($ou == false) {
  1283. // return false;
  1284. // }
  1285. // $order['send_num'] += $value['receipt_quantity'];
  1286. // $order['wsend_num'] -= $value['receipt_quantity'];
  1287. // if ($order['wsend_num'] < 0) {
  1288. // return false;
  1289. // }
  1290. // $ups = Db::name("order_num")->save($order);
  1291. // if ($ups) {
  1292. // $tep = [
  1293. // "cgdNo" => $order['cgdNo'],
  1294. // "outCode" => $outCode,
  1295. // "send_num" => $value['receipt_quantity'],
  1296. // "status" => 1,
  1297. // "addtime" => date("Y-m-d H:i:s"),
  1298. // "updatetime" => date("Y-m-d H:i:s")
  1299. // ];
  1300. // $sen = Db::name("order_send")->save($tep);
  1301. // if ($sen == false) {
  1302. // return false;
  1303. // }
  1304. // }
  1305. } else {
  1306. return false;
  1307. }
  1308. }
  1309. }
  1310. }
  1311. return true;
  1312. }
  1313. /**
  1314. * @param $data
  1315. * @return bool
  1316. * @throws \think\db\exception\DataNotFoundException
  1317. * @throws \think\db\exception\DbException
  1318. * @throws \think\db\exception\ModelNotFoundException
  1319. */
  1320. public function project_good($data){
  1321. $good=Db::name('good')
  1322. ->alias("a")
  1323. ->leftJoin("good_platform b","a.spuCode=b.spuCode")
  1324. ->where(["b.skuCode"=>$data['skuCode'],"a.is_del"=>0,"b.is_del"=>0])
  1325. ->find();
  1326. if($good==false){
  1327. return false;
  1328. }
  1329. $goodlass = Db::name("good_ladder")->where(["skuCode"=>$data['skuCode'],"is_del"=>0,"status"=>1])->where([["min_num",
  1330. "<=",$data['good_num']]])->order("min_num desc")->find();
  1331. if($goodlass==false){
  1332. return false;
  1333. }
  1334. $sale_price = $goodlass['sale_price'];
  1335. $origin = Db::name("good_nake")->where([["spuCode","=",$data['spuCode']],["min_num","<=",$data['good_num']],
  1336. ["is_del","=",0]])->order("min_num desc")->find();
  1337. if($origin==false){
  1338. return false;
  1339. }
  1340. $origin_price = $origin['nake_total'];
  1341. $orderCode=makeNo("QR");
  1342. $datas=[
  1343. "orderCode"=>$orderCode,
  1344. "good_code"=>$data['spuCode'],
  1345. "skuCode"=>$data['skuCode'],
  1346. "customer_code"=>$data['customerNo'],
  1347. "good_name"=>isset($good['good_name'])&&$good['good_name']!==''?$good['good_name']:'',
  1348. "good_num"=>$data['good_num'],
  1349. "cat_id"=>$good['cat_id'],
  1350. "apply_id"=>$data['rm'],
  1351. "apply_name"=>$data['ri'],
  1352. "origin_price"=>$origin_price,
  1353. "sale_price"=>$sale_price,
  1354. "post_fee"=>0,
  1355. "status"=>0,
  1356. "send_num"=>0,
  1357. "wsend_num"=>$data['good_num'],
  1358. "send_status"=>1,
  1359. "good_type"=>1,
  1360. "send_type"=>$data['sendtype'],
  1361. "supplierNo"=>$data['companyNo'],
  1362. "is_del"=>0,
  1363. "zxNo"=>$data["pgNo"],
  1364. "platform_order"=>"",
  1365. "platform_id"=>0,
  1366. "remark"=>"",
  1367. "is_stock"=>$good['is_stock'],
  1368. "is_activity"=>0,
  1369. "proof_id"=>0,
  1370. "order_type"=>2,
  1371. "addtime"=>date("Y-m-d H:i:s"),
  1372. "updatetime"=>date("Y-m-d H:i:s"),
  1373. 'total_price'=>round($sale_price*$data['good_num'],2),
  1374. ];
  1375. $datainfo = Db::name('sale')->insert($datas, true);
  1376. if($datainfo>0) {
  1377. $cgd=[
  1378. "supplierNo"=>$good['supplierNo'],
  1379. "companyNo"=>$data['companyNo'],
  1380. "orderCode"=>$orderCode,
  1381. "spuCode"=>$good['spuCode'],
  1382. "skuCode"=>$good['skuCode'],
  1383. "good_name"=>$good['good_name'],
  1384. "sale_price"=>$origin_price,
  1385. "total_fee"=>$origin_price*$data['good_num'],
  1386. "pakge_fee"=>$origin['package_fee'],
  1387. "cert_fee"=>$origin['cert_fee'],
  1388. "open_fee"=>$good['open_fee'],
  1389. "cost_fee"=>$origin['cost_fee'],
  1390. "mark_fee"=>$origin['mark_fee'],
  1391. "demo_fee"=>$good['demo_fee'],
  1392. "good_num"=>$data['good_num'],
  1393. "good_type"=>1,
  1394. "createrid"=>$good['createrid'],
  1395. "creater"=>$good['creater'],
  1396. "order_type"=>$good['is_stock']==1?1:2,
  1397. 'send_way'=>2
  1398. ];
  1399. if($good['is_stock']==0) {
  1400. $bol = $this->createCgd($cgd);
  1401. if ($bol == false) {
  1402. return false;
  1403. }
  1404. }else{
  1405. $dd=[
  1406. "orderCode"=>$orderCode,
  1407. "spuCode"=>$good['spuCode'],
  1408. "total_num"=>$data['good_num'],
  1409. "merge_num"=>0,
  1410. "balance_num"=>$data['good_num'],
  1411. "status"=>1,
  1412. "is_del"=>0,
  1413. "addtime"=>date("Y-m-d H:i:s"),
  1414. "updatetime"=>date("Y-m-d H:i:s"),
  1415. ];
  1416. $db=Db::name("sale_bk")->insert($dd);
  1417. if($db==false){
  1418. return false;
  1419. }
  1420. }
  1421. if ($data['sendtype']==1&&!empty($data['addrlist'])) {
  1422. // $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
  1423. // ->find();
  1424. // if ($order == false) {
  1425. // return false;
  1426. // }
  1427. foreach ($data['addrlist'] as $value) {
  1428. $temp = [];
  1429. $addrs = [];
  1430. if ($value['addr_code'] !== '' && is_array($value['addr_code'])) {
  1431. $addrs['provice_code'] = $value['addr_code'][0];
  1432. $addrs['city_code'] = $value['addr_code'][1];
  1433. $addrs['area_code'] = $value['addr_code'][2];
  1434. $addr = json_encode($addrs);
  1435. } else {
  1436. $addr = isset($value['addr_code']) ? $value['addr_code'] : '';
  1437. }
  1438. $temp['orderCode'] = $orderCode;
  1439. $temp['contactor'] = $value['contactor'];
  1440. $temp['mobile'] = $value['mobile'];
  1441. $temp['addr'] = $value['addr'];
  1442. $temp['addr_code'] = $addr;
  1443. $temp['customer_code'] =$data['companyNo'];
  1444. $temp['receipt_quantity'] = $value['receipt_quantity'];
  1445. $temp['post_fee'] = 0;
  1446. $temp['is_del'] = 0;
  1447. $temp['addtime'] = date("Y-m-d H:i:s");
  1448. $temp['updatetime'] = date("Y-m-d H:i:s");
  1449. $temp['arrive_time'] = $data['arrtime'];
  1450. $vmp = Db::name('order_addr')->insert($temp, true);
  1451. if ($vmp > 0) {
  1452. // if($good['is_stock']!=1){
  1453. // $outCode = makeNo("CK");
  1454. // $out = [
  1455. // "orderCode" => $orderCode,
  1456. // "outCode" => $outCode,
  1457. // "apply_id"=>$data['rm'],
  1458. // "apply_name"=>$data['ri'],
  1459. // "addrid" => $vmp,
  1460. // "post_name" => "",
  1461. // "post_code" => "",
  1462. // "post_fee" => 0,
  1463. // "sendtime" => date("Y-m-d H:i:s"),
  1464. // "send_num" => $value['receipt_quantity'],
  1465. // "check_num" => 0,
  1466. // "error_num" => 0,
  1467. // "wsm_code" => "",
  1468. // "order_type" => 4,
  1469. // "status" => 0,
  1470. // "addtime" => date("Y-m-d H:i:s"),
  1471. // "updatetime" => date("Y-m-d H:i:s")
  1472. // ];
  1473. // $ou = Db::name("order_out")->insert($out);
  1474. // if ($ou == false) {
  1475. // return false;
  1476. // }
  1477. // $order['send_num'] += $value['receipt_quantity'];
  1478. // $order['wsend_num'] -= $value['receipt_quantity'];
  1479. // if ($order['wsend_num'] < 0) {
  1480. // return false;
  1481. // }
  1482. // $ups = Db::name("order_num")->save($order);
  1483. // if ($ups) {
  1484. // $tep = [
  1485. // "cgdNo" => $order['cgdNo'],
  1486. // "outCode" => $outCode,
  1487. // "send_num" => $value['receipt_quantity'],
  1488. // "status" => 1,
  1489. // "addtime" => date("Y-m-d H:i:s"),
  1490. // "updatetime" => date("Y-m-d H:i:s")
  1491. // ];
  1492. // $sen = Db::name("order_send")->insert($tep);
  1493. // if ($sen == false) {
  1494. // return false;
  1495. // }
  1496. // }
  1497. // }
  1498. } else {
  1499. return false;
  1500. }
  1501. }
  1502. }
  1503. }
  1504. return true;
  1505. }
  1506. public function list()
  1507. {
  1508. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  1509. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  1510. $where[] = ['is_del', "=", 0];
  1511. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  1512. if ($orderCode !== "") {
  1513. $where[] = ['orderCode', "like", "%$orderCode%"];
  1514. }
  1515. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !== "" ? trim($this->post['apply_name'])
  1516. : "";
  1517. if ($apply_name !== "") {
  1518. $where[] = ['apply_name', "like", "%$apply_name%"];
  1519. }
  1520. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name'])
  1521. : "";
  1522. if ($good_name !== "") {
  1523. $where[] = ['good_name', "like", "%$good_name%"];
  1524. }
  1525. $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
  1526. if ($good_code !== "") {
  1527. $where[] = ['good_code', "like", "%$good_code%"];
  1528. }
  1529. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] !== "" ? trim($this->post['customer_code']) : "";
  1530. if ($customer_code !== "") {
  1531. $where[] = ['customer_code', "like", "%$customer_code%"];
  1532. }
  1533. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  1534. if ($supplierNo !== "") {
  1535. $where[] = ['supplierNo', "like", "%$supplierNo%"];
  1536. }
  1537. $ordertype = isset($this->post['order_type']) && $this->post['order_type'] !== "" ? intval($this->post['order_type'])
  1538. : "";
  1539. if ($ordertype !== "") {
  1540. $where[] = ['order_type', "=", $ordertype];
  1541. }
  1542. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  1543. if ($status !== "") {
  1544. $where[] = ['status', "=", $status];
  1545. }
  1546. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  1547. if ($start != "") {
  1548. $where[] = ["addtime", '>=', $start];
  1549. }
  1550. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  1551. if ($end != "") {
  1552. $where[] = ["addtime", '<=', $end];
  1553. }
  1554. $count = Db::name('sale')->where($where)->count();
  1555. $total = ceil($count / $size);
  1556. $page = $page >= $total ? $total : $page;
  1557. $list = Db::name('sale')->where($where)->order("addtime desc")->page($page, $size)->select();
  1558. $data = [];
  1559. foreach ($list as $value) {
  1560. if($value['order_type']==3|| $value['order_type']==4){
  1561. $var = Db::name("good_zixun")->where(["spuCode"=>$value['good_code'],"is_del"=>0])->find();
  1562. $value["speclist"]=isset($var['specinfo'])&&$var['specinfo']!=""? json_decode($var['specinfo'],true):"";
  1563. }else {
  1564. $var = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  1565. ->where(['a.skuCode' => $value['skuCode']])->find();
  1566. $spec = Db::name("good_spec")->where(["spuCode"=>$var['spuCode'],"is_del"=>0])->select()->toArray();
  1567. $speclist=[];
  1568. if(!empty($spec)){
  1569. foreach ($spec as $val){
  1570. $temp=[];
  1571. $temp['id']=$val['id'];
  1572. $temp['spuCode']=$val['spuCode'];
  1573. $temp['spec_id']=$val['spec_id'];
  1574. $temp['spec_value_id']=$val['spec_value_id'];
  1575. $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
  1576. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  1577. $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
  1578. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  1579. $speclist[]=$temp;
  1580. }
  1581. }
  1582. $value["speclist"]=empty($speclist)?[]:$speclist;
  1583. }
  1584. $value['can'] = isset($var['cat_id']) && $var['cat_id'] != 0 ? made($var['cat_id']) : [];
  1585. $value['supplierName'] = '';
  1586. if ($value['supplierNo'] != "") {
  1587. $supplier = Db::name("business")->where(["companyNo" => $value['supplierNo']])->find();
  1588. $value['supplierName'] = isset($supplier['company']) ? $supplier['company'] : "";
  1589. }
  1590. $value['customerName'] = '';
  1591. if ($value['customer_code'] != "") {
  1592. $supplier = Db::name("customer_info")->where(["companyNo" => $value['customer_code']])->find();
  1593. $value['customerName'] = isset($supplier['companyName']) ? $supplier['companyName'] : "";
  1594. }
  1595. $value['useage']="";
  1596. if($value['use_order']!=0){
  1597. $use =Db::name("order_use")->where(["id"=>$value['use_order']])->find();
  1598. $value['useage'] = isset($use['order_use']) ?$use['order_use']:"";
  1599. }else{
  1600. $value['use_order']='';
  1601. }
  1602. $data[] = $value;
  1603. }
  1604. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  1605. }
  1606. public function edit()
  1607. {
  1608. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  1609. $id = isset($this->post['id']) && $this->post['id'] !== "" ? trim($this->post['id']) : "";
  1610. if ($id == "") {
  1611. return error_show(1002, "参数id不能为空");
  1612. }
  1613. $etid = Db::name("sale")->where(["id" => $id, "is_del" => 0])->find();
  1614. if (empty($etid)) {
  1615. return error_show(1002, "未找到数据");
  1616. }
  1617. // $orderCode=isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
  1618. // if($orderCode==""){
  1619. // return error_show(1002,"销售单code不能为空");
  1620. // }
  1621. $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
  1622. if ($good_code == "") {
  1623. return error_show(1002, "商品code不能为空");
  1624. }
  1625. $ct = Db::name('good')->alias('a')->join('good_type b', 'b.good_code=a.good_code', 'left')
  1626. ->where(['b.type_code' => $good_code])->find();
  1627. if ($ct == "") {
  1628. return error_show(1002, "未找到商品数据");
  1629. }
  1630. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] !== "" ? trim($this->post['customer_code']) : "";
  1631. if ($customer_code == "") {
  1632. return error_show(1002, "客户code不能为空");
  1633. }
  1634. $customer = Db::name("customer_info")->where(["companyNo" => $customer_code])->find();
  1635. if ($customer == false) {
  1636. return error_show(1004, "未找到客户数据");
  1637. }
  1638. $supplierNo = $this->post['supplierNo'] && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  1639. if ($supplierNo == "") {
  1640. return error_show(1002, "参数supplierNo不能为空");
  1641. }
  1642. $supplier = Db::name("supplier")->where(["code" => $supplierNo])->find();
  1643. if ($supplier == false) {
  1644. return error_show(1004, "未找到平台供应商数据");
  1645. }
  1646. $apply_id = GetUserInfo($token);
  1647. if (empty($apply_id) || $apply_id['code'] != 0) {
  1648. return error_show(1002, "申请人数据不存在");
  1649. }
  1650. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1651. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1652. // $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim
  1653. //($this->post['good_name']) : "";
  1654. // $good_num = isset($this->post['good_num']) && $this->post['good_num'] !== "" ? intval
  1655. //($this->post['good_num']) : "";
  1656. // $origin_price = isset($this->post['origin_price']) && $this->post['origin_price'] !== "" ? intval
  1657. // ($this->post['origin_price']) : "";
  1658. // $sale_price = isset($this->post['sale_price']) && $this->post['sale_price'] !== "" ? trim($this->post['sale_price']) : "";
  1659. // $total_price = isset($this->post['total_price']) && $this->post['total_price'] !== "" ? trim($this->post['total_price']) : "";
  1660. // $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? trim($this->post['post_fee']) : "";
  1661. // $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1662. $vr = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
  1663. if ($vr == "") {
  1664. return error_show(1002, "参数order_addr不能为空");
  1665. }
  1666. $vi = isset($this->post['good_stock']) && $this->post['good_stock'] !== "" ? $this->post['good_stock'] : "";
  1667. if ($vi == "") {
  1668. return error_show(1002, "参数good_stock不能为空");
  1669. }
  1670. $good_num = intval(array_sum(array_column($vi, "num")));
  1671. Db::startTrans();
  1672. try {
  1673. $datn = [
  1674. "id" => $id,
  1675. "good_code" => $good_code,
  1676. "customer_code" => $customer_code,
  1677. "good_num" => $good_num,
  1678. "supplierNo" => $supplierNo,
  1679. "apply_id" => $rm,
  1680. "apply_name" => $ri,
  1681. "is_del" => 0,
  1682. "updatetime" => date("Y-m-d H:i:s")
  1683. ];
  1684. $datninfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->save($datn);
  1685. if ($datninfo > 0) {
  1686. $stn = ["order_code"=>$etid['orderCode'],"status"=>$etid['status'],"action_remark"=>'',"action_type"=>"edit"];
  1687. ActionLog::logAdd($this->post['token'],$stn,"XSQRD",$etid['status'],$datn);
  1688. $order=["order_type"=>'XSQRD',"order_code"=>$etid['orderCode'],"order_id"=>$id,"order_status"=>$etid['status']];
  1689. ProcessOrder::AddProcess($this->post['token'],$order);
  1690. foreach ($vi as $ion) {
  1691. $iten = [];
  1692. isset($ion['id']) && $ion['id'] !== "" ? $iten['id'] = $ion['id'] : '';
  1693. $iten['orderCode'] = $etid['orderCode'];
  1694. $iten['wsm_code'] = $ion['wsm_code'];
  1695. $iten['stock_id'] = 0;
  1696. $iten['num'] = $ion['num'];
  1697. $iten['status'] = 1;
  1698. $iten['sale_price'] = $ct['original_price'];
  1699. isset($ion['id']) && $ion['id'] !== "" ? '' : $iten['addtime'] = date("Y-m-d H:i:s");
  1700. $iten['updatetime'] = date("Y-m-d H:i:s");
  1701. $vp = Db::name('sale_info')->save($iten);
  1702. if ($vp == false)
  1703. {
  1704. Db::rollback();
  1705. return error_show(1002, "更新失败");
  1706. }
  1707. }
  1708. foreach ($vr as $value) {
  1709. $temp = [];
  1710. isset($value['id']) && $value['id'] !== "" ? $temp['id'] = $value['id'] : '';
  1711. $temp['orderCode'] = $etid['orderCode'];
  1712. $temp['contactor'] = $value['contactor'];
  1713. $temp['mobile'] = $value['mobile'];
  1714. $temp['addr'] = $value['addr'];
  1715. $temp['addr_code'] = $value['addr_code'];
  1716. $temp['customer_code'] = $customer_code;
  1717. $temp['receipt_quantity'] = $value['receipt_quantity'];
  1718. $temp['post_fee'] = 0;
  1719. $temp['is_del'] = $value['is_del'];
  1720. isset($value['id']) && $value['id'] !== "" ? '' : $temp['addtime'] = date("Y-m-d H:i:s");
  1721. $temp['updatetime'] = date("Y-m-d H:i:s");
  1722. $temp['arrive_time'] = date("Y-m-d H:i:s");
  1723. $dat = Db::name('order_addr')->save($temp);
  1724. if ($dat == false) {
  1725. Db::rollback();
  1726. return error_show(1002, "更新失败");
  1727. }
  1728. }
  1729. Db::commit();
  1730. return error_show(0, "更新成功");
  1731. }
  1732. Db::rollback();
  1733. return error_show(1002, "更新失败");
  1734. } catch (Exception $e) {
  1735. Db::rollback();
  1736. return error_show(1005, $e->getMessage());
  1737. }
  1738. }
  1739. public function info()
  1740. {
  1741. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  1742. if ($id == "") {
  1743. return error_show(1002, "参数id不能为空");
  1744. }
  1745. $einfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
  1746. if (empty($einfo)) {
  1747. return error_show(1002, "未找到销售订单数据");
  1748. }
  1749. if($einfo['order_type']==3|| $einfo['order_type']==4){
  1750. $goon = Db::name("good_zixun")->where(["spuCode"=>$einfo['good_code'],"is_del"=>0])->find();
  1751. }else {
  1752. $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  1753. ->where(['a.skuCode' => $einfo['skuCode']])->find();
  1754. }
  1755. if ($goon==false) {
  1756. return error_show(1003, "未找到商品数据");
  1757. }else{
  1758. $goon['exclusive']=isset($goon['is_exclusive'])?makeExcluse($goon['is_exclusive']):"";
  1759. $unit =Db::name("unit")->where(["id"=>$goon['good_unit']])->find();
  1760. $goon['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1761. $spec = Db::name("good_spec")->where(["spuCode"=>$goon['spuCode'],"is_del"=>0])->select()->toArray();
  1762. $speclist=[];
  1763. if(!empty($spec)){
  1764. foreach ($spec as $value){
  1765. $temp=[];
  1766. $temp['id']=$value['id'];
  1767. $temp['spuCode']=$value['spuCode'];
  1768. $temp['spec_id']=$value['spec_id'];
  1769. $temp['spec_value_id']=$value['spec_value_id'];
  1770. $temp['is_del']=$value['is_del'];
  1771. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  1772. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  1773. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  1774. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  1775. $speclist[]=$temp;
  1776. }
  1777. }
  1778. $goon["speclist"]=empty($speclist)?[]:$speclist;
  1779. $proof =Db::name("good_proof")->where(["spuCode"=>$goon['spuCode'],"is_del"=>0])->order("updatetime desc")->field("id,proof_type,proof_url")->find();
  1780. $goon['proof'] = isset($proof)&&$proof!=false? $proof:[];
  1781. $goon['origin_place_cn']="";
  1782. $goon['delivery_place_cn']="";
  1783. if(isset($goon['delivery_place'])&&$goon['delivery_place']!==""){
  1784. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1785. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$goon['delivery_place']);
  1786. $goon['delivery_place_cn']=GetAddr(json_encode($place));
  1787. }
  1788. if(isset($goon['delivery_place'])&&$goon['origin_place']!==""){
  1789. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1790. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$goon['origin_place']);
  1791. $goon['origin_place_cn']=GetAddr(json_encode($place));
  1792. }
  1793. if($goon['brand_id']!=0){
  1794. $brand=Db::name("brand")->where(["id"=>$goon['brand_id']])->find();
  1795. $goon["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1796. }else{
  1797. $goon["brand_name"]="";
  1798. $goon["brand_id"]="";
  1799. }
  1800. $supplier = Db::name("supplier")->where(["code"=>$goon['supplierNo']])->find();
  1801. $goon['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1802. $goon['noble_name']=isset($goon['noble_metal'])&&$goon['noble_metal']!=0?$this->noble[$goon['noble_metal']] :"";
  1803. if(isset($goon['companyNo'])&&$goon['companyNo']!=""){
  1804. $company = Db::name("business")->where(["companyNo"=>$goon['companyNo']])->find();
  1805. }
  1806. $goon['company'] = isset($company['company'])?$company['company']:"";
  1807. }
  1808. $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  1809. $in = Db::name('customer_info')->where(['companyNo' => $einfo['customer_code']])->field('companyName')->find();
  1810. $einfo['supplierName'] = '';
  1811. if ($einfo['supplierNo'] != "") {
  1812. $supplier = Db::name("business")->where(["companyNo" => $einfo['supplierNo']])->find();
  1813. $einfo['supplierName'] = isset($supplier['company']) ? $supplier['company'] : "";
  1814. }
  1815. $fo = Db::name('order_addr')->alias("a")->leftJoin("order_out b","a.id=b.addrid")
  1816. ->where(['a.orderCode' => $einfo['orderCode'], 'a.is_del' => 0])->field("a.*,b.post_name,b.post_code,
  1817. 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")
  1818. ->select();
  1819. $addrs = [];
  1820. if (!empty($fo)) {
  1821. foreach ($fo as $value) {
  1822. $value['addr_info'] = "";
  1823. $value['send_num'] = 0;
  1824. if ($value['addr_code'] != "") {
  1825. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1826. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['addr_code']);
  1827. $addr = GetAddr(json_encode($place));
  1828. $value['addr_info'] = $addr;
  1829. }
  1830. $value['wsm_name']="";
  1831. if(isset($value['wsm_code'])&&$value['wsm_code']!=""){
  1832. $wsmcode = Db::name("warehouse_info")->where(["wsm_code" => $value['wsm_code']])->find();
  1833. $value['wsm_name'] =isset($wsmcode['name'])?$wsmcode['name']:"";
  1834. }
  1835. $addrs[] = $value;
  1836. }
  1837. }
  1838. $einfo['useage']="";
  1839. if($einfo['use_order']!=0){
  1840. $use =Db::name("order_use")->where(["id"=>$einfo['use_order']])->find();
  1841. $einfo['useage'] = isset($use['order_use']) ?$use['order_use']:"";
  1842. }else{
  1843. $einfo['use_order']='';
  1844. }
  1845. $einfo['platform_name']='';
  1846. if($einfo['platform_id']!=0){
  1847. $plat=Db::name("platform")->where(['id'=>$einfo['platform_id']])->find();
  1848. $einfo['platform_name']=isset($plat['platform_name'])?$plat['platform_name']:"";
  1849. }
  1850. $einfo['companyName'] = isset($in['companyName']) ? $in['companyName'] : "";
  1851. $einfo['addrs'] = $addrs;
  1852. $einfo['can'] = $int;
  1853. $einfo['goodinfo'] = $goon;
  1854. if (empty($einfo)) {
  1855. return error_show(1002, "未找到销售订单数据");
  1856. } else {
  1857. return app_show(0, "获取成功", $einfo);
  1858. }
  1859. }
  1860. public function del()
  1861. {
  1862. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  1863. if ($id === "") {
  1864. return error_show(1002, "参数id不能为空");
  1865. }
  1866. $ed = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
  1867. if (empty($ed)) {
  1868. return error_show(1002, "未找到销售订单数据");
  1869. }
  1870. $str = Db::name('sale')->update(['id' => $id, 'is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")]);
  1871. if ($str) {
  1872. $stc = ["order_code"=>$id,"status"=>$ed['status'],"action_remark"=>'',"action_type"=>"delete"];
  1873. ActionLog::logAdd($this->post['token'],$stc,"XSQRD",$ed['status'],['id' => $id, 'is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")]);
  1874. $order=["order_type"=>'XSQRD',"order_code"=>$ed['orderCode'],"order_id"=>$id,"order_status"=>$ed['status']];
  1875. ProcessOrder::workdel($order);
  1876. return error_show(0, "删除成功");
  1877. } else {
  1878. return error_show(1002, "删除失败");
  1879. }
  1880. }
  1881. public function status()
  1882. {
  1883. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  1884. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  1885. if ($id == "") {
  1886. return error_show(1002, "参数id不能为空");
  1887. }
  1888. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1889. if ($status == "") {
  1890. return error_show(1002, "订单状态不能为空");
  1891. }
  1892. $dio = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
  1893. if (empty($dio)) {
  1894. return error_show(1002, "销售单信息未找到");
  1895. }
  1896. if ($status == 1 && $dio['order_type'] == 2) {
  1897. $zxinfo = Db::name("consult")->where(["zxNo" => $dio['zxNo'], "is_del" => 0])->find();
  1898. if ($zxinfo == false) {
  1899. return error_show(1004, "未找到咨询单数据");
  1900. }
  1901. $gold['price'] = 0;
  1902. if ($zxinfo['zx_type'] == 2) {
  1903. if ($zxinfo['metals'] == "") {
  1904. return error_show(1004, "未找到咨询单贵金属类型数据");
  1905. }
  1906. $metals = $zxinfo['metals'] == '18K' ? 1 : ($zxinfo['metals'] == '24K' ? 2 : 3);
  1907. $gold = Db::name("gold_price")->where(["type" => $metals])->order("addtime desc")->find();
  1908. if (empty($gold)) {
  1909. return error_show(1004, "未找到咨询单贵金属类型数据");
  1910. }
  1911. $dio['gold_price'] = $gold['price'];
  1912. }
  1913. $wsm = Db::name("warehouse_info")->where(["supplierNo" => $zxinfo['gysNo'], "wsm_type" => 2])->find();
  1914. if (empty($wsm)) {
  1915. return error_show(1002, "供应商仓库未找到");
  1916. }
  1917. }
  1918. $apply_id = GetUserInfo($token);
  1919. if (empty($apply_id) || $apply_id['code'] != 0) {
  1920. return error_show(1002, "申请人数据不存在");
  1921. }
  1922. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1923. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1924. Db::startTrans();
  1925. try {
  1926. $vmp =$dio['status'];
  1927. $dio['status'] = $status;
  1928. $dio['updatetime'] = date("Y-m-d H:i:s");
  1929. $st = Db::name('sale')->save($dio);
  1930. if ($st) {
  1931. $stn = ["order_code"=>$dio['orderCode'],"status"=>$vmp,"action_remark"=>'',"action_type"=>"status"];
  1932. ActionLog::logAdd($this->post['token'],$stn, $dio['order_type'] == 2?"ZXQRD":"XSQRD",$dio['status'],$dio);
  1933. $order=["order_type"=>$dio['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$dio['orderCode'],"order_id"=>$id,"order_status"=>$dio['status']];
  1934. ProcessOrder::AddProcess($this->post['token'],$order);
  1935. if ($status == 3 && $dio['order_type'] == 1) {
  1936. $dn = Db::name('sale_info')->where(['orderCode' => $st['orderCode']])->select();
  1937. foreach ($dn as $value) {
  1938. $dm = Db::name('good_stock')->where(['wsm_code' => $value['wsm_code'], 'good_type_code' => $st['good_code']])->find();
  1939. if ($dm == "") {
  1940. Db::rollback();
  1941. return error_show(1003, "未找到商品数据");
  1942. }
  1943. if ($value['num'] > $dm['usable_stock']) {
  1944. Db::rollback();
  1945. return error_show(1002, "超出库存数量");
  1946. }
  1947. $dm['usable_stock'] -= $value['num'];
  1948. $dm['wait_out_stock'] += $value['num'];
  1949. $send = Db::name("order_out")->where(["wsm_code" => $value['wsm_code']])->sum("send_num");
  1950. $value['send_num'] = $send ?? 0;
  1951. $value['wsend_num'] = $value['num'] - $value['send_num'];
  1952. $Db = Db::name('good_stock')->update($dm);
  1953. $Db['updatetime'] = date('Y-m-d H:i:s');
  1954. if ($Db == false) {
  1955. Db::rollback();
  1956. return error_show(1002, "状态更新失败");
  1957. }
  1958. }
  1959. }
  1960. if ($status == 1 && $dio['order_type'] == 2) {
  1961. $cgd = makeNo("CG");
  1962. $clll = [
  1963. "cgdNo" => $cgd,
  1964. "bkcode" => $dio['orderCode'],
  1965. "wsm_code" => $wsm['wsm_code'],
  1966. "cgder_id" => Db::name('depart_user')->where('nickname',$zxinfo['saler'])->value('uid')??0,//重名以及多个账号的话…………
  1967. "cgder" => $zxinfo['saler'],
  1968. "good_code" => "GD-" . $zxinfo['cpNo'],
  1969. "good_name" => $zxinfo['cpName'],
  1970. "good_type_code" => $zxinfo['cpNo'],
  1971. "good_num" => $dio['good_num'],
  1972. "good_price" => $zxinfo['total_fee'],
  1973. "total_fee" => round($zxinfo['total_fee'] * $dio['good_num'], 2),
  1974. "pakge_fee" => $zxinfo['package_fee'],
  1975. "cert_fee" => $zxinfo['cert_fee'],
  1976. "open_fee" => $zxinfo['open_fee'],
  1977. "delivery_fee" => $zxinfo['delivery_fee'],
  1978. "mark_fee" => $zxinfo['mark_fee'],
  1979. "teach_fee" => $zxinfo['cost_fee'],
  1980. "demo_fee" => $zxinfo['demo_fee'],
  1981. "nake_fee" => $zxinfo['bare_fee'],
  1982. "weight" => isset($zxinfo['weight']) ? $zxinfo['weight'] : 0,
  1983. "supplierNo" => $zxinfo['gysNo'],
  1984. "supplier_name" => $zxinfo['gysname'],
  1985. "gold_price" => $gold['price'],
  1986. "send_num" => 0,
  1987. "wsend_num" => $dio['good_num'],
  1988. "remark" => '',
  1989. "lasttime" => date("Y-m-d H:i:s"),
  1990. "is_del" => 0,
  1991. "status" => $dio['send_type'] == 1 ? 3 : 0,
  1992. "order_type" => 2,
  1993. "addtime" => date("Y-m-d H:i:s"),
  1994. "updatetime" => date("Y-m-d H:i:s")
  1995. ];
  1996. $cgin = Db::name("purchease_order")->insert($clll);
  1997. // var_dump(Db::name("purchease_order")->getLastSql(),$clll);
  1998. if ($cgin == false) {
  1999. $stb = ["order_code"=>$cgd,"status"=> $clll['status'],"action_remark"=>'',"action_type"=>"create"];
  2000. ActionLog::logAdd($this->post['token'],$stb,"xsd", $clll['status'],$stb);
  2001. Db::rollback();
  2002. return error_show(1002, "咨询采购单创建商品失败");
  2003. }
  2004. if ($dio['send_type'] == 1) {
  2005. $addr = Db::name('order_addr')->where(["orderCode" => $dio['orderCode'], 'is_del' => 0])->select();
  2006. foreach ($addr as $value) {
  2007. $outCode = makeNo("DF");
  2008. $data = [
  2009. "wsm_code" => $wsm['wsm_code'],
  2010. "orderCode" => $dio['orderCode'],
  2011. "outCode" => $outCode,
  2012. "order_type" => $dio['order_type'],
  2013. "apply_id" => $rm,
  2014. "apply_name" => $ri,
  2015. "addrid" => $value['id'],
  2016. "post_name" => '',
  2017. "post_code" => '',
  2018. "post_fee" => '',
  2019. "sendtime" => date("Y-m-d H:i:s"),
  2020. "send_num" => $value['receipt_quantity'],
  2021. "check_num" => 0,
  2022. "error_num" => 0,
  2023. "status" => 0,
  2024. "addtime" => date("Y-m-d H:i:s"),
  2025. "updatetime" => date("Y-m-d H:i:s")
  2026. ];
  2027. $datainfo = Db::name('order_out')->insert($data);
  2028. if (!$datainfo) {
  2029. $sti = ["order_code"=>$dio['orderCode'],"status"=> 0,"action_remark"=>'',"action_type"=>"create"];
  2030. ActionLog::logAdd($this->post['token'],$sti,"xsd",0,$sti);
  2031. Db::rollback();
  2032. return error_show(1003, "创建失败");
  2033. }else{
  2034. //修改状态,添加待办
  2035. ActionLog::logAdd($this->post['token'], [
  2036. "order_code" => $outCode,//出库单号
  2037. "status" => 0,//这里的status是之前的值
  2038. "action_remark" => '',//备注
  2039. "action_type" => "create"//新建create,编辑edit,更改状态status
  2040. ], "CKD", 0, $data);
  2041. ProcessOrder::AddProcess($this->post['token'], [
  2042. "order_type" => 'CKD',
  2043. "order_code" => $outCode,//出库单号
  2044. "order_id" => 0,
  2045. "order_status" => 0
  2046. ]);
  2047. }
  2048. }
  2049. $wsm_in_code = makeNo("CF");
  2050. $orin = [
  2051. "wsm_in_code" => $wsm_in_code,
  2052. "cgdNo" => $cgd,
  2053. "wsm_code" => $wsm['wsm_code'],
  2054. "wsm_reaper" => "",
  2055. "send_num" => $dio['good_num'],
  2056. "post_company" => '',
  2057. "post_code" => '',
  2058. "post_fee" => '',
  2059. "sendtime" => date("Y-m-d H:i:s"),
  2060. "apply_id" => $rm,
  2061. "apply_name" => $ri,
  2062. "wait_num" => 0,
  2063. "status" => 4,
  2064. "addtime" => date("Y-m-d H:i:s"),
  2065. "updatetime" => date("Y-m-d H:i:s")
  2066. ];
  2067. $win = Db::name("purchease_in")->insert($orin);
  2068. if (!$win){
  2069. $stv = ["order_code"=>$wsm_in_code,"status"=>4,"action_remark"=>'',"action_type"=>"create"];
  2070. ActionLog::logAdd($this->post['token'],$stv,"xsd",4,$stv);
  2071. Db::rollback();
  2072. return error_show(1003, "创建失败");
  2073. }
  2074. $good = Db::name("good_stock")->where(["wsm_code" => $wsm['wsm_code'], "good_type_code" => $zxinfo['cpNo'], "is_del" => 0])->find();
  2075. if (empty($good)) {
  2076. $good = [
  2077. "good_type_code" => $zxinfo['cpNo'],
  2078. "wsm_code" => $wsm['wsm_code'],
  2079. "usable_stock" => 0,
  2080. "wait_out_stock" => 0,
  2081. "total_stock" => 0,
  2082. "addtime" => date("Y-m-d H:i:s"),
  2083. "updatetime" => date("Y-m-d H:i:s"),
  2084. ];
  2085. }
  2086. $good['wait_out_stock'] += $dio['good_num'];
  2087. $good['total_stock'] = $good['usable_stock'] + $good['wait_out_stock'];
  2088. $good['updatetime'] = date("Y-m-d H:i:s");
  2089. $upd = Db::name("good_stock")->save($good);
  2090. if (!$upd) {
  2091. $ste = ["order_code"=> $zxinfo['cpNo'],"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  2092. ActionLog::logAdd($this->post['token'],$ste,"xsd",0,$ste);
  2093. Db::rollback();
  2094. return error_show(1003, "创建失败");
  2095. }
  2096. }
  2097. }
  2098. }
  2099. Db::commit();
  2100. return error_show(0, "订单状态更新成功");
  2101. } catch (Exception $e) {
  2102. Db::rollback();
  2103. return error_show(1005, $e->getMessage());
  2104. }
  2105. }
  2106. public function fee()
  2107. {
  2108. $id = isset($this->post['id']) && $this->post['id'] !== "" ? trim($this->post['id']) : "";
  2109. if ($id == "") {
  2110. return error_show(1002, "参数id不能为空");
  2111. }
  2112. $etid = Db::name("sale")->where(["id" => $id, "is_del" => 0])->find();
  2113. if (empty($etid)) {
  2114. return error_show(1002, "未找到数据");
  2115. }
  2116. $vr = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
  2117. if ($vr == "") {
  2118. return error_show(1002, "参数order_addr不能为空");
  2119. }
  2120. Db::startTrans();
  2121. try {
  2122. $data = [
  2123. "id" => $id,
  2124. "status" => 2,
  2125. "is_del" => 0,
  2126. "updatetime" => date("Y-m-d H:i:s")
  2127. ];
  2128. $datainfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->save($data);
  2129. if ($datainfo) {
  2130. $stx = ["order_code"=> $etid['orderCode'],"status"=>$etid['status'],"action_remark"=>'',
  2131. "action_type"=>"edit"];
  2132. ActionLog::logAdd($this->post['token'],$stx,$etid['order_type'] == 2?"ZXQRD":"XSQRD",2,$data);
  2133. $order=["order_type"=>$etid['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$etid['orderCode'],"order_id"=>$id,"order_status"=>$data['status']];
  2134. ProcessOrder::AddProcess($this->post['token'],$order);
  2135. foreach ($vr as $value) {
  2136. $tm = [];
  2137. $tm['id'] = $value['id'];
  2138. $tm['orderCode'] = $etid['orderCode'];
  2139. $tm['post_fee'] = $value['post_fee'];
  2140. $tm['updatetime'] = date("Y-m-d H:i:s");
  2141. $dn = Db::name('order_addr')->save($tm);
  2142. if ($dn == false) {
  2143. Db::rollback();
  2144. return error_show(1002, "更新失败");
  2145. }
  2146. }
  2147. Db::commit();
  2148. return error_show(0, "更新成功");
  2149. }
  2150. Db::rollback();
  2151. return error_show(1003, "更新失败");
  2152. } catch (Exception $e) {
  2153. Db::rollback();
  2154. return error_show(1005, $e->getMessage());
  2155. }
  2156. }
  2157. public function out()
  2158. {
  2159. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  2160. $outCode = makeNo("DF");
  2161. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  2162. if ($orderCode == "") {
  2163. return error_show(1002, "参数orderCoder不能为空");
  2164. }
  2165. $der = Db::name('sale')->where(['orderCode' => $orderCode])->find();
  2166. if ($der == "") {
  2167. return error_show(1002, "未找到出库订单单号");
  2168. }
  2169. // $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !== "" ? trim($this->post['wsm_code']) : "";
  2170. // if ($wsm_code == "") {
  2171. // return error_show(1002, "参数wsm_code不能为空");
  2172. // }
  2173. // $wsm = Db::name('sale_info')->where(['wsm_code' => $wsm_code, 'orderCode' => $der['orderCode']])->find();
  2174. // if ($wsm == "") {
  2175. // return error_show(1002, "未找到仓库编码");
  2176. // }
  2177. $post_name = isset($this->post['post_name']) && $this->post['post_name'] !== "" ? trim($this->post['post_name']) : "";
  2178. if ($post_name == "") {
  2179. return error_show(1002, "物流公司不能为空");
  2180. }
  2181. $post_code = isset($this->post['post_code']) && $this->post['post_code'] !== "" ? trim($this->post['post_code']) : "";
  2182. if ($post_code == "") {
  2183. return error_show(1002, "物流单号不能为空");
  2184. }
  2185. $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? intval($this->post['post_fee']) : "";
  2186. if ($post_fee == "") {
  2187. return error_show(1002, "物流费不能为空");
  2188. }
  2189. $send_num = isset($this->post['send_num']) && $this->post['send_num'] !== "" ? $this->post['send_num'] : "";
  2190. if ($send_num == "") {
  2191. return error_show(1002, "发货数量不能为空");
  2192. }
  2193. if ($send_num > $der['wsend_num']) {
  2194. return error_show(1002, "超出可发货数量");
  2195. }
  2196. $apply_id = GetUserInfo($token);
  2197. if (empty($apply_id) || $apply_id['code'] != 0) {
  2198. return error_show(1002, "申请人数据不存在");
  2199. }
  2200. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  2201. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  2202. $addrid = isset($this->post['addrid']) && $this->post['addrid'] !== "" ? intval($this->post['addrid']) : "";
  2203. $dr = Db::name('order_addr')->where(['id' => $addrid, 'is_del' => 0])->find();
  2204. if (empty($dr)) {
  2205. return error_show(1003, "收货人信息未找到");
  2206. }
  2207. if ($dr['orderCode'] !== $orderCode) {
  2208. return error_show(1002, "订单code不存在");
  2209. }
  2210. $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !== "" ? $this->post['sendtime'] : date("Y-m-d H:i:s");
  2211. // $check_num = isset($this->post['check_num']) && $this->post['check_num'] !=="" ? $this->post['check_num'] :"";
  2212. // $error_num = isset($this->post['error_num']) && $this->post['error_num'] !=="" ? $this->post['error_num'] :"";
  2213. $status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] : "1";
  2214. //$order_type = isset($this->post['order_type']) && $this->post['order_type'] !=="" ? $this->post['order_type'] :"1";
  2215. //$dn=Db::name('sale_info')->where(['wsm_code'=>$outCode])->find();
  2216. Db::startTrans();
  2217. try {
  2218. $data = [
  2219. "wsm_code" => "",
  2220. "orderCode" => $orderCode,
  2221. "outCode" => $outCode,
  2222. "order_type" => $der['order_type'],
  2223. "apply_id" => $rm,
  2224. "apply_name" => $ri,
  2225. "addrid" => $dr['id'],
  2226. "post_name" => $post_name,
  2227. "post_code" => $post_code,
  2228. "post_fee" => $post_fee,
  2229. "sendtime" => $sendtime,
  2230. "send_num" => $send_num,
  2231. "check_num" => 0,
  2232. "error_num" => 0,
  2233. "status" => $status,
  2234. "addtime" => date("Y-m-d H:i:s"),
  2235. "updatetime" => date("Y-m-d H:i:s")
  2236. ];
  2237. $datainfo = Db::name('order_out')->insert($data,true);
  2238. if ($datainfo>0) {
  2239. $stx = ["order_code"=>$outCode,"status"=>$status,"action_remark"=>'',"action_type"=>"create"];
  2240. ActionLog::logAdd($this->post['token'],$stx,$der['order_type']==1?"CKD":'ZXCKD',$status,$data);
  2241. $order=["order_type"=>$der['order_type']==1?"CKD":'ZXCKD',"order_code"=>$outCode,"order_id"=>$datainfo,"order_status"=>$data['status']];
  2242. ProcessOrder::AddProcess($this->post['token'],$order);
  2243. if ($status == 1) {
  2244. $item =$der['status'];
  2245. $der['send_num'] += $send_num;
  2246. $der['wsend_num'] -= $send_num;//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
  2247. $der['send_status'] = $der['send_num'] == 0 ? 1 : $der['wsend_num'] == 0 ? 3 : 2;
  2248. $der['status'] = $der['send_num'] == 0 ? 3 : $der['wsend_num'] == 0 ? 5 : 4;
  2249. $der['updatetime'] = date("Y-m-d H:i:s");
  2250. $si = Db::name('sale')->save($der);
  2251. if ($si == false) {
  2252. Db::rollback();
  2253. return error_show(1003, "更新失败");
  2254. }
  2255. $stx = ["order_code"=>$orderCode,"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
  2256. ActionLog::logAdd($this->post['token'],$stx,$der['order_type'] == 2?"ZXQRD":"XSQRD",$der['status'],$der);
  2257. $order=["order_type"=>$der['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$orderCode,"order_id"=>$der['id'],"order_status"=>$data['status']];
  2258. ProcessOrder::AddProcess($this->post['token'],$order);
  2259. $str = Db::name('good_stock')->where(['wsm_code' => $var['wsm_code'], 'good_type_code' => $der['good_code']])->find();
  2260. if ($str == false) {
  2261. Db::rollback();
  2262. return error_show(1002, "商品数据未找到");
  2263. }
  2264. if ($send_num > $str['wait_out_stock']) {
  2265. Db::rollback();
  2266. return error_show(1002, "超出库存数量");
  2267. }
  2268. $str['wait_out_stock'] -= $send_num;
  2269. $str['intra_stock'] += $send_num;
  2270. $str['updatetime'] = date("Y-m-d H:i:s");
  2271. $stre = Db::name('good_stock')->save($str);
  2272. if ($stre == false) {
  2273. Db::rollback();
  2274. return error_show(1002, "状态更新失败");
  2275. }
  2276. //商品变动日志表,good_log_code字段存储采购单号
  2277. $good_data[] = ['good_log_code' => $outCode, "stock_id" => $str['id'], "type" => 2, 'stock' => $send_num, "stock_name" => "wait_out_stock"];
  2278. $good_data[] = ['good_log_code' => $outCode, "stock_id" => $str['id'], "type" => 1, 'stock' => $send_num, "stock_name" => "intra_stock"];
  2279. GoodLog::LogAdd($this->post['token'],$good_data,$der['order_type'] != 1?"ZXQRD":"XSQRD");
  2280. }
  2281. Db::commit();
  2282. return error_show(0, "创建成功");
  2283. } else {
  2284. Db::rollback();
  2285. return error_show(1003, "创建失败");
  2286. }
  2287. } catch (Exception $e) {
  2288. Db::rollback();
  2289. return error_show(1005, $e->getMessage());
  2290. }
  2291. }
  2292. public function customer()
  2293. {
  2294. $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
  2295. if (empty($outCode)) {
  2296. return error_show(1002, "销售订单编号不能为空");
  2297. }
  2298. $codeinfo = Db::name('order_out')->where(['outCode' => $outCode])->find();
  2299. if ($codeinfo == "") {
  2300. return error_show(1003, "未找到订单数据");
  2301. }
  2302. // $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
  2303. // if($orderCode==""){
  2304. // return error_show(1002,"参数orderCoder不能为空");
  2305. // }
  2306. $dr = Db::name('sale')->where(['orderCode' => $codeinfo['orderCode']])->find();
  2307. if ($dr == "") {
  2308. return error_show(1002, "未找到销售订单");
  2309. }
  2310. $status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] : "";
  2311. if ($status == "") {
  2312. return error_show(10002, "状态不能为空");
  2313. }
  2314. Db::startTrans();
  2315. try {
  2316. $time = $codeinfo['status'];
  2317. $codeinfo['status'] = $status;
  2318. $codeinfo['updatetime'] = date("Y-m-d H:i:s");
  2319. $cust = Db::name('order_out')->save($codeinfo);
  2320. if ($cust) {
  2321. $stx = ["order_code"=>$outCode,"status"=>$time,"action_remark"=>'',"action_type"=>"status"];
  2322. ActionLog::logAdd($this->post['token'],$stx,$codeinfo['order_type'] == 2?"ZXCKD":"CKD",$codeinfo['status'],$codeinfo);
  2323. $order=["order_type"=>$codeinfo['order_type'] == 2?"ZXCKD":"CKD","order_code"=>$outCode,
  2324. "order_id"=>$codeinfo['id'],"order_status"=>$codeinfo['status']];
  2325. ProcessOrder::AddProcess($this->post['token'],$order);
  2326. if ($status == 1) {
  2327. $stokc =Db::name("good_stock")->where(['spuCode'=>$codeinfo['spuCode'],"wsm_code"=>$codeinfo['wsm_code'],
  2328. "is_del"=>0])->find();
  2329. if($stokc==false){
  2330. Db::rollback();
  2331. return error_show(1002, "未找库存到数据");
  2332. }else{
  2333. if ($codeinfo['send_num'] > $stokc['usable_stock']) {
  2334. Db::rollback();
  2335. return error_show(1002, "超出库存数量");
  2336. }
  2337. $stokc['wait_out_stock']+=$codeinfo['send_num'];
  2338. $stokc['usable_stock']-=$codeinfo['send_num'];
  2339. $stokc['updatetime']=date("Y-m-d H:i:s");
  2340. }
  2341. $stoc= Db::name("good_stock")->save($stokc);
  2342. if($stoc==false){
  2343. Db::rollback();
  2344. return error_show(1002, "库存更新失败");
  2345. }
  2346. $item =$dr['status'];
  2347. $dr['send_num'] +=$codeinfo['send_num'];
  2348. $dr['wsend_num'] -= $codeinfo['send_num'];//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
  2349. $dr['send_status'] = $dr['send_num'] == 0 ? 1 : $dr['wsend_num'] == 0 ? 3 : 2;
  2350. $dr['status'] = $dr['send_num'] == 0 ? 3 : $dr['wsend_num'] == 0 ? 5 : 4;
  2351. $dr['updatetime'] = date("Y-m-d H:i:s");
  2352. $si = Db::name('sale')->save($dr);
  2353. if ($si == false) {
  2354. Db::rollback();
  2355. return error_show(1003, "更新失败");
  2356. }
  2357. $stx = ["order_code"=>$dr['orderCode'],"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
  2358. ActionLog::logAdd($this->post['token'],$stx,$dr['order_type'] == 2?"ZXQRD":"XSQRD",$dr['status'],
  2359. $dr);
  2360. $order=["order_type"=>$dr['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$dr['orderCode'],"order_id"=>$dr['id'],"order_status"=>$dr['status']];
  2361. ProcessOrder::AddProcess($this->post['token'],$order);
  2362. //商品变动日志表,good_log_code字段存储销售订单编号
  2363. $good_data[] = ['good_log_code' => $outCode, "stock_id" => $stoc['id'], "type" => 1, 'stock' => $codeinfo['send_num'], "stock_name" => "wait_out_stock"];
  2364. $good_data[] = ['good_log_code' => $outCode, "stock_id" => $stoc['id'], "type" => 2, 'stock' => $codeinfo['send_num'], "stock_name" => "usable_stock"];
  2365. GoodLog::LogAdd($this->post['token'],$good_data,'CKD');
  2366. }
  2367. if ($status == 3) {
  2368. $var = Db::name('good_stock')->where(['wsm_code' => $codeinfo['wsm_code'], 'good_type_code' => $dr['good_code']])->find();
  2369. if ($var == false) {
  2370. Db::rollback();
  2371. return error_show(1002, "未找到商品数据");
  2372. }
  2373. if ($codeinfo['send_num'] > $var['intra_stock']) {
  2374. Db::rollback();
  2375. return error_show(1003, "超出在途库存数量");
  2376. }
  2377. $var['intra_stock'] -= $codeinfo['send_num'];
  2378. $var['updatetime'] = date("Y-m-d H:i:s");
  2379. $stre = Db::name('good_stock')->save($var);
  2380. //商品变动日志表,good_log_code字段存储销售订单编号
  2381. $good_data[] = ['good_log_code' => $outCode, "stock_id" => $var['id'], "type" => 2, 'stock' => $codeinfo['send_num'], "stock_name" => "intra_stock"];
  2382. GoodLog::LogAdd($this->post['token'],$good_data,$codeinfo['order_type'] == 2?"ZXCKD":"CKD");
  2383. if ($stre == false) {
  2384. Db::rollback();
  2385. return error_show(1002, "状态更新失败");
  2386. }
  2387. }
  2388. Db::commit();
  2389. return error_show(0, "出库订单更新成功");
  2390. } else {
  2391. Db::rollback();
  2392. return error_show(1003, "出库订单更新失败");
  2393. }
  2394. } catch (Exception $e) {
  2395. Db::rollback();
  2396. return error_show(1005, $e->getMessage());
  2397. }
  2398. }
  2399. public function difflist()
  2400. {
  2401. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  2402. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  2403. $where = [];
  2404. $cgdNo = isset($this->post['orderCode']) && $this->post['orderCode'] != "" ? trim($this->post['orderCode']) : "";
  2405. if ($cgdNo != "") {
  2406. $where[] = ['a.orderCode', "like", "%$cgdNo%"];
  2407. }
  2408. $diffNo = isset($this->post['diffCode']) && $this->post['diffCode'] != "" ? trim($this->post['diffCode']) : "";
  2409. if ($diffNo != "") {
  2410. $where[] = ['a.diffCode', "like", "%$diffNo%"];
  2411. }
  2412. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  2413. if ($status !== "") {
  2414. $where[] = ['a.status', "=", $status];
  2415. }
  2416. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  2417. if ($start != "") {
  2418. $where[] = ["a.addtime", '>=', $start];
  2419. }
  2420. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  2421. if ($end != "") {
  2422. $where[] = ["a.addtime", '<=', $end];
  2423. }
  2424. // $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !==""? intval($this->post['apply_name']):"";
  2425. // if($apply_name!==""){
  2426. // $where[]=['a.apply_name',"like","%$apply_name%"];
  2427. // }
  2428. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  2429. if ($supplierNo != "") {
  2430. // $supplier = Db::name("business")->where([['code', "like", "%$supplierNo%"]])->column('code');
  2431. //// if(empty($supplier)){
  2432. //// return error_show(1004,"未找到供应商信息");
  2433. //// }
  2434. // $wsmcode = Db::name("sale")->where(["is_del" => 0, "supplierNo" => $supplier])->column("orderCode");
  2435. $where[] = ['c.supplierNo', "like", "%$supplierNo%"];
  2436. }
  2437. $companyNo =isset($this->post['companyNo']) &&$this->post['companyNo'] !=="" ? trim($this->post['companyNo']):"";
  2438. if($companyNo!=""){
  2439. $where[]=['c.customer_code',"like","%$companyNo%"];
  2440. }
  2441. $count = Db::name('sale_diff')->alias('a')
  2442. ->join("sale c", "c.orderCode=a.orderCode", "left")
  2443. ->join("customer_info v", "v.companyNo=c.customer_code", "left")
  2444. ->where($where)->count();
  2445. $total = ceil($count / $size);
  2446. $page = $page >= $total ? intval($total) : $page;
  2447. $list = Db::name('sale_diff')->alias('a')
  2448. ->join("sale c", "c.orderCode=a.orderCode", "left")
  2449. ->join("customer_info v", "v.companyNo=c.customer_code", "left")
  2450. ->where($where)->page($page, $size)->field("a.*,c.customer_code,v.companyName,c.skuCode,c.order_type,c.supplierNo")
  2451. ->order("a.addtime desc")->select();
  2452. $data = [];
  2453. foreach ($list as $value) {
  2454. if($value['order_type']==3|| $value['order_type']==4){
  2455. $goon = Db::name("good_zixun")->where(["spuCode"=>$value['good_code'],"is_del"=>0])->find();
  2456. }else {
  2457. $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  2458. ->where(['a.skuCode' => $value['skuCode']])->find();
  2459. }
  2460. $value['can'] = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  2461. $wsm = Db::name("business")->where(['companyNo' => $value['supplierNo']])->find();
  2462. $value['supplierNo'] = isset($wsm['companyNo']) ? $wsm['companyNo'] : "";
  2463. $value['supplierName'] = isset($wsm['company']) ? $wsm['company'] : "";
  2464. $data[] = $value;
  2465. }
  2466. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  2467. }
  2468. /**
  2469. * @return \think\response\Json|void
  2470. * @throws \think\db\exception\DataNotFoundException
  2471. * @throws \think\db\exception\DbException
  2472. * @throws \think\db\exception\ModelNotFoundException
  2473. */
  2474. public function diffcheck()
  2475. {
  2476. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  2477. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  2478. if ($id === "") {
  2479. return error_show(1004, "参数id不能为空");
  2480. }
  2481. $info = Db::name("sale_diff")->where(["id" => $id])->find();
  2482. if (empty($info)) {
  2483. return error_show(1004, "订单数据未找到");
  2484. }
  2485. $is_act = isset($this->post['is_act']) && $this->post['is_act'] !== "" ? intval($this->post['is_act']) : "";
  2486. if ($is_act === '') {
  2487. return error_show(1004, "参数is_act不能为空");
  2488. }
  2489. $customer_remark = isset($this->post['customer_remark']) && $this->post['customer_remark'] !== "" ? trim($this->post['customer_remark']) : "";
  2490. if ($customer_remark === '') {
  2491. return error_show(1004, "参数customer_remark不能为空");
  2492. }
  2493. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "2";
  2494. $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
  2495. $item = $info['status'];
  2496. $info['is_act'] = $is_act;
  2497. $info['customer_remark'] = $customer_remark;
  2498. $info['status'] = $status;
  2499. $info['remark'] = $remark;
  2500. $info['updatetime'] = date("Y-m-d H:i:s");
  2501. $up = Db::name("sale_diff")->save($info);
  2502. if ($up) {
  2503. $stx = ["order_code"=>$info["orderCode"],"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
  2504. ActionLog::logAdd($this->post['token'],$stx,"QRGCD",$info['status'],$info);
  2505. $order=["order_type"=>"QRGCD","order_code"=>$info["orderCode"],"order_id"=>$info['id'],"order_status"=>$info['status']];
  2506. ProcessOrder::AddProcess($this->post['token'],$order);
  2507. return app_show(0, "更新成功");
  2508. } else {
  2509. return error_show(1003, "更新失败");
  2510. }
  2511. }
  2512. /**
  2513. * @return \think\response\Json|void
  2514. * @throws \think\db\exception\DataNotFoundException
  2515. * @throws \think\db\exception\DbException
  2516. * @throws \think\db\exception\ModelNotFoundException
  2517. */
  2518. public function diffstatus()
  2519. {
  2520. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  2521. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  2522. if ($id === "") {
  2523. return error_show(1004, "参数id不能为空");
  2524. }
  2525. $info = Db::name("sale_diff")->where(["id" => $id])->find();
  2526. if ($info==false) {
  2527. return error_show(1004, "订单数据未找到");
  2528. }
  2529. $cgd = Db::name("purchease_diff")->where(['id'=>$info['cgd_diffid']])->find();
  2530. if($cgd==false){
  2531. return error_show(1004, "采购工差单数据未找到");
  2532. }
  2533. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "3";
  2534. $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
  2535. $ite=$info['status'];
  2536. Db::startTrans();
  2537. try{
  2538. $upda=[
  2539. "status"=>$status,
  2540. "remark"=>$remark,
  2541. "updatetime"=> date("Y-m-d H:i:s"),
  2542. ];
  2543. $up = Db::name("sale_diff")->where($info)->save($upda);
  2544. if ($up) {
  2545. $stx = ["order_code"=>$info["orderCode"],"status"=>$ite,"action_remark"=>'',"action_type"=>"status"];
  2546. ActionLog::logAdd($this->post['token'],$stx,"QRGCD",$info['status'],$info);
  2547. $order=["order_type"=>"QRGCD","order_code"=>$info["orderCode"],"order_id"=>$info['id'],"order_status"=>$status];
  2548. ProcessOrder::AddProcess($this->post['token'],$order);
  2549. $cgdup =Db::name("purchease_diff")->where(["id"=>$info['cgd_diffid']])->save($upda);
  2550. if($cgdup){
  2551. Db::commit();
  2552. return app_show(0, "更新成功");
  2553. }
  2554. }
  2555. Db::rollback();
  2556. return error_show(1003, "更新失败");
  2557. }catch (\Exception $e){
  2558. Db::rollback();
  2559. return error_show(1003,$e->getMessage());
  2560. }
  2561. }
  2562. /**
  2563. * @return \think\response\Json|void
  2564. * @throws \think\db\exception\DataNotFoundException
  2565. * @throws \think\db\exception\DbException
  2566. * @throws \think\db\exception\ModelNotFoundException
  2567. */
  2568. public function diffinfo()
  2569. {
  2570. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  2571. if ($id === "") {
  2572. return error_show(1004, "参数id不能为空");
  2573. }
  2574. $info = Db::name('sale_diff')->where(["id" => $id])->find();
  2575. if (empty($info)) {
  2576. return error_show(1004, "工差订单数据未找到");
  2577. }
  2578. $einfo = Db::name('sale')->where(['orderCode' => $info['orderCode'], 'is_del' => 0])->find();
  2579. if ($einfo==false) {
  2580. return error_show(1002, "未找到销售订单数据");
  2581. }
  2582. if($einfo['order_type']==3|| $einfo['order_type']==4){
  2583. $goon = Db::name("good_zixun")->where(["spuCode"=>$einfo['good_code'],"is_del"=>0])->find();
  2584. }else {
  2585. $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  2586. ->where(['a.skuCode' => $einfo['skuCode']])->find();
  2587. }
  2588. if($goon==false){
  2589. return error_show(1002, "未找到商品数据");
  2590. }
  2591. $info['skuCode'] =isset($goon['skuCode']) ? $goon['skuCode']:"";
  2592. $info['spuCode'] =isset($goon['spuCode']) ? $goon['spuCode']:"";
  2593. $info['order_type'] =isset($einfo['order_type']) ? $einfo['order_type']:"";
  2594. $info['can'] = isset($info['cat_id']) && $info['cat_id'] !== 0 ? made($info['cat_id']) : [];
  2595. return app_show(0, "获取成功", $info);
  2596. }
  2597. public function saleout(){
  2598. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  2599. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
  2600. $where= [];
  2601. $orderCode=isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode'])
  2602. :"";
  2603. if($orderCode !==""){
  2604. $where[]=['a.orderCode',"like","%$orderCode%"];
  2605. }
  2606. $order_type=isset($this->post['order_type']) && $this->post['order_type'] !=="" ? trim($this->post['order_type'])
  2607. :"";
  2608. if($order_type !==""){
  2609. $where[]=['a.order_type',"=",$order_type];
  2610. }
  2611. $outCode=isset($this->post['outCode']) && $this->post['outCode'] !=="" ? trim($this->post['outCode'])
  2612. :"";
  2613. if($outCode !==""){
  2614. $where[]=['a.outCode',"like","%$outCode%"];
  2615. }
  2616. $apply_name=isset($this->post['apply_name']) && $this->post['apply_name'] !=="" ? trim($this->post['apply_name'])
  2617. :"";
  2618. if($apply_name !==""){
  2619. $where[]=['a.apply_name',"like","%$apply_name%"];
  2620. }
  2621. $good_code=isset($this->post['good_code']) && $this->post['good_code'] !=="" ? trim($this->post['good_code'])
  2622. :"";
  2623. if($good_code !==""){
  2624. $where[]=['b.good_code',"like","%$good_code%"];
  2625. }
  2626. $good_name=isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name'])
  2627. :"";
  2628. if($good_name !==""){
  2629. $where[]=['b.good_name',"like","%$good_name%"];
  2630. }
  2631. $status=isset($this->post['status']) && $this->post['status'] !=="" ? trim($this->post['status']):"";
  2632. if($status !==""){
  2633. $where[]=['a.status',"=",$status];
  2634. }
  2635. $start = isset($this->post['start']) && $this->post['start'] !=="" ? $this->post['start'] :"";
  2636. if($start !=""){
  2637. $where[]= ["a.addtime",'>=',$start];
  2638. }
  2639. $end = isset($this->post['end']) && $this->post['end'] !=="" ? $this->post['end'] :"";
  2640. if($end !=""){
  2641. $where[]= ["a.addtime",'<=',$end];
  2642. }
  2643. $companyNo =isset($this->post['companyNo']) &&$this->post['companyNo'] !=="" ? trim($this->post['companyNo']):"";
  2644. if($companyNo!=""){
  2645. $where[]=['b.customer_code',"like","%$companyNo%"];
  2646. }
  2647. $count = Db::name('order_out')->alias('a')
  2648. ->join("sale b", "b.orderCode=a.orderCode", "left")
  2649. ->join("customer_info v", "v.companyNo=b.customer_code", "left")
  2650. //->join("good n","n.good_code=b.good_code","left")
  2651. ->where($where)->count();
  2652. $total = ceil($count / $size);
  2653. $page = $page >= $total ? $total : $page;
  2654. $list = Db::name('order_out')->alias('a')->join("sale b", "b.orderCode=a.orderCode", "left")
  2655. ->join("customer_info v", "v.companyNo=b.customer_code", "left")
  2656. //->join("good n","n.good_code=b.good_code","left")
  2657. ->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")
  2658. ->where($where)->order("addtime desc")->page($page, $size)->select();
  2659. $data=[];
  2660. foreach ($list as $value) {
  2661. $wsmcode = Db::name("warehouse_info")->alias("k")->leftJoin("supplier c", "k.supplierNo=c.code")
  2662. ->where(["k.wsm_code" => $value['wsm_code']])->field("k.name as wsm_name,c.name,c.code")->find();
  2663. $addr = Db::name("order_addr")->where(["id" => $value['addrid']])->find();
  2664. if($value['order_type']==3|| $value['order_type']==4){
  2665. $goon = Db::name("good_zixun")->where(["spuCode"=>$value['good_code'],"is_del"=>0])->find();
  2666. }else {
  2667. $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  2668. ->where(['a.skuCode' => $value['skuCode']])->find();
  2669. }
  2670. $value['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
  2671. $value['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
  2672. $value['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
  2673. $value['addr'] = isset($addr['addr']) ? $addr['addr'] : "";
  2674. $value['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
  2675. $value['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
  2676. $value['can'] = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  2677. $data[] = $value;
  2678. }
  2679. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  2680. }
  2681. public function outinfo()
  2682. {
  2683. $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
  2684. if ($outCode == "") {
  2685. return error_show(1002, "参数outcode不能为空");
  2686. }
  2687. $codeinfo = Db::name("order_out")->where(['outCode' => $outCode])->find();
  2688. if (empty($codeinfo)) {
  2689. return error_show(1002, "未找到出库数据");
  2690. }
  2691. $item = Db::name("sale")->where(['orderCode' => $codeinfo['orderCode']])->find();
  2692. if($item['order_type']==3|| $item['order_type']==4){
  2693. $goodinfo = Db::name("good_zixun")->where(["spuCode"=>$item['good_code'],"is_del"=>0])->find();
  2694. if($goodinfo==false){
  2695. return error_show(1004,"未找到商品数据");
  2696. }
  2697. }else{
  2698. $goodinfo = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  2699. ->where(['a.skuCode' =>$item['skuCode']])->find();
  2700. if ($goodinfo == false) {
  2701. return error_show(1002, "未找到商品数据");
  2702. }
  2703. }
  2704. $int = isset($goodinfo['cat_id']) && $goodinfo['cat_id'] != 0 ? made($goodinfo['cat_id']) : [];
  2705. $addr = Db::name("order_addr")->where(["id" => $codeinfo['addrid']])->find();
  2706. $codeinfo['good_name'] = isset($item['good_name']) ? $item['good_name'] : "";
  2707. $codeinfo['good_num'] = isset($item['good_num']) ? $item['good_num'] : "";
  2708. $codeinfo['good_code'] = isset($item['good_code']) ? $item['good_code'] : "";
  2709. $codeinfo['origin_price'] = isset($item['origin_price']) ? $item['origin_price'] : "";
  2710. $codeinfo['sale_price'] = isset($item['sale_price']) ? $item['sale_price'] : "";
  2711. $codeinfo['total_price'] = isset($item['total_price']) ? $item['total_price'] : "";
  2712. $codeinfo['skuCode'] = isset($item['skuCode']) ? $item['skuCode'] : "";
  2713. $codeinfo['addr'] = GetAddr($addr['addr_code']);
  2714. $codeinfo['addr'] .= isset($addr['addr']) ? $addr['addr'] : "";
  2715. $codeinfo['addr_code'] = isset($addr['addr_code']) ? $addr['addr_code'] : "";
  2716. $codeinfo['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
  2717. $codeinfo['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
  2718. $codeinfo['can'] = $int;
  2719. $orderReturn = Db::name("order_return")->where(["outCode"=>$outCode,"is_del"=>0])->order("id desc")->find();
  2720. $codeinfo['order_return'] = $orderReturn ;
  2721. return app_show(0, "获取成功", $codeinfo);
  2722. }
  2723. public function outadd(){
  2724. $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
  2725. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
  2726. if ($orderCode == "") {
  2727. return error_show(1002, "参数orderCoder不能为空");
  2728. }
  2729. $der = Db::name('sale')->where(['orderCode' => $orderCode,"is_del"=>0])->find();
  2730. if ($der == "") {
  2731. return error_show(1002, "未找到出库订单单号");
  2732. }
  2733. $send_num = isset($this->post['send_num']) && $this->post['send_num'] !== "" ? $this->post['send_num'] : "";
  2734. if ($send_num == "") {
  2735. return error_show(1002, "发货数量不能为空");
  2736. }
  2737. if ($send_num > $der['wsend_num']) {
  2738. return error_show(1002, "超出可发货数量");
  2739. }
  2740. $contactor = isset($this->post['contactor'])&&$this->post['contactor']!="" ? trim($this->post['contactor']):"";
  2741. if($contactor==""){
  2742. return error_show(1002, "参数contactor不能为空");
  2743. }
  2744. $mobile = isset($this->post['mobile'])&&$this->post['mobile']!="" ? trim($this->post['mobile']):"";
  2745. if($mobile==""){
  2746. return error_show(1002, "参数mobile不能为空");
  2747. }
  2748. $addr = isset($this->post['addr'])&&$this->post['addr']!="" ? trim($this->post['addr']):"";
  2749. if($addr==""){
  2750. return error_show(1002, "参数addr不能为空");
  2751. }
  2752. $addr_code = isset($this->post['addr_code'])&&$this->post['addr_code']!="" ? trim($this->post['addr_code']):"";
  2753. if($addr_code==""){
  2754. return error_show(1002, "参数addr_code不能为空");
  2755. }
  2756. $apply_id = GetUserInfo($token);
  2757. if (empty($apply_id) || $apply_id['code'] != 0) {
  2758. return error_show(1002, "申请人数据不存在");
  2759. }
  2760. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  2761. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  2762. $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !== "" ? $this->post['sendtime'] : date("Y-m-d H:i:s");
  2763. $order =Db::name("order_num")->where(["orderCode"=>$orderCode,"status"=>1])->where([["wsend_num",">=",0]])
  2764. ->select()->toArray();
  2765. if(empty($order)){
  2766. return error_show(1004,"未找到可以发货得采购单数据");
  2767. }
  2768. Db::startTrans();
  2769. try {
  2770. $addrlst =[
  2771. "orderCode"=>$orderCode,
  2772. "addr"=>$addr,
  2773. "addr_code"=>json_encode($addr_code),
  2774. "contactor"=>$contactor,
  2775. "mobile"=>$mobile,
  2776. "customer_code"=>$der['customer_code'],
  2777. "post_fee"=>$der['post_fee'],
  2778. "arrive_time"=>$sendtime,
  2779. "receipt_quantity"=>$send_num,
  2780. "is_del"=>0,
  2781. "addtime"=>date("Y-m-d H:i:s"),
  2782. "updatetime"=>date("Y-m-d H:i:s")
  2783. ];
  2784. $addrid = Db::name("order_addr")->insert($addrlst,true);
  2785. if($addrid>0){
  2786. $der['send_num'] +=$send_num;
  2787. $der['wsend_num'] -= $send_num;
  2788. $der['send_status'] = $der['send_num'] == 0 ? 1 : $der['wsend_num'] == 0 ? 3 : 2;
  2789. $der['status'] = $der['send_num'] == 0 ? 3 : $der['wsend_num'] == 0 ? 5 : 4;
  2790. $der['updatetime'] = date("Y-m-d H:i:s");
  2791. $si = Db::name('sale')->save($der);
  2792. if($si==false){
  2793. Db::rollback();
  2794. return error_show(1002,"出库单新建失败");
  2795. }
  2796. $num = $send_num;
  2797. $data=[];
  2798. foreach ($order as $val){
  2799. $outCode = makeNo("DF");
  2800. $cgd =Db::name("purchease_order")->where(["cgdNo"=>$val['cgdNo']])->find();
  2801. $tep=[];
  2802. $ornum=0;
  2803. if($val['wsend_num']>=$num){
  2804. $val['wsend_num']-=$num;
  2805. $val['send_num']+=$num;
  2806. $ornum =$num;
  2807. $num=0;
  2808. }else{
  2809. $num-=$val['wsend_num'];
  2810. $val['send_num']+=$val['wsend_num'];
  2811. $ornum =$val['wsend_num'];
  2812. $val['wsend_num']=0;
  2813. }
  2814. $or =Db::name("order_num")->save($val);
  2815. if($or==false){
  2816. Db::rollback();
  2817. return error_show(1002,"发货地址添加创建失败");
  2818. }
  2819. $tep=[
  2820. "cgdNo"=>$val['cgdNo'],
  2821. "outCode"=>$outCode,
  2822. "send_num"=>$ornum,
  2823. "status"=>1,
  2824. "addtime"=>date("Y-m-d H:i:s"),
  2825. "updatetime"=>date("Y-m-d H:i:s")
  2826. ];
  2827. $sen=Db::name("order_send")->save($tep);
  2828. if($sen==false){
  2829. Db::rollback();
  2830. return error_show(1002,"发货地址添加创建失败");
  2831. }
  2832. $data[] = [
  2833. "wsm_code" => isset($cgd['wsm_code'])? $cgd['wsm_code']:"",
  2834. "orderCode" => $orderCode,
  2835. "outCode" => $outCode,
  2836. "order_type" => $der['order_type'],
  2837. "apply_id" => $rm,
  2838. "apply_name" => $ri,
  2839. "addrid" => $addrid,
  2840. "post_name" => "",
  2841. "post_code" =>"",
  2842. "post_fee" => "",
  2843. "sendtime" => $sendtime,
  2844. "send_num" => $ornum,
  2845. "check_num" => 0,
  2846. "error_num" => 0,
  2847. "status" => 1,
  2848. "addtime" => date("Y-m-d H:i:s"),
  2849. "updatetime" => date("Y-m-d H:i:s")
  2850. ];
  2851. //维护商品所在仓库的库存 --- start
  2852. $temp = Db::name('good_stock')
  2853. ->field('id,usable_stock,wait_out_stock')
  2854. ->where(['spuCode' => $val['spuCode'], 'wsm_code' => $cgd['wsm_code']])
  2855. ->find();
  2856. if ($temp == false) {
  2857. Db::rollback();
  2858. return error_show(1004, '库存不足');
  2859. }
  2860. if (($temp['usable_stock'] - $ornum) < 0) {
  2861. Db::rollback();
  2862. return error_show(1004, '库存不足');
  2863. }
  2864. $up =Db::name('good_stock')
  2865. ->where('id', $temp['id'])
  2866. ->update([
  2867. 'usable_stock' => $temp['usable_stock'] - $ornum,
  2868. 'wait_out_stock' => $temp['wait_out_stock'] + $ornum,
  2869. 'updatetime' => date('Y-m-d H:i:s'),
  2870. ]);
  2871. if($up==false){
  2872. Db::rollback();
  2873. return error_show(1004, '库存更新失败');
  2874. }
  2875. if($num==0){
  2876. break;
  2877. }
  2878. }
  2879. $datainfo = Db::name('order_out')->insertAll($data);
  2880. if($datainfo>0){
  2881. foreach ($data as $k => $v_data) {
  2882. //修改状态,添加待办
  2883. ActionLog::logAdd($this->post['token'], [
  2884. "order_code" => $v_data['outCode'],//出库单号
  2885. "status" => $v_data['status'],//这里的status是之前的值
  2886. "action_remark" => '',//备注
  2887. "action_type" => "create"//新建create,编辑edit,更改状态status
  2888. ], "CKD", $v_data['status'], $v_data);
  2889. ProcessOrder::AddProcess($this->post['token'], [
  2890. "order_type" => 'CKD',
  2891. "order_code" => $v_data['outCode'],//出库单号
  2892. "order_id" => 0,
  2893. "order_status" => $v_data['status']
  2894. ]);
  2895. }
  2896. Db::commit();
  2897. return app_show(0,"出库单新建成功");
  2898. }
  2899. }
  2900. Db::rollback();
  2901. return error_show(1004,"出库单新建失败");
  2902. } catch (Exception $e) {
  2903. Db::rollback();
  2904. return error_show(1005, $e->getMessage());
  2905. }
  2906. }
  2907. public function outdel(){
  2908. }
  2909. public function outSend(){
  2910. $outCode=isset($this->post['outCode'])&& $this->post['outCode']!=""? trim($this->post['outCode']):"";
  2911. if($outCode==""){
  2912. return error_show(1004,"参数outCode不能为空");
  2913. }
  2914. $outinfo = Db::name("order_out")->where(["outCode"=>$outCode])->find();
  2915. if($outinfo==false){
  2916. return error_show(1004,"发货数据未找到");
  2917. }
  2918. $einfo = Db::name('sale')->where(['orderCode' => $outinfo['orderCode'], 'is_del' => 0])->find();
  2919. if (empty($einfo)) {
  2920. return error_show(1002, "未找到销售订单数据");
  2921. }
  2922. $post_name = isset($this->post['post_name']) &&$this->post['post_name']!="" ? trim($this->post['post_name']):"";
  2923. if($post_name==""){
  2924. return error_show(1004,"参数post_name不能为空");
  2925. }
  2926. $post_code = isset($this->post['post_code']) &&$this->post['post_code']!="" ? trim($this->post['post_code']):"";
  2927. if($post_code==""){
  2928. return error_show(1004,"参数post_code不能为空");
  2929. }
  2930. $post_fee = isset($this->post['post_fee']) && $this->post['post_fee']!="" ? floatval($this->post['post_fee']):"";
  2931. $outinfo['post_name'] = $post_name;
  2932. $outinfo['post_code'] = $post_code;
  2933. $outinfo['post_fee'] = $post_fee;
  2934. $outinfo['sendtime'] = date("Y-m-d H:i:s");
  2935. $old_outinfo_status = $outinfo['status'];
  2936. $outinfo['status'] = 2;
  2937. $outinfo['updatetime'] = date("Y-m-d H:i:s");
  2938. Db::startTrans();
  2939. try{
  2940. $up =Db::name("order_out")->save($outinfo);
  2941. if($up){
  2942. //修改状态,添加待办
  2943. ActionLog::logAdd($this->post['token'], [
  2944. "order_code" => $outinfo['outCode'],//出库单号
  2945. "status" => $old_outinfo_status,//这里的status是之前的值
  2946. "action_remark" => '',//备注
  2947. "action_type" => "edit"//新建create,编辑edit,更改状态status
  2948. ], "CKD", $outinfo['status'], $outinfo);
  2949. ProcessOrder::AddProcess($this->post['token'], [
  2950. "order_type" => 'CKD',
  2951. "order_code" => $outinfo['outCode'],//出库单号
  2952. "order_id" => $outinfo['id'],
  2953. "order_status" => $outinfo['status']
  2954. ]);
  2955. $stokc =Db::name("good_stock")->where(['spuCode'=>$einfo['good_code'],"wsm_code"=>$outinfo['wsm_code'],"is_del"=>0])->find();
  2956. if($stokc==false){
  2957. Db::rollback();
  2958. return error_show(1002, "未找库存到数据");
  2959. }else{
  2960. if ($outinfo['send_num'] > $stokc['wait_out_stock']) {
  2961. Db::rollback();
  2962. return error_show(1002, "超出库存数量");
  2963. }
  2964. $stokc['wait_out_stock']-=$outinfo['send_num'];
  2965. $stokc['intra_stock']+=$outinfo['send_num'];
  2966. $stokc['updatetime']=date("Y-m-d H:i:s");
  2967. }
  2968. $stoc= Db::name("good_stock")->save($stokc);
  2969. if($stoc==false){
  2970. Db::rollback();
  2971. return error_show(1002, "库存更新失败");
  2972. }
  2973. Db::commit();
  2974. return app_show(0,"发货成功");
  2975. }else{
  2976. Db::rollback();
  2977. return error_show(1004,"发货失败");
  2978. }
  2979. }catch (\Exception $e){
  2980. Db::rollback();
  2981. return error_show(1004,$e->getMessage());
  2982. }
  2983. }
  2984. public function RelaCgd($outinfo){
  2985. $der = Db::name('sale')->where(['orderCode' => $outinfo['orderCode']])->find();
  2986. if ($der == "") {
  2987. return false;
  2988. }
  2989. if($der['is_stock']==1){
  2990. $cgd = Db::name("order_bk")->where([["spuCode","=",$der['spuCode']],["is_del","=",0],["balance_num",">",0]])
  2991. ->select()->toArray();
  2992. if(empty($cgd)){
  2993. return false;
  2994. }
  2995. $send =$outinfo['send_num'];
  2996. $outsend=[];
  2997. foreach ($cgd as $value){
  2998. $temp=[];
  2999. if($value['balance_num']>=$send){
  3000. $value['balance_num']-=$send;
  3001. $value['merge_num']+=$send;
  3002. $send=0;
  3003. $temp['send_num'] =$send;
  3004. }else{
  3005. $value['balance_num'] =0;
  3006. $value['merge_num']+=$value['balance_num'];
  3007. $send -= $value['balance_num'];
  3008. $temp['send_num'] =$value['balance_num'];
  3009. }
  3010. $value['status'] = $value['balance_num']==0 ?2:$value['merge_num']==0?0:1 ;
  3011. $value['updatetime'] = date("Y-m-d H:i:s");
  3012. $bk = Db::name("order_bk")->save($value);
  3013. if($bk==false){
  3014. return false;
  3015. }
  3016. $temp['cgdNo'] = $value['cgdNo'];
  3017. $temp['outCode'] = $outinfo['outCode'];
  3018. $temp['status'] = 1;
  3019. $temp['addtime']=date("Y-m-d H:i:s");
  3020. $temp['updatetime']=date("Y-m-d H:i:s");
  3021. $outsend[]=$temp;
  3022. $order = Db::name("order_num")->where(["orderCode"=>$der['orderCode'],"cgdNo"=>$value['cgdNo'],"spuCode"=>$der['spuCode'],"status"=>1])->find();
  3023. if($order==false){
  3024. $order=[
  3025. "orderCode"=>$der['orderCode'],
  3026. "cgdNo"=>$value['cgdNo'],
  3027. "spuCode"=>$der['spuCode'],
  3028. "good_num"=>$der['good_num'],
  3029. "wsend_num"=>$der['good_num']-$temp['send_num'],
  3030. "send_num"=>$temp['send_num'],
  3031. "status"=>1,
  3032. "source"=>1
  3033. ];
  3034. }else{
  3035. $order['wsend_num']-=$temp['send_num'];
  3036. $order['send_num']+=$temp['send_num'];
  3037. }
  3038. if($order['wsend_num']<0){
  3039. return false;
  3040. }
  3041. $up =Db::name("order_num")->save($order);
  3042. if($up==false){
  3043. return false;
  3044. }
  3045. if($send==0){
  3046. break;
  3047. }
  3048. }
  3049. if(empty($temp)){
  3050. return false;
  3051. }
  3052. $insert = Db::name("order_send")->insertAll($outsend);
  3053. if($insert){
  3054. return true;
  3055. }else{
  3056. return false;
  3057. }
  3058. }else{
  3059. $order = Db::name("order_num")->where(["orderCode"=>$der['orderCode'],"spuCode"=>$der['spuCode'],
  3060. "status"=>1])->find();
  3061. if($order==false){
  3062. return false;
  3063. }else{
  3064. if($outinfo['send_num']> $order['wsend_num']){
  3065. return false;
  3066. }
  3067. $order['wsend_num']-=$outinfo['send_num'];
  3068. $order['send_num']+=$outinfo['send_num'];
  3069. if($order['wsend_num']<0){
  3070. return false;
  3071. }
  3072. $up =Db::name("order_num")->save($order);
  3073. if($up==false){
  3074. return false;
  3075. }
  3076. $temp=[];
  3077. $temp['cgdNo'] = $order['cgdNo'];
  3078. $temp['outCode'] = $outinfo['outCode'];
  3079. $temp['send_num'] =$outinfo['send_num'];
  3080. $temp['status'] = 1;
  3081. $temp['addtime']=date("Y-m-d H:i:s");
  3082. $temp['updatetime']=date("Y-m-d H:i:s");
  3083. $insert = Db::name("order_send")->insert($temp);
  3084. if($insert){
  3085. return true;
  3086. }else{
  3087. return false;
  3088. }
  3089. }
  3090. }
  3091. }
  3092. public function addother(){
  3093. $orderCode =isset($this->post['orderCode']) && $this->post['orderCode']!=""?trim($this->post['orderCode']):"";
  3094. if($orderCode==""){
  3095. return error_show(1004,"参数orderCode不能为空");
  3096. }
  3097. $order =Db::name("sale")->where(["orderCode"=>$orderCode,"is_del"=>0])->find();
  3098. if($order==false){
  3099. return error_show(1004,"未找到订单数据");
  3100. }
  3101. $paytime =isset($this->post['paytime'])&&$this->post['paytime']!=""? $this->post['paytime']:"";
  3102. $workNo =isset($this->post['workNo'])&&$this->post['workNo']!=""? trim($this->post['workNo']):"";
  3103. $platform_order =isset($this->post['platform_order'])&&$this->post['platform_order']!=""? trim($this->post['platform_order']):"";
  3104. $paytime==""?"":$order['paytime']=$paytime;
  3105. $order['workNo']=$workNo;
  3106. $order['platform_order']=$platform_order;
  3107. $order['updatetime']=date("Y-m-d H:i:s");
  3108. $sa=Db::name("sale")->save($order);
  3109. if($sa){
  3110. return app_show(0,"更新成功");
  3111. }else{
  3112. return error_show(1004,"更新失败");
  3113. }
  3114. }
  3115. public function getPrice()
  3116. {
  3117. $skuCode = isset($this->post['skuCode']) && $this->post['skuCode'] != "" ? trim($this->post['skuCode']) : "";
  3118. if ($skuCode === "") {
  3119. return error_show(1003, "参数skuCode不能为空");
  3120. }
  3121. $is_activity = isset($this->post['is_activity']) && $this->post['is_activity'] !== "" ? intval($this->post['is_activity'])
  3122. : "";
  3123. if ($is_activity === "") {
  3124. return error_show(1003, "参数is_activity不能为空");
  3125. }
  3126. $sale_num = isset($this->post['sale_num']) && $this->post['sale_num'] !== "" ? intval($this->post['sale_num']) : "";
  3127. if ($sale_num === "") {
  3128. return error_show(1003, "参数sale_num不能为空");
  3129. }
  3130. $ct = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  3131. ->where(['a.skuCode' => $skuCode])->find();
  3132. if ($ct == false) {
  3133. return error_show(1002, "未找到商品数据");
  3134. }
  3135. $stock = 0;
  3136. if ($ct['is_stock'] == 1) {
  3137. $good_stock = Db::name("good_stock")->where(["spuCode" => $ct['spuCode'], "is_del" => 0])->find();
  3138. $stock = isset($good_stock['usable_stock']) ? $good_stock['usable_stock'] : "0";
  3139. }
  3140. if ($is_activity == 1) {
  3141. $act = Db::name("activity_info")->alias("a")->leftJoin("good_activity b", "a.activity_code=b.activity_code")
  3142. ->where(["a.skuCode" => $skuCode, "a.is_del" => 0, "a.status" => 1, "b.status" => 6, "b.is_del" => 0])->find();
  3143. if ($act == false) {
  3144. return error_show(1003, "未找到相关活动价");
  3145. }
  3146. if ($act['moq_num'] > $sale_num) {
  3147. return error_show(1003, "商品不满足活动价起订量{$act['moq_num']}");
  3148. }
  3149. if ($act['activity_stock'] < $sale_num) {
  3150. return error_show(1003, "商品活动库存剩余{$act['activity_stock']}");
  3151. }
  3152. return app_show(0, "获取成功", ['sale_price' => $act['activity_price'], "stock" => $act['activity_stock']]);
  3153. } else {
  3154. if ($ct['is_stock'] == 0) {
  3155. //good_nake 成本阶梯 good_ladder销售阶梯
  3156. $origin = Db::name("good_nake")->where([["spuCode", "=", $ct['spuCode']], ["is_del", "=", 0]])->order("min_num asc")->find();
  3157. if (!$origin) {
  3158. return error_show(1003, "没有找到成本数据");
  3159. }
  3160. }
  3161. $good = Db::name("good_ladder")->where(["skuCode" => $skuCode, "is_del" => 0, "status" => 1])->order("min_num asc")->find();
  3162. if (!$good) {
  3163. return error_show(1003, "未找到相关阶梯价格");
  3164. }
  3165. if(!isset($origin['min_num'])) $origin['min_num']=0;
  3166. $lastnum = max($origin['min_num']??0, $good['min_num']);
  3167. if ($sale_num < $lastnum) {
  3168. return error_show(1003, "商品不满足起订量{$lastnum}");
  3169. }
  3170. $good_temp = Db::name("good_ladder")->where(["skuCode" => $skuCode, "is_del" => 0, "status" => 1])->where('min_num', '<=', $sale_num)->order("min_num desc")->find();
  3171. if (!$good_temp) {
  3172. return error_show(1003, "未找到相关阶梯价格");
  3173. }
  3174. return app_show(0, "获取成功", ['sale_price' => $good_temp['sale_price'], "stock" => $stock]);
  3175. }
  3176. }
  3177. public function saleuse(){
  3178. $orderCode= isset($this->post['orderCode'])&&!empty($this->post['orderCode'])?$this->post['orderCode']:"";
  3179. if($orderCode==""){
  3180. return error_show(1003,"参数orderCode不能为空");
  3181. }
  3182. $order= Db::name("sale")->where(["orderCode"=>$orderCode,"is_del"=>0])->select()->toArray();
  3183. if(empty($order)){
  3184. return error_show(1003,"订单数据未找到");
  3185. }
  3186. $useid= isset($this->post['useid'])&&$this->post['useid']!=""?intval($this->post['useid']):"";
  3187. if($useid==""){
  3188. return error_show(1003,"参数useid不能为空");
  3189. }
  3190. $use =Db::name("order_use")->where(["id"=>$useid,"is_del"=>0])->find();
  3191. if($use==false){
  3192. return error_show(1003,"用途数据未找到");
  3193. }
  3194. $asve=['use_order'=>$useid,"updatetime"=>date("Y-m-d H:i:s")];
  3195. $up=Db::name("sale")->where(["orderCode"=>$orderCode,"is_del"=>0])->update($asve);
  3196. if($up>0){
  3197. return app_show(0,"更新成功");
  3198. }else{
  3199. return error_show(1003,"更新失败");
  3200. }
  3201. }
  3202. public function goodzxinfo(){
  3203. $orderCode= isset($this->post['spuCode'])&&$this->post['spuCode']!=''?trim($this->post['spuCode']):"";
  3204. if($orderCode==""){
  3205. return error_show(1003,"参数spuCode不能为空");
  3206. }
  3207. $order= Db::name("good_zixun")->where(["spuCode"=>$orderCode,"is_del"=>0])->find();
  3208. if(empty($order)){
  3209. return error_show(1003,"订单数据未找到");
  3210. }
  3211. $unit =Db::name("unit")->where(["id"=>$order['good_unit']])->find();
  3212. if($order['brand_id']!=0){
  3213. $brand=Db::name("brand")->where(["id"=>$order['brand_id']])->find();
  3214. $order["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  3215. }else{
  3216. $order["brand_name"]="";
  3217. $order["brand_id"]="";
  3218. }
  3219. $order['specinfo']=json_decode($order['specinfo'],true);
  3220. $order['unit'] = isset($unit['unit'])?$unit['unit']:'';
  3221. $order['cat_info'] = made($order['cat_id'],[]);
  3222. $order['noble_name']=isset($order['noble_metal'])&&$order['noble_metal']!=0?$this->noble[$order['noble_metal']] :"";
  3223. if($order['is_gold_price']==1){
  3224. $price=Db::name("gold_price1")->where(["type"=>$order['noble_metal'],"status"=>1,"is_del"=>0])->order("addtime desc")->find();
  3225. }
  3226. $supplier = Db::name("supplier")->where(["code"=>$order['supplierNo']])->find();
  3227. $order['supplier_name'] = isset($supplier['name']) ? $supplier['name']:"";
  3228. $palt =Db::name("platform")->where(["id"=>$order['platform_id']])->find();
  3229. $order['platform_name']=isset($palt['platform_name']) ? $palt['platform_name']:"";
  3230. $order["gold_price"] = isset($price['price'])?$price['price']:0;
  3231. $order["noble_weight"] = isset($order['weight'])?$order['weight']:0;
  3232. return app_show(0,"获取成功",$order);
  3233. }
  3234. //获取采反商品详情,当数据不在good_zixun中,模仿goodzxinfo
  3235. public function getGoodZxInfoByNotZixun(){
  3236. $param=$this->request->only(['spuCode'],'post','trim');
  3237. $val=Validate::rule(['spuCode'=>'require']);
  3238. if(!$val->check($param)) return error_show(1004,$val->getError());
  3239. $order = Db::name('consult_bids')
  3240. ->field(true)
  3241. ->where(['spuCode'=>$param['spuCode'],'is_del'=>0])
  3242. ->find();
  3243. // $orderCode= isset($this->post['spuCode'])&&$this->post['spuCode']!=''?trim($this->post['spuCode']):"";
  3244. // if($orderCode==""){
  3245. // return error_show(1003,"参数spuCode不能为空");
  3246. // }
  3247. // $order= Db::name("good_zixun")->where(["spuCode"=>$orderCode,"is_del"=>0])->find();
  3248. // if(empty($order)){
  3249. // return error_show(1003,"订单数据未找到");
  3250. // }
  3251. $unit =Db::name("unit")->where(["id"=>$order['unit_id']])->find();
  3252. if($order['brand_id']!=0){
  3253. $brand=Db::name("brand")->where(["id"=>$order['brand_id']])->find();
  3254. $order["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  3255. }else{
  3256. $order["brand_name"]="";
  3257. $order["brand_id"]="";
  3258. }
  3259. $order['specinfo']=json_decode($order['specinfo'],true);
  3260. $order['unit'] = isset($unit['unit'])?$unit['unit']:'';
  3261. $order['cat_info'] = made($order['cat_id'],[]);
  3262. $order['noble_name']=isset($order['metal_id'])&&$order['metal_id']!=0?$this->noble[$order['metal_id']] :"";
  3263. if($order['is_gold_price']==1){
  3264. $price=Db::name("gold_price1")->where(["type"=>$order['metal_id'],"status"=>1,"is_del"=>0])->order("addtime desc")->find();
  3265. }
  3266. $supplier = Db::name("supplier")->where(["code"=>$order['supplierNo']])->find();
  3267. $order['supplier_name'] = isset($supplier['name']) ? $supplier['name']:"";
  3268. // $palt =Db::name("platform")->where(["id"=>$order['platform_id']])->find();
  3269. // $order['platform_name']=isset($palt['platform_name']) ? $palt['platform_name']:"";
  3270. $order["gold_price"] = isset($price['price'])?$price['price']:0;
  3271. $order["noble_weight"] = isset($order['weight'])?$order['weight']:0;
  3272. return app_show(0,"获取成功",$order);
  3273. }
  3274. }