Sale.php 137 KB

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