Sale.php 152 KB

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