Sale.php 141 KB

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