Customer.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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([["inv_in","=",$value['companyNo'],["status","<=",3],
  34. ["is_del","=",0]]])->field("sum(ainv_fee) as ainv_fee,sum(winv_fee) as winv_fee,sum(inv_value) as total_fee")->find();
  35. $value['ainv_fee'] = $total_fee['ainv_fee']??0;
  36. $value['winv_fee'] = $total_fee['winv_fee']??0;
  37. $value['total_fee'] = $total_fee['total_fee']??0;
  38. $data[]=$value;
  39. }
  40. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  41. }
  42. /**
  43. * 获取客户信息回款开票数据统计信息
  44. *
  45. * @return \think\Response
  46. */
  47. public function info()
  48. {
  49. $post = $this->post;
  50. $companyNo= isset($post['companyNo'])&&$post['companyNo']!='' ? $post['companyNo'] : "";
  51. if($companyNo==""){
  52. return error_show(1003,"参数companyNo 不能为空");
  53. }
  54. $info = Db::name("customer_info")->where("companyNo","=",$companyNo)->find();
  55. if(empty($info)){
  56. return error_show(1004,"未找到客户数据");
  57. }
  58. // $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")
  59. // ->find();
  60. // $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")
  61. // ->find();
  62. $order = Db::name("qrd_info")->where([["customerNo","=",$companyNo]])->field("sum(apay_fee) as apay_fee,sum(wpay_fee+pay_fee) as wpay_fee,sum(ainv_fee) as ainv_fee,sum(winv_fee+inv_fee) as winv_fee")
  63. ->find();
  64. array_walk($order,function (&$value){
  65. if(is_null($value)){
  66. $value=0;
  67. }
  68. });
  69. // array_walk($inv,function (&$value){
  70. // if(is_null($value)){
  71. // $value=0;
  72. // }
  73. // });
  74. // array_walk($trade,function (&$value){
  75. // if(is_null($value)){
  76. // $value=0;
  77. // }
  78. // });
  79. return app_show(0,"获取成功",$order);
  80. }
  81. /**
  82. * 保存新建的资源
  83. *
  84. * @param \think\Request $request
  85. * @return \think\Response
  86. */
  87. public function save(Request $request)
  88. {
  89. //
  90. }
  91. /**
  92. * 获取客户企业信息
  93. *
  94. * @param int $id
  95. * @return \think\Response
  96. */
  97. public function read()
  98. {
  99. $post = $this->post;
  100. $companyNo= isset($post['companyNo'])&&$post['companyNo']!='' ? $post['companyNo'] : "";
  101. if($companyNo==""){
  102. return error_show(1003,"参数companyNo 不能为空");
  103. }
  104. $info = Db::name("customer_info")->where("companyNo","=",$companyNo)->find();
  105. if(empty($info)){
  106. return error_show(1004,"未找到客户数据");
  107. }
  108. if($info['invoice_code']!=""){
  109. $list = Db::name("customer_invoice")->where([["invoice_code","=",$info['invoice_code']],["is_del","=",0]])
  110. ->field("id,invoice_title,invoice_people,invoice_addr,invoice_mobile,invoice_code,invoice_bank,invoice_bankNo")->find();
  111. if(!empty($list)){
  112. $info['invoice_title'] = $list['invoice_title'];
  113. $info['invoice_people'] = $list['invoice_people'];
  114. $info['invoice_addr'] = $list['invoice_addr'];
  115. $info['invoice_mobile'] = $list['invoice_mobile'];
  116. $info['invoice_code'] = $list['invoice_code'];
  117. $info['invoice_bank'] = $list['invoice_bank'];
  118. $info['invoice_bankNo'] = $list['invoice_bankNo'];
  119. }
  120. }
  121. return app_show(0,"获取成功",$info);
  122. }
  123. /**
  124. * 获取客户企业发票抬头.
  125. *
  126. * @param int $id
  127. * @return \think\Response
  128. */
  129. public function invoice()
  130. {
  131. $post = $this->post;
  132. $companyNo= isset($post['name'])&&$post['name']!='' ? $post['name'] : "";
  133. if($companyNo==""){
  134. return error_show(1003,"参数name 不能为空");
  135. }
  136. $condition = [['invoice_title','like',"%{$companyNo}%"],['is_del',"=",0]];
  137. $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")
  138. ->order('weight asc')->select();
  139. if(empty($list)){
  140. return error_show(1004,"未找到企业财务信息数据");
  141. }
  142. return app_show(0,"获取成功",$list);
  143. }
  144. //客户开票信息列表翻译
  145. public function invoicelist(){
  146. $page = isset($this->post['page'])&&$this->post['page']!='' ?intval($this->post['page']):1 ;
  147. $size = isset($this->post['size'])&&$this->post['size']!='' ?intval($this->post['size']):15 ;
  148. $where =[['is_del',"=",0]];
  149. $title = isset($this->post['invoice_title'])&&$this->post['invoice_title']!=''?trim($this->post['invoice_title']) :"";
  150. if($title!=''){
  151. $where[]=["invoice_title","like","%$title"];
  152. }
  153. $code = isset($this->post['invoice_code'])&&$this->post['invoice_code']!=''?trim($this->post['invoice_code']):"";
  154. if($code!=''){
  155. $where[]=["invoice_code","like","%$code"];
  156. }
  157. $count=Db::name("customer_invoice")->where($where)->count();
  158. $total =ceil($count/$size);
  159. $page= $page>=$total ? intval($total) :$page;
  160. $list = Db::name("customer_invoice")->where($where)->page($page,$size)->order("id desc")->select();
  161. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  162. }
  163. //客户开票信息列表翻译
  164. public function invoiceAdd(){
  165. $title = isset($this->post['invoice_title'])&&$this->post['invoice_title']!=''?trim($this->post['invoice_title']) :"";
  166. if($title==''){
  167. return error_show(1004,"参数 invoice_title 不能为空");
  168. }
  169. $code = isset($this->post['invoice_code'])&&$this->post['invoice_code']!=''?trim($this->post['invoice_code']):"";
  170. if($code==''){
  171. return error_show(1004,"参数 invoice_code 不能为空");
  172. }
  173. $people = isset($this->post['invoice_people'])&&$this->post['invoice_people']!=''?trim($this->post['invoice_people']):"";
  174. if($people==''){
  175. return error_show(1004,"参数 invoice_people 不能为空");
  176. }
  177. $invoice_addr = isset($this->post['invoice_addr'])&&$this->post['invoice_addr']!=''?trim($this->post['invoice_addr']):"";
  178. if($invoice_addr==''){
  179. return error_show(1004,"参数 invoice_addr 不能为空");
  180. }
  181. $invoice_mobile = isset($this->post['invoice_mobile'])&&$this->post['invoice_mobile']!=''?trim($this->post['invoice_mobile']):"";
  182. if($invoice_mobile==''){
  183. return error_show(1004,"参数 invoice_mobile 不能为空");
  184. }
  185. $invoice_bank = isset($this->post['invoice_bank'])&&$this->post['invoice_bank']!=''?trim($this->post['invoice_bank']):"";
  186. if($invoice_bank==''){
  187. return error_show(1004,"参数 invoice_bank 不能为空");
  188. }
  189. $invoice_bankNo = isset($this->post['invoice_bankNo'])&&$this->post['invoice_bankNo']!=''?trim($this->post['invoice_bankNo']):"";
  190. if($invoice_bankNo==''){
  191. return error_show(1004,"参数 invoice_bankNo 不能为空");
  192. }
  193. $isTr =Db::name("customer_invoice")->where(["invoice_code"=>$code,"is_del"=>0])->find();
  194. if($isTr){
  195. return error_show(1004,"开票信息已存在");
  196. }
  197. $data=[
  198. "invoice_title"=>$title,
  199. "invoice_code"=>$code,
  200. "invoice_people"=>$people,
  201. "invoice_addr"=>$invoice_addr,
  202. "invoice_mobile"=>$invoice_mobile,
  203. "invoice_bank"=>$invoice_bank,
  204. "invoice_bankNo"=>$invoice_bankNo,
  205. "apply_id"=>$this->uid,
  206. "apply_name"=>$this->uname,
  207. "addtime"=>date("Y-m-d H:i:s"),
  208. "updatetime"=>date("Y-m-d H:i:s")
  209. ];
  210. $ind =Db::name("customer_invoice")->insert($data);
  211. if($ind) return app_show(0,"新建成功"); else return error_show(1004,"新建失败");
  212. }
  213. //编辑开票信息
  214. public function invoiceSave(){
  215. $id =isset($this->post['id'])&&$this->post['id']!='' ? intval($this->post['id']):"";
  216. if($id==''){
  217. return error_show(1004,"参数 id 不能为空");
  218. }
  219. $isTr =Db::name("customer_invoice")->where(["id"=>$id,"is_del"=>0])->find();
  220. if($isTr==false){
  221. return error_show(1004,"开票信息不存在");
  222. }
  223. $title = isset($this->post['invoice_title'])&&$this->post['invoice_title']!=''?trim($this->post['invoice_title']) :"";
  224. if($title==''){
  225. return error_show(1004,"参数 invoice_title 不能为空");
  226. }
  227. $code = isset($this->post['invoice_code'])&&$this->post['invoice_code']!=''?trim($this->post['invoice_code']):"";
  228. if($code==''){
  229. return error_show(1004,"参数 invoice_code 不能为空");
  230. }
  231. $isTrs =Db::name("customer_invoice")->where([["invoice_code","=",$code,"is_del","=",0],["id","<>",$id]])
  232. ->find();
  233. if($isTrs){
  234. return error_show(1004,"开票信息已存在");
  235. }
  236. $people = isset($this->post['invoice_people'])&&$this->post['invoice_people']!=''?trim($this->post['invoice_people']):"";
  237. if($people==''){
  238. return error_show(1004,"参数 invoice_people 不能为空");
  239. }
  240. $invoice_addr = isset($this->post['invoice_addr'])&&$this->post['invoice_addr']!=''?trim($this->post['invoice_addr']):"";
  241. if($invoice_addr==''){
  242. return error_show(1004,"参数 invoice_addr 不能为空");
  243. }
  244. $invoice_mobile = isset($this->post['invoice_mobile'])&&$this->post['invoice_mobile']!=''?trim($this->post['invoice_mobile']):"";
  245. if($invoice_mobile==''){
  246. return error_show(1004,"参数 invoice_mobile 不能为空");
  247. }
  248. $invoice_bank = isset($this->post['invoice_bank'])&&$this->post['invoice_bank']!=''?trim($this->post['invoice_bank']):"";
  249. if($invoice_bank==''){
  250. return error_show(1004,"参数 invoice_bank 不能为空");
  251. }
  252. $invoice_bankNo = isset($this->post['invoice_bankNo'])&&$this->post['invoice_bankNo']!=''?trim($this->post['invoice_bankNo']):"";
  253. if($invoice_bankNo==''){
  254. return error_show(1004,"参数 invoice_bankNo 不能为空");
  255. }
  256. $data=[
  257. "invoice_title"=>$title,
  258. "invoice_code"=>$code,
  259. "invoice_people"=>$people,
  260. "invoice_addr"=>$invoice_addr,
  261. "invoice_mobile"=>$invoice_mobile,
  262. "invoice_bank"=>$invoice_bank,
  263. "invoice_bankNo"=>$invoice_bankNo,
  264. "updatetime"=>date("Y-m-d H:i:s")
  265. ];
  266. $ind =Db::name("customer_invoice")->where($isTr)->update($data);
  267. if($ind) return app_show(0,"更新成功"); else return error_show(1004,"更新失败");
  268. }
  269. //开票信息删除
  270. public function invoiceDel(){
  271. $id =isset($this->post['id'])&&$this->post['id']!='' ? intval($this->post['id']):"";
  272. if($id==''){
  273. return error_show(1004,"参数 id 不能为空");
  274. }
  275. $isTr =Db::name("customer_invoice")->where(["id"=>$id,"is_del"=>0])->find();
  276. if($isTr==false){
  277. return error_show(1004,"开票信息不存在");
  278. }
  279. $ind =Db::name("customer_invoice")->where($isTr)->update(["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  280. if($ind) return app_show(0,"删除成功"); else return error_show(1004,"删除失败");
  281. }
  282. }