Sale.php 146 KB

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