Sale.php 164 KB

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