UserEquityLists.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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\equity;
  15. use app\adminapi\lists\BaseAdminDataLists;
  16. use app\common\model\equity\UserEquity;
  17. use app\common\lists\ListsSearchInterface;
  18. use app\common\model\user\User;
  19. /**
  20. * UserEquity列表
  21. * Class UserEquityLists
  22. * @package app\adminapi\lists
  23. */
  24. class UserEquityLists extends BaseAdminDataLists implements ListsSearchInterface
  25. {
  26. /**
  27. * @notes 设置搜索条件
  28. * @return \string[][]
  29. * @author likeadmin
  30. * @date 2024/12/19 11:43
  31. */
  32. public function setSearch(): array
  33. {
  34. if(isset($this->params['mobile']) && !empty($this->params['mobile'])){
  35. $userId = User::where('mobile',$this->params['mobile'])->value('id')??-1;
  36. $this->params['user_id'] = $userId;
  37. }
  38. return [
  39. '=' => ['user_id', 'equity_id', 'goods_id', 'number', 'end_time'],
  40. ];
  41. }
  42. public function queryWhere()
  43. {
  44. $where = [];
  45. if (isset($this->params['is_binding']) && !empty($this->params['is_binding'])) {
  46. if((int)$this->params['is_binding'] === 1){
  47. $where[] = ['user_id','>',0];
  48. }else{
  49. $where[] = ['user_id','=',0];
  50. }
  51. }
  52. return $where;
  53. }
  54. /**
  55. * @notes 获取列表
  56. * @return array
  57. * @throws \think\db\exception\DataNotFoundException
  58. * @throws \think\db\exception\DbException
  59. * @throws \think\db\exception\ModelNotFoundException
  60. * @author likeadmin
  61. * @date 2024/12/19 11:43
  62. */
  63. public function lists(): array
  64. {
  65. return UserEquity::with(['equityConfig', 'goods','user'])
  66. ->where($this->searchWhere)
  67. ->where($this->queryWhere())
  68. ->field(['id', 'user_id', 'equity_id', 'goods_id', 'number', 'end_time','code','IF(user_id=0,2,1) as is_binding'])
  69. ->limit($this->limitOffset, $this->limitLength)
  70. ->order(['id' => 'desc'])
  71. ->select()
  72. ->toArray();
  73. }
  74. /**
  75. * @notes 获取数量
  76. * @return int
  77. * @author likeadmin
  78. * @date 2024/12/19 11:43
  79. */
  80. public function count(): int
  81. {
  82. return UserEquity::where($this->searchWhere)->count();
  83. }
  84. }