Sale.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\CgdInfo;use app\admin\model\GoodCombind;use app\admin\model\InvoiceOrder;use app\admin\model\InvoicePool;use app\admin\model\OrderCategory;use app\admin\model\Pay;use app\admin\model\PayInvoice;use app\admin\model\QrdInfo;use app\admin\model\TradePool;use think\App;use think\facade\Db;use think\facade\Validate;
  4. class Sale extends Base{
  5. public function __construct(App $app) {
  6. parent::__construct($app);
  7. }
  8. /** 获取列表
  9. * @return \think\response\Json|void
  10. * @throws \think\db\exception\DataNotFoundException
  11. * @throws \think\db\exception\DbException
  12. * @throws \think\db\exception\ModelNotFoundException
  13. */
  14. public function list(){
  15. $post =$this->request->param();
  16. $condition = [['a.is_del',"=",0]];
  17. $roleid = $this->roleid;
  18. $check = checkRole($roleid,'86');
  19. if($check){
  20. $condition[]=["a.ownerid","=",$this->uid];
  21. }
  22. $page = isset($post['page'])&&$post['page']!==''?intval($post['page']):1;
  23. $size = isset($post['size'])&&$post['size']!==''?intval($post['size']):15;
  24. $start =isset($post['start'])&&$post['start']!==''?trim($post['start']):'';
  25. if($start!=''){
  26. $condition[]=["a.createdTime",">=",$start." 00:00:00"];
  27. }
  28. $end =isset($post['end'])&&$post['end']!==''?trim($post['end']):'';
  29. if($end!=''){
  30. $condition[]=["a.createdTime","<=",$end." 23:59:59"];
  31. }
  32. $total_min = isset($post['total_min'])&&$post['total_min']!==''?floatval($post['total_min']):'';
  33. if($total_min!==''){
  34. $condition[]=["a.totalPrice",">=",$total_min];
  35. }
  36. $total_max = isset($post['total_max'])&&$post['total_max']!==''?floatval($post['total_max']):'';
  37. if($total_max!==''){
  38. $condition[]=["a.totalPrice","<=",$total_max];
  39. }
  40. if(isset($post['is_comon'])&&$post['is_comon']!=='') $condition []=['is_comon','=',$post['is_comon']];
  41. $cxCode =$post['cxCode']??[];
  42. if(!empty($cxCode)){
  43. $condition[]=["a.cxCode","in",$cxCode];
  44. }
  45. $inv_status = isset($post['inv_status'])&&$post['inv_status']!==''?intval($post['inv_status']):'';
  46. if($inv_status!==''){
  47. if($inv_status==0){
  48. $condition[]=["a.inv_status","<>",3];
  49. }else{
  50. $condition[]=["a.inv_status","=",$inv_status];
  51. }
  52. }
  53. $invIs = isset($post['inv_is'])&&$post['inv_is']!==''?intval($post['inv_is']):'';
  54. if($invIs!==''){
  55. if($invIs==1){
  56. $condition[]=["a.winv_fee","<>",0];
  57. }else{
  58. $condition[]=["a.winv_fee","=",0];
  59. }
  60. }
  61. $payIs = isset($post['pay_is'])&&$post['pay_is']!==''?intval($post['pay_is']):'';
  62. if($payIs!==''){
  63. if($payIs==1){
  64. $condition[]=["a.wpay_fee","<>",0];
  65. }else{
  66. $condition[]=["a.wpay_fee","=",0];
  67. }
  68. }
  69. $pay_status = isset($post['pay_status'])&&$post['pay_status']!==''?intval($post['pay_status']):'';
  70. if($pay_status!==''){
  71. if($pay_status==0){
  72. $condition[]=["a.pay_status","<>",3];
  73. }else{
  74. $condition[]=["a.pay_status","=",$pay_status];
  75. }
  76. }
  77. $status = isset($post['status'])&&$post['status']!==''?intval($post['status']):'';
  78. if($status!==''){
  79. if($status==3){
  80. $condition[]=["a.status","<>",2];
  81. }else{
  82. $condition[]=["a.status","=",$status];
  83. }
  84. }
  85. $poCode = isset($post['poCode']) && $post['poCode'] !== '' ? trim($post['poCode']) : '';
  86. if ($poCode !== '') {
  87. $condition[] = ['a.poCode', 'like', "%$poCode%"];
  88. }
  89. $qrdNo = isset($post['sequenceNo'])&&$post['sequenceNo']!=''?trim($post['sequenceNo']):'';
  90. if($qrdNo!==''){
  91. $condition[]=["a.sequenceNo","like","%$qrdNo%"];
  92. }
  93. $department = isset($post['department'])&&$post['department']!=''?trim($post['department']):'';
  94. if($department!==''){
  95. $condition[]=["a.department","like","%$department%"];
  96. }
  97. $customerNo = isset($post['customerNo'])&&$post['customerNo']!=''?trim($post['customerNo']):'';
  98. if($customerNo!==''){
  99. $condition[]=["a.customerNo","like","%$customerNo%"];
  100. }
  101. $customer = isset($post['customer'])&&$post['customer']!=''?trim($post['customer']):'';
  102. if($customer!=''){
  103. $condition[]=["a.customerName","like","%$customer%"];
  104. }
  105. $companyNo = isset($post['companyNo'])&&$post['companyNo']!=''?trim($post['companyNo']):'';
  106. if($companyNo!==''){
  107. $condition[]=["a.companyNo","=",$companyNo];
  108. }
  109. $companyName = isset($post['companyName'])&&$post['companyName']!=''?trim($post['companyName']):'';
  110. if($companyName !=''){
  111. $condition[]=["a.companyName","like","%$companyName%"];
  112. }
  113. $platName = isset($post['platName'])&&$post['platName']!=''?trim($post['platName']):'';
  114. if($platName!=''){
  115. $condition[]=["a.platName","like","%$platName%"];
  116. }
  117. $platform_type = isset($post['platform_type'])&&$post['platform_type']!==''?intval($post['platform_type']):'';
  118. if($platform_type!==''){
  119. $condition[]=["a.platform_type","=",$platform_type];
  120. }
  121. $saler= isset($post['saler']) && $post['saler']!='' ? trim($post['saler']) :"";
  122. if($saler!='') $condition []=["a.ownerName","like","%$saler%"];
  123. $salerid= isset($post['salerid']) && $post['salerid']!='' ? intval($post['salerid']) :"";
  124. if($salerid!='') $condition []=["a.ownerid","=",$salerid];
  125. $qrdtype= isset($post['qrdtype']) && $post['qrdtype']!='' ? intval($post['qrdtype']) :"";
  126. if($qrdtype!='') $condition []=["a.qrdType","=",$qrdtype];
  127. $qrdsource= isset($post['qrdsource']) && $post['qrdsource']!='' ? intval($post['qrdsource']) :"";
  128. if($qrdsource!='') $condition []=["a.qrdSource","=",$qrdsource];
  129. $sendstatus= isset($post['sendstatus']) && $post['sendstatus']!='' ? intval($post['sendstatus']) :"";
  130. if($sendstatus!='') $condition []=["a.sendStatus","=",$sendstatus];
  131. $tag_id= isset($post['tag_id'])&&$post['tag_id']!=="" ? intval($post['tag_id']) :"";
  132. if($tag_id!==''){
  133. if($tag_id==1) $condition[]=["a.inv_tag","=",1];
  134. if($tag_id==2) $condition[]=["a.pay_tag","=",1];
  135. if($tag_id==3) $condition[]=["a.pay_tag|inv_tag","=",1];
  136. if($tag_id==4) $condition[]=["a.pay_tag&inv_tag","=",1];
  137. }
  138. $cat_status= isset($post['cat_status'])&&$post['cat_status']!=="" ? intval($post['cat_status']) :"";
  139. if($cat_status!=='') $condition[]=["b.status","=",$cat_status];
  140. $goodNo= isset($post['goodNo'])&&$post['goodNo']!=="" ? trim($post['goodNo']) :"";
  141. if($goodNo!=='') $condition[]=["a.goodNo","like","%$goodNo%"];
  142. $goodName= isset($post['goodName'])&&$post['goodName']!=="" ? trim($post['goodName']) :"";
  143. if($goodName!=='') $condition[]=["a.goodName","like","%$goodName%"];
  144. $count =Db::name("qrd_info")
  145. ->alias("a")
  146. ->leftJoin("good b","a.goodNo=b.spuCode")->where($condition)->count();
  147. $total = ceil($count/$size);
  148. $page = $page>$total ? intval($total) : $page;
  149. $list =Db::name("qrd_info")->alias("a")
  150. ->leftJoin("good b","a.goodNo=b.spuCode")
  151. ->field("a.*,b.status as cat_status,b.inv_cat_name,b.inv_cat_code,b.inv_tax,b.inv_good_name,b.isZx")
  152. ->order("a.createdTime desc")
  153. ->where($condition)->page($page,$size)->select();
  154. $data=[];
  155. foreach ( $list as $ky=>$value){
  156. $value['orderTax'] = OrderCategory::where(['code' => $value['sequenceNo'], 'spuCode' => $value['goodNo']])
  157. ->field(['cat_code', 'cat_name', 'merge_code', 'short_name', 'tax', 'inv_good_name'])->findOrEmpty();
  158. $value['catInfo'] = json_decode($value['catInfo'],true);
  159. $value['inv_tag_name']='';
  160. $value['pay_tag_name']='';
  161. $value['pay_tag_img']='';
  162. $value['inv_tag_id']='0';
  163. $value['pay_tag_id']='0';
  164. $value['pay_tag_remark']='';
  165. $value['inv_tag_img']='';
  166. $value['inv_tag_remark']='';
  167. if($value['pay_tag']==1 || $value['inv_tag']==1){
  168. $tag =Db::name("tag_log")->alias("a")->leftJoin("order_tag b","a.tag_id=b.id")->where
  169. (["code"=>$value['sequenceNo'],"a.status"=>[1,2]])->order("a.id desc")->column("a.id,b.tag_name,a.tag_img,a.tag_remark","b.type");
  170. if($value['inv_tag']==1){
  171. $value['inv_tag_name']=$tag[4]['tag_name']??'';
  172. $value['inv_tag_id']=$tag[4]['id']??'0';
  173. $value['inv_tag_img']=$tag[4]['tag_img']??'';
  174. $value['inv_tag_remark']=$tag[4]['tag_remark']??'';
  175. }
  176. if($value['pay_tag']==1){
  177. $value['pay_tag_id']=$tag[3]['id']??'0';
  178. $value['pay_tag_name']=$tag[3]['tag_name']??'';
  179. $value['pay_tag_img']=$tag[3]['tag_img']??'';
  180. $value['pay_tag_remark']=$tag[3]['tag_remark']??'';
  181. }
  182. }
  183. $value['plat_pay_fee']=0;
  184. if($value['is_comon']==1){
  185. $tax = QrdInfo::where(['cxCode'=>$value['cxCode'],'is_comon'=>0])->findOrEmpty();
  186. if($tax->isEmpty()==false){
  187. $rate =$tax->totalPrice==0?0: ($tax->apay_fee/$tax->totalPrice);
  188. $value['plat_pay_fee']= round($value['totalPrice']* $rate,2);
  189. }
  190. }
  191. $value['goodNum'] = $value['goodNum'] -$value['thNum'];
  192. $value['sendNum'] = $value['sendNum'] -$value['thNum'];
  193. $invArr = Db::name("assoc")
  194. ->alias("a")
  195. ->leftJoin("invoice_good b", "a.viceCode=b.invNo AND b.orderCode =a.orderCode")
  196. ->where(["a.status" => [1, 2], "a.is_del" => 0, "a.type" => 1, "a.orderCode" => $value['sequenceNo']])->group("a.status")
  197. ->column("sum(b.goodNum) as goodNum", "a.status");
  198. $value['inv_num'] = $invArr[1]??0;
  199. $value['ainv_num'] = $invArr[2]??0;
  200. $value['winv_num'] =$value['goodNum']- $value['inv_num']-$value['ainv_num'];
  201. $data[]=$value;
  202. }
  203. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  204. }
  205. public function query(){
  206. $post =$this->request->param();
  207. $condition = [['a.is_del',"=",0]];
  208. $start =isset($post['start'])&&$post['start']!==''?trim($post['start']):'';
  209. if($start!=''){
  210. $condition[]=["a.createdTime",">=",$start." 00:00:00"];
  211. }
  212. $end =isset($post['end'])&&$post['end']!==''?trim($post['end']):'';
  213. if($end!=''){
  214. $condition[]=["a.createdTime","<=",$end." 23:59:59"];
  215. }
  216. $total_min = isset($post['total_min'])&&$post['total_min']!==''?floatval($post['total_min']):'';
  217. if($total_min!==''){
  218. $condition[]=["a.totalPrice",">=",$total_min];
  219. }
  220. if(isset($post['is_comon'])&&$post['is_comon']!=='') $condition []=['is_comon','=',$post['is_comon']];
  221. $total_max = isset($post['total_max'])&&$post['total_max']!==''?floatval($post['total_max']):'';
  222. if($total_max!==''){
  223. $condition[]=["a.totalPrice","<=",$total_max];
  224. }
  225. $cxCode =$post['cxCode']??[];
  226. if(!empty($cxCode)){
  227. $condition[]=['a.cxCode','in',$cxCode];
  228. }
  229. $inv_status = isset($post['inv_status'])&&$post['inv_status']!==''?intval($post['inv_status']):'';
  230. if($inv_status!==''){
  231. if($inv_status==0){
  232. $condition[]=["a.inv_status","<>",3];
  233. }else{
  234. $condition[]=["a.inv_status","=",$inv_status];
  235. }
  236. }
  237. $invIs = isset($post['inv_is'])&&$post['inv_is']!==''?intval($post['inv_is']):'';
  238. if($invIs!==''){
  239. if($invIs==1){
  240. $condition[]=["a.winv_fee","<>",0];
  241. }else{
  242. $condition[]=["a.winv_fee","=",0];
  243. }
  244. }
  245. $payIs = isset($post['pay_is'])&&$post['pay_is']!==''?intval($post['pay_is']):'';
  246. if($payIs!==''){
  247. if($payIs==1){
  248. $condition[]=["a.wpay_fee","<>",0];
  249. }else{
  250. $condition[]=["a.wpay_fee","=",0];
  251. }
  252. }
  253. $pay_status = isset($post['pay_status'])&&$post['pay_status']!==''?intval($post['pay_status']):'';
  254. if($pay_status!==''){
  255. if($pay_status==0){
  256. $condition[]=["a.pay_status","<>",3];
  257. }else{
  258. $condition[]=["a.pay_status","=",$pay_status];
  259. }
  260. }
  261. $status = isset($post['status'])&&$post['status']!==''?intval($post['status']):'';
  262. if($status!==''){
  263. if($status==3){
  264. $condition[]=["a.status","<>",2];
  265. }else{
  266. $condition[]=["a.status","=",$status];
  267. }
  268. }
  269. $qrdNo = isset($post['sequenceNo'])&&$post['sequenceNo']!=''?trim($post['sequenceNo']):'';
  270. if($qrdNo!==''){
  271. $condition[]=["a.sequenceNo","in",explode(",",$qrdNo)];
  272. }
  273. $department = isset($post['department'])&&$post['department']!=''?trim($post['department']):'';
  274. if($department!==''){
  275. $condition[]=["a.department","like","%$department%"];
  276. }
  277. $customerNo = isset($post['customerNo'])&&$post['customerNo']!=''?trim($post['customerNo']):'';
  278. if($customerNo!==''){
  279. $condition[]=["a.customerNo","like","%$customerNo%"];
  280. }
  281. $customer = isset($post['customer'])&&$post['customer']!=''?trim($post['customer']):'';
  282. if($customer!=''){
  283. $condition[]=["a.customerName","like","%$customer%"];
  284. }
  285. $companyNo = isset($post['companyNo'])&&$post['companyNo']!=''?trim($post['companyNo']):'';
  286. if($companyNo!==''){
  287. $condition[]=["a.companyNo","=",$companyNo];
  288. }
  289. $companyName = isset($post['companyName'])&&$post['companyName']!=''?trim($post['companyName']):'';
  290. if($companyName !=''){
  291. $condition[]=["a.companyName","like","%$companyName%"];
  292. }
  293. $platName = isset($post['platName'])&&$post['platName']!=''?trim($post['platName']):'';
  294. if($platName!=''){
  295. $condition[]=["a.platName","like","%$platName%"];
  296. }
  297. $platform_type = isset($post['platform_type'])&&$post['platform_type']!==''?intval($post['platform_type']):'';
  298. if($platform_type!==''){
  299. $condition[]=["a.platform_type","=",$platform_type];
  300. }
  301. $saler= isset($post['saler']) && $post['saler']!='' ? trim($post['saler']) :"";
  302. if($saler!='') $condition []=["a.ownerName","like","%$saler%"];
  303. $salerid= isset($post['salerid']) && $post['salerid']!='' ? intval($post['salerid']) :"";
  304. if($salerid!='') $condition []=["a.ownerid","=",$salerid];
  305. $qrdtype= isset($post['qrdtype']) && $post['qrdtype']!='' ? intval($post['qrdtype']) :"";
  306. if($qrdtype!='') $condition []=["a.qrdType","=",$qrdtype];
  307. $qrdsource= isset($post['qrdsource']) && $post['qrdsource']!='' ? intval($post['qrdsource']) :"";
  308. if($qrdsource!='') $condition []=["a.qrdSource","=",$qrdsource];
  309. $sendstatus= isset($post['sendstatus']) && $post['sendstatus']!='' ? intval($post['sendstatus']) :"";
  310. if($sendstatus!='') $condition []=["a.sendStatus","=",$sendstatus];
  311. $tag_id= isset($post['tag_id'])&&$post['tag_id']!=="" ? intval($post['tag_id']) :"";
  312. if($tag_id!==''){
  313. if($tag_id==1) $condition[]=["a.inv_tag","=",1];
  314. if($tag_id==2) $condition[]=["a.pay_tag","=",1];
  315. if($tag_id==3) $condition[]=["a.pay_tag|inv_tag","=",1];
  316. if($tag_id==4) $condition[]=["a.pay_tag&inv_tag","=",1];
  317. }
  318. $poCode = isset($post['poCode']) && $post['poCode'] !== '' ? trim($post['poCode']) : '';
  319. if ($poCode !== '') {
  320. $condition[] = ['a.poCode', 'like', "%$poCode%"];
  321. }
  322. $cat_status= isset($post['cat_status'])&&$post['cat_status']!=="" ? intval($post['cat_status']) :"";
  323. if($cat_status!=='') $condition[]=["b.status","=",$cat_status];
  324. $list =Db::name("qrd_info")->alias("a")
  325. ->leftJoin("good b","a.goodNo=b.spuCode")
  326. ->field("a.*,b.status as cat_status,b.inv_cat_name,b.inv_cat_code,b.inv_tax,b.inv_good_name,b.isZx")
  327. ->order("a.createdTime desc")
  328. ->where($condition)->select();
  329. $data=[];
  330. foreach ( $list as $ky=>$value){
  331. $value['catInfo'] = json_decode($value['catInfo'],true);
  332. $value['inv_tag_name']='';
  333. $value['pay_tag_name']='';
  334. $value['pay_tag_img']='';
  335. $value['inv_tag_id']='0';
  336. $value['pay_tag_id']='0';
  337. $value['pay_tag_remark']='';
  338. $value['inv_tag_img']='';
  339. $value['inv_tag_remark']='';
  340. if($value['pay_tag']==1 || $value['inv_tag']==1){
  341. $tag =Db::name('tag_log')->alias('a')->leftJoin('order_tag b','a.tag_id=b.id')->where
  342. (['code'=>$value['sequenceNo'],'a.status'=>[1,2]])->order('id desc')->column('a.id,b.tag_name,a.tag_img,a.tag_remark','b.type');
  343. if($value['inv_tag']==1){
  344. $value['inv_tag_name']=$tag[4]['tag_name']??'';
  345. $value['inv_tag_id']=$tag[4]['id']??'0';
  346. $value['inv_tag_img']=$tag[4]['tag_img']??'';
  347. $value['inv_tag_remark']=$tag[4]['tag_remark']??'';
  348. }
  349. if($value['pay_tag']==1){
  350. $value['pay_tag_id']=$tag[3]['id']??'0';
  351. $value['pay_tag_name']=$tag[3]['tag_name']??'';
  352. $value['pay_tag_img']=$tag[3]['tag_img']??'';
  353. $value['pay_tag_remark']=$tag[3]['tag_remark']??'';
  354. }
  355. }
  356. $value['goodNum'] = $value['goodNum'] -$value['thNum'];
  357. $value['sendNum'] = $value['sendNum'] -$value['thNum'];
  358. $value['plat_pay_fee']=0;
  359. if($value['is_comon']==1){
  360. $tax = QrdInfo::where(["cxCode"=>$value['cxCode'],"is_comon"=>0])->findOrEmpty();
  361. if($tax->isEmpty()==false){
  362. $rate = $tax->totalPrice==0?0: ($tax->apay_fee/$tax->totalPrice);
  363. $value['plat_pay_fee']= round($value['totalPrice']* $rate,2);
  364. }
  365. }
  366. $invArr = Db::name("assoc")
  367. ->alias("a")
  368. ->leftJoin("invoice_good b", "a.viceCode=b.invNo AND b.orderCode =a.orderCode")
  369. ->where(["a.status" => [1, 2], "a.is_del" => 0, "a.type" => 1, "a.orderCode" => $value['sequenceNo']])->group("a.status")
  370. ->column("sum(b.goodNum) as goodNum", "a.status");
  371. $value['inv_num'] = $invArr[1]??0;
  372. $value['ainv_num'] = $invArr[2]??0;
  373. $value['winv_num'] =$value['goodNum']- $value['inv_num']-$value['ainv_num'];
  374. $data[]=$value;
  375. }
  376. return app_show(0,"获取成功",$data);
  377. }
  378. /**
  379. * 更改销售单状态 是否需要回款 0 未回款对账 1 回款对账 2 无需汇款操作
  380. */
  381. public function status(){
  382. $post =$this->request->only(["sequenceNo"=>'',"status"=>0],"post","trim");
  383. if($post['sequenceNo']==''){
  384. return error_show(1004,"参数 sequenceNo 不能为空");
  385. }
  386. if($post['status']===''){
  387. return error_show(1004,"参数 status 不能为空");
  388. }
  389. $qrdinfo =Db::name("qrd_info")->where("sequenceNo","=",$post['sequenceNo'])->findOrEmpty();
  390. if(empty($qrdinfo)){
  391. return error_show(1004,"未找到确认单信息");
  392. }
  393. if ($qrdinfo['status']==1){
  394. return error_show(1004,"确认单已参与对账");
  395. }
  396. $update=[
  397. "status"=>$post['status'],
  398. "updatetime"=>date("Y-m-d H:i:s")
  399. ];
  400. $up =Db::name("qrd_info")->where($qrdinfo)->update($update);
  401. if($up){
  402. return app_show(0,"更新成功");
  403. }else{
  404. return error_show(1003,"更新失败");
  405. }
  406. }
  407. //确认单信息详情
  408. public function saleinfo(){
  409. $post=$this->post;
  410. $sequenceNo =isset($post['sequenceNo'])&&$post['sequenceNo']?trim($post['sequenceNo']):"";
  411. if($sequenceNo==''){
  412. return error_show(1003,"参数 sequenceNo 不能为空");
  413. }
  414. $qrdinfo =Db::name("qrd_info")->where("sequenceNo","=",$post['sequenceNo'])->findOrEmpty();
  415. if(empty($qrdinfo)){
  416. return error_show(1004,"未找到确认单信息");
  417. }
  418. $goodinfo = Db::name("good")->where(["spuCode"=>$qrdinfo["goodNo"]])->findOrEmpty();
  419. $qrdinfo['goodinfo'] =$goodinfo;
  420. $qrdinfo['catInfo'] = json_decode($qrdinfo['catInfo'],true);
  421. $qrdinfo['inv_tag_name']='';
  422. $qrdinfo['pay_tag_name']='';
  423. $qrdinfo['pay_tag_img']='';
  424. $qrdinfo['inv_tag_id']='0';
  425. $qrdinfo['pay_tag_id']='0';
  426. $qrdinfo['pay_tag_remark']='';
  427. $qrdinfo['inv_tag_img']='';
  428. $qrdinfo['inv_tag_remark']='';
  429. $qrdinfo['orderTax']=OrderCategory::where(['code' => $qrdinfo['sequenceNo'], 'spuCode' => $qrdinfo['goodNo']])
  430. ->field(['cat_code', 'cat_name', 'merge_code', 'short_name', 'tax', 'inv_good_name'])->findOrEmpty();
  431. $qrdinfo['child']=[];
  432. if(isset($goodinfo['isCombind'])&&$goodinfo['isCombind']==1){
  433. $list=(new GoodCombind())->where('spuCode',$qrdinfo['goodNo'])->visible(['child'])->with(['child'])
  434. ->select();
  435. if(!$list->isEmpty()){
  436. $qrdinfo['child']=array_column($list->toArray(),'child');
  437. foreach ($qrdinfo['child'] as &$value){
  438. $value['orderTax'] = OrderCategory::where(['code' => $qrdinfo['sequenceNo'], 'spuCode' => $value['spuCode']])
  439. ->field(['cat_code', 'cat_name', 'merge_code', 'short_name', 'tax', 'inv_good_name'])->findOrEmpty();;
  440. }
  441. }
  442. } ;
  443. if($qrdinfo['pay_tag']==1 || $qrdinfo['inv_tag']==1){
  444. $tag =Db::name('tag_log')->alias('a')->leftJoin('order_tag b','a.tag_id=b.id')
  445. ->where(['code'=>$qrdinfo['sequenceNo'],'a.status'=>[1,2]])->order('id desc')->column('a.id,b.tag_name,a.tag_img,a.tag_remark','b.type');
  446. if($qrdinfo['inv_tag']==1){
  447. $qrdinfo['inv_tag_name']=$tag[4]['tag_name']??'';
  448. $qrdinfo['inv_tag_id']=$tag[4]['id']??'0';
  449. $qrdinfo['inv_tag_img']=$tag[4]['tag_img']??'';
  450. $qrdinfo['inv_tag_remark']=$tag[4]['tag_remark']??'';
  451. }
  452. if($qrdinfo['pay_tag']==1){
  453. $qrdinfo['pay_tag_id']=$tag[3]['id']??'0';
  454. $qrdinfo['pay_tag_name']=$tag[3]['tag_name']??'';
  455. $qrdinfo['pay_tag_img']=$tag[3]['tag_img']??'';
  456. $qrdinfo['pay_tag_remark']=$tag[3]['tag_remark']??'';
  457. }
  458. }
  459. $qrdinfo['goodNum'] = $qrdinfo['goodNum'] -$qrdinfo['thNum'];
  460. $qrdinfo['sendNum'] = $qrdinfo['sendNum'] -$qrdinfo['thNum'];
  461. $qrdinfo['customerAttr'] = Db::name("customer_info")->where(["companyNo"=>$qrdinfo['customerNo']])->value("parent",'');
  462. return app_show(0,"获取成功",$qrdinfo);
  463. }
  464. /**验证采销订单管联数据是否对账
  465. * @return \think\response\Json|void
  466. */
  467. public function OrderIsCheck(){
  468. $post =$this->request->only(["orderCode"=>'',"isCgd"=>0,"is_cgd_check"=>0],"post","trim");
  469. $vali=Validate::rule([
  470. "orderCode|销售单单号"=>"require|max:255",
  471. "isCgd|是否退采购单"=>"require|in:0,1",
  472. "is_cgd_check|只退采购单"=>"in:0,1"
  473. ]);
  474. if($vali->check($post)==false) return error_show(1004,$vali->getError());
  475. $data=[];
  476. if($post['is_cgd_check']==0){
  477. QrdInfo::CheckQrd($post['orderCode'],$data);
  478. CgdInfo::CheckCgd(['cxCode'=>$post['orderCode']],$data);
  479. if($post['isCgd']==1)CgdInfo::CheckCgd(['qrdCode'=>$post['orderCode']],$data);
  480. }else{
  481. CgdInfo::CheckCgd(['sequenceNo'=>$post['orderCode']],$data);
  482. CgdInfo::CheckCgd(['is_comon'=>2,'mainCode'=>$post['orderCode']],$data);
  483. }
  484. empty($data)?$this->success("不存在对账订单"):$this->error("存在对账业务数据",1005,$data);
  485. }
  486. }