Sale.php 143 KB

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