Customer.php 13 KB

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