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); $assets_type_map = CloudStockEnum::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]; if (CloudStockEnum::STOCK_CHANGE_ADD == $changes_dir) { $type = 'add'; } elseif (CloudStockEnum::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]]; } $params = [ 'select' => 'id,mall_id,user_id,change_type,change_num,current_num,desc,from_type,capital_type,created_at,source_table,source_table_id,order_no,contributor_id', 'where' => $wheres, 'order' => 'created_at desc', 'page' => $page, 'limit' => $limit ]; CapitalLog::$capitalType = 'commission'; $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'; $list['from_user_id'] = ''; $list['from_user_nickname'] = ''; $list['goods_name'] = ''; $list['goods_num'] = ''; $order = null; $order_type = 0; $from_order = null; $user_id_arr = array_column($detail_list['list'], 'user_id'); $contributor_id_arr = array_column($detail_list['list'], 'contributor_id'); $user_arr = User::lists([ 'where' => [ ['id' => array_merge($contributor_id_arr, $user_id_arr)] ], 'index' => 'id', ]); if($list['source_table'] == Order::tableName()){ $order = Order::findOne(['id'=>$list['source_table_id']]); $from_order = CloudStockBuyingOrder::findOne(['order_id'=>$list['source_table_id']]); // 因为直推和间推都是走主商城订单, 所以需要判断下 $mallCapitalType = ['first_equal', 'first_over', 'second_equal', 'second_over']; if (in_array($list['capital_type'], $mallCapitalType)) { $from_order = OrderDetail::findOne(['order_id' => $list['source_table_id']]); } $order_type = CloudStockEnum::STOCK_ORDER_TYPE_USER; }elseif($list['source_table'] == OrderDetail::tableName()){ $order_detail = OrderDetail::findOne(['id'=>$list['source_table_id']]); if($order_detail){ $order = Order::findOne(['id'=>$order_detail['order_id']]); } $from_order = CloudStockBuyingOrder::findOne(['order_detail_id'=>$list['source_table_id']]); $order_type = CloudStockEnum::STOCK_ORDER_TYPE_USER; }elseif($list['source_table'] == CloudStockFillOrder::tableName()){ $order = CloudStockFillOrder::findOne(['id'=>$list['source_table_id']]); $from_order = $order; $order_type = CloudStockEnum::STOCK_ORDER_TYPE_REPLENISH; } if (empty($list['order_no']) && !empty($order)) { $list['order_no'] = $order['order_no']; $user = User::find()->where(['id'=>$order['user_id']])->select('id,nickname')->asArray()->one(); } if(in_array($list['source_table'], [Order::tableName(), OrderDetail::tableName(), CloudStockFillOrder::tableName()])) { $modelClass = [ CloudStockFillOrder::tableName() => CloudStockFillOrder::class, Order::tableName() => Order::class, OrderDetail::tableName() => OrderDetail::class, ][$list['source_table']]; if (!empty($modelClass) && !empty($list['source_table_id'])) { $user_id = $modelClass::find()->where(['id' => $list['source_table_id']])->select('user_id')->scalar(); $userInfo = User::find()->where(['id' => $user_id])->select('id, nickname')->asArray()->one(); if ($userInfo) { $list['from_user_id'] = $userInfo['id']; $list['from_user_nickname'] = $userInfo['nickname']; } } } else { if (!empty($order)) { $list['from_user'] = User::find()->where(['id' => $order['user_id']])->select('id,nickname,mobile,avatar_url')->asArray()->one(); } } if(!empty($from_order)){ $goods = Goods::findOne(['id'=>$from_order['goods_id']]); $list['goods_name'] = $goods['goods_name']; $list['goods_num'] = $from_order['num']; $deduction = CloudStockGoodsStockLog::find() ->alias('stock') ->leftJoin(['d' => CloudStockDeductionDetail::tableName()], ' d.stock_log_id = stock.id') ->where(['stock.order_id'=>$from_order['id'],'stock.order_type'=>$order_type,'d.user_id'=>$list['user_id'],'d.changes_type'=>CloudStockEnum::CHANGE_TYPE_DEDUTION_FILL]) ->select('d.num') ->one(); if($deduction){ $list['goods_num'] = $deduction['num']; } } unset($list['source_table'],$list['source_table_id']); } 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, '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, '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 = CloudStockAgent::setData($params); if (false === $res_agent) return $this->error(CloudStockAgent::getStaticError()); $res_queue = UserWalletService::batchHandleByQueue($wallet_datas); if ($res_queue === false) { return $this->error('云库存收益转入余额出错:' . UserWalletService::getStaticError()); } return $this->success('操作成功'); } /** * @name: * @msg: 积分明细 * @param {*} * @return {*} */ public function actionScoreList() { if (!\Yii::$app->request->isGet) { return $this->error('请求方式错误'); } $date = \Yii::$app->request->get('date'); $page = \Yii::$app->request->get('page', 1); $limit = \Yii::$app->request->get('limit', $this->pageSize); $wheres[] = ['a.mall_id' => $this->mall_id, 'a.user_id' => $this->user_id]; if (!empty($date)) { $start_time = strtotime($date . '-01 00:00:00'); $end_time = strtotime($date . '-' . date('t', $start_time) . ' 23:59:59'); $wheres[] = ['and', ['>=', 'a.created_at', $start_time], ['<=', 'a.created_at', $end_time]]; } $wheres[] = ['td.pay_type' => 12,'a.is_pay'=>1]; $params = [ 'select' => '*', 'where' => $wheres, 'order' => 'a.created_at desc', 'page' => $page, 'limit' => $limit ]; $params['alias'] = 'a'; $params['with'] = ['goods']; $params['join'] = [['LEFT JOIN', PaymentTradeOrder::tableName() . ' td', "td.trade_id = a.trade_id"]]; $params['joinWith'] =['score']; $detail_list=CloudStockFillOrder::listPage($params); return $this->success('success', $detail_list); } public function actionEqualAwardList() { $params = \Yii::$app->request->get(); $params['mall_id'] = $this->mall_id; $params['user_id'] = $this->user_id; $list = (new EqualAwardService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id]))->equalAwardList($params); return $this->success('操作成功', $list); } }