Userconsumecurrencysum.php 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace app\admin\controller\auth;
  3. use app\main\constants\AdminConstants;
  4. use app\main\constants\ConsumeConstants;
  5. use app\main\service\BookService;
  6. use think\db\Query;
  7. use think\Log;
  8. class Userconsumecurrencysum extends UserDetailBase
  9. {
  10. public function _initialize()
  11. {
  12. parent::_initialize();
  13. }
  14. public function index()
  15. {
  16. $params = $this->request->param();
  17. $ids = $params['ids'];
  18. $state = $params['state'] ?? 0;
  19. if ($this->request->isAjax()) {
  20. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  21. try{
  22. $whereChannel = [];
  23. if (in_array($this->group, [AdminConstants::ADMIN_GROUP_ID_CHANNEL, AdminConstants::ADMIN_GROUP_ID_AGENT, AdminConstants::ADMIN_GROUP_ID_VIP, AdminConstants::ADMIN_GROUP_ID_VIP_OPERATOR])) {
  24. $whereChannel = function (Query $query) {
  25. $query->where('free_kandian+kandian-dd_free_kandian-dd_kandian>0');
  26. };
  27. }
  28. if($state == 1){
  29. if ($this->group == AdminConstants::ADMIN_GROUP_ID_CUSTOMER_SERVICE) {
  30. $fields = 'kandian + free_kandian';
  31. }else{
  32. $fields = 'kandian + free_kandian - dd_kandian - dd_free_kandian';
  33. }
  34. $data = model('consume')->setConnect($ids)
  35. ->where($whereChannel)
  36. ->field('book_id,book_name,COUNT(chapter_id) AS total_chapter,SUM('.$fields.') AS total_kandian')
  37. ->where(['user_id' => $ids])
  38. ->where('type', 'neq', ConsumeConstants::CONSUME_TYPE_CAMPAIGN)
  39. ->where($where)
  40. ->group('book_id,book_name')
  41. ->order('book_id desc')
  42. ->limit($offset, $limit)
  43. ->select();
  44. $total = model('consume')->setConnect($ids)
  45. ->where($whereChannel)
  46. ->where(['user_id' => $ids])
  47. ->where('type', 'neq', ConsumeConstants::CONSUME_TYPE_CAMPAIGN)
  48. ->where($where)
  49. ->group('book_id')
  50. ->order('book_id desc')
  51. ->count();
  52. }else{
  53. # $data => 消费记录
  54. $data = model('consume')->setConnect($ids)
  55. ->where($whereChannel)
  56. ->where(['user_id' => $ids])
  57. ->where($where)
  58. ->where('type', 'neq', ConsumeConstants::CONSUME_TYPE_CAMPAIGN)
  59. ->order('id desc')->limit($offset, $limit)->select();
  60. foreach($data as $key=>$val){
  61. $data[$key]['kandian'] = intval($val['free_kandian'])+intval($val['kandian']);
  62. if ($this->group != AdminConstants::ADMIN_GROUP_ID_CUSTOMER_SERVICE) {
  63. $data[$key]['kandian'] = $data[$key]['kandian'] - intval($val['dd_free_kandian']) - intval($val['dd_kandian']);
  64. }
  65. $data[$key]['createtime'] = date('Y-m-d H:i:s',$val['createtime']);
  66. if (intval($val['chapter_name'])) {
  67. $chapterInfo = BookService::instance()->getBookChapterInfo($val['book_id'], $val['chapter_id']);
  68. $data[$key]['chapter_name'] = $chapterInfo->data['chapter']['name'];
  69. }
  70. }
  71. $total = model('consume')->setConnect($ids)
  72. ->where($whereChannel)
  73. ->where(['user_id' => $ids])
  74. ->where($where)
  75. ->where('type', 'neq', ConsumeConstants::CONSUME_TYPE_CAMPAIGN)
  76. ->order('id desc')->count();
  77. }
  78. $result = array("total" => $total, "rows" => $data);
  79. return json($result);
  80. }catch (\Exception $exception){
  81. Log::error(__FILE__.'::'.__LINE__.'::'.__METHOD__.$exception->getMessage());
  82. }
  83. }
  84. $this->assignconfig('state', $state);
  85. $this->view->assign('title', '消费记录');
  86. $this->view->assign('state', $state);
  87. $this->view->assign('type', 'userconsumecurrencysum');
  88. return $this->view->fetch();
  89. }
  90. }