Customer.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller;
  4. use app\admin\BaseController;
  5. use think\facade\Db;
  6. class Customer extends BaseController
  7. {
  8. /**
  9. * 获取企业客户列表
  10. * @return \think\Response
  11. */
  12. public function list()
  13. {
  14. $post = $this->post;
  15. $condition=[];
  16. isset($post['company'])&&$post['company']!=""? $condition[]=['companyName|contactor',"like","%{$post['company']}%"] : "";
  17. isset($post['contactor'])&&$post['contactor']!=""? $condition[]=['contactor',"like","%{$post['contactor']}%"] :
  18. "";
  19. $page = isset($post['page'])&& $post['page']!="" ? intval($post['page']) :1;
  20. $size = isset($post['size'])&& $post['size']!="" ? intval($post['size']) :10;
  21. $count = Db::name("customer_info")->where($condition)->count();
  22. $total = ceil($count/$size)>1 ? ceil($count/$size) : 1;
  23. $page = $page>=$total?intval($total):$page;
  24. if( isset($post['company'])&&$post['company']!=""){
  25. $list = Db::name("customer_info")->where($condition)->page($page,$size)->field("companyNo,companyName,parent,area,contactor,depart,mobile,addtime,updatetime,LENGTH(companyName) as weight")
  26. ->order('weight asc')->select();
  27. }else{
  28. $list = Db::name("customer_info")->where($condition)->page($page,$size)->field("companyNo,companyName,parent,area,contactor,depart,mobile,addtime,updatetime")
  29. ->select();
  30. }
  31. $data =[];
  32. foreach ($list as $key=>$value){
  33. $total_fee = Db::name("invoice_pool")->where([["status","=",5],["is_del","=",0],["type_check","=",2],
  34. ["trade_status","in",[1,2]],["wtrade_fee",">",0],["inv_in","=",$value['companyNo']]])->sum("wtrade_fee");
  35. $value["trade_inv"]=$total_fee;
  36. $value["trade_inv_status"]=$total_fee>0 ? 1 :0;
  37. $data[]=$value;
  38. }
  39. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  40. }
  41. /**
  42. * 获取客户信息回款开票数据统计信息
  43. *
  44. * @return \think\Response
  45. */
  46. public function info()
  47. {
  48. $post = $this->post;
  49. $companyNo= isset($post['companyNo'])&&$post['companyNo']!='' ? $post['companyNo'] : "";
  50. if($companyNo==""){
  51. return error_show(1003,"参数companyNo 不能为空");
  52. }
  53. $info = Db::name("customer_info")->where("companyNo","=",$companyNo)->find();
  54. if(empty($info)){
  55. return error_show(1004,"未找到客户数据");
  56. }
  57. $trade = Db::name("trade_pool")->where([["companyNo","=",$companyNo],["is_del","=",0]])->field("sum(order_fee) as aorder_fee,sum(worder_fee) as worder_fee,sum(inv_fee) as inv_fee,sum(winv_fee) as winv_fee")
  58. ->find();
  59. $inv = Db::name("invoice_pool")->where([["inv_in","=",$companyNo],["is_del","=",0]])->field("sum(aorder_fee) as aorder_fee,sum(worder_fee) as worder_fee,sum(atrade_fee) as atrade_fee,sum(wtrade_fee) as wtrade_fee")
  60. ->find();
  61. $order = Db::name("qrd_info")->where([["customerNo","=",$companyNo]])->field("sum(apay_fee) as apay_fee,sum(wpay_fee) as wpay_fee,sum(ainv_fee) as ainv_fee,sum(winv_fee) as winv_fee")
  62. ->find();
  63. array_walk($order,function (&$value){
  64. if(is_null($value)){
  65. $value=0;
  66. }
  67. });
  68. array_walk($inv,function (&$value){
  69. if(is_null($value)){
  70. $value=0;
  71. }
  72. });
  73. array_walk($trade,function (&$value){
  74. if(is_null($value)){
  75. $value=0;
  76. }
  77. });
  78. $balance = $order["apay_fee"] - $order["ainv_fee"];
  79. $order["trade_inv"]=$balance >0 ?$balance :0 ;
  80. $order["inv_trade"]= $balance <0 ? $order["ainv_fee"]-$order["apay_fee"] :0;
  81. $data=["trade"=>$trade,"inv"=>$inv,"order"=>$order];
  82. return app_show(0,"获取成功",$data);
  83. }
  84. /**
  85. * 保存新建的资源
  86. *
  87. * @param \think\Request $request
  88. * @return \think\Response
  89. */
  90. public function save(Request $request)
  91. {
  92. //
  93. }
  94. /**
  95. * 获取客户企业信息
  96. *
  97. * @param int $id
  98. * @return \think\Response
  99. */
  100. public function read()
  101. {
  102. $post = $this->post;
  103. $companyNo= isset($post['companyNo'])&&$post['companyNo']!='' ? $post['companyNo'] : "";
  104. if($companyNo==""){
  105. return error_show(1003,"参数companyNo 不能为空");
  106. }
  107. $info = Db::name("customer_info")->where("companyNo","=",$companyNo)->find();
  108. if(empty($info)){
  109. return error_show(1004,"未找到客户数据");
  110. }
  111. if($info['invoice_code']!=""){
  112. $list = Db::name("customer_invoice")->where("invoice_code","=",$info['invoice_code'])->field("id,invoice_title,invoice_people,invoice_addr,invoice_mobile,invoice_code,invoice_bank,invoice_bankNo")
  113. ->find();
  114. if(!empty($list)){
  115. $info['invoice_title'] = $list['invoice_title'];
  116. $info['invoice_people'] = $list['invoice_people'];
  117. $info['invoice_addr'] = $list['invoice_addr'];
  118. $info['invoice_mobile'] = $list['invoice_mobile'];
  119. $info['invoice_code'] = $list['invoice_code'];
  120. $info['invoice_bank'] = $list['invoice_bank'];
  121. $info['invoice_bankNo'] = $list['invoice_bankNo'];
  122. }
  123. }
  124. return app_show(0,"获取成功",$info);
  125. }
  126. /**
  127. * 获取客户企业发票抬头.
  128. *
  129. * @param int $id
  130. * @return \think\Response
  131. */
  132. public function invoice()
  133. {
  134. $post = $this->post;
  135. $companyNo= isset($post['name'])&&$post['name']!='' ? $post['name'] : "";
  136. if($companyNo==""){
  137. return error_show(1003,"参数name 不能为空");
  138. }
  139. $condition = [['invoice_title','like',"%{$companyNo}%"],['is_del',"=",0]];
  140. $list = Db::name("customer_invoice")->where($condition)->page(1,100)->field("id,invoice_title,invoice_people,invoice_addr,invoice_mobile,invoice_code,invoice_bank,invoice_bankNo,LENGTH(invoice_title) as weight")
  141. ->order('weight asc')->select();
  142. if(empty($list)){
  143. return error_show(1004,"未找到企业财务信息数据");
  144. }
  145. return app_show(0,"获取成功",$list);
  146. }
  147. /**
  148. * 保存更新的资源
  149. *
  150. * @param \think\Request $request
  151. * @param int $id
  152. * @return \think\Response
  153. */
  154. public function update(Request $request, $id)
  155. {
  156. //
  157. }
  158. /**
  159. * 删除指定资源
  160. *
  161. * @param int $id
  162. * @return \think\Response
  163. */
  164. public function delete($id)
  165. {
  166. //
  167. }
  168. }