Customer.php 13 KB

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