MoneyAnalysis.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\lists\master_worker;
  15. use app\adminapi\lists\BaseAdminDataLists;
  16. use app\common\model\master_worker\MasterWorkerAccountLog;
  17. use app\common\model\property\PropertyHead;
  18. use app\common\model\property\PropertyOrder;
  19. use app\common\lists\ListsSearchInterface;
  20. use app\common\model\works\ServiceWork;
  21. use think\facade\Db;
  22. /**
  23. * MoneyAnalysis列表
  24. * Class MoneyAnalysis
  25. * @package app\adminapi\lists
  26. */
  27. class MoneyAnalysis extends BaseAdminDataLists implements ListsSearchInterface
  28. {
  29. /**
  30. * @notes 设置搜索条件
  31. * @return \string[][]
  32. * @author likeadmin
  33. * @date 2024/09/19 14:48
  34. */
  35. public function setSearch(): array
  36. {
  37. return [
  38. ];
  39. }
  40. public function queryWhere()
  41. {
  42. $where = [];
  43. /*$tmpWhere = [];
  44. $workIds = [];
  45. isset($this->params['property_name']) && !empty($this->params['property_name']) && $tmpWhere[] = ['property_name', 'LIKE', '%'.$this->params['property_name'].'%'];
  46. isset($this->params['village_name']) && !empty($this->params['village_name']) && $tmpWhere[] = ['village_name', 'LIKE', '%'.$this->params['village_name'].'%'];
  47. isset($this->params['head_name']) && !empty($this->params['head_name']) && $tmpWhere[] = ['head_name', 'LIKE', '%'.$this->params['head_name'].'%'];
  48. isset($this->params['head_mobile']) && !empty($this->params['head_mobile']) && $tmpWhere[] = ['head_mobile', '=', $this->params['head_mobile']];
  49. if(!empty($tmpWhere)){
  50. $property_head_ids = PropertyHead::where($tmpWhere)->column('id');
  51. $property_head_ids && $workIds = PropertyOrder::where('order_status',3)->where('property_head_id','IN',$property_head_ids)->column('work_id');
  52. }else{
  53. $workIds = PropertyOrder::where('order_status',3)->column('work_id');
  54. }*/
  55. if(isset($this->params['start_month']) && $this->params['start_month']){
  56. $startDateTime = strtotime($this->params['start_month']);
  57. $endDateTime = strtotime('+1 month', $startDateTime)-1;
  58. $where[] = ['create_time','BETWEEN',[$startDateTime,$endDateTime]];
  59. }
  60. return $where;
  61. }
  62. /**
  63. * @notes 获取列表
  64. * @return array
  65. * @throws \think\db\exception\DataNotFoundException
  66. * @throws \think\db\exception\DbException
  67. * @throws \think\db\exception\ModelNotFoundException
  68. * @author likeadmin
  69. * @date 2024/09/19 14:48
  70. */
  71. public function lists(): array
  72. {
  73. return MasterWorkerAccountLog::with(['masterWorker'])->where($this->queryWhere())
  74. ->field(Db::raw('worker_id,action,DATE_FORMAT(FROM_UNIXTIME(create_time), "%Y-%m") AS month_format,COUNT(id) as month_num, SUM(change_amount) as month_amount'))
  75. ->group('worker_id,action,month_format') //action
  76. ->limit($this->limitOffset, $this->limitLength)
  77. ->select()
  78. ->toArray();
  79. }
  80. /**
  81. * @notes 获取数量
  82. * @return int
  83. * @author likeadmin
  84. * @date 2024/09/19 14:48
  85. */
  86. public function count(): int
  87. {
  88. return MasterWorkerAccountLog::with(['masterWorker'])->where($this->queryWhere())
  89. ->field(Db::raw('worker_id,DATE_FORMAT(FROM_UNIXTIME(create_time), "%Y-%m") AS month_format,COUNT(id) as month_num, SUM(change_amount) as month_amount'))
  90. ->group('worker_id,month_format')
  91. ->count();
  92. }
  93. }