文件
mashangyoujiu/Application/Blessing/Controller/AppletsController.class.php

327 行
11 KiB
PHP
可执行文件

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
/**
* Created by PhpStorm.
* User: yang
* Date: 2021/3/23
* Time: 17:58
*/
namespace Blessing\Controller;
use SmallProgramApi\Controller\BaseController;
use Blessing\Business\Index;
use Blessing\Model\BlessingModel;
use Common\Model\StoreConfigModel;
use Common\Model\ImageGalleryModel;
use Common\Validate\CustomValidate;
use Common\Model\RetailBillOrderModel;//商品出售订单表
//小程序
class AppletsController extends BaseController{
/**
* 上传音视频:MP3,MP4
*/
public function uploadBlessing(){
$index = new Index();
$identification = 'blessing';
$limitSize = $index->plugSetInfo($identification);
if($limitSize){
$post['limit_size'] = $limitSize['space'];//文件大小
}
$post['catalog'] = 'plug/blessing';//文件子目录
$data = $index->videoUpload($post);
$this->ajaxReturn($data);
}
/**
* 修改删除
* 删除音视频:MP3,MP4
*/
public function deleteBlessing(){
$post = I("post.");
$param = [
'storage_type',//存储类型:1本地,2七牛云,3腾讯云,4阿里云
'url',//地址
];
$index = new Index();
$customValidate = new CustomValidate();
$dataOne = $customValidate->validationParameters($param,$post);
if($dataOne !== true){
$this->ajaxReturn($dataOne);
}
if($post['storage_type'] == ''|| $post['url'] == ''){
$res = callBack(statusCode()['error'],'参数不能为空');
$this->ajaxReturn($res);
}
$index = new Index();
$data = $index->videoDelete($post['url'],$post['storage_type']);
$this->ajaxReturn($data);
}
/**
* 祝福语
*/
//添加祝福语
public function addBlessing(){
$post = I("post.");
$param = [
'orderId',//订单id
'type',//类型:1视频,2音频
'url',//路径地址:Uploads/plug/blessing/2021-03-30/606300c886fa12205.mp4
'storageType',//存储类型:1本地,2七牛云,3腾讯云,4阿里云
'address',//http://qny.zaiyuliya.com/plug/blessing/16171579126063df1852bf1.mp4
];
$index = new Index();
$customValidate = new CustomValidate();
$dataOne = $customValidate->validationParameters($param,$post);
if($dataOne !== true){
$this->ajaxReturn($dataOne);
}
if($post['orderId'] == '' || $post['type'] == '' || $post['url'] == '' || $post['storageType'] == '' || $post['address'] == ''){
$res = callBack(statusCode()['error'],'参数不能为空');
$this->ajaxReturn($res);
}
$storeId = self::$store_id;
//添加祝福语,判断门店是否有权限
$storePlug['store_id'] = $storeId;
$storePlug['identification'] = 'blessing';
//门店id
$merchantIdBlessingPlug = $index->storeBlessingPlug($storePlug);
if($merchantIdBlessingPlug['status'] != 1){
//无权限
$this->ajaxReturn($merchantIdBlessingPlug);
}
//生成提取码
$extractionCode = $index->extractionCode($storeId);
$add = [
'merchant_id'=>self::$merchant_id,
'store_id'=>$storeId,
'order_id'=>$post['orderId'],
'user_id'=>self::$uid,
'type'=>$post['type'],
'extraction_code'=>$extractionCode,
'url'=>$post['url'],
'storage_type'=>$post['storageType'],
'address'=>$post['address'],
'create_time'=>time(),
];
$plugBlessingModel = new BlessingModel();
$data = $plugBlessingModel->addOrder($add);
if($data === false){
$res = callBack(statusCode()['error'],'失败');
}else{
$res = callBack(statusCode()['success'],'成功',$extractionCode);
}
$this->ajaxReturn($res);
}
//修改祝福语
public function blessingSave(){
$post = I("post.");
$param = [
'orderId',//订单id
'type',//类型:1视频,2音频
'url',//路径地址
'storageType',//存储类型:1本地,2七牛云,3腾讯云,4阿里云
'address',//http://qny.zaiyuliya.com/plug/blessing/16171579126063df1852bf1.mp4
];
$index = new Index();
$customValidate = new CustomValidate();
$dataOne = $customValidate->validationParameters($param,$post);
if($dataOne !== true){
$this->ajaxReturn($dataOne);
}
if($post['orderId'] == '' || $post['type'] == '' || $post['url'] == '' || $post['storageType'] == '' || $post['address'] == ''){
$res = callBack(statusCode()['error'],'参数不能为空');
$this->ajaxReturn($res);
}
$retailBillOrderModel = new RetailBillOrderModel;
$orderWhere = [
'id'=>$post['orderId']
];
$orderFields = [
'store_id'
];
//获取这条订单id
$storeId = $retailBillOrderModel->getFindField($orderWhere,$orderFields);
//添加祝福语,判断门店是否有权限
$storePlug['store_id'] = $storeId;
$storePlug['identification'] = 'blessing';
//门店id
$merchantIdBlessingPlug = $index->storeBlessingPlug($storePlug);
if($merchantIdBlessingPlug['status'] != 1){
//无权限
$this->ajaxReturn($merchantIdBlessingPlug);
}
$where = [
'order_id'=>$post['orderId']
];
$save = [
'type'=>$post['type'],//类型:1视频,2音频
'url'=>$post['url'],//路径地址
'storage_type'=>$post['storageType'],//存储类型:1本地,2七牛云,3腾讯云,4阿里云
'address'=>$post['address'],//详细路径地址
'update_time'=>time(),//更新时间
];
$plugBlessingModel = new BlessingModel();
$data = $plugBlessingModel->updateOrder($where,$save);
if($data === false){
$res = callBack(statusCode()['error'],'失败');
}else{
$res = callBack(statusCode()['success'],'成功');
}
$this->ajaxReturn($res);
}
/**
* 祝福语隐私声明
*/
public function privacyStatement(){
$storeId = self::$store_id;
$storeConfigModel = new StoreConfigModel();
$where = [
'store_id'=>$storeId
];
$field = [
'entrance_img_id',
'privacy_statement',
];
$data = $storeConfigModel->getFind($where,$field);//门店设置表信息
$identification = 'blessing';//插件名
$index = new Index();
//添加祝福语,判断门店是否有权限,并开启权限
$storePlug['store_id'] = $storeId;
$storePlug['identification'] = $identification;
//门店id
$merchantIdBlessingPlug = $index->storePlugStatus($storePlug);
if($merchantIdBlessingPlug['status'] != 1){
//无权限
$data['status'] = '2';
}else{
$data['status'] = '1';
}
if($data === false){
$res = callBack(statusCode()['error'],'失败');
}else{
if($data['entrance_img_id']){
$ImageGalleryModel = new ImageGalleryModel();
$data['entrance_style'] = $ImageGalleryModel->getImagePath($data['entrance_img_id']);//图片拼接路径
if($data['entrance_style'] == ''){
$entrance_style = getServerUrl();
$data['entrance_style'] = $entrance_style.'/Public/plug/blessing/images/blessing_default.png';
}
}else{
$entrance_style = getServerUrl();
$data['entrance_style'] = $entrance_style.'/Public/plug/blessing/images/blessing_default.png';
}
$res = callBack(statusCode()['success'],'成功',$data);
}
$this->ajaxReturn($res);
}
/**
* 祝福语
* 小程序订单查询祝福语
*/
public function blessingInfo(){
$post = I("post.");
$param = [
'orderId',//订单id
];
$index = new Index();
$customValidate = new CustomValidate();
$dataOne = $customValidate->validationParameters($param,$post);
if($dataOne !== true){
$this->ajaxReturn($dataOne);
}
if($post['orderId'] == ''){
$res = callBack(statusCode()['error'],'请选择订单');
$this->ajaxReturn($res);
}
$where = [
'order_id'=>$post['orderId'],//订单id
];
$field = [
'type',//类型:1视频,2音频
'storage_type',//存储类型:1本地,2七牛云,3腾讯云,4阿里云
'address',//路径地址
'validity_time',//1永久有效,有效期:时间戳
'extraction_code',//祝福码
'url',//路径
];
$plugBlessingModel = new BlessingModel();
$data = $plugBlessingModel->getFind($where,$field);
if(!$data){
$res = callBack(statusCode()['error'],'订单没有祝福语');
$this->ajaxReturn($res);
}
//判断祝福语是否过期
$time = time();
if($data['validity_time'] && $data['validity_time'] != 1 && $data['validity_time'] < $time){
$res = callBack(statusCode()['error'],'祝福语已过期');
$this->ajaxReturn($res);
}
if($data === false){
$res = callBack(statusCode()['error'],'失败');
}else{
if($data && $data['storage_type'] == 1){
$entrance_style = getServerUrl();
$data['address'] = $entrance_style.'/'.$data['url'];
}
$res = callBack(statusCode()['success'],'成功',$data);
}
$this->ajaxReturn($res);
}
//取消祝福语
public function blessingDelete(){
$post = I("post.");
$param = [
'orderId',//订单id
'extractionCode',//祝福码
];
$index = new Index();
$customValidate = new CustomValidate();
$dataOne = $customValidate->validationParameters($param,$post);
if($dataOne !== true){
$this->ajaxReturn($dataOne);
}
if($post['orderId'] == '' || $post['extractionCode'] == ''){
$res = callBack(statusCode()['error'],'参数不能为空');
$this->ajaxReturn($res);
}
$where = [
'order_id'=>$post['orderId'],//订单id
'extraction_code'=>$post['extractionCode'],//祝福码
];
$plugBlessingModel = new BlessingModel();
$data = $plugBlessingModel->deleteOrder($where);
if($data === false){
$res = callBack(statusCode()['error'],'失败');
}else{
$res = callBack(statusCode()['success'],'成功');
}
$this->ajaxReturn($res);
}
}