VideoGoodsController.php 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\client\controllers\v1;
  8. use app\models\AccountLog;
  9. use app\models\Goods;
  10. use app\models\Option;
  11. use app\models\Order;
  12. use app\models\OrderDetail;
  13. use app\models\OrderRefund;
  14. use app\models\SaasUser;
  15. use app\models\StoreMini;
  16. use app\models\User;
  17. use app\models\VideoGoods;
  18. use app\models\VideoGoodsAuthor;
  19. use app\models\VideoGoodsCat;
  20. use app\models\VideoGoodsComment;
  21. use app\models\VideoGoodsCommentLike;
  22. use app\models\VideoGoodsFocus;
  23. use app\models\VideoGoodsList;
  24. use app\models\VideoGoodsReduceShow;
  25. use app\models\VideoGoodsReport;
  26. use app\models\VideoGoodsSetting;
  27. use app\models\VideoGoodsShare;
  28. use app\models\VideoGoodsVote;
  29. use app\modules\client\controllers\BaseController;
  30. use app\modules\client\models\v1\ShareQrcodeForm;
  31. use app\utils\Tools;
  32. use app\utils\VideoAnalyze;
  33. use EasyWeChat\Factory;
  34. use EasyWeChat\Kernel\BaseClient;
  35. use yii\base\BaseObject;
  36. use yii\data\Pagination;
  37. use yii\helpers\Json;
  38. class VideoGoodsController extends BaseController
  39. {
  40. /**
  41. * 作品列表
  42. */
  43. public function actionList() {
  44. $cat_id = get_params('cat_id', 0);
  45. $page = get_params('page', 1);
  46. $limit = get_params('limit', 20);
  47. $sort_type = get_params('sort_type', 0);
  48. $type = get_params('type', -1);
  49. $vl_id = get_params('vl_id', 0);
  50. $store_id = get_store_id();
  51. $user_id = get_user_id();
  52. $query = VideoGoodsList::find()->alias('vgl')->where(['vgl.store_id' => $store_id, 'vgl.is_delete' => 0, 'vgl.status' => 1, 'vgl.is_show' => 1])
  53. ->leftJoin(['u' => User::tableName()], 'u.id=vgl.user_id')
  54. ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding')
  55. ->leftJoin(['vgc' => VideoGoodsCat::tableName()], 'vgc.id=vgl.cat_id');
  56. // 分类
  57. if (!empty($cat_id)) {
  58. $query->andWhere(['vgl.cat_id' => $cat_id]);
  59. }
  60. if ($sort_type == 1) { // 关注
  61. $query->leftJoin(['vgf' => VideoGoodsFocus::tableName()], 'vgf.focus_user_id=vgl.user_id')
  62. ->andWhere(['vgf.user_id' => $user_id, 'vgf.is_cancel' => 0, 'vgf.is_delete' => 0])
  63. ->orderBy('vgl.created_at desc, vgf.created_at desc');
  64. } else if ($sort_type == 2) { // 最新
  65. $query->orderBy('vgl.created_at desc');
  66. } else { // 默认 推荐排序
  67. $query->orderBy('vgl.sort desc, vgl.created_at desc');
  68. }
  69. if ($type != -1 && in_array($type, [1, 2])) {
  70. $query->andWhere(['vgl.type' => $type]);
  71. }
  72. if (!empty($vl_id)) {
  73. $query->andWhere(['vgl.id' => $vl_id]);
  74. }
  75. $query->andWhere(['vgl.user_delete' => 0]);
  76. $query->andWhere(['is not', 'u.id', null]);
  77. $query->andWhere(['is not', 'su.id', null]);
  78. $count = $query->count();
  79. //减少此类内容/不看该作者视频
  80. $author = VideoGoodsReduceShow::find()->where(['user_id' => $user_id])->select(['author'])->column();
  81. if (!empty($author) && !empty($store_id)) {
  82. $query->andWhere(
  83. [
  84. 'and',
  85. ['not in', 'vgl.user_id', $author]
  86. ]
  87. );
  88. }
  89. $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]);
  90. $list = $query->select('vgl.*, vgc.name cat_name, su.name user_name, su.avatar user_avatar')->limit($pagination->limit)
  91. ->offset($pagination->offset)->asArray()->all();
  92. foreach ($list as &$value) {
  93. // 当前作品是否点赞
  94. $value['is_like'] = VideoGoodsVote::findOne(['store_id' => $value['store_id'], 'type' => 1, 'is_delete' => 0, 'is_cancel' => 0,
  95. 'vl_id' => $value['id'], 'user_id' => $user_id]) ? 1 : 0;
  96. // 作品点赞数
  97. $like_count = VideoGoodsVote::find()->where(['store_id' => $value['store_id'], 'type' => 1, 'is_delete' => 0, 'is_cancel' => 0,
  98. 'vl_id' => $value['id']])->count();
  99. $value['like_count'] = Tools::float_number($like_count);
  100. // 当前作品是否收藏
  101. $value['is_collect'] = VideoGoodsVote::findOne(['store_id' => $value['store_id'], 'type' => 2, 'is_delete' => 0, 'is_cancel' => 0,
  102. 'vl_id' => $value['id'], 'user_id' => $user_id]) ? 1 : 0;
  103. // 收藏数量
  104. $value['collect_count'] = VideoGoodsVote::find()->where(['store_id' => get_store_id(), 'vl_id' => $value['id'], 'is_cancel' => 0, 'is_delete' => 0, 'type' => 2])->count();
  105. // 转发数量
  106. $value['trans_count'] = VideoGoodsVote::find()->where(['store_id' => get_store_id(), 'vl_id' => $value['id'], 'is_cancel' => 0, 'is_delete' => 0, 'type' => 3])->count();
  107. // 评论数量
  108. $value['comment_count'] = VideoGoodsComment::find()->where(['store_id' => get_store_id(), 'vl_id' => $value['id'], 'is_delete' => 0, 'status' => 1])->count();
  109. // 商品
  110. $value['goods_list'] = [];
  111. if ($value['goods_id']) {
  112. $goods_id = Json::decode($value['goods_id']);
  113. $value['goods_list'] = Goods::find()->where(['store_id' => get_store_id(), 'is_delete' => 0, 'status' => 1])->andWhere(['in', 'id', $goods_id])
  114. ->select('id, name, price, use_attr, attr, original_price, cover_pic')->asArray()->all();
  115. if (!empty($value['goods_list'])) {
  116. foreach ($value['goods_list'] as &$g) {
  117. $g['attr_group_list'] = Goods::findOne($g['id'])->getAttrGroupList();
  118. }
  119. }
  120. }
  121. $value['add_time'] = Tools::date_before($value['created_at'], time());
  122. }
  123. return $this->asJson([
  124. 'code' => 0,
  125. 'msg' => 'success',
  126. 'data' => [
  127. 'list' => $list,
  128. 'page_count' => $pagination->pageCount,
  129. 'row_count' => $count,
  130. 'cat_list' => VideoGoodsCat::find()->where(['store_id' => $store_id, 'is_show' => 1, 'is_delete' => 0])
  131. ->orderBy('sort desc')->select('id, name')->asArray()->all()
  132. ]
  133. ]);
  134. }
  135. //视频解析
  136. public function actionVideoAnalyze() {
  137. try {
  138. $url = post_params('url');
  139. $form = new VideoAnalyze();
  140. $form->store_id = get_store_id();
  141. $result = $form->videoAnalyzeCurl($url);
  142. $result = json_decode($result, true);
  143. if ($result['code'] === 200) {
  144. return $this->asJson([
  145. 'code' => 0,
  146. 'msg' => '解析成功',
  147. 'data' => $result['data']
  148. ]);
  149. }
  150. throw new \Exception('解析失败');
  151. //测试数据
  152. // return $this->asJson([
  153. // 'code' => 0,
  154. // 'msg' => '解析成功',
  155. // 'data' => [
  156. // "title" => "大哥每次离开总是装作轻松的样子",
  157. // "image" => "http://tbfile.izuiyou.com/img/frame/id/2234788961?w=540&delogo=0",
  158. // "video" => "http://jsy.izuiyou.com/zyvqwz/264/93/00/664f-fd26-11ed-b1f9-00163e023ce8",
  159. // "url" => "http://jsy.izuiyou.com/zyvqwz/264/93/00/664f-fd26-11ed-b1f9-00163e023ce8",
  160. // "alais" => null
  161. // ]
  162. // ]);
  163. } catch (\Exception $e) {
  164. return $this->asJson([
  165. 'code' => 1,
  166. 'msg' => $e->getMessage()
  167. ]);
  168. }
  169. }
  170. /**
  171. * 1,点赞,2,收藏,3,转发
  172. */
  173. public function actionVote() {
  174. $user_id = get_user_id();
  175. $store_id = get_store_id();
  176. $vl_id = post_params('vl_id', 0);
  177. $type = post_params('type', 0);
  178. if (empty($vl_id) || !in_array($type, [1, 2, 3])) {
  179. return $this->asJson([
  180. 'code' => 1,
  181. 'msg' => '参数错误'
  182. ]);
  183. }
  184. $video = VideoGoodsList::findOne(['store_id' => $store_id, 'status' => 1, 'is_show' => 1, 'is_delete' => 0, 'id' => $vl_id]);
  185. if (!$video) {
  186. return $this->asJson([
  187. 'code' => 1,
  188. 'msg' => '操作的作品不存在'
  189. ]);
  190. }
  191. $video_vote = VideoGoodsVote::findOne(['store_id' => $store_id, 'type' => $type, 'is_delete' => 0,
  192. 'vl_id' => $vl_id, 'user_id' => $user_id]);
  193. if ($video_vote && $type != 3) {
  194. if ($video_vote->is_cancel == 0) {
  195. if (in_array($type, [1, 2])) {
  196. return $this->asJson([
  197. 'code' => 1,
  198. 'msg' => $type == 1 ? '请不要重复点赞哦~' : '请不要重复收藏哦~'
  199. ]);
  200. }
  201. } else {
  202. $video_vote->is_cancel = 0;
  203. $video_vote->updated_at = time();
  204. if (!$video_vote->save()) {
  205. return $this->asJson([
  206. 'code' => 1,
  207. 'msg' => '操作失败'
  208. ]);
  209. }
  210. }
  211. } else {
  212. $video_vote = new VideoGoodsVote();
  213. $video_vote->store_id = $store_id;
  214. $video_vote->user_id = $user_id;
  215. $video_vote->type = $type;
  216. $video_vote->vl_id = $vl_id;
  217. $video_vote->vl_user_id = VideoGoodsList::findOne($vl_id)->user_id;
  218. $video_vote->is_delete = 0;
  219. $video_vote->is_cancel = 0;
  220. $video_vote->created_at = time();
  221. $video_vote->updated_at = time();
  222. if (!$video_vote->save()) {
  223. return $this->asJson([
  224. 'code' => 1,
  225. 'msg' => '操作失败'
  226. ]);
  227. }
  228. }
  229. return $this->asJson([
  230. 'code' => 0,
  231. 'msg' => $type == 1 ? '点赞成功' : ($type == 2 ? '收藏成功' : '转发成功')
  232. ]);
  233. }
  234. /**
  235. * 取消点赞或者收藏
  236. */
  237. public function actionCancelVote() {
  238. $user_id = get_user_id();
  239. $store_id = get_store_id();
  240. $vl_id = post_params('vl_id', 0);
  241. $type = post_params('type', 0);
  242. if (empty($vl_id) || !in_array($type, [1, 2])) {
  243. return $this->asJson([
  244. 'code' => 1,
  245. 'msg' => '参数错误'
  246. ]);
  247. }
  248. $video_vote = VideoGoodsVote::findOne(['store_id' => $store_id, 'type' => $type, 'is_delete' => 0, 'is_cancel' => 0,
  249. 'vl_id' => $vl_id, 'user_id' => $user_id]);
  250. if (!$video_vote) {
  251. return $this->asJson([
  252. 'code' => 1,
  253. 'msg' => '没有记录哦~'
  254. ]);
  255. }
  256. $video_vote->is_cancel = 1;
  257. $video_vote->updated_at = time();
  258. if (!$video_vote->save()) {
  259. return $this->asJson([
  260. 'code' => 1,
  261. 'msg' => '取消失败'
  262. ]);
  263. }
  264. return $this->asJson([
  265. 'code' => 0,
  266. 'msg' => '取消成功'
  267. ]);
  268. }
  269. /**
  270. * 关注用户
  271. */
  272. public function actionFocus() {
  273. $user_id = get_user_id();
  274. $store_id = get_store_id();
  275. $focus_user_id = post_params('focus_user_id');
  276. if (empty($focus_user_id)) {
  277. return $this->asJson([
  278. 'code' => 1,
  279. 'msg' => '被关注人不能为空'
  280. ]);
  281. }
  282. if ($focus_user_id == $user_id) {
  283. return $this->asJson([
  284. 'code' => 1,
  285. 'msg' => '不能关注自己'
  286. ]);
  287. }
  288. $focus = VideoGoodsFocus::findOne(['store_id' => $store_id, 'is_delete' => 0,
  289. 'focus_user_id' => $focus_user_id, 'user_id' => $user_id]);
  290. if ($focus) {
  291. if ($focus->is_cancel == 0) {
  292. return $this->asJson([
  293. 'code' => 1,
  294. 'msg' => '请不要重复关注哦~'
  295. ]);
  296. } else {
  297. $focus->is_cancel = 0;
  298. $focus->updated_at = time();
  299. if (!$focus->save()) {
  300. return $this->asJson([
  301. 'code' => 1,
  302. 'msg' => '关注失败'
  303. ]);
  304. }
  305. }
  306. } else {
  307. $focus = new VideoGoodsFocus();
  308. $focus->store_id = $store_id;
  309. $focus->user_id = $user_id;
  310. $focus->focus_user_id = $focus_user_id;
  311. $focus->is_delete = 0;
  312. $focus->is_cancel = 0;
  313. $focus->created_at = time();
  314. $focus->updated_at = time();
  315. if (!$focus->save()) {
  316. return $this->asJson([
  317. 'code' => 1,
  318. 'msg' => '关注失败'
  319. ]);
  320. }
  321. }
  322. return $this->asJson([
  323. 'code' => 0,
  324. 'msg' => '关注成功'
  325. ]);
  326. }
  327. /**
  328. * 取消关注用户
  329. */
  330. public function actionCancelFocus() {
  331. $user_id = get_user_id();
  332. $store_id = get_store_id();
  333. $focus_user_id = post_params('user_id');
  334. if (empty($focus_user_id)) {
  335. return $this->asJson([
  336. 'code' => 1,
  337. 'msg' => '取消关注人不能为空'
  338. ]);
  339. }
  340. $focus = VideoGoodsFocus::findOne(['store_id' => $store_id, 'is_delete' => 0,
  341. 'focus_user_id' => $focus_user_id, 'user_id' => $user_id, 'is_cancel' => 0]);
  342. if (!$focus) {
  343. return $this->asJson([
  344. 'code' => 1,
  345. 'msg' => '关系不存在'
  346. ]);
  347. }
  348. $focus->is_cancel = 1;
  349. if (!$focus->save()) {
  350. return $this->asJson([
  351. 'code' => 1,
  352. 'msg' => '取消失败'
  353. ]);
  354. }
  355. return $this->asJson([
  356. 'code' => 0,
  357. 'msg' => '取消成功'
  358. ]);
  359. }
  360. /**
  361. * 提交抖品
  362. */
  363. public function actionSubmit(){
  364. $store_id = get_params('store_id') ?: get_store_id();
  365. $user_id = get_user_id();
  366. $saas_user = get_saas_user();
  367. $title = post_params('title', $saas_user->name ?? '');
  368. $cat_id = post_params('cat_id');
  369. $cover_pic = post_params('cover_pic', '');
  370. $pic_list = post_params('pic_list', []);
  371. $video_url = post_params('video_url', '');
  372. $content = post_params('content', '');
  373. $type = post_params('type');
  374. $longitude = post_params('longitude', '');
  375. $latitude = post_params('latitude', '');
  376. $address = post_params('address', '');
  377. $goods_id = post_params('goods_id', []);
  378. $douyin_url = post_params('douyin_url', '');
  379. $is_douyin_video = \post_params('is_douyin_video', 0); // 是否是抖音的视频链接, 如果是,要用消息队列下载到本地或oss
  380. $author = VideoGoodsAuthor::findOne(['store_id' => $store_id, 'user_id' => $user_id, 'is_delete' => 0, 'status' => 1]);
  381. $setting = VideoGoodsSetting::findOne(['store_id' => $store_id]);
  382. //TODO 感觉有问题 start
  383. if (($setting->is_author_audit === 1 && !$author) || ($setting->is_author_audit === 1 && (int)$author->is_show === 0)) {
  384. return $this->asJson([
  385. 'code' => 1,
  386. 'msg' => '非创作者禁止发布'
  387. ]);
  388. } elseif ($setting->is_author_audit === 0 && !$author) {
  389. // 创建作者
  390. $author = new VideoGoodsAuthor();
  391. $author->store_id = get_store_id();
  392. $author->user_id = $user_id;
  393. $author->is_delete = 0;
  394. $author->is_show = 1;
  395. $author->status = 1;
  396. $author->save();
  397. }
  398. //TODO end
  399. if (!in_array($type, [1, 2])) {
  400. return $this->asJson([
  401. 'code' => 1,
  402. 'msg' => '发布类型错误'
  403. ]);
  404. }
  405. if (empty($cat_id)) {
  406. return $this->asJson([
  407. 'code' => 1,
  408. 'msg' => '请选择分类'
  409. ]);
  410. }
  411. // 视频
  412. if ($type == 1) {
  413. if (empty($video_url)) {
  414. return $this->asJson([
  415. 'code' => 1,
  416. 'msg' => '请上传视频'
  417. ]);
  418. }
  419. if (empty($cover_pic)) {
  420. return $this->asJson([
  421. 'code' => 1,
  422. 'msg' => '请上传视频封面'
  423. ]);
  424. }
  425. }
  426. // 图文
  427. if ($type == 2) {
  428. if (empty($title)) {
  429. return $this->asJson([
  430. 'code' => 1,
  431. 'msg' => '请填写标题'
  432. ]);
  433. }
  434. if (empty($pic_list) || !is_array($pic_list)) {
  435. return $this->asJson([
  436. 'code' => 1,
  437. 'msg' => '请正确的上传图片'
  438. ]);
  439. }
  440. }
  441. if (empty($content)) {
  442. return $this->asJson([
  443. 'code' => 1,
  444. 'msg' => '请填写内容'
  445. ]);
  446. }
  447. if (!empty($goods_id) && !is_array($goods_id)) {
  448. return $this->asJson([
  449. 'code' => 1,
  450. 'msg' => '商品数据格式不正确'
  451. ]);
  452. }
  453. $setting = VideoGoodsSetting::findOne(['store_id' => $store_id]);
  454. if ($setting) {
  455. if ($setting->is_video_audit) {
  456. $is_video_audit = true;
  457. } else {
  458. $is_video_audit = false;
  459. }
  460. } else {
  461. // 在未保存过设置项的时候 页面默认是关闭审核 所以这里也要是默认关闭审核
  462. $is_video_audit = false;
  463. }
  464. $video = new VideoGoodsList();
  465. $video->store_id = $store_id;
  466. $video->user_id = $user_id;
  467. $video->title = $title;
  468. $video->cat_id = $cat_id;
  469. $video->address = $address;
  470. $video->cover_pic = $cover_pic;
  471. $video->pic_list = !empty($pic_list) ? Json::encode($pic_list) : Json::encode([]);
  472. $video->video_url = $video_url;
  473. $video->content = $content;
  474. $video->type = $type;
  475. $video->goods_id = !empty($goods_id) ? Json::encode($goods_id) : Json::encode([]);
  476. $video->longitude = $longitude;
  477. $video->latitude = $latitude;
  478. // 判断当前开启是否审核
  479. $video->status = $is_video_audit ? 0 : 1;
  480. $video->douyin_url = $douyin_url;
  481. if (!$video->save()) {
  482. return $this->asJson([
  483. 'code' => 1,
  484. 'msg' => '上传失败'
  485. ]);
  486. }
  487. if ($is_douyin_video) {
  488. queue_push(new \app\jobs\DownloadVideoJob([
  489. 'id' => $video->id,
  490. 'baseUrl' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl,
  491. ]));
  492. }
  493. return $this->asJson([
  494. 'code' => 0,
  495. 'msg' => '上传成功'
  496. ]);
  497. }
  498. /**
  499. * 可选择商品列表
  500. */
  501. public function actionGoodsList() {
  502. $name = get_params('name', '');
  503. $page = get_params('page', 1);
  504. $limit = get_params('limit', 10);
  505. $video_goods = VideoGoods::find()->where(['store_id' => get_store_id(), 'status' => 1, 'is_delete' => 0])->asArray()->all();
  506. if (empty($video_goods)) {
  507. return $this->asJson([
  508. 'code' => 1,
  509. 'msg' => '没有可选择的商品'
  510. ]);
  511. }
  512. $query = Goods::find()->alias('g')
  513. ->where(['g.store_id' => get_store_id(), 'g.is_delete' => 0, 'g.md_food_id' => 0, 'g.status' => 1])
  514. ->andWhere(['not like', 'g.name', '当面付'])->andWhere(['in', 'g.product_type', [0]])
  515. ->andWhere(['in', 'id', array_column($video_goods, 'goods_id')]);
  516. if (!empty($name)) {
  517. $query->andWhere([
  518. 'like',
  519. 'g.name',
  520. $name
  521. ]);
  522. }
  523. $select = ['g.id', 'g.name', 'g.status', 'g.service',
  524. 'g.virtual_sales', 'g.price', 'g.goods_num', 'g.sort' ,'g.cover_pic', 'g.original_price',
  525. 'g.attr', 'g.detail', 'g.use_attr'];
  526. $count = $query->count();
  527. $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]);
  528. $list = $query->offset($pagination->offset)->limit($pagination->limit)
  529. ->select($select)->orderBy(['g.sort' => SORT_DESC, 'g.id' => SORT_DESC])->asArray()->all();
  530. return $this->asJson([
  531. 'code' => 0,
  532. 'msg' => 'success',
  533. 'data' => [
  534. 'list' => $list,
  535. 'page_count' => $pagination->pageCount,
  536. 'row_count' => $count,
  537. ]
  538. ]);
  539. }
  540. /**
  541. * 分类列表
  542. */
  543. public function actionCatList() {
  544. $store_id = get_store_id();
  545. $cat_list = VideoGoodsCat::find()->where(['is_show' => 1, 'is_delete' => 0, 'store_id' => $store_id])->orderBy('sort desc')->asArray()->all();
  546. $arr = [
  547. [
  548. 'id' => 0,
  549. 'name' => '全部'
  550. ]
  551. ];
  552. if (!empty($cat_list)) {
  553. foreach ($cat_list as $v) {
  554. $arr[] = [
  555. 'id' => $v['id'],
  556. 'name' => $v['name']
  557. ];
  558. }
  559. }
  560. return $this->asJson([
  561. 'code' => 0,
  562. 'msg' => 'success',
  563. 'data' => $arr
  564. ]);
  565. }
  566. /**
  567. * 作品详情
  568. */
  569. public function actionDetail() {
  570. $id = get_params('id');
  571. $video = VideoGoodsList::findOne(['store_id' => get_store_id(), 'id' => $id, 'status' => 1, 'is_delete' => 0, 'is_show' => 1, 'user_delete' => 0]);
  572. if (!$video) {
  573. return $this->asJson([
  574. 'code' => 1,
  575. 'msg' => '作品不存在'
  576. ]);
  577. }
  578. $user = User::findOne($video->user_id);
  579. // 点赞数量
  580. $like_count = VideoGoodsVote::find()->where(['store_id' => get_store_id(), 'vl_id' => $id, 'is_cancel' => 0, 'is_delete' => 0, 'type' => 1])->count();
  581. // 收藏数量
  582. $collect_count = VideoGoodsVote::find()->where(['store_id' => get_store_id(), 'vl_id' => $id, 'is_cancel' => 0, 'is_delete' => 0, 'type' => 2])->count();
  583. // 转发数量
  584. $trans_count = VideoGoodsVote::find()->where(['store_id' => get_store_id(), 'vl_id' => $id, 'is_cancel' => 0, 'is_delete' => 0, 'type' => 3])->count();
  585. // 评论数量
  586. $comment_count = VideoGoodsComment::find()->where(['store_id' => get_store_id(), 'vl_id' => $id, 'is_delete' => 0, 'status' => 1])->count();
  587. // 商品
  588. $goods_id = Json::decode($video->goods_id);
  589. $goods_list = Goods::find()->where(['store_id' => get_store_id(), 'is_delete' => 0, 'status' => 1])->andWhere(['in', 'id', $goods_id])
  590. ->select('id, name, price, use_attr, attr, original_price, cover_pic')->asArray()->all();
  591. if (!empty($goods_list)) {
  592. foreach ($goods_list as &$g) {
  593. $g['attr_group_list'] = Goods::findOne($g['id'])->getAttrGroupList();
  594. }
  595. }
  596. $data = [
  597. 'user_id' => $user->id,
  598. 'user_name' => $user->nickname,
  599. 'user_avatar' => $user->avatar_url,
  600. 'video_url' => $video->video_url,
  601. 'pic_list' => $video->pic_list ? Json::decode($video->pic_list) : [],
  602. 'type' => $video->type,
  603. 'title' => $video->title,
  604. 'content' => $video->content,
  605. 'cover_pic' => $video->cover_pic,
  606. 'like_count' => Tools::float_number($like_count),
  607. // 是否点赞
  608. '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,
  609. '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,
  610. 'comment_count' => Tools::float_number($comment_count),
  611. 'collect_count' => Tools::float_number($collect_count),
  612. 'trans_count' => Tools::float_number($trans_count),
  613. 'goods' => [
  614. 'count' => count($goods_list),
  615. 'list' => $goods_list
  616. ],
  617. 'longitude' => $video->longitude,
  618. 'latitude' => $video->latitude,
  619. 'address' => $video->address,
  620. 'add_time' => Tools::date_before($video->created_at, time()),
  621. '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,
  622. 'douyin_url' => $video->douyin_url,
  623. 'rewards' => VideoGoodsSetting::checkUserRewardsIntegral($id),
  624. ];
  625. return $this->asJson([
  626. 'code' => 0,
  627. 'msg' => 'success',
  628. 'data' => $data
  629. ]);
  630. }
  631. public function actionLookVideoSendIntegral(){
  632. $user_id = get_user_id();
  633. $id = get_params('id');
  634. $checkRes = VideoGoodsSetting::checkUserRewardsIntegral($id);
  635. if($checkRes['remaining_number'] <= 0){
  636. return $this->asJson([
  637. 'code' => 1,
  638. 'msg' => '用户无获取积分奖励次数'
  639. ]);
  640. }
  641. $res = AccountLog::saveLog($user_id,$checkRes['integral'],AccountLog::TYPE_INTEGRAL,AccountLog::LOG_TYPE_INCOME,AccountLog::VIDEO_GOODS_REWARDS,$id,'短视频奖励');
  642. if($res){
  643. return $this->asJson([
  644. 'code' => 0,
  645. 'msg' => '积分奖励发放成功',
  646. // 重新计算返回可领取次数等信息
  647. 'data' => VideoGoodsSetting::checkUserRewardsIntegral($id),
  648. ]);
  649. }else{
  650. return $this->asJson([
  651. 'code' => 1,
  652. 'msg' => '积分奖励发放失败'
  653. ]);
  654. }
  655. }
  656. /**
  657. * 用户删除自己作品
  658. */
  659. public function actionUserDelete() {
  660. $user_id = get_user_id();
  661. $id = post_params('id');
  662. $video = VideoGoodsList::findOne(['id' => $id, 'user_delete' => 0, 'is_delete' => 0]);
  663. if (!$video) {
  664. return $this->asJson([
  665. 'code' => 1,
  666. 'msg' => '作品不存在'
  667. ]);
  668. }
  669. if ($video->user_id != $user_id) {
  670. return $this->asJson([
  671. 'code' => 1,
  672. 'msg' => '不能删除他人作品'
  673. ]);
  674. }
  675. $video->user_delete = 1;
  676. if (!$video->save()) {
  677. return $this->asJson([
  678. 'code' => 1,
  679. 'msg' => '删除失败'
  680. ]);
  681. }
  682. return $this->asJson([
  683. 'code' => 0,
  684. 'msg' => '删除成功'
  685. ]);
  686. }
  687. /**
  688. * 抖品个人中心
  689. */
  690. public function actionUserIndex() {
  691. $store_id = get_store_id();
  692. $user_id = get_params('user_id', get_user_id());
  693. if (!$user_id) {
  694. return $this->asJson([
  695. 'code' => 1,
  696. 'msg' => '未找到用户数据'
  697. ]);
  698. }
  699. $author = VideoGoodsAuthor::findOne(['store_id' => $store_id, 'status' => 1, 'is_delete' => 0, 'is_show' => 1, 'user_id' => $user_id]);
  700. $setting = VideoGoodsSetting::findOne(['store_id' => $store_id]);
  701. if ($setting->is_author_audit === 0 && !$author) {
  702. // 创建作者
  703. $author = new VideoGoodsAuthor();
  704. $author->store_id = get_store_id();
  705. $author->is_delete = 0;
  706. $author->is_show = 0;
  707. $author->user_id = $user_id;
  708. $author->status = 0;
  709. if (!$author->save()) {
  710. return $this->asJson([
  711. 'code' => 1,
  712. 'msg' => '未找到作者相关数据'
  713. ]);
  714. };
  715. }
  716. if ($setting->is_author_audit === 1 && !$author) {
  717. return $this->asJson([
  718. 'code' => 1,
  719. 'msg' => '未找到作者相关数据'
  720. ]);
  721. }
  722. // 用户信息
  723. $user = User::findOne($user_id);
  724. $saas_user = SaasUser::findOne(['mobile' => $user->binding]);
  725. // 获得收藏和点赞数量
  726. $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();
  727. // 粉丝数量
  728. $fans_count = VideoGoodsFocus::find()->where(['store_id' => $store_id, 'focus_user_id' => $user_id, 'is_delete' => 0, 'is_cancel' => 0])->count();
  729. // 关注数量
  730. $focus_count = VideoGoodsFocus::find()->where(['store_id' => $store_id, 'user_id' => $user_id, 'is_delete' => 0, 'is_cancel' => 0])->count();
  731. // 是否关注
  732. $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;
  733. $data = [
  734. 'user_info' => [
  735. 'id' => $user->id,
  736. 'name' => $saas_user->name,
  737. 'avatar' => $saas_user->avatar
  738. ],
  739. 'vote_count' => Tools::float_number($vote_count),
  740. 'fans_count' => Tools::float_number($fans_count),
  741. 'focus_count' => Tools::float_number($focus_count),
  742. 'is_focus' => $is_focus,
  743. 'collect_count' => VideoGoodsVote::find()->where(['store_id' => $store_id, 'vl_user_id' => $user_id, 'is_cancel' => 0, 'is_delete' => 0, 'type' => 2])->count(),
  744. 'up_count' => VideoGoodsVote::find()->where(['store_id' => $store_id, 'vl_user_id' => $user_id, 'is_cancel' => 0, 'is_delete' => 0, 'type' => 1])->count()
  745. ];
  746. return $this->asJson([
  747. 'code' => 0,
  748. 'msg' => 'success',
  749. 'data' => $data
  750. ]);
  751. }
  752. /**
  753. * 用户关注的用户列表
  754. */
  755. public function actionFocusList() {
  756. $page = get_params('page', 1);
  757. $limit = get_params('limit', 20);
  758. $store_id = get_store_id();
  759. $user_id = get_params('user_id', get_user_id());
  760. $query = VideoGoodsFocus::find()->alias('vgf')->where(['vgf.store_id' => $store_id, 'vgf.is_delete' => 0, 'vgf.is_cancel' => 0, 'vgf.user_id' => $user_id])
  761. ->leftJoin(['u' => User::tableName()], 'u.id=vgf.focus_user_id')
  762. ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding');
  763. $count = $query->count();
  764. $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]);
  765. $list = $query->select('u.id, su.name, su.avatar')->limit($pagination->limit)
  766. ->offset($pagination->offset)->orderBy('vgf.created_at desc')->asArray()->all();
  767. return $this->asJson([
  768. 'code' => 0,
  769. 'msg' => 'success',
  770. 'data' => [
  771. 'list' => $list,
  772. 'page_count' => $pagination->pageCount,
  773. 'row_count' => $count,
  774. ]
  775. ]);
  776. }
  777. /**
  778. * 用户粉丝列表
  779. */
  780. public function actionFansList() {
  781. $page = get_params('page', 1);
  782. $limit = get_params('limit', 20);
  783. $store_id = get_store_id();
  784. $user_id = get_params('user_id', get_user_id());
  785. $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])
  786. ->leftJoin(['u' => User::tableName()], 'u.id=vgf.user_id')
  787. ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding');
  788. $count = $query->count();
  789. $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]);
  790. $list = $query->select('u.id, su.name, su.avatar')->limit($pagination->limit)
  791. ->offset($pagination->offset)->orderBy('vgf.created_at desc')->asArray()->all();
  792. return $this->asJson([
  793. 'code' => 0,
  794. 'msg' => 'success',
  795. 'data' => [
  796. 'list' => $list,
  797. 'page_count' => $pagination->pageCount,
  798. 'row_count' => $count,
  799. ]
  800. ]);
  801. }
  802. /**
  803. * 用户作品列表
  804. */
  805. public function actionUserVideoList() {
  806. $type = get_params('type', 0);
  807. $choose = get_params('choose', -1);
  808. $page = get_params('page', 1);
  809. $limit = get_params('limit', 20);
  810. $store_id = get_store_id();
  811. $user_id = get_params('user_id', get_user_id());
  812. if ($choose == -1) { // 默认动态
  813. $query = VideoGoodsList::find()->alias('vgl')->where(['vgl.store_id' => $store_id, 'vgl.is_delete' => 0,
  814. 'vgl.status' => 1, 'vgl.is_show' => 1, 'vgl.user_id' => $user_id, 'vgl.user_delete' => 0])
  815. ->leftJoin(['u' => User::tableName()], 'u.id=vgl.user_id')
  816. ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding');
  817. } else { // 点赞作品记录
  818. $query = VideoGoodsVote::find()->alias('vgv')->where(['vgv.store_id' => $store_id, 'vgv.is_delete' => 0,
  819. 'vgv.is_cancel' => 0, 'vgv.type' => 1, 'vgv.user_id' => $user_id, 'vgl.user_delete' => 0])
  820. ->leftJoin(['vgl' => VideoGoodsList::tableName()], 'vgl.id=vgv.vl_id')
  821. ->leftJoin(['u' => User::tableName()], 'u.id=vgv.vl_user_id')
  822. ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding');
  823. }
  824. $query->andWhere(['is not', 'u.id', null]);
  825. $query->andWhere(['is not', 'su.id', null]);
  826. // 视频数量
  827. $video_count_query = clone $query;
  828. $video_count = $video_count_query->andWhere(['vgl.type' => 1])->count();
  829. // 图文数量
  830. $pic_count_query = clone $query;
  831. $pic_count = $pic_count_query->andWhere(['vgl.type' => 2])->count();
  832. // 所有
  833. $all_count_query = clone $query;
  834. $all_count = $all_count_query->count();
  835. // 类型。1:视频,2:图文
  836. if (!empty($type)) {
  837. $query->andWhere(['vgl.type' => $type]);
  838. }
  839. if ($choose == -1) {
  840. $query->orderBy('vgl.is_top desc, vgl.created_at desc');
  841. } else {
  842. $query->orderBy('vgv.created_at desc');
  843. }
  844. $count = $query->count();
  845. $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]);
  846. $list = $query->select('vgl.*, su.name user_name, su.avatar user_avatar')->limit($pagination->limit)
  847. ->offset($pagination->offset)->asArray()->all();
  848. foreach ($list as &$value) {
  849. // 当前作品是否点赞
  850. $value['is_like'] = VideoGoodsVote::findOne(['store_id' => $value['store_id'], 'type' => 1, 'is_delete' => 0, 'is_cancel' => 0,
  851. 'vl_id' => $value['id'], 'user_id' => $user_id]) ? 1 : 0;
  852. // 作品点赞数
  853. $like_count = VideoGoodsVote::find()->where(['store_id' => $value['store_id'], 'type' => 1, 'is_delete' => 0, 'is_cancel' => 0,
  854. 'vl_id' => $value['id']])->count();
  855. $value['like_count'] = Tools::float_number($like_count);
  856. }
  857. return $this->asJson([
  858. 'code' => 0,
  859. 'msg' => 'success',
  860. 'data' => [
  861. 'list' => $list,
  862. 'page_count' => $pagination->pageCount,
  863. 'row_count' => $count,
  864. 'all_count' => $all_count,
  865. 'video_count' => $video_count,
  866. 'pic_count' => $pic_count
  867. ]
  868. ]);
  869. }
  870. /**
  871. * 更换置顶
  872. */
  873. public function actionChangeTop() {
  874. $store_id = get_store_id();
  875. $vl_id = post_params('vl_id', 0);
  876. $user_id = get_user_id();
  877. $video = VideoGoodsList::findOne(['id' => $vl_id, 'user_id' => $user_id, 'store_id' => $store_id]);
  878. if (!$video) {
  879. return $this->asJson([
  880. 'code' => 1,
  881. 'msg' => '需要置顶的数据不存在'
  882. ]);
  883. }
  884. if ($video->user_id != $user_id) {
  885. return $this->asJson([
  886. 'code' => 1,
  887. 'msg' => '系统异常'
  888. ]);
  889. }
  890. if ($video->is_top == 1) {
  891. return $this->asJson([
  892. 'code' => 1,
  893. 'msg' => '请勿重复置顶'
  894. ]);
  895. }
  896. VideoGoodsList::updateAll(['is_top' => 0], ['user_id' => $user_id, 'store_id' => $store_id]);
  897. $video->is_top = 1;
  898. if (!$video->save()) {
  899. return $this->asJson([
  900. 'code' => 1,
  901. 'msg' => '置顶失败'
  902. ]);
  903. }
  904. return $this->asJson([
  905. 'code' => 0,
  906. 'msg' => '置顶成功'
  907. ]);
  908. }
  909. //申请单提交配置信息
  910. public function actionAuditApplyConfig()
  911. {
  912. try {
  913. $store_id = get_params('store_id') ?: get_store_id();
  914. $setting = VideoGoodsSetting::findOne(['store_id' => $store_id]);
  915. $user_id = get_user_id();
  916. $author = VideoGoodsAuthor::findOne(['store_id' => $store_id, 'user_id' => $user_id, 'is_delete' => 0,
  917. 'is_show' => 1, 'status' => [1, 0]]);
  918. if (!$setting) {
  919. return $this->asJson([
  920. 'code' => 0,
  921. 'msg' => 'success',
  922. 'data' => [
  923. 'verify' => []
  924. ]
  925. ]);
  926. }
  927. return $this->asJson([
  928. 'code' => 0,
  929. 'msg' => 'success',
  930. 'data' => [
  931. 'verify' => json_decode($setting->verify) ?: [],
  932. 'is_author_audit' => $setting->is_author_audit,
  933. 'is_author' => $author->status == 1 ? 1 : 0,
  934. 'is_apply' => $author ? 1 : 0
  935. ]
  936. ]);
  937. } catch (\Exception $e) {
  938. return [
  939. 'code' => 1,
  940. 'msg' => "数据错误"
  941. ];
  942. }
  943. }
  944. /**
  945. * 作者权限提交
  946. * @return \yii\web\Response
  947. */
  948. public function actionAuthorApply() {
  949. $user_id = get_user_id();
  950. $store_id = get_store_id();
  951. $author = VideoGoodsAuthor::findOne(['store_id' => $store_id, 'is_delete' => 0, 'user_id' => $user_id]);
  952. $setting = VideoGoodsSetting::findOne(['store_id' => $store_id]);
  953. if ($setting) {
  954. if ($setting->is_author_audit == 1) {
  955. $is_author_audit = true;
  956. } else {
  957. $is_author_audit = false;
  958. }
  959. } else {
  960. $is_author_audit = true;
  961. }
  962. if ($author) {
  963. if ($author->status == 1) {
  964. return $this->asJson([
  965. 'status' => 1,
  966. 'code' => 0,
  967. 'msg' => '作者权限已开通'
  968. ]);
  969. } else if ($author->status == 2 || $author->status == 0) {
  970. if (!$is_author_audit) {
  971. $author->status = 1;
  972. if (!$author->save()) {
  973. return $this->asJson([
  974. 'code' => 1,
  975. 'msg' => '作者权限开通失败'
  976. ]);
  977. }
  978. return $this->asJson([
  979. 'status' => 1,
  980. 'code' => 0,
  981. 'msg' => '作者权限开通成功'
  982. ]);
  983. } else {
  984. if ($author->status == 2) {
  985. $author->status = 0;
  986. if (!$author->save()) {
  987. return $this->asJson([
  988. 'code' => 1,
  989. 'msg' => '作者权限开通申请失败'
  990. ]);
  991. }
  992. }
  993. return $this->asJson([
  994. 'status' => 0,
  995. 'code' => 0,
  996. 'msg' => '已提交,请等待审核'
  997. ]);
  998. }
  999. } else {
  1000. return $this->asJson([
  1001. 'code' => 1,
  1002. 'msg' => '系统异常'
  1003. ]);
  1004. }
  1005. } else {
  1006. $video_author = new VideoGoodsAuthor();
  1007. $video_author->store_id = $store_id;
  1008. $video_author->user_id = $user_id;
  1009. $video_author->is_delete = 0;
  1010. $video_author->is_show = 1;
  1011. $video_author->card_type = post_params("card_type", 0);
  1012. $video_author->name = post_params("name", "");
  1013. $video_author->card_front = post_params("card_front", "");
  1014. $video_author->card_before = post_params("card_before", "");
  1015. $video_author->mobile = post_params("mobile", "");
  1016. $video_author->desc = post_params("desc", "");
  1017. if ($is_author_audit) {
  1018. $video_author->status = 0;
  1019. } else {
  1020. $video_author->status = 1;
  1021. }
  1022. $video_author->created_at = time();
  1023. $video_author->updated_at = time();
  1024. if (!$video_author->save()) {
  1025. return $this->asJson([
  1026. 'code' => 1,
  1027. 'msg' => '提交异常'
  1028. ]);
  1029. }
  1030. return $this->asJson([
  1031. 'status' => $video_author->status,
  1032. 'code' => 0,
  1033. 'msg' => !$is_author_audit ? '开通权限成功' : '申请已提交!'
  1034. ]);
  1035. }
  1036. }
  1037. /**
  1038. * 提交评论
  1039. */
  1040. public function actionSubmitComment() {
  1041. $content = post_params('content');
  1042. $user_id = get_user_id();
  1043. $vl_id = post_params('vl_id');
  1044. $top_parent_id = post_params('top_parent_id', 0);
  1045. $parent_id = post_params('parent_id', 0);
  1046. if (empty($content) || empty($vl_id)) {
  1047. return $this->asJson([
  1048. 'code' => 1,
  1049. 'msg' => '参数错误,请稍后重试'
  1050. ]);
  1051. }
  1052. $video = VideoGoodsList::findOne($vl_id);
  1053. if (!$video) {
  1054. return $this->asJson([
  1055. 'code' => 1,
  1056. 'msg' => '评论的内容不存在'
  1057. ]);
  1058. }
  1059. if ($parent_id) {
  1060. $parent_comment = VideoGoodsComment::findOne(['store_id' => get_store_id(), 'status' => 1, 'is_delete' => 0, 'id' => $parent_id]);
  1061. if (!$parent_comment) {
  1062. return $this->asJson([
  1063. 'code' => 1,
  1064. 'msg' => '回复的评论不存在'
  1065. ]);
  1066. }
  1067. }
  1068. /** @var \EasyWeChat\MiniProgram\Application $wechat */
  1069. // 敏感词校验
  1070. // Todo 此处获取微信配置有误,先不处理这块逻辑
  1071. if ($this->wechat && false) {
  1072. if (is_open_platform()) {
  1073. $wechat = $this->wechat;
  1074. $result = $wechat->content_security->checkText($content);
  1075. } else {
  1076. //微信三方配置信息
  1077. $wx_config = [
  1078. //微信三方appid
  1079. 'app_id' => Option::get("platform_third_appid", 0, 'saas')['value'],
  1080. //微信三方appSecret
  1081. 'secret' => Option::get("platform_third_secret", 0, 'saas')['value'],
  1082. //微信三方平台设置的token
  1083. 'token' => Option::get("platform_token", 0, 'saas')['value'],
  1084. //微信三方平台设置的加密key
  1085. 'aes_key' => Option::get("platform_encodingAesKey", 0, 'saas')['value']
  1086. ];
  1087. $openPlatform = Factory::openPlatform($wx_config);
  1088. //获取小程序信息
  1089. $store_mini = StoreMini::find()->where(['store_id' => get_store_id()])->orderBy('id desc')->one();
  1090. if (empty($store_mini->appid) || empty($store_mini->authorizer_refresh_token)) {
  1091. return [
  1092. 'code' => 1,
  1093. 'msg' => '获取小程序信息失败',
  1094. ];
  1095. }
  1096. //配置easyWechat
  1097. //获取微信配置
  1098. $miniProgram = $openPlatform->miniProgram($store_mini->appid, $store_mini->authorizer_refresh_token);
  1099. //使用自定义接口
  1100. $client = new BaseClient($miniProgram);
  1101. //请求自定义接口
  1102. $res = $client->httpPostJson('wxa/msg_sec_check');
  1103. }
  1104. if ($result['errcode'] != 0) {
  1105. return $this->asJson([
  1106. 'code' => 1,
  1107. 'msg' => '发布的内容不符合要求'
  1108. ]);
  1109. }
  1110. }
  1111. $comment = new VideoGoodsComment();
  1112. $comment->comment = $content;
  1113. $comment->reply_id = 0;
  1114. $comment->reply_name = '';
  1115. $comment->user_id = $user_id;
  1116. $comment->created_at = time();
  1117. $comment->vl_id = $vl_id;
  1118. $comment->store_id = get_store_id();
  1119. $comment->parent_id = $parent_id;
  1120. $comment->top_parent_id = $top_parent_id;
  1121. if ($comment->save()) {
  1122. return $this->asJson([
  1123. 'code' => 0,
  1124. 'msg' => '评论成功'
  1125. ]);
  1126. }
  1127. return $this->asJson([
  1128. 'code' => 1,
  1129. 'msg' => '提交失败',
  1130. ]);
  1131. }
  1132. /**
  1133. * 作品评论列表
  1134. */
  1135. public function actionCommentList() {
  1136. $page = get_params('page', 1);
  1137. $limit = get_params('limit', 10);
  1138. $vl_id = get_params('vl_id', 0);
  1139. $user_id = get_user_id();
  1140. $comment_list = VideoGoodsComment::find()->alias('vgc')->leftJoin(['u' => User::tableName()],'vgc.user_id=u.id')
  1141. ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding')
  1142. ->where(['vgc.store_id' => get_store_id(), 'vgc.vl_id' => $vl_id, 'vgc.is_delete' => 0, 'vgc.top_parent_id' => 0, 'vgc.status' => 1])
  1143. ->select('vgc.user_id, su.name, su.avatar, vgc.id, vgc.comment, vgc.created_at');
  1144. $count = $comment_list->count();
  1145. $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $limit, 'page' => $page - 1]);
  1146. $comment_list = $comment_list->offset($pagination->offset)->limit($pagination->limit)
  1147. ->orderBy('vgc.created_at DESC')
  1148. ->asArray()->all();
  1149. $now_time = time();
  1150. $author_user_id = VideoGoodsList::findOne($vl_id)->user_id;
  1151. foreach ($comment_list as &$item){
  1152. $item['time'] = Tools::getTime($item['created_at'], $now_time);
  1153. $item['is_like'] = VideoGoodsCommentLike::findOne(['user_id' => $user_id, 'comment_id' => $item['id'], 'is_cancel' => 0]) ? 1 : 0;
  1154. $item['like_count'] = VideoGoodsCommentLike::find()->where(['comment_id' => $item['id'], 'is_cancel' => 0])->count();
  1155. $reply_list = VideoGoodsComment::find()->alias('vgc')
  1156. ->leftJoin(['u' => User::tableName()],'vgc.user_id=u.id')
  1157. ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding')
  1158. ->where(['vgc.vl_id' => $vl_id, 'vgc.is_delete' => 0, 'vgc.top_parent_id' => $item['id'], 'vgc.status' => 1])
  1159. ->select('vgc.user_id, su.name, su.avatar, vgc.id, vgc.comment, vgc.created_at, vgc.parent_id')
  1160. ->orderBy('vgc.created_at desc')->asArray()->all();
  1161. foreach($reply_list as &$reply) {
  1162. // 被回复人信息
  1163. $reply_info = VideoGoodsComment::findOne($reply['parent_id']);
  1164. $saas_user = SaasUser::findOne(['mobile' => User::findOne($reply_info->user_id)->binding]);
  1165. $reply['reply_user'] = $saas_user->name;
  1166. $reply['reply_user_id'] = $reply_info->user_id;
  1167. $reply['reply_user_avatar'] = $saas_user->avatar;
  1168. $reply['time'] = Tools::getTime($reply['created_at'], $now_time);
  1169. $reply['is_like'] = VideoGoodsCommentLike::findOne(['user_id' => $user_id, 'comment_id' => $reply['id'], 'is_cancel' => 0]) ? 1 : 0;
  1170. $reply['like_count'] = VideoGoodsCommentLike::find()->where(['comment_id' => $reply['id'], 'is_cancel' => 0])->count();
  1171. }
  1172. $item['reply_list'] = $reply_list;
  1173. }
  1174. return $this->asJson([
  1175. 'code' => 0,
  1176. 'msg' => 'success',
  1177. 'data' => [
  1178. 'list' => $comment_list,
  1179. 'page_count' => $pagination->pageCount,
  1180. 'row_count' => $count,
  1181. 'user_id' => $author_user_id
  1182. ]
  1183. ]);
  1184. }
  1185. /**
  1186. * 评论点赞
  1187. */
  1188. public function actionCommentLike() {
  1189. $id = post_params('id');
  1190. if (empty($id)) {
  1191. return $this->asJson([
  1192. 'code' => 1,
  1193. 'msg' => '缺少必要参数'
  1194. ]);
  1195. }
  1196. $store_id = get_store_id();
  1197. $user_id = get_user_id();
  1198. $comment_like = VideoGoodsCommentLike::findOne(['store_id' => $store_id, 'comment_id' => $id, 'user_id' => $user_id, 'is_cancel' => 0]);
  1199. if($comment_like) {
  1200. $comment_like->is_cancel = $comment_like->is_cancel ? 0 : 1;
  1201. $comment_like->updated_at = time();
  1202. } else {
  1203. $comment_like = new VideoGoodsCommentLike();
  1204. $comment_like->is_cancel = 0;
  1205. $comment_like->updated_at = time();
  1206. $comment_like->store_id = $store_id;
  1207. $comment_like->comment_id = $id;
  1208. $comment_like->user_id = $user_id;
  1209. $comment_like->created_at = time();
  1210. }
  1211. if (!$comment_like->save()) {
  1212. return $this->asJson([
  1213. 'code' => 1,
  1214. 'msg' => '点赞失败'
  1215. ]);
  1216. }
  1217. return $this->asJson([
  1218. 'code' => 0,
  1219. 'msg' => '点赞成功'
  1220. ]);
  1221. }
  1222. /**
  1223. * 举报抖品
  1224. */
  1225. public function actionReport() {
  1226. $user_id = get_user_id();
  1227. $store_id = get_store_id();
  1228. $vl_id = post_params('vl_id', 0);
  1229. $video = VideoGoodsList::findOne($vl_id);
  1230. if (!$video) {
  1231. return $this->asJson([
  1232. 'code' => 1,
  1233. 'msg' => '举报内容不存在'
  1234. ]);
  1235. }
  1236. if ($video->is_delete == 1) {
  1237. return $this->asJson([
  1238. 'code' => 1,
  1239. 'msg' => '举报内容已删除'
  1240. ]);
  1241. }
  1242. if ($video->is_show == 0) {
  1243. return $this->asJson([
  1244. 'code' => 1,
  1245. 'msg' => '举报内容已隐藏'
  1246. ]);
  1247. }
  1248. $pic_url = post_params('pic_url', []);
  1249. $desc = post_params('desc', '');
  1250. $type = post_params('type', 0);
  1251. if (empty($desc) || !in_array($type, array_keys(VideoGoodsReport::$validReportType))) {
  1252. return $this->asJson([
  1253. 'code' => 1,
  1254. 'msg' => '参数不正确'
  1255. ]);
  1256. }
  1257. $video_report = VideoGoodsReport::findOne(['store_id' => $store_id, 'user_id' => $user_id, 'vl_id' => $vl_id, 'is_delete' => 0, 'status' => 0]);
  1258. if (!$video_report) {
  1259. $report = new VideoGoodsReport();
  1260. $report->store_id = $store_id;
  1261. $report->user_id = $user_id;
  1262. $report->vl_id = $vl_id;
  1263. $report->pic_url = Json::encode($pic_url);
  1264. $report->desc = $desc;
  1265. $report->type = $type;
  1266. if (!$report->save()) {
  1267. return $this->asJson([
  1268. 'code' => 1,
  1269. 'msg' => '提交失败'
  1270. ]);
  1271. }
  1272. return $this->asJson([
  1273. 'code' => 0,
  1274. 'msg' => '提交成功'
  1275. ]);
  1276. }
  1277. return $this->asJson([
  1278. 'code' => 1,
  1279. 'msg' => '请勿重复提交举报'
  1280. ]);
  1281. }
  1282. /**
  1283. * 减少此类内容/不看该作者
  1284. */
  1285. public function actionShow()
  1286. {
  1287. try {
  1288. $vl_id = post_params('vl_id', 0);
  1289. $type = post_params('type', 1);
  1290. $video = VideoGoodsList::findOne($vl_id);
  1291. if (empty($video)) {
  1292. throw new \Exception("获取视频信息失败");
  1293. }
  1294. $author = $video->user_id;
  1295. $store_id = $video->store_id;
  1296. $user_id = get_user_id();
  1297. $video = new VideoGoodsReduceShow();
  1298. $video->author = $author;
  1299. $video->vl_id = $vl_id;
  1300. $video->store_id = $store_id;
  1301. $video->user_id = $user_id;
  1302. $video->created_at = time();
  1303. $video->type = $type;
  1304. if (!$video->save()) {
  1305. throw new \Exception($video->errors);
  1306. }
  1307. return $this->asJson([
  1308. 'code' => 0,
  1309. 'msg' => "保存成功"
  1310. ]);
  1311. } catch (\Exception $e) {
  1312. return $this->asJson([
  1313. 'code' => 1,
  1314. 'msg' => $e->getMessage()
  1315. ]);
  1316. }
  1317. }
  1318. /**
  1319. * 作品分享海报
  1320. */
  1321. public function actionQrcode() {
  1322. $form = new ShareQrcodeForm();
  1323. $form->attributes = get_params();
  1324. $form->store_id = get_store_id();
  1325. $form->type = 10;
  1326. $form->user = get_user();
  1327. $form->user_id = get_user_id();
  1328. return $this->asJson($form->search());
  1329. }
  1330. //获取分销订单
  1331. public function actionVideoShareOrder() {
  1332. $user_id = get_user_id();
  1333. $status = get_params('status', -1);
  1334. $query = VideoGoodsShare::find()->alias('vgs')->leftJoin(['o' => Order::tableName()], 'vgs.order_id = o.id')->where(['vgs.author_user_id' => $user_id])->groupBy('order_id')
  1335. ->select('vgs.id, vgs.order_id, SUM(vgs.profit) share_money, vgs.is_send, o.trade_status, o.order_no');
  1336. if ($status == -1) {
  1337. $query->andWhere(['<>', 'o.trade_status', 1]);
  1338. }
  1339. if ($status == 0) {
  1340. $query->andWhere(['o.trade_status' => -1]);
  1341. }
  1342. if ($status == 1) {
  1343. $query->andWhere(['o.trade_status' => [0, 2]]);
  1344. }
  1345. if ($status == 2) {
  1346. $query->andWhere(['o.trade_status' => 3]);
  1347. }
  1348. $list = pagination_make($query);
  1349. foreach ($list['list'] as &$item) {
  1350. $item['orderDetail'] = VideoGoodsShare::find()->alias('vgs')->where(['vgs.order_id' => $item['order_id']])
  1351. ->leftJoin(['od' => OrderDetail::tableName()], 'vgs.order_detail = od.id')
  1352. ->select('od.attr, od.pic cover_pic, od.pic goods_pic, od.id, od.goods_name name, od.total_price, od.num')
  1353. ->asArray()->all();
  1354. $order = Order::findOne($item['order_id']);
  1355. $item['order_no'] = $order->order_no ?? '';
  1356. $item['trade_status'] = (int)$item['trade_status'];
  1357. $item['is_send'] = (int)$item['is_send'];
  1358. $item['status'] = "待付款";
  1359. if ($item['trade_status'] == Order::ORDER_FLOW_DEFAULT) {
  1360. $item['status'] = "待付款";
  1361. } elseif ($item['trade_status'] == Order::ORDER_FLOW_NO_SEND) {
  1362. $item['status'] = "待发货";
  1363. } elseif ($item['trade_status'] == Order::ORDER_FLOW_SEND) {
  1364. $item['status'] = "已发货";
  1365. } elseif ($item['trade_status'] == Order::ORDER_FLOW_CANCEL) {
  1366. $item['status'] = "已取消";
  1367. } elseif ($item['trade_status'] == Order::ORDER_FLOW_CONFIRM) {
  1368. $item['status'] = "已完成";
  1369. }
  1370. $refund = OrderRefund::findOne(['order_id' => $item['order_id'], 'is_delete' => 0, 'type' => 1]);
  1371. if ($refund) {
  1372. if ($refund->status == 1) {
  1373. $item['status'] = "已退款";
  1374. } elseif ($refund->status == 0) {
  1375. $item['status'] = '售后申请中';
  1376. }
  1377. }
  1378. $item['share_status'] = '视频号分佣';
  1379. }
  1380. return $this->asJson([
  1381. 'code' => 0,
  1382. 'msg' => 'success',
  1383. 'data' => [
  1384. 'data' => $list['list'],
  1385. 'pageNo' => $list['pageNo'],
  1386. 'totalCount' => $list['totalCount']
  1387. ]
  1388. ]);
  1389. }
  1390. }