Sale.php 153 KB

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