request->isAjax) { if (\Yii::$app->request->isGet) { $page = \Yii::$app->request->get('page', 1); $limit = \Yii::$app->request->get('limit', $this->pageSize); $related_type = \Yii::$app->request->get('related_type', 0); $video_title = \Yii::$app->request->get('video_title'); $user_nickname = \Yii::$app->request->get('user_nickname'); $start_time = \Yii::$app->request->get('start_time'); $end_time = \Yii::$app->request->get('end_time'); $list_type = \Yii::$app->request->get('list_type', 1); $params = compact('page', 'limit', 'related_type', 'video_title', 'user_nickname', 'start_time', 'end_time'); try { $video_list = ShortVideo::getList($this->mall_id, $list_type, $params); // dd($video_list); return $this->success('success', $video_list); } catch (\Exception $e) { return $this->error($e->getMessage()); } } } else { return $this->render('index'); } } public function actionBasicSetting() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isGet) { $config = ShortVideoConfig::find() ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]) ->orderBy('updated_at desc') ->asArray() ->limit(1) ->one(); $sensitive_config = \Yii::$app->services->setting->mall->get($this->mall_id, 'sensitive'); $is_can_use_sensitive = true; if (empty($sensitive_config['api_key']) || empty($sensitive_config['secret_key'])) $is_can_use_sensitive = false; if (1 == $config['purchase_goods_status'] && !empty($config['purchase_goods_id'])) { $good = Goods::find() ->select('id,goods_name,price,cover_pic') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'mch_id' => $this->admin->mch_id, 'is_on_sale' => 1, 'id' => (int)$config['purchase_goods_id']]) ->asArray() ->all(); } else { $good = []; } $group = 'basic'; $basic_data = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_SHORT_VIDEO, $group); $config['is_show_at_center'] = 1; if (isset($basic_data['is_show_at_center'])) { $config['is_show_at_center'] = $basic_data['is_show_at_center']; } if (!isset($config['award_status'])) { $config['award_status'] = 0; $config['award_type'] = 0; } $config['is_shuffle'] = $basic_data['is_shuffle'] ?? 0; return $this->success('success', ['config' => $config, 'is_can_use_sensitive' => $is_can_use_sensitive, 'good' => $good]); } else { $post = \Yii::$app->request->post('form'); $post['mall_id'] = $this->mall_id; $is_show_at_center = $post['is_show_at_center']; $is_shuffle = $post['is_shuffle']; unset($post['is_show_at_center']); unset($post['is_shuffle']); unset($post['is_can_use_sensitive']); $model = new ShortVideoConfig(); if (!$model->load($post, '') || false === $model->validate()) { $errors = $model->errors; $error_str = ''; foreach ($errors as $error) { $error_str .= implode(',', $error) . ','; } $error_str = trim($error_str, ','); return $this->error($error_str); } $res = ShortVideoConfig::setData($this->mall_id, $post); if (false === $res) return $this->error('保存配置失败'); \Yii::$app->services->setting->addons->set($this->mall_id, AddonsEnum::ADDONS_NAME_SHORT_VIDEO, ['basic' => ['mall_id' => $this->mall_id, 'is_show_at_center' => $is_show_at_center, 'is_shuffle' => $is_shuffle]]); return $this->success('保存成功'); } } else { return $this->render('/config/index'); } } public function actionVideoDetail() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isGet) { $id = \Yii::$app->request->get('id'); if (empty($id)) return $this->error('参数错误'); $video_info = ShortVideo::find() ->select('id,title,content,video_url,first_frame,user_id,created_at,check_time,duration_str,duration_seconds,related_type,related_goods_id,related_store_id,related_lon,related_lat,tag_id,is_blacklist,check_status,max_integral,max_money,surplus_money,surplus_integral,open_integral_award,watch_integral_sum,watch_integral,watch_integral_one,watch_integral_two,open_money_award,watch_money_sum,watch_money,watch_money_one,watch_money_two') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $id]) ->asArray() ->one(); if (empty($video_info)) return $this->error('视频不存在'); $user = User::find() ->select('id,nickname,mobile,username,avatar_url') ->where(['id' => $video_info['user_id'], 'status' => StatusEnum::ENABLED]) ->one(); $video_info['nickname'] = $user->nickname ?: $user->mobile; $video_info['avatar_url'] = $user->avatar_url ?: \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png'; if (1 == $video_info['is_blacklist']) { $video_info['status'] = '黑名单'; } else { if (0 == $video_info['check_status']) { $video_info['status'] = '待审核'; } elseif (1 == $video_info['check_status']) { $video_info['status'] = '审核通过'; } else { $video_info['status'] = '审核不通过'; } } if (empty($video_info['tag_id'])) { $video_info['label_list'] = []; } else { $tag_ids = explode(',', $video_info['tag_id']); $video_info['label_list'] = ShortVideoTag::find() ->where(['mall_id' => $this->mall_id, 'id' => $tag_ids, 'status' => StatusEnum::ENABLED]) ->asArray() ->all(); } if ($video_info['related_type'] == AddonsShortVideoEnum::VIDEO_RELATE_TYPE1) { // 关联商品 if (empty($video_info['related_goods_id'])) { $video_info['goods'] = []; } else { $good = Goods::find() ->select('id,goods_name as name,cover_pic,price') ->where(['mall_id' => $this->mall_id, 'id' => $video_info['related_goods_id'], 'status' => StatusEnum::ENABLED]) ->asArray() ->one(); $video_info['goods'] = !empty($good) ? $good : []; } // dd($video_info['related_goods_id'], $video_info['goods']); } elseif ($video_info['related_type'] == AddonsShortVideoEnum::VIDEO_RELATE_TYPE2) { // 关联店铺 // TODO: 店铺暂时不做 $video_info['store'] = []; } else { $video_info['related_type'] == 4; } // 分红比例 $item_id = $video_info['related_goods_id'] ?? 0; $item_setting = ShortVideoCommissionItemSetting::find() ->where(['mall_id' => $this->mall_id, 'is_enable' => 1, 'status' => StatusEnum::ENABLED, 'item_type' => 'goods', 'id' => $item_id]) ->one(); if (empty($item_setting)) { // 非独立设置商品分红 $config = ShortVideoConfig::findOne(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]); $goodsAward = [ 'share_type' => $config->award_status == 0 ? 0 : $config->award_type, 'percentage' => $config->award_status == 0 ? 0 : $config->award_percentage, 'fixed_value' => $config->award_status == 0 ? 0 : $config->award_money ]; } else { $setting_detail = $item_setting->detail; // dd($setting_detail); $goodsAward = [ 'share_type' => $setting_detail->calculate_type, 'percentage' => $setting_detail->value, 'fixed_value' => $setting_detail->value, ]; } $video_info['share'] = $goodsAward; return $this->success('success', $video_info); } else { $post = \Yii::$app->request->post('form'); // dd($post); if (empty($post['id'])) return $this->error('参数错误'); $video = ShortVideo::findOne(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $post['id'], 'check_status' => AddonsShortVideoEnum::VIDEO_AUDIT_STATUS1, 'is_blacklist' => 0]); if (empty($video)) return $this->error('视频不存在或者不能修改配置'); if (!empty($video['max_integral']) && !empty($post['operation_integral'])) { $max_integral = $video['max_integral'] + $post['operation_integral']; $post['max_integral'] = $max_integral >= 0 ? $max_integral : 0; $surplus_integral = $video['surplus_integral'] + $post['operation_integral']; $post['surplus_integral'] = $surplus_integral >= 0 ? $surplus_integral : 0; } if (!empty($video['max_money']) && !empty($post['operation_money'])) { $max_money = $video['max_money'] + $post['operation_money']; $post['max_money'] = $max_money >= 0 ? $max_money : 0; $surplus_money = $video['surplus_money'] + $post['operation_money']; $post['surplus_money'] = $surplus_money >= 0 ? $surplus_money : 0; } unset($post['operation_money'], $post['operation_integral'], $post['_csrf']); $post['duration_seconds'] = ceil($post['duration_seconds']) ?? 0; try { $res = ShortVideo::setData($this->mall_id, $post); if (false === $res) { return $this->error('操作失败'); } else { return $this->success('操作成功'); } } catch (\Exception $e) { return $this->error($e->getMessage()); } } } else { return $this->render('details'); } } public function actionAuditList() { return $this->render('/audit/index'); } public function actionBlackList() { return $this->render('/blacklist/index'); } public function actionTagList() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isGet) { $create_type = \Yii::$app->request->get('create_type'); $id = \Yii::$app->request->get('id'); $name = \Yii::$app->request->get('name'); $start_time = \Yii::$app->request->get('start_time'); $end_time = \Yii::$app->request->get('end_time'); $page = \Yii::$app->request->get('page', 1); $limit = \Yii::$app->request->get('limit', $this->pageSize); $is_recommend = \Yii::$app->request->get('is_recommend'); $wheres[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]; if (!empty($create_type)) $wheres[] = ['create_type' => $create_type]; if (!empty($id)) $wheres[] = ['id' => $id]; if (!empty($name)) $wheres[] = ['like', 'name', $name]; if (!empty($start_time)) $wheres[] = ['>=', 'created_at', strtotime($start_time . ' 00:00:00')]; if (!empty($end_time)) $wheres[] = ['>=', 'created_at', strtotime($end_time . ' 23:59:59')]; if (!empty($is_recommend)) $wheres[] = ['is_recommend' => $is_recommend]; $params = [ 'where' => $wheres, 'order' => 'id desc', 'page' => $page, 'limit' => $limit, ]; $tag_list = ShortVideoTag::listPage($params); if (!empty($tag_list['list'])) { $video_count = ShortVideo::find()->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'check_status' => AddonsShortVideoEnum::VIDEO_AUDIT_STATUS1, 'is_blacklist' => 0])->count(); // dd($video_count); foreach ($tag_list['list'] as &$tag) { if (empty($video_count)) { $tag['frequency'] = 0; continue; } $tag['frequency'] = floatval(round($tag['usage_num'] / $video_count * 100, 2)); } } return $this->success('success', $tag_list); } } else { return $this->render('/tag/index'); } } public function actionShareBenefits() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isGet) { $page = \Yii::$app->request->get('page', 1); $limit = \Yii::$app->request->get('limit', $this->pageSize); $start_time = \Yii::$app->request->get('start_time'); $end_time = \Yii::$app->request->get('end_time'); $nickname = \Yii::$app->request->get('nickname'); $video_id = \Yii::$app->request->get('video_id'); $order_no = \Yii::$app->request->get('order_no'); $wheres[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]; if (!empty($start_time)) $wheres[] = ['>=', 'created_at', strtotime($start_time . ' 00:00:00')]; if (!empty($end_time)) $wheres[] = ['<=', 'created_at', strtotime($end_time . ' 23:59:59')]; if (!empty($nickname)) { $users = User::find() ->select('id,nickname,mobile,avatar_url') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]) ->andWhere(['like', 'nickname', $nickname]) ->asArray() ->indexBy('id') ->all(); if (!empty($users)) { $user_ids = array_column($users, 'id'); $wheres[] = ['user_id' => $user_ids]; } } if (!empty($video_id)) $wheres[] = ['video_id' => $video_id]; if (!empty($order_no)) { $orders = Order::find() ->select('id,order_no,pay_money') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]) ->andWhere(['like', 'order_no', $order_no]) ->asArray() ->indexBy('id') ->all(); $order_ids = array_column($orders, 'id'); $wheres[] = ['order_id' => $order_ids]; } $params = [ 'select' => 'id,order_id,user_id,created_at,video_id,goods_id,award_type,goods_price,award_percentage,award_money,is_settlement', 'where' => $wheres, 'order' => 'created_at desc,id desc', 'page' => $page, 'limit' => $limit ]; $order_awards = ShortVideoOrderAward::listPage($params); // dd($order_awards); // $order_awards = ShortVideoOrderAward::getStaticError(); // dd($order_awards); if (empty($order_awards['list'])) { if (is_array($order_awards['list'])) { return $this->success('success', $order_awards); } else { return $this->error(ShortVideoOrderAward::getStaticError()); } } if (empty($users)) { $user_ids = array_column($order_awards['list'], 'user_id'); $users = User::find() ->select('id,nickname,mobile,avatar_url') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $user_ids]) ->asArray() ->indexBy('id') ->all(); } $good_ids = array_column($order_awards['list'], 'goods_id'); $goods = Goods::find() ->select('id,goods_name,cover_pic,price') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $good_ids]) ->asArray() ->indexBy('id') ->all(); if (empty($orders)) { $order_ids = array_column($order_awards['list'], 'order_id'); $orders = Order::find() ->select('id,order_no,pay_money') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $order_ids]) ->asArray() ->indexBy('id') ->all(); } foreach ($order_awards['list'] as &$award) { $user = $users[$award['user_id']] ?? []; $award['nickname'] = $user['nickname'] ?? ''; $award['mobile'] = $user['mobile'] ?? ''; $award['avatar_url'] = $user['avatar_url'] ?? \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png'; $award['goods_name'] = $goods[$award['goods_id']]['goods_name'] ?? ''; $award['cover_pic'] = $goods[$award['goods_id']]['cover_pic'] ?? ''; $award['price'] = $goods[$award['goods_id']]['price'] ?? 0; $award['order_no'] = $orders[$award['order_id']]['order_no'] ?? ''; $award['total_pay_price'] = $orders[$award['order_id']]['pay_money'] ?? 0; } return $this->success('success', $order_awards); } } else { return $this->render('/share-benefits/index'); } } public function actionBrowseRewardList() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isGet) { $page = \Yii::$app->request->get('page', 1); $limit = \Yii::$app->request->get('limit', $this->pageSize); $video_id = \Yii::$app->request->get('video_id'); $nickname = \Yii::$app->request->get('nickname'); $start_time = \Yii::$app->request->get('start_time'); $end_time = \Yii::$app->request->get('end_time'); $wheres[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]; if (!empty($video_id)) $wheres[] = ['video_id' => $video_id]; if (!empty($start_time)) $wheres[] = ['>=', 'created_at', strtotime($start_time . ' 00:00:00')]; if (!empty($end_time)) $wheres[] = ['<=', 'created_at', strtotime($end_time . ' 23:59:59')]; if (!empty($nickname)) { $users = User::find() ->select('id,nickname,mobile,avatar_url') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]) ->andWhere(['like', 'nickname', $nickname]) ->asArray() ->indexBy('id') ->all(); if (!empty($users)) { $user_ids = array_column($users, 'id'); $wheres[] = ['user_id' => $user_ids]; } } $params = [ 'select' => 'id,created_at,video_id,user_id,user_type,award_type,award_integral,award_money', 'where' => $wheres, 'order' => 'created_at desc,id desc', 'page' => $page, 'limit' => $limit, ]; $rewards = ShortVideoBrowseAward::listPage($params); if (empty($rewards['list'])) { if (is_array($rewards['list'])) { return $this->success('success', $rewards); } else { return $this->error(ShortVideoBrowseAward::getStaticError()); } } if (empty($users)) { $user_ids = array_column($rewards['list'], 'user_id'); $users = User::find() ->select('id,nickname,mobile,avatar_url') ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $user_ids]) ->asArray() ->indexBy('id') ->all(); if (empty($users)) $users = []; } foreach ($rewards['list'] as &$reward) { $reward['nickname'] = ($users[$reward['user_id']]['nickname'] ?? $users[$reward['user_id']]['mobile']) ?? ''; $reward['mobile'] = $users[$reward['user_id']]['mobile'] ?? ''; $reward['avatar_url'] = $users[$reward['user_id']]['avatar_url'] ?? \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png'; } return $this->success('success', $rewards); } } else { return $this->render('/watch-reward/index'); } } public function actionCommentList() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isGet) { $params = \Yii::$app->request->get(); $where[] = ['mall_id' => $this->mall_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]; !empty($params['user_id']) && $where[] = ['=', 'user_id', $params['user_id']]; if (!empty($params['mobile'])) { $user_id = User::find()->select('id')->where(['mall_id' => $this->mall_id, 'mobile' => $params['mobile'], 'status' => StatusEnum::ENABLED])->scalar() ?? 0; $where[] = ['=', 'user_id', $user_id]; } if (!empty($params['start_at']) && !empty($params['end_at'])) { $where[] = ['between', 'created_at', strtotime($params['start_at']), strtotime($params['end_at'])]; } if(!empty($params['content'])){ $where[] = ['like', 'content', $params['content']]; } $params['where'] = $where; $params['order'] = 'id desc'; $params['with'] = ['user']; $comment_list = ShortVideoComment::listPage($params); if($comment_list==false) return $this->error(AddonsOperatingNoteComment::getStaticError()); if (!empty($comment_list['list'])) { } return $this->success('success', $comment_list); } } else { return $this->render('comment-list'); } } public function actionCommentDel() { $request = \Yii::$app->request; if ($request->isAjax && $request->isPost) { // 检查提交的参数 $post = $request->post(); $res = \Yii::$app->services->validate->validate($post, [ [['id'], 'required'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $post['mall_id'] = $this->mall_id; $post['attributes'] = ['status'=>StatusEnum::DELETE]; ShortVideoComment::updateData($post); return $this->success('成功'); } } public function actionCommentUpTop() { $request = \Yii::$app->request; if ($request->isAjax && $request->isPost) { // 检查提交的参数 $post = $request->post(); $res = \Yii::$app->services->validate->validate($post, [ [['id','is_top'], 'required'], ['is_top', 'integer', 'min' => 0, 'max' => 1], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $post['mall_id'] = $this->mall_id; $post['attributes'] = ['is_top'=>$post['is_top']]; ShortVideoComment::updateData($post); return $this->success('成功'); } } public function actionCommentChangeStatus() { $request = \Yii::$app->request; if ($request->isAjax && $request->isPost) { // 检查提交的参数 $post = $request->post(); $res = \Yii::$app->services->validate->validate($post, [ [['id','status'], 'required'], ['status', 'integer', 'min' => 0, 'max' => 1], ]); if ($res == false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $post['mall_id'] = $this->mall_id; $post['attributes'] = ['status'=> $post['status']]; ShortVideoComment::updateData($post); return $this->success('成功'); } } public function actionRepair() { $request = \Yii::$app->request; if ($request->isAjax && $request->isGet) { try { $list = ShortVideo::lists([ 'where' => [ ['mall_id' => $this->mall_id], ['status' => 1], ['duration_seconds' => 0], ['check_status' => 1], ['is_blacklist' => 0] ], 'order' => 'id desc', ]); return $this->success('获取成功', $list); } catch (\Exception $e) { return $this->error($e->getMessage()); } } return $this->render('repair'); } }