Sale.php 134 KB

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