Settlement.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\Db;
  5. use think\Exception;
  6. class Settlement extends Auth
  7. {
  8. protected $status = [
  9. 0=>'待分配',
  10. 1=>'进行中',
  11. 2=>'已完成',
  12. 3=>'已作废',
  13. 4=>'已结算'
  14. ];
  15. public function index(){
  16. if(request()->isAjax()){
  17. //分页参数
  18. $length = input('rows',10,'intval'); //每页条数
  19. $page = input('page',1,'intval'); //第几页
  20. $start = ($page - 1) * $length; //分页开始位置
  21. //排序
  22. $sortRow = input('sidx','u.id','trim'); //排序列
  23. $sort = input('sord','desc','trim'); //排序方式
  24. $order = 'a.id desc';
  25. $title = input('title','','trim');//用户
  26. if($title){
  27. $user = Db::name('user')
  28. ->alias('u')
  29. ->join('user_org uo','uo.user_id = u.id')
  30. ->where('u.real_name','like','%'.$title.'%')
  31. ->where('uo.org_id',$this->orgId)
  32. ->column('u.id');
  33. if(!empty($user)){
  34. $map[] = ['a.user_id','in',$user];
  35. }else{
  36. $map[] = ['a.user_id','=',0];
  37. }
  38. }
  39. $title1 = input('title1','','trim');//护工
  40. if($title1){
  41. $user = Db::name('worker')
  42. ->where('name','like','%'.$title1.'%')
  43. ->where('org_id',$this->orgId)
  44. ->column('id');
  45. if(!empty($user)){
  46. $ids = Db::name('todo')
  47. ->where('worker_id','in',$user)
  48. ->column('order_id');
  49. if(empty($ids)){
  50. $map[] = ['a.id','=',0];
  51. }else{
  52. $map[] = ['a.id','in',$ids];
  53. }
  54. }else{
  55. $map[] = ['a.id','=',0];
  56. }
  57. }
  58. $sn = input('sn','','trim');
  59. if($sn){
  60. $map[] = ['a.sn','=',$sn];
  61. }
  62. $cateId = input('cateId','','trim');
  63. if($cateId){
  64. $map[] = ['a.cate_id','=',$cateId];
  65. }
  66. $depId = input('depId','','trim');
  67. if($depId){
  68. $map[] = ['a.dep_id','=',$depId];
  69. }
  70. $status = input('status','','trim');
  71. if($status != ''){
  72. $map[] = ['a.status','=',$status];
  73. }
  74. $b = input('begin','','trim');
  75. $e = input('end','','trim');
  76. if($b){
  77. $b = date('Y-m-d 00:00:00',strtotime($b));
  78. $map[] = ['a.create_time','>=',$b];
  79. }
  80. if($e){
  81. $e = date('Y-m-d 23:59:59',strtotime($e));
  82. $map[] = ['a.create_time','<=',$e];
  83. }
  84. $map[] = ['a.status','=',2];
  85. $map[] = ['org_id','=',$this->orgId];
  86. $map= empty($map) ? true: $map;
  87. //数据查询
  88. $lists = Db::name('ph_orders')->alias('a')
  89. ->where($map)
  90. ->field('a.*')
  91. ->limit($start,$length)
  92. ->order($order)
  93. ->select();
  94. foreach ($lists as $k=>$v){
  95. $lists[$k]['userName'] = Db::name('user')
  96. ->where('id',$v['user_id'])
  97. ->value('real_name');
  98. $lists[$k]['depName'] = '';
  99. $lists[$k]['cateName'] = '';
  100. if($v['cate_id'] > 0){
  101. $lists[$k]['cateName'] = Db::name('cate')->where('id',$v['cate_id'])->value('title');
  102. }
  103. if($v['dep_id'] > 0){
  104. $lists[$k]['depName'] = Db::name('dep')->where('id',$v['dep_id'])->value('title');
  105. }
  106. }
  107. int_to_string($lists,['status' => $this->status]);
  108. //数据返回
  109. $totalCount = Db::name('ph_orders')->alias('a')
  110. ->where($map)->count();
  111. $totalPage = ceil($totalCount/$length);
  112. $totalMoney = Db::name('ph_orders')->alias('a')
  113. ->where($map)->sum('a.amount');
  114. $result['totalMoney'] = $totalMoney;
  115. $result['page'] = $page;
  116. $result['total'] = $totalPage;
  117. $result['records'] = $totalCount;
  118. $result['rows'] = $lists;
  119. return json($result);
  120. }else{
  121. $cate =(new \app\common\model\Cate())->getAllByOrg($this->orgId);
  122. $this->assign('cate',$cate);
  123. $dep =(new \app\common\model\Dep())->getList($this->orgId);
  124. $this->assign('dep',$dep);
  125. $this->assign('status',$this->status);
  126. return $this->fetch();
  127. }
  128. }
  129. //订单结算
  130. public function js(){
  131. if(request()->isAjax()){
  132. $data = request()->post();
  133. $ids = $data['ids'];
  134. $web_bl = Db::name('config')
  135. ->alias('a')
  136. ->join('config_org b','a.id=b.config_id')
  137. ->where('b.org_id',$this->orgId)
  138. ->where('a.name','web_bl')
  139. ->value('b.value');
  140. $web_bl = floatval($web_bl)?floatval($web_bl):0;
  141. // if(empty($web_bl)){
  142. // $this->error('请先设置扣除比例');
  143. // }
  144. $web_deduct = Db::name('config')
  145. ->alias('a')
  146. ->join('config_org b','a.id=b.config_id')
  147. ->where('b.org_id',$this->orgId)
  148. ->where('a.name','web_deduct')
  149. ->value('b.value');
  150. $web_deduct = $web_deduct?$web_deduct:0;
  151. // if(empty($web_deduct)){
  152. // $this->error('请先设置结算前扣除金额');
  153. // }
  154. $res = (new \app\common\model\PhOrders())->js($ids,$web_bl,$web_deduct,$this->orgId);
  155. $this->success('','',$res);
  156. }
  157. }
  158. public function detail($id=0){
  159. $model = new \app\common\model\PhOrders();
  160. $info = $model->getInfo($id);
  161. if(!$info){
  162. $this->error('订单不存在');
  163. }
  164. $this->assign('info',$info);
  165. return $this->fetch();
  166. }
  167. }