VideoController.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. namespace addons\Store\api\modules\v1\controllers;
  3. use addons\Store\common\enums\StoreEnum;
  4. use addons\Store\common\models\Store;
  5. use addons\Store\common\models\StoreCoupon;
  6. use addons\Store\common\models\StoreCouponGoodsRelate;
  7. use addons\Store\common\models\StoreCouponUserRelate;
  8. use addons\Store\common\models\StoreGoods;
  9. use addons\Store\common\models\StoreVideo;
  10. use addons\Store\common\models\StoreVideoOrder;
  11. use common\models\goods\Goods;
  12. use common\models\order\Order;
  13. use common\models\user\User;
  14. use Yii;
  15. use api\controllers\OnAuthController;
  16. use common\enums\StatusEnum;
  17. use common\models\common\AddonsMarketingSetting;
  18. /**
  19. * 默认控制器
  20. *
  21. * Class DefaultController
  22. * @package addons\Store\api\modules\v1\controllers
  23. */
  24. class VideoController extends OnAuthController
  25. {
  26. public $modelClass = '';
  27. /**
  28. * 不用进行登录验证的方法
  29. *
  30. * 例如: ['index', 'update', 'create', 'view', 'delete']
  31. * 默认全部需要验证
  32. *
  33. * @var array
  34. */
  35. protected $authOptional = ['index'];
  36. /**
  37. * 首页
  38. *
  39. * @return string
  40. */
  41. public function actionIndex()
  42. {
  43. echo 'this is home index page 。。。。';
  44. }
  45. //发布视频
  46. public function actionPostVideo()
  47. {
  48. $params = Yii::$app->request->post();
  49. $params['mall_id'] = $this->mall_id;
  50. $params['user_id'] = $this->user_id;
  51. $params['is_on_sale'] = 1;
  52. if(empty($params['reward_amount'])||$params['reward_amount']<1) return $this->error('奖励金额不得低于1元');
  53. if(empty($params['viewing_times'])||$params['viewing_times']<1) return $this->error('观看次数不能少于1');
  54. if(empty($params['goods_id'])) $params['goods_id'] = 0;
  55. $res = StoreVideo::setData($params);
  56. if ($res == false) return $this->error(StoreVideo::getStaticError());
  57. return $this->success('操作成功', $res);
  58. }
  59. //视频列表
  60. public function actionList()
  61. {
  62. $params = [];
  63. $where = [
  64. ['sv.mall_id' => $this->mall_id],
  65. ['sv.user_id' => $this->user_id],
  66. ['sv.status' => StatusEnum::ENABLED],
  67. ['svo.pay_status' => 1],
  68. ['sv.is_on_sale' => 1],
  69. ];
  70. $join = [
  71. ['LEFT JOIN', StoreVideoOrder::tableName() . 'as svo', 'svo.video_id = sv.id'],
  72. ];
  73. $params['where'] = $where;
  74. $params['order'] = 'id desc';
  75. $params['select'] = 'sv.id,sv.mall_id,sv.store_id,sv.user_id,sv.title,content,sv.video_url,
  76. sv.first_frame,sv.viewing_times,sv.look_complete_num,sv.check_status,sv.check_remark,sv.is_on_sale';
  77. $params['alias'] = 'sv';
  78. $params['join'] = $join;
  79. $list = StoreVideo::listPage($params);
  80. return $this->success('操作成功', $list);
  81. }
  82. //视频详情
  83. public function actionDetail()
  84. {
  85. $params = Yii::$app->request->get();
  86. $where = [
  87. ['id' => $params['id']],
  88. ['mall_id' => $this->mall_id],
  89. ['user_id' => $this->user_id],
  90. ['status' => StatusEnum::ENABLED],
  91. ];
  92. $params['where'] = $where;
  93. $params['order'] = 'id desc';
  94. $detail = StoreVideo::getOne($where);
  95. return $this->success('操作成功', $detail??[]);
  96. }
  97. //视频删除
  98. public function actionDel()
  99. {
  100. $params = Yii::$app->request->post();
  101. $condition = ['id' => $params['id'], 'mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'status' => StatusEnum::ENABLED];
  102. StoreVideo::updateAll(['status' => StatusEnum::DELETE], $condition);
  103. return $this->success('操作成功');
  104. }
  105. //视频观看完
  106. public function actionWatchComplete()
  107. {
  108. if (!\Yii::$app->request->isPost) return $this->error('请求方式错误');
  109. $params = \Yii::$app->request->post();
  110. $params['watch_second'] = $params['watch_second']??0;
  111. if (empty($params['video_id'])) return $this->error('参数错误');
  112. $params['user_id'] = $this->user_id;
  113. $params['mall_id'] = $this->mall_id;
  114. $res = StoreVideo::grantReward($params);
  115. if (false == $res) return $this->error('');
  116. return $this->success('奖励发放成功', []);
  117. }
  118. //观看视频列表
  119. public function actionWatchList()
  120. {
  121. $params = [];
  122. $where = [
  123. ['sv.mall_id' => $this->mall_id],
  124. ['sv.status' => StatusEnum::ENABLED],
  125. ['svo.pay_status' => 1],
  126. ['sv.is_on_sale' => 1],
  127. ];
  128. $join = [
  129. ['LEFT JOIN', StoreVideoOrder::tableName() . 'as svo', 'svo.video_id = sv.id'],
  130. ];
  131. $params['where'] = $where;
  132. $params['order'] = 'id desc';
  133. $params['alias'] = 'sv';
  134. $params['join'] = $join;
  135. $select = 'sv.id,sv.mall_id,sv.store_id,sv.user_id,sv.goods_id,sv.title,sv.content,sv.video_url,
  136. sv.first_frame,sv.viewing_times,sv.duration_seconds,sv.duration_str,sv.look_complete_num';
  137. $params['select'] = $select;
  138. $list = StoreVideo::listPage($params);
  139. if(!empty($list['list'])){
  140. $good_ids = array_column($list['list'], 'goods_id');
  141. $goods = StoreGoods::lists(
  142. [
  143. 'where'=> [
  144. ['mall_id' => $this->mall_id],
  145. ['status' => StatusEnum::ENABLED],
  146. ['id' => $good_ids],
  147. ['is_on_sale' => 1]
  148. ],
  149. 'select'=>'id,goods_name,cover_pic,price,sales_num,detail',
  150. 'index'=>'id'
  151. ]
  152. );
  153. $watch_times = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'basic.watch_times');
  154. foreach ($list['list'] as &$item) {
  155. $item['good_info'] = $goods[$item['goods_id']] ?? [];
  156. $item['watch_times'] = $watch_times??0;
  157. }
  158. }
  159. return $this->success('操作成功', $list);
  160. }
  161. //浏览视频
  162. public function actionVideoBrowse()
  163. {
  164. if (!\Yii::$app->request->isGet) return $this->error('请求方式错误');
  165. $video_id = \Yii::$app->request->get('video_id');
  166. if (empty($video_id)) return $this->error('参数错误');
  167. $params = [
  168. 'id' => $video_id,
  169. 'user_id' => $this->user_id,
  170. ];
  171. $res = StoreVideo::browse($params);
  172. if (false === $res) return $this->error('操作失败');
  173. return $this->success('操作成功');
  174. }
  175. //关联商品接口
  176. public function actionGoodsList()
  177. {
  178. $params = Yii::$app->request->get();
  179. $user_id = $this->user_id;
  180. $store = Store::findOne(['user_id' => $user_id]);
  181. if (empty($store)) return $this->success('', ['list' => []]);
  182. $where[] = ['store_id' => $store['id'], 'mall_id' => $this->mall_id, 'check_status' => 1, 'is_on_sale' => 1, 'status' => StatusEnum::ENABLED];
  183. $params['select'] = 'id,goods_name,cover_pic,price,goods_type';
  184. $params['order'] = 'sort asc';
  185. $params['where'] = $where;
  186. $goods_list = StoreGoods::listPage($params);
  187. return $this->success('操作成功', $goods_list);
  188. }
  189. }