180 lines
7.4 KiB
PHP
180 lines
7.4 KiB
PHP
<?php
|
||
namespace app\controllers\channel;
|
||
use Illuminate\Support\Facades\DB;
|
||
use app\models\common\Store;
|
||
use app\models\common\WeChat;
|
||
use Yii;
|
||
use EasyWeChat\Factory;
|
||
use app\models\common\Config;
|
||
class LiveController extends CommonController{
|
||
public $enableCsrfValidation = false;
|
||
//获取直播
|
||
public function actionLiveList(){
|
||
$get=axios_request();
|
||
$res=WeChat::getMiniLive($this->wqData['uniacid'],$get['page'],$get['size']);
|
||
for($i=0;$i<count($res);$i++){
|
||
$res[$i]['end_time']=date("Y-m-d",$res[$i]['end_time']);
|
||
$res[$i]['start_time']=date("Y-m-d",$res[$i]['start_time']);
|
||
}
|
||
return $this->result(1,'成功',$res);
|
||
}
|
||
//商品列表
|
||
public function actionGoodsList(){
|
||
$get=axios_request();
|
||
$page=($get['page']-1)?:0;
|
||
$size=$get['size']?:30;
|
||
$status=$get['status'];
|
||
$synchro=$get['synchro']?:0;
|
||
$path='./models/common/live'.$status.'.php';
|
||
// $cache=file_get_contents($path);
|
||
if(!$synchro){
|
||
$data= (new \yii\db\Query())
|
||
->select('*')
|
||
->from('{{%ybwm_live_goods}} ')
|
||
->where(['uniacid'=>$this->wqData['uniacid'],'status'=>$status])
|
||
->offset($page-1)
|
||
->limit($size)
|
||
->all();
|
||
$count=(new \yii\db\Query()) ->from('{{%ybwm_live_goods}}')->where(['uniacid'=>$this->wqData['uniacid'],'status'=>$status])->count();
|
||
return $this->result(1,'成功',$data,$count);
|
||
}
|
||
$config=Config::getSystemSet('miniConfig',$this->wqData['uniacid']);
|
||
if(!$config){
|
||
return $this->result(2,'当前小程序未正确填写相关信息或未开通直播权限!!!');
|
||
}
|
||
$res=WeChat::goodsList($this->wqData['uniacid'],$page,$size,$status);
|
||
$result=json_decode($res,true);
|
||
|
||
if($result['errcode']==0) {
|
||
$total=ceil($result['total']/100);
|
||
for($i=0;$i<$total;$i++) {
|
||
if ($i == 0) {
|
||
$start = 0;
|
||
} else {
|
||
$start = $i * 100 + 1;
|
||
}
|
||
$res = WeChat::goodsList($this->wqData['uniacid'], $start, 100, $status);
|
||
$result = json_decode($res, true);
|
||
if($result['errcode']!=0){
|
||
return $this->result(2,$result['errmsg']);
|
||
}
|
||
$re = YII::$app->db->createCommand()->delete('{{%ybwm_live_goods}}', ['uniacid' => $this->wqData['uniacid'], 'status' => $status])->execute();
|
||
//var_dump($result['goods']);die;
|
||
foreach ($result['goods'] as $value) {
|
||
$data['goodsId'] = $value['goodsId'];
|
||
$data['coverImgUrl'] = $value['coverImgUrl'];
|
||
$data['name'] = $value['name'];
|
||
$data['price'] = $value['price'];
|
||
$data['url'] = $value['url'];
|
||
$data['priceType'] = $value['priceType'];
|
||
$data['price2'] = $value['price2'];
|
||
$data['thirdPartyTag'] = $value['thirdPartyTag'];
|
||
$data['thirdPartyAppid'] = $value['thirdPartyAppid'];
|
||
$data['onShelves'] = $value['onShelves'];
|
||
$data['goodsIdStr'] = $value['goodsIdStr'];
|
||
$data['smallStoreGoodSoure'] = $value['smallStoreGoodSoure'];
|
||
$data['vendorGoodsKey'] = json_encode($value['vendorGoodsKey']);
|
||
$data['status'] = $status;
|
||
$data['uniacid'] = $this->wqData['uniacid'];
|
||
$re = YII::$app->db->createCommand()->insert('{{%ybwm_live_goods}}', $data)->execute();
|
||
}
|
||
}
|
||
$data= (new \yii\db\Query())
|
||
->select('*')
|
||
->from('{{%ybwm_live_goods}} ')
|
||
->where(['uniacid'=>$this->wqData['uniacid'],'status'=>$status])
|
||
->offset($page-1)
|
||
->limit($size)
|
||
->all();
|
||
$count=(new \yii\db\Query()) ->from('{{%ybwm_live_goods}}')->where(['uniacid'=>$this->wqData['uniacid'],'status'=>$status])->count();
|
||
return $this->result(1,'成功',$data,$count);
|
||
|
||
|
||
}else{
|
||
return $this->result(2,$result['errmsg']);
|
||
}
|
||
|
||
}
|
||
//查找平台商品
|
||
public function actionFindGoods(){
|
||
$result=axios_request();
|
||
$info=(new \yii\db\Query())
|
||
->from('{{%ybwm_core_goods}}')
|
||
->select('id,name,icon,crossedPrice,costPrice')
|
||
->where('id=:id',[':id'=>$result['id']])->one();
|
||
return $this->result(1,'成功',$info);
|
||
}
|
||
//获取mediaId
|
||
public function actionGetMediaid(){
|
||
$result=axios_request();
|
||
$res=WeChat::getMediaId($this->wqData['uniacid'],$result['src']);
|
||
$res=json_decode($res,true);
|
||
if($res['errcode']==0){
|
||
return $this->result(1,'成功',$res);
|
||
}else{
|
||
return $this->result(2,$res['errmsg']);
|
||
}
|
||
}
|
||
//添加商品
|
||
public function actionAddGoods(){
|
||
$result=axios_request();
|
||
$type=$result['type']?:'add';
|
||
$data['coverImgUrl']=$result['coverImgUrl']?:'3QHN1pLRCCwAdCaQZxcelFs3tgCrajwRRMTbs6rZThOLIBfSoe-JfCR8SQD11G5r';
|
||
$data['name']=$result['name']?:'测试商品';
|
||
$data['priceType']=$result['priceType']?:2;
|
||
$data['price']=$result['price']?:'1.01';
|
||
$data['price2']=$result['price2']?:'9.09';
|
||
$data['url']=$result['url']?:'yb_cy/shop/goods';
|
||
$res=WeChat::saveGoods($this->wqData['uniacid'],$data,$type);
|
||
$res=json_decode($res,true);
|
||
if($res['errcode']==0){
|
||
return $this->result(1,'成功',$res);
|
||
}else{
|
||
return $this->result(2,$res['errmsg']);
|
||
}
|
||
}
|
||
|
||
//创建直播间
|
||
public function actionCreatedLive(){
|
||
$result=axios_request();
|
||
if(strtotime($result['startTime'])-time()<600 || strtotime($result['startTime'])-time()>15759360){
|
||
return $this->result(2,'开播时间需要在当前时间的10分钟后 并且 开始时间不能在 6 个月后');
|
||
}
|
||
if(strtotime($result['endTime'])-strtotime($result['startTime'])<1800 || strtotime($result['endTime'])-strtotime($result['startTime'])>86400){
|
||
return $this->result(2,'开播时间和结束时间间隔不得短于30分钟,不得超过24小时');
|
||
}
|
||
$res=WeChat::saveMiniLive($this->wqData['uniacid'],$result);
|
||
$res=json_decode($res,true);
|
||
if($res['errcode']==0){
|
||
return $this->result(1,'成功');
|
||
} else{
|
||
return $this->result(2,$res['errmsg']);
|
||
}
|
||
}
|
||
|
||
//删除商品
|
||
public function actionDelGoods(){
|
||
$result=axios_request();
|
||
$res=WeChat::delGoods($this->wqData['uniacid'],$result);
|
||
$res=json_decode($res,true);
|
||
if($res['errcode']==0){
|
||
$re = YII::$app->db->createCommand()->delete('{{%ybwm_live_goods}}', ['goodsId'=>$result['goodsId']])->execute();
|
||
return $this->result(1,'成功');
|
||
} else{
|
||
return $this->result(2,$res['errmsg']);
|
||
}
|
||
}
|
||
|
||
//获取商品详情
|
||
public function actionGoodsDetails(){
|
||
$result=axios_request();
|
||
$res=WeChat::goodsDetails($this->wqData['uniacid'],$result);
|
||
$res=json_decode($res,true);
|
||
if($res['errcode']==0){
|
||
return $this->result(1,'成功');
|
||
} else{
|
||
return $this->result(2,$res['errmsg']);
|
||
}
|
||
}
|
||
|
||
} |