Sale.php 129 KB

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