Sale.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\BaseController;
  4. use think\App;
  5. use think\facade\Db;use think\facade\Validate;
  6. class Sale extends BaseController{
  7. public function __construct(App $app) {parent::__construct($app);}
  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. $cxCode = isset($post['cxCode'])&&$post['cxCode']!==''?trim($post['cxCode']):'';
  41. if($cxCode!==''){
  42. $condition[]=["a.cxCode","=",$cxCode];
  43. }
  44. $inv_status = isset($post['inv_status'])&&$post['inv_status']!==''?intval($post['inv_status']):'';
  45. if($inv_status!==''){
  46. if($inv_status==0){
  47. $condition[]=["a.inv_status","<>",3];
  48. }else{
  49. $condition[]=["a.inv_status","=",$inv_status];
  50. }
  51. }
  52. $invIs = isset($post['inv_is'])&&$post['inv_is']!==''?intval($post['inv_is']):'';
  53. if($invIs!==''){
  54. if($invIs==1){
  55. $condition[]=["a.winv_fee","<>",0];
  56. }else{
  57. $condition[]=["a.winv_fee","=",0];
  58. }
  59. }
  60. $payIs = isset($post['pay_is'])&&$post['pay_is']!==''?intval($post['pay_is']):'';
  61. if($payIs!==''){
  62. if($invIs==1){
  63. $condition[]=["a.wpay_fee","<>",0];
  64. }else{
  65. $condition[]=["a.wpay_fee","=",0];
  66. }
  67. }
  68. $pay_status = isset($post['pay_status'])&&$post['pay_status']!==''?intval($post['pay_status']):'';
  69. if($pay_status!==''){
  70. if($pay_status==0){
  71. $condition[]=["a.pay_status","<>",3];
  72. }else{
  73. $condition[]=["a.pay_status","=",$pay_status];
  74. }
  75. }
  76. $status = isset($post['status'])&&$post['status']!==''?intval($post['status']):'';
  77. if($status!==''){
  78. if($status==3){
  79. $condition[]=["a.status","<>",2];
  80. }else{
  81. $condition[]=["a.status","=",$status];
  82. }
  83. }
  84. $qrdNo = isset($post['sequenceNo'])&&$post['sequenceNo']!=''?trim($post['sequenceNo']):'';
  85. if($qrdNo!==''){
  86. $condition[]=["a.sequenceNo","like","%$qrdNo%"];
  87. }
  88. $department = isset($post['department'])&&$post['department']!=''?trim($post['department']):'';
  89. if($department!==''){
  90. $condition[]=["a.department","like","%$department%"];
  91. }
  92. $customerNo = isset($post['customerNo'])&&$post['customerNo']!=''?trim($post['customerNo']):'';
  93. if($customerNo!==''){
  94. $condition[]=["a.customerNo","like","%$customerNo%"];
  95. }
  96. $customer = isset($post['customer'])&&$post['customer']!=''?trim($post['customer']):'';
  97. if($customer!=''){
  98. $condition[]=["a.customerName","like","%$customer%"];
  99. }
  100. $companyNo = isset($post['companyNo'])&&$post['companyNo']!=''?trim($post['companyNo']):'';
  101. if($companyNo!==''){
  102. $condition[]=["a.companyNo","=",$companyNo];
  103. }
  104. $companyName = isset($post['companyName'])&&$post['companyName']!=''?trim($post['companyName']):'';
  105. if($companyName !=''){
  106. $condition[]=["a.companyName","like","%$companyName%"];
  107. }
  108. $platName = isset($post['platName'])&&$post['platName']!=''?trim($post['platName']):'';
  109. if($platName!=''){
  110. $condition[]=["a.platName","like","%$platName%"];
  111. }
  112. $platform_type = isset($post['platform_type'])&&$post['platform_type']!==''?intval($post['platform_type']):'';
  113. if($platform_type!==''){
  114. $condition[]=["a.platform_type","=",$platform_type];
  115. }
  116. $saler= isset($post['saler']) && $post['saler']!='' ? trim($post['saler']) :"";
  117. if($saler!='') $condition []=["a.ownerName","like","%$saler%"];
  118. $salerid= isset($post['salerid']) && $post['salerid']!='' ? intval($post['salerid']) :"";
  119. if($salerid!='') $condition []=["a.ownerid","=",$salerid];
  120. $qrdtype= isset($post['qrdtype']) && $post['qrdtype']!='' ? intval($post['qrdtype']) :"";
  121. if($qrdtype!='') $condition []=["a.qrdType","=",$qrdtype];
  122. $qrdsource= isset($post['qrdsource']) && $post['qrdsource']!='' ? intval($post['qrdsource']) :"";
  123. if($qrdsource!='') $condition []=["a.qrdSource","=",$qrdsource];
  124. $sendstatus= isset($post['sendstatus']) && $post['sendstatus']!='' ? intval($post['sendstatus']) :"";
  125. if($sendstatus!='') $condition []=["a.sendStatus","=",$sendstatus];
  126. $tag_id= isset($post['tag_id'])&&$post['tag_id']!=="" ? intval($post['tag_id']) :"";
  127. if($tag_id!==''){
  128. if($tag_id==1) $condition[]=["a.inv_tag","=",1];
  129. if($tag_id==2) $condition[]=["a.pay_tag","=",1];
  130. if($tag_id==3) $condition[]=["a.pay_tag|inv_tag","=",1];
  131. if($tag_id==4) $condition[]=["a.pay_tag&inv_tag","=",1];
  132. }
  133. $cat_status= isset($post['cat_status'])&&$post['cat_status']!=="" ? intval($post['cat_status']) :"";
  134. if($cat_status!=='') $condition[]=["b.status","=",$cat_status];
  135. $count =Db::name("qrd_info")->alias("a")->leftJoin("good b","a.goodNo=b.spuCode")->where($condition)->count();
  136. $total = ceil($count/$size);
  137. $page = $page>$total ? intval($total) : $page;
  138. $list =Db::name("qrd_info")->alias("a")
  139. ->leftJoin("good b","a.goodNo=b.spuCode")
  140. ->field("a.*,b.status as cat_status,b.inv_cat_name,b.inv_cat_code,b.inv_tax,b.inv_good_name,b.isZx")
  141. ->order("a.createdTime desc")
  142. ->where($condition)->page($page,$size)->select();
  143. $data=[];
  144. foreach ( $list as $ky=>$value){
  145. $value['catInfo'] = json_decode($value['catInfo'],true);
  146. $tag =Db::name("tag_log")->alias("a")->leftJoin("order_tag b","a.tag_id=b.id")->where
  147. (["code"=>$value['sequenceNo'],"a.status"=>1])->column("b.tag_name,a.tag_img,a.tag_remark","b.type");
  148. $value['goodNum'] = $value['goodNum'] -$value['thNum'];
  149. $value['sendNum'] = $value['sendNum'] -$value['thNum'];
  150. $value['inv_tag_name']=$tag[4]['tag_name']??'';
  151. $value['pay_tag_name']=$tag[3]['tag_name']??'';
  152. $value['pay_tag_img']=$tag[3]['tag_img']??'';
  153. $value['inv_tag_img']=$tag[4]['tag_img']??'';
  154. $value['inv_tag_remark']=$tag[4]['tag_remark']??'';
  155. $value['pay_tag_remark']=$tag[3]['tag_remark']??'';
  156. $invArr = Db::name("assoc")
  157. ->alias("a")
  158. ->leftJoin("invoice_good b", "a.viceCode=b.invNo AND b.orderCode =a.orderCode")
  159. ->where(["a.status" => [1, 2], "a.is_del" => 0, "a.type" => 1, "a.orderCode" => $value['sequenceNo']])->group("a.status")
  160. ->column("sum(b.goodNum) as goodNum", "a.status");
  161. $value['inv_num'] = $invArr[1]??0;
  162. $value['ainv_num'] = $invArr[2]??0;
  163. $value['winv_num'] =$value['goodNum']- $value['inv_num']-$value['ainv_num'];
  164. $data[]=$value;
  165. }
  166. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  167. }
  168. /**
  169. * 更改销售单状态 是否需要回款 0 未回款对账 1 回款对账 2 无需汇款操作
  170. */
  171. public function status(){
  172. $post =$this->request->only(["sequenceNo"=>'',"status"=>0],"post","trim");
  173. if($post['sequenceNo']==''){
  174. return error_show(1004,"参数 sequenceNo 不能为空");
  175. }
  176. if($post['status']===''){
  177. return error_show(1004,"参数 status 不能为空");
  178. }
  179. $qrdinfo =Db::name("qrd_info")->where("sequenceNo","=",$post['sequenceNo'])->findOrEmpty();
  180. if(empty($qrdinfo)){
  181. return error_show(1004,"未找到确认单信息");
  182. }
  183. if ($qrdinfo['status']==1){
  184. return error_show(1004,"确认单已参与对账");
  185. }
  186. $update=[
  187. "status"=>$post['status'],
  188. "updatetime"=>date("Y-m-d H:i:s")
  189. ];
  190. $up =Db::name("qrd_info")->where($qrdinfo)->update($update);
  191. if($up){
  192. return app_show(0,"更新成功");
  193. }else{
  194. return error_show(1003,"更新失败");
  195. }
  196. }
  197. //确认单信息详情
  198. public function saleinfo(){
  199. $post=$this->post;
  200. $sequenceNo =isset($post['sequenceNo'])&&$post['sequenceNo']?trim($post['sequenceNo']):"";
  201. if($sequenceNo==''){
  202. return error_show(1003,"参数 sequenceNo 不能为空");
  203. }
  204. $qrdinfo =Db::name("qrd_info")->where("sequenceNo","=",$post['sequenceNo'])->findOrEmpty();
  205. if(empty($qrdinfo)){
  206. return error_show(1004,"未找到确认单信息");
  207. }
  208. $goodinfo = Db::name("good")->where(["spuCode"=>$qrdinfo["goodNo"]])->findOrEmpty();
  209. $qrdinfo['goodinfo'] =$goodinfo;
  210. $qrdinfo['catInfo'] = json_decode($qrdinfo['catInfo'],true);
  211. $tag =Db::name("tag_log")->alias("a")->leftJoin("order_tag b","a.tag_id=b.id")
  212. ->where(["code"=>$qrdinfo['sequenceNo'],"a.status"=>1])->column("b.tag_name,a.tag_img,a.tag_remark","b.type");
  213. $qrdinfo['inv_tag_name']=$tag[4]['tag_name']??'';
  214. $qrdinfo['pay_tag_name']=$tag[3]['tag_name']??'';
  215. $qrdinfo['pay_tag_img']=$tag[3]['tag_img']??'';
  216. $qrdinfo['pay_tag_remark']=$tag[3]['tag_remark']??'';
  217. $qrdinfo['inv_tag_img']=$tag[4]['tag_img']??'';
  218. $qrdinfo['inv_tag_remark']=$tag[4]['tag_remark']??'';
  219. $qrdinfo['goodNum'] = $qrdinfo['goodNum'] -$qrdinfo['thNum'];
  220. $qrdinfo['sendNum'] = $qrdinfo['sendNum'] -$qrdinfo['thNum'];
  221. $qrdinfo['customerAttr'] = Db::name("customer_info")->where(["companyNo"=>$qrdinfo['customerNo']])->value("parent",'');
  222. return app_show(0,"获取成功",$qrdinfo);
  223. }
  224. /**验证采销订单管联数据是否对账
  225. * @return \think\response\Json|void
  226. */
  227. public function OrderIsCheck(){
  228. $post =$this->request->only(["orderCode"=>'',"isCgd"=>0],"post","trim");
  229. $vali=Validate::rule([
  230. "orderCode|销售单单号"=>"require|max:255",
  231. "isCgd|是否退采购单"=>"require|in:0,1",
  232. ]);
  233. if($vali->check($post)==false) return error_show(1004,$vali->getError());
  234. $qrdinf =Db::name("qrd_info")->where(["sequenceNo|cxCode"=>$post['orderCode'],"status"=>1,"is_del"=>0])->column("sequenceNo");
  235. if(!empty($qrdinf)){
  236. $asscoinfo =Db::name("assoc")->where(["ocderCode"=>$qrdinf,"status"=>[1,2],"is_del"=>0])->column("viceCode","type");
  237. $message="该销售订单在结算中已参与了以下业务,请全部解除后在申请,";
  238. if(isset($asscoinfo[1]))$message.="开票申请编号:".$asscoinfo[1]."\r\n";
  239. if(isset($asscoinfo[2]))$message.="资金认领编号:".$asscoinfo[2]."\r\n";
  240. return error_show(1005,$message);
  241. }
  242. $cgdinfo =Db::name("cgd_info")->where(["cxCode"=>$post['orderCode'],"status"=>1,"is_del"=>0])->column("sequenceNo");
  243. if(!empty($cgdinfo)){
  244. $message="该销售采购订单在结算中已参与了以下业务,请全部解除后在申请,";
  245. $payinfo = Db::name("pay_info")->where(["cgdNo"=>$cgdinfo,"status"=>1,"is_del"=>0])->column("payNo");
  246. if(!empty($payinfo))$message.="对账单编号:".implode(",",$payinfo)."\n";
  247. $hp = Db::name("pay_invoice")->where(["payNo"=>$payinfo,"is_del"=>0,"status"=>[1,2,3,4]])->column("hpNo");
  248. if(!empty($hp))$message.="对账单回票编号:".implode(",",$hp)."\n";
  249. $paydz = Db::name("pay_payment")->where(["payNo"=>$payinfo,"is_del"=>0,"status"=>[1,2,3,4]])->column("dzNo");
  250. if(!empty($paydz))$message.="对账单付款编号:".implode(",",$paydz)."\n";
  251. return error_show(1005,$message);
  252. }
  253. if($post['isCgd']==1){
  254. $cgdinfo =Db::name("cgd_info")->where(["qrdCode"=>$post['orderCode'],"status"=>1,"is_del"=>0])->column("sequenceNo");
  255. if(!empty($cgdinfo)){
  256. $message="该销售采购订单在结算中已参与了以下业务,请全部解除后在申请,";
  257. $payinfo = Db::name("pay_info")->where(["cgdNo"=>$cgdinfo,"status"=>1,"is_del"=>0])->column("payNo");
  258. if(!empty($payinfo))$message.="对账单编号:".implode(",",$payinfo)."\n";
  259. $hp = Db::name("pay_invoice")->where(["payNo"=>$payinfo,"is_del"=>0,"status"=>[1,2,3,4]])->column("hpNo");
  260. if(!empty($hp))$message.="对账单回票编号:".implode(",",$hp)."\n";
  261. $paydz = Db::name("pay_payment")->where(["payNo"=>$payinfo,"is_del"=>0,"status"=>[1,2,3,4]])->column("dzNo");
  262. if(!empty($paydz))$message.="对账单付款编号:".implode(",",$paydz)."\n";
  263. return error_show(1005,$message);
  264. }
  265. }
  266. return app_show(0,"不存在对账订单");
  267. }
  268. }