Sale.php 149 KB

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