UserPartake.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace app\admin\model\user;
  3. use app\admin\model\order\StoreOrder;
  4. use app\models\store\StoreProduct;
  5. use crmeb\services\SystemConfigService;
  6. use think\facade\Db;
  7. use crmeb\traits\ModelTrait;
  8. use crmeb\basic\BaseModel;
  9. /**
  10. * TODO 场馆model
  11. * Class Article
  12. * @package app\models\article
  13. */
  14. class UserPartake extends BaseModel
  15. {
  16. /**
  17. * 数据表主键
  18. * @var string
  19. */
  20. protected $pk = 'id';
  21. /**
  22. * 模型名称
  23. * @var string
  24. */
  25. protected $name = 'user_partake';
  26. protected $autoWriteTimestamp = true;
  27. use ModelTrait;
  28. public static function list($where)
  29. {
  30. $model = self::alias('a')
  31. ->field('a.*,b.nickname,c.name,c.number')
  32. ->order('a.id DESC')
  33. ->leftJoin('user b', 'b.uid = a.uid')
  34. ->leftJoin('out c', 'c.id = a.out_id');
  35. if ($where['name']) $model->where('b.nickname|a.uid', 'like', '%'.$where['name'].'%');
  36. if ($where['status'] == 1){
  37. $model->where('a.status', 0);
  38. }
  39. if ($where['status'] == 2){
  40. $model->where('a.status', 1);
  41. }
  42. if ($where['status'] == 3){
  43. $model->where('a.status', 2);
  44. }
  45. if ($where['status'] == 4){
  46. $model->where('a.status', -1);
  47. }
  48. $data['count'] = $model->count();
  49. if ($where['page'] && $where['limit']){
  50. $model->page($where['page'], $where['limit']);
  51. }else{
  52. $model->page(20, 1);
  53. }
  54. $list = $model->select();
  55. $list = count($list) ? $list->toArray() : [];
  56. foreach ($list as &$item)
  57. {
  58. $uids = User::where('spread_uid', $item['uid'])->column('uid');
  59. if ($item['money'] == 0){
  60. $item['money'] = StoreOrder::where('uid', 'in', $uids)
  61. ->where('paid', 1)
  62. ->where('is_participate', 0)
  63. ->sum('pay_price');
  64. }
  65. }
  66. $data['data'] = $list;
  67. return $data;
  68. }
  69. }