Sale.php 152 KB

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