TrainingTaskLists.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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\training;
  15. use app\adminapi\lists\BaseAdminDataLists;
  16. use app\common\model\goods_category\GoodsCategory;
  17. use app\common\model\training\TrainingTask;
  18. use app\common\lists\ListsSearchInterface;
  19. /**
  20. * TrainingTask列表
  21. * Class TrainingTaskLists
  22. * @package app\adminapi\lists
  23. */
  24. class TrainingTaskLists extends BaseAdminDataLists implements ListsSearchInterface
  25. {
  26. /**
  27. * @notes 设置搜索条件
  28. * @return \string[][]
  29. * @author likeadmin
  30. * @date 2025/02/14 17:45
  31. */
  32. public function setSearch(): array
  33. {
  34. if(isset($this->params['subclass']) && !empty($this->params['subclass'])) $this->params['subclass'] = end($this->params['subclass']);
  35. return [
  36. '=' => ['subclass','training_course_id'],
  37. '%like%' => ['task_name'],
  38. ];
  39. }
  40. /**
  41. * @notes 获取列表
  42. * @return array
  43. * @throws \think\db\exception\DataNotFoundException
  44. * @throws \think\db\exception\DbException
  45. * @throws \think\db\exception\ModelNotFoundException
  46. * @author likeadmin
  47. * @date 2025/02/14 17:45
  48. */
  49. public function lists(): array
  50. {
  51. $lists = TrainingTask::with(['goodsCategory'])->where($this->searchWhere)->where('master_worker_id',0)
  52. ->field(['*'])
  53. ->limit($this->limitOffset, $this->limitLength)
  54. ->order(['id' => 'desc'])
  55. ->select()
  56. ->toArray();
  57. foreach ($lists as &$item) {
  58. if($item['goodsCategory']){
  59. $item['category_id_text'] = $item['goodsCategory']['name'];
  60. $item['category_two_text'] = GoodsCategory::where('id',$item['goodsCategory']['pid']??0)->value('name')??'';
  61. $item['category_three_text'] = GoodsCategory::where('id',GoodsCategory::where('id',$item['goodsCategory']['pid'])->value('pid')??0)->value('name')??'';
  62. }
  63. }
  64. return $lists;
  65. }
  66. /**
  67. * @notes 获取数量
  68. * @return int
  69. * @author likeadmin
  70. * @date 2025/02/14 17:45
  71. */
  72. public function count(): int
  73. {
  74. return TrainingTask::where($this->searchWhere)->count();
  75. }
  76. }