Customer.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. $company_type= isset($post['company_type'])&&$post['company_type']!='' ? $post['company_type'] : "";
  138. if($company_type!=""){
  139. $condition[]=["company_type","=",$company_type];
  140. }
  141. $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")
  142. ->order('weight asc')->select();
  143. if(empty($list)){
  144. return error_show(1004,"未找到企业财务信息数据");
  145. }
  146. return app_show(0,"获取成功",$list);
  147. }
  148. //客户开票信息列表翻译
  149. public function invoicelist(){
  150. $page = isset($this->post['page'])&&$this->post['page']!='' ?intval($this->post['page']):1 ;
  151. $size = isset($this->post['size'])&&$this->post['size']!='' ?intval($this->post['size']):15 ;
  152. $where =[['is_del',"=",0]];
  153. $title = isset($this->post['invoice_title'])&&$this->post['invoice_title']!=''?trim($this->post['invoice_title']) :"";
  154. if($title!=''){
  155. $where[]=["invoice_title","like","%$title"];
  156. }
  157. $code = isset($this->post['invoice_code'])&&$this->post['invoice_code']!=''?trim($this->post['invoice_code']):"";
  158. if($code!=''){
  159. $where[]=["invoice_code","like","%$code"];
  160. }
  161. $count=Db::name("customer_invoice")->where($where)->count();
  162. $total =ceil($count/$size);
  163. $page= $page>=$total ? intval($total) :$page;
  164. $list = Db::name("customer_invoice")->where($where)->page($page,$size)->order("id desc")->select();
  165. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  166. }
  167. //客户开票信息列表翻译
  168. public function invoiceAdd(){
  169. $title = isset($this->post['invoice_title'])&&$this->post['invoice_title']!=''?trim($this->post['invoice_title']) :"";
  170. if($title==''){
  171. return error_show(1004,"参数 invoice_title 不能为空");
  172. }
  173. $code = isset($this->post['invoice_code'])&&$this->post['invoice_code']!=''?trim($this->post['invoice_code']):"";
  174. if($code==''){
  175. return error_show(1004,"参数 invoice_code 不能为空");
  176. }
  177. $people = isset($this->post['invoice_people'])&&$this->post['invoice_people']!=''?trim($this->post['invoice_people']):"";
  178. if($people==''){
  179. return error_show(1004,"参数 invoice_people 不能为空");
  180. }
  181. $invoice_addr = isset($this->post['invoice_addr'])&&$this->post['invoice_addr']!=''?trim($this->post['invoice_addr']):"";
  182. if($invoice_addr==''){
  183. return error_show(1004,"参数 invoice_addr 不能为空");
  184. }
  185. $invoice_mobile = isset($this->post['invoice_mobile'])&&$this->post['invoice_mobile']!=''?trim($this->post['invoice_mobile']):"";
  186. if($invoice_mobile==''){
  187. return error_show(1004,"参数 invoice_mobile 不能为空");
  188. }
  189. $invoice_bank = isset($this->post['invoice_bank'])&&$this->post['invoice_bank']!=''?trim($this->post['invoice_bank']):"";
  190. if($invoice_bank==''){
  191. return error_show(1004,"参数 invoice_bank 不能为空");
  192. }
  193. $invoice_bankNo = isset($this->post['invoice_bankNo'])&&$this->post['invoice_bankNo']!=''?trim($this->post['invoice_bankNo']):"";
  194. if($invoice_bankNo==''){
  195. return error_show(1004,"参数 invoice_bankNo 不能为空");
  196. }
  197. $company_type = isset($this->post['company_type'])&&$this->post['company_type']!=''?trim($this->post['company_type']):"01";
  198. $isTr =Db::name("customer_invoice")->where(["invoice_code"=>$code,"is_del"=>0])->find();
  199. if($isTr){
  200. return error_show(1004,"开票信息已存在");
  201. }
  202. $data=[
  203. "invoice_title"=>$title,
  204. "invoice_code"=>$code,
  205. "invoice_people"=>$people,
  206. "invoice_addr"=>$invoice_addr,
  207. "invoice_mobile"=>$invoice_mobile,
  208. "invoice_bank"=>$invoice_bank,
  209. "invoice_bankNo"=>$invoice_bankNo,
  210. "company_type"=>$company_type,
  211. "apply_id"=>$this->uid,
  212. "apply_name"=>$this->uname,
  213. "addtime"=>date("Y-m-d H:i:s"),
  214. "updatetime"=>date("Y-m-d H:i:s")
  215. ];
  216. $ind =Db::name("customer_invoice")->insertGetId($data);
  217. if($ind) return app_show(0,"新建成功",["id"=>$ind]); else return error_show(1004,"新建失败");
  218. }
  219. //编辑开票信息
  220. public function invoiceSave(){
  221. $id =isset($this->post['id'])&&$this->post['id']!='' ? intval($this->post['id']):"";
  222. if($id==''){
  223. return error_show(1004,"参数 id 不能为空");
  224. }
  225. $isTr =Db::name("customer_invoice")->where(["id"=>$id,"is_del"=>0])->find();
  226. if($isTr==false){
  227. return error_show(1004,"开票信息不存在");
  228. }
  229. $title = isset($this->post['invoice_title'])&&$this->post['invoice_title']!=''?trim($this->post['invoice_title']) :"";
  230. if($title==''){
  231. return error_show(1004,"参数 invoice_title 不能为空");
  232. }
  233. $code = isset($this->post['invoice_code'])&&$this->post['invoice_code']!=''?trim($this->post['invoice_code']):"";
  234. if($code==''){
  235. return error_show(1004,"参数 invoice_code 不能为空");
  236. }
  237. $isTrs =Db::name("customer_invoice")->where([["invoice_code","=",$code,"is_del","=",0],["id","<>",$id]])
  238. ->find();
  239. if($isTrs){
  240. return error_show(1004,"开票信息已存在");
  241. }
  242. $people = isset($this->post['invoice_people'])&&$this->post['invoice_people']!=''?trim($this->post['invoice_people']):"";
  243. if($people==''){
  244. return error_show(1004,"参数 invoice_people 不能为空");
  245. }
  246. $invoice_addr = isset($this->post['invoice_addr'])&&$this->post['invoice_addr']!=''?trim($this->post['invoice_addr']):"";
  247. if($invoice_addr==''){
  248. return error_show(1004,"参数 invoice_addr 不能为空");
  249. }
  250. $invoice_mobile = isset($this->post['invoice_mobile'])&&$this->post['invoice_mobile']!=''?trim($this->post['invoice_mobile']):"";
  251. if($invoice_mobile==''){
  252. return error_show(1004,"参数 invoice_mobile 不能为空");
  253. }
  254. $invoice_bank = isset($this->post['invoice_bank'])&&$this->post['invoice_bank']!=''?trim($this->post['invoice_bank']):"";
  255. if($invoice_bank==''){
  256. return error_show(1004,"参数 invoice_bank 不能为空");
  257. }
  258. $invoice_bankNo = isset($this->post['invoice_bankNo'])&&$this->post['invoice_bankNo']!=''?trim($this->post['invoice_bankNo']):"";
  259. if($invoice_bankNo==''){
  260. return error_show(1004,"参数 invoice_bankNo 不能为空");
  261. }
  262. $company_type = isset($this->post['company_type'])&&$this->post['company_type']!=''?trim($this->post['company_type']):"01";
  263. $data=[
  264. "invoice_title"=>$title,
  265. "invoice_code"=>$code,
  266. "invoice_people"=>$people,
  267. "invoice_addr"=>$invoice_addr,
  268. "invoice_mobile"=>$invoice_mobile,
  269. "invoice_bank"=>$invoice_bank,
  270. "invoice_bankNo"=>$invoice_bankNo,
  271. "company_type"=>$company_type,
  272. "updatetime"=>date("Y-m-d H:i:s")
  273. ];
  274. $ind =Db::name("customer_invoice")->where($isTr)->update($data);
  275. if($ind) return app_show(0,"更新成功"); else return error_show(1004,"更新失败");
  276. }
  277. //开票信息删除
  278. public function invoiceDel(){
  279. $id =isset($this->post['id'])&&$this->post['id']!='' ? intval($this->post['id']):"";
  280. if($id==''){
  281. return error_show(1004,"参数 id 不能为空");
  282. }
  283. $isTr =Db::name("customer_invoice")->where(["id"=>$id,"is_del"=>0])->find();
  284. if($isTr==false){
  285. return error_show(1004,"开票信息不存在");
  286. }
  287. $ind =Db::name("customer_invoice")->where($isTr)->update(["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  288. if($ind) return app_show(0,"删除成功"); else return error_show(1004,"删除失败");
  289. }
  290. }