Sale.php 146 KB

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