Sale.php 147 KB

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