Sale.php 149 KB

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