Settle.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. namespace app\agent\controller;
  3. use think\facade\Session;
  4. use app\agent\BaseController;
  5. use app\common\model\Agent as AgentModel;
  6. use app\common\model\SettleCate as SettleCateModel;
  7. use app\common\model\SettleAgent as SettleAgentModel;
  8. use PHPExcel_IOFactory;
  9. use PHPExcel;
  10. class Settle extends BaseController
  11. {
  12. // 结算名单
  13. public function agentList()
  14. {
  15. $cateid = input('cateid/d', 0);
  16. $catelist = SettleCateModel::order(['priority'=>'desc','id'=>'desc'])->select();
  17. return view('settle/agentlist',[
  18. 'cateid' => $cateid,
  19. 'catelist' => $catelist
  20. ]);
  21. }
  22. public function agentForm()
  23. {
  24. $agentid = $this->access_agent['id'];
  25. $id = input('id/d, 0');
  26. $agent = SettleAgentModel::where(['agentid'=>$agentid])->findOrEmpty($id);
  27. $catelist = SettleCateModel::order(['priority'=>'desc','id'=>'desc'])->select();
  28. return view('settle/agentform',[
  29. 'catelist' => $catelist,
  30. 'agent' => $agent
  31. ]);
  32. }
  33. public function listAgent()
  34. {
  35. $agentid = $this->access_agent['id'];
  36. $limit = input('limit/d',20);
  37. $page = input('page/d',1);
  38. $map = array();
  39. $map[] = ['agentid', '=', $agentid];
  40. $keywords = input('keywords/s');
  41. if (!empty($keywords)){
  42. $map[] =['factory|pername', 'like', '%'.$keywords.'%'];
  43. }
  44. $cateid = input('cateid/d', 0);
  45. if (!empty($cateid)){
  46. $map[] = ['cateid', '=', $cateid];
  47. }
  48. $stype = input('stype/d', 0);
  49. if (!empty($stype)){
  50. $map[] = ['stype', '=', $stype];
  51. }
  52. $list = SettleAgentModel::with(['settleCate'])->where($map)->order('id','DESC')->limit($limit)->page($page)->append(['stype_text'])->select();
  53. $count = SettleAgentModel::where($map)->count();
  54. if ($count==0){
  55. exit(json_encode(array(
  56. 'code' => 1,
  57. 'msg' => "未查询到数据"
  58. )));
  59. }
  60. exit(json_encode(array(
  61. 'code' => 0,
  62. 'msg' => "",
  63. 'count' => $count,
  64. 'data' => $list
  65. )));
  66. }
  67. public function exportAgent()
  68. {
  69. $agentid = $this->access_agent['id'];
  70. $map = array();
  71. $map[] = ['agentid', '=', $agentid];
  72. $keywords = input('keywords/s');
  73. if (!empty($keywords)){
  74. $map[] =['factory|realname', 'like', '%'.$keywords.'%'];
  75. }
  76. $cateid = input('cateid/d', 0);
  77. if (!empty($cateid)){
  78. $map[] = ['cateid', '=', $cateid];
  79. }
  80. $stype = input('stype/d', 0);
  81. if (!empty($stype)){
  82. $map[] = ['stype', '=', $stype];
  83. }
  84. $xlsData = SettleAgentModel::with(['settleCate','agent'])->where($map)->order('id','DESC')->append(['stype_text'])->select()->toArray();
  85. $xlsCell = array(
  86. array('id','表ID'),
  87. array('settle_cate.title','批次号'),
  88. array('agent.idnumber','代理编号'),
  89. array('agent.title','代理门店'),
  90. array('yearmonth', '年月'),
  91. array('pername', '员工姓名'),
  92. array('perid', '员工工号'),
  93. array('permobile', '员工手机号'),
  94. array('pernumber', '员工身份证号'),
  95. array('sdate', '入职日期'),
  96. array('edate', '离职日期'),
  97. array('factory', '入职企业'),
  98. array('accountname', '收款人姓名'),
  99. array('accountnumber', '收款人身份证号码'),
  100. array('accountbank', '收款人银行账号'),
  101. array('accountstatus', '结算状态'),
  102. array('remark', '备注'),
  103. array('accountmoney', '实结金额'),
  104. array('createtime', '添加时间'),
  105. array('stype_text', '类型'),
  106. array('onefield1', '小时工-出勤时数'),
  107. array('onefield2', '小时工-员工单价'),
  108. array('onefield3', '小时工-代理费基数'),
  109. array('onefield4', '小时工-结算单价'),
  110. array('onefield5', '小时工-应结费用'),
  111. array('onefield6', '小时工-税费'),
  112. array('thrfield1', '管理费-返费政策'),
  113. array('thrfield2', '管理费-核对情况'),
  114. array('thrfield3', '管理费-员工薪资')
  115. );
  116. export_excel("代理结算",$xlsCell,$xlsData);
  117. }
  118. // 分类
  119. public function cateList()
  120. {
  121. return view('settle/catelist');
  122. }
  123. public function listCate()
  124. {
  125. $agentid = $this->access_agent['id'];
  126. $limit = input('limit');
  127. $page = input('page');
  128. $cateidarr = SettleAgentModel::where('agentid','=',$agentid)->column('cateid');
  129. $list = SettleCateModel::withCount(['settleAgent' => function($query) use($agentid) {
  130. $query->where('agentid',$agentid);
  131. }])->withSum(['settleAgent' => function($query) use($agentid) {
  132. $query->where('agentid',$agentid);
  133. }],'accountmoney')->whereIn('id', $cateidarr)->order(['priority'=>'desc','id'=>'desc'])->limit($limit)->page($page)->select();
  134. $count = SettleCateModel::whereIn('id', $cateidarr)->count();
  135. if ($count==0){
  136. exit(json_encode(array(
  137. 'code' => 1,
  138. 'msg' => "未查询到数据"
  139. )));
  140. }
  141. exit(json_encode(array(
  142. 'code' => 0,
  143. 'msg' => "",
  144. 'count' => $count,
  145. 'data' => $list
  146. )));
  147. }
  148. }