| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- <?php
- namespace addons\Store\api\modules\v1\controllers;
- use addons\Store\common\enums\StoreEnum;
- use addons\Store\common\models\Store;
- use addons\Store\common\models\StoreCoupon;
- use addons\Store\common\models\StoreCouponGoodsRelate;
- use addons\Store\common\models\StoreCouponUserRelate;
- use addons\Store\common\models\StoreGoods;
- use addons\Store\common\models\StoreVideo;
- use addons\Store\common\models\StoreVideoOrder;
- use common\models\goods\Goods;
- use common\models\order\Order;
- use common\models\user\User;
- use Yii;
- use api\controllers\OnAuthController;
- use common\enums\StatusEnum;
- use common\models\common\AddonsMarketingSetting;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\Store\api\modules\v1\controllers
- */
- class VideoController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = ['index'];
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- echo 'this is home index page 。。。。';
- }
- //发布视频
- public function actionPostVideo()
- {
- $params = Yii::$app->request->post();
- $params['mall_id'] = $this->mall_id;
- $params['user_id'] = $this->user_id;
- $params['is_on_sale'] = 1;
- if(empty($params['reward_amount'])||$params['reward_amount']<1) return $this->error('奖励金额不得低于1元');
- if(empty($params['viewing_times'])||$params['viewing_times']<1) return $this->error('观看次数不能少于1');
- if(empty($params['goods_id'])) $params['goods_id'] = 0;
- $res = StoreVideo::setData($params);
- if ($res == false) return $this->error(StoreVideo::getStaticError());
- return $this->success('操作成功', $res);
- }
- //视频列表
- public function actionList()
- {
- $params = [];
- $where = [
- ['sv.mall_id' => $this->mall_id],
- ['sv.user_id' => $this->user_id],
- ['sv.status' => StatusEnum::ENABLED],
- ['svo.pay_status' => 1],
- ['sv.is_on_sale' => 1],
- ];
- $join = [
- ['LEFT JOIN', StoreVideoOrder::tableName() . 'as svo', 'svo.video_id = sv.id'],
- ];
- $params['where'] = $where;
- $params['order'] = 'id desc';
- $params['select'] = 'sv.id,sv.mall_id,sv.store_id,sv.user_id,sv.title,content,sv.video_url,
- sv.first_frame,sv.viewing_times,sv.look_complete_num,sv.check_status,sv.check_remark,sv.is_on_sale';
- $params['alias'] = 'sv';
- $params['join'] = $join;
- $list = StoreVideo::listPage($params);
- return $this->success('操作成功', $list);
- }
- //视频详情
- public function actionDetail()
- {
- $params = Yii::$app->request->get();
- $where = [
- ['id' => $params['id']],
- ['mall_id' => $this->mall_id],
- ['user_id' => $this->user_id],
- ['status' => StatusEnum::ENABLED],
- ];
- $params['where'] = $where;
- $params['order'] = 'id desc';
- $detail = StoreVideo::getOne($where);
- return $this->success('操作成功', $detail??[]);
- }
- //视频删除
- public function actionDel()
- {
- $params = Yii::$app->request->post();
- $condition = ['id' => $params['id'], 'mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'status' => StatusEnum::ENABLED];
- StoreVideo::updateAll(['status' => StatusEnum::DELETE], $condition);
- return $this->success('操作成功');
- }
- //视频观看完
- public function actionWatchComplete()
- {
- if (!\Yii::$app->request->isPost) return $this->error('请求方式错误');
- $params = \Yii::$app->request->post();
- $params['watch_second'] = $params['watch_second']??0;
- if (empty($params['video_id'])) return $this->error('参数错误');
- $params['user_id'] = $this->user_id;
- $params['mall_id'] = $this->mall_id;
- $res = StoreVideo::grantReward($params);
- if (false == $res) return $this->error('');
- return $this->success('奖励发放成功', []);
- }
- //观看视频列表
- public function actionWatchList()
- {
- $params = [];
- $where = [
- ['sv.mall_id' => $this->mall_id],
- ['sv.status' => StatusEnum::ENABLED],
- ['svo.pay_status' => 1],
- ['sv.is_on_sale' => 1],
- ];
- $join = [
- ['LEFT JOIN', StoreVideoOrder::tableName() . 'as svo', 'svo.video_id = sv.id'],
- ];
- $params['where'] = $where;
- $params['order'] = 'id desc';
- $params['alias'] = 'sv';
- $params['join'] = $join;
- $select = 'sv.id,sv.mall_id,sv.store_id,sv.user_id,sv.goods_id,sv.title,sv.content,sv.video_url,
- sv.first_frame,sv.viewing_times,sv.duration_seconds,sv.duration_str,sv.look_complete_num';
- $params['select'] = $select;
- $list = StoreVideo::listPage($params);
- if(!empty($list['list'])){
- $good_ids = array_column($list['list'], 'goods_id');
- $goods = StoreGoods::lists(
- [
- 'where'=> [
- ['mall_id' => $this->mall_id],
- ['status' => StatusEnum::ENABLED],
- ['id' => $good_ids],
- ['is_on_sale' => 1]
- ],
- 'select'=>'id,goods_name,cover_pic,price,sales_num,detail',
- 'index'=>'id'
- ]
- );
- $watch_times = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'basic.watch_times');
- foreach ($list['list'] as &$item) {
- $item['good_info'] = $goods[$item['goods_id']] ?? [];
- $item['watch_times'] = $watch_times??0;
- }
- }
- return $this->success('操作成功', $list);
- }
- //浏览视频
- public function actionVideoBrowse()
- {
- if (!\Yii::$app->request->isGet) return $this->error('请求方式错误');
- $video_id = \Yii::$app->request->get('video_id');
- if (empty($video_id)) return $this->error('参数错误');
- $params = [
- 'id' => $video_id,
- 'user_id' => $this->user_id,
- ];
- $res = StoreVideo::browse($params);
- if (false === $res) return $this->error('操作失败');
- return $this->success('操作成功');
- }
- //关联商品接口
- public function actionGoodsList()
- {
- $params = Yii::$app->request->get();
- $user_id = $this->user_id;
- $store = Store::findOne(['user_id' => $user_id]);
- if (empty($store)) return $this->success('', ['list' => []]);
- $where[] = ['store_id' => $store['id'], 'mall_id' => $this->mall_id, 'check_status' => 1, 'is_on_sale' => 1, 'status' => StatusEnum::ENABLED];
- $params['select'] = 'id,goods_name,cover_pic,price,goods_type';
- $params['order'] = 'sort asc';
- $params['where'] = $where;
- $goods_list = StoreGoods::listPage($params);
- return $this->success('操作成功', $goods_list);
- }
- }
|