Sale.php 164 KB

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