Sale.php 164 KB

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