Inter.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\Admin\controller;
  4. use app\BaseController;
  5. use think\facade\Db;
  6. class Inter extends BaseController
  7. {
  8. /**
  9. * 显示资源列表
  10. *
  11. * @return \think\Response
  12. */
  13. public function list()
  14. {
  15. $post = $this->request->post();
  16. $condition = [['suppitem', '=', '网络部']];
  17. $page = isset($post['page']) && $post['page'] !== '' ? intval($post['page']) : 1;
  18. $size = isset($post['size']) && $post['size'] !== '' ? intval($post['size']) : 10;
  19. $qrdNo = isset($post['qrdNo'])&&$post['qrdNo']!=='' ? trim($post['qrdNo']) :'';
  20. if($qrdNo!=""){
  21. $condition[]=['a.qrdNo','=',$qrdNo];
  22. }
  23. $cgdNo = isset($post['cgdNo'])&&$post['cgdNo']!=='' ? trim($post['cgdNo']) :'';
  24. if($cgdNo!=""){
  25. $condition[]=['a.cgdNo','=',$cgdNo];
  26. }
  27. $khNo = isset($post['khNo'])&&$post['khNo']!=='' ? trim($post['khNo']) :'';
  28. if($khNo!=""){
  29. $condition[]=['a.companyNo','=',$khNo];
  30. }
  31. $supplierNo = isset($post['supplierNo'])&&$post['supplierNo']!=='' ? trim($post['supplierNo']) :'';
  32. if($supplierNo!=""){
  33. $condition[]=['a.supplierNo','=',$supplierNo];
  34. }
  35. $starttime = isset($post['starttime']) && $post['starttime']!='' ? $post['starttime'] :"";
  36. if($starttime!=""){
  37. $condition[]=['a.ordertime','>=',$starttime];
  38. }
  39. $endtime = isset($post['endtime']) && $post['endtime']!='' ? $post['endtime'] :"";
  40. if($endtime!=""){
  41. $condition[]=['a.ordertime','<=',$endtime];
  42. }
  43. $sale_name = isset($post['sale_name']) && $post['sale_name']!='' ? trim($post['sale_name']) :"";
  44. if($sale_name!=""){
  45. $condition[]=['a.sale_name','like','%'.$sale_name.'%'];
  46. }
  47. $cgd_saler = isset($post['cgd_saler']) && $post['cgd_saler']!='' ? trim($post['cgd_saler']) :"";
  48. if($cgd_saler!=""){
  49. $condition[]=['a.cgd_saler','like','%'.$cgd_saler.'%'];
  50. }
  51. $count = Db::table('source_all')->alias('a')->join('cfp_qrd_info b','a.productNo=b.sequenceNo','left')
  52. ->join('cfp_cgd_info c','a.cgdNo=c.ShortText1618315935182','left')->where($condition)->count();
  53. $total = ceil($count/$size)>1 ? ceil($count/$size) : 1;
  54. $page = $page>=$total?intval($total):$page;
  55. $list=Db::table('source_all')->alias('a')->join('cfp_qrd_info b','a.productNo=b.sequenceNo','left')
  56. ->join('cfp_cgd_info c','a.cgdNo=c.ShortText1618315935182','left')->where($condition)
  57. ->page(intval($page),$size)->order("a.ordertime desc")->field('a.id,a.productNo,a.companyName as khName,a.companyNo as khNo,a.qrdNo,
  58. a.supperinfo,a.suppitem,a.poNo,a.ordertime,a.sale_name,a.depart,a.product_name,a.tax,a.sale_price,a.order_num,
  59. a.sale_total,a.supplier,a.supplierNo,b.Number1618249146997 as apay_fee,b.number1618249149738 as wpay_fee,
  60. b.Number1618249202608 as ainv_fee,b.Number1618249205231 as winv_fee,a.qrd_type,a.rate*100 as cgd_tax,a.cat_f,
  61. a.cgdNo, a.workNo as sequenceNo')->select();
  62. $all =[];
  63. foreach ($list as $key=>$value){
  64. if($value['supperinfo']!=''){
  65. $company = Db::name('company_info')->where('company_name',"=",$value['supperinfo'])->find();
  66. $value['companyNo'] = isset($company['companyNo']) ? $company['companyNo']:"";
  67. }else{
  68. $value['companyNo'] = "";
  69. }
  70. $all[]=$value;
  71. }
  72. return app_show(0, '获取数据成功', ['list' => $all, 'count' => $count]);
  73. }
  74. /**
  75. * 显示创建资源表单页.
  76. *
  77. * @return \think\Response
  78. */
  79. public function add()
  80. {
  81. $post = $this->request->post();
  82. $token = isset($post['token']) ? trim($post['token']) : "";
  83. if ($token == "") {
  84. return error_show(101, 'token不能为空');
  85. }
  86. $effetc = VerifyTokens($token);
  87. if (!empty($effetc) && $effetc['code'] != 0) {
  88. return error_show($effetc['code'], $effetc['message']);
  89. }
  90. $guserinfo = GetUserInfo($token);
  91. if (isset($guserinfo['code']) && $guserinfo['code'] != 0) {
  92. return error_show($guserinfo['code'], $guserinfo['message']);
  93. }
  94. $sale_name = isset($post['sale_name']) && $post['sale_name'] != '' ? trim($post['sale_name']) : '';
  95. if ($sale_name == '') {
  96. return error_show(1004, "参数sale_name 不能为空");
  97. }
  98. $department = isset($post['department']) && $post['department'] != '' ? trim($post['department']) : '网络部';
  99. $companyNo = isset($post['companyNo']) && $post['companyNo'] != '' ? trim($post['companyNo']) : '';
  100. if ($companyNo == '') {
  101. return error_show(1004, "参数companyNo 不能为空");
  102. }
  103. $poNo = isset($post['poNo']) && $post['poNo'] != '' ? trim($post['poNo']) : '';
  104. if ($poNo == '') {
  105. return error_show(1004, "参数poNo 不能为空");
  106. }
  107. $sequenceNo = isset($post['sequenceNo']) && $post['sequenceNo'] != '' ? trim($post['sequenceNo']) : '';
  108. if ($sequenceNo == '') {
  109. return error_show(1004, "参数sequenceNo 不能为空");
  110. }
  111. $khNo = isset($post['khNo']) && $post['khNo'] != '' ? trim($post['khNo']) : '';
  112. if ($khNo == '') {
  113. return error_show(1004, "参数khNo 不能为空");
  114. }
  115. $cunstmer = Db::name('customer_info')->where('companyNo', "=", $khNo)->find();
  116. if (empty($cunstmer)) {
  117. return error_show(1004, "客户信息未找到");
  118. }
  119. $qrdType = isset($post['qrdType']) && $post['qrdType'] != '' ? trim($post['qrdType']) : '';
  120. if ($qrdType == '') {
  121. return error_show(1004, "参数qrdType 不能为空");
  122. }
  123. $goodName = isset($post['goodName']) && $post['goodName'] != '' ? trim($post['goodName']) : '';
  124. if ($goodName == '') {
  125. return error_show(1004, "参数goodName 不能为空");
  126. }
  127. $tax = isset($post['tax']) && $post['tax'] != '' ? trim($post['tax']) : '';
  128. if ($tax == '') {
  129. return error_show(1004, "参数tax 不能为空");
  130. }
  131. $goodNum = isset($post['goodNum']) && $post['goodNum'] !== '' ? intval($post['goodNum']) : '';
  132. if ($goodNum === '') {
  133. return error_show(1004, "参数goodNum 不能为空");
  134. }
  135. $goodPrice = isset($post['goodPice']) && $post['goodPice'] !== '' ? $post['goodPice'] : '';
  136. if ($goodPrice == '') {
  137. return error_show(1004, "参数goodPrice 不能为空");
  138. }
  139. $good_total = isset($post['good_total']) && $post['good_total'] !== '' ? $post['good_total'] : '';
  140. if ($good_total == '') {
  141. return error_show(1004, "参数good_total 不能为空");
  142. }
  143. $contactor = isset($post['contactor']) && $post['contactor'] != '' ? trim($post['contactor']) : '';
  144. if ($contactor == '') {
  145. return error_show(1004, "参数contactor 不能为空");
  146. }
  147. $mobile = isset($post['mobile']) && $post['mobile'] != '' ? trim($post['mobile']) : '';
  148. if ($mobile == '') {
  149. return error_show(1004, "参数mobile 不能为空");
  150. }
  151. $addr = isset($post['addr']) && $post['addr'] != '' ? trim($post['addr']) : '';
  152. if ($addr == '') {
  153. return error_show(1004, "参数addr 不能为空");
  154. }
  155. $buyer = isset($post['buyer']) && $post['buyer'] != '' ? trim($post['buyer']) : '';
  156. if ($buyer == '') {
  157. return error_show(1004, "参数buyer 不能为空");
  158. }
  159. $buy_depart = isset($post['buy_depart']) && $post['buy_depart'] != '' ? trim($post['buy_depart']) : '';
  160. if ($buy_depart == '') {
  161. return error_show(1004, "参数buy_depart 不能为空");
  162. }
  163. $sendtime = isset($post['sendtime']) && $post['sendtime'] != '' ? $post['sendtime'] : '';
  164. if ($sendtime == '') {
  165. return error_show(1004, "参数sendtime 不能为空");
  166. }
  167. $cat_f = isset($post['cat_f']) && $post['cat_f'] != '' ? $post['cat_f'] : '';
  168. if ($cat_f == '') {
  169. return error_show(1004, "参数cat_f 不能为空");
  170. }
  171. $supplierNo = isset($post['supplierNo']) && $post['supplierNo'] != '' ? trim($post['supplierNo']) : '';
  172. if ($supplierNo == '') {
  173. return error_show(1004, "参数supplierNo 不能为空");
  174. }
  175. $supplier = Db::name('supplier_info')->where('code', "=", $supplierNo)->find();
  176. if (empty($supplier)) {
  177. return error_show(1004, "供应商信息未找到");
  178. }
  179. $cgd_tax = isset($post['cgd_tax']) && $post['cgd_tax'] !== '' ? round($post['cgd_tax']/100,4) : '';
  180. if ($cgd_tax === '') {
  181. return error_show(1004, "参数cgd_tax 不能为空");
  182. }
  183. $company = Db::name("company_info")->where("companyNo","=",$companyNo)->find();
  184. if(empty($company)){
  185. return error_show(1004, "确认单销售公司未找到");
  186. }
  187. $rate = Db::name('order_rate')->where('id',"=",$tax)->find();
  188. if(empty($rate)){
  189. return error_show(1004, "税率数据未找到");
  190. }
  191. $qrdno = makeNo("QRD");
  192. $Cgd = makeNo('CGD');
  193. $goodNo=makeNo("GY");
  194. $qrdData=[
  195. "name"=>'网络部确认单'.$sequenceNo,
  196. 'createdTime'=>date("Y-m-d H:i:s"),
  197. 'sequenceNo'=>$qrdno,
  198. 'sales_name'=>$sale_name,
  199. 'sales_depart'=>$department,
  200. 'customer'=>isset($cunstmer['companyName']) ? $cunstmer['companyName'] : "",
  201. 'total_fee'=>$good_total,
  202. 'mobile'=>$mobile,
  203. 'contactor'=>$contactor,
  204. 'qrddate'=>date("Y-m-d H:i:s"),
  205. 'companyNo'=>$khNo,
  206. 'supplerName'=>isset($company['company_name']) ? $company['company_name'] : "",
  207. 'addr'=>$addr,
  208. 'depart'=>$department,
  209. 'type'=>1,
  210. 'apay_fee'=>0,
  211. 'pay_fee'=>0,
  212. 'wpay_fee'=>$good_total,
  213. 'ainv_fee'=>0,
  214. 'inv_fee'=>0,
  215. 'winv_fee'=>$good_total,
  216. 'inv_status'=>1,
  217. 'pay_status'=>1,
  218. 'status'=>1,
  219. 'addtime'=>date("Y-m-d H:i:s"),
  220. 'updatetime'=>date("Y-m-d H:i:s")
  221. ];
  222. $data = [
  223. 'name' => '网络部确认单',
  224. 'createdTime' => date("Y-m-d H:i:s"),
  225. 'startTime' => date("Y-m-d H:i:s"),
  226. 'finishTime' => date("Y-m-d H:i:s"),
  227. "Date1617081795606"=>date("Y-m-d H:i:s"),
  228. // 'ownerName'=>date("Y-m-d H:i:s"),
  229. // 'departmentName'=>date("Y-m-d H:i:s"),
  230. 'sequenceNo' => $qrdno,
  231. 'sequenceStatus' => 1,
  232. 'ShortText1617022967356' => '网络部',
  233. 'text1617499162303'=>$goodNo,
  234. 'ShortText1617365292699' => $goodName,
  235. "ShortText1617367958909" => $rate['rate'].'%',
  236. 'text1617365646297'=>$poNo,
  237. "ShortText1618447165317"=>isset($company['company_name']) ? $company['company_name'] : "",
  238. "Number1617365688048" => $goodNum,
  239. 'ShortText1617650669915' => $qrdType,
  240. 'ShortText1617650701648' => $qrdno,
  241. "Number1618248810624" => $goodPrice,
  242. 'Number1618248813613' => $good_total,
  243. "Number1618249015661" => $goodNum,
  244. "number1618249149738" => $good_total,
  245. "Number1618249205231" => $good_total,
  246. 'ShortText1618446949933' => $contactor,
  247. 'ShortText1618446973813' => $mobile,
  248. 'LongText1618446982973' => $addr,
  249. 'ShortText1618559007040' => 3,
  250. 'ShortText1618559043560' => 1,
  251. 'ShortText1618559274859' => 1,
  252. "ShortText1617499192065"=>$cat_f,
  253. 'StaffSelector1619488013389' => $sale_name,
  254. 'ShortText1619523689586' => $department,
  255. 'ShortText1620750298602' => $supplierNo,
  256. 'ShortText1620750301301' => isset($supplier['name']) ? $supplier['name'] : "",
  257. 'Date1620370378620' => $sendtime,
  258. 'departmentName' => $department,
  259. 'ShortText1619542951283' => $khNo,
  260. 'ShortText1619523892833' => isset($cunstmer['companyName']) ? $cunstmer['companyName'] : "",
  261. 'StaffSelector1618445844046' => $sale_name,
  262. 'StaffSelector1618445850209' => $department,
  263. 'ownerName' => $sale_name,
  264. ];
  265. $data2 = [
  266. 'name'=>'网络部采购单',
  267. 'ownerName'=>$buyer,
  268. 'sequenceNo' => $Cgd,
  269. 'startTime' => date("Y-m-d H:i:s"),
  270. 'finishTime' => date("Y-m-d H:i:s"),
  271. "createdTime" => date("Y-m-d H:i:s"),
  272. "ShortText1618315935182"=>$Cgd,
  273. 'Date1618315953443'=>date("Y-m-d H:i:s"),
  274. "ShortText1617865626160" => $cat_f,
  275. "ShortText1617865688485" => $rate['rate']."%",
  276. "RelevanceForm1617861284547" => '',
  277. "ShortText1617866364821" => '',
  278. "ShortText1617866362204" => $qrdType,
  279. "ShortText1617866360004" =>$qrdno,
  280. "Number1618316157066" => $goodNum,
  281. "Number1618316171848" => 0,
  282. "ShortText1617861449444" => $contactor,
  283. "ShortText1617861455145" => $mobile,
  284. 'ShortText1617861001482'=>$goodNo,
  285. "ShortText1617861966146" => $goodName,
  286. "ShortText1618270466672" => isset($company['company_name'])?$company['company_name']:"",
  287. "Number1618330470625" => 0,
  288. "Number1618330472961" =>round($good_total*(1-$cgd_tax),2),
  289. "Number1618330541286" => 0,
  290. "Number1618330543270" =>round($good_total*(1-$cgd_tax),2),
  291. "StaffSelector1618885082387" => $buyer,
  292. "ShortText1619463188366" => 1,
  293. "ShortText1619463208482" => 1,
  294. "ShortText1620399144946" => isset($supplier['name']) ? $supplier['name'] : "",
  295. "ShortText1617861287265" => $supplierNo,
  296. "sequenceStatus" => 1,
  297. "department" => $buy_depart,
  298. "ShortText1618859321070"=>3,
  299. "ShortText1620753234895" => '',
  300. "ShortText1620753237335" => '',
  301. "Number1619625470651" => $goodNum,
  302. "Number1618240600907" => $goodNum,
  303. 'StaffSelector1620899427104'=>$buyer,
  304. 'Number1618240685904'=>round($good_total*(1-$cgd_tax),2)
  305. ];
  306. //var_dump($data);
  307. $td = [
  308. "return_ticket" => '',
  309. "return_trade" => '',
  310. "product_code" =>$goodNo,
  311. "product_name" => $goodName,
  312. "supplierNo" => $supplierNo,
  313. "suppierNo" => $supplierNo,
  314. 'companyNo'=>$khNo,
  315. "supplier" => isset($supplier['name']) ? $supplier['name'] : "",
  316. "cgd_tax" => $rate['rate']."%",
  317. "suplier_name" => isset($supplier['name']) ? $supplier['name'] : "",
  318. "unit" => '',
  319. 'ordertime'=>date("Y-m-d H:i:s"),
  320. "status" => 1,
  321. "productNo" => $qrdno,
  322. "order_num" => $goodNum,
  323. "sale_total" => $good_total,
  324. "sale_price" => $goodPrice,
  325. "apay_fee" => 0,
  326. "cat_f" =>$cat_f,
  327. "cgd_cat_f" =>$cat_f,
  328. "wpay_fee" => round($good_total*(1-$cgd_tax),2),
  329. "pay_status" => 1,
  330. "inv_fee" => 0,
  331. "winv_fee" => round($good_total*(1-$cgd_tax),2),
  332. "inv_status" => 1,
  333. "delivery_send" => $goodNum,
  334. "poNo" => $poNo,
  335. 'workNo'=>$sequenceNo,
  336. "qrdNo" => $qrdno,
  337. "qrd_type" => $qrdType,
  338. "qrd_ainv_fee" => 0,
  339. "qrd_winv_fee" => $good_total,
  340. "qrd_inv_status" => 1,
  341. "qrd_pay_status" => 1,
  342. "qrd_apay_fee" => 0,
  343. "qrd_wpay_fee" => $good_total,
  344. "qrd_invtime" => date("Y-m-d H:i:s"),
  345. "delivery_num" => $goodNum,
  346. "supperinfo" =>isset($company['company_name']) ? $company['company_name'] : "",
  347. "company" =>isset($company['company_name']) ? $company['company_name'] : "",
  348. "suppitem" => '网络部',
  349. "depart" => $department,
  350. "paytime" => date("Y-m-d H:i:s"),
  351. "cgdtime" => date("Y-m-d H:i:s"),
  352. "cgd_num" => $goodNum,
  353. "cgd_total" => round($good_total*(1-$cgd_tax),2),
  354. 'cgdNo'=>$Cgd,
  355. 'cgdjlNo'=>$Cgd,
  356. 'tax'=> $rate['rate']."%",
  357. "bktime" => date("Y-m-d H:i:s"),
  358. "saler" => $sale_name,
  359. "cgd_saler" => $buyer,
  360. "sale_name" => $sale_name,
  361. "cgd_good_name" => $goodName,
  362. "cgd_delivery_status" =>'已发',
  363. "delivery_wsend" => 0,
  364. "companyName" => isset($cunstmer['companyName']) ? $cunstmer['companyName'] : "",
  365. 'rate'=>$cgd_tax
  366. ];
  367. Db::startTrans();
  368. try {
  369. $a = Db::name("qrd_info")->insert($data);
  370. $d = Db::name("qrd")->insert($qrdData);
  371. $b = Db::name('cgd_info')->insert($data2);
  372. $c = Db::table('source_all')->insert($td);
  373. if ($a && $b && $c&&$d) {
  374. Db::commit();
  375. return app_show(0,'新建成功');
  376. } else {
  377. Db::rollback();
  378. return error_show(1004,'新建失败');
  379. }
  380. } catch (\Exception $e) {
  381. Db::rollback();
  382. return error_show(1004, $e->getMessage());
  383. }
  384. }
  385. public function edit(){
  386. $post = $this->request->post();
  387. $token = isset($post['token']) ? trim($post['token']) : "";
  388. if ($token == "") {
  389. return error_show(101, 'token不能为空');
  390. }
  391. $effetc = VerifyTokens($token);
  392. if (!empty($effetc) && $effetc['code'] != 0) {
  393. return error_show($effetc['code'], $effetc['message']);
  394. }
  395. $guserinfo = GetUserInfo($token);
  396. if (isset($guserinfo['code']) && $guserinfo['code'] != 0) {
  397. return error_show($guserinfo['code'], $guserinfo['message']);
  398. }
  399. $id = isset($post['id']) && $post['id'] != '' ? trim($post['id']) : '';
  400. if ($id == '') {
  401. return error_show(1004, "参数id 不能为空");
  402. }
  403. $source = Db::table('source_all')->where([['id',"=",$id]])->find();
  404. if(empty($source)){
  405. return error_show(1004, "数据未找到");
  406. }
  407. if(!isset($source['qrdNo'])||$source['qrdNo']==''){
  408. return error_show(1004, "数据未找到确认单号");
  409. }
  410. if(!isset($source['cgdNo'])||$source['cgdNo']==''){
  411. return error_show(1004, "数据未找到采购单号");
  412. }
  413. $qrd = Db::name('qrd')->where('sequenceNo',"=",$source['qrdNo'])->find();
  414. if(empty($qrd)){
  415. return error_show(1004, "确认单数据未找到");
  416. }
  417. $qrdinfo = Db::name('qrd_info')->where('ShortText1617650701648',"=",$source['qrdNo'])->find();
  418. if(empty($qrdinfo)){
  419. return error_show(1004, "确认单产品数据未找到");
  420. }
  421. $cat_f = isset($post['cat_f']) && $post['cat_f'] != '' ? $post['cat_f'] : '';
  422. if ($cat_f == '') {
  423. return error_show(1004, "参数cat_f 不能为空");
  424. }
  425. $cgdinfo = Db::name('cgd_info')->where('ShortText1618315935182',"=",$source['cgdNo'])->find();
  426. if(empty($cgdinfo)){
  427. return error_show(1004, "采购单数据未找到");
  428. }
  429. $pay = Db::name('pay_info')->alias('a')->join('cfp_pay b','a.payNo=b.payNo','left')->where("a.STATUS = 1
  430. AND (b.`status` = 2 or b.status=1) AND a.sequenceNo = '{$cgdinfo['sequenceNo']}' ")->find();
  431. if(!empty($pay)){
  432. return error_show(1004, "采购单数据正在对账中");
  433. }
  434. $qrdpay = Db::name('order_info')->alias('a')->join('cfp_order_pool b','a.orderNo = b.orderNo','left')
  435. ->where("a.status=1 and b.is_del=0 and a.qrdNo='{$source['qrdNo']}'")->find();
  436. if(!empty($qrdpay)){
  437. return error_show(1004, "确认单数据正在核算中");
  438. }
  439. $sale_name = isset($post['sale_name']) && $post['sale_name'] != '' ? trim($post['sale_name']) : '';
  440. if ($sale_name == '') {
  441. return error_show(1004, "参数sale_name 不能为空");
  442. }
  443. $poNo = isset($post['poNo']) && $post['poNo'] != '' ? trim($post['poNo']) : '';
  444. if ($poNo == '') {
  445. return error_show(1004, "参数poNo 不能为空");
  446. }
  447. $sequenceNo = isset($post['sequenceNo']) && $post['sequenceNo'] != '' ? trim($post['sequenceNo']) : '';
  448. if ($sequenceNo == '') {
  449. return error_show(1004, "参数sequenceNo 不能为空");
  450. }
  451. $department = isset($post['department']) && $post['department'] != '' ? trim($post['department']) : '网络部';
  452. $companyNo = isset($post['companyNo']) && $post['companyNo'] != '' ? trim($post['companyNo']) : '';
  453. if ($companyNo == '') {
  454. return error_show(1004, "参数companyNo 不能为空");
  455. }
  456. $company = Db::name("company_info")->where("companyNo","=",$companyNo)->find();
  457. if(empty($company)){
  458. return error_show(1004, "确认单销售公司未找到");
  459. }
  460. $khNo = isset($post['khNo']) && $post['khNo'] != '' ? trim($post['khNo']) : '';
  461. if ($khNo == '') {
  462. return error_show(1004, "参数khNo 不能为空");
  463. }
  464. $cunstmer = Db::name('customer_info')->where('companyNo', "=", $khNo)->find();
  465. if (empty($cunstmer)) {
  466. return error_show(1004, "客户信息未找到");
  467. }
  468. $qrdType = isset($post['qrdType']) && $post['qrdType'] != '' ? trim($post['qrdType']) : '';
  469. if ($qrdType == '') {
  470. return error_show(1004, "参数qrdType 不能为空");
  471. }
  472. $goodName = isset($post['goodName']) && $post['goodName'] != '' ? trim($post['goodName']) : '';
  473. if ($goodName == '') {
  474. return error_show(1004, "参数goodName 不能为空");
  475. }
  476. $tax = isset($post['tax']) && $post['tax'] != '' ? trim($post['tax']) : '';
  477. if ($tax == '') {
  478. return error_show(1004, "参数tax 不能为空");
  479. }
  480. $goodNum = isset($post['goodNum']) && $post['goodNum'] !== '' ? intval($post['goodNum']) : '';
  481. if ($goodNum === '') {
  482. return error_show(1004, "参数goodNum 不能为空");
  483. }
  484. $goodPrice = isset($post['goodPice']) && $post['goodPice'] !== '' ? $post['goodPice'] : '';
  485. if ($goodPrice == '') {
  486. return error_show(1004, "参数goodPrice 不能为空");
  487. }
  488. $good_total = isset($post['good_total']) && $post['good_total'] !== '' ? $post['good_total'] : '';
  489. if ($good_total == '') {
  490. return error_show(1004, "参数good_total 不能为空");
  491. }
  492. $contactor = isset($post['contactor']) && $post['contactor'] != '' ? trim($post['contactor']) : '';
  493. if ($contactor == '') {
  494. return error_show(1004, "参数contactor 不能为空");
  495. }
  496. $mobile = isset($post['mobile']) && $post['mobile'] != '' ? trim($post['mobile']) : '';
  497. if ($mobile == '') {
  498. return error_show(1004, "参数mobile 不能为空");
  499. }
  500. $addr = isset($post['addr']) && $post['addr'] != '' ? trim($post['addr']) : '';
  501. if ($addr == '') {
  502. return error_show(1004, "参数addr 不能为空");
  503. }
  504. $buyer = isset($post['buyer']) && $post['buyer'] != '' ? trim($post['buyer']) : '';
  505. if ($buyer == '') {
  506. return error_show(1004, "参数buyer 不能为空");
  507. }
  508. $buy_depart = isset($post['buy_depart']) && $post['buy_depart'] != '' ? trim($post['buy_depart']) : '';
  509. if ($buy_depart == '') {
  510. return error_show(1004, "参数buy_depart 不能为空");
  511. }
  512. $sendtime = isset($post['sendtime']) && $post['sendtime'] != '' ? $post['sendtime'] : '';
  513. if ($sendtime == '') {
  514. return error_show(1004, "参数sendtime 不能为空");
  515. }
  516. $supplierNo = isset($post['supplierNo']) && $post['supplierNo'] != '' ? trim($post['supplierNo']) : '';
  517. if ($supplierNo == '') {
  518. return error_show(1004, "参数supplierNo 不能为空");
  519. }
  520. $supplier = Db::name('supplier_info')->where('code', "=", $supplierNo)->find();
  521. if (empty($supplier)) {
  522. return error_show(1004, "供应商信息未找到");
  523. }
  524. $cgd_tax = isset($post['cgd_tax']) && $post['cgd_tax'] !== '' ? round($post['cgd_tax']/100,4) : '';
  525. if ($cgd_tax === '') {
  526. return error_show(1004, "参数cgd_tax 不能为空");
  527. }
  528. $rate = Db::name('order_rate')->where('id',"=",$tax)->find();
  529. if(empty($rate)){
  530. return error_show(1004, "税率数据未找到");
  531. }
  532. $qrdData=[
  533. "name"=>'网络部确认单'.$sequenceNo,
  534. 'createdTime'=>date("Y-m-d H:i:s"),
  535. 'sales_name'=>$sale_name,
  536. 'sales_depart'=>$department,
  537. 'customer'=>isset($cunstmer['companyName']) ? $cunstmer['companyName'] : "",
  538. 'total_fee'=>$good_total,
  539. 'mobile'=>$mobile,
  540. 'contactor'=>$contactor,
  541. 'qrddate'=>date("Y-m-d H:i:s"),
  542. 'companyNo'=>$khNo,
  543. 'supplerName'=>isset($company['company_name']) ?$company['company_name']: "",
  544. 'addr'=>$addr,
  545. 'depart'=>$department,
  546. 'wpay_fee'=>$good_total,
  547. 'winv_fee'=>$good_total,
  548. 'updatetime'=>date("Y-m-d H:i:s")
  549. ];
  550. $data = [
  551. 'ShortText1617365292699' => $goodName,
  552. "ShortText1617367958909" => $rate['rate'].'%',
  553. 'text1617365646297'=>$poNo,
  554. "Number1617365688048" => $goodNum,
  555. 'ShortText1617650669915' => $qrdType,
  556. "Number1618248810624" => $goodPrice,
  557. 'Number1618248813613' => $good_total,
  558. "Number1618249015661" => $goodNum,
  559. "number1618249149738" => $good_total,
  560. "Number1618249205231" => $good_total,
  561. 'ShortText1618446949933' => $contactor,
  562. 'ShortText1618446973813' => $mobile,
  563. 'LongText1618446982973' => $addr,
  564. "ShortText1617499192065"=>$cat_f,
  565. 'StaffSelector1619488013389' => $sale_name,
  566. 'ShortText1619523689586' => $department,
  567. 'ShortText1620750298602' => $supplierNo,
  568. 'ShortText1620750301301' => isset($supplier['name']) ? $supplier['name'] : "",
  569. 'Date1620370378620' => $sendtime,
  570. 'departmentName' => $department,
  571. 'ShortText1619542951283' => $khNo,
  572. "ShortText1618447165317"=>isset($company['company_name']) ? $company['company_name'] : "",
  573. 'ShortText1619523892833' => isset($cunstmer['companyName']) ? $cunstmer['companyName'] : "",
  574. 'StaffSelector1618445844046' => $sale_name,
  575. 'StaffSelector1618445850209' => $department,
  576. 'ownerName' => $sale_name,
  577. 'finishTime'=>date("Y-m-d H:i:s")
  578. ];
  579. $data2 = [
  580. 'ownerName'=>$buyer,
  581. "ShortText1617865688485" => $rate['rate']."%",
  582. "ShortText1617866362204" => $qrdType,
  583. "Number1618316157066" => $goodNum,
  584. "Number1618316171848" => 0,
  585. "ShortText1617861449444" => $contactor,
  586. "ShortText1617861455145" => $mobile,
  587. "ShortText1617861966146" => $goodName,
  588. "Number1618330472961" => round($good_total*(1-$cgd_tax),2),
  589. "Number1618330543270" => round($good_total*(1-$cgd_tax),2),
  590. "StaffSelector1618885082387" => $buyer,
  591. "ShortText1620399144946" => isset($supplier['name']) ? $supplier['name'] : "",
  592. "ShortText1617861287265" => $supplierNo,
  593. "department" => $buy_depart,
  594. "ShortText1618859321070"=>3,
  595. "ShortText1617865626160"=>$cat_f,
  596. "Number1619625470651" => $goodNum,
  597. "Number1618240600907" => $goodNum,
  598. "ShortText1618270466672" => isset($company['company_name'])?$company['company_name']:"",
  599. 'Number1618240685904'=>round($good_total*(1-$cgd_tax),2),
  600. 'finishTime'=>date("Y-m-d H:i:s")
  601. ];
  602. //var_dump($data);
  603. $td = [
  604. "product_name" => $goodName,
  605. 'companyNo'=>$khNo,
  606. "supplierNo" => $supplierNo,
  607. "suppierNo" => $supplierNo,
  608. "supplier" => isset($supplier['name']) ? $supplier['name'] : "",
  609. "cgd_tax" => $rate['rate']."%",
  610. "suplier_name" => isset($supplier['name']) ? $supplier['name'] : "",
  611. "order_num" => $goodNum,
  612. "sale_total" => $good_total,
  613. "sale_price" => $goodPrice,
  614. "wpay_fee" => round($good_total*(1-$cgd_tax),2),
  615. "winv_fee" => round($good_total*(1-$cgd_tax),2),
  616. "delivery_send" => $goodNum,
  617. "poNo" => $poNo,
  618. "cat_f" =>$cat_f,
  619. "cgd_cat_f" =>$cat_f,
  620. 'workNo'=>$sequenceNo,
  621. "qrd_type" => $qrdType,
  622. "qrd_winv_fee" => $good_total,
  623. "qrd_wpay_fee" => $good_total,
  624. "delivery_num" => $goodNum,
  625. "depart" => $department,
  626. "cgd_num" => $goodNum,
  627. "cgd_total" => round($good_total*(1-$cgd_tax),2),
  628. 'tax'=> $rate['rate']."%",
  629. "saler" => $sale_name,
  630. "cgd_saler" => $buyer,
  631. "sale_name" => $sale_name,
  632. "cgd_good_name" => $goodName,
  633. "delivery_wsend" => 0,
  634. "companyName" => isset($cunstmer['companyName']) ? $cunstmer['companyName'] : "",
  635. "supperinfo" =>isset($company['company_name']) ? $company['company_name'] : "",
  636. "company" =>isset($company['company_name']) ? $company['company_name'] : "",
  637. 'rate'=>$cgd_tax,
  638. 'cgdtime'=>date("Y-m-d H:i:s")
  639. ];
  640. Db::startTrans();
  641. try {
  642. $a = Db::name("qrd_info")->where('id','=',$qrdinfo['id'])->save($data);
  643. $d = Db::name("qrd")->where('id','=',$qrd['id'])->save($qrdData);
  644. $b = Db::name('cgd_info')->where('id','=',$cgdinfo['id'])->save($data2);
  645. $c = Db::table('source_all')->where('id','=',$id)->save($td);
  646. if ($a && $b && $c&&$d) {
  647. Db::commit();
  648. return app_show(0,'修改成功');
  649. } else {
  650. Db::rollback();
  651. return error_show(1004,'修改失败');
  652. }
  653. } catch (\Exception $e) {
  654. Db::rollback();
  655. return error_show(1004, $e->getMessage());
  656. }
  657. }
  658. public function info(){
  659. $post=$this->request->post();
  660. $id = isset($post['id'])&&$post['id']!='' ? $post['id'] :"";
  661. $condition = [['a.id',"=",$id]];
  662. $list=Db::table('source_all')->alias('a')->join('cfp_qrd_info b','a.productNo=b.sequenceNo','left')
  663. ->join('cfp_cgd_info c','a.cgdNo=c.ShortText1618315935182','left')->where($condition)
  664. ->order("a.ordertime desc")->field('a.id,
  665. a.productNo as qrdcpNo,
  666. a.qrdNo,
  667. a.companyNo as khNo,
  668. a.companyName as knName,
  669. a.supperinfo,
  670. a.suppitem,
  671. a.poNo,
  672. a.workNo as sequenceNo,
  673. a.ordertime,
  674. a.sale_name,
  675. a.depart as department,
  676. a.product_name as goodName,
  677. a.tax,
  678. a.cat_f,
  679. a.sale_price as goodPice,
  680. a.order_num as goodNum,
  681. a.sale_total as good_total,
  682. a.qrd_type as qrdType,
  683. a.supplier,
  684. a.supplierNo,
  685. a.cgdNo,
  686. a.cgd_saler as buyer,
  687. c.department as buy_depart,
  688. b.Date1620370378620 as sendtime,
  689. a.rate*100 as cgd_tax,
  690. b.ShortText1618446949933 as contactor,
  691. b.ShortText1618446973813 as mobile,
  692. b.LongText1618446982973 as addr
  693. ')->find();
  694. if(empty($list)){
  695. return error_show(1004,'未找到数据');
  696. }
  697. $company = Db::name('company_info')->where('company_name',"=",$list['supperinfo'])->find();
  698. $list['companyNo'] = isset($company['companyNo']) ? $company['companyNo']:"";
  699. $rateid = Db::name("order_rate")->where('rate',"=",str_replace("%","",$list['tax']))->find();
  700. $list['rateid'] = isset($rateid['id'])?$rateid['id'] : 0;
  701. return app_show(0,"获取成功",$list);
  702. }
  703. public function getCat(){
  704. $post=$this->request->post();
  705. $condition = [['status',"=",1]];
  706. $pid = isset($post['pid'])&&$post['pid']!==""? $post['pid'] :'0';
  707. if($pid!==''){
  708. $condition[]=["pid","=",$pid];
  709. }
  710. $level= isset($post['level'])&&$post['level']!==""? $post['level'] :'1';
  711. if($level!=""){
  712. $condition[]=["level","=",$level];
  713. }
  714. $cat = Db::name("cat")->where($condition)->field("id,cat_name,level")->order("weight desc ,addtime desc")
  715. ->select();
  716. return app_show(0,"获取成功",$cat);
  717. }
  718. }