Sale.php 149 KB

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