Customer.php 8.1 KB

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