VideoGoodsController.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\controllers;
  8. use app\jobs\storeSync\DiyCommon;
  9. use app\models\Goods;
  10. use app\models\Option;
  11. use app\models\SaasUser;
  12. use app\models\StoreSyncExtLog;
  13. use app\models\User;
  14. use app\models\VideoGoods;
  15. use app\models\VideoGoodsAuthor;
  16. use app\models\VideoGoodsCat;
  17. use app\models\VideoGoodsFocus;
  18. use app\models\VideoGoodsList;
  19. use app\models\VideoGoodsReport;
  20. use app\models\VideoGoodsSetting;
  21. use app\models\VideoGoodsVote;
  22. use app\modules\admin\models\VideoGoodsForm;
  23. use yii\helpers\Json;
  24. class VideoGoodsController extends BaseController
  25. {
  26. /**
  27. * 分类列表
  28. */
  29. public function actionCatList() {
  30. $name = get_params('name');
  31. $is_show = get_params('is_show', -1);
  32. $query = VideoGoodsCat::find()->where([
  33. 'is_delete' => 0,
  34. 'store_id' => get_store_id()
  35. ]);
  36. if ($is_show != -1) {
  37. $query->andWhere(['is_show' => intval($is_show)]);
  38. }
  39. if (!empty($name)) {
  40. $query->andWhere(['like', 'name', $name]);
  41. }
  42. $query->orderBy(['sort' => SORT_DESC]);
  43. $list = pagination_make($query);
  44. return $this->asJson([
  45. 'code' => 0,
  46. 'msg' => 'success',
  47. 'data' => [
  48. 'data' => $list['list'],
  49. 'pageNo' => $list['pageNo'],
  50. 'totalCount' => $list['totalCount'],
  51. ],
  52. ]);
  53. }
  54. /**
  55. * 分类状态修改
  56. * @return \yii\web\Response
  57. */
  58. public function actionCatStatus()
  59. {
  60. $id = post_params('id');
  61. $type = post_params('type');
  62. $status = post_params('status', 1);
  63. $status = intval($status);
  64. // 1:禁用,2: 删除
  65. if (!in_array($type, [1, 2]) || empty($id)) {
  66. return $this->asJson([
  67. 'code' => 1,
  68. 'msg' => '参数错误'
  69. ]);
  70. }
  71. if (!is_array($id)) {
  72. $cat_id[] = intval($id);
  73. } else {
  74. $cat_id = $id;
  75. }
  76. $t = \Yii::$app->db->beginTransaction();
  77. foreach ($cat_id as $_id) {
  78. $cat = VideoGoodsCat::findOne($_id);
  79. if (!$cat) {
  80. $t->rollBack();
  81. return $this->asJson([
  82. 'code' => 1,
  83. 'msg' => '未找到ID:' . $_id . '记录'
  84. ]);
  85. }
  86. if ($type == 1) {
  87. if ($status == 1) {
  88. VideoGoodsCat::updateAll(['is_show' => 1], ['id' => $cat->id]);
  89. } else {
  90. VideoGoodsCat::updateAll(['is_show' => 0], ['id' => $cat->id]);
  91. }
  92. } else {
  93. VideoGoodsCat::updateAll(['is_delete' => 1], ['id' => $cat->id]);
  94. }
  95. $cat->updated_at = time();
  96. if (!$cat->save()) {
  97. $t->rollBack();
  98. return $this->asJson([
  99. 'code' => 1,
  100. 'msg' => 'ID: ' . $_id . '处理失败'
  101. ]);
  102. }
  103. }
  104. $t->commit();
  105. return $this->asJson([
  106. 'code' => 0,
  107. 'msg' => '处理成功'
  108. ]);
  109. }
  110. /**
  111. * 分类删除
  112. * @return \yii\web\Response
  113. */
  114. public function actionCatDel()
  115. {
  116. $id = post_params('id');
  117. if (empty($id)) {
  118. return $this->asJson([
  119. 'code' => 1,
  120. 'msg' => '缺少参数或参数错误'
  121. ]);
  122. }
  123. if (is_array($id)) {
  124. $count_ids = count($id);
  125. $update_num = VideoGoodsCat::updateAll(['is_delete' => 1], ['in', 'id', $id]);
  126. if ($update_num == $count_ids) {
  127. return $this->asJson([
  128. 'code' => 0,
  129. 'msg' => '删除成功'
  130. ]);
  131. } else {
  132. return $this->asJson([
  133. 'code' => 0,
  134. 'msg' => '有' . ($count_ids - $update_num ) . '条数据未删除成功,请稍后重试'
  135. ]);
  136. }
  137. } else {
  138. $cat = VideoGoodsCat::findOne($id);
  139. $cat->is_delete = 1;
  140. if ($cat->save()) {
  141. return $this->asJson([
  142. 'code' => 0,
  143. 'msg' => '删除成功'
  144. ]);
  145. }
  146. return $this->asJson([
  147. 'code' => 1,
  148. 'msg' => '删除失败',
  149. ]);
  150. }
  151. }
  152. /**
  153. * 分类编辑
  154. * @return \yii\web\Response
  155. */
  156. public function actionCatEdit()
  157. {
  158. $store_id = get_store_id();
  159. $id = post_params('id', 0);
  160. $name = post_params('name');
  161. if (empty($name)) {
  162. return $this->asJson([
  163. 'code' => 1,
  164. 'msg' => '名称不能为空'
  165. ]);
  166. }
  167. $pic_url = post_params('pic_url', '');
  168. $sort = post_params('sort',0);
  169. $is_show = post_params('is_show', 0);
  170. if ($id > 0) {
  171. $cat = VideoGoodsCat::findOne($id);
  172. } else {
  173. $cat = new VideoGoodsCat();
  174. }
  175. $cat->store_id = $store_id;
  176. $cat->name = $name;
  177. $cat->pic_url = $pic_url;
  178. $cat->sort = $sort;
  179. $cat->is_show = $is_show;
  180. if ($cat->save()) {
  181. return $this->asJson([
  182. 'code' => 0,
  183. 'msg' => $id > 0 ? '编辑成功' : '添加成功',
  184. ]);
  185. }
  186. return $this->asJson([
  187. 'code' => 1,
  188. 'msg' => $id > 0 ? '编辑失败' : '添加失败',
  189. ]);
  190. }
  191. /**
  192. * 获取抖品设置
  193. */
  194. public function actionSetting() {
  195. $setting = VideoGoodsSetting::findOne(['store_id' => get_store_id()]);
  196. if (!$setting) {
  197. return $this->asJson([
  198. 'code' => 0,
  199. 'msg' => 'success',
  200. 'data' => [
  201. 'is_video_audit' => 0,
  202. 'is_author_audit' => 0,
  203. 'profit' => 0,
  204. 'verify' => [],
  205. 'video_analyze_345' => Option::get('video_analyze_345', get_store_id(), 'saas')['value'],
  206. 'rewards' => VideoGoodsSetting::REWAEDS_DEFAULT
  207. ]
  208. ]);
  209. }
  210. return $this->asJson([
  211. 'code' => 0,
  212. 'msg' => 'success',
  213. 'data' => [
  214. 'is_video_audit' => $setting->is_video_audit,
  215. 'is_author_audit' => $setting->is_author_audit,
  216. 'profit' => $setting->profit,
  217. 'verify' => json_decode($setting->verify) ?: [],
  218. 'video_analyze_345' => Option::get('video_analyze_345', get_store_id(), 'saas')['value'],
  219. 'rewards' => empty($setting->rewards) ? VideoGoodsSetting::REWAEDS_DEFAULT : json_decode($setting->rewards,true)
  220. ]
  221. ]);
  222. }
  223. /**
  224. * 抖品设置
  225. */
  226. public function actionSetSetting() {
  227. $is_video_audit = post_params('is_video_audit');
  228. $is_author_audit = post_params('is_author_audit');
  229. $verify = post_params("verify");
  230. $rewards = post_params("rewards");
  231. $profit = post_params('profit', 0);
  232. $video_analyze_345 = post_params('video_analyze_345', 0);
  233. Option::set('video_analyze_345', $video_analyze_345, get_store_id(), 'saas');
  234. $setting = VideoGoodsSetting::findOne(['store_id' => get_store_id()]);
  235. if (!$setting) {
  236. $setting = new VideoGoodsSetting();
  237. $setting->store_id = get_store_id();
  238. }
  239. $setting->is_author_audit = intval($is_author_audit);
  240. $setting->is_video_audit = intval($is_video_audit);
  241. $setting->profit = $profit;
  242. $setting->verify = json_encode($verify) ?: "";
  243. $setting->rewards = json_encode($rewards) ?: "";
  244. if ($setting->save()) {
  245. return $this->asJson([
  246. 'code' => 0,
  247. 'msg' => '设置成功'
  248. ]);
  249. }
  250. return $this->asJson([
  251. 'code' => 1,
  252. 'msg' => '设置失败'
  253. ]);
  254. }
  255. /**
  256. * 添加视频商品
  257. */
  258. public function actionAddGoods() {
  259. $goods_id = post_params('goods_id');
  260. if (empty($goods_id)) {
  261. return $this->asJson([
  262. 'code' => 1,
  263. 'msg' => '参数错误'
  264. ]);
  265. }
  266. if (!is_array($goods_id)) {
  267. $goods_ids[] = $goods_id;
  268. } else {
  269. $goods_ids = $goods_id;
  270. }
  271. foreach ($goods_ids as $_id) {
  272. $goods = VideoGoods::findOne(['store_id' => get_store_id(), 'goods_id' => $_id, 'is_delete' => 0]);
  273. if (!$goods) {
  274. $video_goods = new VideoGoods();
  275. $video_goods->goods_id = $_id;
  276. $video_goods->store_id = get_store_id();
  277. $video_goods->is_delete = 0;
  278. $video_goods->status = 0;
  279. $video_goods->save();
  280. }
  281. }
  282. return $this->asJson([
  283. 'code' => 0,
  284. 'msg' => '添加成功'
  285. ]);
  286. }
  287. /**
  288. * 获取商城可选择的商品列表
  289. * @return \yii\web\Response
  290. */
  291. public function actionStoreGoodsList() {
  292. return $this->asJson(Goods::getGoodsList(get_params()));
  293. }
  294. /**
  295. * 视频商品列表
  296. */
  297. public function actionGoodsList() {
  298. $params = get_params();
  299. $video_goods = VideoGoods::find()->where(['store_id' => get_store_id(), 'is_delete' => 0]);
  300. if (isset($params['status']) && $params['status'] != -1) {
  301. $video_goods->andWhere(['status' => $params['status']]);
  302. }
  303. $video_goods = $video_goods->asArray()->all();
  304. if (!empty($video_goods)) {
  305. $params = array_merge($params, ['goods_id' => array_column($video_goods, 'goods_id')]);
  306. } else {
  307. $params = array_merge($params, ['goods_id' => []]);
  308. }
  309. \Yii::error($params);
  310. return $this->asJson(Goods::getGoodsList($params, true));
  311. }
  312. /**
  313. * 商品状态修改
  314. * @return \yii\web\Response
  315. */
  316. public function actionGoodsStatus()
  317. {
  318. $id = post_params('id');
  319. $status = post_params('status');
  320. $store_id = get_store_id();
  321. if (empty($id) || !in_array($status, [0, 1])) {
  322. return $this->asJson([
  323. 'code' => 1,
  324. 'msg' => '缺少参数或参数错误'
  325. ]);
  326. }
  327. if (is_array($id)) {
  328. $count_ids = count($id);
  329. $update_num = VideoGoods::updateAll(['status' => intval($status)], ['in', 'id', $id]);
  330. if ($update_num == $count_ids) {
  331. if (count($id) === 1) {
  332. (new DiyCommon)->JobBehaviors($store_id, StoreSyncExtLog::TYPE_VIDEO_GOODS, $id);
  333. }
  334. return $this->asJson([
  335. 'code' => 0,
  336. 'msg' => '更新成功'
  337. ]);
  338. } else {
  339. return $this->asJson([
  340. 'code' => 0,
  341. 'msg' => '有' . ($count_ids - $update_num ) . '条数据未更新成功,请稍后重试'
  342. ]);
  343. }
  344. } else {
  345. $video_goods = VideoGoods::findOne($id);
  346. $video_goods->status = $status;
  347. if ($video_goods->save()) {
  348. return $this->asJson([
  349. 'code' => 0,
  350. 'msg' => '更新成功'
  351. ]);
  352. }
  353. return $this->asJson([
  354. 'code' => 1,
  355. 'msg' => '修改失败',
  356. ]);
  357. }
  358. }
  359. /**
  360. * 商品删除
  361. * @return \yii\web\Response
  362. */
  363. public function actionGoodsDel()
  364. {
  365. $id = post_params('id');
  366. $store_id = get_store_id();
  367. if (empty($id)) {
  368. return $this->asJson([
  369. 'code' => 1,
  370. 'msg' => '缺少参数或参数错误'
  371. ]);
  372. }
  373. if (is_array($id)) {
  374. $count_ids = count($id);
  375. $update_num = VideoGoods::updateAll(['is_delete' => 1], ['in', 'id', $id]);
  376. if ($update_num == $count_ids) {
  377. if (count($id) === 1) {
  378. (new DiyCommon)->JobBehaviors($store_id, StoreSyncExtLog::TYPE_VIDEO_GOODS, $id);
  379. }
  380. return $this->asJson([
  381. 'code' => 0,
  382. 'msg' => '更新成功'
  383. ]);
  384. } else {
  385. return $this->asJson([
  386. 'code' => 0,
  387. 'msg' => '有' . ($count_ids - $update_num ) . '条数据未更新成功,请稍后重试'
  388. ]);
  389. }
  390. } else {
  391. $video_goods = VideoGoods::findOne($id);
  392. $video_goods->is_delete = 1;
  393. if ($video_goods->save()) {
  394. return $this->asJson([
  395. 'code' => 0,
  396. 'msg' => '更新成功'
  397. ]);
  398. }
  399. return $this->asJson([
  400. 'code' => 1,
  401. 'msg' => '修改失败',
  402. ]);
  403. }
  404. }
  405. /**
  406. * 举报列表
  407. */
  408. public function actionReportList() {
  409. $type = get_params('type', -1);
  410. $status = get_params('status', -1);
  411. $report_id = get_params('report_id', 0);
  412. $title = get_params('title', '');
  413. $name = get_params('name', '');
  414. $query = VideoGoodsReport::find()->alias('vgr')->where(['vgr.store_id' => get_store_id(), 'vgr.is_delete' => 0])
  415. ->leftJoin(['u' => User::tableName()], 'u.id=vgr.user_id')
  416. ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding')
  417. ->leftJoin(['vgl' => VideoGoodsList::tableName()], 'vgl.id=vgr.vl_id')
  418. ->leftJoin(['vu' => User::tableName()], 'vu.id=vgl.user_id')
  419. ->leftJoin(['vsu' => SaasUser::tableName()], 'vsu.mobile=vu.binding');
  420. // 举报类型
  421. if (in_array(intval($type), VideoGoodsReport::$validReportType)) {
  422. $query->andWhere(['vgr.type' => $type]);
  423. }
  424. // 举报视频的标题或内容
  425. if (!empty($title)) {
  426. $query->andWhere(['or', ['like', 'vgl.title', $title], ['like', 'vgl.content', $title]]);
  427. }
  428. // 举报人昵称
  429. if (!empty($name)) {
  430. $query->andWhere(['like', 'su.name', $name]);
  431. }
  432. // 状态
  433. if (in_array(intval($status), [0, 1])) {
  434. $query->andWhere(['vgr.status' => $status]);
  435. }
  436. // 举报id
  437. if (!empty($report_id)) {
  438. $query->andWhere(['vgr.id' => $report_id]);
  439. }
  440. $query->orderBy('vgr.id desc, vgr.status asc')->select(
  441. 'vgr.id report_id, vgr.store_id, vgr.user_id report_user_id, su.name report_user_name, su.avatar report_avatar,
  442. vgr.vl_id, vgr.pic_url report_pic_url, vgr.desc report_desc, vgr.type report_type, vgr.status report_status,
  443. vgl.title vl_title, vgl.cat_id vl_cat_id, vgl.is_delete vl_is_delete, vgl.is_show vl_is_show, vgl.cover_pic vl_cover_pic,
  444. vgl.pic_list vl_pic_list, vgl.video_url vl_video_url, vgl.content vl_content, vgl.type vl_type, vgr.created_at report_created_at,
  445. vgr.updated_at report_updated_at, vsu.name reported_name, vsu.avatar reported_avatar'
  446. );
  447. $list = pagination_make($query);
  448. if (!empty($list['list'])) {
  449. foreach ($list['list'] as $key => $value) {
  450. $list['list'][$key]['cat_name'] = VideoGoodsCat::findOne($value['vl_cat_id'])->name;
  451. $list['list'][$key]['vl_pic_list'] = Json::decode($value['vl_pic_list']);
  452. }
  453. }
  454. return $this->asJson([
  455. 'code' => 0,
  456. 'msg' => 'success',
  457. 'data' => [
  458. 'data' => $list['list'],
  459. 'pageNo' => $list['pageNo'],
  460. 'totalCount' => $list['totalCount'],
  461. ],
  462. ]);
  463. }
  464. /**
  465. * 处理举报
  466. */
  467. public function actionHandleReport() {
  468. $id = post_params('id');
  469. $type = post_params('type');
  470. // 1:下架视频,2: 删除视频
  471. if (!in_array($type, [1, 2]) || empty($id)) {
  472. return $this->asJson([
  473. 'code' => 1,
  474. 'msg' => '参数错误'
  475. ]);
  476. }
  477. if (!is_array($id)) {
  478. $report_id[] = intval($id);
  479. } else {
  480. $report_id = $id;
  481. }
  482. $t = \Yii::$app->db->beginTransaction();
  483. foreach ($report_id as $_id) {
  484. $video_report = VideoGoodsReport::findOne($_id);
  485. if (!$video_report) {
  486. $t->rollBack();
  487. return $this->asJson([
  488. 'code' => 1,
  489. 'msg' => '未找到ID:' . $_id . '记录'
  490. ]);
  491. }
  492. if ($type == 1) {
  493. VideoGoodsList::updateAll(['is_show' => 0], ['id' => $video_report->vl_id]);
  494. } else {
  495. VideoGoodsList::updateAll(['is_delete' => 1], ['id' => $video_report->vl_id]);
  496. }
  497. $video_report->status = 1;
  498. $video_report->updated_at = time();
  499. if (!$video_report->save()) {
  500. $t->rollBack();
  501. return $this->asJson([
  502. 'code' => 1,
  503. 'msg' => 'ID: ' . $_id . '处理失败'
  504. ]);
  505. }
  506. }
  507. $t->commit();
  508. return $this->asJson([
  509. 'code' => 0,
  510. 'msg' => '处理成功'
  511. ]);
  512. }
  513. /**
  514. * 作品列表
  515. */
  516. public function actionList() {
  517. $cat_id = get_params('cat_id', 0);
  518. $type = get_params('type', 0);
  519. $status = get_params('status', -1);
  520. $name = get_params('name', '');
  521. $mobile = get_params('mobile', '');
  522. $id = get_params('id', 0);
  523. $user_id = get_params('user_id', 0);
  524. $query = VideoGoodsList::find()->alias('vgl')->where(['vgl.store_id' => get_store_id(), 'vgl.is_delete' => 0])
  525. ->leftJoin(['u' => User::tableName()], 'u.id=vgl.user_id')
  526. ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding')
  527. ->leftJoin(['vgc' => VideoGoodsCat::tableName()], 'vgc.id=vgl.cat_id');
  528. // 分类
  529. if (!empty($cat_id)) {
  530. $query->andWhere(['vgl.cat_id' => $cat_id]);
  531. }
  532. // 用户id
  533. if (!empty($user_id)) {
  534. $query->andWhere(['vgl.user_id' => $user_id]);
  535. }
  536. // 作品id
  537. if (!empty($id)) {
  538. $query->andWhere(['vgl.id' => $id]);
  539. }
  540. // 1:视频,2:图文
  541. if (!empty($type)) {
  542. $query->andWhere(['vgl.type' => $type]);
  543. }
  544. // 0:待审核。1:已通过,2:已拒绝
  545. if (in_array(intval($status), [0, 1, 2])) {
  546. $query->andWhere(['vgl.status' => $status]);
  547. }
  548. // 昵称
  549. if (!empty($name)) {
  550. $query->andWhere(['like', 'su.name', $name]);
  551. }
  552. // 电话
  553. if (!empty($mobile)) {
  554. $query->andWhere(['like', 'su.mobile', $mobile]);
  555. }
  556. $query->orderBy('vgl.id desc, vgl.status asc')->select(
  557. 'vgl.*, su.name user_name, su.mobile user_mobile, su.avatar user_avatar'
  558. );
  559. $list = pagination_make($query);
  560. if (!empty($list['list'])) {
  561. foreach ($list['list'] as $key => $value) {
  562. $list['list'][$key]['cat_name'] = VideoGoodsCat::findOne($value['cat_id'])->name;
  563. $list['list'][$key]['pic_list'] = Json::decode($value['pic_list']);
  564. }
  565. }
  566. return $this->asJson([
  567. 'code' => 0,
  568. 'msg' => 'success',
  569. 'data' => [
  570. 'data' => $list['list'],
  571. 'pageNo' => $list['pageNo'],
  572. 'totalCount' => $list['totalCount'],
  573. ],
  574. ]);
  575. }
  576. /**
  577. * 审核作品
  578. */
  579. public function actionAudit() {
  580. $id = post_params('id');
  581. $status = post_params('status', 0);
  582. $refuse_desc = post_params('refuse_desc', '');
  583. if (empty($id)) {
  584. return $this->asJson([
  585. 'code' => 1,
  586. 'msg' => '参数不正确'
  587. ]);
  588. }
  589. if (!in_array($status, [1, 2])) {
  590. return $this->asJson([
  591. 'code' => 1,
  592. 'msg' => '参数不正确'
  593. ]);
  594. }
  595. if (is_array($id)) {
  596. $video_id_arr = $id;
  597. } else {
  598. $video_id_arr[] = intval($id);
  599. }
  600. foreach ($video_id_arr as $video_id) {
  601. $video_goods = VideoGoodsList::findOne(['id' => $video_id, 'status' => 0]);
  602. if (!$video_goods) {
  603. return $this->asJson([
  604. 'code' => 1,
  605. 'msg' => '作品不存在或不需要重复处理'
  606. ]);
  607. }
  608. $video_goods->status = $status;
  609. if (!empty($refuse_desc) && $status == 2) {
  610. $video_goods->refuse_desc = $refuse_desc;
  611. }
  612. $video_goods->updated_at = time();
  613. if (!$video_goods->save()) {
  614. return $this->asJson([
  615. 'code' => 1,
  616. 'msg' => $video_goods->errors[0]
  617. ]);
  618. }
  619. }
  620. return $this->asJson([
  621. 'code' => 0,
  622. 'msg' => '审核成功'
  623. ]);
  624. }
  625. /**
  626. * 操作作品状态
  627. * @return \yii\web\Response
  628. */
  629. public function actionHandleVideo() {
  630. $id = post_params('id');
  631. $type = post_params('type');
  632. $status = post_params('status', 1);
  633. $status = intval($status);
  634. // 1:禁用,2: 删除
  635. if (!in_array($type, [1, 2]) || empty($id)) {
  636. return $this->asJson([
  637. 'code' => 1,
  638. 'msg' => '参数错误'
  639. ]);
  640. }
  641. if (!is_array($id)) {
  642. $video_id[] = intval($id);
  643. } else {
  644. $video_id = $id;
  645. }
  646. $t = \Yii::$app->db->beginTransaction();
  647. foreach ($video_id as $_id) {
  648. $video = VideoGoodsList::findOne($_id);
  649. if (!$video) {
  650. $t->rollBack();
  651. return $this->asJson([
  652. 'code' => 1,
  653. 'msg' => '未找到ID:' . $_id . '记录'
  654. ]);
  655. }
  656. if ($type == 1) {
  657. if ($status == 1) {
  658. VideoGoodsList::updateAll(['is_show' => 1], ['id' => $video->id]);
  659. } else {
  660. VideoGoodsList::updateAll(['is_show' => 0], ['id' => $video->id]);
  661. }
  662. } else {
  663. VideoGoodsList::updateAll(['is_delete' => 1], ['id' => $video->id]);
  664. }
  665. $video->updated_at = time();
  666. if (!$video->save()) {
  667. $t->rollBack();
  668. return $this->asJson([
  669. 'code' => 1,
  670. 'msg' => 'ID: ' . $_id . '处理失败'
  671. ]);
  672. }
  673. }
  674. $t->commit();
  675. return $this->asJson([
  676. 'code' => 0,
  677. 'msg' => '处理成功'
  678. ]);
  679. }
  680. /**
  681. * 作者列表
  682. */
  683. public function actionAuthorList() {
  684. $name = get_params('name', '');
  685. $mobile = get_params('mobile', '');
  686. $status = get_params('status', -1);
  687. $query = VideoGoodsAuthor::find()->alias('vga')->where(['vga.store_id' => get_store_id(), 'vga.is_delete' => 0])
  688. ->leftJoin(['u' => User::tableName()], 'u.id=vga.user_id')
  689. ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding');
  690. if (!empty($name)) {
  691. $query->andWhere(['like', 'su.name', $name]);
  692. }
  693. if (!empty($mobile)) {
  694. $query->andWhere(['like', 'su.mobile', $mobile]);
  695. }
  696. if (in_array($status, [0, 1, 2])) {
  697. $query->andWhere(['vga.status' => $status]);
  698. }
  699. $query->orderBy('vga.id desc, vga.status asc')->select(
  700. 'vga.id, vga.user_id, vga.is_delete, vga.is_show, vga.created_at, vga.store_id, vga.status, su.name, su.mobile, su.avatar, vga.card_type, vga.card_front, vga.card_before, vga.name, vga.mobile, vga.desc'
  701. );
  702. $list = pagination_make($query);
  703. if (!empty($list['list'])) {
  704. foreach ($list['list'] as &$value) {
  705. // 获赞数
  706. $value['like_count'] = VideoGoodsVote::find()->where(['store_id' => $value['store_id'], 'is_delete' => 0,
  707. 'is_cancel' => 0, 'type' => 1, 'vl_user_id' => $value['user_id']])->count();
  708. // 收藏数
  709. $value['collect_count'] = VideoGoodsVote::find()->where(['store_id' => $value['store_id'], 'is_delete' => 0,
  710. 'is_cancel' => 0, 'type' => 2, 'vl_user_id' => $value['user_id']])->count();
  711. // 粉丝数
  712. $value['fans_count'] = VideoGoodsFocus::find()->where(['store_id' => $value['store_id'], 'is_delete' => 0,
  713. 'is_cancel' => 0, 'focus_user_id' => $value['user_id']])->count();
  714. // 关注数
  715. $value['focus_count'] = VideoGoodsFocus::find()->where(['store_id' => $value['store_id'], 'is_delete' => 0,
  716. 'is_cancel' => 0, 'user_id' => $value['user_id']])->count();
  717. }
  718. }
  719. return $this->asJson([
  720. 'code' => 0,
  721. 'msg' => 'success',
  722. 'data' => [
  723. 'data' => $list['list'],
  724. 'pageNo' => $list['pageNo'],
  725. 'totalCount' => $list['totalCount'],
  726. ],
  727. ]);
  728. }
  729. /**
  730. * 作者审核
  731. */
  732. public function actionAuditAuthor() {
  733. $id = post_params('id');
  734. $status = post_params('status', 0);
  735. if (empty($id)) {
  736. return $this->asJson([
  737. 'code' => 1,
  738. 'msg' => '参数不正确'
  739. ]);
  740. }
  741. if (!in_array($status, [1, 2])) {
  742. return $this->asJson([
  743. 'code' => 1,
  744. 'msg' => '参数不正确'
  745. ]);
  746. }
  747. if (is_array($id)) {
  748. $author_id_arr = $id;
  749. } else {
  750. $author_id_arr[] = intval($id);
  751. }
  752. foreach ($author_id_arr as $author_id) {
  753. $author = VideoGoodsAuthor::findOne(['id' => $author_id, 'status' => 0]);
  754. if (!$author) {
  755. return $this->asJson([
  756. 'code' => 1,
  757. 'msg' => '作者不存在或不需要重复处理'
  758. ]);
  759. }
  760. $author->status = $status;
  761. $author->updated_at = time();
  762. if (!$author->save()) {
  763. return $this->asJson([
  764. 'code' => 1,
  765. 'msg' => $author->errors[0]
  766. ]);
  767. }
  768. }
  769. return $this->asJson([
  770. 'code' => 0,
  771. 'msg' => '审核成功'
  772. ]);
  773. }
  774. /**
  775. * 操作作者状态
  776. * @return \yii\web\Response
  777. */
  778. public function actionHandleAuthor() {
  779. $id = post_params('id');
  780. $type = post_params('type');
  781. $status = post_params('status', 1);
  782. $status = intval($status);
  783. // 1:禁用,2: 删除
  784. if (!in_array($type, [1, 2]) || empty($id)) {
  785. return $this->asJson([
  786. 'code' => 1,
  787. 'msg' => '参数错误'
  788. ]);
  789. }
  790. if (!is_array($id)) {
  791. $author_id[] = intval($id);
  792. } else {
  793. $author_id = $id;
  794. }
  795. $t = \Yii::$app->db->beginTransaction();
  796. foreach ($author_id as $_id) {
  797. $author = VideoGoodsAuthor::findOne($_id);
  798. if (!$author) {
  799. $t->rollBack();
  800. return $this->asJson([
  801. 'code' => 1,
  802. 'msg' => '未找到ID:' . $_id . '记录'
  803. ]);
  804. }
  805. if ($type == 1) {
  806. if ($status == 1) {
  807. VideoGoodsAuthor::updateAll(['is_show' => 1], ['id' => $author->id]);
  808. } else {
  809. VideoGoodsAuthor::updateAll(['is_show' => 0], ['id' => $author->id]);
  810. }
  811. } else {
  812. VideoGoodsAuthor::updateAll(['is_delete' => 1], ['id' => $author->id]);
  813. // 删除作品
  814. VideoGoodsList::updateAll(['is_delete' => 1], ['store_id' => get_store_id(), 'user_id' => $author->user_id]);
  815. }
  816. $author->updated_at = time();
  817. if (!$author->save()) {
  818. $t->rollBack();
  819. return $this->asJson([
  820. 'code' => 1,
  821. 'msg' => 'ID: ' . $_id . '处理失败'
  822. ]);
  823. }
  824. }
  825. $t->commit();
  826. return $this->asJson([
  827. 'code' => 0,
  828. 'msg' => '处理成功'
  829. ]);
  830. }
  831. /**
  832. * 用户关注或粉丝列表
  833. */
  834. public function actionUserFocusList() {
  835. $user_id = get_params('user_id', 0);
  836. $type = get_params('type', 0);
  837. $name = get_params('name', '');
  838. $mobile = get_params('mobile', '');
  839. $query = VideoGoodsFocus::find()->alias('vgf')->where(['vgf.store_id' => get_store_id(), 'vgf.is_delete' => 0,
  840. 'vgf.is_cancel' => 0, 'vgf.user_id' => $user_id])
  841. ->leftJoin(['u' => User::tableName()], 'u.id=vgf.focus_user_id')
  842. ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding');
  843. // 默认0,关注列表,其他粉丝列表
  844. if (!empty($type)) {
  845. $query->andWhere(['vgf.user_id' => $user_id]);
  846. } else {
  847. // 粉丝列表
  848. $query->andWhere(['vgf.focus_user_id' => $user_id]);
  849. }
  850. if (!empty($name)) {
  851. $query->andWhere(['like', 'su.name', $name]);
  852. }
  853. if (!empty($mobile)) {
  854. $query->andWhere(['like', 'su.mobile', $mobile]);
  855. }
  856. $query->orderBy('vgf.created_at desc')->select(
  857. 'vgf.*, su.name focus_user_name, su.mobile focus_user_mobile, su.avatar focus_user_avatar'
  858. );
  859. $list = pagination_make($query);
  860. return $this->asJson([
  861. 'code' => 0,
  862. 'msg' => 'success',
  863. 'data' => [
  864. 'data' => $list['list'],
  865. 'pageNo' => $list['pageNo'],
  866. 'totalCount' => $list['totalCount'],
  867. ],
  868. ]);
  869. }
  870. /**
  871. * 某个作品或用户的点赞,收藏,转发数据
  872. */
  873. public function actionVoteList() {
  874. $user_id = get_params('user_id', 0);
  875. $vl_id = get_params('vl_id', 0);
  876. $type = get_params('type', -1);
  877. $name = get_params('name', '');
  878. $mobile = get_params('mobile', '');
  879. if (empty($user_id) && empty($vl_id)) {
  880. return $this->asJson([
  881. 'code' => 1,
  882. 'msg' => '参数错误'
  883. ]);
  884. }
  885. $query = VideoGoodsVote::find()->alias('vgv')->where(['vgv.store_id' => get_store_id(), 'vgv.is_delete' => 0,
  886. 'vgv.is_cancel' => 0])
  887. ->leftJoin(['u' => User::tableName()], 'u.id=vgv.user_id')
  888. ->leftJoin(['su' => SaasUser::tableName()], 'su.mobile=u.binding');
  889. if (!empty($user_id)) {
  890. $query->andWhere(['vgv.vl_user_id' => $user_id]);
  891. }
  892. if (!empty($vl_id)) {
  893. $query->andWhere(['vgv.vl_id' => $vl_id]);
  894. }
  895. if (in_array($type, [1, 2, 3])) {
  896. $query->andWhere(['vgv.type' => $type]);
  897. }
  898. if (!empty($name)) {
  899. $query->andWhere(['like', 'su.name', $name]);
  900. }
  901. if (!empty($mobile)) {
  902. $query->andWhere(['like', 'su.mobile', $mobile]);
  903. }
  904. $query->orderBy('vgv.created_at desc')->select(
  905. 'vgv.*, su.name vote_user_name, su.mobile vote_user_mobile, su.avatar vote_user_avatar'
  906. );
  907. $list = pagination_make($query);
  908. return $this->asJson([
  909. 'code' => 0,
  910. 'msg' => 'success',
  911. 'data' => [
  912. 'data' => $list['list'],
  913. 'pageNo' => $list['pageNo'],
  914. 'totalCount' => $list['totalCount'],
  915. ],
  916. ]);
  917. }
  918. public function actionVideoGoodsShareList()
  919. {
  920. $form = new VideoGoodsForm();
  921. $form->attributes = post_params();
  922. $res = $form->videoGoodsShareList();
  923. return $this->asJson($res);
  924. }
  925. }