Sale.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  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. $page = isset($post['page'])&&$post['page']!==''?intval($post['page']):1;
  18. $size = isset($post['size'])&&$post['size']!==''?intval($post['size']):15;
  19. $start =isset($post['start'])&&$post['start']!==''?trim($post['start']):'';
  20. if($start!=''){
  21. $condition[]=["a.createdTime",">=",$start." 00:00:00"];
  22. }
  23. $end =isset($post['end'])&&$post['end']!==''?trim($post['end']):'';
  24. if($end!=''){
  25. $condition[]=["a.createdTime","<=",$end." 23:59:59"];
  26. }
  27. $total_min = isset($post['total_min'])&&$post['total_min']!==''?floatval($post['total_min']):'';
  28. if($total_min!==''){
  29. $condition[]=["a.totalPrice",">=",$total_min];
  30. }
  31. $total_max = isset($post['total_max'])&&$post['total_max']!==''?floatval($post['total_max']):'';
  32. if($total_max!==''){
  33. $condition[]=["a.totalPrice","<=",$total_max];
  34. }
  35. $cxCode = isset($post['cxCode'])&&$post['cxCode']!==''?trim($post['cxCode']):'';
  36. if($cxCode!==''){
  37. $condition[]=["a.cxCode","=",$cxCode];
  38. }
  39. $inv_status = isset($post['inv_status'])&&$post['inv_status']!==''?intval($post['inv_status']):'';
  40. if($inv_status!==''){
  41. if($inv_status==0){
  42. $condition[]=["a.inv_status","<>",3];
  43. }else{
  44. $condition[]=["a.inv_status","=",$inv_status];
  45. }
  46. }
  47. $invIs = isset($post['inv_is'])&&$post['inv_is']!==''?intval($post['inv_is']):'';
  48. if($invIs!==''){
  49. if($invIs==1){
  50. $condition[]=["a.winv_fee","<>",0];
  51. }else{
  52. $condition[]=["a.winv_fee","=",0];
  53. }
  54. }
  55. $payIs = isset($post['pay_is'])&&$post['pay_is']!==''?intval($post['pay_is']):'';
  56. if($payIs!==''){
  57. if($invIs==1){
  58. $condition[]=["a.wpay_fee","<>",0];
  59. }else{
  60. $condition[]=["a.wpay_fee","=",0];
  61. }
  62. }
  63. $pay_status = isset($post['pay_status'])&&$post['pay_status']!==''?intval($post['pay_status']):'';
  64. if($pay_status!==''){
  65. if($pay_status==0){
  66. $condition[]=["a.pay_status","<>",3];
  67. }else{
  68. $condition[]=["a.pay_status","=",$pay_status];
  69. }
  70. }
  71. $status = isset($post['status'])&&$post['status']!==''?intval($post['status']):'';
  72. if($status!==''){
  73. if($status==3){
  74. $condition[]=["a.status","<>",2];
  75. }else{
  76. $condition[]=["a.status","=",$status];
  77. }
  78. }
  79. $qrdNo = isset($post['sequenceNo'])&&$post['sequenceNo']!=''?trim($post['sequenceNo']):'';
  80. if($qrdNo!==''){
  81. $condition[]=["a.sequenceNo","like","%$qrdNo%"];
  82. }
  83. $department = isset($post['department'])&&$post['department']!=''?trim($post['department']):'';
  84. if($department!==''){
  85. $condition[]=["a.department","like","%$department%"];
  86. }
  87. $customerNo = isset($post['customerNo'])&&$post['customerNo']!=''?trim($post['customerNo']):'';
  88. if($customerNo!==''){
  89. $condition[]=["a.customerNo","like","%$customerNo%"];
  90. }
  91. $customer = isset($post['customer'])&&$post['customer']!=''?trim($post['customer']):'';
  92. if($customer!=''){
  93. $condition[]=["a.customerName","like","%$customer%"];
  94. }
  95. $companyNo = isset($post['companyNo'])&&$post['companyNo']!=''?trim($post['companyNo']):'';
  96. if($companyNo!==''){
  97. $condition[]=["a.companyNo","=",$companyNo];
  98. }
  99. $companyName = isset($post['companyName'])&&$post['companyName']!=''?trim($post['companyName']):'';
  100. if($companyName !=''){
  101. $condition[]=["a.companyName","like","%$companyName%"];
  102. }
  103. $platName = isset($post['platName'])&&$post['platName']!=''?trim($post['platName']):'';
  104. if($platName!=''){
  105. $condition[]=["a.platName","like","%$platName%"];
  106. }
  107. $saler= isset($post['saler']) && $post['saler']!='' ? trim($post['saler']) :"";
  108. if($saler!='') $condition []=["a.ownerName","like","%$saler%"];
  109. $salerid= isset($post['salerid']) && $post['salerid']!='' ? intval($post['salerid']) :"";
  110. if($salerid!='') $condition []=["a.ownerid","=",$salerid];
  111. $qrdtype= isset($post['qrdtype']) && $post['qrdtype']!='' ? intval($post['qrdtype']) :"";
  112. if($qrdtype!='') $condition []=["a.qrdType","=",$qrdtype];
  113. $qrdsource= isset($post['qrdsource']) && $post['qrdsource']!='' ? intval($post['qrdsource']) :"";
  114. if($qrdsource!='') $condition []=["a.qrdSource","=",$qrdsource];
  115. $sendstatus= isset($post['sendstatus']) && $post['sendstatus']!='' ? intval($post['sendstatus']) :"";
  116. if($sendstatus!='') $condition []=["a.sendStatus","=",$sendstatus];
  117. $tag_id= isset($post['tag_id'])&&$post['tag_id']!=="" ? intval($post['tag_id']) :"";
  118. if($tag_id!==''){
  119. if($tag_id==1) $condition[]=["a.inv_tag","=",1];
  120. if($tag_id==2) $condition[]=["a.pay_tag","=",1];
  121. if($tag_id==3) $condition[]=["a.pay_tag|inv_tag","=",1];
  122. if($tag_id==4) $condition[]=["a.pay_tag&inv_tag","=",1];
  123. }
  124. $cat_status= isset($post['cat_status'])&&$post['cat_status']!=="" ? intval($post['cat_status']) :"";
  125. if($cat_status!=='') $condition[]=["b.status","=",$cat_status];
  126. $count =Db::name("qrd_info")->alias("a")->leftJoin("good b","a.goodNo=b.spuCode")->where($condition)->count();
  127. $total = ceil($count/$size);
  128. $page = $page>$total ? intval($total) : $page;
  129. $list =Db::name("qrd_info")->alias("a")
  130. ->leftJoin("good b","a.goodNo=b.spuCode")
  131. ->field("a.*,b.status as cat_status,b.inv_cat_name,b.inv_cat_code,b.inv_tax,b.inv_good_name,b.isZx")
  132. ->order("a.createdTime desc")
  133. ->where($condition)->page($page,$size)->select();
  134. $data=[];
  135. foreach ( $list as $ky=>$value){
  136. $value['catInfo'] = json_decode($value['catInfo'],true);
  137. $tag =Db::name("tag_log")->alias("a")->leftJoin("order_tag b","a.tag_id=b.id")->where
  138. (["code"=>$value['sequenceNo'],"a.status"=>1])->column("b.tag_name,a.tag_img,a.tag_remark","b.type");
  139. $value['goodNum'] = $value['goodNum'] -$value['thNum'];
  140. $value['sendNum'] = $value['sendNum'] -$value['thNum'];
  141. $value['inv_tag_name']=$tag[4]['tag_name']??'';
  142. $value['pay_tag_name']=$tag[3]['tag_name']??'';
  143. $value['pay_tag_img']=$tag[3]['tag_img']??'';
  144. $value['inv_tag_img']=$tag[4]['tag_img']??'';
  145. $value['inv_tag_remark']=$tag[4]['tag_remark']??'';
  146. $value['pay_tag_remark']=$tag[3]['tag_remark']??'';
  147. $invArr = Db::name("assoc")
  148. ->alias("a")
  149. ->leftJoin("invoice_good b", "a.viceCode=b.invNo AND b.orderCode =a.orderCode")
  150. ->where(["a.status" => [1, 2], "a.is_del" => 0, "a.type" => 1, "a.orderCode" => $value['sequenceNo']])->group("a.status")
  151. ->column("sum(b.goodNum) as goodNum", "a.status");
  152. $value['inv_num'] = $invArr[1]??0;
  153. $value['ainv_num'] = $invArr[2]??0;
  154. $value['winv_num'] =$value['goodNum']- $value['inv_num']-$value['ainv_num'];
  155. $data[]=$value;
  156. }
  157. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  158. }
  159. /**
  160. * 更改销售单状态 是否需要回款 0 未回款对账 1 回款对账 2 无需汇款操作
  161. */
  162. public function status(){
  163. $post =$this->request->only(["sequenceNo"=>'',"status"=>0],"post","trim");
  164. if($post['sequenceNo']==''){
  165. return error_show(1004,"参数 sequenceNo 不能为空");
  166. }
  167. if($post['status']===''){
  168. return error_show(1004,"参数 status 不能为空");
  169. }
  170. $qrdinfo =Db::name("qrd_info")->where("sequenceNo","=",$post['sequenceNo'])->findOrEmpty();
  171. if(empty($qrdinfo)){
  172. return error_show(1004,"未找到确认单信息");
  173. }
  174. if ($qrdinfo['status']==1){
  175. return error_show(1004,"确认单已参与对账");
  176. }
  177. $update=[
  178. "status"=>$post['status'],
  179. "updatetime"=>date("Y-m-d H:i:s")
  180. ];
  181. $up =Db::name("qrd_info")->where($qrdinfo)->update($update);
  182. if($up){
  183. return app_show(0,"更新成功");
  184. }else{
  185. return error_show(1003,"更新失败");
  186. }
  187. }
  188. //确认单信息详情
  189. public function saleinfo(){
  190. $post=$this->post;
  191. $sequenceNo =isset($post['sequenceNo'])&&$post['sequenceNo']?trim($post['sequenceNo']):"";
  192. if($sequenceNo==''){
  193. return error_show(1003,"参数 sequenceNo 不能为空");
  194. }
  195. $qrdinfo =Db::name("qrd_info")->where("sequenceNo","=",$post['sequenceNo'])->findOrEmpty();
  196. if(empty($qrdinfo)){
  197. return error_show(1004,"未找到确认单信息");
  198. }
  199. $goodinfo = Db::name("good")->where(["spuCode"=>$qrdinfo["goodNo"]])->findOrEmpty();
  200. $qrdinfo['goodinfo'] =$goodinfo;
  201. $qrdinfo['catInfo'] = json_decode($qrdinfo['catInfo'],true);
  202. $tag =Db::name("tag_log")->alias("a")->leftJoin("order_tag b","a.tag_id=b.id")
  203. ->where(["code"=>$qrdinfo['sequenceNo'],"a.status"=>1])->column("b.tag_name,a.tag_img,a.tag_remark","b.type");
  204. $qrdinfo['inv_tag_name']=$tag[4]['tag_name']??'';
  205. $qrdinfo['pay_tag_name']=$tag[3]['tag_name']??'';
  206. $qrdinfo['pay_tag_img']=$tag[3]['tag_img']??'';
  207. $qrdinfo['pay_tag_remark']=$tag[3]['tag_remark']??'';
  208. $qrdinfo['inv_tag_img']=$tag[4]['tag_img']??'';
  209. $qrdinfo['inv_tag_remark']=$tag[4]['tag_remark']??'';
  210. $qrdinfo['goodNum'] = $qrdinfo['goodNum'] -$qrdinfo['thNum'];
  211. $qrdinfo['sendNum'] = $qrdinfo['sendNum'] -$qrdinfo['thNum'];
  212. $qrdinfo['customerAttr'] = Db::name("customer_info")->where(["companyNo"=>$qrdinfo['customerNo']])->value("parent",'');
  213. return app_show(0,"获取成功",$qrdinfo);
  214. }
  215. }