Sale.php 164 KB

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