Sale.php 148 KB

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