Sale.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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. $count =Db::name("qrd_info")
  141. ->alias("a")
  142. ->leftJoin("good b","a.goodNo=b.spuCode")->where($condition)->count();
  143. $total = ceil($count/$size);
  144. $page = $page>$total ? intval($total) : $page;
  145. $list =Db::name("qrd_info")->alias("a")
  146. ->leftJoin("good b","a.goodNo=b.spuCode")
  147. ->field("a.*,b.status as cat_status,b.inv_cat_name,b.inv_cat_code,b.inv_tax,b.inv_good_name,b.isZx")
  148. ->order("a.createdTime desc")
  149. ->where($condition)->page($page,$size)->select();
  150. $data=[];
  151. foreach ( $list as $ky=>$value){
  152. $value['orderTax'] = OrderCategory::where(['code' => $value['sequenceNo'], 'spuCode' => $value['goodNo']])
  153. ->field(['cat_code', 'cat_name', 'merge_code', 'short_name', 'tax', 'inv_good_name'])->findOrEmpty();
  154. $value['catInfo'] = json_decode($value['catInfo'],true);
  155. $value['inv_tag_name']='';
  156. $value['pay_tag_name']='';
  157. $value['pay_tag_img']='';
  158. $value['inv_tag_id']='0';
  159. $value['pay_tag_id']='0';
  160. $value['pay_tag_remark']='';
  161. $value['inv_tag_img']='';
  162. $value['inv_tag_remark']='';
  163. if($value['pay_tag']==1 || $value['inv_tag']==1){
  164. $tag =Db::name("tag_log")->alias("a")->leftJoin("order_tag b","a.tag_id=b.id")->where
  165. (["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");
  166. if($value['inv_tag']==1){
  167. $value['inv_tag_name']=$tag[4]['tag_name']??'';
  168. $value['inv_tag_id']=$tag[4]['id']??'0';
  169. $value['inv_tag_img']=$tag[4]['tag_img']??'';
  170. $value['inv_tag_remark']=$tag[4]['tag_remark']??'';
  171. }
  172. if($value['pay_tag']==1){
  173. $value['pay_tag_id']=$tag[3]['id']??'0';
  174. $value['pay_tag_name']=$tag[3]['tag_name']??'';
  175. $value['pay_tag_img']=$tag[3]['tag_img']??'';
  176. $value['pay_tag_remark']=$tag[3]['tag_remark']??'';
  177. }
  178. }
  179. $value['plat_pay_fee']=0;
  180. if($value['is_comon']==1){
  181. $tax = QrdInfo::where(['cxCode'=>$value['cxCode'],'is_comon'=>0])->findOrEmpty();
  182. if($tax->isEmpty()==false){
  183. $rate =$tax->totalPrice==0?0: ($tax->apay_fee/$tax->totalPrice);
  184. $value['plat_pay_fee']= round($value['totalPrice']* $rate,2);
  185. }
  186. }
  187. $value['goodNum'] = $value['goodNum'] -$value['thNum'];
  188. $value['sendNum'] = $value['sendNum'] -$value['thNum'];
  189. $invArr = Db::name("assoc")
  190. ->alias("a")
  191. ->leftJoin("invoice_good b", "a.viceCode=b.invNo AND b.orderCode =a.orderCode")
  192. ->where(["a.status" => [1, 2], "a.is_del" => 0, "a.type" => 1, "a.orderCode" => $value['sequenceNo']])->group("a.status")
  193. ->column("sum(b.goodNum) as goodNum", "a.status");
  194. $value['inv_num'] = $invArr[1]??0;
  195. $value['ainv_num'] = $invArr[2]??0;
  196. $value['winv_num'] =$value['goodNum']- $value['inv_num']-$value['ainv_num'];
  197. $data[]=$value;
  198. }
  199. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  200. }
  201. public function query(){
  202. $post =$this->request->param();
  203. $condition = [['a.is_del',"=",0]];
  204. $start =isset($post['start'])&&$post['start']!==''?trim($post['start']):'';
  205. if($start!=''){
  206. $condition[]=["a.createdTime",">=",$start." 00:00:00"];
  207. }
  208. $end =isset($post['end'])&&$post['end']!==''?trim($post['end']):'';
  209. if($end!=''){
  210. $condition[]=["a.createdTime","<=",$end." 23:59:59"];
  211. }
  212. $total_min = isset($post['total_min'])&&$post['total_min']!==''?floatval($post['total_min']):'';
  213. if($total_min!==''){
  214. $condition[]=["a.totalPrice",">=",$total_min];
  215. }
  216. if(isset($post['is_comon'])&&$post['is_comon']!=='') $condition []=['is_comon','=',$post['is_comon']];
  217. $total_max = isset($post['total_max'])&&$post['total_max']!==''?floatval($post['total_max']):'';
  218. if($total_max!==''){
  219. $condition[]=["a.totalPrice","<=",$total_max];
  220. }
  221. $cxCode =$post['cxCode']??[];
  222. if(!empty($cxCode)){
  223. $condition[]=['a.cxCode','in',$cxCode];
  224. }
  225. $inv_status = isset($post['inv_status'])&&$post['inv_status']!==''?intval($post['inv_status']):'';
  226. if($inv_status!==''){
  227. if($inv_status==0){
  228. $condition[]=["a.inv_status","<>",3];
  229. }else{
  230. $condition[]=["a.inv_status","=",$inv_status];
  231. }
  232. }
  233. $invIs = isset($post['inv_is'])&&$post['inv_is']!==''?intval($post['inv_is']):'';
  234. if($invIs!==''){
  235. if($invIs==1){
  236. $condition[]=["a.winv_fee","<>",0];
  237. }else{
  238. $condition[]=["a.winv_fee","=",0];
  239. }
  240. }
  241. $payIs = isset($post['pay_is'])&&$post['pay_is']!==''?intval($post['pay_is']):'';
  242. if($payIs!==''){
  243. if($payIs==1){
  244. $condition[]=["a.wpay_fee","<>",0];
  245. }else{
  246. $condition[]=["a.wpay_fee","=",0];
  247. }
  248. }
  249. $pay_status = isset($post['pay_status'])&&$post['pay_status']!==''?intval($post['pay_status']):'';
  250. if($pay_status!==''){
  251. if($pay_status==0){
  252. $condition[]=["a.pay_status","<>",3];
  253. }else{
  254. $condition[]=["a.pay_status","=",$pay_status];
  255. }
  256. }
  257. $status = isset($post['status'])&&$post['status']!==''?intval($post['status']):'';
  258. if($status!==''){
  259. if($status==3){
  260. $condition[]=["a.status","<>",2];
  261. }else{
  262. $condition[]=["a.status","=",$status];
  263. }
  264. }
  265. $qrdNo = isset($post['sequenceNo'])&&$post['sequenceNo']!=''?trim($post['sequenceNo']):'';
  266. if($qrdNo!==''){
  267. $condition[]=["a.sequenceNo","in",explode(",",$qrdNo)];
  268. }
  269. $department = isset($post['department'])&&$post['department']!=''?trim($post['department']):'';
  270. if($department!==''){
  271. $condition[]=["a.department","like","%$department%"];
  272. }
  273. $customerNo = isset($post['customerNo'])&&$post['customerNo']!=''?trim($post['customerNo']):'';
  274. if($customerNo!==''){
  275. $condition[]=["a.customerNo","like","%$customerNo%"];
  276. }
  277. $customer = isset($post['customer'])&&$post['customer']!=''?trim($post['customer']):'';
  278. if($customer!=''){
  279. $condition[]=["a.customerName","like","%$customer%"];
  280. }
  281. $companyNo = isset($post['companyNo'])&&$post['companyNo']!=''?trim($post['companyNo']):'';
  282. if($companyNo!==''){
  283. $condition[]=["a.companyNo","=",$companyNo];
  284. }
  285. $companyName = isset($post['companyName'])&&$post['companyName']!=''?trim($post['companyName']):'';
  286. if($companyName !=''){
  287. $condition[]=["a.companyName","like","%$companyName%"];
  288. }
  289. $platName = isset($post['platName'])&&$post['platName']!=''?trim($post['platName']):'';
  290. if($platName!=''){
  291. $condition[]=["a.platName","like","%$platName%"];
  292. }
  293. $platform_type = isset($post['platform_type'])&&$post['platform_type']!==''?intval($post['platform_type']):'';
  294. if($platform_type!==''){
  295. $condition[]=["a.platform_type","=",$platform_type];
  296. }
  297. $saler= isset($post['saler']) && $post['saler']!='' ? trim($post['saler']) :"";
  298. if($saler!='') $condition []=["a.ownerName","like","%$saler%"];
  299. $salerid= isset($post['salerid']) && $post['salerid']!='' ? intval($post['salerid']) :"";
  300. if($salerid!='') $condition []=["a.ownerid","=",$salerid];
  301. $qrdtype= isset($post['qrdtype']) && $post['qrdtype']!='' ? intval($post['qrdtype']) :"";
  302. if($qrdtype!='') $condition []=["a.qrdType","=",$qrdtype];
  303. $qrdsource= isset($post['qrdsource']) && $post['qrdsource']!='' ? intval($post['qrdsource']) :"";
  304. if($qrdsource!='') $condition []=["a.qrdSource","=",$qrdsource];
  305. $sendstatus= isset($post['sendstatus']) && $post['sendstatus']!='' ? intval($post['sendstatus']) :"";
  306. if($sendstatus!='') $condition []=["a.sendStatus","=",$sendstatus];
  307. $tag_id= isset($post['tag_id'])&&$post['tag_id']!=="" ? intval($post['tag_id']) :"";
  308. if($tag_id!==''){
  309. if($tag_id==1) $condition[]=["a.inv_tag","=",1];
  310. if($tag_id==2) $condition[]=["a.pay_tag","=",1];
  311. if($tag_id==3) $condition[]=["a.pay_tag|inv_tag","=",1];
  312. if($tag_id==4) $condition[]=["a.pay_tag&inv_tag","=",1];
  313. }
  314. $poCode = isset($post['poCode']) && $post['poCode'] !== '' ? trim($post['poCode']) : '';
  315. if ($poCode !== '') {
  316. $condition[] = ['a.poCode', 'like', "%$poCode%"];
  317. }
  318. $cat_status= isset($post['cat_status'])&&$post['cat_status']!=="" ? intval($post['cat_status']) :"";
  319. if($cat_status!=='') $condition[]=["b.status","=",$cat_status];
  320. $list =Db::name("qrd_info")->alias("a")
  321. ->leftJoin("good b","a.goodNo=b.spuCode")
  322. ->field("a.*,b.status as cat_status,b.inv_cat_name,b.inv_cat_code,b.inv_tax,b.inv_good_name,b.isZx")
  323. ->order("a.createdTime desc")
  324. ->where($condition)->select();
  325. $data=[];
  326. foreach ( $list as $ky=>$value){
  327. $value['catInfo'] = json_decode($value['catInfo'],true);
  328. $value['inv_tag_name']='';
  329. $value['pay_tag_name']='';
  330. $value['pay_tag_img']='';
  331. $value['inv_tag_id']='0';
  332. $value['pay_tag_id']='0';
  333. $value['pay_tag_remark']='';
  334. $value['inv_tag_img']='';
  335. $value['inv_tag_remark']='';
  336. if($value['pay_tag']==1 || $value['inv_tag']==1){
  337. $tag =Db::name('tag_log')->alias('a')->leftJoin('order_tag b','a.tag_id=b.id')->where
  338. (['code'=>$value['sequenceNo'],'a.status'=>[1,2]])->order('id desc')->column('a.id,b.tag_name,a.tag_img,a.tag_remark','b.type');
  339. if($value['inv_tag']==1){
  340. $value['inv_tag_name']=$tag[4]['tag_name']??'';
  341. $value['inv_tag_id']=$tag[4]['id']??'0';
  342. $value['inv_tag_img']=$tag[4]['tag_img']??'';
  343. $value['inv_tag_remark']=$tag[4]['tag_remark']??'';
  344. }
  345. if($value['pay_tag']==1){
  346. $value['pay_tag_id']=$tag[3]['id']??'0';
  347. $value['pay_tag_name']=$tag[3]['tag_name']??'';
  348. $value['pay_tag_img']=$tag[3]['tag_img']??'';
  349. $value['pay_tag_remark']=$tag[3]['tag_remark']??'';
  350. }
  351. }
  352. $value['goodNum'] = $value['goodNum'] -$value['thNum'];
  353. $value['sendNum'] = $value['sendNum'] -$value['thNum'];
  354. $value['plat_pay_fee']=0;
  355. if($value['is_comon']==1){
  356. $tax = QrdInfo::where(["cxCode"=>$value['cxCode'],"is_comon"=>0])->findOrEmpty();
  357. if($tax->isEmpty()==false){
  358. $rate = $tax->totalPrice==0?0: ($tax->apay_fee/$tax->totalPrice);
  359. $value['plat_pay_fee']= round($value['totalPrice']* $rate,2);
  360. }
  361. }
  362. $invArr = Db::name("assoc")
  363. ->alias("a")
  364. ->leftJoin("invoice_good b", "a.viceCode=b.invNo AND b.orderCode =a.orderCode")
  365. ->where(["a.status" => [1, 2], "a.is_del" => 0, "a.type" => 1, "a.orderCode" => $value['sequenceNo']])->group("a.status")
  366. ->column("sum(b.goodNum) as goodNum", "a.status");
  367. $value['inv_num'] = $invArr[1]??0;
  368. $value['ainv_num'] = $invArr[2]??0;
  369. $value['winv_num'] =$value['goodNum']- $value['inv_num']-$value['ainv_num'];
  370. $data[]=$value;
  371. }
  372. return app_show(0,"获取成功",$data);
  373. }
  374. /**
  375. * 更改销售单状态 是否需要回款 0 未回款对账 1 回款对账 2 无需汇款操作
  376. */
  377. public function status(){
  378. $post =$this->request->only(["sequenceNo"=>'',"status"=>0],"post","trim");
  379. if($post['sequenceNo']==''){
  380. return error_show(1004,"参数 sequenceNo 不能为空");
  381. }
  382. if($post['status']===''){
  383. return error_show(1004,"参数 status 不能为空");
  384. }
  385. $qrdinfo =Db::name("qrd_info")->where("sequenceNo","=",$post['sequenceNo'])->findOrEmpty();
  386. if(empty($qrdinfo)){
  387. return error_show(1004,"未找到确认单信息");
  388. }
  389. if ($qrdinfo['status']==1){
  390. return error_show(1004,"确认单已参与对账");
  391. }
  392. $update=[
  393. "status"=>$post['status'],
  394. "updatetime"=>date("Y-m-d H:i:s")
  395. ];
  396. $up =Db::name("qrd_info")->where($qrdinfo)->update($update);
  397. if($up){
  398. return app_show(0,"更新成功");
  399. }else{
  400. return error_show(1003,"更新失败");
  401. }
  402. }
  403. //确认单信息详情
  404. public function saleinfo(){
  405. $post=$this->post;
  406. $sequenceNo =isset($post['sequenceNo'])&&$post['sequenceNo']?trim($post['sequenceNo']):"";
  407. if($sequenceNo==''){
  408. return error_show(1003,"参数 sequenceNo 不能为空");
  409. }
  410. $qrdinfo =Db::name("qrd_info")->where("sequenceNo","=",$post['sequenceNo'])->findOrEmpty();
  411. if(empty($qrdinfo)){
  412. return error_show(1004,"未找到确认单信息");
  413. }
  414. $goodinfo = Db::name("good")->where(["spuCode"=>$qrdinfo["goodNo"]])->findOrEmpty();
  415. $qrdinfo['goodinfo'] =$goodinfo;
  416. $qrdinfo['catInfo'] = json_decode($qrdinfo['catInfo'],true);
  417. $qrdinfo['inv_tag_name']='';
  418. $qrdinfo['pay_tag_name']='';
  419. $qrdinfo['pay_tag_img']='';
  420. $qrdinfo['inv_tag_id']='0';
  421. $qrdinfo['pay_tag_id']='0';
  422. $qrdinfo['pay_tag_remark']='';
  423. $qrdinfo['inv_tag_img']='';
  424. $qrdinfo['inv_tag_remark']='';
  425. $qrdinfo['orderTax']=OrderCategory::where(['code' => $qrdinfo['sequenceNo'], 'spuCode' => $qrdinfo['goodNo']])
  426. ->field(['cat_code', 'cat_name', 'merge_code', 'short_name', 'tax', 'inv_good_name'])->findOrEmpty();
  427. $qrdinfo['child']=[];
  428. if(isset($goodinfo['isCombind'])&&$goodinfo['isCombind']==1){
  429. $list=(new GoodCombind())->where('spuCode',$qrdinfo['goodNo'])->visible(['child'])->with(['child'])
  430. ->select();
  431. if(!$list->isEmpty()){
  432. $qrdinfo['child']=array_column($list->toArray(),'child');
  433. foreach ($qrdinfo['child'] as &$value){
  434. $value['orderTax'] = OrderCategory::where(['code' => $qrdinfo['sequenceNo'], 'spuCode' => $value['spuCode']])
  435. ->field(['cat_code', 'cat_name', 'merge_code', 'short_name', 'tax', 'inv_good_name'])->findOrEmpty();;
  436. }
  437. }
  438. } ;
  439. if($qrdinfo['pay_tag']==1 || $qrdinfo['inv_tag']==1){
  440. $tag =Db::name('tag_log')->alias('a')->leftJoin('order_tag b','a.tag_id=b.id')
  441. ->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');
  442. if($qrdinfo['inv_tag']==1){
  443. $qrdinfo['inv_tag_name']=$tag[4]['tag_name']??'';
  444. $qrdinfo['inv_tag_id']=$tag[4]['id']??'0';
  445. $qrdinfo['inv_tag_img']=$tag[4]['tag_img']??'';
  446. $qrdinfo['inv_tag_remark']=$tag[4]['tag_remark']??'';
  447. }
  448. if($qrdinfo['pay_tag']==1){
  449. $qrdinfo['pay_tag_id']=$tag[3]['id']??'0';
  450. $qrdinfo['pay_tag_name']=$tag[3]['tag_name']??'';
  451. $qrdinfo['pay_tag_img']=$tag[3]['tag_img']??'';
  452. $qrdinfo['pay_tag_remark']=$tag[3]['tag_remark']??'';
  453. }
  454. }
  455. $qrdinfo['goodNum'] = $qrdinfo['goodNum'] -$qrdinfo['thNum'];
  456. $qrdinfo['sendNum'] = $qrdinfo['sendNum'] -$qrdinfo['thNum'];
  457. $qrdinfo['customerAttr'] = Db::name("customer_info")->where(["companyNo"=>$qrdinfo['customerNo']])->value("parent",'');
  458. return app_show(0,"获取成功",$qrdinfo);
  459. }
  460. /**验证采销订单管联数据是否对账
  461. * @return \think\response\Json|void
  462. */
  463. public function OrderIsCheck(){
  464. $post =$this->request->only(["orderCode"=>'',"isCgd"=>0,"is_cgd_check"=>0],"post","trim");
  465. $vali=Validate::rule([
  466. "orderCode|销售单单号"=>"require|max:255",
  467. "isCgd|是否退采购单"=>"require|in:0,1",
  468. "is_cgd_check|只退采购单"=>"in:0,1"
  469. ]);
  470. if($vali->check($post)==false) return error_show(1004,$vali->getError());
  471. $data=[];
  472. if($post['is_cgd_check']==0){
  473. QrdInfo::CheckQrd($post['orderCode'],$data);
  474. CgdInfo::CheckCgd(['cxCode'=>$post['orderCode']],$data);
  475. if($post['isCgd']==1)CgdInfo::CheckCgd(['qrdCode'=>$post['orderCode']],$data);
  476. }else{
  477. CgdInfo::CheckCgd(['sequenceNo'=>$post['orderCode']],$data);
  478. CgdInfo::CheckCgd(['is_comon'=>2,'mainCode'=>$post['orderCode']],$data);
  479. }
  480. empty($data)?$this->success("不存在对账订单"):$this->error("存在对账业务数据",1005,$data);
  481. }
  482. }