1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace app\admin\controller\auth;
- use app\main\constants\AdminConstants;
- use app\main\constants\ConsumeConstants;
- use app\main\service\BookService;
- use think\db\Query;
- use think\Log;
- class Userconsumecurrencysum extends UserDetailBase
- {
- public function _initialize()
- {
- parent::_initialize();
- }
- public function index()
- {
- $params = $this->request->param();
- $ids = $params['ids'];
- $state = $params['state'] ?? 0;
- if ($this->request->isAjax()) {
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- try{
- $whereChannel = [];
- 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])) {
- $whereChannel = function (Query $query) {
- $query->where('free_kandian+kandian-dd_free_kandian-dd_kandian>0');
- };
- }
- if($state == 1){
- if ($this->group == AdminConstants::ADMIN_GROUP_ID_CUSTOMER_SERVICE) {
- $fields = 'kandian + free_kandian';
- }else{
- $fields = 'kandian + free_kandian - dd_kandian - dd_free_kandian';
- }
- $data = model('consume')->setConnect($ids)
- ->where($whereChannel)
- ->field('book_id,book_name,COUNT(chapter_id) AS total_chapter,SUM('.$fields.') AS total_kandian')
- ->where(['user_id' => $ids])
- ->where('type', 'neq', ConsumeConstants::CONSUME_TYPE_CAMPAIGN)
- ->where($where)
- ->group('book_id,book_name')
- ->order('book_id desc')
- ->limit($offset, $limit)
- ->select();
- $total = model('consume')->setConnect($ids)
- ->where($whereChannel)
- ->where(['user_id' => $ids])
- ->where('type', 'neq', ConsumeConstants::CONSUME_TYPE_CAMPAIGN)
- ->where($where)
- ->group('book_id')
- ->order('book_id desc')
- ->count();
- }else{
- # $data => 消费记录
- $data = model('consume')->setConnect($ids)
- ->where($whereChannel)
- ->where(['user_id' => $ids])
- ->where($where)
- ->where('type', 'neq', ConsumeConstants::CONSUME_TYPE_CAMPAIGN)
- ->order('id desc')->limit($offset, $limit)->select();
- foreach($data as $key=>$val){
- $data[$key]['kandian'] = intval($val['free_kandian'])+intval($val['kandian']);
- if ($this->group != AdminConstants::ADMIN_GROUP_ID_CUSTOMER_SERVICE) {
- $data[$key]['kandian'] = $data[$key]['kandian'] - intval($val['dd_free_kandian']) - intval($val['dd_kandian']);
- }
- $data[$key]['createtime'] = date('Y-m-d H:i:s',$val['createtime']);
- if (intval($val['chapter_name'])) {
- $chapterInfo = BookService::instance()->getBookChapterInfo($val['book_id'], $val['chapter_id']);
- $data[$key]['chapter_name'] = $chapterInfo->data['chapter']['name'];
- }
- }
- $total = model('consume')->setConnect($ids)
- ->where($whereChannel)
- ->where(['user_id' => $ids])
- ->where($where)
- ->where('type', 'neq', ConsumeConstants::CONSUME_TYPE_CAMPAIGN)
- ->order('id desc')->count();
- }
- $result = array("total" => $total, "rows" => $data);
- return json($result);
- }catch (\Exception $exception){
- Log::error(__FILE__.'::'.__LINE__.'::'.__METHOD__.$exception->getMessage());
- }
- }
- $this->assignconfig('state', $state);
- $this->view->assign('title', '消费记录');
- $this->view->assign('state', $state);
- $this->view->assign('type', 'userconsumecurrencysum');
- return $this->view->fetch();
- }
- }
|