Customer.php 13 KB

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