Sale.php 147 KB

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