| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\client\controllers\v1;
- use app\models\AccountLog;
- use app\models\Goods;
- use app\models\Option;
- use app\models\Order;
- use app\models\OrderDetail;
- use app\models\OrderRefund;
- use app\models\SaasUser;
- use app\models\StoreMini;
- use app\models\User;
- use app\models\VideoGoods;
- use app\models\VideoGoodsAuthor;
- use app\models\VideoGoodsCat;
- use app\models\VideoGoodsComment;
- use app\models\VideoGoodsCommentLike;
- use app\models\VideoGoodsFocus;
- use app\models\VideoGoodsList;
- use app\models\VideoGoodsReduceShow;
- use app\models\VideoGoodsReport;
- use app\models\VideoGoodsSetting;
- use app\models\VideoGoodsShare;
- use app\models\VideoGoodsVote;
- use app\modules\client\controllers\BaseController;
- use app\modules\client\models\v1\ShareQrcodeForm;
- use app\utils\Tools;
- use app\utils\VideoAnalyze;
- use EasyWeChat\Factory;
- use EasyWeChat\Kernel\BaseClient;
- use yii\base\BaseObject;
- use yii\data\Pagination;
- use yii\helpers\Json;
- class VideoGoodsController extends BaseController
- {
- /**
- * 作品列表
- */
- public function actionList() {
- $cat_id = get_params('cat_id', 0);
- $page = get_params('page', 1);
- $limit = get_params('limit', 20);
- $sort_type = get_params('sort_type', 0);
- $type = get_params('type', -1);
- $vl_id = get_params('vl_id', 0);
- $store_id = get_store_id();
- $user_id = get_user_id();
- $query = VideoGoodsList::find()->alias('vgl')->where(['vgl.store_id' => $store_id, 'vgl.is_delete' => 0, 'vgl.status' => 1, 'vgl.is_show' => 1])
- ->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]);
- }
- if ($sort_type == 1) { // 关注
- $query->leftJoin(['vgf' => VideoGoodsFocus::tableName()], 'vgf.focus_user_id=vgl.user_id')
- ->andWhere(['vgf.user_id' => $user_id, 'vgf.is_cancel' => 0, 'vgf.is_delete' => 0])
- ->orderBy('vgl.created_at desc, vgf.created_at desc');
- } else if ($sort_type == 2) { // 最新
- $query->orderBy('vgl.created_at desc');
- } else { // 默认 推荐排序
- $query->orderBy('vgl.sort desc, vgl.created_at desc');
- }
- if ($type != -1 && in_array($type, [1, 2])) {
- $query->andWhere(['vgl.type' => $type]);
- }
- if (!empty($vl_id)) {
- $query->andWhere(['vgl.id' => $vl_id]);
- }
- $query->andWhere(['vgl.user_delete' => 0]);
- $query->andWhere(['is not', 'u.id', null]);
- $query->andWhere(['is not', 'su.id', null]);
- $count = $query->count();
- //减少此类内容/不看该作者视频
- $author = VideoGoodsReduceShow::find()->where(['user_id' => $user_id])->select(['author'])->column();
- if (!empty($author) && !empty($store_id)) {
- $query->andWhere(
- [
- 'and',
- ['not in', 'vgl.user_id', $author]
- ]
- );
- }
- $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]);
- $list = $query->select('vgl.*, vgc.name cat_name, su.name user_name, su.avatar user_avatar')->limit($pagination->limit)
- ->offset($pagination->offset)->asArray()->all();
- foreach ($list as &$value) {
- // 当前作品是否点赞
- $value['is_like'] = VideoGoodsVote::findOne(['store_id' => $value['store_id'], 'type' => 1, 'is_delete' => 0, 'is_cancel' => 0,
- 'vl_id' => $value['id'], 'user_id' => $user_id]) ? 1 : 0;
- // 作品点赞数
- $like_count = VideoGoodsVote::find()->where(['store_id' => $value['store_id'], 'type' => 1, 'is_delete' => 0, 'is_cancel' => 0,
- 'vl_id' => $value['id']])->count();
- $value['like_count'] = Tools::float_number($like_count);
- // 当前作品是否收藏
- $value['is_collect'] = VideoGoodsVote::findOne(['store_id' => $value['store_id'], 'type' => 2, 'is_delete' => 0, 'is_cancel' => 0,
- 'vl_id' => $value['id'], 'user_id' => $user_id]) ? 1 : 0;
- // 收藏数量
- $value['collect_count'] = VideoGoodsVote::find()->where(['store_id' => get_store_id(), 'vl_id' => $value['id'], 'is_cancel' => 0, 'is_delete' => 0, 'type' => 2])->count();
- // 转发数量
- $value['trans_count'] = VideoGoodsVote::find()->where(['store_id' => get_store_id(), 'vl_id' => $value['id'], 'is_cancel' => 0, 'is_delete' => 0, 'type' => 3])->count();
- // 评论数量
- $value['comment_count'] = VideoGoodsComment::find()->where(['store_id' => get_store_id(), 'vl_id' => $value['id'], 'is_delete' => 0, 'status' => 1])->count();
- // 商品
- $value['goods_list'] = [];
- if ($value['goods_id']) {
- $goods_id = Json::decode($value['goods_id']);
- $value['goods_list'] = Goods::find()->where(['store_id' => get_store_id(), 'is_delete' => 0, 'status' => 1])->andWhere(['in', 'id', $goods_id])
- ->select('id, name, price, use_attr, attr, original_price, cover_pic')->asArray()->all();
- if (!empty($value['goods_list'])) {
- foreach ($value['goods_list'] as &$g) {
- $g['attr_group_list'] = Goods::findOne($g['id'])->getAttrGroupList();
- }
- }
- }
- $value['add_time'] = Tools::date_before($value['created_at'], time());
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'list' => $list,
- 'page_count' => $pagination->pageCount,
- 'row_count' => $count,
- 'cat_list' => VideoGoodsCat::find()->where(['store_id' => $store_id, 'is_show' => 1, 'is_delete' => 0])
- ->orderBy('sort desc')->select('id, name')->asArray()->all()
- ]
- ]);
- }
- //视频解析
- public function actionVideoAnalyze() {
- try {
- $url = post_params('url');
- $form = new VideoAnalyze();
- $form->store_id = get_store_id();
- $result = $form->videoAnalyzeCurl($url);
- $result = json_decode($result, true);
- if ($result['code'] === 200) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '解析成功',
- 'data' => $result['data']
- ]);
- }
- throw new \Exception('解析失败');
- //测试数据
- // return $this->asJson([
- // 'code' => 0,
- // 'msg' => '解析成功',
- // 'data' => [
- // "title" => "大哥每次离开总是装作轻松的样子",
- // "image" => "http://tbfile.izuiyou.com/img/frame/id/2234788961?w=540&delogo=0",
- // "video" => "http://jsy.izuiyou.com/zyvqwz/264/93/00/664f-fd26-11ed-b1f9-00163e023ce8",
- // "url" => "http://jsy.izuiyou.com/zyvqwz/264/93/00/664f-fd26-11ed-b1f9-00163e023ce8",
- // "alais" => null
- // ]
- // ]);
- } catch (\Exception $e) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage()
- ]);
- }
- }
- /**
- * 1,点赞,2,收藏,3,转发
- */
- public function actionVote() {
- $user_id = get_user_id();
- $store_id = get_store_id();
- $vl_id = post_params('vl_id', 0);
- $type = post_params('type', 0);
- if (empty($vl_id) || !in_array($type, [1, 2, 3])) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数错误'
- ]);
- }
- $video = VideoGoodsList::findOne(['store_id' => $store_id, 'status' => 1, 'is_show' => 1, 'is_delete' => 0, 'id' => $vl_id]);
- if (!$video) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '操作的作品不存在'
- ]);
- }
- $video_vote = VideoGoodsVote::findOne(['store_id' => $store_id, 'type' => $type, 'is_delete' => 0,
- 'vl_id' => $vl_id, 'user_id' => $user_id]);
- if ($video_vote && $type != 3) {
- if ($video_vote->is_cancel == 0) {
- if (in_array($type, [1, 2])) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $type == 1 ? '请不要重复点赞哦~' : '请不要重复收藏哦~'
- ]);
- }
- } else {
- $video_vote->is_cancel = 0;
- $video_vote->updated_at = time();
- if (!$video_vote->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '操作失败'
- ]);
- }
- }
- } else {
- $video_vote = new VideoGoodsVote();
- $video_vote->store_id = $store_id;
- $video_vote->user_id = $user_id;
- $video_vote->type = $type;
- $video_vote->vl_id = $vl_id;
- $video_vote->vl_user_id = VideoGoodsList::findOne($vl_id)->user_id;
- $video_vote->is_delete = 0;
- $video_vote->is_cancel = 0;
- $video_vote->created_at = time();
- $video_vote->updated_at = time();
- if (!$video_vote->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '操作失败'
- ]);
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => $type == 1 ? '点赞成功' : ($type == 2 ? '收藏成功' : '转发成功')
- ]);
- }
- /**
- * 取消点赞或者收藏
- */
- public function actionCancelVote() {
- $user_id = get_user_id();
- $store_id = get_store_id();
- $vl_id = post_params('vl_id', 0);
- $type = post_params('type', 0);
- if (empty($vl_id) || !in_array($type, [1, 2])) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数错误'
- ]);
- }
- $video_vote = VideoGoodsVote::findOne(['store_id' => $store_id, 'type' => $type, 'is_delete' => 0, 'is_cancel' => 0,
- 'vl_id' => $vl_id, 'user_id' => $user_id]);
- if (!$video_vote) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '没有记录哦~'
- ]);
- }
- $video_vote->is_cancel = 1;
- $video_vote->updated_at = time();
- if (!$video_vote->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '取消失败'
- ]);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '取消成功'
- ]);
- }
- /**
- * 关注用户
- */
- public function actionFocus() {
- $user_id = get_user_id();
- $store_id = get_store_id();
- $focus_user_id = post_params('focus_user_id');
- if (empty($focus_user_id)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '被关注人不能为空'
- ]);
- }
- if ($focus_user_id == $user_id) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '不能关注自己'
- ]);
- }
- $focus = VideoGoodsFocus::findOne(['store_id' => $store_id, 'is_delete' => 0,
- 'focus_user_id' => $focus_user_id, 'user_id' => $user_id]);
- if ($focus) {
- if ($focus->is_cancel == 0) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '请不要重复关注哦~'
- ]);
- } else {
- $focus->is_cancel = 0;
- $focus->updated_at = time();
- if (!$focus->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '关注失败'
- ]);
- }
- }
- } else {
- $focus = new VideoGoodsFocus();
- $focus->store_id = $store_id;
- $focus->user_id = $user_id;
- $focus->focus_user_id = $focus_user_id;
- $focus->is_delete = 0;
- $focus->is_cancel = 0;
- $focus->created_at = time();
- $focus->updated_at = time();
- if (!$focus->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '关注失败'
- ]);
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '关注成功'
- ]);
- }
- /**
- * 取消关注用户
- */
- public function actionCancelFocus() {
- $user_id = get_user_id();
- $store_id = get_store_id();
- $focus_user_id = post_params('user_id');
- if (empty($focus_user_id)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '取消关注人不能为空'
- ]);
- }
- $focus = VideoGoodsFocus::findOne(['store_id' => $store_id, 'is_delete' => 0,
- 'focus_user_id' => $focus_user_id, 'user_id' => $user_id, 'is_cancel' => 0]);
- if (!$focus) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '关系不存在'
- ]);
- }
- $focus->is_cancel = 1;
- if (!$focus->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '取消失败'
- ]);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '取消成功'
- ]);
- }
- /**
- * 提交抖品
- */
- public function actionSubmit(){
- $store_id = get_params('store_id') ?: get_store_id();
- $user_id = get_user_id();
- $saas_user = get_saas_user();
- $title = post_params('title', $saas_user->name ?? '');
- $cat_id = post_params('cat_id');
- $cover_pic = post_params('cover_pic', '');
- $pic_list = post_params('pic_list', []);
- $video_url = post_params('video_url', '');
- $content = post_params('content', '');
- $type = post_params('type');
- $longitude = post_params('longitude', '');
- $latitude = post_params('latitude', '');
- $address = post_params('address', '');
- $goods_id = post_params('goods_id', []);
- $douyin_url = post_params('douyin_url', '');
- $is_douyin_video = \post_params('is_douyin_video', 0); // 是否是抖音的视频链接, 如果是,要用消息队列下载到本地或oss
- $author = VideoGoodsAuthor::findOne(['store_id' => $store_id, 'user_id' => $user_id, 'is_delete' => 0, 'status' => 1]);
- $setting = VideoGoodsSetting::findOne(['store_id' => $store_id]);
- //TODO 感觉有问题 start
- if (($setting->is_author_audit === 1 && !$author) || ($setting->is_author_audit === 1 && (int)$author->is_show === 0)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '非创作者禁止发布'
- ]);
- } elseif ($setting->is_author_audit === 0 && !$author) {
- // 创建作者
- $author = new VideoGoodsAuthor();
- $author->store_id = get_store_id();
- $author->user_id = $user_id;
- $author->is_delete = 0;
- $author->is_show = 1;
- $author->status = 1;
- $author->save();
- }
- //TODO end
- if (!in_array($type, [1, 2])) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '发布类型错误'
- ]);
- }
- if (empty($cat_id)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '请选择分类'
- ]);
- }
- // 视频
- if ($type == 1) {
- if (empty($video_url)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '请上传视频'
- ]);
- }
- if (empty($cover_pic)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '请上传视频封面'
- ]);
- }
- }
- // 图文
- if ($type == 2) {
- if (empty($title)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '请填写标题'
- ]);
- }
- if (empty($pic_list) || !is_array($pic_list)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '请正确的上传图片'
- ]);
- }
- }
- if (empty($content)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '请填写内容'
- ]);
- }
- if (!empty($goods_id) && !is_array($goods_id)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '商品数据格式不正确'
- ]);
- }
- $setting = VideoGoodsSetting::findOne(['store_id' => $store_id]);
- if ($setting) {
- if ($setting->is_video_audit) {
- $is_video_audit = true;
- } else {
- $is_video_audit = false;
- }
- } else {
- // 在未保存过设置项的时候 页面默认是关闭审核 所以这里也要是默认关闭审核
- $is_video_audit = false;
- }
- $video = new VideoGoodsList();
- $video->store_id = $store_id;
- $video->user_id = $user_id;
- $video->title = $title;
- $video->cat_id = $cat_id;
- $video->address = $address;
- $video->cover_pic = $cover_pic;
- $video->pic_list = !empty($pic_list) ? Json::encode($pic_list) : Json::encode([]);
- $video->video_url = $video_url;
- $video->content = $content;
- $video->type = $type;
- $video->goods_id = !empty($goods_id) ? Json::encode($goods_id) : Json::encode([]);
- $video->longitude = $longitude;
- $video->latitude = $latitude;
- // 判断当前开启是否审核
- $video->status = $is_video_audit ? 0 : 1;
- $video->douyin_url = $douyin_url;
- if (!$video->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '上传失败'
- ]);
- }
- if ($is_douyin_video) {
- queue_push(new \app\jobs\DownloadVideoJob([
- 'id' => $video->id,
- 'baseUrl' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl,
- ]));
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '上传成功'
- ]);
- }
- /**
- * 可选择商品列表
- */
- public function actionGoodsList() {
- $name = get_params('name', '');
- $page = get_params('page', 1);
- $limit = get_params('limit', 10);
- $video_goods = VideoGoods::find()->where(['store_id' => get_store_id(), 'status' => 1, 'is_delete' => 0])->asArray()->all();
- if (empty($video_goods)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '没有可选择的商品'
- ]);
- }
- $query = Goods::find()->alias('g')
- ->where(['g.store_id' => get_store_id(), 'g.is_delete' => 0, 'g.md_food_id' => 0, 'g.status' => 1])
- ->andWhere(['not like', 'g.name', '当面付'])->andWhere(['in', 'g.product_type', [0]])
- ->andWhere(['in', 'id', array_column($video_goods, 'goods_id')]);
- if (!empty($name)) {
- $query->andWhere([
- 'like',
- 'g.name',
- $name
- ]);
- }
- $select = ['g.id', 'g.name', 'g.status', 'g.service',
- 'g.virtual_sales', 'g.price', 'g.goods_num', 'g.sort' ,'g.cover_pic', 'g.original_price',
- 'g.attr', 'g.detail', 'g.use_attr'];
- $count = $query->count();
- $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]);
- $list = $query->offset($pagination->offset)->limit($pagination->limit)
- ->select($select)->orderBy(['g.sort' => SORT_DESC, 'g.id' => SORT_DESC])->asArray()->all();
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'list' => $list,
- 'page_count' => $pagination->pageCount,
- 'row_count' => $count,
- ]
- ]);
- }
- /**
- * 分类列表
- */
- public function actionCatList() {
- $store_id = get_store_id();
- $cat_list = VideoGoodsCat::find()->where(['is_show' => 1, 'is_delete' => 0, 'store_id' => $store_id])->orderBy('sort desc')->asArray()->all();
- $arr = [
- [
- 'id' => 0,
- 'name' => '全部'
- ]
- ];
- if (!empty($cat_list)) {
- foreach ($cat_list as $v) {
- $arr[] = [
- 'id' => $v['id'],
- 'name' => $v['name']
- ];
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $arr
- ]);
- }
- /**
- * 作品详情
- */
- public function actionDetail() {
- $id = get_params('id');
- $video = VideoGoodsList::findOne(['store_id' => get_store_id(), 'id' => $id, 'status' => 1, 'is_delete' => 0, 'is_show' => 1, 'user_delete' => 0]);
- if (!$video) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '作品不存在'
- ]);
- }
- $user = User::findOne($video->user_id);
- // 点赞数量
- $like_count = VideoGoodsVote::find()->where(['store_id' => get_store_id(), 'vl_id' => $id, 'is_cancel' => 0, 'is_delete' => 0, 'type' => 1])->count();
- // 收藏数量
- $collect_count = VideoGoodsVote::find()->where(['store_id' => get_store_id(), 'vl_id' => $id, 'is_cancel' => 0, 'is_delete' => 0, 'type' => 2])->count();
- // 转发数量
- $trans_count = VideoGoodsVote::find()->where(['store_id' => get_store_id(), 'vl_id' => $id, 'is_cancel' => 0, 'is_delete' => 0, 'type' => 3])->count();
- // 评论数量
- $comment_count = VideoGoodsComment::find()->where(['store_id' => get_store_id(), 'vl_id' => $id, 'is_delete' => 0, 'status' => 1])->count();
- // 商品
- $goods_id = Json::decode($video->goods_id);
- $goods_list = Goods::find()->where(['store_id' => get_store_id(), 'is_delete' => 0, 'status' => 1])->andWhere(['in', 'id', $goods_id])
- ->select('id, name, price, use_attr, attr, original_price, cover_pic')->asArray()->all();
- if (!empty($goods_list)) {
- foreach ($goods_list as &$g) {
- $g['attr_group_list'] = Goods::findOne($g['id'])->getAttrGroupList();
- }
- }
- $data = [
- 'user_id' => $user->id,
- 'user_name' => $user->nickname,
- 'user_avatar' => $user->avatar_url,
- 'video_url' => $video->video_url,
- 'pic_list' => $video->pic_list ? Json::decode($video->pic_list) : [],
- 'type' => $video->type,
- 'title' => $video->title,
- 'content' => $video->content,
- 'cover_pic' => $video->cover_pic,
- 'like_count' => Tools::float_number($like_count),
- // 是否点赞
- 'is_like' => VideoGoodsVote::findOne(['store_id' => get_store_id(), 'type' => 1, 'is_delete' => 0, 'is_cancel' => 0, 'vl_id' => $id, 'user_id' => get_user_id()]) ? 1 : 0,
- 'is_collect' => VideoGoodsVote::findOne(['store_id' => get_store_id(), 'type' => 2, 'is_delete' => 0, 'is_cancel' => 0, 'vl_id' => $id, 'user_id' => get_user_id()]) ? 1 : 0,
- 'comment_count' => Tools::float_number($comment_count),
- 'collect_count' => Tools::float_number($collect_count),
- 'trans_count' => Tools::float_number($trans_count),
- 'goods' => [
- 'count' => count($goods_list),
- 'list' => $goods_list
- ],
- 'longitude' => $video->longitude,
- 'latitude' => $video->latitude,
- 'address' => $video->address,
- 'add_time' => Tools::date_before($video->created_at, time()),
- 'is_focus' => VideoGoodsFocus::findOne(['store_id' => get_store_id(), 'user_id' => get_user_id(), 'focus_user_id' => $video->user_id, 'is_delete' => 0, 'is_cancel' => 0]) ? 1 : 0,
- 'douyin_url' => $video->douyin_url,
- 'rewards' => VideoGoodsSetting::checkUserRewardsIntegral($id),
- ];
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $data
- ]);
- }
- public function actionLookVideoSendIntegral(){
- $user_id = get_user_id();
- $id = get_params('id');
- $checkRes = VideoGoodsSetting::checkUserRewardsIntegral($id);
- if($checkRes['remaining_number'] <= 0){
- return $this->asJson([
- 'code' => 1,
- 'msg' => '用户无获取积分奖励次数'
- ]);
- }
- $res = AccountLog::saveLog($user_id,$checkRes['integral'],AccountLog::TYPE_INTEGRAL,AccountLog::LOG_TYPE_INCOME,AccountLog::VIDEO_GOODS_REWARDS,$id,'短视频奖励');
- if($res){
- return $this->asJson([
- 'code' => 0,
- 'msg' => '积分奖励发放成功',
- // 重新计算返回可领取次数等信息
- 'data' => VideoGoodsSetting::checkUserRewardsIntegral($id),
- ]);
- }else{
- return $this->asJson([
- 'code' => 1,
- 'msg' => '积分奖励发放失败'
- ]);
- }
- }
- /**
- * 用户删除自己作品
- */
- public function actionUserDelete() {
- $user_id = get_user_id();
- $id = post_params('id');
- $video = VideoGoodsList::findOne(['id' => $id, 'user_delete' => 0, 'is_delete' => 0]);
- if (!$video) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '作品不存在'
- ]);
- }
- if ($video->user_id != $user_id) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '不能删除他人作品'
- ]);
- }
- $video->user_delete = 1;
- if (!$video->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '删除失败'
- ]);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '删除成功'
- ]);
- }
- /**
- * 抖品个人中心
- */
- public function actionUserIndex() {
- $store_id = get_store_id();
- $user_id = get_params('user_id', get_user_id());
- if (!$user_id) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '未找到用户数据'
- ]);
- }
- $author = VideoGoodsAuthor::findOne(['store_id' => $store_id, 'status' => 1, 'is_delete' => 0, 'is_show' => 1, 'user_id' => $user_id]);
- $setting = VideoGoodsSetting::findOne(['store_id' => $store_id]);
- if ($setting->is_author_audit === 0 && !$author) {
- // 创建作者
- $author = new VideoGoodsAuthor();
- $author->store_id = get_store_id();
- $author->is_delete = 0;
- $author->is_show = 0;
- $author->user_id = $user_id;
- $author->status = 0;
- if (!$author->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '未找到作者相关数据'
- ]);
- };
- }
- if ($setting->is_author_audit === 1 && !$author) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '未找到作者相关数据'
- ]);
- }
- // 用户信息
- $user = User::findOne($user_id);
- $saas_user = SaasUser::findOne(['mobile' => $user->binding]);
- // 获得收藏和点赞数量
- $vote_count = VideoGoodsVote::find()->where(['store_id' => $store_id, 'vl_user_id' => $user_id, 'is_cancel' => 0, 'is_delete' => 0])->andWhere(['in', 'type', [1, 2]])->count();
- // 粉丝数量
- $fans_count = VideoGoodsFocus::find()->where(['store_id' => $store_id, 'focus_user_id' => $user_id, 'is_delete' => 0, 'is_cancel' => 0])->count();
- // 关注数量
- $focus_count = VideoGoodsFocus::find()->where(['store_id' => $store_id, 'user_id' => $user_id, 'is_delete' => 0, 'is_cancel' => 0])->count();
- // 是否关注
- $is_focus = VideoGoodsFocus::findOne(['store_id' => $store_id, 'user_id' => get_user_id(), 'focus_user_id' => $user_id, 'is_delete' => 0, 'is_cancel' => 0]) ? 1 : 0;
- $data = [
- 'user_info' => [
- 'id' => $user->id,
- 'name' => $saas_user->name,
- 'avatar' => $saas_user->avatar
- ],
- 'vote_count' => Tools::float_number($vote_count),
- 'fans_count' => Tools::float_number($fans_count),
- 'focus_count' => Tools::float_number($focus_count),
- 'is_focus' => $is_focus,
- 'collect_count' => VideoGoodsVote::find()->where(['store_id' => $store_id, 'vl_user_id' => $user_id, 'is_cancel' => 0, 'is_delete' => 0, 'type' => 2])->count(),
- 'up_count' => VideoGoodsVote::find()->where(['store_id' => $store_id, 'vl_user_id' => $user_id, 'is_cancel' => 0, 'is_delete' => 0, 'type' => 1])->count()
- ];
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $data
- ]);
- }
- /**
- * 用户关注的用户列表
- */
- public function actionFocusList() {
- $page = get_params('page', 1);
- $limit = get_params('limit', 20);
- $store_id = get_store_id();
- $user_id = get_params('user_id', get_user_id());
- $query = VideoGoodsFocus::find()->alias('vgf')->where(['vgf.store_id' => $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');
- $count = $query->count();
- $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]);
- $list = $query->select('u.id, su.name, su.avatar')->limit($pagination->limit)
- ->offset($pagination->offset)->orderBy('vgf.created_at desc')->asArray()->all();
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'list' => $list,
- 'page_count' => $pagination->pageCount,
- 'row_count' => $count,
- ]
- ]);
- }
- /**
- * 用户粉丝列表
- */
- public function actionFansList() {
- $page = get_params('page', 1);
- $limit = get_params('limit', 20);
- $store_id = get_store_id();
- $user_id = get_params('user_id', get_user_id());
- $query = VideoGoodsFocus::find()->alias('vgf')->where(['vgf.store_id' => $store_id, 'vgf.is_delete' => 0, 'vgf.is_cancel' => 0, 'vgf.focus_user_id' => $user_id])
- ->leftJoin(['u' => User::tableName()], 'u.id=vgf.user_id')
- ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding');
- $count = $query->count();
- $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]);
- $list = $query->select('u.id, su.name, su.avatar')->limit($pagination->limit)
- ->offset($pagination->offset)->orderBy('vgf.created_at desc')->asArray()->all();
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'list' => $list,
- 'page_count' => $pagination->pageCount,
- 'row_count' => $count,
- ]
- ]);
- }
- /**
- * 用户作品列表
- */
- public function actionUserVideoList() {
- $type = get_params('type', 0);
- $choose = get_params('choose', -1);
- $page = get_params('page', 1);
- $limit = get_params('limit', 20);
- $store_id = get_store_id();
- $user_id = get_params('user_id', get_user_id());
- if ($choose == -1) { // 默认动态
- $query = VideoGoodsList::find()->alias('vgl')->where(['vgl.store_id' => $store_id, 'vgl.is_delete' => 0,
- 'vgl.status' => 1, 'vgl.is_show' => 1, 'vgl.user_id' => $user_id, 'vgl.user_delete' => 0])
- ->leftJoin(['u' => User::tableName()], 'u.id=vgl.user_id')
- ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding');
- } else { // 点赞作品记录
- $query = VideoGoodsVote::find()->alias('vgv')->where(['vgv.store_id' => $store_id, 'vgv.is_delete' => 0,
- 'vgv.is_cancel' => 0, 'vgv.type' => 1, 'vgv.user_id' => $user_id, 'vgl.user_delete' => 0])
- ->leftJoin(['vgl' => VideoGoodsList::tableName()], 'vgl.id=vgv.vl_id')
- ->leftJoin(['u' => User::tableName()], 'u.id=vgv.vl_user_id')
- ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding');
- }
- $query->andWhere(['is not', 'u.id', null]);
- $query->andWhere(['is not', 'su.id', null]);
- // 视频数量
- $video_count_query = clone $query;
- $video_count = $video_count_query->andWhere(['vgl.type' => 1])->count();
- // 图文数量
- $pic_count_query = clone $query;
- $pic_count = $pic_count_query->andWhere(['vgl.type' => 2])->count();
- // 所有
- $all_count_query = clone $query;
- $all_count = $all_count_query->count();
- // 类型。1:视频,2:图文
- if (!empty($type)) {
- $query->andWhere(['vgl.type' => $type]);
- }
- if ($choose == -1) {
- $query->orderBy('vgl.is_top desc, vgl.created_at desc');
- } else {
- $query->orderBy('vgv.created_at desc');
- }
- $count = $query->count();
- $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]);
- $list = $query->select('vgl.*, su.name user_name, su.avatar user_avatar')->limit($pagination->limit)
- ->offset($pagination->offset)->asArray()->all();
- foreach ($list as &$value) {
- // 当前作品是否点赞
- $value['is_like'] = VideoGoodsVote::findOne(['store_id' => $value['store_id'], 'type' => 1, 'is_delete' => 0, 'is_cancel' => 0,
- 'vl_id' => $value['id'], 'user_id' => $user_id]) ? 1 : 0;
- // 作品点赞数
- $like_count = VideoGoodsVote::find()->where(['store_id' => $value['store_id'], 'type' => 1, 'is_delete' => 0, 'is_cancel' => 0,
- 'vl_id' => $value['id']])->count();
- $value['like_count'] = Tools::float_number($like_count);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'list' => $list,
- 'page_count' => $pagination->pageCount,
- 'row_count' => $count,
- 'all_count' => $all_count,
- 'video_count' => $video_count,
- 'pic_count' => $pic_count
- ]
- ]);
- }
- /**
- * 更换置顶
- */
- public function actionChangeTop() {
- $store_id = get_store_id();
- $vl_id = post_params('vl_id', 0);
- $user_id = get_user_id();
- $video = VideoGoodsList::findOne(['id' => $vl_id, 'user_id' => $user_id, 'store_id' => $store_id]);
- if (!$video) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '需要置顶的数据不存在'
- ]);
- }
- if ($video->user_id != $user_id) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '系统异常'
- ]);
- }
- if ($video->is_top == 1) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '请勿重复置顶'
- ]);
- }
- VideoGoodsList::updateAll(['is_top' => 0], ['user_id' => $user_id, 'store_id' => $store_id]);
- $video->is_top = 1;
- if (!$video->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '置顶失败'
- ]);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '置顶成功'
- ]);
- }
- //申请单提交配置信息
- public function actionAuditApplyConfig()
- {
- try {
- $store_id = get_params('store_id') ?: get_store_id();
- $setting = VideoGoodsSetting::findOne(['store_id' => $store_id]);
- $user_id = get_user_id();
- $author = VideoGoodsAuthor::findOne(['store_id' => $store_id, 'user_id' => $user_id, 'is_delete' => 0,
- 'is_show' => 1, 'status' => [1, 0]]);
- if (!$setting) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'verify' => []
- ]
- ]);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'verify' => json_decode($setting->verify) ?: [],
- 'is_author_audit' => $setting->is_author_audit,
- 'is_author' => $author->status == 1 ? 1 : 0,
- 'is_apply' => $author ? 1 : 0
- ]
- ]);
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => "数据错误"
- ];
- }
- }
- /**
- * 作者权限提交
- * @return \yii\web\Response
- */
- public function actionAuthorApply() {
- $user_id = get_user_id();
- $store_id = get_store_id();
- $author = VideoGoodsAuthor::findOne(['store_id' => $store_id, 'is_delete' => 0, 'user_id' => $user_id]);
- $setting = VideoGoodsSetting::findOne(['store_id' => $store_id]);
- if ($setting) {
- if ($setting->is_author_audit == 1) {
- $is_author_audit = true;
- } else {
- $is_author_audit = false;
- }
- } else {
- $is_author_audit = true;
- }
- if ($author) {
- if ($author->status == 1) {
- return $this->asJson([
- 'status' => 1,
- 'code' => 0,
- 'msg' => '作者权限已开通'
- ]);
- } else if ($author->status == 2 || $author->status == 0) {
- if (!$is_author_audit) {
- $author->status = 1;
- if (!$author->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '作者权限开通失败'
- ]);
- }
- return $this->asJson([
- 'status' => 1,
- 'code' => 0,
- 'msg' => '作者权限开通成功'
- ]);
- } else {
- if ($author->status == 2) {
- $author->status = 0;
- if (!$author->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '作者权限开通申请失败'
- ]);
- }
- }
- return $this->asJson([
- 'status' => 0,
- 'code' => 0,
- 'msg' => '已提交,请等待审核'
- ]);
- }
- } else {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '系统异常'
- ]);
- }
- } else {
- $video_author = new VideoGoodsAuthor();
- $video_author->store_id = $store_id;
- $video_author->user_id = $user_id;
- $video_author->is_delete = 0;
- $video_author->is_show = 1;
- $video_author->card_type = post_params("card_type", 0);
- $video_author->name = post_params("name", "");
- $video_author->card_front = post_params("card_front", "");
- $video_author->card_before = post_params("card_before", "");
- $video_author->mobile = post_params("mobile", "");
- $video_author->desc = post_params("desc", "");
- if ($is_author_audit) {
- $video_author->status = 0;
- } else {
- $video_author->status = 1;
- }
- $video_author->created_at = time();
- $video_author->updated_at = time();
- if (!$video_author->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '提交异常'
- ]);
- }
- return $this->asJson([
- 'status' => $video_author->status,
- 'code' => 0,
- 'msg' => !$is_author_audit ? '开通权限成功' : '申请已提交!'
- ]);
- }
- }
- /**
- * 提交评论
- */
- public function actionSubmitComment() {
- $content = post_params('content');
- $user_id = get_user_id();
- $vl_id = post_params('vl_id');
- $top_parent_id = post_params('top_parent_id', 0);
- $parent_id = post_params('parent_id', 0);
- if (empty($content) || empty($vl_id)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数错误,请稍后重试'
- ]);
- }
- $video = VideoGoodsList::findOne($vl_id);
- if (!$video) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '评论的内容不存在'
- ]);
- }
- if ($parent_id) {
- $parent_comment = VideoGoodsComment::findOne(['store_id' => get_store_id(), 'status' => 1, 'is_delete' => 0, 'id' => $parent_id]);
- if (!$parent_comment) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '回复的评论不存在'
- ]);
- }
- }
- /** @var \EasyWeChat\MiniProgram\Application $wechat */
- // 敏感词校验
- // Todo 此处获取微信配置有误,先不处理这块逻辑
- if ($this->wechat && false) {
- if (is_open_platform()) {
- $wechat = $this->wechat;
- $result = $wechat->content_security->checkText($content);
- } else {
- //微信三方配置信息
- $wx_config = [
- //微信三方appid
- 'app_id' => Option::get("platform_third_appid", 0, 'saas')['value'],
- //微信三方appSecret
- 'secret' => Option::get("platform_third_secret", 0, 'saas')['value'],
- //微信三方平台设置的token
- 'token' => Option::get("platform_token", 0, 'saas')['value'],
- //微信三方平台设置的加密key
- 'aes_key' => Option::get("platform_encodingAesKey", 0, 'saas')['value']
- ];
- $openPlatform = Factory::openPlatform($wx_config);
- //获取小程序信息
- $store_mini = StoreMini::find()->where(['store_id' => get_store_id()])->orderBy('id desc')->one();
- if (empty($store_mini->appid) || empty($store_mini->authorizer_refresh_token)) {
- return [
- 'code' => 1,
- 'msg' => '获取小程序信息失败',
- ];
- }
- //配置easyWechat
- //获取微信配置
- $miniProgram = $openPlatform->miniProgram($store_mini->appid, $store_mini->authorizer_refresh_token);
- //使用自定义接口
- $client = new BaseClient($miniProgram);
- //请求自定义接口
- $res = $client->httpPostJson('wxa/msg_sec_check');
- }
- if ($result['errcode'] != 0) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '发布的内容不符合要求'
- ]);
- }
- }
- $comment = new VideoGoodsComment();
- $comment->comment = $content;
- $comment->reply_id = 0;
- $comment->reply_name = '';
- $comment->user_id = $user_id;
- $comment->created_at = time();
- $comment->vl_id = $vl_id;
- $comment->store_id = get_store_id();
- $comment->parent_id = $parent_id;
- $comment->top_parent_id = $top_parent_id;
- if ($comment->save()) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '评论成功'
- ]);
- }
- return $this->asJson([
- 'code' => 1,
- 'msg' => '提交失败',
- ]);
- }
- /**
- * 作品评论列表
- */
- public function actionCommentList() {
- $page = get_params('page', 1);
- $limit = get_params('limit', 10);
- $vl_id = get_params('vl_id', 0);
- $user_id = get_user_id();
- $comment_list = VideoGoodsComment::find()->alias('vgc')->leftJoin(['u' => User::tableName()],'vgc.user_id=u.id')
- ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding')
- ->where(['vgc.store_id' => get_store_id(), 'vgc.vl_id' => $vl_id, 'vgc.is_delete' => 0, 'vgc.top_parent_id' => 0, 'vgc.status' => 1])
- ->select('vgc.user_id, su.name, su.avatar, vgc.id, vgc.comment, vgc.created_at');
- $count = $comment_list->count();
- $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]);
- $comment_list = $comment_list->offset($pagination->offset)->limit($pagination->limit)
- ->orderBy('vgc.created_at DESC')
- ->asArray()->all();
- $now_time = time();
- $author_user_id = VideoGoodsList::findOne($vl_id)->user_id;
- foreach ($comment_list as &$item){
- $item['time'] = Tools::getTime($item['created_at'], $now_time);
- $item['is_like'] = VideoGoodsCommentLike::findOne(['user_id' => $user_id, 'comment_id' => $item['id'], 'is_cancel' => 0]) ? 1 : 0;
- $item['like_count'] = VideoGoodsCommentLike::find()->where(['comment_id' => $item['id'], 'is_cancel' => 0])->count();
- $reply_list = VideoGoodsComment::find()->alias('vgc')
- ->leftJoin(['u' => User::tableName()],'vgc.user_id=u.id')
- ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding')
- ->where(['vgc.vl_id' => $vl_id, 'vgc.is_delete' => 0, 'vgc.top_parent_id' => $item['id'], 'vgc.status' => 1])
- ->select('vgc.user_id, su.name, su.avatar, vgc.id, vgc.comment, vgc.created_at, vgc.parent_id')
- ->orderBy('vgc.created_at desc')->asArray()->all();
- foreach($reply_list as &$reply) {
- // 被回复人信息
- $reply_info = VideoGoodsComment::findOne($reply['parent_id']);
- $saas_user = SaasUser::findOne(['mobile' => User::findOne($reply_info->user_id)->binding]);
- $reply['reply_user'] = $saas_user->name;
- $reply['reply_user_id'] = $reply_info->user_id;
- $reply['reply_user_avatar'] = $saas_user->avatar;
- $reply['time'] = Tools::getTime($reply['created_at'], $now_time);
- $reply['is_like'] = VideoGoodsCommentLike::findOne(['user_id' => $user_id, 'comment_id' => $reply['id'], 'is_cancel' => 0]) ? 1 : 0;
- $reply['like_count'] = VideoGoodsCommentLike::find()->where(['comment_id' => $reply['id'], 'is_cancel' => 0])->count();
- }
- $item['reply_list'] = $reply_list;
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'list' => $comment_list,
- 'page_count' => $pagination->pageCount,
- 'row_count' => $count,
- 'user_id' => $author_user_id
- ]
- ]);
- }
- /**
- * 评论点赞
- */
- public function actionCommentLike() {
- $id = post_params('id');
- if (empty($id)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '缺少必要参数'
- ]);
- }
- $store_id = get_store_id();
- $user_id = get_user_id();
- $comment_like = VideoGoodsCommentLike::findOne(['store_id' => $store_id, 'comment_id' => $id, 'user_id' => $user_id, 'is_cancel' => 0]);
- if($comment_like) {
- $comment_like->is_cancel = $comment_like->is_cancel ? 0 : 1;
- $comment_like->updated_at = time();
- } else {
- $comment_like = new VideoGoodsCommentLike();
- $comment_like->is_cancel = 0;
- $comment_like->updated_at = time();
- $comment_like->store_id = $store_id;
- $comment_like->comment_id = $id;
- $comment_like->user_id = $user_id;
- $comment_like->created_at = time();
- }
- if (!$comment_like->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '点赞失败'
- ]);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '点赞成功'
- ]);
- }
- /**
- * 举报抖品
- */
- public function actionReport() {
- $user_id = get_user_id();
- $store_id = get_store_id();
- $vl_id = post_params('vl_id', 0);
- $video = VideoGoodsList::findOne($vl_id);
- if (!$video) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '举报内容不存在'
- ]);
- }
- if ($video->is_delete == 1) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '举报内容已删除'
- ]);
- }
- if ($video->is_show == 0) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '举报内容已隐藏'
- ]);
- }
- $pic_url = post_params('pic_url', []);
- $desc = post_params('desc', '');
- $type = post_params('type', 0);
- if (empty($desc) || !in_array($type, array_keys(VideoGoodsReport::$validReportType))) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '参数不正确'
- ]);
- }
- $video_report = VideoGoodsReport::findOne(['store_id' => $store_id, 'user_id' => $user_id, 'vl_id' => $vl_id, 'is_delete' => 0, 'status' => 0]);
- if (!$video_report) {
- $report = new VideoGoodsReport();
- $report->store_id = $store_id;
- $report->user_id = $user_id;
- $report->vl_id = $vl_id;
- $report->pic_url = Json::encode($pic_url);
- $report->desc = $desc;
- $report->type = $type;
- if (!$report->save()) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '提交失败'
- ]);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '提交成功'
- ]);
- }
- return $this->asJson([
- 'code' => 1,
- 'msg' => '请勿重复提交举报'
- ]);
- }
- /**
- * 减少此类内容/不看该作者
- */
- public function actionShow()
- {
- try {
- $vl_id = post_params('vl_id', 0);
- $type = post_params('type', 1);
- $video = VideoGoodsList::findOne($vl_id);
- if (empty($video)) {
- throw new \Exception("获取视频信息失败");
- }
- $author = $video->user_id;
- $store_id = $video->store_id;
- $user_id = get_user_id();
- $video = new VideoGoodsReduceShow();
- $video->author = $author;
- $video->vl_id = $vl_id;
- $video->store_id = $store_id;
- $video->user_id = $user_id;
- $video->created_at = time();
- $video->type = $type;
- if (!$video->save()) {
- throw new \Exception($video->errors);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => "保存成功"
- ]);
- } catch (\Exception $e) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage()
- ]);
- }
- }
- /**
- * 作品分享海报
- */
- public function actionQrcode() {
- $form = new ShareQrcodeForm();
- $form->attributes = get_params();
- $form->store_id = get_store_id();
- $form->type = 10;
- $form->user = get_user();
- $form->user_id = get_user_id();
- return $this->asJson($form->search());
- }
- //获取分销订单
- public function actionVideoShareOrder() {
- $user_id = get_user_id();
- $status = get_params('status', -1);
- $query = VideoGoodsShare::find()->alias('vgs')->leftJoin(['o' => Order::tableName()], 'vgs.order_id = o.id')->where(['vgs.author_user_id' => $user_id])->groupBy('order_id')
- ->select('vgs.id, vgs.order_id, SUM(vgs.profit) share_money, vgs.is_send, o.trade_status, o.order_no');
- if ($status == -1) {
- $query->andWhere(['<>', 'o.trade_status', 1]);
- }
- if ($status == 0) {
- $query->andWhere(['o.trade_status' => -1]);
- }
- if ($status == 1) {
- $query->andWhere(['o.trade_status' => [0, 2]]);
- }
- if ($status == 2) {
- $query->andWhere(['o.trade_status' => 3]);
- }
- $list = pagination_make($query);
- foreach ($list['list'] as &$item) {
- $item['orderDetail'] = VideoGoodsShare::find()->alias('vgs')->where(['vgs.order_id' => $item['order_id']])
- ->leftJoin(['od' => OrderDetail::tableName()], 'vgs.order_detail = od.id')
- ->select('od.attr, od.pic cover_pic, od.pic goods_pic, od.id, od.goods_name name, od.total_price, od.num')
- ->asArray()->all();
- $order = Order::findOne($item['order_id']);
- $item['order_no'] = $order->order_no ?? '';
- $item['trade_status'] = (int)$item['trade_status'];
- $item['is_send'] = (int)$item['is_send'];
- $item['status'] = "待付款";
- if ($item['trade_status'] == Order::ORDER_FLOW_DEFAULT) {
- $item['status'] = "待付款";
- } elseif ($item['trade_status'] == Order::ORDER_FLOW_NO_SEND) {
- $item['status'] = "待发货";
- } elseif ($item['trade_status'] == Order::ORDER_FLOW_SEND) {
- $item['status'] = "已发货";
- } elseif ($item['trade_status'] == Order::ORDER_FLOW_CANCEL) {
- $item['status'] = "已取消";
- } elseif ($item['trade_status'] == Order::ORDER_FLOW_CONFIRM) {
- $item['status'] = "已完成";
- }
- $refund = OrderRefund::findOne(['order_id' => $item['order_id'], 'is_delete' => 0, 'type' => 1]);
- if ($refund) {
- if ($refund->status == 1) {
- $item['status'] = "已退款";
- } elseif ($refund->status == 0) {
- $item['status'] = '售后申请中';
- }
- }
- $item['share_status'] = '视频号分佣';
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list['list'],
- 'pageNo' => $list['pageNo'],
- 'totalCount' => $list['totalCount']
- ]
- ]);
- }
- }
|