| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\controllers;
- use app\jobs\storeSync\DiyCommon;
- use app\models\Goods;
- use app\models\Option;
- use app\models\SaasUser;
- use app\models\StoreSyncExtLog;
- use app\models\User;
- use app\models\VideoGoods;
- use app\models\VideoGoodsAuthor;
- use app\models\VideoGoodsCat;
- use app\models\VideoGoodsFocus;
- use app\models\VideoGoodsList;
- use app\models\VideoGoodsReport;
- use app\models\VideoGoodsSetting;
- use app\models\VideoGoodsVote;
- use app\modules\admin\models\VideoGoodsForm;
- use yii\helpers\Json;
- class VideoGoodsController extends BaseController
- {
- /**
- * 分类列表
- */
- public function actionCatList() {
- $name = get_params('name');
- $is_show = get_params('is_show', -1);
- $query = VideoGoodsCat::find()->where([
- 'is_delete' => 0,
- 'store_id' => get_store_id()
- ]);
- if ($is_show != -1) {
- $query->andWhere(['is_show' => intval($is_show)]);
- }
- if (!empty($name)) {
- $query->andWhere(['like', 'name', $name]);
- }
- $query->orderBy(['sort' => SORT_DESC]);
- $list = pagination_make($query);
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list['list'],
- 'pageNo' => $list['pageNo'],
- 'totalCount' => $list['totalCount'],
- ],
- ]);
- }
- /**
- * 分类状态修改
- * @return \yii\web\Response
- */
- public function actionCatStatus()
- {
- $id = post_params('id');
- $type = post_params('type');
- $status = post_params('status', 1);
- $status = intval($status);
- // 1:禁用,2: 删除
- if (!in_array($type, [1, 2]) || empty($id)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数错误'
- ]);
- }
- if (!is_array($id)) {
- $cat_id[] = intval($id);
- } else {
- $cat_id = $id;
- }
- $t = \Yii::$app->db->beginTransaction();
- foreach ($cat_id as $_id) {
- $cat = VideoGoodsCat::findOne($_id);
- if (!$cat) {
- $t->rollBack();
- return $this->asJson([
- 'code' => 1,
- 'msg' => '未找到ID:' . $_id . '记录'
- ]);
- }
- if ($type == 1) {
- if ($status == 1) {
- VideoGoodsCat::updateAll(['is_show' => 1], ['id' => $cat->id]);
- } else {
- VideoGoodsCat::updateAll(['is_show' => 0], ['id' => $cat->id]);
- }
- } else {
- VideoGoodsCat::updateAll(['is_delete' => 1], ['id' => $cat->id]);
- }
- $cat->updated_at = time();
- if (!$cat->save()) {
- $t->rollBack();
- return $this->asJson([
- 'code' => 1,
- 'msg' => 'ID: ' . $_id . '处理失败'
- ]);
- }
- }
- $t->commit();
- return $this->asJson([
- 'code' => 0,
- 'msg' => '处理成功'
- ]);
- }
- /**
- * 分类删除
- * @return \yii\web\Response
- */
- public function actionCatDel()
- {
- $id = post_params('id');
- if (empty($id)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '缺少参数或参数错误'
- ]);
- }
- if (is_array($id)) {
- $count_ids = count($id);
- $update_num = VideoGoodsCat::updateAll(['is_delete' => 1], ['in', 'id', $id]);
- if ($update_num == $count_ids) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '删除成功'
- ]);
- } else {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '有' . ($count_ids - $update_num ) . '条数据未删除成功,请稍后重试'
- ]);
- }
- } else {
- $cat = VideoGoodsCat::findOne($id);
- $cat->is_delete = 1;
- if ($cat->save()) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '删除成功'
- ]);
- }
- return $this->asJson([
- 'code' => 1,
- 'msg' => '删除失败',
- ]);
- }
- }
- /**
- * 分类编辑
- * @return \yii\web\Response
- */
- public function actionCatEdit()
- {
- $store_id = get_store_id();
- $id = post_params('id', 0);
- $name = post_params('name');
- if (empty($name)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '名称不能为空'
- ]);
- }
- $pic_url = post_params('pic_url', '');
- $sort = post_params('sort',0);
- $is_show = post_params('is_show', 0);
- if ($id > 0) {
- $cat = VideoGoodsCat::findOne($id);
- } else {
- $cat = new VideoGoodsCat();
- }
- $cat->store_id = $store_id;
- $cat->name = $name;
- $cat->pic_url = $pic_url;
- $cat->sort = $sort;
- $cat->is_show = $is_show;
- if ($cat->save()) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => $id > 0 ? '编辑成功' : '添加成功',
- ]);
- }
- return $this->asJson([
- 'code' => 1,
- 'msg' => $id > 0 ? '编辑失败' : '添加失败',
- ]);
- }
- /**
- * 获取抖品设置
- */
- public function actionSetting() {
- $setting = VideoGoodsSetting::findOne(['store_id' => get_store_id()]);
- if (!$setting) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'is_video_audit' => 0,
- 'is_author_audit' => 0,
- 'profit' => 0,
- 'verify' => [],
- 'video_analyze_345' => Option::get('video_analyze_345', get_store_id(), 'saas')['value'],
- 'rewards' => VideoGoodsSetting::REWAEDS_DEFAULT
- ]
- ]);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'is_video_audit' => $setting->is_video_audit,
- 'is_author_audit' => $setting->is_author_audit,
- 'profit' => $setting->profit,
- 'verify' => json_decode($setting->verify) ?: [],
- 'video_analyze_345' => Option::get('video_analyze_345', get_store_id(), 'saas')['value'],
- 'rewards' => empty($setting->rewards) ? VideoGoodsSetting::REWAEDS_DEFAULT : json_decode($setting->rewards,true)
- ]
- ]);
- }
- /**
- * 抖品设置
- */
- public function actionSetSetting() {
- $is_video_audit = post_params('is_video_audit');
- $is_author_audit = post_params('is_author_audit');
- $verify = post_params("verify");
- $rewards = post_params("rewards");
- $profit = post_params('profit', 0);
- $video_analyze_345 = post_params('video_analyze_345', 0);
- Option::set('video_analyze_345', $video_analyze_345, get_store_id(), 'saas');
- $setting = VideoGoodsSetting::findOne(['store_id' => get_store_id()]);
- if (!$setting) {
- $setting = new VideoGoodsSetting();
- $setting->store_id = get_store_id();
- }
- $setting->is_author_audit = intval($is_author_audit);
- $setting->is_video_audit = intval($is_video_audit);
- $setting->profit = $profit;
- $setting->verify = json_encode($verify) ?: "";
- $setting->rewards = json_encode($rewards) ?: "";
- if ($setting->save()) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '设置成功'
- ]);
- }
- return $this->asJson([
- 'code' => 1,
- 'msg' => '设置失败'
- ]);
- }
- /**
- * 添加视频商品
- */
- public function actionAddGoods() {
- $goods_id = post_params('goods_id');
- if (empty($goods_id)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数错误'
- ]);
- }
- if (!is_array($goods_id)) {
- $goods_ids[] = $goods_id;
- } else {
- $goods_ids = $goods_id;
- }
- foreach ($goods_ids as $_id) {
- $goods = VideoGoods::findOne(['store_id' => get_store_id(), 'goods_id' => $_id, 'is_delete' => 0]);
- if (!$goods) {
- $video_goods = new VideoGoods();
- $video_goods->goods_id = $_id;
- $video_goods->store_id = get_store_id();
- $video_goods->is_delete = 0;
- $video_goods->status = 0;
- $video_goods->save();
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '添加成功'
- ]);
- }
- /**
- * 获取商城可选择的商品列表
- * @return \yii\web\Response
- */
- public function actionStoreGoodsList() {
- return $this->asJson(Goods::getGoodsList(get_params()));
- }
- /**
- * 视频商品列表
- */
- public function actionGoodsList() {
- $params = get_params();
- $video_goods = VideoGoods::find()->where(['store_id' => get_store_id(), 'is_delete' => 0]);
- if (isset($params['status']) && $params['status'] != -1) {
- $video_goods->andWhere(['status' => $params['status']]);
- }
- $video_goods = $video_goods->asArray()->all();
- if (!empty($video_goods)) {
- $params = array_merge($params, ['goods_id' => array_column($video_goods, 'goods_id')]);
- } else {
- $params = array_merge($params, ['goods_id' => []]);
- }
- \Yii::error($params);
- return $this->asJson(Goods::getGoodsList($params, true));
- }
- /**
- * 商品状态修改
- * @return \yii\web\Response
- */
- public function actionGoodsStatus()
- {
- $id = post_params('id');
- $status = post_params('status');
- $store_id = get_store_id();
- if (empty($id) || !in_array($status, [0, 1])) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '缺少参数或参数错误'
- ]);
- }
- if (is_array($id)) {
- $count_ids = count($id);
- $update_num = VideoGoods::updateAll(['status' => intval($status)], ['in', 'id', $id]);
- if ($update_num == $count_ids) {
- if (count($id) === 1) {
- (new DiyCommon)->JobBehaviors($store_id, StoreSyncExtLog::TYPE_VIDEO_GOODS, $id);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '更新成功'
- ]);
- } else {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '有' . ($count_ids - $update_num ) . '条数据未更新成功,请稍后重试'
- ]);
- }
- } else {
- $video_goods = VideoGoods::findOne($id);
- $video_goods->status = $status;
- if ($video_goods->save()) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '更新成功'
- ]);
- }
- return $this->asJson([
- 'code' => 1,
- 'msg' => '修改失败',
- ]);
- }
- }
- /**
- * 商品删除
- * @return \yii\web\Response
- */
- public function actionGoodsDel()
- {
- $id = post_params('id');
- $store_id = get_store_id();
- if (empty($id)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '缺少参数或参数错误'
- ]);
- }
- if (is_array($id)) {
- $count_ids = count($id);
- $update_num = VideoGoods::updateAll(['is_delete' => 1], ['in', 'id', $id]);
- if ($update_num == $count_ids) {
- if (count($id) === 1) {
- (new DiyCommon)->JobBehaviors($store_id, StoreSyncExtLog::TYPE_VIDEO_GOODS, $id);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '更新成功'
- ]);
- } else {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '有' . ($count_ids - $update_num ) . '条数据未更新成功,请稍后重试'
- ]);
- }
- } else {
- $video_goods = VideoGoods::findOne($id);
- $video_goods->is_delete = 1;
- if ($video_goods->save()) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '更新成功'
- ]);
- }
- return $this->asJson([
- 'code' => 1,
- 'msg' => '修改失败',
- ]);
- }
- }
- /**
- * 举报列表
- */
- public function actionReportList() {
- $type = get_params('type', -1);
- $status = get_params('status', -1);
- $report_id = get_params('report_id', 0);
- $title = get_params('title', '');
- $name = get_params('name', '');
- $query = VideoGoodsReport::find()->alias('vgr')->where(['vgr.store_id' => get_store_id(), 'vgr.is_delete' => 0])
- ->leftJoin(['u' => User::tableName()], 'u.id=vgr.user_id')
- ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding')
- ->leftJoin(['vgl' => VideoGoodsList::tableName()], 'vgl.id=vgr.vl_id')
- ->leftJoin(['vu' => User::tableName()], 'vu.id=vgl.user_id')
- ->leftJoin(['vsu' => SaasUser::tableName()], 'vsu.mobile=vu.binding');
- // 举报类型
- if (in_array(intval($type), VideoGoodsReport::$validReportType)) {
- $query->andWhere(['vgr.type' => $type]);
- }
- // 举报视频的标题或内容
- if (!empty($title)) {
- $query->andWhere(['or', ['like', 'vgl.title', $title], ['like', 'vgl.content', $title]]);
- }
- // 举报人昵称
- if (!empty($name)) {
- $query->andWhere(['like', 'su.name', $name]);
- }
- // 状态
- if (in_array(intval($status), [0, 1])) {
- $query->andWhere(['vgr.status' => $status]);
- }
- // 举报id
- if (!empty($report_id)) {
- $query->andWhere(['vgr.id' => $report_id]);
- }
- $query->orderBy('vgr.id desc, vgr.status asc')->select(
- 'vgr.id report_id, vgr.store_id, vgr.user_id report_user_id, su.name report_user_name, su.avatar report_avatar,
- vgr.vl_id, vgr.pic_url report_pic_url, vgr.desc report_desc, vgr.type report_type, vgr.status report_status,
- vgl.title vl_title, vgl.cat_id vl_cat_id, vgl.is_delete vl_is_delete, vgl.is_show vl_is_show, vgl.cover_pic vl_cover_pic,
- vgl.pic_list vl_pic_list, vgl.video_url vl_video_url, vgl.content vl_content, vgl.type vl_type, vgr.created_at report_created_at,
- vgr.updated_at report_updated_at, vsu.name reported_name, vsu.avatar reported_avatar'
- );
- $list = pagination_make($query);
- if (!empty($list['list'])) {
- foreach ($list['list'] as $key => $value) {
- $list['list'][$key]['cat_name'] = VideoGoodsCat::findOne($value['vl_cat_id'])->name;
- $list['list'][$key]['vl_pic_list'] = Json::decode($value['vl_pic_list']);
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list['list'],
- 'pageNo' => $list['pageNo'],
- 'totalCount' => $list['totalCount'],
- ],
- ]);
- }
- /**
- * 处理举报
- */
- public function actionHandleReport() {
- $id = post_params('id');
- $type = post_params('type');
- // 1:下架视频,2: 删除视频
- if (!in_array($type, [1, 2]) || empty($id)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数错误'
- ]);
- }
- if (!is_array($id)) {
- $report_id[] = intval($id);
- } else {
- $report_id = $id;
- }
- $t = \Yii::$app->db->beginTransaction();
- foreach ($report_id as $_id) {
- $video_report = VideoGoodsReport::findOne($_id);
- if (!$video_report) {
- $t->rollBack();
- return $this->asJson([
- 'code' => 1,
- 'msg' => '未找到ID:' . $_id . '记录'
- ]);
- }
- if ($type == 1) {
- VideoGoodsList::updateAll(['is_show' => 0], ['id' => $video_report->vl_id]);
- } else {
- VideoGoodsList::updateAll(['is_delete' => 1], ['id' => $video_report->vl_id]);
- }
- $video_report->status = 1;
- $video_report->updated_at = time();
- if (!$video_report->save()) {
- $t->rollBack();
- return $this->asJson([
- 'code' => 1,
- 'msg' => 'ID: ' . $_id . '处理失败'
- ]);
- }
- }
- $t->commit();
- return $this->asJson([
- 'code' => 0,
- 'msg' => '处理成功'
- ]);
- }
- /**
- * 作品列表
- */
- public function actionList() {
- $cat_id = get_params('cat_id', 0);
- $type = get_params('type', 0);
- $status = get_params('status', -1);
- $name = get_params('name', '');
- $mobile = get_params('mobile', '');
- $id = get_params('id', 0);
- $user_id = get_params('user_id', 0);
- $query = VideoGoodsList::find()->alias('vgl')->where(['vgl.store_id' => get_store_id(), 'vgl.is_delete' => 0])
- ->leftJoin(['u' => User::tableName()], 'u.id=vgl.user_id')
- ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding')
- ->leftJoin(['vgc' => VideoGoodsCat::tableName()], 'vgc.id=vgl.cat_id');
- // 分类
- if (!empty($cat_id)) {
- $query->andWhere(['vgl.cat_id' => $cat_id]);
- }
- // 用户id
- if (!empty($user_id)) {
- $query->andWhere(['vgl.user_id' => $user_id]);
- }
- // 作品id
- if (!empty($id)) {
- $query->andWhere(['vgl.id' => $id]);
- }
- // 1:视频,2:图文
- if (!empty($type)) {
- $query->andWhere(['vgl.type' => $type]);
- }
- // 0:待审核。1:已通过,2:已拒绝
- if (in_array(intval($status), [0, 1, 2])) {
- $query->andWhere(['vgl.status' => $status]);
- }
- // 昵称
- if (!empty($name)) {
- $query->andWhere(['like', 'su.name', $name]);
- }
- // 电话
- if (!empty($mobile)) {
- $query->andWhere(['like', 'su.mobile', $mobile]);
- }
- $query->orderBy('vgl.id desc, vgl.status asc')->select(
- 'vgl.*, su.name user_name, su.mobile user_mobile, su.avatar user_avatar'
- );
- $list = pagination_make($query);
- if (!empty($list['list'])) {
- foreach ($list['list'] as $key => $value) {
- $list['list'][$key]['cat_name'] = VideoGoodsCat::findOne($value['cat_id'])->name;
- $list['list'][$key]['pic_list'] = Json::decode($value['pic_list']);
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list['list'],
- 'pageNo' => $list['pageNo'],
- 'totalCount' => $list['totalCount'],
- ],
- ]);
- }
- /**
- * 审核作品
- */
- public function actionAudit() {
- $id = post_params('id');
- $status = post_params('status', 0);
- $refuse_desc = post_params('refuse_desc', '');
- if (empty($id)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数不正确'
- ]);
- }
- if (!in_array($status, [1, 2])) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数不正确'
- ]);
- }
- if (is_array($id)) {
- $video_id_arr = $id;
- } else {
- $video_id_arr[] = intval($id);
- }
- foreach ($video_id_arr as $video_id) {
- $video_goods = VideoGoodsList::findOne(['id' => $video_id, 'status' => 0]);
- if (!$video_goods) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '作品不存在或不需要重复处理'
- ]);
- }
- $video_goods->status = $status;
- if (!empty($refuse_desc) && $status == 2) {
- $video_goods->refuse_desc = $refuse_desc;
- }
- $video_goods->updated_at = time();
- if (!$video_goods->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $video_goods->errors[0]
- ]);
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '审核成功'
- ]);
- }
- /**
- * 操作作品状态
- * @return \yii\web\Response
- */
- public function actionHandleVideo() {
- $id = post_params('id');
- $type = post_params('type');
- $status = post_params('status', 1);
- $status = intval($status);
- // 1:禁用,2: 删除
- if (!in_array($type, [1, 2]) || empty($id)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数错误'
- ]);
- }
- if (!is_array($id)) {
- $video_id[] = intval($id);
- } else {
- $video_id = $id;
- }
- $t = \Yii::$app->db->beginTransaction();
- foreach ($video_id as $_id) {
- $video = VideoGoodsList::findOne($_id);
- if (!$video) {
- $t->rollBack();
- return $this->asJson([
- 'code' => 1,
- 'msg' => '未找到ID:' . $_id . '记录'
- ]);
- }
- if ($type == 1) {
- if ($status == 1) {
- VideoGoodsList::updateAll(['is_show' => 1], ['id' => $video->id]);
- } else {
- VideoGoodsList::updateAll(['is_show' => 0], ['id' => $video->id]);
- }
- } else {
- VideoGoodsList::updateAll(['is_delete' => 1], ['id' => $video->id]);
- }
- $video->updated_at = time();
- if (!$video->save()) {
- $t->rollBack();
- return $this->asJson([
- 'code' => 1,
- 'msg' => 'ID: ' . $_id . '处理失败'
- ]);
- }
- }
- $t->commit();
- return $this->asJson([
- 'code' => 0,
- 'msg' => '处理成功'
- ]);
- }
- /**
- * 作者列表
- */
- public function actionAuthorList() {
- $name = get_params('name', '');
- $mobile = get_params('mobile', '');
- $status = get_params('status', -1);
- $query = VideoGoodsAuthor::find()->alias('vga')->where(['vga.store_id' => get_store_id(), 'vga.is_delete' => 0])
- ->leftJoin(['u' => User::tableName()], 'u.id=vga.user_id')
- ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding');
- if (!empty($name)) {
- $query->andWhere(['like', 'su.name', $name]);
- }
- if (!empty($mobile)) {
- $query->andWhere(['like', 'su.mobile', $mobile]);
- }
- if (in_array($status, [0, 1, 2])) {
- $query->andWhere(['vga.status' => $status]);
- }
- $query->orderBy('vga.id desc, vga.status asc')->select(
- 'vga.id, vga.user_id, vga.is_delete, vga.is_show, vga.created_at, vga.store_id, vga.status, su.name, su.mobile, su.avatar, vga.card_type, vga.card_front, vga.card_before, vga.name, vga.mobile, vga.desc'
- );
- $list = pagination_make($query);
- if (!empty($list['list'])) {
- foreach ($list['list'] as &$value) {
- // 获赞数
- $value['like_count'] = VideoGoodsVote::find()->where(['store_id' => $value['store_id'], 'is_delete' => 0,
- 'is_cancel' => 0, 'type' => 1, 'vl_user_id' => $value['user_id']])->count();
- // 收藏数
- $value['collect_count'] = VideoGoodsVote::find()->where(['store_id' => $value['store_id'], 'is_delete' => 0,
- 'is_cancel' => 0, 'type' => 2, 'vl_user_id' => $value['user_id']])->count();
- // 粉丝数
- $value['fans_count'] = VideoGoodsFocus::find()->where(['store_id' => $value['store_id'], 'is_delete' => 0,
- 'is_cancel' => 0, 'focus_user_id' => $value['user_id']])->count();
- // 关注数
- $value['focus_count'] = VideoGoodsFocus::find()->where(['store_id' => $value['store_id'], 'is_delete' => 0,
- 'is_cancel' => 0, 'user_id' => $value['user_id']])->count();
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list['list'],
- 'pageNo' => $list['pageNo'],
- 'totalCount' => $list['totalCount'],
- ],
- ]);
- }
- /**
- * 作者审核
- */
- public function actionAuditAuthor() {
- $id = post_params('id');
- $status = post_params('status', 0);
- if (empty($id)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数不正确'
- ]);
- }
- if (!in_array($status, [1, 2])) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数不正确'
- ]);
- }
- if (is_array($id)) {
- $author_id_arr = $id;
- } else {
- $author_id_arr[] = intval($id);
- }
- foreach ($author_id_arr as $author_id) {
- $author = VideoGoodsAuthor::findOne(['id' => $author_id, 'status' => 0]);
- if (!$author) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '作者不存在或不需要重复处理'
- ]);
- }
- $author->status = $status;
- $author->updated_at = time();
- if (!$author->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $author->errors[0]
- ]);
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '审核成功'
- ]);
- }
- /**
- * 操作作者状态
- * @return \yii\web\Response
- */
- public function actionHandleAuthor() {
- $id = post_params('id');
- $type = post_params('type');
- $status = post_params('status', 1);
- $status = intval($status);
- // 1:禁用,2: 删除
- if (!in_array($type, [1, 2]) || empty($id)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数错误'
- ]);
- }
- if (!is_array($id)) {
- $author_id[] = intval($id);
- } else {
- $author_id = $id;
- }
- $t = \Yii::$app->db->beginTransaction();
- foreach ($author_id as $_id) {
- $author = VideoGoodsAuthor::findOne($_id);
- if (!$author) {
- $t->rollBack();
- return $this->asJson([
- 'code' => 1,
- 'msg' => '未找到ID:' . $_id . '记录'
- ]);
- }
- if ($type == 1) {
- if ($status == 1) {
- VideoGoodsAuthor::updateAll(['is_show' => 1], ['id' => $author->id]);
- } else {
- VideoGoodsAuthor::updateAll(['is_show' => 0], ['id' => $author->id]);
- }
- } else {
- VideoGoodsAuthor::updateAll(['is_delete' => 1], ['id' => $author->id]);
- // 删除作品
- VideoGoodsList::updateAll(['is_delete' => 1], ['store_id' => get_store_id(), 'user_id' => $author->user_id]);
- }
- $author->updated_at = time();
- if (!$author->save()) {
- $t->rollBack();
- return $this->asJson([
- 'code' => 1,
- 'msg' => 'ID: ' . $_id . '处理失败'
- ]);
- }
- }
- $t->commit();
- return $this->asJson([
- 'code' => 0,
- 'msg' => '处理成功'
- ]);
- }
- /**
- * 用户关注或粉丝列表
- */
- public function actionUserFocusList() {
- $user_id = get_params('user_id', 0);
- $type = get_params('type', 0);
- $name = get_params('name', '');
- $mobile = get_params('mobile', '');
- $query = VideoGoodsFocus::find()->alias('vgf')->where(['vgf.store_id' => get_store_id(), 'vgf.is_delete' => 0,
- 'vgf.is_cancel' => 0, 'vgf.user_id' => $user_id])
- ->leftJoin(['u' => User::tableName()], 'u.id=vgf.focus_user_id')
- ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding');
- // 默认0,关注列表,其他粉丝列表
- if (!empty($type)) {
- $query->andWhere(['vgf.user_id' => $user_id]);
- } else {
- // 粉丝列表
- $query->andWhere(['vgf.focus_user_id' => $user_id]);
- }
- if (!empty($name)) {
- $query->andWhere(['like', 'su.name', $name]);
- }
- if (!empty($mobile)) {
- $query->andWhere(['like', 'su.mobile', $mobile]);
- }
- $query->orderBy('vgf.created_at desc')->select(
- 'vgf.*, su.name focus_user_name, su.mobile focus_user_mobile, su.avatar focus_user_avatar'
- );
- $list = pagination_make($query);
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list['list'],
- 'pageNo' => $list['pageNo'],
- 'totalCount' => $list['totalCount'],
- ],
- ]);
- }
- /**
- * 某个作品或用户的点赞,收藏,转发数据
- */
- public function actionVoteList() {
- $user_id = get_params('user_id', 0);
- $vl_id = get_params('vl_id', 0);
- $type = get_params('type', -1);
- $name = get_params('name', '');
- $mobile = get_params('mobile', '');
- if (empty($user_id) && empty($vl_id)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数错误'
- ]);
- }
- $query = VideoGoodsVote::find()->alias('vgv')->where(['vgv.store_id' => get_store_id(), 'vgv.is_delete' => 0,
- 'vgv.is_cancel' => 0])
- ->leftJoin(['u' => User::tableName()], 'u.id=vgv.user_id')
- ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding');
- if (!empty($user_id)) {
- $query->andWhere(['vgv.vl_user_id' => $user_id]);
- }
- if (!empty($vl_id)) {
- $query->andWhere(['vgv.vl_id' => $vl_id]);
- }
- if (in_array($type, [1, 2, 3])) {
- $query->andWhere(['vgv.type' => $type]);
- }
- if (!empty($name)) {
- $query->andWhere(['like', 'su.name', $name]);
- }
- if (!empty($mobile)) {
- $query->andWhere(['like', 'su.mobile', $mobile]);
- }
- $query->orderBy('vgv.created_at desc')->select(
- 'vgv.*, su.name vote_user_name, su.mobile vote_user_mobile, su.avatar vote_user_avatar'
- );
- $list = pagination_make($query);
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list['list'],
- 'pageNo' => $list['pageNo'],
- 'totalCount' => $list['totalCount'],
- ],
- ]);
- }
- public function actionVideoGoodsShareList()
- {
- $form = new VideoGoodsForm();
- $form->attributes = post_params();
- $res = $form->videoGoodsShareList();
- return $this->asJson($res);
- }
- }
|