1
0

GroupServiceWorkLists.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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\works;
  15. use think\db\Query;
  16. use app\adminapi\lists\BaseAdminDataLists;
  17. use app\common\lists\ListsSearchInterface;
  18. use app\common\model\works\GroupServiceWork;
  19. use app\common\model\goods_category\GoodsCategory;
  20. use app\common\model\master_worker\MasterWorkerTemporary;
  21. /**
  22. * ServiceWork列表
  23. * Class ServiceWorkLists
  24. * @package app\adminapi\listsworks
  25. */
  26. class GroupServiceWorkLists extends BaseAdminDataLists implements ListsSearchInterface
  27. {
  28. /**
  29. * @notes 设置搜索条件
  30. * @return \string[][]
  31. * @author likeadmin
  32. * @date 2024/07/10 15:06
  33. */
  34. public function setSearch(): array
  35. {
  36. return [
  37. '=' => ['id','category_type', 'work_status', 'service_status', 'master_worker_id','third_type','group_order_id'],
  38. '%like%'=>[ 'work_sn','mobile','real_name', 'title', 'address']
  39. ];
  40. }
  41. public function queryWhere(){
  42. $where = [];
  43. if (isset($this->params['all_tenant'])) {
  44. if((int)$this->params['all_tenant'] === 1){
  45. $where[] = ['tenant_id','>' ,0];
  46. }else{
  47. $where[] = ['tenant_id','=', 0];
  48. }
  49. }
  50. if (isset($this->params['master_worker_name']) && !empty($this->params['master_worker_name'])) {
  51. $master_worker_ids = MasterWorkerTemporary::where([['worker_number|mobile|real_name', 'like','%' .$this->params['master_worker_name'] . '%']])->column('id')??[0];
  52. $where[] = ['master_worker_id','in' ,$master_worker_ids];
  53. }
  54. if(isset($this->params['workid']) && !empty($this->params['workid'])){
  55. $where[] = ['master_worker_id', '=', $this->params['workid']];
  56. $where[] = ['work_status', 'NOT IN', [7,8,9]];
  57. }
  58. if (!empty($this->params['goods_category_id'])) {
  59. $goodsCategoryId = end($this->params['goods_category_id']);
  60. $goodsCategoryData = GoodsCategory::where(['status'=>1])->order(['pid' => 'asc','weigh' => 'desc', 'id' => 'desc'])
  61. ->select()->toArray();
  62. $ids =get_tree_ids($goodsCategoryData,$goodsCategoryId);
  63. $ids[] = $goodsCategoryId;
  64. $where[] = ['goods_category_id','in' ,$ids];
  65. }
  66. if(isset($this->params['work_status']) && (!empty($this->params['work_status']) || $this->params['work_status'] != '')){
  67. switch ($this->params['work_status']){
  68. case 0:
  69. $where[] = ['service_status','<' ,3];
  70. break;
  71. }
  72. }
  73. return $where;
  74. }
  75. /**
  76. * @notes 获取列表
  77. * @return array
  78. * @throws \think\db\exception\DataNotFoundException
  79. * @throws \think\db\exception\DbException
  80. * @throws \think\db\exception\ModelNotFoundException
  81. * @author likeadmin
  82. * @date 2024/07/10 15:06
  83. */
  84. public function lists(): array
  85. {
  86. $lists = GroupServiceWork::with([
  87. 'worker'=>function(Query $query) {
  88. $query->field("id,worker_number,real_name,mobile");
  89. },
  90. 'goodsCategory' =>function (Query $query) {
  91. $query->field('id,name');
  92. },
  93. 'serviceWorkLog' =>function(Query $query){
  94. $query->field('id,work_id,opera_log,create_time');
  95. },
  96. ])
  97. ->where($this->searchWhere)
  98. ->where($this->queryWhere())
  99. ->field(['id', 'code','work_sn', 'real_name', 'mobile', 'address', 'title', 'category_type', 'goods_category_ids', 'goods_category_id', 'work_total','settlement_amount','work_status', 'service_status', 'dispatch_time', 'receive_time', 'appointment_time', 'work_images','finished_images', 'finished_time', 'master_worker_id', 'work_amount', 'create_time', 'finally_door_time','third_type'])
  100. ->append(['service_status_text','category_type_text','third_type_text'])
  101. ->limit($this->limitOffset, $this->limitLength)
  102. ->order(['id' => 'desc'])
  103. ->select()
  104. ->toArray();
  105. return $lists;
  106. }
  107. /**
  108. * @notes 获取数量
  109. * @return int
  110. * @author likeadmin
  111. * @date 2024/07/10 15:06
  112. */
  113. public function count(): int
  114. {
  115. return GroupServiceWork::where($this->searchWhere)->where($this->queryWhere())->count();
  116. }
  117. public function setExcelComplexFields(): array
  118. {
  119. $zh_cn_fields = [
  120. '客户名字','工单编号','下单时间','手机号','服务内容','工程师',
  121. '工单状态','消费金额','订单来源','完成时间','城市','服务类别'
  122. ];
  123. $data_fields = [
  124. 'real_name','work_sn','create_time','mobile','title',function ($row) { return $row['worker']['real_name'] ?? ''; },
  125. 'service_status_text','work_total','third_type_text','finished_time','area_name','category_type_text'
  126. ];
  127. return [
  128. 'zh_cn_fields' => $zh_cn_fields,
  129. 'data_fields' => $data_fields
  130. ];
  131. }
  132. }