Sale.php 146 KB

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