Sale.php 150 KB

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