request->isGet) { return $this->error('请求方式错误'); } $changes_dir = \Yii::$app->request->get('changes_dir'); $changes_type = \Yii::$app->request->get('changes_type'); $date = \Yii::$app->request->get('date'); $page = \Yii::$app->request->get('page', 1); $limit = \Yii::$app->request->get('limit', $this->pageSize); $status = \Yii::$app->request->get('status', 0); $assets_type_map = CloudStockTwoEnum::getAssetsTypeMap(); $changes_types = array_keys($assets_type_map); $changes_types[] = 0; if (empty($changes_dir) || !in_array($changes_type, $changes_types)) return $this->error('参数错误'); $wheres[] = ['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'from_type' => AddonsEnum::ADDONS_NAME_CLOUD_STOCK_TWO]; if (CloudStockTwoEnum::STOCK_CHANGE_ADD == $changes_dir) { $type = 'add'; } elseif (CloudStockTwoEnum::STOCK_CHANGE_SUB == $changes_dir) { $type = 'sub'; } $wheres[] = ['change_type' => $type]; if (!empty($changes_type)) { $wheres[] = ['capital_type' => $changes_type]; } if (!empty($date)) { $start_time = strtotime($date . '-01 00:00:00'); $end_time = strtotime($date . '-' . date('t', $start_time) . ' 23:59:59'); $wheres[] = ['and', ['>=', 'created_at', $start_time], ['<=', 'created_at', $end_time]]; } if($status == 1) { //查询冻结表,未结算数据 $wheres[] = ['in', 'status', [-1, 0]]; CapitalLog::$capitalType = 'commission_frozen'; }else{ CapitalLog::$capitalType = 'commission'; } $params = [ 'select' => 'id,mall_id,user_id,change_type,change_num,current_num,desc,from_type,capital_type,created_at', 'where' => $wheres, 'order' => 'created_at desc', 'page' => $page, 'limit' => $limit ]; $detail_list = CapitalLog::listPage($params); // dd($detail_list); if (false === $detail_list['list']) { return $this->error('获取明细失败: ' . CapitalLog::getStaticError()); } $user = User::find() ->select('id,nickname,avatar_url,mobile') ->where(['mall_id' => $this->mall_id, 'id' => $this->user_id]) ->one(); foreach ($detail_list['list'] as &$list) { $list['nickname'] = ($user['nickname'] ?? $user['mobile']) ?? ''; $list['mobile'] = $user['mobile'] ?? ''; $list['avatar_url'] = $user['avatar_url'] ?? \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png'; } if (!empty($assets_type_map)) { $assets_types[] = [ 'name' => '全部', 'value' => '', 'type' => 1, 'is' => true, ]; foreach ($assets_type_map as $key => $val) { $type = [ 'name' => $val, 'value' => $key, 'type' => 1, 'is' => true, ]; if (UserWalletEnum::RECHARGE_COMMISSION == $key) { $type['type'] = 2; } $assets_types[] = $type; } } else { $assets_types = []; } $detail_list['assets_type_map'] = $assets_types; return $this->success('success', $detail_list); } public function actionToBalance() { return $this->error('请求方式错误'); if (!\Yii::$app->request->isPost) { return $this->error('请求方式错误'); } $money = \Yii::$app->request->post('money'); if (empty($money)) return $this->error('参数错误'); if ($money > $this->stock_agent->price) return $this->error('收益余额不足'); $wallet_datas = [ // 入余额记录 [ 'mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'is_frozen' => false, 'wallet_type' => UserWalletService::WALLET_TYPE_BALANCE, 'money' => $money, 'desc' => '云库存收益转入余额,余额增加', 'source_table' => $this->stock_agent->tableSchema->name, 'source_table_id' => $this->stock_agent->id, 'from_type' => AddonsEnum::ADDONS_NAME_CLOUD_STOCK_TWO, 'capital_type' => UserWalletEnum::RECHARGE_COMMISSION, ], // 出收益的记录 [ 'mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'is_frozen' => false, 'wallet_type' => UserWalletService::WALLET_TYPE_COMMISSION, 'money' => -$money, 'desc' => '云库存收益转入余额,收益减少', 'source_table' => $this->stock_agent->tableSchema->name, 'source_table_id' => $this->stock_agent->id, 'from_type' => AddonsEnum::ADDONS_NAME_CLOUD_STOCK_TWO, 'capital_type' => UserWalletEnum::RECHARGE_COMMISSION, ], ]; $price = bcsub($this->stock_agent->price, $money, 2); $params = [ 'id' => $this->stock_agent->id, 'mall_id' => $this->mall_id, 'price' => $price, 'before_level' => $this->stock_agent->before_level, 'level' => $this->stock_agent->level, ]; $res_agent = CloudStockTwoAgent::setData($params); if (false === $res_agent) return $this->error(CloudStockTwoAgent::getStaticError()); $res_queue = UserWalletService::batchHandleByQueue($wallet_datas); if ($res_queue === false) { return $this->error('云库存收益转入余额出错:' . UserWalletService::getStaticError()); } return $this->success('操作成功'); } }