| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\plugins\wxlive\models\live;
- use app\plugins\wxlive\models\Wechat;
- use app\utils\CurlHelper;
- use yii\base\Model;
- class LiveDetailForm extends Model
- {
- public $store_id;
- public $page;
- public $roomid;
- public $file;
- public $data;
- public $goods_id;
- public $roomId;
- public $limit = 10;
- /**
- * 获取直播间列表
- * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
- * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function getLiveList()
- {
- $start = ($this->page - 1) * $this->limit;
- $wechat = Wechat::getWechat();
- if (!is_array($wechat) || !isset($wechat['code'])) {
- return $wechat->broadcast->getRooms($start, $this->limit);
- } else {
- return [
- 'errcode' => 1
- ];
- }
- }
- public function deleteRoom()
- {
- $wechat = Wechat::getWechat();
- return $wechat->broadcast->deleteLiveRoom([
- 'id' => $this->roomId,
- ]);
- }
- public function getHuifang()
- {
- $wechat = Wechat::getWechat();
- return $wechat->broadcast->getPlaybacks($this->roomid, 0, 10);
- }
- public function getMedia()
- {
- $file = $this->file;
- $root_url = $this->saveTempImage($file);
- $wechat = Wechat::getWechat();
- return $wechat->media->upload('image', $root_url);
- }
- public function submitLive()
- {
- set_time_limit(0);
- $wechat = Wechat::getWechat();
- $coverImg = trim($this->data['coverImg']);
- $coverImgPath = $this->saveTempImage($coverImg);
- $coverImgMedia = $wechat->media->upload('image', $coverImgPath);
- if (isset($coverImgMedia['errcode'])) {
- return $coverImgMedia;
- }
- $shareImg = trim($this->data['shareImg']);
- $shareImgPath = $this->saveTempImage($shareImg);
- $shareImgMedia = $wechat->media->upload('image', $shareImgPath);
- if (isset($shareImgMedia['errcode'])) {
- return $shareImgMedia;
- }
- $feedsImg = trim($this->data['feedsImg']);
- $feedsImgPath = $this->saveTempImage($feedsImg);
- $feedsImgMedia = $wechat->media->upload('image', $feedsImgPath);
- if (isset($feedsImgMedia['errcode'])) {
- return $feedsImgMedia;
- }
- $postData = [
- 'type' => 1,
- 'name' => trim($this->data['name']),
- 'coverImg' => $coverImgMedia['media_id'],
- 'shareImg' => $shareImgMedia['media_id'],
- 'feedsImg' => $feedsImgMedia['media_id'],
- 'startTime' => strtotime(trim($this->data['startTime'])),
- 'endTime' => strtotime(trim($this->data['endTime'])),
- 'anchorName' => trim($this->data['anchorName']),
- 'anchorWechat' => trim($this->data['anchorWechat']),
- 'closeComment' =>intval( $this->data['closeComment']),
- 'closeLike' => intval($this->data['closeLike']),
- 'closeGoods' => intval($this->data['closeGoods']),
- 'closeReplay' => intval($this->data['closeReplay']),
- 'closeShare' => intval($this->data['closeShare']),
- 'closeKf' => intval($this->data['closeKf']),
- ];
- $wechat = Wechat::getWechat();
- return $wechat->broadcast->createLiveRoom($postData);
- }
- public function addGoods()
- {
- if (empty($this->goods_id)) {
- return [
- 'code' => 1,
- 'msg' => '请选择商品'
- ];
- }
- $goods_id = $this->goods_id;
- $postData = [
- 'ids' => $goods_id,
- 'roomId' => trim($this->roomId)
- ];
- $wechat = Wechat::getWechat();
- return $wechat->broadcast->addGoods($postData);
- }
- //获取网络图片到临时目录
- private function saveTempImage($url)
- {
- if (strpos($url,'http') === false) {
- $url = 'http:'. trim($url);
- }
- if (!is_dir(\Yii::$app->runtimePath . '/image')) {
- mkdir(\Yii::$app->runtimePath . '/image');
- }
- $save_path = \Yii::$app->runtimePath . '/image/' . md5($url) . '.jpg';
- CurlHelper::download($url, $save_path);
- return $save_path;
- }
- /**
- * 获取已经审核通过的商品列表
- * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
- * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function getGoodsList()
- {
- $wechat = Wechat::getWechat();
- $start = ($this->page - 1) * $this->limit;
- return $wechat->broadcast->getApproved([
- 'offset' => $start,
- 'limit' => $this->limit,
- 'status' => 2
- ]);
- }
- }
|