Sale.php 146 KB

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